blob: 955514889d8dd2b0db6ee618297b2361960e37d0 [file] [log] [blame]
Andrew Jefferycc45aed2023-09-10 23:03:29 +09301// NOLINTNEXTLINE(bugprone-suspicious-include)
2#include "responder.c"
3
4#include <gtest/gtest.h>
5
6TEST(Responder, track_untrack_one)
7{
Patrick Williamsf37edd72024-12-18 11:22:58 -05008 struct pldm_responder_cookie jar{};
Andrew Jefferycc45aed2023-09-10 23:03:29 +09309 struct pldm_responder_cookie cookie = {
10 .tid = 1,
11 .instance_id = 1,
12 .type = 0,
13 .command = 0x01, /* SetTID */
14 .next = nullptr,
15 };
16
17 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0);
18 ASSERT_NE(jar.next, nullptr);
19 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie);
20 ASSERT_EQ(jar.next, nullptr);
21}
22
23TEST(Responder, untrack_none)
24{
Patrick Williamsf37edd72024-12-18 11:22:58 -050025 struct pldm_responder_cookie jar{};
Andrew Jefferycc45aed2023-09-10 23:03:29 +093026
27 ASSERT_EQ(jar.next, nullptr);
28 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), nullptr);
29 ASSERT_EQ(jar.next, nullptr);
30}
31
32TEST(Responder, track_one_untrack_bad)
33{
Patrick Williamsf37edd72024-12-18 11:22:58 -050034 struct pldm_responder_cookie jar{};
Andrew Jefferycc45aed2023-09-10 23:03:29 +093035 struct pldm_responder_cookie cookie = {
36 .tid = 1,
37 .instance_id = 1,
38 .type = 0,
39 .command = 0x01, /* SetTID */
40 .next = nullptr,
41 };
42
43 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0);
44 ASSERT_NE(jar.next, nullptr);
45 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), nullptr);
46 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 2, 0, 0x01), nullptr);
47 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 1, 0x01), nullptr);
48 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x02), nullptr);
49 ASSERT_NE(jar.next, nullptr);
50 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie);
51 ASSERT_EQ(jar.next, nullptr);
52}
53
54TEST(Responder, track_untrack_two)
55{
Patrick Williamsf37edd72024-12-18 11:22:58 -050056 struct pldm_responder_cookie jar{};
Andrew Jefferycc45aed2023-09-10 23:03:29 +093057 struct pldm_responder_cookie cookies[] = {
58 {
59 .tid = 1,
60 .instance_id = 1,
61 .type = 0,
62 .command = 0x01, /* SetTID */
63 .next = nullptr,
64 },
65 {
66 .tid = 2,
67 .instance_id = 1,
68 .type = 0,
69 .command = 0x01, /* SetTID */
70 .next = nullptr,
71 },
72 };
73
74 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[0]), 0);
75 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[1]), 0);
76 ASSERT_NE(jar.next, nullptr);
77 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), &cookies[1]);
78 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookies[0]);
79 ASSERT_EQ(jar.next, nullptr);
80}