Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 1 | #include "parser.hpp" |
| 2 | #include "types.hpp" |
| 3 | #include "utility/json_utility.hpp" |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 4 | #include "utility/vpd_specific_utility.hpp" |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 5 | |
| 6 | #include <iostream> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using namespace vpd; |
| 11 | |
| 12 | TEST(IsFruPowerOffOnlyTest, PositiveTestCase) |
| 13 | { |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 14 | uint16_t l_errCode = 0; |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 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"}; |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 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 | |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 27 | const bool l_result = |
| 28 | jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath); |
| 29 | EXPECT_TRUE(l_result); |
| 30 | } |
| 31 | |
| 32 | TEST(IsFruPowerOffOnlyTest, NegativeTestCase) |
| 33 | { |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 34 | uint16_t l_errCode = 0; |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 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"}; |
Rekha Aparna | ca9a086 | 2025-08-29 04:08:33 -0500 | [diff] [blame] | 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 | |
Sunny Srivastava | fa5e4d3 | 2023-03-12 11:59:49 -0500 | [diff] [blame] | 47 | const bool l_result = |
| 48 | jsonUtility::isFruPowerOffOnly(l_parsedJson, l_vpdPath); |
| 49 | EXPECT_FALSE(l_result); |
| 50 | } |