xref: /openbmc/openpower-vpd-parser/test/utest_json_utility.cpp (revision 480807cf8a3ef27eef4063bac422d69343b123d1)
1 #include "parser.hpp"
2 #include "types.hpp"
3 #include "utility/json_utility.hpp"
4 #include "utility/vpd_specific_utility.hpp"
5 
6 #include <iostream>
7 
8 #include <gtest/gtest.h>
9 
10 using namespace vpd;
11 
12 TEST(IsFruPowerOffOnlyTest, PositiveTestCase)
13 {
14     uint16_t l_errCode = 0;
15     const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
16     const std::string l_vpdPath{"/sys/bus/spi/drivers/at25/spi12.0/eeprom"};
17     const nlohmann::json l_parsedJson =
18         jsonUtility::getParsedJson(l_jsonPath, l_errCode);
19 
20     if (l_errCode)
21     {
22         logging::logMessage(
23             "Failed to parse JSON file [" + l_jsonPath +
24             "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
25     }
26 
27     const bool l_result =
28         jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath);
29     EXPECT_TRUE(l_result);
30 }
31 
32 TEST(IsFruPowerOffOnlyTest, NegativeTestCase)
33 {
34     uint16_t l_errCode = 0;
35     const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
36     const std::string l_vpdPath{"/sys/bus/i2c/drivers/at24/4-0050/eeprom"};
37     const nlohmann::json l_parsedJson =
38         jsonUtility::getParsedJson(l_jsonPath, l_errCode);
39 
40     if (l_errCode)
41     {
42         logging::logMessage(
43             "Failed to parse JSON file [" + l_jsonPath +
44             "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
45     }
46 
47     const bool l_result =
48         jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath);
49     EXPECT_FALSE(l_result);
50 }
51