regulators: Implements support for not action
Enhance the configuration file parser to support the not action element.
Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: Ia88eee705a9fae28a816aeb6dff9e0b6f0deba39
diff --git a/phosphor-regulators/test/config_file_parser_tests.cpp b/phosphor-regulators/test/config_file_parser_tests.cpp
index ed3c271..4dfc45e 100644
--- a/phosphor-regulators/test/config_file_parser_tests.cpp
+++ b/phosphor-regulators/test/config_file_parser_tests.cpp
@@ -27,6 +27,7 @@
#include "i2c_write_bit_action.hpp"
#include "i2c_write_byte_action.hpp"
#include "i2c_write_bytes_action.hpp"
+#include "not_action.hpp"
#include "pmbus_utils.hpp"
#include "pmbus_write_vout_command_action.hpp"
#include "presence_detection.hpp"
@@ -350,7 +351,16 @@
// TODO: Not implemented yet
// Test where works: not action type specified
- // TODO: Not implemented yet
+ {
+ const json element = R"(
+ {
+ "not":
+ { "i2c_compare_byte": { "register": "0xA0", "value": "0xFF" } }
+ }
+ )"_json;
+ std::unique_ptr<Action> action = parseAction(element);
+ EXPECT_NE(action.get(), nullptr);
+ }
// Test where works: or action type specified
// TODO: Not implemented yet
@@ -2547,6 +2557,30 @@
}
}
+TEST(ConfigFileParserTests, ParseNot)
+{
+ // Test where works
+ {
+ const json element = R"(
+ { "i2c_compare_byte": { "register": "0xA0", "value": "0x00" } }
+ )"_json;
+ std::unique_ptr<NotAction> action = parseNot(element);
+ EXPECT_NE(action->getAction().get(), nullptr);
+ }
+
+ // Test where fails: Element is not an object
+ try
+ {
+ const json element = R"( [ "0xFF", "0x01" ] )"_json;
+ parseNot(element);
+ ADD_FAILURE() << "Should not have reached this line.";
+ }
+ catch (const std::invalid_argument& e)
+ {
+ EXPECT_STREQ(e.what(), "Element is not an object");
+ }
+}
+
TEST(ConfigFileParserTests, ParsePMBusWriteVoutCommand)
{
// Test where works: Only required properties specified