Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: components/json_schema/json_schema_validator_unittest_base.cc

Issue 2838893002: Remove base::ListValue::Set(size_t, base::Value*) (Closed)
Patch Set: Fix Compilation Error Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/json_schema/json_schema_validator_unittest_base.h" 5 #include "components/json_schema/json_schema_validator_unittest_base.h"
6 6
7 #include <cfloat> 7 #include <cfloat>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <memory> 10 #include <memory>
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 NULL, 391 NULL,
392 std::string(), 392 std::string(),
393 JSONSchemaValidator::FormatErrorMessage( 393 JSONSchemaValidator::FormatErrorMessage(
394 JSONSchemaValidator::kArrayMaxItems, "2")); 394 JSONSchemaValidator::kArrayMaxItems, "2"));
395 395
396 instance->Remove(1, NULL); 396 instance->Remove(1, NULL);
397 instance->Remove(1, NULL); 397 instance->Remove(1, NULL);
398 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 398 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
399 JSONSchemaValidator::kArrayItemRequired); 399 JSONSchemaValidator::kArrayItemRequired);
400 400
401 instance->Set(0, new base::Value(42)); 401 instance->Set(0, base::MakeUnique<base::Value>(42));
402 instance->AppendInteger(42); 402 instance->AppendInteger(42);
403 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 403 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
404 JSONSchemaValidator::FormatErrorMessage( 404 JSONSchemaValidator::FormatErrorMessage(
405 JSONSchemaValidator::kInvalidType, 405 JSONSchemaValidator::kInvalidType,
406 schema::kString, 406 schema::kString,
407 schema::kInteger)); 407 schema::kInteger));
408 408
409 base::DictionaryValue* additional_properties = new base::DictionaryValue(); 409 base::DictionaryValue* additional_properties = new base::DictionaryValue();
410 additional_properties->SetString(schema::kType, schema::kAny); 410 additional_properties->SetString(schema::kType, schema::kAny);
411 schema->Set(schema::kAdditionalProperties, additional_properties); 411 schema->Set(schema::kAdditionalProperties, additional_properties);
412 instance->Set(0, new base::Value("42")); 412 instance->Set(0, base::MakeUnique<base::Value>("42"));
413 instance->AppendString("anything"); 413 instance->AppendString("anything");
414 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 414 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
415 instance->Set(2, new base::ListValue()); 415 instance->Set(2, base::MakeUnique<base::ListValue>());
416 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 416 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
417 417
418 additional_properties->SetString(schema::kType, schema::kBoolean); 418 additional_properties->SetString(schema::kType, schema::kBoolean);
419 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", 419 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2",
420 JSONSchemaValidator::FormatErrorMessage( 420 JSONSchemaValidator::FormatErrorMessage(
421 JSONSchemaValidator::kInvalidType, 421 JSONSchemaValidator::kInvalidType,
422 schema::kBoolean, 422 schema::kBoolean,
423 schema::kArray)); 423 schema::kArray));
424 instance->Set(2, new base::Value(false)); 424 instance->Set(2, base::MakeUnique<base::Value>(false));
425 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 425 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
426 426
427 base::ListValue* items_schema = NULL; 427 base::ListValue* items_schema = NULL;
428 base::DictionaryValue* item0_schema = NULL; 428 base::DictionaryValue* item0_schema = NULL;
429 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); 429 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema));
430 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); 430 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema));
431 item0_schema->SetBoolean(schema::kOptional, true); 431 item0_schema->SetBoolean(schema::kOptional, true);
432 instance->Remove(2, NULL); 432 instance->Remove(2, NULL);
433 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 433 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
434 // TODO(aa): I think this is inconsistent with the handling of NULL+optional 434 // TODO(aa): I think this is inconsistent with the handling of NULL+optional
435 // for objects. 435 // for objects.
436 instance->Set(0, base::MakeUnique<base::Value>()); 436 instance->Set(0, base::MakeUnique<base::Value>());
437 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 437 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
438 instance->Set(0, new base::Value(42)); 438 instance->Set(0, base::MakeUnique<base::Value>(42));
439 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 439 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
440 JSONSchemaValidator::FormatErrorMessage( 440 JSONSchemaValidator::FormatErrorMessage(
441 JSONSchemaValidator::kInvalidType, 441 JSONSchemaValidator::kInvalidType,
442 schema::kString, 442 schema::kString,
443 schema::kInteger)); 443 schema::kInteger));
444 } 444 }
445 445
446 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { 446 void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
447 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); 447 std::unique_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
448 schema->SetString(schema::kType, schema::kArray); 448 schema->SetString(schema::kType, schema::kArray);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 JSONSchemaValidator::kInvalidType, schema::kBoolean, 724 JSONSchemaValidator::kInvalidType, schema::kBoolean,
725 schema::kInteger)); 725 schema::kInteger));
726 726
727 schema->SetString(schema::kType, schema::kNull); 727 schema->SetString(schema::kType, schema::kNull);
728 ExpectNotValid( 728 ExpectNotValid(
729 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), 729 TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(),
730 schema.get(), NULL, std::string(), 730 schema.get(), NULL, std::string(),
731 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, 731 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType,
732 schema::kNull, schema::kBoolean)); 732 schema::kNull, schema::kBoolean));
733 } 733 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698