regulators: Add phase fault type to parser
Enhance the JSON configuration file parser to support the new
phase fault type values.
Add gtest test cases to exercise new code.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: If5ac011f740fdb6f24692c713a56d4947709d660
diff --git a/phosphor-regulators/src/config_file_parser.cpp b/phosphor-regulators/src/config_file_parser.cpp
index be28fdc..5330f59 100644
--- a/phosphor-regulators/src/config_file_parser.cpp
+++ b/phosphor-regulators/src/config_file_parser.cpp
@@ -738,6 +738,27 @@
return std::make_unique<OrAction>(std::move(actions));
}
+PhaseFaultType parsePhaseFaultType(const json& element)
+{
+ std::string value = parseString(element);
+ PhaseFaultType type{};
+
+ if (value == "n")
+ {
+ type = PhaseFaultType::n;
+ }
+ else if (value == "n+1")
+ {
+ type = PhaseFaultType::n_plus_1;
+ }
+ else
+ {
+ throw std::invalid_argument{"Element is not a phase fault type"};
+ }
+
+ return type;
+}
+
std::unique_ptr<PMBusReadSensorAction> parsePMBusReadSensor(const json& element)
{
verifyIsObject(element);
@@ -1054,11 +1075,7 @@
SensorType parseSensorType(const json& element)
{
- if (!element.is_string())
- {
- throw std::invalid_argument{"Element is not a string"};
- }
- std::string value = element.get<std::string>();
+ std::string value = parseString(element);
SensorType type{};
if (value == "iout")