blob: ed2f0263b152ce22937410009b0ca1b5577c0bab [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#include "ipmi.hpp"
2
3#include <cstring>
4
5#include <gtest/gtest.h>
6
7namespace 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
14TEST(StringInputTest, NullPointerInput)
15{
16 // The method should verify it did receive a non-null input pointer.
Willy Tu067ece12022-06-16 02:07:06 -070017 EXPECT_STREQ("", stringFromBuffer({}).c_str());
Patrick Ventureef3aead2018-09-12 08:53:29 -070018}
19
20TEST(StringInputTest, ZeroBytesInput)
21{
22 // Verify that if the input length is 0 that it'll return the empty string.
Willy Tu067ece12022-06-16 02:07:06 -070023 const std::string request = "asdf";
24 EXPECT_STREQ("", stringFromBuffer(
25 std::vector<uint8_t>(request.begin(), request.end()))
26 .c_str());
Patrick Ventureef3aead2018-09-12 08:53:29 -070027}
28
29TEST(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 Tu067ece12022-06-16 02:07:06 -070033 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 Ventureef3aead2018-09-12 08:53:29 -070038}
39
40TEST(StringInputTest, NulTerminatorFound)
41{
42 // Verify that if it's provided a valid nul-terminated string, it'll
43 // return it.
Willy Tu067ece12022-06-16 02:07:06 -070044 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());
Patrick Ventureef3aead2018-09-12 08:53:29 -070049}
50} // namespace blobs