1*24d124f9SAlexander Hansen /**
2*24d124f9SAlexander Hansen * Copyright © 2024 9elements
3*24d124f9SAlexander Hansen *
4*24d124f9SAlexander Hansen * Licensed under the Apache License, Version 2.0 (the "License");
5*24d124f9SAlexander Hansen * you may not use this file except in compliance with the License.
6*24d124f9SAlexander Hansen * You may obtain a copy of the License at
7*24d124f9SAlexander Hansen *
8*24d124f9SAlexander Hansen * http://www.apache.org/licenses/LICENSE-2.0
9*24d124f9SAlexander Hansen *
10*24d124f9SAlexander Hansen * Unless required by applicable law or agreed to in writing, software
11*24d124f9SAlexander Hansen * distributed under the License is distributed on an "AS IS" BASIS,
12*24d124f9SAlexander Hansen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*24d124f9SAlexander Hansen * See the License for the specific language governing permissions and
14*24d124f9SAlexander Hansen * limitations under the License.
15*24d124f9SAlexander Hansen */
16*24d124f9SAlexander Hansen
17*24d124f9SAlexander Hansen #include "interfaces/internal_interface.hpp"
18*24d124f9SAlexander Hansen #include "sysfs.hpp"
19*24d124f9SAlexander Hansen
20*24d124f9SAlexander Hansen #include <gtest/gtest.h>
21*24d124f9SAlexander Hansen
22*24d124f9SAlexander Hansen using namespace phosphor::led;
23*24d124f9SAlexander Hansen
runtest(const std::string & name)24*24d124f9SAlexander Hansen static LedDescr runtest(const std::string& name)
25*24d124f9SAlexander Hansen {
26*24d124f9SAlexander Hansen std::string path = devParent + name;
27*24d124f9SAlexander Hansen SysfsLed led(path);
28*24d124f9SAlexander Hansen return led.getLedDescr();
29*24d124f9SAlexander Hansen }
30*24d124f9SAlexander Hansen
TEST(LEDDescr,Has4PartsInvalid)31*24d124f9SAlexander Hansen TEST(LEDDescr, Has4PartsInvalid)
32*24d124f9SAlexander Hansen {
33*24d124f9SAlexander Hansen LedDescr d = runtest("devicename:color:function:part4");
34*24d124f9SAlexander Hansen
35*24d124f9SAlexander Hansen ASSERT_EQ("devicename", d.devicename);
36*24d124f9SAlexander Hansen ASSERT_EQ("color", d.color);
37*24d124f9SAlexander Hansen ASSERT_EQ("function", d.function);
38*24d124f9SAlexander Hansen }
39*24d124f9SAlexander Hansen
TEST(LEDDescr,Has3Parts)40*24d124f9SAlexander Hansen TEST(LEDDescr, Has3Parts)
41*24d124f9SAlexander Hansen {
42*24d124f9SAlexander Hansen LedDescr d = runtest("devicename:color:function");
43*24d124f9SAlexander Hansen
44*24d124f9SAlexander Hansen ASSERT_EQ("devicename", d.devicename);
45*24d124f9SAlexander Hansen ASSERT_EQ("color", d.color);
46*24d124f9SAlexander Hansen ASSERT_EQ("function", d.function);
47*24d124f9SAlexander Hansen }
48*24d124f9SAlexander Hansen
TEST(LEDDescr,Has2PartsColorFunction)49*24d124f9SAlexander Hansen TEST(LEDDescr, Has2PartsColorFunction)
50*24d124f9SAlexander Hansen {
51*24d124f9SAlexander Hansen LedDescr d = runtest("red:fault");
52*24d124f9SAlexander Hansen
53*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.devicename);
54*24d124f9SAlexander Hansen ASSERT_EQ("red", d.color);
55*24d124f9SAlexander Hansen ASSERT_EQ("fault", d.function);
56*24d124f9SAlexander Hansen }
57*24d124f9SAlexander Hansen
TEST(LEDDescr,Has2PartsDevicenameFunction)58*24d124f9SAlexander Hansen TEST(LEDDescr, Has2PartsDevicenameFunction)
59*24d124f9SAlexander Hansen {
60*24d124f9SAlexander Hansen LedDescr d = runtest("input9::capslock");
61*24d124f9SAlexander Hansen
62*24d124f9SAlexander Hansen ASSERT_EQ("input9", d.devicename);
63*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.color);
64*24d124f9SAlexander Hansen ASSERT_EQ("capslock", d.function);
65*24d124f9SAlexander Hansen }
66*24d124f9SAlexander Hansen
TEST(LEDDescr,Has1PartColor)67*24d124f9SAlexander Hansen TEST(LEDDescr, Has1PartColor)
68*24d124f9SAlexander Hansen {
69*24d124f9SAlexander Hansen LedDescr d = runtest("green:");
70*24d124f9SAlexander Hansen
71*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.devicename);
72*24d124f9SAlexander Hansen ASSERT_EQ("green", d.color);
73*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.function);
74*24d124f9SAlexander Hansen }
75*24d124f9SAlexander Hansen
TEST(LEDDescr,Has1PartFunction)76*24d124f9SAlexander Hansen TEST(LEDDescr, Has1PartFunction)
77*24d124f9SAlexander Hansen {
78*24d124f9SAlexander Hansen LedDescr d = runtest(":boot");
79*24d124f9SAlexander Hansen
80*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.devicename);
81*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.color);
82*24d124f9SAlexander Hansen ASSERT_EQ("boot", d.function);
83*24d124f9SAlexander Hansen }
84*24d124f9SAlexander Hansen
TEST(LEDDescr,Has1PartLabel)85*24d124f9SAlexander Hansen TEST(LEDDescr, Has1PartLabel)
86*24d124f9SAlexander Hansen {
87*24d124f9SAlexander Hansen LedDescr d = runtest("identify");
88*24d124f9SAlexander Hansen
89*24d124f9SAlexander Hansen ASSERT_EQ("identify", d.devicename);
90*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.color);
91*24d124f9SAlexander Hansen ASSERT_EQ(std::nullopt, d.function);
92*24d124f9SAlexander Hansen }
93