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

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

Issue 9456007: Add wider support to json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: reupload Created 8 years, 9 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/array.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 8
9 using namespace test::api::array; 9 using namespace test::api::arrays;
10 10
11 namespace { 11 namespace {
12 12
13 // TODO(calamity): Change to AppendString etc once kalman's patch goes through 13 // TODO(calamity): Change to AppendString etc once kalman's patch goes through
14 static scoped_ptr<DictionaryValue> CreateBasicArrayTypeDictionary() { 14 static scoped_ptr<DictionaryValue> CreateBasicArrayTypeDictionary() {
15 DictionaryValue* value = new DictionaryValue(); 15 DictionaryValue* value = new DictionaryValue();
16 ListValue* strings_value = new ListValue(); 16 ListValue* strings_value = new ListValue();
17 strings_value->Append(Value::CreateStringValue("a")); 17 strings_value->Append(Value::CreateStringValue("a"));
18 strings_value->Append(Value::CreateStringValue("b")); 18 strings_value->Append(Value::CreateStringValue("b"));
19 strings_value->Append(Value::CreateStringValue("c")); 19 strings_value->Append(Value::CreateStringValue("c"));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 TEST(JsonSchemaCompilerArrayTest, RefArrayType) { 54 TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
55 { 55 {
56 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 56 scoped_ptr<DictionaryValue> value(new DictionaryValue());
57 scoped_ptr<ListValue> ref_array(new ListValue()); 57 scoped_ptr<ListValue> ref_array(new ListValue());
58 ref_array->Append(CreateItemValue(1)); 58 ref_array->Append(CreateItemValue(1));
59 ref_array->Append(CreateItemValue(2)); 59 ref_array->Append(CreateItemValue(2));
60 ref_array->Append(CreateItemValue(3)); 60 ref_array->Append(CreateItemValue(3));
61 value->Set("refs", ref_array.release()); 61 value->Set("refs", ref_array.release());
62 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType()); 62 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
63 EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get())); 63 EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get()));
64 EXPECT_EQ(3UL, ref_array_type->refs.size()); 64 EXPECT_EQ((size_t) 3, ref_array_type->refs.size());
65 EXPECT_EQ(1, ref_array_type->refs[0]->val); 65 EXPECT_EQ(1, ref_array_type->refs[0]->val);
66 EXPECT_EQ(2, ref_array_type->refs[1]->val); 66 EXPECT_EQ(2, ref_array_type->refs[1]->val);
67 EXPECT_EQ(3, ref_array_type->refs[2]->val); 67 EXPECT_EQ(3, ref_array_type->refs[2]->val);
68 } 68 }
69 { 69 {
70 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 70 scoped_ptr<DictionaryValue> value(new DictionaryValue());
71 scoped_ptr<ListValue> not_ref_array(new ListValue()); 71 scoped_ptr<ListValue> not_ref_array(new ListValue());
72 not_ref_array->Append(CreateItemValue(1)); 72 not_ref_array->Append(CreateItemValue(1));
73 not_ref_array->Append(Value::CreateIntegerValue(3)); 73 not_ref_array->Append(Value::CreateIntegerValue(3));
74 value->Set("refs", not_ref_array.release()); 74 value->Set("refs", not_ref_array.release());
75 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType()); 75 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
76 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get())); 76 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get()));
77 } 77 }
78 } 78 }
79 79
80 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) { 80 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
81 scoped_ptr<ListValue> params_value(new ListValue()); 81 scoped_ptr<ListValue> params_value(new ListValue());
82 scoped_ptr<ListValue> integer_array(new ListValue()); 82 scoped_ptr<ListValue> integer_array(new ListValue());
83 integer_array->Append(Value::CreateIntegerValue(2)); 83 integer_array->Append(Value::CreateIntegerValue(2));
84 integer_array->Append(Value::CreateIntegerValue(4)); 84 integer_array->Append(Value::CreateIntegerValue(4));
85 integer_array->Append(Value::CreateIntegerValue(8)); 85 integer_array->Append(Value::CreateIntegerValue(8));
86 params_value->Append(integer_array.release()); 86 params_value->Append(integer_array.release());
87 scoped_ptr<IntegerArray::Params> params( 87 scoped_ptr<IntegerArray::Params> params(
88 IntegerArray::Params::Create(*params_value)); 88 IntegerArray::Params::Create(*params_value));
89 EXPECT_TRUE(params.get()); 89 EXPECT_TRUE(params.get());
90 EXPECT_EQ(3UL, params->nums.size()); 90 EXPECT_EQ((size_t) 3, params->nums.size());
91 EXPECT_EQ(2, params->nums[0]); 91 EXPECT_EQ(2, params->nums[0]);
92 EXPECT_EQ(4, params->nums[1]); 92 EXPECT_EQ(4, params->nums[1]);
93 EXPECT_EQ(8, params->nums[2]); 93 EXPECT_EQ(8, params->nums[2]);
94 } 94 }
95 95
96 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) { 96 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) {
97 scoped_ptr<ListValue> params_value(new ListValue()); 97 scoped_ptr<ListValue> params_value(new ListValue());
98 scoped_ptr<ListValue> item_array(new ListValue()); 98 scoped_ptr<ListValue> item_array(new ListValue());
99 item_array->Append(CreateItemValue(1)); 99 item_array->Append(CreateItemValue(1));
100 item_array->Append(CreateItemValue(2)); 100 item_array->Append(CreateItemValue(2));
101 params_value->Append(item_array.release()); 101 params_value->Append(item_array.release());
102 scoped_ptr<RefArray::Params> params( 102 scoped_ptr<RefArray::Params> params(
103 RefArray::Params::Create(*params_value)); 103 RefArray::Params::Create(*params_value));
104 EXPECT_TRUE(params.get()); 104 EXPECT_TRUE(params.get());
105 EXPECT_EQ(2UL, params->refs.size()); 105 EXPECT_EQ((size_t) 2, params->refs.size());
106 EXPECT_EQ(1, params->refs[0]->val); 106 EXPECT_EQ(1, params->refs[0]->val);
107 EXPECT_EQ(2, params->refs[1]->val); 107 EXPECT_EQ(2, params->refs[1]->val);
108 } 108 }
109 109
110 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) { 110 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) {
111 std::vector<int> integers; 111 std::vector<int> integers;
112 integers.push_back(1); 112 integers.push_back(1);
113 integers.push_back(2); 113 integers.push_back(2);
114 scoped_ptr<Value> result(ReturnIntegerArray::Result::Create(integers)); 114 scoped_ptr<Value> result(ReturnIntegerArray::Result::Create(integers));
115 ListValue* list = NULL; 115 ListValue* list = NULL;
116 EXPECT_TRUE(result->GetAsList(&list)); 116 EXPECT_TRUE(result->GetAsList(&list));
117 int temp; 117 int temp;
118 EXPECT_EQ(2UL, list->GetSize()); 118 EXPECT_EQ((size_t) 2, list->GetSize());
119 EXPECT_TRUE(list->GetInteger(0, &temp)); 119 EXPECT_TRUE(list->GetInteger(0, &temp));
120 EXPECT_EQ(1, temp); 120 EXPECT_EQ(1, temp);
121 EXPECT_TRUE(list->GetInteger(1, &temp)); 121 EXPECT_TRUE(list->GetInteger(1, &temp));
122 EXPECT_EQ(2, temp); 122 EXPECT_EQ(2, temp);
123 } 123 }
124 124
125 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) { 125 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) {
126 std::vector<linked_ptr<Item> > items; 126 std::vector<linked_ptr<Item> > items;
127 items.push_back(linked_ptr<Item>(new Item())); 127 items.push_back(linked_ptr<Item>(new Item()));
128 items.push_back(linked_ptr<Item>(new Item())); 128 items.push_back(linked_ptr<Item>(new Item()));
129 items[0]->val = 1; 129 items[0]->val = 1;
130 items[1]->val = 2; 130 items[1]->val = 2;
131 scoped_ptr<Value> result(ReturnRefArray::Result::Create(items)); 131 scoped_ptr<Value> result(ReturnRefArray::Result::Create(items));
132 ListValue* list = NULL; 132 ListValue* list = NULL;
133 EXPECT_TRUE(result->GetAsList(&list)); 133 EXPECT_TRUE(result->GetAsList(&list));
134 EXPECT_EQ(2UL, list->GetSize()); 134 EXPECT_EQ((size_t) 2, list->GetSize());
135 DictionaryValue* item_value = NULL; 135 DictionaryValue* item_value = NULL;
136 int temp; 136 int temp;
137 EXPECT_TRUE(list->GetDictionary(0, &item_value)); 137 EXPECT_TRUE(list->GetDictionary(0, &item_value));
138 EXPECT_TRUE(item_value->GetInteger("val", &temp)); 138 EXPECT_TRUE(item_value->GetInteger("val", &temp));
139 EXPECT_EQ(1, temp); 139 EXPECT_EQ(1, temp);
140 EXPECT_TRUE(list->GetDictionary(1, &item_value)); 140 EXPECT_TRUE(list->GetDictionary(1, &item_value));
141 EXPECT_TRUE(item_value->GetInteger("val", &temp)); 141 EXPECT_TRUE(item_value->GetInteger("val", &temp));
142 EXPECT_EQ(2, temp); 142 EXPECT_EQ(2, temp);
143 } 143 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/arrays.json ('k') | tools/json_schema_compiler/test/choices_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698