1 /**
2  * Copyright © 2020 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_error.hpp"
17 #include "run_rule_action.hpp"
18 
19 #include <gtest/gtest.h>
20 
21 using namespace phosphor::power::regulators;
22 
TEST(ActionErrorTests,Constructor)23 TEST(ActionErrorTests, Constructor)
24 {
25     // Test where only action is specified
26     {
27         RunRuleAction action{"set_voltage_rule"};
28         ActionError error{action};
29         EXPECT_STREQ(error.what(), "ActionError: run_rule: set_voltage_rule");
30     }
31 
32     // Test where action and error message are specified
33     {
34         RunRuleAction action{"set_voltage_rule"};
35         ActionError error{action, "Infinite loop"};
36         EXPECT_STREQ(error.what(),
37                      "ActionError: run_rule: set_voltage_rule: Infinite loop");
38     }
39 }
40 
TEST(ActionErrorTests,What)41 TEST(ActionErrorTests, What)
42 {
43     RunRuleAction action{"set_voltage_rule"};
44     ActionError error{action, "Invalid rule ID"};
45     EXPECT_STREQ(error.what(),
46                  "ActionError: run_rule: set_voltage_rule: Invalid rule ID");
47 }
48