| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "tools/json_schema_compiler/test/error_generation.h" | 5 #include "tools/json_schema_compiler/test/error_generation.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 return testing::AssertionSuccess(); | 29 return testing::AssertionSuccess(); |
| 30 return testing::AssertionFailure() << "\n actual: " << actual | 30 return testing::AssertionFailure() << "\n actual: " << actual |
| 31 << "\n expected: " << expected; | 31 << "\n expected: " << expected; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // GenerateTypePopulate errors | 34 // GenerateTypePopulate errors |
| 35 | 35 |
| 36 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { | 36 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { |
| 37 { | 37 { |
| 38 std::unique_ptr<base::DictionaryValue> value = | 38 std::unique_ptr<base::DictionaryValue> value = |
| 39 Dictionary("string", new base::StringValue("bling")); | 39 Dictionary("string", new base::Value("bling")); |
| 40 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 40 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 41 } | 41 } |
| 42 { | 42 { |
| 43 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); | 43 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); |
| 44 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", | 44 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", |
| 45 GetPopulateError<TestType>(*value))); | 45 GetPopulateError<TestType>(*value))); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { | 49 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); | 106 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); |
| 107 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); | 107 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 // GeneratePopulateVariableFromValue errors | 111 // GeneratePopulateVariableFromValue errors |
| 112 | 112 |
| 113 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { | 113 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { |
| 114 { | 114 { |
| 115 std::unique_ptr<base::DictionaryValue> value = | 115 std::unique_ptr<base::DictionaryValue> value = |
| 116 Dictionary("string", new base::StringValue("yes")); | 116 Dictionary("string", new base::Value("yes")); |
| 117 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 117 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 118 } | 118 } |
| 119 { | 119 { |
| 120 std::unique_ptr<base::DictionaryValue> value = | 120 std::unique_ptr<base::DictionaryValue> value = |
| 121 Dictionary("string", new Value(1.1)); | 121 Dictionary("string", new Value(1.1)); |
| 122 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double", | 122 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double", |
| 123 GetPopulateError<TestType>(*value))); | 123 GetPopulateError<TestType>(*value))); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { | 127 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { |
| 128 { | 128 { |
| 129 base::string16 error; | 129 base::string16 error; |
| 130 std::unique_ptr<base::ListValue> params_value = | 130 std::unique_ptr<base::ListValue> params_value = |
| 131 List(new base::StringValue("Yeah!")); | 131 List(new base::Value("Yeah!")); |
| 132 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); | 132 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); |
| 133 } | 133 } |
| 134 { | 134 { |
| 135 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 135 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); |
| 136 base::string16 error; | 136 base::string16 error; |
| 137 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); | 137 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); |
| 138 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", | 138 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", |
| 139 error)); | 139 error)); |
| 140 } | 140 } |
| 141 } | 141 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 198 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
| 199 GetPopulateError<ArrayObject>(*value))); | 199 GetPopulateError<ArrayObject>(*value))); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 // GenerateStringToEnumConversion errors | 203 // GenerateStringToEnumConversion errors |
| 204 | 204 |
| 205 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { | 205 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { |
| 206 { | 206 { |
| 207 std::unique_ptr<base::DictionaryValue> value = | 207 std::unique_ptr<base::DictionaryValue> value = |
| 208 Dictionary("enumeration", new base::StringValue("one")); | 208 Dictionary("enumeration", new base::Value("one")); |
| 209 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); | 209 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); |
| 210 } | 210 } |
| 211 { | 211 { |
| 212 std::unique_ptr<base::DictionaryValue> value = | 212 std::unique_ptr<base::DictionaryValue> value = |
| 213 Dictionary("enumeration", new base::StringValue("bad sauce")); | 213 Dictionary("enumeration", new base::Value("bad sauce")); |
| 214 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " | 214 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " |
| 215 "or \"three\", got \"bad sauce\"", | 215 "or \"three\", got \"bad sauce\"", |
| 216 GetPopulateError<HasEnumeration>(*value))); | 216 GetPopulateError<HasEnumeration>(*value))); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Warn but don't fail out errors | 220 // Warn but don't fail out errors |
| 221 | 221 |
| 222 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { | 222 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { |
| 223 { | 223 { |
| 224 std::unique_ptr<base::DictionaryValue> value = | 224 std::unique_ptr<base::DictionaryValue> value = |
| 225 Dictionary("string", new base::StringValue("bling")); | 225 Dictionary("string", new base::Value("bling")); |
| 226 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); | 226 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); |
| 227 } | 227 } |
| 228 { | 228 { |
| 229 std::unique_ptr<base::DictionaryValue> value = | 229 std::unique_ptr<base::DictionaryValue> value = |
| 230 Dictionary("string", new base::Value(1)); | 230 Dictionary("string", new base::Value(1)); |
| 231 | 231 |
| 232 OptionalTestType out; | 232 OptionalTestType out; |
| 233 base::string16 error; | 233 base::string16 error; |
| 234 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); | 234 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); |
| 235 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", | 235 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " | 311 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " |
| 312 "'TheArray': expected list, got integer", | 312 "'TheArray': expected list, got integer", |
| 313 error)); | 313 error)); |
| 314 EXPECT_EQ(NULL, out.the_array.get()); | 314 EXPECT_EQ(NULL, out.the_array.get()); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { | 318 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { |
| 319 { | 319 { |
| 320 std::unique_ptr<base::DictionaryValue> value = | 320 std::unique_ptr<base::DictionaryValue> value = |
| 321 Dictionary("string", new base::StringValue("yes")); | 321 Dictionary("string", new base::Value("yes")); |
| 322 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 322 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 323 } | 323 } |
| 324 { | 324 { |
| 325 std::unique_ptr<base::DictionaryValue> value = | 325 std::unique_ptr<base::DictionaryValue> value = |
| 326 Dictionary("string", new base::StringValue("yes"), "ohno", | 326 Dictionary("string", new base::Value("yes"), "ohno", |
| 327 new base::StringValue("many values")); | 327 new base::Value("many values")); |
| 328 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", | 328 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", |
| 329 GetPopulateError<TestType>(*value))); | 329 GetPopulateError<TestType>(*value))); |
| 330 } | 330 } |
| 331 } | 331 } |
| OLD | NEW |