Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 1 | #include "ipmi.hpp" |
| 2 | |
| 3 | #include <cstring> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace blobs |
| 8 | { |
| 9 | |
| 10 | // ipmid.hpp isn't installed where we can grab it and this value is per BMC |
| 11 | // SoC. |
| 12 | #define MAX_IPMI_BUFFER 64 |
| 13 | |
| 14 | TEST(StringInputTest, NullPointerInput) |
| 15 | { |
| 16 | // The method should verify it did receive a non-null input pointer. |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 17 | EXPECT_STREQ("", stringFromBuffer({}).c_str()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | TEST(StringInputTest, ZeroBytesInput) |
| 21 | { |
| 22 | // Verify that if the input length is 0 that it'll return the empty string. |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 23 | const std::string request = "asdf"; |
| 24 | EXPECT_STREQ("", stringFromBuffer( |
| 25 | std::vector<uint8_t>(request.begin(), request.end())) |
| 26 | .c_str()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | TEST(StringInputTest, NulTerminatorNotFound) |
| 30 | { |
| 31 | // Verify that if there isn't a nul-terminator found in an otherwise valid |
| 32 | // string, it'll return the emptry string. |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 33 | std::array<char, MAX_IPMI_BUFFER> request; |
| 34 | std::memset(request.data(), 'a', sizeof(request)); |
| 35 | EXPECT_STREQ("", stringFromBuffer( |
| 36 | std::vector<uint8_t>(request.begin(), request.end())) |
| 37 | .c_str()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | TEST(StringInputTest, NulTerminatorFound) |
| 41 | { |
| 42 | // Verify that if it's provided a valid nul-terminated string, it'll |
| 43 | // return it. |
Willy Tu | 067ece1 | 2022-06-16 02:07:06 -0700 | [diff] [blame] | 44 | std::string request = "asdf"; |
| 45 | request.push_back('\0'); |
Patrick Williams | 97e69ca | 2024-08-16 15:21:49 -0400 | [diff] [blame^] | 46 | EXPECT_STREQ( |
| 47 | "asdf", |
| 48 | stringFromBuffer(std::vector<uint8_t>(request.begin(), request.end())) |
| 49 | .c_str()); |
Patrick Venture | ef3aead | 2018-09-12 08:53:29 -0700 | [diff] [blame] | 50 | } |
| 51 | } // namespace blobs |