diff options
author | Ivan Kotenkov <kotenkov@yandex-team.ru> | 2017-10-24 23:47:24 +0900 |
---|---|---|
committer | Qijiang Fan <fqj@google.com> | 2020-06-05 07:34:23 +0900 |
commit | 5066341b8be1643353464f8f078a7fa07fc072c0 (patch) | |
tree | f3534acdbbcf8e1c49e2a06671cf29532095b454 /components | |
parent | 57d3940b4acf0b7414f232ca507923ca933075b1 (diff) | |
download | libchrome-5066341b8be1643353464f8f078a7fa07fc072c0.tar.gz |
Convert 0 and NULL to nullptr in components.
Steps to replicate:
1. Build clang-tidy and clang-apply-replacements as described here: https://chromium.googlesource.com/chromium/src/+/lkcr/docs/clang_tidy.md
2. Build targets necessary for the change in out/gn.
3. Generate the compilation database:
tools/clang/scripts/generate_compdb.py -p out/gn > compile_commands.json
4. Run clang-tidy and apply replacements:
cd out/gn && PATH_TO_RUN_CLANG_TIDY/run-clang-tidy.py -p ../../ -clang-tidy-binary PATH_TO_CLANG_TIDY_BINARY -clang-apply-replacements-binary PATH_TO_CLANG_APPLY_REPLACEMENTS_BINARY -checks=-*,modernize-use-nullptr -fix -j 8 DIR_TO_CONVERT
Bug: 403854, 776257
Change-Id: Ifd0c147ac6866beacffbddb0c56b20502cb4f127
Reviewed-on: https://chromium-review.googlesource.com/732308
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Commit-Queue: Ivan Kotenkov <kotenkov@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#511144}
CrOS-Libchrome-Original-Commit: 75b1c3aed7e1265eab65c1fc5516ca5cfda59284
Diffstat (limited to 'components')
8 files changed, 229 insertions, 256 deletions
diff --git a/components/json_schema/json_schema_validator.cc b/components/json_schema/json_schema_validator.cc index 21f0950951..080f4d7372 100644 --- a/components/json_schema/json_schema_validator.cc +++ b/components/json_schema/json_schema_validator.cc @@ -62,8 +62,8 @@ bool CompareToString(const ExpectedType& entry, const std::string& key) { // If |value| is a dictionary, returns the "name" attribute of |value| or NULL // if |value| does not contain a "name" attribute. Otherwise, returns |value|. const base::Value* ExtractNameFromDictionary(const base::Value* value) { - const base::DictionaryValue* value_dict = NULL; - const base::Value* name_value = NULL; + const base::DictionaryValue* value_dict = nullptr; + const base::Value* name_value = nullptr; if (value->GetAsDictionary(&value_dict)) { value_dict->Get("name", &name_value); return name_value; @@ -100,8 +100,8 @@ bool IsValidSchema(const base::DictionaryValue* dict, }; bool has_type_or_ref = false; - const base::ListValue* list_value = NULL; - const base::DictionaryValue* dictionary_value = NULL; + const base::ListValue* list_value = nullptr; + const base::DictionaryValue* dictionary_value = nullptr; std::string string_value; for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { @@ -240,7 +240,7 @@ bool IsValidSchema(const base::DictionaryValue* dict, if (it.key() == schema::kEnum) { it.value().GetAsList(&list_value); for (size_t i = 0; i < list_value->GetSize(); ++i) { - const base::Value* value = NULL; + const base::Value* value = nullptr; list_value->Get(i, &value); // Sometimes the enum declaration is a dictionary with the enum value // under "name". @@ -402,11 +402,11 @@ std::unique_ptr<base::DictionaryValue> JSONSchemaValidator::IsValidSchema( int validator_options, std::string* error) { base::JSONParserOptions json_options = base::JSON_PARSE_RFC; - std::unique_ptr<base::Value> json = - base::JSONReader::ReadAndReturnError(schema, json_options, NULL, error); + std::unique_ptr<base::Value> json = base::JSONReader::ReadAndReturnError( + schema, json_options, nullptr, error); if (!json) return std::unique_ptr<base::DictionaryValue>(); - base::DictionaryValue* dict = NULL; + base::DictionaryValue* dict = nullptr; if (!json->GetAsDictionary(&dict)) { *error = "Schema must be a JSON object"; return std::unique_ptr<base::DictionaryValue>(); @@ -428,7 +428,7 @@ JSONSchemaValidator::JSONSchemaValidator(base::DictionaryValue* schema, return; for (size_t i = 0; i < types->GetSize(); ++i) { - base::DictionaryValue* type = NULL; + base::DictionaryValue* type = nullptr; CHECK(types->GetDictionary(i, &type)); std::string id; @@ -476,7 +476,7 @@ void JSONSchemaValidator::Validate(const base::Value* instance, // If the schema has a choices property, the instance must validate against at // least one of the items in that array. - const base::ListValue* choices = NULL; + const base::ListValue* choices = nullptr; if (schema->GetList(schema::kChoices, &choices)) { ValidateChoices(instance, choices, path); return; @@ -484,7 +484,7 @@ void JSONSchemaValidator::Validate(const base::Value* instance, // If the schema has an enum property, the instance must be one of those // values. - const base::ListValue* enumeration = NULL; + const base::ListValue* enumeration = nullptr; if (schema->GetList(schema::kEnum, &enumeration)) { ValidateEnum(instance, enumeration, path); return; @@ -524,7 +524,7 @@ void JSONSchemaValidator::ValidateChoices(const base::Value* instance, size_t original_num_errors = errors_.size(); for (size_t i = 0; i < choices->GetSize(); ++i) { - const base::DictionaryValue* choice = NULL; + const base::DictionaryValue* choice = nullptr; CHECK(choices->GetDictionary(i, &choice)); Validate(instance, choice, path); @@ -545,7 +545,7 @@ void JSONSchemaValidator::ValidateEnum(const base::Value* instance, const base::ListValue* choices, const std::string& path) { for (size_t i = 0; i < choices->GetSize(); ++i) { - const base::Value* choice = NULL; + const base::Value* choice = nullptr; CHECK(choices->Get(i, &choice)); // Sometimes the enum declaration is a dictionary with the enum value under // "name". @@ -581,15 +581,15 @@ void JSONSchemaValidator::ValidateEnum(const base::Value* instance, void JSONSchemaValidator::ValidateObject(const base::DictionaryValue* instance, const base::DictionaryValue* schema, const std::string& path) { - const base::DictionaryValue* properties = NULL; + const base::DictionaryValue* properties = nullptr; if (schema->GetDictionary(schema::kProperties, &properties)) { for (base::DictionaryValue::Iterator it(*properties); !it.IsAtEnd(); it.Advance()) { std::string prop_path = path.empty() ? it.key() : (path + "." + it.key()); - const base::DictionaryValue* prop_schema = NULL; + const base::DictionaryValue* prop_schema = nullptr; CHECK(it.value().GetAsDictionary(&prop_schema)); - const base::Value* prop_value = NULL; + const base::Value* prop_value = nullptr; if (instance->Get(it.key(), &prop_value)) { Validate(prop_value, prop_schema, prop_path); } else { @@ -604,11 +604,11 @@ void JSONSchemaValidator::ValidateObject(const base::DictionaryValue* instance, } } - const base::DictionaryValue* additional_properties_schema = NULL; + const base::DictionaryValue* additional_properties_schema = nullptr; bool allow_any_additional_properties = SchemaAllowsAnyAdditionalItems(schema, &additional_properties_schema); - const base::DictionaryValue* pattern_properties = NULL; + const base::DictionaryValue* pattern_properties = nullptr; std::vector<std::unique_ptr<re2::RE2>> pattern_properties_pattern; std::vector<const base::DictionaryValue*> pattern_properties_schema; @@ -625,7 +625,7 @@ void JSONSchemaValidator::ValidateObject(const base::DictionaryValue* instance, kInvalidRegex, it.key(), prop_pattern->error()))); continue; } - const base::DictionaryValue* prop_schema = NULL; + const base::DictionaryValue* prop_schema = nullptr; CHECK(it.value().GetAsDictionary(&prop_schema)); pattern_properties_pattern.push_back(std::move(prop_pattern)); pattern_properties_schema.push_back(prop_schema); @@ -662,7 +662,7 @@ void JSONSchemaValidator::ValidateObject(const base::DictionaryValue* instance, void JSONSchemaValidator::ValidateArray(const base::ListValue* instance, const base::DictionaryValue* schema, const std::string& path) { - const base::DictionaryValue* single_type = NULL; + const base::DictionaryValue* single_type = nullptr; size_t instance_size = instance->GetSize(); if (schema->GetDictionary(schema::kItems, &single_type)) { int min_items = 0; @@ -686,7 +686,7 @@ void JSONSchemaValidator::ValidateArray(const base::ListValue* instance, // If the items property is a single schema, each item in the array must // validate against that schema. for (size_t i = 0; i < instance_size; ++i) { - const base::Value* item = NULL; + const base::Value* item = nullptr; CHECK(instance->Get(i, &item)); std::string i_str = base::Uint64ToString(i); std::string item_path = path.empty() ? i_str : (path + "." + i_str); @@ -704,16 +704,16 @@ void JSONSchemaValidator::ValidateArray(const base::ListValue* instance, void JSONSchemaValidator::ValidateTuple(const base::ListValue* instance, const base::DictionaryValue* schema, const std::string& path) { - const base::ListValue* tuple_type = NULL; + const base::ListValue* tuple_type = nullptr; schema->GetList(schema::kItems, &tuple_type); size_t tuple_size = tuple_type ? tuple_type->GetSize() : 0; if (tuple_type) { for (size_t i = 0; i < tuple_size; ++i) { std::string i_str = base::Uint64ToString(i); std::string item_path = path.empty() ? i_str : (path + "." + i_str); - const base::DictionaryValue* item_schema = NULL; + const base::DictionaryValue* item_schema = nullptr; CHECK(tuple_type->GetDictionary(i, &item_schema)); - const base::Value* item_value = NULL; + const base::Value* item_value = nullptr; instance->Get(i, &item_value); if (item_value && item_value->type() != base::Value::Type::NONE) { Validate(item_value, item_schema, item_path); @@ -728,7 +728,7 @@ void JSONSchemaValidator::ValidateTuple(const base::ListValue* instance, } } - const base::DictionaryValue* additional_properties_schema = NULL; + const base::DictionaryValue* additional_properties_schema = nullptr; if (SchemaAllowsAnyAdditionalItems(schema, &additional_properties_schema)) return; @@ -739,7 +739,7 @@ void JSONSchemaValidator::ValidateTuple(const base::ListValue* instance, for (size_t i = tuple_size; i < instance_size; ++i) { std::string i_str = base::Uint64ToString(i); std::string item_path = path.empty() ? i_str : (path + "." + i_str); - const base::Value* item_value = NULL; + const base::Value* item_value = nullptr; CHECK(instance->Get(i, &item_value)); Validate(item_value, additional_properties_schema, item_path); } diff --git a/components/json_schema/json_schema_validator_unittest_base.cc b/components/json_schema/json_schema_validator_unittest_base.cc index 43d292b42f..15e6f76848 100644 --- a/components/json_schema/json_schema_validator_unittest_base.cc +++ b/components/json_schema/json_schema_validator_unittest_base.cc @@ -39,7 +39,7 @@ base::Value* LoadValue(const std::string& filename) { std::string error_message; JSONFileValueDeserializer deserializer(path); base::Value* result = - deserializer.Deserialize(NULL, &error_message).release(); + deserializer.Deserialize(nullptr, &error_message).release(); if (!result) ADD_FAILURE() << "Could not parse JSON: " << error_message; return result; @@ -48,10 +48,10 @@ base::Value* LoadValue(const std::string& filename) { base::Value* LoadValue(const std::string& filename, base::Value::Type type) { std::unique_ptr<base::Value> result(LoadValue(filename)); if (!result.get()) - return NULL; + return nullptr; if (!result->IsType(type)) { ADD_FAILURE() << "Expected type " << type << ", got: " << result->type(); - return NULL; + return nullptr; } return result.release(); } @@ -96,23 +96,21 @@ void JSONSchemaValidatorTestBase::TestComplex() { ASSERT_TRUE(schema.get()); ASSERT_TRUE(instance.get()); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); - instance->Remove(instance->GetSize() - 1, NULL); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); + instance->Remove(instance->GetSize() - 1, nullptr); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->Append(base::MakeUnique<base::DictionaryValue>()); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", - JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kNumber, - schema::kObject)); - instance->Remove(instance->GetSize() - 1, NULL); + ExpectNotValid( + TEST_SOURCE, instance.get(), schema.get(), nullptr, "1", + JSONSchemaValidator::FormatErrorMessage( + JSONSchemaValidator::kInvalidType, schema::kNumber, schema::kObject)); + instance->Remove(instance->GetSize() - 1, nullptr); - base::DictionaryValue* item = NULL; + base::DictionaryValue* item = nullptr; ASSERT_TRUE(instance->GetDictionary(0, &item)); item->SetString("url", "xxxxxxxxxxx"); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "0.url", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "0.url", JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kStringMaxLength, "10")); } @@ -124,13 +122,13 @@ void JSONSchemaValidatorTestBase::TestStringPattern() { ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("foo")).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("foooooo")).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("bar")).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kStringPattern, "foo+")); } @@ -141,19 +139,19 @@ void JSONSchemaValidatorTestBase::TestEnum() { ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("foo")).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("42")).get(), - schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidEnum); + schema.get(), nullptr, std::string(), JSONSchemaValidator::kInvalidEnum); ExpectNotValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::kInvalidEnum); } @@ -162,29 +160,27 @@ void JSONSchemaValidatorTestBase::TestChoices() { LoadDictionary("choices_schema.json")); ExpectValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), - NULL); + nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); std::unique_ptr<base::DictionaryValue> instance(new base::DictionaryValue()); instance->SetString("foo", "bar"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); - ExpectNotValid( - TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("foo")).get(), - schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidChoice); - ExpectNotValid( - TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), - schema.get(), NULL, std::string(), JSONSchemaValidator::kInvalidChoice); - - instance->SetInteger("foo", 42); ExpectNotValid(TEST_SOURCE, - instance.get(), - schema.get(), - NULL, - std::string(), + std::unique_ptr<base::Value>(new base::Value("foo")).get(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::kInvalidChoice); + ExpectNotValid(TEST_SOURCE, + std::unique_ptr<base::Value>(new base::ListValue()).get(), + schema.get(), nullptr, std::string(), + JSONSchemaValidator::kInvalidChoice); + + instance->SetInteger("foo", 42); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, + std::string(), JSONSchemaValidator::kInvalidChoice); } void JSONSchemaValidatorTestBase::TestExtends() { @@ -201,58 +197,55 @@ void JSONSchemaValidatorTestBase::TestObject() { instance->SetString("foo", "foo"); instance->SetInteger("bar", 42); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->SetBoolean("extra", true); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "extra", JSONSchemaValidator::kUnexpectedProperty); - instance->Remove("extra", NULL); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "extra", + JSONSchemaValidator::kUnexpectedProperty); + instance->Remove("extra", nullptr); - instance->Remove("bar", NULL); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", + instance->Remove("bar", nullptr); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "bar", JSONSchemaValidator::kObjectPropertyIsRequired); instance->SetString("bar", "42"); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "bar", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kInteger, + JSONSchemaValidator::kInvalidType, schema::kInteger, schema::kString)); instance->SetInteger("bar", 42); // Test "patternProperties". instance->SetInteger("extra", 42); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "extra", JSONSchemaValidator::kUnexpectedProperty); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "extra", + JSONSchemaValidator::kUnexpectedProperty); schema->SetString("patternProperties.extra+.type", schema::kInteger); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); - instance->Remove("extra", NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); + instance->Remove("extra", nullptr); instance->SetInteger("extraaa", 42); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); - instance->Remove("extraaa", NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); + instance->Remove("extraaa", nullptr); instance->SetInteger("extr", 42); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "extr", JSONSchemaValidator::kUnexpectedProperty); - instance->Remove("extr", NULL); - schema->Remove(schema::kPatternProperties, NULL); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "extr", + JSONSchemaValidator::kUnexpectedProperty); + instance->Remove("extr", nullptr); + schema->Remove(schema::kPatternProperties, nullptr); // Test "patternProperties" and "properties" schemas are both checked if // applicable. schema->SetString("patternProperties.fo+.type", schema::kInteger); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "foo", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "foo", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kInteger, + JSONSchemaValidator::kInvalidType, schema::kInteger, schema::kString)); instance->SetInteger("foo", 123); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "foo", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "foo", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kString, + JSONSchemaValidator::kInvalidType, schema::kString, schema::kInteger)); instance->SetString("foo", "foo"); - schema->Remove(schema::kPatternProperties, NULL); + schema->Remove(schema::kPatternProperties, nullptr); // Test additional properties. base::DictionaryValue* additional_properties = schema->SetDictionary( @@ -260,43 +253,40 @@ void JSONSchemaValidatorTestBase::TestObject() { additional_properties->SetString(schema::kType, schema::kAny); instance->SetBoolean("extra", true); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->SetString("extra", "foo"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); additional_properties->SetString(schema::kType, schema::kBoolean); instance->SetBoolean("extra", true); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->SetString("extra", "foo"); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "extra", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kBoolean, + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "extra", + JSONSchemaValidator::FormatErrorMessage( + JSONSchemaValidator::kInvalidType, schema::kBoolean, schema::kString)); - instance->Remove("extra", NULL); + instance->Remove("extra", nullptr); - base::DictionaryValue* properties = NULL; - base::DictionaryValue* bar_property = NULL; + base::DictionaryValue* properties = nullptr; + base::DictionaryValue* bar_property = nullptr; ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties)); ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); bar_property->SetBoolean(schema::kOptional, true); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); - instance->Remove("bar", NULL); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); + instance->Remove("bar", nullptr); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->Set("bar", base::MakeUnique<base::Value>()); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "bar", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kInteger, - schema::kNull)); + ExpectNotValid( + TEST_SOURCE, instance.get(), schema.get(), nullptr, "bar", + JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, + schema::kInteger, schema::kNull)); instance->SetString("bar", "42"); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "bar", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kInteger, + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "bar", + JSONSchemaValidator::FormatErrorMessage( + JSONSchemaValidator::kInvalidType, schema::kInteger, schema::kString)); // Verify that JSON parser handles dot in "patternProperties" well. @@ -306,10 +296,10 @@ void JSONSchemaValidatorTestBase::TestObject() { instance.reset(new base::DictionaryValue()); instance->SetString("a", "whatever"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->SetString("foo", "bar"); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, - "foo", JSONSchemaValidator::kUnexpectedProperty); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "foo", + JSONSchemaValidator::kUnexpectedProperty); } void JSONSchemaValidatorTestBase::TestTypeReference() { @@ -343,7 +333,7 @@ void JSONSchemaValidatorTestBase::TestTypeReference() { instance_inline->SetInteger("baz", -2); ExpectValid(TEST_SOURCE, instance.get(), schema.get(), types.get()); - ExpectValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL); + ExpectValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), nullptr); // Validation failure, but successful schema reference. instance->SetString("baz", "a"); @@ -352,12 +342,13 @@ void JSONSchemaValidatorTestBase::TestTypeReference() { JSONSchemaValidator::kStringMinLength, "2")); instance_inline->SetInteger("bar", 20); - ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL, - "bar", JSONSchemaValidator::FormatErrorMessage( + ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), + nullptr, "bar", + JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kNumberMaximum, "0")); // Remove MinLengthString type. - types->Remove(types->GetSize() - 1, NULL); + types->Remove(types->GetSize() - 1, nullptr); instance->SetString("baz", "ab"); ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), types.get(), "bar", JSONSchemaValidator::FormatErrorMessage( @@ -365,12 +356,12 @@ void JSONSchemaValidatorTestBase::TestTypeReference() { "Max10Int")); // Remove internal type "NegativeInt". - schema_inline->Remove("properties.bar", NULL); - instance_inline->Remove("bar", NULL); - ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL, - "baz", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kUnknownTypeReference, - "NegativeInt")); + schema_inline->Remove("properties.bar", nullptr); + instance_inline->Remove("bar", nullptr); + ExpectNotValid( + TEST_SOURCE, instance_inline.get(), schema_inline.get(), nullptr, "baz", + JSONSchemaValidator::FormatErrorMessage( + JSONSchemaValidator::kUnknownTypeReference, "NegativeInt")); } void JSONSchemaValidatorTestBase::TestArrayTuple() { @@ -382,28 +373,24 @@ void JSONSchemaValidatorTestBase::TestArrayTuple() { instance->AppendString("42"); instance->AppendInteger(42); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->AppendString("anything"); - ExpectNotValid(TEST_SOURCE, - instance.get(), - schema.get(), - NULL, + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kArrayMaxItems, "2")); - instance->Remove(1, NULL); - instance->Remove(1, NULL); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", + instance->Remove(1, nullptr); + instance->Remove(1, nullptr); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "1", JSONSchemaValidator::kArrayItemRequired); instance->Set(0, base::MakeUnique<base::Value>(42)); instance->AppendInteger(42); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "0", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kString, + JSONSchemaValidator::kInvalidType, schema::kString, schema::kInteger)); base::DictionaryValue* additional_properties = schema->SetDictionary( @@ -411,35 +398,33 @@ void JSONSchemaValidatorTestBase::TestArrayTuple() { additional_properties->SetString(schema::kType, schema::kAny); instance->Set(0, base::MakeUnique<base::Value>("42")); instance->AppendString("anything"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->Set(2, base::MakeUnique<base::ListValue>()); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); additional_properties->SetString(schema::kType, schema::kBoolean); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", - JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kBoolean, - schema::kArray)); + ExpectNotValid( + TEST_SOURCE, instance.get(), schema.get(), nullptr, "2", + JSONSchemaValidator::FormatErrorMessage( + JSONSchemaValidator::kInvalidType, schema::kBoolean, schema::kArray)); instance->Set(2, base::MakeUnique<base::Value>(false)); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); - base::ListValue* items_schema = NULL; - base::DictionaryValue* item0_schema = NULL; + base::ListValue* items_schema = nullptr; + base::DictionaryValue* item0_schema = nullptr; ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); item0_schema->SetBoolean(schema::kOptional, true); - instance->Remove(2, NULL); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + instance->Remove(2, nullptr); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); // TODO(aa): I think this is inconsistent with the handling of NULL+optional // for objects. instance->Set(0, base::MakeUnique<base::Value>()); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->Set(0, base::MakeUnique<base::Value>(42)); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "0", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kString, + JSONSchemaValidator::kInvalidType, schema::kString, schema::kInteger)); } @@ -454,35 +439,28 @@ void JSONSchemaValidatorTestBase::TestArrayNonTuple() { instance->AppendString("x"); instance->AppendString("x"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->AppendString("x"); - ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), nullptr); instance->AppendString("x"); - ExpectNotValid(TEST_SOURCE, - instance.get(), - schema.get(), - NULL, + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kArrayMaxItems, "3")); - instance->Remove(1, NULL); - instance->Remove(1, NULL); - instance->Remove(1, NULL); - ExpectNotValid(TEST_SOURCE, - instance.get(), - schema.get(), - NULL, + instance->Remove(1, nullptr); + instance->Remove(1, nullptr); + instance->Remove(1, nullptr); + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kArrayMinItems, "2")); - instance->Remove(1, NULL); + instance->Remove(1, nullptr); instance->AppendInteger(42); - ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), nullptr, "1", JSONSchemaValidator::FormatErrorMessage( - JSONSchemaValidator::kInvalidType, - schema::kString, + JSONSchemaValidator::kInvalidType, schema::kString, schema::kInteger)); } @@ -494,21 +472,21 @@ void JSONSchemaValidatorTestBase::TestString() { ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("x")).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("xxxxxxxxxx")).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(std::string())).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kStringMinLength, "1")); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("xxxxxxxxxxx")).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kStringMaxLength, "10")); } @@ -522,25 +500,25 @@ void JSONSchemaValidatorTestBase::TestNumber() { ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(1)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(50)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(100)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(88.88)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(0.5)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kNumberMinimum, "1")); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(100.1)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kNumberMaximum, "100")); } @@ -614,76 +592,76 @@ void JSONSchemaValidatorTestBase::TestTypes() { schema->SetString(schema::kType, schema::kObject); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::DictionaryValue()).get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kArray); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kString); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("foobar")).get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kNumber); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(88.8)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(0)).get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kInteger); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(0)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(pow(2.0, DBL_MANT_DIG))) .get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(pow(-2.0, DBL_MANT_DIG))) .get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kBoolean); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), - schema.get(), NULL); + schema.get(), nullptr); ExpectValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(true)).get(), - schema.get(), NULL); + schema.get(), nullptr); schema->SetString(schema::kType, schema::kNull); ExpectValid(TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), - NULL); + nullptr); // not valid schema->SetString(schema::kType, schema::kObject); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::ListValue()).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, schema::kObject, schema::kArray)); schema->SetString(schema::kType, schema::kObject); ExpectNotValid( - TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), NULL, + TEST_SOURCE, base::MakeUnique<base::Value>().get(), schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, schema::kObject, schema::kNull)); @@ -691,14 +669,14 @@ void JSONSchemaValidatorTestBase::TestTypes() { schema->SetString(schema::kType, schema::kArray); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger)); schema->SetString(schema::kType, schema::kString); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(42)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kInvalidType, schema::kString, schema::kInteger)); @@ -706,20 +684,20 @@ void JSONSchemaValidatorTestBase::TestTypes() { schema->SetString(schema::kType, schema::kNumber); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value("42")).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kInvalidType, schema::kNumber, schema::kString)); schema->SetString(schema::kType, schema::kInteger); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(88.8)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::kInvalidTypeIntegerNumber); schema->SetString(schema::kType, schema::kBoolean); ExpectNotValid(TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(1)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage( JSONSchemaValidator::kInvalidType, schema::kBoolean, schema::kInteger)); @@ -727,7 +705,7 @@ void JSONSchemaValidatorTestBase::TestTypes() { schema->SetString(schema::kType, schema::kNull); ExpectNotValid( TEST_SOURCE, std::unique_ptr<base::Value>(new base::Value(false)).get(), - schema.get(), NULL, std::string(), + schema.get(), nullptr, std::string(), JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType, schema::kNull, schema::kBoolean)); } diff --git a/components/policy/core/common/config_dir_policy_loader.cc b/components/policy/core/common/config_dir_policy_loader.cc index c95e9098a5..a0d3a0a496 100644 --- a/components/policy/core/common/config_dir_policy_loader.cc +++ b/components/policy/core/common/config_dir_policy_loader.cc @@ -157,7 +157,7 @@ void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path, status.Add(JsonErrorToPolicyLoadStatus(error_code)); continue; } - base::DictionaryValue* dictionary_value = NULL; + base::DictionaryValue* dictionary_value = nullptr; if (!value->GetAsDictionary(&dictionary_value)) { LOG(WARNING) << "Expected JSON dictionary in configuration file " << config_file_iter->value(); diff --git a/components/policy/core/common/configuration_policy_provider.cc b/components/policy/core/common/configuration_policy_provider.cc index fd3beec280..04f9b68ca8 100644 --- a/components/policy/core/common/configuration_policy_provider.cc +++ b/components/policy/core/common/configuration_policy_provider.cc @@ -13,8 +13,7 @@ namespace policy { ConfigurationPolicyProvider::Observer::~Observer() {} ConfigurationPolicyProvider::ConfigurationPolicyProvider() - : initialized_(false), - schema_registry_(NULL) {} + : initialized_(false), schema_registry_(nullptr) {} ConfigurationPolicyProvider::~ConfigurationPolicyProvider() { DCHECK(!initialized_); @@ -32,7 +31,7 @@ void ConfigurationPolicyProvider::Shutdown() { // Unit tests don't initialize the BrowserPolicyConnector but call // shutdown; handle that. schema_registry_->RemoveObserver(this); - schema_registry_ = NULL; + schema_registry_ = nullptr; } } diff --git a/components/policy/core/common/generate_policy_source_unittest.cc b/components/policy/core/common/generate_policy_source_unittest.cc index 8ea85fdc03..1e9fa94eb7 100644 --- a/components/policy/core/common/generate_policy_source_unittest.cc +++ b/components/policy/core/common/generate_policy_source_unittest.cc @@ -136,22 +136,18 @@ TEST(GeneratePolicySource, ChromeSchemaData) { // The properties are iterated in order. const char* kExpectedProperties[] = { - key::kProxyBypassList, - key::kProxyMode, - key::kProxyPacUrl, - key::kProxyServer, - key::kProxyServerMode, - NULL, + key::kProxyBypassList, key::kProxyMode, key::kProxyPacUrl, + key::kProxyServer, key::kProxyServerMode, nullptr, }; const char** next = kExpectedProperties; for (Schema::Iterator it(subschema.GetPropertiesIterator()); !it.IsAtEnd(); it.Advance(), ++next) { - ASSERT_TRUE(*next != NULL); + ASSERT_TRUE(*next != nullptr); EXPECT_STREQ(*next, it.key()); ASSERT_TRUE(it.schema().valid()); EXPECT_EQ(base::Value::Type::STRING, it.schema().type()); } - EXPECT_TRUE(*next == NULL); + EXPECT_TRUE(*next == nullptr); #if defined(OS_CHROMEOS) subschema = schema.GetKnownProperty(key::kPowerManagementIdleSettings); diff --git a/components/policy/core/common/schema.cc b/components/policy/core/common/schema.cc index 05adbe1550..4cd6ed61c1 100644 --- a/components/policy/core/common/schema.cc +++ b/components/policy/core/common/schema.cc @@ -307,11 +307,11 @@ Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema, IdMap id_map; ReferenceList reference_list; if (!storage->Parse(schema, &root_index, &id_map, &reference_list, error)) - return NULL; + return nullptr; if (root_index == kInvalid) { *error = "The main schema can't have a $ref"; - return NULL; + return nullptr; } // None of this should ever happen without having been already detected. @@ -327,11 +327,11 @@ Schema::InternalStorage::ParseSchema(const base::DictionaryValue& schema, sizes.string_enums != storage->string_enums_.size()) { *error = "Failed to parse the schema due to a Chrome bug. Please file a " "new issue at http://crbug.com"; - return NULL; + return nullptr; } if (!ResolveReferences(id_map, reference_list, error)) - return NULL; + return nullptr; SchemaData* data = &storage->schema_data_; data->schema_nodes = storage->schema_nodes_.data(); @@ -376,17 +376,17 @@ void Schema::InternalStorage::DetermineStorageSizes( sizes->schema_nodes++; if (type == base::Value::Type::LIST) { - const base::DictionaryValue* items = NULL; + const base::DictionaryValue* items = nullptr; if (schema.GetDictionary(schema::kItems, &items)) DetermineStorageSizes(*items, sizes); } else if (type == base::Value::Type::DICTIONARY) { sizes->properties_nodes++; - const base::DictionaryValue* dict = NULL; + const base::DictionaryValue* dict = nullptr; if (schema.GetDictionary(schema::kAdditionalProperties, &dict)) DetermineStorageSizes(*dict, sizes); - const base::DictionaryValue* properties = NULL; + const base::DictionaryValue* properties = nullptr; if (schema.GetDictionary(schema::kProperties, &properties)) { for (base::DictionaryValue::Iterator it(*properties); !it.IsAtEnd(); it.Advance()) { @@ -398,7 +398,7 @@ void Schema::InternalStorage::DetermineStorageSizes( } } - const base::DictionaryValue* pattern_properties = NULL; + const base::DictionaryValue* pattern_properties = nullptr; if (schema.GetDictionary(schema::kPatternProperties, &pattern_properties)) { for (base::DictionaryValue::Iterator it(*pattern_properties); !it.IsAtEnd(); it.Advance()) { @@ -409,7 +409,7 @@ void Schema::InternalStorage::DetermineStorageSizes( } } } else if (schema.HasKey(schema::kEnum)) { - const base::ListValue* possible_values = NULL; + const base::ListValue* possible_values = nullptr; if (schema.GetList(schema::kEnum, &possible_values)) { if (type == base::Value::Type::INTEGER) { sizes->int_enums += possible_values->GetSize(); @@ -509,7 +509,7 @@ bool Schema::InternalStorage::ParseDictionary( properties_nodes_[extra].additional = kInvalid; schema_node->extra = extra; - const base::DictionaryValue* dict = NULL; + const base::DictionaryValue* dict = nullptr; if (schema.GetDictionary(schema::kAdditionalProperties, &dict)) { if (!Parse(*dict, &properties_nodes_[extra].additional, id_map, reference_list, error)) { @@ -519,7 +519,7 @@ bool Schema::InternalStorage::ParseDictionary( properties_nodes_[extra].begin = static_cast<int>(property_nodes_.size()); - const base::DictionaryValue* properties = NULL; + const base::DictionaryValue* properties = nullptr; if (schema.GetDictionary(schema::kProperties, &properties)) { // This and below reserves nodes for all of the |properties|, and makes sure // they are contiguous. Recursive calls to Parse() will append after these @@ -529,14 +529,14 @@ bool Schema::InternalStorage::ParseDictionary( properties_nodes_[extra].end = static_cast<int>(property_nodes_.size()); - const base::DictionaryValue* pattern_properties = NULL; + const base::DictionaryValue* pattern_properties = nullptr; if (schema.GetDictionary(schema::kPatternProperties, &pattern_properties)) property_nodes_.resize(property_nodes_.size() + pattern_properties->size()); properties_nodes_[extra].pattern_end = static_cast<int>(property_nodes_.size()); - if (properties != NULL) { + if (properties != nullptr) { int base_index = properties_nodes_[extra].begin; int index = base_index; @@ -554,7 +554,7 @@ bool Schema::InternalStorage::ParseDictionary( CHECK_EQ(static_cast<int>(properties->size()), index - base_index); } - if (pattern_properties != NULL) { + if (pattern_properties != nullptr) { int base_index = properties_nodes_[extra].end; int index = base_index; @@ -591,7 +591,7 @@ bool Schema::InternalStorage::ParseList(const base::DictionaryValue& schema, IdMap* id_map, ReferenceList* reference_list, std::string* error) { - const base::DictionaryValue* dict = NULL; + const base::DictionaryValue* dict = nullptr; if (!schema.GetDictionary(schema::kItems, &dict)) { *error = "Arrays must declare a single schema for their items."; return false; @@ -603,7 +603,7 @@ bool Schema::InternalStorage::ParseEnum(const base::DictionaryValue& schema, base::Value::Type type, SchemaNode* schema_node, std::string* error) { - const base::ListValue *possible_values = NULL; + const base::ListValue* possible_values = nullptr; if (!schema.GetList(schema::kEnum, &possible_values)) { *error = "Enum attribute must be a list value"; return false; @@ -750,7 +750,7 @@ Schema Schema::Iterator::schema() const { return Schema(storage_, storage_->schema(it_->schema)); } -Schema::Schema() : node_(NULL) {} +Schema::Schema() : node_(nullptr) {} Schema::Schema(const scoped_refptr<const InternalStorage>& storage, const SchemaNode* node) @@ -795,8 +795,8 @@ bool Schema::Validate(const base::Value& value, return false; } - const base::DictionaryValue* dict = NULL; - const base::ListValue* list = NULL; + const base::DictionaryValue* dict = nullptr; + const base::ListValue* list = nullptr; int int_value; std::string str_value; if (value.GetAsDictionary(&dict)) { @@ -874,8 +874,8 @@ bool Schema::Normalize(base::Value* value, return false; } - base::DictionaryValue* dict = NULL; - base::ListValue* list = NULL; + base::DictionaryValue* dict = nullptr; + base::ListValue* list = nullptr; if (value->GetAsDictionary(&dict)) { std::vector<std::string> drop_list; // Contains the keys to drop. for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); @@ -891,7 +891,7 @@ bool Schema::Normalize(base::Value* value, } else { for (SchemaList::iterator subschema = schema_list.begin(); subschema != schema_list.end(); ++subschema) { - base::Value* sub_value = NULL; + base::Value* sub_value = nullptr; dict->GetWithoutPathExpansion(it.key(), &sub_value); if (!subschema->Normalize(sub_value, StrategyForNextLevel(strategy), @@ -915,13 +915,13 @@ bool Schema::Normalize(base::Value* value, for (std::vector<std::string>::const_iterator it = drop_list.begin(); it != drop_list.end(); ++it) { - dict->RemoveWithoutPathExpansion(*it, NULL); + dict->RemoveWithoutPathExpansion(*it, nullptr); } return true; } else if (value->GetAsList(&list)) { std::vector<size_t> drop_list; // Contains the indexes to drop. for (size_t index = 0; index < list->GetSize(); index++) { - base::Value* sub_value = NULL; + base::Value* sub_value = nullptr; list->Get(index, &sub_value); if (!sub_value || !GetItems().Normalize(sub_value, StrategyForNextLevel(strategy), @@ -940,7 +940,7 @@ bool Schema::Normalize(base::Value* value, *changed = true; for (std::vector<size_t>::reverse_iterator it = drop_list.rbegin(); it != drop_list.rend(); ++it) { - list->Remove(*it, NULL); + list->Remove(*it, nullptr); } return true; } diff --git a/components/policy/core/common/schema_registry.cc b/components/policy/core/common/schema_registry.cc index ff5a4b190f..d23f8dbf78 100644 --- a/components/policy/core/common/schema_registry.cc +++ b/components/policy/core/common/schema_registry.cc @@ -265,7 +265,7 @@ void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown( DCHECK_EQ(wrapped_, registry); wrapped_->RemoveObserver(this); wrapped_->RemoveInternalObserver(this); - wrapped_ = NULL; + wrapped_ = nullptr; // Keep serving the same |schema_map_|. } diff --git a/components/policy/core/common/schema_unittest.cc b/components/policy/core/common/schema_unittest.cc index 9ee2f6ba56..6829de9b03 100644 --- a/components/policy/core/common/schema_unittest.cc +++ b/components/policy/core/common/schema_unittest.cc @@ -154,7 +154,7 @@ void TestSchemaValidationHelper(const std::string& source, // Test that Schema::Validate() works as expected. error = kNoErrorReturned; - bool returned = schema.Validate(value, strategy, NULL, &error); + bool returned = schema.Validate(value, strategy, nullptr, &error); ASSERT_EQ(expected_return_value, returned) << source << ": " << error; // Test that Schema::Normalize() will return the same value as @@ -163,20 +163,20 @@ void TestSchemaValidationHelper(const std::string& source, std::unique_ptr<base::Value> cloned_value(value.DeepCopy()); bool touched = false; returned = - schema.Normalize(cloned_value.get(), strategy, NULL, &error, &touched); + schema.Normalize(cloned_value.get(), strategy, nullptr, &error, &touched); EXPECT_EQ(expected_return_value, returned) << source << ": " << error; - bool strictly_valid = schema.Validate(value, SCHEMA_STRICT, NULL, &error); + bool strictly_valid = schema.Validate(value, SCHEMA_STRICT, nullptr, &error); EXPECT_EQ(touched, !strictly_valid && returned) << source; // Test that Schema::Normalize() have actually dropped invalid and unknown // properties. if (expected_return_value) { EXPECT_TRUE( - schema.Validate(*cloned_value.get(), SCHEMA_STRICT, NULL, &error)) + schema.Validate(*cloned_value.get(), SCHEMA_STRICT, nullptr, &error)) << source; - EXPECT_TRUE( - schema.Normalize(cloned_value.get(), SCHEMA_STRICT, NULL, &error, NULL)) + EXPECT_TRUE(schema.Normalize(cloned_value.get(), SCHEMA_STRICT, nullptr, + &error, nullptr)) << source; } } @@ -729,7 +729,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(schema, bundle, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, true); TestSchemaValidation(schema, bundle, SCHEMA_ALLOW_UNKNOWN, true); TestSchemaValidationWithPath(schema, bundle, ""); - bundle.Remove("boom", NULL); + bundle.Remove("boom", nullptr); // Invalid top level property. bundle.SetInteger("Boolean", 12345); @@ -753,7 +753,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); TestSchemaValidationWithPath(subschema, root, "Object"); - root.Remove("Object.three", NULL); + root.Remove("Object.three", nullptr); // Invalid property. root.SetInteger("Object.one", 12345); @@ -763,7 +763,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); TestSchemaValidationWithPath(subschema, root, "Object.one"); - root.Remove("Object.one", NULL); + root.Remove("Object.one", nullptr); } // Tests on ArrayOfObjects. @@ -783,7 +783,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); TestSchemaValidationWithPath(subschema, root, "items[0]"); - root.Remove(root.GetSize() - 1, NULL); + root.Remove(root.GetSize() - 1, nullptr); // Invalid property. dict_value.reset(new base::DictionaryValue()); @@ -795,7 +795,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); TestSchemaValidationWithPath(subschema, root, "items[0].two"); - root.Remove(root.GetSize() - 1, NULL); + root.Remove(root.GetSize() - 1, nullptr); } // Tests on ObjectOfArray. @@ -888,13 +888,13 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); root.SetBoolean("fooo", false); TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); - root.Remove("fooo", NULL); + root.Remove("fooo", nullptr); root.SetInteger("foo", 123); TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); root.SetBoolean("foo", false); TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); - root.Remove("foo", NULL); + root.Remove("foo", nullptr); root.SetString("barr", "one"); TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); @@ -902,7 +902,7 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); root.SetBoolean("barr", false); TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); - root.Remove("barr", NULL); + root.Remove("barr", nullptr); root.SetString("bar", "one"); TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); @@ -910,12 +910,12 @@ TEST(SchemaTest, Validate) { TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); root.SetString("bar", "three"); TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); - root.Remove("bar", NULL); + root.Remove("bar", nullptr); root.SetInteger("foobar", 123); TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, true); - root.Remove("foobar", NULL); + root.Remove("foobar", nullptr); } // Test that integer to double promotion is allowed. |