1 #include "json-config.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_NE(ledMap.find(bmcBooted), ledMap.end()); 16 ASSERT_NE(ledMap.find(powerOn), ledMap.end()); 17 ASSERT_NE(ledMap.find(enclosureIdentify), ledMap.end()); 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 }