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

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

Issue 383263005: Remove more CreateIntegerValue calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/SetBoolean/SetInteger Created 6 years, 5 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 | Annotate | Revision Log
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/arrays.h" 5 #include "tools/json_schema_compiler/test/arrays.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "tools/json_schema_compiler/test/enums.h" 8 #include "tools/json_schema_compiler/test/enums.h"
9 9
10 using namespace test::api::arrays; 10 using namespace test::api::arrays;
11 11
12 namespace { 12 namespace {
13 13
14 // TODO(calamity): Change to AppendString etc once kalman's patch goes through 14 // TODO(calamity): Change to AppendString etc once kalman's patch goes through
15 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() { 15 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() {
16 base::DictionaryValue* value = new base::DictionaryValue(); 16 base::DictionaryValue* value = new base::DictionaryValue();
17 base::ListValue* strings_value = new base::ListValue(); 17 base::ListValue* strings_value = new base::ListValue();
18 strings_value->Append(base::Value::CreateStringValue("a")); 18 strings_value->Append(base::Value::CreateStringValue("a"));
19 strings_value->Append(base::Value::CreateStringValue("b")); 19 strings_value->Append(base::Value::CreateStringValue("b"));
20 strings_value->Append(base::Value::CreateStringValue("c")); 20 strings_value->Append(base::Value::CreateStringValue("c"));
21 strings_value->Append(base::Value::CreateStringValue("it's easy as")); 21 strings_value->Append(base::Value::CreateStringValue("it's easy as"));
22 base::ListValue* integers_value = new base::ListValue(); 22 base::ListValue* integers_value = new base::ListValue();
23 integers_value->Append(base::Value::CreateIntegerValue(1)); 23 integers_value->Append(new base::FundamentalValue(1));
24 integers_value->Append(base::Value::CreateIntegerValue(2)); 24 integers_value->Append(new base::FundamentalValue(2));
25 integers_value->Append(base::Value::CreateIntegerValue(3)); 25 integers_value->Append(new base::FundamentalValue(3));
26 base::ListValue* booleans_value = new base::ListValue(); 26 base::ListValue* booleans_value = new base::ListValue();
27 booleans_value->Append(base::Value::CreateBooleanValue(false)); 27 booleans_value->Append(base::Value::CreateBooleanValue(false));
28 booleans_value->Append(base::Value::CreateBooleanValue(true)); 28 booleans_value->Append(base::Value::CreateBooleanValue(true));
29 base::ListValue* numbers_value = new base::ListValue(); 29 base::ListValue* numbers_value = new base::ListValue();
30 numbers_value->Append(base::Value::CreateDoubleValue(6.1)); 30 numbers_value->Append(base::Value::CreateDoubleValue(6.1));
31 value->Set("numbers", numbers_value); 31 value->Set("numbers", numbers_value);
32 value->Set("booleans", booleans_value); 32 value->Set("booleans", booleans_value);
33 value->Set("strings", strings_value); 33 value->Set("strings", strings_value);
34 value->Set("integers", integers_value); 34 value->Set("integers", integers_value);
35 return scoped_ptr<base::DictionaryValue>(value); 35 return scoped_ptr<base::DictionaryValue>(value);
36 } 36 }
37 37
38 static base::Value* CreateItemValue(int val) { 38 static base::Value* CreateItemValue(int val) {
39 base::DictionaryValue* value(new base::DictionaryValue()); 39 base::DictionaryValue* value(new base::DictionaryValue());
40 value->Set("val", base::Value::CreateIntegerValue(val)); 40 value->Set("val", new base::FundamentalValue(val));
41 return value; 41 return value;
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { 46 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
47 { 47 {
48 scoped_ptr<base::DictionaryValue> value = CreateBasicArrayTypeDictionary(); 48 scoped_ptr<base::DictionaryValue> value = CreateBasicArrayTypeDictionary();
49 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType()); 49 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
50 ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get())); 50 ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get())); 206 EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get()));
207 ASSERT_EQ(3u, ref_array_type->refs.size()); 207 ASSERT_EQ(3u, ref_array_type->refs.size());
208 EXPECT_EQ(1, ref_array_type->refs[0]->val); 208 EXPECT_EQ(1, ref_array_type->refs[0]->val);
209 EXPECT_EQ(2, ref_array_type->refs[1]->val); 209 EXPECT_EQ(2, ref_array_type->refs[1]->val);
210 EXPECT_EQ(3, ref_array_type->refs[2]->val); 210 EXPECT_EQ(3, ref_array_type->refs[2]->val);
211 } 211 }
212 { 212 {
213 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); 213 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
214 scoped_ptr<base::ListValue> not_ref_array(new base::ListValue()); 214 scoped_ptr<base::ListValue> not_ref_array(new base::ListValue());
215 not_ref_array->Append(CreateItemValue(1)); 215 not_ref_array->Append(CreateItemValue(1));
216 not_ref_array->Append(base::Value::CreateIntegerValue(3)); 216 not_ref_array->Append(new base::FundamentalValue(3));
217 value->Set("refs", not_ref_array.release()); 217 value->Set("refs", not_ref_array.release());
218 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType()); 218 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
219 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get())); 219 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get()));
220 } 220 }
221 } 221 }
222 222
223 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) { 223 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
224 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 224 scoped_ptr<base::ListValue> params_value(new base::ListValue());
225 scoped_ptr<base::ListValue> integer_array(new base::ListValue()); 225 scoped_ptr<base::ListValue> integer_array(new base::ListValue());
226 integer_array->Append(base::Value::CreateIntegerValue(2)); 226 integer_array->Append(new base::FundamentalValue(2));
227 integer_array->Append(base::Value::CreateIntegerValue(4)); 227 integer_array->Append(new base::FundamentalValue(4));
228 integer_array->Append(base::Value::CreateIntegerValue(8)); 228 integer_array->Append(new base::FundamentalValue(8));
229 params_value->Append(integer_array.release()); 229 params_value->Append(integer_array.release());
230 scoped_ptr<IntegerArray::Params> params( 230 scoped_ptr<IntegerArray::Params> params(
231 IntegerArray::Params::Create(*params_value)); 231 IntegerArray::Params::Create(*params_value));
232 EXPECT_TRUE(params.get()); 232 EXPECT_TRUE(params.get());
233 ASSERT_EQ(3u, params->nums.size()); 233 ASSERT_EQ(3u, params->nums.size());
234 EXPECT_EQ(2, params->nums[0]); 234 EXPECT_EQ(2, params->nums[0]);
235 EXPECT_EQ(4, params->nums[1]); 235 EXPECT_EQ(4, params->nums[1]);
236 EXPECT_EQ(8, params->nums[2]); 236 EXPECT_EQ(8, params->nums[2]);
237 } 237 }
238 238
239 TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) { 239 TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) {
240 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 240 scoped_ptr<base::ListValue> params_value(new base::ListValue());
241 scoped_ptr<base::ListValue> any_array(new base::ListValue()); 241 scoped_ptr<base::ListValue> any_array(new base::ListValue());
242 any_array->Append(base::Value::CreateIntegerValue(1)); 242 any_array->Append(new base::FundamentalValue(1));
243 any_array->Append(base::Value::CreateStringValue("test")); 243 any_array->Append(base::Value::CreateStringValue("test"));
244 any_array->Append(CreateItemValue(2)); 244 any_array->Append(CreateItemValue(2));
245 params_value->Append(any_array.release()); 245 params_value->Append(any_array.release());
246 scoped_ptr<AnyArray::Params> params( 246 scoped_ptr<AnyArray::Params> params(
247 AnyArray::Params::Create(*params_value)); 247 AnyArray::Params::Create(*params_value));
248 EXPECT_TRUE(params.get()); 248 EXPECT_TRUE(params.get());
249 ASSERT_EQ(3u, params->anys.size()); 249 ASSERT_EQ(3u, params->anys.size());
250 int int_temp = 0; 250 int int_temp = 0;
251 EXPECT_TRUE(params->anys[0]->GetAsInteger(&int_temp)); 251 EXPECT_TRUE(params->anys[0]->GetAsInteger(&int_temp));
252 EXPECT_EQ(1, int_temp); 252 EXPECT_EQ(1, int_temp);
(...skipping 29 matching lines...) Expand all
282 282
283 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) { 283 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) {
284 std::vector<int> integers; 284 std::vector<int> integers;
285 integers.push_back(1); 285 integers.push_back(1);
286 integers.push_back(2); 286 integers.push_back(2);
287 scoped_ptr<base::ListValue> results = 287 scoped_ptr<base::ListValue> results =
288 ReturnIntegerArray::Results::Create(integers); 288 ReturnIntegerArray::Results::Create(integers);
289 289
290 base::ListValue expected; 290 base::ListValue expected;
291 base::ListValue* expected_argument = new base::ListValue(); 291 base::ListValue* expected_argument = new base::ListValue();
292 expected_argument->Append(base::Value::CreateIntegerValue(1)); 292 expected_argument->Append(new base::FundamentalValue(1));
293 expected_argument->Append(base::Value::CreateIntegerValue(2)); 293 expected_argument->Append(new base::FundamentalValue(2));
294 expected.Append(expected_argument); 294 expected.Append(expected_argument);
295 EXPECT_TRUE(results->Equals(&expected)); 295 EXPECT_TRUE(results->Equals(&expected));
296 } 296 }
297 297
298 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) { 298 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) {
299 std::vector<linked_ptr<Item> > items; 299 std::vector<linked_ptr<Item> > items;
300 items.push_back(linked_ptr<Item>(new Item())); 300 items.push_back(linked_ptr<Item>(new Item()));
301 items.push_back(linked_ptr<Item>(new Item())); 301 items.push_back(linked_ptr<Item>(new Item()));
302 items[0]->val = 1; 302 items[0]->val = 1;
303 items[1]->val = 2; 303 items[1]->val = 2;
304 scoped_ptr<base::ListValue> results = 304 scoped_ptr<base::ListValue> results =
305 ReturnRefArray::Results::Create(items); 305 ReturnRefArray::Results::Create(items);
306 306
307 base::ListValue expected; 307 base::ListValue expected;
308 base::ListValue* expected_argument = new base::ListValue(); 308 base::ListValue* expected_argument = new base::ListValue();
309 base::DictionaryValue* first = new base::DictionaryValue(); 309 base::DictionaryValue* first = new base::DictionaryValue();
310 first->SetInteger("val", 1); 310 first->SetInteger("val", 1);
311 expected_argument->Append(first); 311 expected_argument->Append(first);
312 base::DictionaryValue* second = new base::DictionaryValue(); 312 base::DictionaryValue* second = new base::DictionaryValue();
313 second->SetInteger("val", 2); 313 second->SetInteger("val", 2);
314 expected_argument->Append(second); 314 expected_argument->Append(second);
315 expected.Append(expected_argument); 315 expected.Append(expected_argument);
316 EXPECT_TRUE(results->Equals(&expected)); 316 EXPECT_TRUE(results->Equals(&expected));
317 } 317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698