| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "tools/json_schema_compiler/test/test_util.h" | 11 #include "tools/json_schema_compiler/test/test_util.h" |
| 11 | 12 |
| 12 using namespace test::api::error_generation; | 13 using namespace test::api::error_generation; |
| 13 using base::FundamentalValue; | 14 using base::FundamentalValue; |
| 14 using json_schema_compiler::test_util::Dictionary; | 15 using json_schema_compiler::test_util::Dictionary; |
| 15 using json_schema_compiler::test_util::List; | 16 using json_schema_compiler::test_util::List; |
| 16 | 17 |
| 17 template <typename T> | 18 template <typename T> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 32 | 33 |
| 33 // GenerateTypePopulate errors | 34 // GenerateTypePopulate errors |
| 34 | 35 |
| 35 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { | 36 TEST(JsonSchemaCompilerErrorTest, RequiredPropertyPopulate) { |
| 36 { | 37 { |
| 37 std::unique_ptr<base::DictionaryValue> value = | 38 std::unique_ptr<base::DictionaryValue> value = |
| 38 Dictionary("string", new base::StringValue("bling")); | 39 Dictionary("string", new base::StringValue("bling")); |
| 39 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 40 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 40 } | 41 } |
| 41 { | 42 { |
| 42 std::unique_ptr<base::BinaryValue> value(new base::BinaryValue()); | 43 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); |
| 43 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", | 44 EXPECT_TRUE(EqualsUtf16("expected dictionary, got binary", |
| 44 GetPopulateError<TestType>(*value))); | 45 GetPopulateError<TestType>(*value))); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { | 49 TEST(JsonSchemaCompilerErrorTest, UnexpectedTypePopulation) { |
| 49 { | 50 { |
| 50 std::unique_ptr<base::ListValue> value(new base::ListValue()); | 51 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
| 51 EXPECT_TRUE(EqualsUtf16("", | 52 EXPECT_TRUE(EqualsUtf16("", |
| 52 GetPopulateError<ChoiceType::Integers>(*value))); | 53 GetPopulateError<ChoiceType::Integers>(*value))); |
| 53 } | 54 } |
| 54 { | 55 { |
| 55 std::unique_ptr<base::BinaryValue> value(new base::BinaryValue()); | 56 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); |
| 56 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", | 57 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", |
| 57 GetPopulateError<ChoiceType::Integers>(*value))); | 58 GetPopulateError<ChoiceType::Integers>(*value))); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 // GenerateTypePopulateProperty errors | 62 // GenerateTypePopulateProperty errors |
| 62 | 63 |
| 63 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { | 64 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { |
| 64 { | 65 { |
| 65 std::unique_ptr<base::DictionaryValue> value = | 66 std::unique_ptr<base::DictionaryValue> value = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 List(new FundamentalValue(5), new FundamentalValue(false)); | 172 List(new FundamentalValue(5), new FundamentalValue(false)); |
| 172 EXPECT_TRUE(EqualsUtf16( | 173 EXPECT_TRUE(EqualsUtf16( |
| 173 "expected integer, got boolean; unable to populate array 'integers'", | 174 "expected integer, got boolean; unable to populate array 'integers'", |
| 174 GetPopulateError<ChoiceType::Integers>(*params_value))); | 175 GetPopulateError<ChoiceType::Integers>(*params_value))); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { | 179 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { |
| 179 { | 180 { |
| 180 std::unique_ptr<base::DictionaryValue> value = | 181 std::unique_ptr<base::DictionaryValue> value = |
| 181 Dictionary("data", new base::BinaryValue()); | 182 Dictionary("data", new base::Value(base::Value::Type::BINARY)); |
| 182 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); | 183 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); |
| 183 } | 184 } |
| 184 { | 185 { |
| 185 std::unique_ptr<base::DictionaryValue> value = | 186 std::unique_ptr<base::DictionaryValue> value = |
| 186 Dictionary("data", new FundamentalValue(1.1)); | 187 Dictionary("data", new FundamentalValue(1.1)); |
| 187 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double", | 188 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double", |
| 188 GetPopulateError<BinaryData>(*value))); | 189 GetPopulateError<BinaryData>(*value))); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); | 238 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); |
| 238 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", | 239 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", |
| 239 error)); | 240 error)); |
| 240 EXPECT_EQ(NULL, out.string.get()); | 241 EXPECT_EQ(NULL, out.string.get()); |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 | 244 |
| 244 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { | 245 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { |
| 245 { | 246 { |
| 246 std::unique_ptr<base::DictionaryValue> value = | 247 std::unique_ptr<base::DictionaryValue> value = |
| 247 Dictionary("data", new base::BinaryValue()); | 248 Dictionary("data", new base::Value(base::Value::Type::BINARY)); |
| 248 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); | 249 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); |
| 249 } | 250 } |
| 250 { | 251 { |
| 251 // There's a bug with silent failures if the key doesn't exist. | 252 // There's a bug with silent failures if the key doesn't exist. |
| 252 std::unique_ptr<base::DictionaryValue> value = | 253 std::unique_ptr<base::DictionaryValue> value = |
| 253 Dictionary("data", new base::FundamentalValue(1)); | 254 Dictionary("data", new base::FundamentalValue(1)); |
| 254 | 255 |
| 255 OptionalBinaryData out; | 256 OptionalBinaryData out; |
| 256 base::string16 error; | 257 base::string16 error; |
| 257 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); | 258 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 327 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 327 } | 328 } |
| 328 { | 329 { |
| 329 std::unique_ptr<base::DictionaryValue> value = | 330 std::unique_ptr<base::DictionaryValue> value = |
| 330 Dictionary("string", new base::StringValue("yes"), "ohno", | 331 Dictionary("string", new base::StringValue("yes"), "ohno", |
| 331 new base::StringValue("many values")); | 332 new base::StringValue("many values")); |
| 332 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", | 333 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", |
| 333 GetPopulateError<TestType>(*value))); | 334 GetPopulateError<TestType>(*value))); |
| 334 } | 335 } |
| 335 } | 336 } |
| OLD | NEW |