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

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

Issue 276603003: Support converting referenced enum array into string. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win compile error Created 6 years, 7 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/arrays.json ('k') | tools/json_schema_compiler/util.h » ('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/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 9
9 using namespace test::api::arrays; 10 using namespace test::api::arrays;
10 11
11 namespace { 12 namespace {
12 13
13 // 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
14 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() { 15 static scoped_ptr<base::DictionaryValue> CreateBasicArrayTypeDictionary() {
15 base::DictionaryValue* value = new base::DictionaryValue(); 16 base::DictionaryValue* value = new base::DictionaryValue();
16 base::ListValue* strings_value = new base::ListValue(); 17 base::ListValue* strings_value = new base::ListValue();
17 strings_value->Append(base::Value::CreateStringValue("a")); 18 strings_value->Append(base::Value::CreateStringValue("a"));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 std::vector<EnumArrayType::TypesType> enums_vector( 74 std::vector<EnumArrayType::TypesType> enums_vector(
74 enums, enums + arraysize(enums)); 75 enums, enums + arraysize(enums));
75 EXPECT_EQ(enums_vector, enum_array_type.types); 76 EXPECT_EQ(enums_vector, enum_array_type.types);
76 } 77 }
77 78
78 // Test ToValue. 79 // Test ToValue.
79 scoped_ptr<base::Value> as_value(enum_array_type.ToValue()); 80 scoped_ptr<base::Value> as_value(enum_array_type.ToValue());
80 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; 81 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
81 } 82 }
82 83
84 TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) {
85 // { "types": ["one", "two", "three"] }
86 base::ListValue* types = new base::ListValue();
87 types->AppendString("one");
88 types->AppendString("two");
89 types->AppendString("three");
90 base::DictionaryValue value;
91 value.Set("types", types);
92
93 EnumArrayReference enum_array_reference;
94
95 // Test Populate.
96 ASSERT_TRUE(EnumArrayReference::Populate(value, &enum_array_reference));
97
98 Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
99 ENUMERATION_THREE};
100 EXPECT_EQ(std::vector<Enumeration>(
101 expected_types, expected_types + arraysize(expected_types)),
102 enum_array_reference.types);
103
104 // Test ToValue.
105 scoped_ptr<base::Value> as_value(enum_array_reference.ToValue());
106 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
107 }
108
109 TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
110 // { "types": ["one", "two", "three"] }
111 base::ListValue* inline_enums = new base::ListValue();
112 inline_enums->AppendString("one");
113 inline_enums->AppendString("two");
114 inline_enums->AppendString("three");
115
116 base::ListValue* infile_enums = new base::ListValue();
117 infile_enums->AppendString("one");
118 infile_enums->AppendString("two");
119 infile_enums->AppendString("three");
120
121 base::ListValue* external_enums = new base::ListValue();
122 external_enums->AppendString("one");
123 external_enums->AppendString("two");
124 external_enums->AppendString("three");
125
126 base::DictionaryValue value;
127 value.Set("inline_enums", inline_enums);
128 value.Set("infile_enums", infile_enums);
129 value.Set("external_enums", external_enums);
130
131 EnumArrayMixed enum_array_mixed;
132
133 // Test Populate.
134 ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed));
135
136 EnumArrayMixed::Inline_enumsType expected_inline_types[] = {
137 EnumArrayMixed::INLINE_ENUMS_TYPE_ONE,
138 EnumArrayMixed::INLINE_ENUMS_TYPE_TWO,
139 EnumArrayMixed::INLINE_ENUMS_TYPE_THREE};
140 EXPECT_EQ(std::vector<EnumArrayMixed::Inline_enumsType>(
141 expected_inline_types,
142 expected_inline_types + arraysize(expected_inline_types)),
143 enum_array_mixed.inline_enums);
144
145 Enumeration expected_infile_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
146 ENUMERATION_THREE};
147 EXPECT_EQ(std::vector<Enumeration>(
148 expected_infile_types,
149 expected_infile_types + arraysize(expected_infile_types)),
150 enum_array_mixed.infile_enums);
151
152 test::api::enums::Enumeration expected_external_types[] = {
153 test::api::enums::ENUMERATION_ONE, test::api::enums::ENUMERATION_TWO,
154 test::api::enums::ENUMERATION_THREE};
155 EXPECT_EQ(std::vector<test::api::enums::Enumeration>(
156 expected_external_types,
157 expected_external_types + arraysize(expected_external_types)),
158 enum_array_mixed.external_enums);
159
160 // Test ToValue.
161 scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue());
162 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value;
163 }
164
83 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { 165 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) {
84 { 166 {
85 std::vector<OptionalEnumArrayType::TypesType> enums; 167 std::vector<OptionalEnumArrayType::TypesType> enums;
86 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); 168 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE);
87 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); 169 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO);
88 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); 170 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE);
89 171
90 scoped_ptr<base::ListValue> types(new base::ListValue()); 172 scoped_ptr<base::ListValue> types(new base::ListValue());
91 for (size_t i = 0; i < enums.size(); ++i) { 173 for (size_t i = 0; i < enums.size(); ++i) {
92 types->Append(new base::StringValue( 174 types->Append(new base::StringValue(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 base::ListValue* expected_argument = new base::ListValue(); 308 base::ListValue* expected_argument = new base::ListValue();
227 base::DictionaryValue* first = new base::DictionaryValue(); 309 base::DictionaryValue* first = new base::DictionaryValue();
228 first->SetInteger("val", 1); 310 first->SetInteger("val", 1);
229 expected_argument->Append(first); 311 expected_argument->Append(first);
230 base::DictionaryValue* second = new base::DictionaryValue(); 312 base::DictionaryValue* second = new base::DictionaryValue();
231 second->SetInteger("val", 2); 313 second->SetInteger("val", 2);
232 expected_argument->Append(second); 314 expected_argument->Append(second);
233 expected.Append(expected_argument); 315 expected.Append(expected_argument);
234 EXPECT_TRUE(results->Equals(&expected)); 316 EXPECT_TRUE(results->Equals(&expected));
235 } 317 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/arrays.json ('k') | tools/json_schema_compiler/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698