| 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::Value("bling")); | 39 Dictionary("string", base::MakeUnique<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) { |
| 50 { | 50 { |
| 51 std::unique_ptr<base::ListValue> value(new base::ListValue()); | 51 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
| 52 EXPECT_TRUE(EqualsUtf16("", | 52 EXPECT_TRUE(EqualsUtf16("", |
| 53 GetPopulateError<ChoiceType::Integers>(*value))); | 53 GetPopulateError<ChoiceType::Integers>(*value))); |
| 54 } | 54 } |
| 55 { | 55 { |
| 56 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); | 56 auto value = base::MakeUnique<base::Value>(base::Value::Type::BINARY); |
| 57 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", | 57 EXPECT_TRUE(EqualsUtf16("expected integers or integer, got binary", |
| 58 GetPopulateError<ChoiceType::Integers>(*value))); | 58 GetPopulateError<ChoiceType::Integers>(*value))); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // GenerateTypePopulateProperty errors | 62 // GenerateTypePopulateProperty errors |
| 63 | 63 |
| 64 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { | 64 TEST(JsonSchemaCompilerErrorTest, TypeIsRequired) { |
| 65 { | 65 { |
| 66 std::unique_ptr<base::DictionaryValue> value = | 66 std::unique_ptr<base::DictionaryValue> value = |
| 67 Dictionary("integers", new Value(5)); | 67 Dictionary("integers", base::MakeUnique<Value>(5)); |
| 68 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); | 68 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ChoiceType>(*value))); |
| 69 } | 69 } |
| 70 { | 70 { |
| 71 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 71 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 72 EXPECT_TRUE(EqualsUtf16("'integers' is required", | 72 EXPECT_TRUE(EqualsUtf16("'integers' is required", |
| 73 GetPopulateError<ChoiceType>(*value))); | 73 GetPopulateError<ChoiceType>(*value))); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 // GenerateParamsCheck errors | 77 // GenerateParamsCheck errors |
| 78 | 78 |
| 79 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) { | 79 TEST(JsonSchemaCompilerErrorTest, TooManyParameters) { |
| 80 { | 80 { |
| 81 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 81 std::unique_ptr<base::ListValue> params_value = |
| 82 List(base::MakeUnique<Value>(5)); |
| 82 base::string16 error; | 83 base::string16 error; |
| 83 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); | 84 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); |
| 84 } | 85 } |
| 85 { | 86 { |
| 86 std::unique_ptr<base::ListValue> params_value = | 87 std::unique_ptr<base::ListValue> params_value = |
| 87 List(new Value(5), new Value(5)); | 88 List(base::MakeUnique<Value>(5), base::MakeUnique<Value>(5)); |
| 88 base::string16 error; | 89 base::string16 error; |
| 89 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); | 90 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); |
| 90 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error)); | 91 EXPECT_TRUE(EqualsUtf16("expected 1 arguments, got 2", error)); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 // GenerateFunctionParamsCreate errors | 95 // GenerateFunctionParamsCreate errors |
| 95 | 96 |
| 96 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { | 97 TEST(JsonSchemaCompilerErrorTest, ParamIsRequired) { |
| 97 { | 98 { |
| 98 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 99 std::unique_ptr<base::ListValue> params_value = |
| 100 List(base::MakeUnique<Value>(5)); |
| 99 base::string16 error; | 101 base::string16 error; |
| 100 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); | 102 EXPECT_TRUE(TestFunction::Params::Create(*params_value, &error)); |
| 101 } | 103 } |
| 102 { | 104 { |
| 103 std::unique_ptr<base::ListValue> params_value = List(new Value()); | 105 std::unique_ptr<base::ListValue> params_value = |
| 106 List(base::MakeUnique<Value>()); |
| 104 base::string16 error; | 107 base::string16 error; |
| 105 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); | 108 EXPECT_FALSE(TestFunction::Params::Create(*params_value, &error)); |
| 106 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); | 109 EXPECT_TRUE(EqualsUtf16("'num' is required", error)); |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 | 112 |
| 110 // GeneratePopulateVariableFromValue errors | 113 // GeneratePopulateVariableFromValue errors |
| 111 | 114 |
| 112 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { | 115 TEST(JsonSchemaCompilerErrorTest, WrongPropertyValueType) { |
| 113 { | 116 { |
| 114 std::unique_ptr<base::DictionaryValue> value = | 117 std::unique_ptr<base::DictionaryValue> value = |
| 115 Dictionary("string", new base::Value("yes")); | 118 Dictionary("string", base::MakeUnique<base::Value>("yes")); |
| 116 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 119 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 117 } | 120 } |
| 118 { | 121 { |
| 119 std::unique_ptr<base::DictionaryValue> value = | 122 std::unique_ptr<base::DictionaryValue> value = |
| 120 Dictionary("string", new Value(1.1)); | 123 Dictionary("string", base::MakeUnique<Value>(1.1)); |
| 121 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double", | 124 EXPECT_TRUE(EqualsUtf16("'string': expected string, got double", |
| 122 GetPopulateError<TestType>(*value))); | 125 GetPopulateError<TestType>(*value))); |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 | 128 |
| 126 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { | 129 TEST(JsonSchemaCompilerErrorTest, WrongParameterCreationType) { |
| 127 { | 130 { |
| 128 base::string16 error; | 131 base::string16 error; |
| 129 std::unique_ptr<base::ListValue> params_value = | 132 std::unique_ptr<base::ListValue> params_value = |
| 130 List(new base::Value("Yeah!")); | 133 List(base::MakeUnique<base::Value>("Yeah!")); |
| 131 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); | 134 EXPECT_TRUE(TestString::Params::Create(*params_value, &error)); |
| 132 } | 135 } |
| 133 { | 136 { |
| 134 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 137 std::unique_ptr<base::ListValue> params_value = |
| 138 List(base::MakeUnique<Value>(5)); |
| 135 base::string16 error; | 139 base::string16 error; |
| 136 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); | 140 EXPECT_FALSE(TestTypeInObject::Params::Create(*params_value, &error)); |
| 137 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", | 141 EXPECT_TRUE(EqualsUtf16("'paramObject': expected dictionary, got integer", |
| 138 error)); | 142 error)); |
| 139 } | 143 } |
| 140 } | 144 } |
| 141 | 145 |
| 142 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { | 146 TEST(JsonSchemaCompilerErrorTest, WrongTypeValueType) { |
| 143 { | 147 { |
| 144 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 148 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 145 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); | 149 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ObjectType>(*value))); |
| 146 } | 150 } |
| 147 { | 151 { |
| 148 std::unique_ptr<base::DictionaryValue> value = | 152 std::unique_ptr<base::DictionaryValue> value = |
| 149 Dictionary("otherType", new Value(1.1)); | 153 Dictionary("otherType", base::MakeUnique<Value>(1.1)); |
| 150 ObjectType out; | 154 ObjectType out; |
| 151 base::string16 error; | 155 base::string16 error; |
| 152 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); | 156 EXPECT_TRUE(ObjectType::Populate(*value, &out, &error)); |
| 153 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double", | 157 EXPECT_TRUE(EqualsUtf16("'otherType': expected dictionary, got double", |
| 154 error)); | 158 error)); |
| 155 EXPECT_EQ(NULL, out.other_type.get()); | 159 EXPECT_EQ(NULL, out.other_type.get()); |
| 156 } | 160 } |
| 157 } | 161 } |
| 158 | 162 |
| 159 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { | 163 TEST(JsonSchemaCompilerErrorTest, UnableToPopulateArray) { |
| 160 { | 164 { |
| 161 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 165 std::unique_ptr<base::ListValue> params_value = |
| 166 List(base::MakeUnique<Value>(5)); |
| 162 EXPECT_TRUE(EqualsUtf16("", | 167 EXPECT_TRUE(EqualsUtf16("", |
| 163 GetPopulateError<ChoiceType::Integers>(*params_value))); | 168 GetPopulateError<ChoiceType::Integers>(*params_value))); |
| 164 } | 169 } |
| 165 { | 170 { |
| 166 std::unique_ptr<base::ListValue> params_value = | 171 std::unique_ptr<base::ListValue> params_value = |
| 167 List(new Value(5), new Value(false)); | 172 List(base::MakeUnique<Value>(5), base::MakeUnique<Value>(false)); |
| 168 EXPECT_TRUE(EqualsUtf16( | 173 EXPECT_TRUE(EqualsUtf16( |
| 169 "expected integer, got boolean; unable to populate array 'integers'", | 174 "expected integer, got boolean; unable to populate array 'integers'", |
| 170 GetPopulateError<ChoiceType::Integers>(*params_value))); | 175 GetPopulateError<ChoiceType::Integers>(*params_value))); |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 | 178 |
| 174 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { | 179 TEST(JsonSchemaCompilerErrorTest, BinaryTypeExpected) { |
| 175 { | 180 { |
| 176 std::unique_ptr<base::DictionaryValue> value = | 181 std::unique_ptr<base::DictionaryValue> value = Dictionary( |
| 177 Dictionary("data", new base::Value(base::Value::Type::BINARY)); | 182 "data", base::MakeUnique<base::Value>(base::Value::Type::BINARY)); |
| 178 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); | 183 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<BinaryData>(*value))); |
| 179 } | 184 } |
| 180 { | 185 { |
| 181 std::unique_ptr<base::DictionaryValue> value = | 186 std::unique_ptr<base::DictionaryValue> value = |
| 182 Dictionary("data", new Value(1.1)); | 187 Dictionary("data", base::MakeUnique<Value>(1.1)); |
| 183 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double", | 188 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got double", |
| 184 GetPopulateError<BinaryData>(*value))); | 189 GetPopulateError<BinaryData>(*value))); |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 TEST(JsonSchemaCompilerErrorTest, ListExpected) { | 193 TEST(JsonSchemaCompilerErrorTest, ListExpected) { |
| 189 { | 194 { |
| 190 std::unique_ptr<base::DictionaryValue> value = | 195 std::unique_ptr<base::DictionaryValue> value = |
| 191 Dictionary("TheArray", new base::ListValue()); | 196 Dictionary("TheArray", base::MakeUnique<base::ListValue>()); |
| 192 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); | 197 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); |
| 193 } | 198 } |
| 194 { | 199 { |
| 195 std::unique_ptr<base::DictionaryValue> value = | 200 std::unique_ptr<base::DictionaryValue> value = |
| 196 Dictionary("TheArray", new Value(5)); | 201 Dictionary("TheArray", base::MakeUnique<Value>(5)); |
| 197 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 202 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
| 198 GetPopulateError<ArrayObject>(*value))); | 203 GetPopulateError<ArrayObject>(*value))); |
| 199 } | 204 } |
| 200 } | 205 } |
| 201 | 206 |
| 202 // GenerateStringToEnumConversion errors | 207 // GenerateStringToEnumConversion errors |
| 203 | 208 |
| 204 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { | 209 TEST(JsonSchemaCompilerErrorTest, BadEnumValue) { |
| 205 { | 210 { |
| 206 std::unique_ptr<base::DictionaryValue> value = | 211 std::unique_ptr<base::DictionaryValue> value = |
| 207 Dictionary("enumeration", new base::Value("one")); | 212 Dictionary("enumeration", base::MakeUnique<base::Value>("one")); |
| 208 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); | 213 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<HasEnumeration>(*value))); |
| 209 } | 214 } |
| 210 { | 215 { |
| 211 std::unique_ptr<base::DictionaryValue> value = | 216 std::unique_ptr<base::DictionaryValue> value = |
| 212 Dictionary("enumeration", new base::Value("bad sauce")); | 217 Dictionary("enumeration", base::MakeUnique<base::Value>("bad sauce")); |
| 213 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " | 218 EXPECT_TRUE(EqualsUtf16("'Enumeration': expected \"one\" or \"two\" " |
| 214 "or \"three\", got \"bad sauce\"", | 219 "or \"three\", got \"bad sauce\"", |
| 215 GetPopulateError<HasEnumeration>(*value))); | 220 GetPopulateError<HasEnumeration>(*value))); |
| 216 } | 221 } |
| 217 } | 222 } |
| 218 | 223 |
| 219 // Warn but don't fail out errors | 224 // Warn but don't fail out errors |
| 220 | 225 |
| 221 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { | 226 TEST(JsonSchemaCompilerErrorTest, WarnOnOptionalFailure) { |
| 222 { | 227 { |
| 223 std::unique_ptr<base::DictionaryValue> value = | 228 std::unique_ptr<base::DictionaryValue> value = |
| 224 Dictionary("string", new base::Value("bling")); | 229 Dictionary("string", base::MakeUnique<base::Value>("bling")); |
| 225 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); | 230 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalTestType>(*value))); |
| 226 } | 231 } |
| 227 { | 232 { |
| 228 std::unique_ptr<base::DictionaryValue> value = | 233 std::unique_ptr<base::DictionaryValue> value = |
| 229 Dictionary("string", new base::Value(1)); | 234 Dictionary("string", base::MakeUnique<base::Value>(1)); |
| 230 | 235 |
| 231 OptionalTestType out; | 236 OptionalTestType out; |
| 232 base::string16 error; | 237 base::string16 error; |
| 233 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); | 238 EXPECT_TRUE(OptionalTestType::Populate(*value, &out, &error)); |
| 234 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", | 239 EXPECT_TRUE(EqualsUtf16("'string': expected string, got integer", |
| 235 error)); | 240 error)); |
| 236 EXPECT_EQ(NULL, out.string.get()); | 241 EXPECT_EQ(NULL, out.string.get()); |
| 237 } | 242 } |
| 238 } | 243 } |
| 239 | 244 |
| 240 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { | 245 TEST(JsonSchemaCompilerErrorTest, OptionalBinaryTypeFailure) { |
| 241 { | 246 { |
| 242 std::unique_ptr<base::DictionaryValue> value = | 247 std::unique_ptr<base::DictionaryValue> value = Dictionary( |
| 243 Dictionary("data", new base::Value(base::Value::Type::BINARY)); | 248 "data", base::MakeUnique<base::Value>(base::Value::Type::BINARY)); |
| 244 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); | 249 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<OptionalBinaryData>(*value))); |
| 245 } | 250 } |
| 246 { | 251 { |
| 247 // 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. |
| 248 std::unique_ptr<base::DictionaryValue> value = | 253 std::unique_ptr<base::DictionaryValue> value = |
| 249 Dictionary("data", new base::Value(1)); | 254 Dictionary("data", base::MakeUnique<base::Value>(1)); |
| 250 | 255 |
| 251 OptionalBinaryData out; | 256 OptionalBinaryData out; |
| 252 base::string16 error; | 257 base::string16 error; |
| 253 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); | 258 EXPECT_TRUE(OptionalBinaryData::Populate(*value, &out, &error)); |
| 254 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer", | 259 EXPECT_TRUE(EqualsUtf16("'data': expected binary, got integer", |
| 255 error)); | 260 error)); |
| 256 EXPECT_EQ(NULL, out.data.get()); | 261 EXPECT_EQ(NULL, out.data.get()); |
| 257 } | 262 } |
| 258 } | 263 } |
| 259 | 264 |
| 260 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) { | 265 TEST(JsonSchemaCompilerErrorTest, OptionalArrayTypeFailure) { |
| 261 { | 266 { |
| 262 std::unique_ptr<base::DictionaryValue> value = | 267 std::unique_ptr<base::DictionaryValue> value = |
| 263 Dictionary("TheArray", new base::ListValue()); | 268 Dictionary("TheArray", base::MakeUnique<base::ListValue>()); |
| 264 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); | 269 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<ArrayObject>(*value))); |
| 265 } | 270 } |
| 266 { | 271 { |
| 267 std::unique_ptr<base::DictionaryValue> value = | 272 std::unique_ptr<base::DictionaryValue> value = |
| 268 Dictionary("TheArray", new Value(5)); | 273 Dictionary("TheArray", base::MakeUnique<Value>(5)); |
| 269 ArrayObject out; | 274 ArrayObject out; |
| 270 base::string16 error; | 275 base::string16 error; |
| 271 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 276 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
| 272 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 277 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
| 273 error)); | 278 error)); |
| 274 EXPECT_EQ(NULL, out.the_array.get()); | 279 EXPECT_EQ(NULL, out.the_array.get()); |
| 275 } | 280 } |
| 276 } | 281 } |
| 277 | 282 |
| 278 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) { | 283 TEST(JsonSchemaCompilerErrorTest, OptionalUnableToPopulateArray) { |
| 279 { | 284 { |
| 280 std::unique_ptr<base::ListValue> params_value = List(new Value(5)); | 285 std::unique_ptr<base::ListValue> params_value = |
| 286 List(base::MakeUnique<Value>(5)); |
| 281 EXPECT_TRUE(EqualsUtf16("", | 287 EXPECT_TRUE(EqualsUtf16("", |
| 282 GetPopulateError<OptionalChoiceType::Integers>(*params_value))); | 288 GetPopulateError<OptionalChoiceType::Integers>(*params_value))); |
| 283 } | 289 } |
| 284 { | 290 { |
| 285 std::unique_ptr<base::ListValue> params_value = | 291 std::unique_ptr<base::ListValue> params_value = |
| 286 List(new Value(5), new Value(false)); | 292 List(base::MakeUnique<Value>(5), base::MakeUnique<Value>(false)); |
| 287 OptionalChoiceType::Integers out; | 293 OptionalChoiceType::Integers out; |
| 288 base::string16 error; | 294 base::string16 error; |
| 289 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out, | 295 EXPECT_TRUE(OptionalChoiceType::Integers::Populate(*params_value, &out, |
| 290 &error)); | 296 &error)); |
| 291 EXPECT_TRUE(EqualsUtf16( | 297 EXPECT_TRUE(EqualsUtf16( |
| 292 "expected integer, got boolean; unable to populate array 'integers'", | 298 "expected integer, got boolean; unable to populate array 'integers'", |
| 293 error)); | 299 error)); |
| 294 EXPECT_EQ(NULL, out.as_integer.get()); | 300 EXPECT_EQ(NULL, out.as_integer.get()); |
| 295 } | 301 } |
| 296 } | 302 } |
| 297 | 303 |
| 298 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) { | 304 TEST(JsonSchemaCompilerErrorTest, MultiplePopulationErrors) { |
| 299 { | 305 { |
| 300 std::unique_ptr<base::DictionaryValue> value = | 306 std::unique_ptr<base::DictionaryValue> value = |
| 301 Dictionary("TheArray", new Value(5)); | 307 Dictionary("TheArray", base::MakeUnique<Value>(5)); |
| 302 ArrayObject out; | 308 ArrayObject out; |
| 303 base::string16 error; | 309 base::string16 error; |
| 304 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 310 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
| 305 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", | 311 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer", |
| 306 error)); | 312 error)); |
| 307 EXPECT_EQ(NULL, out.the_array.get()); | 313 EXPECT_EQ(NULL, out.the_array.get()); |
| 308 | 314 |
| 309 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); | 315 EXPECT_TRUE(ArrayObject::Populate(*value, &out, &error)); |
| 310 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " | 316 EXPECT_TRUE(EqualsUtf16("'TheArray': expected list, got integer; " |
| 311 "'TheArray': expected list, got integer", | 317 "'TheArray': expected list, got integer", |
| 312 error)); | 318 error)); |
| 313 EXPECT_EQ(NULL, out.the_array.get()); | 319 EXPECT_EQ(NULL, out.the_array.get()); |
| 314 } | 320 } |
| 315 } | 321 } |
| 316 | 322 |
| 317 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { | 323 TEST(JsonSchemaCompilerErrorTest, TooManyKeys) { |
| 318 { | 324 { |
| 319 std::unique_ptr<base::DictionaryValue> value = | 325 std::unique_ptr<base::DictionaryValue> value = |
| 320 Dictionary("string", new base::Value("yes")); | 326 Dictionary("string", base::MakeUnique<base::Value>("yes")); |
| 321 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); | 327 EXPECT_TRUE(EqualsUtf16("", GetPopulateError<TestType>(*value))); |
| 322 } | 328 } |
| 323 { | 329 { |
| 324 std::unique_ptr<base::DictionaryValue> value = | 330 std::unique_ptr<base::DictionaryValue> value = |
| 325 Dictionary("string", new base::Value("yes"), "ohno", | 331 Dictionary("string", base::MakeUnique<base::Value>("yes"), "ohno", |
| 326 new base::Value("many values")); | 332 base::MakeUnique<base::Value>("many values")); |
| 327 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", | 333 EXPECT_TRUE(EqualsUtf16("found unexpected key 'ohno'", |
| 328 GetPopulateError<TestType>(*value))); | 334 GetPopulateError<TestType>(*value))); |
| 329 } | 335 } |
| 330 } | 336 } |
| OLD | NEW |