blob: 1eda517c05e2efa49c2a5e7217245833a687cd97 [file] [log] [blame]
Alexander Hansen638d1482024-08-21 17:39:57 +02001#include "config-validator.hpp"
2#include "grouplayout.hpp"
3#include "ledlayout.hpp"
4
5#include <gtest/gtest.h>
6
7using namespace phosphor::led;
8
9static void assertValidationException(const GroupMap& ledMap,
10 error::ConfigValidationError err)
11{
12 try
13 {
14 validateConfigV1(ledMap);
15 ASSERT_FALSE(true);
16 }
17 catch (ConfigValidationException& e)
18 {
19 ASSERT_EQ(e.reason, err);
20 }
21}
22
23TEST(validateConfig, testGoodPathLedPriority)
24{
25 ActionSet group1ActionSet = {
26 {"led1", Layout::Action::On, 0, 0, Layout::Action::On},
27 {"led2", Layout::Action::On, 0, 0, Layout::Action::Blink},
28 };
29 Layout::GroupLayout group1 = {0, group1ActionSet};
30 GroupMap ledMap = {{"group1", group1}};
31
32 validateConfigV1(ledMap);
33}
34
35TEST(validateConfig, testGoodPathGroupPriority)
36{
37 ActionSet group1ActionSet = {
38 {"led1", Layout::Action::On, 0, 0, std::nullopt},
39 {"led2", Layout::Action::On, 0, 0, std::nullopt},
40 };
41 ActionSet group2ActionSet = {
42 {"led1", Layout::Action::On, 0, 0, std::nullopt},
43 {"led2", Layout::Action::On, 0, 0, std::nullopt},
44 };
45 Layout::GroupLayout group1 = {1, group1ActionSet};
46 Layout::GroupLayout group2 = {2, group1ActionSet};
47 GroupMap ledMap = {
48 {"group1", group1},
49 {"group2", group2},
50 };
51
52 validateConfigV1(ledMap);
53}
54
55TEST(validateConfig, testLedPriorityMismatch)
56{
57 ActionSet group1ActionSet = {
58 {"led1", Layout::Action::On, 0, 0, Layout::Action::On},
59 };
60 ActionSet group2ActionSet = {
61 {"led1", Layout::Action::On, 0, 0, Layout::Action::Off},
62 };
63 Layout::GroupLayout group1 = {0, group1ActionSet};
64 Layout::GroupLayout group2 = {0, group2ActionSet};
65 GroupMap ledMap = {
66 {"group1", group1},
67 {"group2", group2},
68 };
69
70 assertValidationException(ledMap, error::LedPriorityMismatch);
71}
72
73TEST(validateConfig, testMissingLedPriority)
74{
75 ActionSet group1ActionSet = {
76 {"led1", Layout::Action::On, 0, 0, Layout::Action::On},
77 };
78 ActionSet group2ActionSet = {
79 {"led1", Layout::Action::On, 0, 0, std::nullopt},
80 };
81 Layout::GroupLayout group1 = {0, group1ActionSet};
82 Layout::GroupLayout group2 = {0, group2ActionSet};
83 GroupMap ledMap = {
84 {"group1", group1},
85 {"group2", group2},
86 };
87
88 assertValidationException(ledMap, error::MissingLedPriority);
89}
90
91TEST(validateConfig, testMixedLedAndGroupPriority)
92{
93 ActionSet group1ActionSet = {
94 {"led1", Layout::Action::On, 0, 0, Layout::Action::On},
95 };
96 ActionSet group2ActionSet = {
97 {"led1", Layout::Action::On, 0, 0, Layout::Action::On},
98 };
99 Layout::GroupLayout group1 = {0, group1ActionSet};
100 Layout::GroupLayout group2 = {1, group2ActionSet};
101 GroupMap ledMap = {
102 {"group1", group1},
103 {"group2", group2},
104 };
105
106 assertValidationException(ledMap, error::MixedLedAndGroupPriority);
107}
108
109TEST(validateConfig, testInvalidGroupPriority)
110{
111 ActionSet group1ActionSet = {
112 {"led1", Layout::Action::On, 0, 0, std::nullopt},
113 };
114 ActionSet group2ActionSet = {
115 {"led1", Layout::Action::On, 0, 0, std::nullopt},
116 };
117 Layout::GroupLayout group1 = {0, group1ActionSet};
118 Layout::GroupLayout group2 = {1, group2ActionSet};
119 GroupMap ledMap = {
120 {"group1", group1},
121 {"group2", group2},
122 };
123
124 assertValidationException(ledMap, error::InvalidGroupPriority);
125}
126
127TEST(validateConfig, testDuplicateGroupPriority)
128{
129 ActionSet group1ActionSet = {
130 {"led1", Layout::Action::On, 0, 0, std::nullopt},
131 };
132 ActionSet group2ActionSet = {
133 {"led1", Layout::Action::On, 0, 0, std::nullopt},
134 };
135 Layout::GroupLayout group1 = {1, group1ActionSet};
136 Layout::GroupLayout group2 = {1, group2ActionSet};
137 GroupMap ledMap = {
138 {"group1", group1},
139 {"group2", group2},
140 };
141
142 assertValidationException(ledMap, error::DuplicateGroupPriority);
143}