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

Side by Side Diff: tools/json_schema_compiler/test/crossref_unittest.cc

Issue 2911033002: Remove raw base::DictionaryValue::Set (Closed)
Patch Set: Proper Windows Fix Created 3 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/crossref.h" 5 #include "tools/json_schema_compiler/test/crossref.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h"
11 #include "base/values.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 #include "tools/json_schema_compiler/test/simple_api.h" 13 #include "tools/json_schema_compiler/test/simple_api.h"
12 14
13 using namespace test::api; 15 using namespace test::api;
14 16
15 namespace { 17 namespace {
16 18
17 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() { 19 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() {
18 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 20 auto value = base::MakeUnique<base::DictionaryValue>();
19 value->Set("number", new base::Value(1.1)); 21 value->SetDouble("number", 1.1);
20 value->Set("integer", new base::Value(4)); 22 value->SetInteger("integer", 4);
21 value->Set("string", new base::Value("bling")); 23 value->SetString("string", "bling");
22 value->Set("boolean", new base::Value(true)); 24 value->SetBoolean("boolean", true);
23 return value; 25 return value;
24 } 26 }
25 27
26 } // namespace 28 } // namespace
27 29
28 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { 30 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
29 base::DictionaryValue crossref_orig; 31 base::DictionaryValue crossref_orig;
30 crossref_orig.Set("testType", CreateTestTypeValue().release()); 32 crossref_orig.Set("testType", CreateTestTypeValue());
31 crossref_orig.Set("testEnumRequired", new base::Value("one")); 33 crossref_orig.SetString("testEnumRequired", "one");
32 crossref_orig.Set("testEnumOptional", new base::Value("two")); 34 crossref_orig.SetString("testEnumOptional", "two");
33 35
34 // Test Populate of the value --> compiled type. 36 // Test Populate of the value --> compiled type.
35 crossref::CrossrefType crossref_type; 37 crossref::CrossrefType crossref_type;
36 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type)); 38 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type));
37 EXPECT_EQ(1.1, crossref_type.test_type.number); 39 EXPECT_EQ(1.1, crossref_type.test_type.number);
38 EXPECT_EQ(4, crossref_type.test_type.integer); 40 EXPECT_EQ(4, crossref_type.test_type.integer);
39 EXPECT_EQ("bling", crossref_type.test_type.string); 41 EXPECT_EQ("bling", crossref_type.test_type.string);
40 EXPECT_EQ(true, crossref_type.test_type.boolean); 42 EXPECT_EQ(true, crossref_type.test_type.boolean);
41 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required); 43 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required);
42 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional); 44 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 80
79 std::unique_ptr<base::ListValue> results = 81 std::unique_ptr<base::ListValue> results =
80 crossref::GetTestType::Results::Create(*test_type); 82 crossref::GetTestType::Results::Create(*test_type);
81 base::DictionaryValue* result_dict = NULL; 83 base::DictionaryValue* result_dict = NULL;
82 results->GetDictionary(0, &result_dict); 84 results->GetDictionary(0, &result_dict);
83 EXPECT_TRUE(value->Equals(result_dict)); 85 EXPECT_TRUE(value->Equals(result_dict));
84 } 86 }
85 87
86 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { 88 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
87 { 89 {
88 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 90 auto params_value = base::MakeUnique<base::ListValue>();
89 std::unique_ptr<base::DictionaryValue> param_object_value( 91 auto param_object_value = base::MakeUnique<base::DictionaryValue>();
90 new base::DictionaryValue()); 92 param_object_value->Set("testType", CreateTestTypeValue());
91 param_object_value->Set("testType", CreateTestTypeValue().release()); 93 param_object_value->SetBoolean("boolean", true);
92 param_object_value->Set("boolean", new base::Value(true));
93 params_value->Append(std::move(param_object_value)); 94 params_value->Append(std::move(param_object_value));
94 std::unique_ptr<crossref::TestTypeInObject::Params> params( 95 std::unique_ptr<crossref::TestTypeInObject::Params> params(
95 crossref::TestTypeInObject::Params::Create(*params_value)); 96 crossref::TestTypeInObject::Params::Create(*params_value));
96 EXPECT_TRUE(params.get()); 97 EXPECT_TRUE(params.get());
97 EXPECT_TRUE(params->param_object.test_type.get()); 98 EXPECT_TRUE(params->param_object.test_type.get());
98 EXPECT_TRUE(params->param_object.boolean); 99 EXPECT_TRUE(params->param_object.boolean);
99 EXPECT_TRUE(CreateTestTypeValue()->Equals( 100 EXPECT_TRUE(CreateTestTypeValue()->Equals(
100 params->param_object.test_type->ToValue().get())); 101 params->param_object.test_type->ToValue().get()));
101 } 102 }
102 { 103 {
103 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 104 auto params_value = base::MakeUnique<base::ListValue>();
104 std::unique_ptr<base::DictionaryValue> param_object_value( 105 auto param_object_value = base::MakeUnique<base::DictionaryValue>();
105 new base::DictionaryValue()); 106 param_object_value->SetBoolean("boolean", true);
106 param_object_value->Set("boolean", new base::Value(true));
107 params_value->Append(std::move(param_object_value)); 107 params_value->Append(std::move(param_object_value));
108 std::unique_ptr<crossref::TestTypeInObject::Params> params( 108 std::unique_ptr<crossref::TestTypeInObject::Params> params(
109 crossref::TestTypeInObject::Params::Create(*params_value)); 109 crossref::TestTypeInObject::Params::Create(*params_value));
110 EXPECT_TRUE(params.get()); 110 EXPECT_TRUE(params.get());
111 EXPECT_FALSE(params->param_object.test_type.get()); 111 EXPECT_FALSE(params->param_object.test_type.get());
112 EXPECT_TRUE(params->param_object.boolean); 112 EXPECT_TRUE(params->param_object.boolean);
113 } 113 }
114 { 114 {
115 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 115 auto params_value = base::MakeUnique<base::ListValue>();
116 std::unique_ptr<base::DictionaryValue> param_object_value( 116 auto param_object_value = base::MakeUnique<base::DictionaryValue>();
117 new base::DictionaryValue()); 117 param_object_value->SetString("testType", "invalid");
118 param_object_value->Set("testType", new base::Value("invalid")); 118 param_object_value->SetBoolean("boolean", true);
119 param_object_value->Set("boolean", new base::Value(true));
120 params_value->Append(std::move(param_object_value)); 119 params_value->Append(std::move(param_object_value));
121 std::unique_ptr<crossref::TestTypeInObject::Params> params( 120 std::unique_ptr<crossref::TestTypeInObject::Params> params(
122 crossref::TestTypeInObject::Params::Create(*params_value)); 121 crossref::TestTypeInObject::Params::Create(*params_value));
123 EXPECT_FALSE(params.get()); 122 EXPECT_FALSE(params.get());
124 } 123 }
125 { 124 {
126 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 125 auto params_value = base::MakeUnique<base::ListValue>();
127 std::unique_ptr<base::DictionaryValue> param_object_value( 126 auto param_object_value = base::MakeUnique<base::DictionaryValue>();
128 new base::DictionaryValue()); 127 param_object_value->Set("testType", CreateTestTypeValue());
129 param_object_value->Set("testType", CreateTestTypeValue().release());
130 params_value->Append(std::move(param_object_value)); 128 params_value->Append(std::move(param_object_value));
131 std::unique_ptr<crossref::TestTypeInObject::Params> params( 129 std::unique_ptr<crossref::TestTypeInObject::Params> params(
132 crossref::TestTypeInObject::Params::Create(*params_value)); 130 crossref::TestTypeInObject::Params::Create(*params_value));
133 EXPECT_FALSE(params.get()); 131 EXPECT_FALSE(params.get());
134 } 132 }
135 } 133 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/choices_unittest.cc ('k') | tools/json_schema_compiler/test/enums_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698