regulators: Add test cases for object 'i2c_compare_byte'.

*Valid: test i2c_compare_byte with all properties
*Valid: test i2c_compare_byte with all required properties
*Invalid: test i2c_compare_byte with no register
*Invalid: test i2c_compare_byte with no value
*Invalid: test i2c_compare_byte with property register wrong type
*Invalid: test i2c_compare_byte with property value wrong type
*Invalid: test i2c_compare_byte with property mask wrong type
*Invalid: test i2c_compare_byte with property register more than 2 hex digits.
*Invalid: test i2c_compare_byte with property value more than 2 hex digits.
*Invalid: test i2c_compare_byte with property mask more than 2 hex digits.
*Invalid: test i2c_compare_byte with property register less than 2 hex digits.
*Invalid: test i2c_compare_byte with property value less than 2 hex digits.
*Invalid: test i2c_compare_byte with property mask less than 2 hex digits.
*Invalid: test i2c_compare_byte with property register no leading prefix.
*Invalid: test i2c_compare_byte with property value no leading prefix.
*Invalid: test i2c_compare_byte with property mask no leading prefix.
*Invalid: test i2c_compare_byte with property register invalid hex digit.
*Invalid: test i2c_compare_byte with property value invalid hex digit.
*Invalid: test i2c_compare_byte with property mask invalid hex digit.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: If3c5b656298022d0cdc8046a2846fd1b7eeb8eff
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index c399a53..65b71a3 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -570,3 +570,160 @@
                             "-1 is less than the minimum of 0");
     }
 }
+TEST(ValidateRegulatorsConfigTest, I2CCompareByte)
+{
+    json i2cCompareByteFile = validConfigFile;
+    i2cCompareByteFile["rules"][0]["actions"][1]["i2c_compare_byte"]
+                      ["register"] = "0x82";
+    i2cCompareByteFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] =
+        "0x40";
+    i2cCompareByteFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] =
+        "0x7F";
+    // Valid: test i2c_compare_byte with all properties.
+    {
+        json configFile = i2cCompareByteFile;
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Valid: test i2c_compare_byte with all required properties.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"].erase("mask");
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Invalid: test i2c_compare_byte with no register.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"].erase(
+            "register");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'register' is a required property");
+    }
+    // Invalid: test i2c_compare_byte with no value.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"].erase("value");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'value' is a required property");
+    }
+    // Invalid: test i2c_compare_byte with property register wrong type.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["register"] =
+            1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'string'");
+    }
+    // Invalid: test i2c_compare_byte with property value wrong type.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'string'");
+    }
+    // Invalid: test i2c_compare_byte with property mask wrong type.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'string'");
+    }
+    // Invalid: test i2c_compare_byte with property register more than 2 hex
+    // digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["register"] =
+            "0x820";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x820' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property value more than 2 hex
+    // digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] =
+            "0x820";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x820' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property mask more than 2 hex digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] =
+            "0x820";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x820' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property register less than 2 hex
+    // digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["register"] =
+            "0x8";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x8' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property value less than 2 hex
+    // digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] =
+            "0x8";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x8' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property mask less than 2 hex digits.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] =
+            "0x8";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0x8' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property register no leading prefix.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["register"] =
+            "82";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'82' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property value no leading prefix.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] =
+            "82";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'82' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property mask no leading prefix.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] = "82";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'82' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property register invalid hex digit.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["register"] =
+            "0xG1";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0xG1' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property value invalid hex digit.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["value"] =
+            "0xG1";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0xG1' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+    // Invalid: test i2c_compare_byte with property mask invalid hex digit.
+    {
+        json configFile = i2cCompareByteFile;
+        configFile["rules"][0]["actions"][1]["i2c_compare_byte"]["mask"] =
+            "0xG1";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'0xG1' does not match u'^0x[0-9A-Fa-f]{2}$'");
+    }
+}