regulators: Add test cases for object 'device'.

*Valid: test device.
*Valid: test device with required properties.
*Invalid: test device with no id.
*Invalid: test device with no is_regulator.
*Invalid: test device with no fru.
*Invalid: test device with no i2c_interface.
*Invalid: test device with property comments wrong type.
*Invalid: test device with property id wrong type.
*Invalid: test device with property is_regulator wrong type.
*Invalid: test device with property fru wrong type.
*Invalid: test device with property i2c_interface wrong type.
*Invalid: test device with property presence_detection wrong type.
*Invalid: test device with property configuration wrong type.
*Invalid: test device with property rails wrong type.
*Invalid: test device with property comments empty array.
*Invalid: test device with property fru length less than 1.
*Invalid: test device with property id wrong format.
*Invalid: test device with property rails empty array.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: I4b7c7b6af43bf57d13ed8b420b780cbac8308332
diff --git a/phosphor-regulators/test/validate-regulators-config_tests.cpp b/phosphor-regulators/test/validate-regulators-config_tests.cpp
index 7eff938..1edb29b 100644
--- a/phosphor-regulators/test/validate-regulators-config_tests.cpp
+++ b/phosphor-regulators/test/validate-regulators-config_tests.cpp
@@ -538,6 +538,137 @@
                             "1 is not of type u'string'");
     }
 }
+TEST(ValidateRegulatorsConfigTest, Device)
+{
+
+    // Valid: test devices.
+    {
+        json configFile = validConfigFile;
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Valid: test devices with required properties.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0].erase("comments");
+        configFile["chassis"][0]["devices"][0].erase("presence_detection");
+        configFile["chassis"][0]["devices"][0].erase("configuration");
+        configFile["chassis"][0]["devices"][0].erase("rails");
+        EXPECT_JSON_VALID(configFile);
+    }
+    // Invalid: test devices with no id.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0].erase("id");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'id' is a required property");
+    }
+    // Invalid: test devices with no is_regulator.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0].erase("is_regulator");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'is_regulator' is a required property");
+    }
+    // Invalid: test devices with no fru.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0].erase("fru");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'fru' is a required property");
+    }
+    // Invalid: test devices with no i2c_interface.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0].erase("i2c_interface");
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'i2c_interface' is a required property");
+    }
+    // Invalid: test devices with property comments wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["comments"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'array'");
+    }
+    // Invalid: test devices with property id wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["id"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'string'");
+    }
+    // Invalid: test devices with property is_regulator wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["is_regulator"] = 1;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "1 is not of type u'boolean'");
+    }
+    // Invalid: test devices with property fru wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["fru"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'string'");
+    }
+    // Invalid: test devices with property i2c_interface wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["i2c_interface"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'object'");
+    }
+    // Invalid: test devices with property presence_detection wrong
+    // type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["presence_detection"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'object'");
+    }
+    // Invalid: test devices with property configuration wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["configuration"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'object'");
+    }
+    // Invalid: test devices with property rails wrong type.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["rails"] = true;
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "True is not of type u'array'");
+    }
+    // Invalid: test devices with property comments empty array.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["comments"] = json::array();
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "[] is too short");
+    }
+    // Invalid: test devices with property fru length less than 1.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["fru"] = "";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'' is too short");
+    }
+    // Invalid: test devices with property id wrong format.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["id"] = "id#";
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "u'id#' does not match u'^[A-Za-z0-9_]+$'");
+    }
+    // Invalid: test devices with property rails empty array.
+    {
+        json configFile = validConfigFile;
+        configFile["chassis"][0]["devices"][0]["rails"] = json::array();
+        EXPECT_JSON_INVALID(configFile, "Validation failed.",
+                            "[] is too short");
+    }
+}
 TEST(ValidateRegulatorsConfigTest, I2CCompareBit)
 {
     json i2cCompareBitFile = validConfigFile;