From 884e897941a600c11b7fcfa3d8cf59ce15eb3571 Mon Sep 17 00:00:00 2001 From: Jacob Keeler Date: Thu, 4 May 2017 12:18:40 -0400 Subject: Invalid data responses now return useful error messages in `info` field --- .../smart_objects/test/BoolSchemaItem_test.cc | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/components/smart_objects/test/BoolSchemaItem_test.cc') diff --git a/src/components/smart_objects/test/BoolSchemaItem_test.cc b/src/components/smart_objects/test/BoolSchemaItem_test.cc index 8e39af8e08..dd6939443c 100644 --- a/src/components/smart_objects/test/BoolSchemaItem_test.cc +++ b/src/components/smart_objects/test/BoolSchemaItem_test.cc @@ -63,14 +63,15 @@ TEST(test_no_default_value, test_BoolSchemaItemTest) { obj = 5; ASSERT_EQ(5, obj.asInt()); - int resultType = item->validate(obj); + std::string errorMessage; + int resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = true; ASSERT_TRUE(obj.asBool()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); bool resDefault = item->setDefaultValue(obj); EXPECT_FALSE(resDefault); @@ -79,12 +80,12 @@ TEST(test_no_default_value, test_BoolSchemaItemTest) { obj = "Test"; ASSERT_EQ(std::string("Test"), obj.asString()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); resDefault = item->setDefaultValue(obj); EXPECT_FALSE(resDefault); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); } @@ -109,14 +110,15 @@ TEST(test_item_with_default_value, test_BoolSchemaItemTest) { obj = 5; ASSERT_EQ(5, obj.asInt()); - int resultType = item->validate(obj); + std::string errorMessage; + int resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = true; ASSERT_TRUE(obj.asBool()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); bool resDefault = item->setDefaultValue(obj); EXPECT_TRUE(resDefault); @@ -125,14 +127,14 @@ TEST(test_item_with_default_value, test_BoolSchemaItemTest) { obj = "Test"; ASSERT_EQ(std::string("Test"), obj.asString()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); resDefault = item->setDefaultValue(obj); EXPECT_TRUE(resDefault); EXPECT_FALSE(obj.asBool()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); EXPECT_FALSE(obj.asBool()); } @@ -147,10 +149,11 @@ TEST(test_map_validate, test_BoolSchemaItemTest) { obj["aa"] = true; ASSERT_TRUE(obj["aa"].asBool()); - int resultType = item->validate(obj["aa"]); + std::string errorMessage; + int resultType = item->validate(obj["aa"], errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); @@ -162,11 +165,11 @@ TEST(test_map_validate, test_BoolSchemaItemTest) { EXPECT_TRUE(resDefault); EXPECT_FALSE(obj.asBool()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); obj["ind"] = true; - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); } @@ -182,13 +185,14 @@ TEST(test_array_validate, test_BoolSchemaItemTest) { ASSERT_TRUE(obj[0].asBool()); ASSERT_FALSE(obj[1].asBool()); - int resultType = item->validate(obj[0]); + std::string errorMessage; + int resultType = item->validate(obj[0], errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj[1]); + resultType = item->validate(obj[1], errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); @@ -200,13 +204,13 @@ TEST(test_array_validate, test_BoolSchemaItemTest) { EXPECT_FALSE(resDefault); EXPECT_FALSE(obj[1].asBool()); - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = false; - resultType = item->validate(obj); + resultType = item->validate(obj, errorMessage); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); } -- cgit v1.2.1 From 273e26304efb215af3416f86ab86c1c7fd39f974 Mon Sep 17 00:00:00 2001 From: jacobkeeler Date: Thu, 30 Nov 2017 15:19:11 -0500 Subject: Use ValidationReport objects for reporting rather than strings --- .../smart_objects/test/BoolSchemaItem_test.cc | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/components/smart_objects/test/BoolSchemaItem_test.cc') diff --git a/src/components/smart_objects/test/BoolSchemaItem_test.cc b/src/components/smart_objects/test/BoolSchemaItem_test.cc index dd6939443c..8d67aa59b2 100644 --- a/src/components/smart_objects/test/BoolSchemaItem_test.cc +++ b/src/components/smart_objects/test/BoolSchemaItem_test.cc @@ -63,15 +63,15 @@ TEST(test_no_default_value, test_BoolSchemaItemTest) { obj = 5; ASSERT_EQ(5, obj.asInt()); - std::string errorMessage; - int resultType = item->validate(obj, errorMessage); + rpc::ValidationReport report("RPC"); + int resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = true; ASSERT_TRUE(obj.asBool()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); bool resDefault = item->setDefaultValue(obj); EXPECT_FALSE(resDefault); @@ -80,12 +80,12 @@ TEST(test_no_default_value, test_BoolSchemaItemTest) { obj = "Test"; ASSERT_EQ(std::string("Test"), obj.asString()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); resDefault = item->setDefaultValue(obj); EXPECT_FALSE(resDefault); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); } @@ -110,15 +110,15 @@ TEST(test_item_with_default_value, test_BoolSchemaItemTest) { obj = 5; ASSERT_EQ(5, obj.asInt()); - std::string errorMessage; - int resultType = item->validate(obj, errorMessage); + rpc::ValidationReport report("RPC"); + int resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = true; ASSERT_TRUE(obj.asBool()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); bool resDefault = item->setDefaultValue(obj); EXPECT_TRUE(resDefault); @@ -127,14 +127,14 @@ TEST(test_item_with_default_value, test_BoolSchemaItemTest) { obj = "Test"; ASSERT_EQ(std::string("Test"), obj.asString()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); resDefault = item->setDefaultValue(obj); EXPECT_TRUE(resDefault); EXPECT_FALSE(obj.asBool()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); EXPECT_FALSE(obj.asBool()); } @@ -149,11 +149,11 @@ TEST(test_map_validate, test_BoolSchemaItemTest) { obj["aa"] = true; ASSERT_TRUE(obj["aa"].asBool()); - std::string errorMessage; - int resultType = item->validate(obj["aa"], errorMessage); + rpc::ValidationReport report("RPC"); + int resultType = item->validate(obj["aa"], &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); @@ -165,11 +165,11 @@ TEST(test_map_validate, test_BoolSchemaItemTest) { EXPECT_TRUE(resDefault); EXPECT_FALSE(obj.asBool()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); obj["ind"] = true; - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); } @@ -185,14 +185,14 @@ TEST(test_array_validate, test_BoolSchemaItemTest) { ASSERT_TRUE(obj[0].asBool()); ASSERT_FALSE(obj[1].asBool()); - std::string errorMessage; - int resultType = item->validate(obj[0], errorMessage); + rpc::ValidationReport report("RPC"); + int resultType = item->validate(obj[0], &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj[1], errorMessage); + resultType = item->validate(obj[1], &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); @@ -204,13 +204,13 @@ TEST(test_array_validate, test_BoolSchemaItemTest) { EXPECT_FALSE(resDefault); EXPECT_FALSE(obj[1].asBool()); - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::INVALID_VALUE, resultType); obj = false; - resultType = item->validate(obj, errorMessage); + resultType = item->validate(obj, &report); EXPECT_EQ(NsSmartDeviceLink::NsSmartObjects::Errors::OK, resultType); } -- cgit v1.2.1