1 #include "json-parser.hpp" 2 3 #include <gtest/gtest.h> 4 5 TEST(loadJsonConfig, testGoodPath) 6 { 7 static constexpr auto jsonPath = "config/led-group-config.json"; 8 LedMap ledMap = loadJsonConfig(jsonPath); 9 10 std::string objPath = "/xyz/openbmc_project/led/groups"; 11 std::string bmcBooted = objPath + "/bmc_booted"; 12 std::string powerOn = objPath + "/power_on"; 13 std::string enclosureIdentify = objPath + "/enclosure_identify"; 14 15 ASSERT_EQ(ledMap.contains(bmcBooted), true); 16 ASSERT_EQ(ledMap.contains(powerOn), true); 17 ASSERT_EQ(ledMap.contains(enclosureIdentify), true); 18 19 LedAction bmcBootedActions = ledMap.at(bmcBooted); 20 LedAction powerOnActions = ledMap.at(powerOn); 21 LedAction enclosureIdentifyActions = ledMap.at(enclosureIdentify); 22 23 for (const auto& group : bmcBootedActions) 24 { 25 ASSERT_EQ(group.name, "heartbeat"); 26 ASSERT_EQ(group.action, phosphor::led::Layout::On); 27 ASSERT_EQ(group.dutyOn, 50); 28 ASSERT_EQ(group.period, 0); 29 ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); 30 } 31 32 for (const auto& group : powerOnActions) 33 { 34 ASSERT_EQ(group.name, "power"); 35 ASSERT_EQ(group.action, phosphor::led::Layout::On); 36 ASSERT_EQ(group.dutyOn, 50); 37 ASSERT_EQ(group.period, 0); 38 ASSERT_EQ(group.priority, phosphor::led::Layout::On); 39 } 40 41 for (const auto& group : enclosureIdentifyActions) 42 { 43 if (group.name == "front_id") 44 { 45 ASSERT_EQ(group.action, phosphor::led::Layout::Blink); 46 ASSERT_EQ(group.dutyOn, 50); 47 ASSERT_EQ(group.period, 1000); 48 ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); 49 } 50 else if (group.name == "rear_id") 51 { 52 ASSERT_EQ(group.action, phosphor::led::Layout::Blink); 53 ASSERT_EQ(group.dutyOn, 50); 54 ASSERT_EQ(group.period, 1000); 55 ASSERT_EQ(group.priority, phosphor::led::Layout::Blink); 56 } 57 else 58 { 59 ASSERT_TRUE(false); 60 } 61 } 62 } 63 64 TEST(loadJsonConfig, testBadPath) 65 { 66 static constexpr auto jsonPath = "config/led-group-config-malformed.json"; 67 ASSERT_THROW(loadJsonConfig(jsonPath), std::exception); 68 } 69 70 TEST(validatePriority, testGoodPriority) 71 { 72 PriorityMap priorityMap{}; 73 validatePriority("heartbeat", phosphor::led::Layout::Blink, priorityMap); 74 validatePriority("power", phosphor::led::Layout::On, priorityMap); 75 76 ASSERT_EQ(priorityMap.at("heartbeat"), phosphor::led::Layout::Blink); 77 ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::On); 78 } 79 80 TEST(validatePriority, testBadPriority) 81 { 82 PriorityMap priorityMap{}; 83 validatePriority("heartbeat", phosphor::led::Layout::Blink, priorityMap); 84 85 ASSERT_EQ(priorityMap.at("heartbeat"), phosphor::led::Layout::Blink); 86 ASSERT_THROW( 87 validatePriority("heartbeat", phosphor::led::Layout::On, priorityMap), 88 std::runtime_error); 89 }