xref: /openbmc/openpower-vpd-parser/test/utest_json_utility.cpp (revision b5fab80a2955b33d56c07f47bf5c20057b3d1de3)
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 
TEST(IsFruPowerOffOnlyTest,PositiveTestCase)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 : " + commonUtility::getErrCodeMsg(l_errCode));
25     }
26 
27     const bool l_result =
28         jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
29 
30     if (l_errCode)
31     {
32         logging::logMessage(
33             "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
34             "], error : " + commonUtility::getErrCodeMsg(l_errCode));
35     }
36 
37     EXPECT_TRUE(l_result);
38 }
39 
TEST(IsFruPowerOffOnlyTest,NegativeTestCase)40 TEST(IsFruPowerOffOnlyTest, NegativeTestCase)
41 {
42     uint16_t l_errCode = 0;
43     const std::string l_jsonPath{"/usr/local/share/vpd/50001001.json"};
44     const std::string l_vpdPath{"/sys/bus/i2c/drivers/at24/4-0050/eeprom"};
45     const nlohmann::json l_parsedJson =
46         jsonUtility::getParsedJson(l_jsonPath, l_errCode);
47 
48     if (l_errCode)
49     {
50         logging::logMessage(
51             "Failed to parse JSON file [" + l_jsonPath +
52             "], error : " + commonUtility::getErrCodeMsg(l_errCode));
53     }
54 
55     const bool l_result =
56         jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath, l_errCode);
57 
58     if (l_errCode)
59     {
60         logging::logMessage(
61             "Failed to check if FRU is power off only for FRU [" + l_vpdPath +
62             "], error : " + commonUtility::getErrCodeMsg(l_errCode));
63     }
64 
65     EXPECT_FALSE(l_result);
66 }
67