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 
TEST(StringInputTest,NullPointerInput)14 TEST(StringInputTest, NullPointerInput)
15 {
16     // The method should verify it did receive a non-null input pointer.
17     EXPECT_STREQ("", stringFromBuffer({}).c_str());
18 }
19 
TEST(StringInputTest,ZeroBytesInput)20 TEST(StringInputTest, ZeroBytesInput)
21 {
22     // Verify that if the input length is 0 that it'll return the empty string.
23     const std::string request = "asdf";
24     EXPECT_STREQ("", stringFromBuffer(
25                          std::vector<uint8_t>(request.begin(), request.end()))
26                          .c_str());
27 }
28 
TEST(StringInputTest,NulTerminatorNotFound)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.
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());
38 }
39 
TEST(StringInputTest,NulTerminatorFound)40 TEST(StringInputTest, NulTerminatorFound)
41 {
42     // Verify that if it's provided a valid nul-terminated string, it'll
43     // return it.
44     std::string request = "asdf";
45     request.push_back('\0');
46     EXPECT_STREQ("asdf", stringFromBuffer(std::vector<uint8_t>(request.begin(),
47                                                                request.end()))
48                              .c_str());
49 }
50 } // namespace blobs
51