Andrew Jeffery | cc45aed | 2023-09-10 23:03:29 +0930 | [diff] [blame] | 1 | // NOLINTNEXTLINE(bugprone-suspicious-include) |
| 2 | #include "responder.c" |
| 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | TEST(Responder, track_untrack_one) |
| 7 | { |
Patrick Williams | f37edd7 | 2024-12-18 11:22:58 -0500 | [diff] [blame^] | 8 | struct pldm_responder_cookie jar{}; |
Andrew Jeffery | cc45aed | 2023-09-10 23:03:29 +0930 | [diff] [blame] | 9 | 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 | |
| 23 | TEST(Responder, untrack_none) |
| 24 | { |
Patrick Williams | f37edd7 | 2024-12-18 11:22:58 -0500 | [diff] [blame^] | 25 | struct pldm_responder_cookie jar{}; |
Andrew Jeffery | cc45aed | 2023-09-10 23:03:29 +0930 | [diff] [blame] | 26 | |
| 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 | |
| 32 | TEST(Responder, track_one_untrack_bad) |
| 33 | { |
Patrick Williams | f37edd7 | 2024-12-18 11:22:58 -0500 | [diff] [blame^] | 34 | struct pldm_responder_cookie jar{}; |
Andrew Jeffery | cc45aed | 2023-09-10 23:03:29 +0930 | [diff] [blame] | 35 | 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 | |
| 54 | TEST(Responder, track_untrack_two) |
| 55 | { |
Patrick Williams | f37edd7 | 2024-12-18 11:22:58 -0500 | [diff] [blame^] | 56 | struct pldm_responder_cookie jar{}; |
Andrew Jeffery | cc45aed | 2023-09-10 23:03:29 +0930 | [diff] [blame] | 57 | 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 | } |