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