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