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

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

Issue 2036013002: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « tools/json_schema_compiler/test/objects_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/simple_api.h" 5 #include "tools/json_schema_compiler/test/simple_api.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 using namespace test::api::simple_api; 9 using namespace test::api::simple_api;
10 10
11 namespace { 11 namespace {
12 12
13 static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() { 13 static std::unique_ptr<base::DictionaryValue> CreateTestTypeDictionary() {
14 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 14 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
15 value->SetWithoutPathExpansion("number", new base::FundamentalValue(1.1)); 15 value->SetWithoutPathExpansion("number", new base::FundamentalValue(1.1));
16 value->SetWithoutPathExpansion("integer", new base::FundamentalValue(4)); 16 value->SetWithoutPathExpansion("integer", new base::FundamentalValue(4));
17 value->SetWithoutPathExpansion("string", new base::StringValue("bling")); 17 value->SetWithoutPathExpansion("string", new base::StringValue("bling"));
18 value->SetWithoutPathExpansion("boolean", new base::FundamentalValue(true)); 18 value->SetWithoutPathExpansion("boolean", new base::FundamentalValue(true));
19 return value; 19 return value;
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { 24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) {
25 std::unique_ptr<base::ListValue> results = 25 std::unique_ptr<base::ListValue> results =
26 IncrementInteger::Results::Create(5); 26 IncrementInteger::Results::Create(5);
27 base::ListValue expected; 27 base::ListValue expected;
28 expected.Append(new base::FundamentalValue(5)); 28 expected.AppendInteger(5);
29 EXPECT_TRUE(results->Equals(&expected)); 29 EXPECT_TRUE(results->Equals(&expected));
30 } 30 }
31 31
32 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { 32 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) {
33 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 33 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
34 params_value->Append(new base::FundamentalValue(6)); 34 params_value->AppendInteger(6);
35 std::unique_ptr<IncrementInteger::Params> params( 35 std::unique_ptr<IncrementInteger::Params> params(
36 IncrementInteger::Params::Create(*params_value)); 36 IncrementInteger::Params::Create(*params_value));
37 EXPECT_TRUE(params.get()); 37 EXPECT_TRUE(params.get());
38 EXPECT_EQ(6, params->num); 38 EXPECT_EQ(6, params->num);
39 } 39 }
40 40
41 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { 41 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) {
42 { 42 {
43 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 43 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
44 params_value->Append(new base::StringValue("text")); 44 params_value->AppendString("text");
45 params_value->Append(new base::StringValue("text")); 45 params_value->AppendString("text");
46 std::unique_ptr<OptionalString::Params> params( 46 std::unique_ptr<OptionalString::Params> params(
47 OptionalString::Params::Create(*params_value)); 47 OptionalString::Params::Create(*params_value));
48 EXPECT_FALSE(params.get()); 48 EXPECT_FALSE(params.get());
49 } 49 }
50 { 50 {
51 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 51 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
52 std::unique_ptr<IncrementInteger::Params> params( 52 std::unique_ptr<IncrementInteger::Params> params(
53 IncrementInteger::Params::Create(*params_value)); 53 IncrementInteger::Params::Create(*params_value));
54 EXPECT_FALSE(params.get()); 54 EXPECT_FALSE(params.get());
55 } 55 }
56 } 56 }
57 57
58 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { 58 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) {
59 { 59 {
60 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 60 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
61 std::unique_ptr<OptionalString::Params> params( 61 std::unique_ptr<OptionalString::Params> params(
62 OptionalString::Params::Create(*params_value)); 62 OptionalString::Params::Create(*params_value));
63 EXPECT_TRUE(params.get()); 63 EXPECT_TRUE(params.get());
64 EXPECT_FALSE(params->str.get()); 64 EXPECT_FALSE(params->str.get());
65 } 65 }
66 { 66 {
67 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 67 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
68 params_value->Append(new base::StringValue("asdf")); 68 params_value->AppendString("asdf");
69 std::unique_ptr<OptionalString::Params> params( 69 std::unique_ptr<OptionalString::Params> params(
70 OptionalString::Params::Create(*params_value)); 70 OptionalString::Params::Create(*params_value));
71 EXPECT_TRUE(params.get()); 71 EXPECT_TRUE(params.get());
72 EXPECT_TRUE(params->str.get()); 72 EXPECT_TRUE(params->str.get());
73 EXPECT_EQ("asdf", *params->str); 73 EXPECT_EQ("asdf", *params->str);
74 } 74 }
75 } 75 }
76 76
77 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { 77 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) {
78 { 78 {
79 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 79 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
80 params_value->Append(base::Value::CreateNullValue()); 80 params_value->Append(base::Value::CreateNullValue());
81 std::unique_ptr<OptionalString::Params> params( 81 std::unique_ptr<OptionalString::Params> params(
82 OptionalString::Params::Create(*params_value)); 82 OptionalString::Params::Create(*params_value));
83 EXPECT_TRUE(params.get()); 83 EXPECT_TRUE(params.get());
84 EXPECT_FALSE(params->str.get()); 84 EXPECT_FALSE(params->str.get());
85 } 85 }
86 } 86 }
87 87
88 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) { 88 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) {
89 { 89 {
90 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 90 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
91 params_value->Append(new base::FundamentalValue(5)); 91 params_value->AppendInteger(5);
92 std::unique_ptr<OptionalString::Params> params( 92 std::unique_ptr<OptionalString::Params> params(
93 OptionalString::Params::Create(*params_value)); 93 OptionalString::Params::Create(*params_value));
94 EXPECT_FALSE(params.get()); 94 EXPECT_FALSE(params.get());
95 } 95 }
96 } 96 }
97 97
98 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { 98 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) {
99 { 99 {
100 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 100 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
101 params_value->Append(base::Value::CreateNullValue()); 101 params_value->Append(base::Value::CreateNullValue());
102 params_value->Append(new base::StringValue("asdf")); 102 params_value->AppendString("asdf");
103 std::unique_ptr<OptionalBeforeRequired::Params> params( 103 std::unique_ptr<OptionalBeforeRequired::Params> params(
104 OptionalBeforeRequired::Params::Create(*params_value)); 104 OptionalBeforeRequired::Params::Create(*params_value));
105 EXPECT_TRUE(params.get()); 105 EXPECT_TRUE(params.get());
106 EXPECT_FALSE(params->first.get()); 106 EXPECT_FALSE(params->first.get());
107 EXPECT_EQ("asdf", params->second); 107 EXPECT_EQ("asdf", params->second);
108 } 108 }
109 } 109 }
110 110
111 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { 111 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) {
112 std::unique_ptr<base::ListValue> results = OptionalString::Results::Create(); 112 std::unique_ptr<base::ListValue> results = OptionalString::Results::Create();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 base::DictionaryValue* result = NULL; 144 base::DictionaryValue* result = NULL;
145 results->GetDictionary(0, &result); 145 results->GetDictionary(0, &result);
146 EXPECT_TRUE(result->Equals(value.get())); 146 EXPECT_TRUE(result->Equals(value.get()));
147 } 147 }
148 } 148 }
149 149
150 TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { 150 TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) {
151 { 151 {
152 std::unique_ptr<base::ListValue> results(OnIntegerFired::Create(5)); 152 std::unique_ptr<base::ListValue> results(OnIntegerFired::Create(5));
153 base::ListValue expected; 153 base::ListValue expected;
154 expected.Append(new base::FundamentalValue(5)); 154 expected.AppendInteger(5);
155 EXPECT_TRUE(results->Equals(&expected)); 155 EXPECT_TRUE(results->Equals(&expected));
156 } 156 }
157 } 157 }
158 158
159 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { 159 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) {
160 { 160 {
161 std::unique_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); 161 std::unique_ptr<base::ListValue> results(OnStringFired::Create("yo dawg"));
162 base::ListValue expected; 162 base::ListValue expected;
163 expected.Append(new base::StringValue("yo dawg")); 163 expected.AppendString("yo dawg");
164 EXPECT_TRUE(results->Equals(&expected)); 164 EXPECT_TRUE(results->Equals(&expected));
165 } 165 }
166 } 166 }
167 167
168 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { 168 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) {
169 { 169 {
170 TestType some_test_type; 170 TestType some_test_type;
171 std::unique_ptr<base::DictionaryValue> expected = 171 std::unique_ptr<base::DictionaryValue> expected =
172 CreateTestTypeDictionary(); 172 CreateTestTypeDictionary();
173 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); 173 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number));
174 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); 174 ASSERT_TRUE(expected->GetString("string", &some_test_type.string));
175 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); 175 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer));
176 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); 176 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean));
177 177
178 std::unique_ptr<base::ListValue> results( 178 std::unique_ptr<base::ListValue> results(
179 OnTestTypeFired::Create(some_test_type)); 179 OnTestTypeFired::Create(some_test_type));
180 base::DictionaryValue* result = NULL; 180 base::DictionaryValue* result = NULL;
181 results->GetDictionary(0, &result); 181 results->GetDictionary(0, &result);
182 EXPECT_TRUE(result->Equals(expected.get())); 182 EXPECT_TRUE(result->Equals(expected.get()));
183 } 183 }
184 } 184 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/objects_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698