regulators: Add test cases for object 'if'.

Test cases for object 'if' are:
*Valid: test if.
*Valid: test if with required properties.
*Invalid: test if with no property condition.
*Invalid: test if with no property then.
*Invalid: test if with property then empty array.
*Invalid: test if with property else empty array.
*Invalid: test if with property condition wrong type.
*Invalid: test if with property then wrong type.
*Invalid: test if with property else wrong type.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I46808c6a1ad67e393b16c846251770e9793718b7
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index 91fec24..259ba37 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -905,3 +905,73 @@
                             "u'0xG1' does not match u'^0x[0-9A-Fa-f]{2}$'");
     }
 }
+TEST(ValidateRegulatorsConfigTest, If)
+{
+    json ifFile = validConfigFile;
+    ifFile["rules"][0]["actions"][1]["if"]["condition"]["run_rule"] =
+        "is_downlevel_regulator";
+    ifFile["rules"][0]["actions"][1]["if"]["then"][0]["run_rule"] =
+        "configure_downlevel_regulator";
+    ifFile["rules"][0]["actions"][1]["if"]["else"][0]["run_rule"] =
+        "configure_downlevel_regulator";
+    // Valid: test if.
+    {
+        json configFile = ifFile;
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Valid: test if with required properties.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"].erase("else");
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Invalid: test if with no property condition.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"].erase("condition");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'condition' is a required property");
+    }
+    // Invalid: test if with no property then.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"].erase("then");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'then' is a required property");
+    }
+    // Invalid: test if with property then empty array.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"]["then"] = json::array();
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "[] is too short");
+    }
+    // Invalid: test if with property else empty array.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"]["else"] = json::array();
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "[] is too short");
+    }
+    // Invalid: test if with property condition wrong type.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"]["condition"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'object'");
+    }
+    // Invalid: test if with property then wrong type.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"]["then"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'array'");
+    }
+    // Invalid: test if with property else wrong type.
+    {
+        json configFile = ifFile;
+        configFile["rules"][0]["actions"][1]["if"]["else"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'array'");
+    }
+}