blob: 6a0a3fdb9789e3623f872628741f130342f05f9c [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{
8 struct pldm_responder_cookie jar
9 {
10 };
11 struct pldm_responder_cookie cookie = {
12 .tid = 1,
13 .instance_id = 1,
14 .type = 0,
15 .command = 0x01, /* SetTID */
16 .next = nullptr,
17 };
18
19 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0);
20 ASSERT_NE(jar.next, nullptr);
21 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie);
22 ASSERT_EQ(jar.next, nullptr);
23}
24
25TEST(Responder, untrack_none)
26{
27 struct pldm_responder_cookie jar
28 {
29 };
30
31 ASSERT_EQ(jar.next, nullptr);
32 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), nullptr);
33 ASSERT_EQ(jar.next, nullptr);
34}
35
36TEST(Responder, track_one_untrack_bad)
37{
38 struct pldm_responder_cookie jar
39 {
40 };
41 struct pldm_responder_cookie cookie = {
42 .tid = 1,
43 .instance_id = 1,
44 .type = 0,
45 .command = 0x01, /* SetTID */
46 .next = nullptr,
47 };
48
49 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0);
50 ASSERT_NE(jar.next, nullptr);
51 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), nullptr);
52 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 2, 0, 0x01), nullptr);
53 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 1, 0x01), nullptr);
54 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x02), nullptr);
55 ASSERT_NE(jar.next, nullptr);
56 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie);
57 ASSERT_EQ(jar.next, nullptr);
58}
59
60TEST(Responder, track_untrack_two)
61{
62 struct pldm_responder_cookie jar
63 {
64 };
65 struct pldm_responder_cookie cookies[] = {
66 {
67 .tid = 1,
68 .instance_id = 1,
69 .type = 0,
70 .command = 0x01, /* SetTID */
71 .next = nullptr,
72 },
73 {
74 .tid = 2,
75 .instance_id = 1,
76 .type = 0,
77 .command = 0x01, /* SetTID */
78 .next = nullptr,
79 },
80 };
81
82 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[0]), 0);
83 ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[1]), 0);
84 ASSERT_NE(jar.next, nullptr);
85 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), &cookies[1]);
86 ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookies[0]);
87 ASSERT_EQ(jar.next, nullptr);
88}