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     auto 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     auto& bmcBootedActions = ledMap.at(bmcBooted).actionSet;
20     auto& powerOnActions = ledMap.at(powerOn).actionSet;
21     auto& enclosureIdentifyActions = ledMap.at(enclosureIdentify).actionSet;
22 
23     for (const auto& group : bmcBootedActions)
24     {
25         ASSERT_EQ(group.name, "heartbeat");
26         ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
27         ASSERT_EQ(group.dutyOn, 50);
28         ASSERT_EQ(group.period, 0);
29         ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink);
30     }
31 
32     for (const auto& group : powerOnActions)
33     {
34         ASSERT_EQ(group.name, "power");
35         ASSERT_EQ(group.action, phosphor::led::Layout::Action::On);
36         ASSERT_EQ(group.dutyOn, 50);
37         ASSERT_EQ(group.period, 0);
38         ASSERT_EQ(group.priority, phosphor::led::Layout::Action::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::Action::Blink);
46             ASSERT_EQ(group.dutyOn, 50);
47             ASSERT_EQ(group.period, 1000);
48             ASSERT_EQ(group.priority, phosphor::led::Layout::Action::Blink);
49         }
50         else if (group.name == "rear_id")
51         {
52             ASSERT_EQ(group.action, phosphor::led::Layout::Action::Blink);
53             ASSERT_EQ(group.dutyOn, 50);
54             ASSERT_EQ(group.period, 1000);
55             ASSERT_EQ(group.priority, phosphor::led::Layout::Action::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::Action::Blink,
74                      priorityMap);
75     validatePriority("power", phosphor::led::Layout::Action::On, priorityMap);
76 
77     ASSERT_EQ(priorityMap.at("heartbeat"),
78               phosphor::led::Layout::Action::Blink);
79     ASSERT_EQ(priorityMap.at("power"), phosphor::led::Layout::Action::On);
80 }
81 
82 TEST(validatePriority, testBadPriority)
83 {
84     PriorityMap priorityMap{};
85     validatePriority("heartbeat", phosphor::led::Layout::Action::Blink,
86                      priorityMap);
87 
88     ASSERT_EQ(priorityMap.at("heartbeat"),
89               phosphor::led::Layout::Action::Blink);
90     ASSERT_THROW(validatePriority("heartbeat",
91                                   phosphor::led::Layout::Action::On,
92                                   priorityMap),
93                  std::runtime_error);
94 }
95