1 /**
2  * Copyright © 2019 IBM Corporation
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 #include "action_environment.hpp"
17 #include "device.hpp"
18 #include "id_map.hpp"
19 #include "set_device_action.hpp"
20 
21 #include <exception>
22 
23 #include <gtest/gtest.h>
24 
25 using namespace phosphor::power::regulators;
26 
27 TEST(SetDeviceActionTests, Constructor)
28 {
29     SetDeviceAction action{"regulator1"};
30     EXPECT_EQ(action.getDeviceID(), "regulator1");
31 }
32 
33 TEST(SetDeviceActionTests, Execute)
34 {
35     // Create IDMap
36     IDMap idMap{};
37     Device reg1{"regulator1"};
38     idMap.addDevice(reg1);
39     Device reg2{"regulator2"};
40     idMap.addDevice(reg2);
41 
42     // Create ActionEnvironment
43     ActionEnvironment env{idMap, "regulator1"};
44 
45     // Create action
46     SetDeviceAction action{"regulator2"};
47 
48     // Execute action
49     try
50     {
51         EXPECT_EQ(env.getDeviceID(), "regulator1");
52         EXPECT_EQ(action.execute(env), true);
53         EXPECT_EQ(env.getDeviceID(), "regulator2");
54     }
55     catch (const std::exception& error)
56     {
57         ADD_FAILURE() << "Should not have caught exception.";
58     }
59 }
60 
61 TEST(SetDeviceActionTests, GetDeviceID)
62 {
63     SetDeviceAction action{"io_expander_0"};
64     EXPECT_EQ(action.getDeviceID(), "io_expander_0");
65 }
66