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