| // NOLINTNEXTLINE(bugprone-suspicious-include) |
| #include "responder.c" |
| |
| #include <gtest/gtest.h> |
| |
| TEST(Responder, track_untrack_one) |
| { |
| struct pldm_responder_cookie jar |
| { |
| }; |
| struct pldm_responder_cookie cookie = { |
| .tid = 1, |
| .instance_id = 1, |
| .type = 0, |
| .command = 0x01, /* SetTID */ |
| .next = nullptr, |
| }; |
| |
| ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0); |
| ASSERT_NE(jar.next, nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie); |
| ASSERT_EQ(jar.next, nullptr); |
| } |
| |
| TEST(Responder, untrack_none) |
| { |
| struct pldm_responder_cookie jar |
| { |
| }; |
| |
| ASSERT_EQ(jar.next, nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), nullptr); |
| ASSERT_EQ(jar.next, nullptr); |
| } |
| |
| TEST(Responder, track_one_untrack_bad) |
| { |
| struct pldm_responder_cookie jar |
| { |
| }; |
| struct pldm_responder_cookie cookie = { |
| .tid = 1, |
| .instance_id = 1, |
| .type = 0, |
| .command = 0x01, /* SetTID */ |
| .next = nullptr, |
| }; |
| |
| ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookie), 0); |
| ASSERT_NE(jar.next, nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 2, 0, 0x01), nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 1, 0x01), nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x02), nullptr); |
| ASSERT_NE(jar.next, nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookie); |
| ASSERT_EQ(jar.next, nullptr); |
| } |
| |
| TEST(Responder, track_untrack_two) |
| { |
| struct pldm_responder_cookie jar |
| { |
| }; |
| struct pldm_responder_cookie cookies[] = { |
| { |
| .tid = 1, |
| .instance_id = 1, |
| .type = 0, |
| .command = 0x01, /* SetTID */ |
| .next = nullptr, |
| }, |
| { |
| .tid = 2, |
| .instance_id = 1, |
| .type = 0, |
| .command = 0x01, /* SetTID */ |
| .next = nullptr, |
| }, |
| }; |
| |
| ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[0]), 0); |
| ASSERT_EQ(pldm_responder_cookie_track(&jar, &cookies[1]), 0); |
| ASSERT_NE(jar.next, nullptr); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 2, 1, 0, 0x01), &cookies[1]); |
| ASSERT_EQ(pldm_responder_cookie_untrack(&jar, 1, 1, 0, 0x01), &cookies[0]); |
| ASSERT_EQ(jar.next, nullptr); |
| } |