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

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

Issue 11827026: Overhaul JSON Schema Compiler to support a number of features required to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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 8
9 using namespace test::api::arrays; 9 using namespace test::api::arrays;
10 10
(...skipping 28 matching lines...) Expand all
39 value->Set("val", Value::CreateIntegerValue(val)); 39 value->Set("val", Value::CreateIntegerValue(val));
40 return value; 40 return value;
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { 45 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
46 { 46 {
47 scoped_ptr<DictionaryValue> value = CreateBasicArrayTypeDictionary(); 47 scoped_ptr<DictionaryValue> value = CreateBasicArrayTypeDictionary();
48 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType()); 48 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
49 EXPECT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get())); 49 ASSERT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
50 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get())); 50 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get()));
51 } 51 }
52 } 52 }
53 53
54 TEST(JsonSchemaCompilerArrayTest, EnumArrayType) { 54 TEST(JsonSchemaCompilerArrayTest, EnumArrayType) {
55 std::vector<EnumArrayType::TypesElement> enums; 55 std::vector<EnumArrayType::TypesType> enums;
56 enums.push_back(EnumArrayType::TYPES_ELEMENT_ONE); 56 enums.push_back(EnumArrayType::TYPES_TYPE_ONE);
57 enums.push_back(EnumArrayType::TYPES_ELEMENT_TWO); 57 enums.push_back(EnumArrayType::TYPES_TYPE_TWO);
58 enums.push_back(EnumArrayType::TYPES_ELEMENT_THREE); 58 enums.push_back(EnumArrayType::TYPES_TYPE_THREE);
59 59
60 scoped_ptr<ListValue> types(new ListValue()); 60 scoped_ptr<ListValue> types(new ListValue());
61 for (size_t i = 0; i < enums.size(); ++i) 61 for (size_t i = 0; i < enums.size(); ++i)
62 types->Append(EnumArrayType::CreateEnumValue(enums[i]).release()); 62 types->Append(new base::StringValue(EnumArrayType::ToString(enums[i])));
63 63
64 DictionaryValue value; 64 DictionaryValue value;
65 value.Set("types", types.release()); 65 value.Set("types", types.release());
66 66
67 EnumArrayType enum_array_type; 67 EnumArrayType enum_array_type;
68 EXPECT_TRUE(EnumArrayType::Populate(value, &enum_array_type)); 68 ASSERT_TRUE(EnumArrayType::Populate(value, &enum_array_type));
69 EXPECT_EQ(enums, enum_array_type.types); 69 EXPECT_EQ(enums, enum_array_type.types);
70 } 70 }
71 71
72 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { 72 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
73 { 73 {
74 std::vector<OptionalEnumArrayType::TypesElement> enums; 74 std::vector<OptionalEnumArrayType::TypesType> enums;
75 enums.push_back(OptionalEnumArrayType::TYPES_ELEMENT_ONE); 75 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE);
76 enums.push_back(OptionalEnumArrayType::TYPES_ELEMENT_TWO); 76 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO);
77 enums.push_back(OptionalEnumArrayType::TYPES_ELEMENT_THREE); 77 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE);
78 78
79 scoped_ptr<ListValue> types(new ListValue()); 79 scoped_ptr<ListValue> types(new ListValue());
80 for (size_t i = 0; i < enums.size(); ++i) 80 for (size_t i = 0; i < enums.size(); ++i) {
81 types->Append(OptionalEnumArrayType::CreateEnumValue(enums[i]).release()); 81 types->Append(new base::StringValue(
82 OptionalEnumArrayType::ToString(enums[i])));
83 }
82 84
83 DictionaryValue value; 85 DictionaryValue value;
84 value.Set("types", types.release()); 86 value.Set("types", types.release());
85 87
86 OptionalEnumArrayType enum_array_type; 88 OptionalEnumArrayType enum_array_type;
87 EXPECT_TRUE(OptionalEnumArrayType::Populate(value, &enum_array_type)); 89 ASSERT_TRUE(OptionalEnumArrayType::Populate(value, &enum_array_type));
88 EXPECT_EQ(enums, *enum_array_type.types); 90 EXPECT_EQ(enums, *enum_array_type.types);
89 } 91 }
90 { 92 {
91 DictionaryValue value; 93 DictionaryValue value;
92 scoped_ptr<ListValue> enum_array(new ListValue()); 94 scoped_ptr<ListValue> enum_array(new ListValue());
93 enum_array->Append(Value::CreateStringValue("invalid")); 95 enum_array->Append(Value::CreateStringValue("invalid"));
94 96
95 value.Set("types", enum_array.release()); 97 value.Set("types", enum_array.release());
96 OptionalEnumArrayType enum_array_type; 98 OptionalEnumArrayType enum_array_type;
97 EXPECT_FALSE(OptionalEnumArrayType::Populate(value, &enum_array_type)); 99 ASSERT_FALSE(OptionalEnumArrayType::Populate(value, &enum_array_type));
98 EXPECT_TRUE(enum_array_type.types->empty()); 100 EXPECT_TRUE(enum_array_type.types->empty());
99 } 101 }
100 } 102 }
101 103
102 TEST(JsonSchemaCompilerArrayTest, RefArrayType) { 104 TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
103 { 105 {
104 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 106 scoped_ptr<DictionaryValue> value(new DictionaryValue());
105 scoped_ptr<ListValue> ref_array(new ListValue()); 107 scoped_ptr<ListValue> ref_array(new ListValue());
106 ref_array->Append(CreateItemValue(1)); 108 ref_array->Append(CreateItemValue(1));
107 ref_array->Append(CreateItemValue(2)); 109 ref_array->Append(CreateItemValue(2));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 scoped_ptr<ListValue> any_array(new ListValue()); 148 scoped_ptr<ListValue> any_array(new ListValue());
147 any_array->Append(Value::CreateIntegerValue(1)); 149 any_array->Append(Value::CreateIntegerValue(1));
148 any_array->Append(Value::CreateStringValue("test")); 150 any_array->Append(Value::CreateStringValue("test"));
149 any_array->Append(CreateItemValue(2)); 151 any_array->Append(CreateItemValue(2));
150 params_value->Append(any_array.release()); 152 params_value->Append(any_array.release());
151 scoped_ptr<AnyArray::Params> params( 153 scoped_ptr<AnyArray::Params> params(
152 AnyArray::Params::Create(*params_value)); 154 AnyArray::Params::Create(*params_value));
153 EXPECT_TRUE(params.get()); 155 EXPECT_TRUE(params.get());
154 ASSERT_EQ(3u, params->anys.size()); 156 ASSERT_EQ(3u, params->anys.size());
155 int int_temp = 0; 157 int int_temp = 0;
156 EXPECT_TRUE(params->anys[0]->value().GetAsInteger(&int_temp)); 158 EXPECT_TRUE(params->anys[0]->GetAsInteger(&int_temp));
157 EXPECT_EQ(1, int_temp); 159 EXPECT_EQ(1, int_temp);
158 } 160 }
159 161
160 TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) { 162 TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) {
161 scoped_ptr<ListValue> params_value(new ListValue()); 163 scoped_ptr<ListValue> params_value(new ListValue());
162 scoped_ptr<ListValue> item_array(new ListValue()); 164 scoped_ptr<ListValue> item_array(new ListValue());
163 item_array->Append(CreateItemValue(1)); 165 item_array->Append(CreateItemValue(1));
164 item_array->Append(CreateItemValue(2)); 166 item_array->Append(CreateItemValue(2));
165 params_value->Append(item_array.release()); 167 params_value->Append(item_array.release());
166 scoped_ptr<ObjectArray::Params> params( 168 scoped_ptr<ObjectArray::Params> params(
167 ObjectArray::Params::Create(*params_value)); 169 ObjectArray::Params::Create(*params_value));
168 EXPECT_TRUE(params.get()); 170 EXPECT_TRUE(params.get());
169 ASSERT_EQ(2u, params->objects.size()); 171 ASSERT_EQ(2u, params->objects.size());
170 int object_val = 0; 172 EXPECT_EQ(1, params->objects[0]->additional_properties["val"]);
171 EXPECT_TRUE(params->objects[0]->additional_properties.GetInteger( 173 EXPECT_EQ(2, params->objects[1]->additional_properties["val"]);
172 "val", &object_val));
173 EXPECT_EQ(1, object_val);
174 EXPECT_TRUE(params->objects[1]->additional_properties.GetInteger(
175 "val", &object_val));
176 EXPECT_EQ(2, object_val);
177 } 174 }
178 175
179 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) { 176 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) {
180 scoped_ptr<ListValue> params_value(new ListValue()); 177 scoped_ptr<ListValue> params_value(new ListValue());
181 scoped_ptr<ListValue> item_array(new ListValue()); 178 scoped_ptr<ListValue> item_array(new ListValue());
182 item_array->Append(CreateItemValue(1)); 179 item_array->Append(CreateItemValue(1));
183 item_array->Append(CreateItemValue(2)); 180 item_array->Append(CreateItemValue(2));
184 params_value->Append(item_array.release()); 181 params_value->Append(item_array.release());
185 scoped_ptr<RefArray::Params> params( 182 scoped_ptr<RefArray::Params> params(
186 RefArray::Params::Create(*params_value)); 183 RefArray::Params::Create(*params_value));
(...skipping 29 matching lines...) Expand all
216 ListValue* expected_argument = new ListValue(); 213 ListValue* expected_argument = new ListValue();
217 DictionaryValue* first = new DictionaryValue(); 214 DictionaryValue* first = new DictionaryValue();
218 first->SetInteger("val", 1); 215 first->SetInteger("val", 1);
219 expected_argument->Append(first); 216 expected_argument->Append(first);
220 DictionaryValue* second = new DictionaryValue(); 217 DictionaryValue* second = new DictionaryValue();
221 second->SetInteger("val", 2); 218 second->SetInteger("val", 2);
222 expected_argument->Append(second); 219 expected_argument->Append(second);
223 expected.Append(expected_argument); 220 expected.Append(expected_argument);
224 EXPECT_TRUE(results->Equals(&expected)); 221 EXPECT_TRUE(results->Equals(&expected));
225 } 222 }
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