OLD | NEW |
---|---|
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 Loading... | |
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 EXPECT_EQ(enum_array_reference.types.at(0), ENUMERATION_ONE); | |
not at google - send to devlin
2014/05/14 22:52:45
- assert correct size
- use [0] not .at(0)
you ca
| |
98 EXPECT_EQ(enum_array_reference.types.at(1), ENUMERATION_TWO); | |
99 EXPECT_EQ(enum_array_reference.types.at(2), ENUMERATION_THREE); | |
100 | |
101 // Test ToValue. | |
102 scoped_ptr<base::Value> as_value(enum_array_reference.ToValue()); | |
103 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | |
104 } | |
105 | |
106 TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) { | |
107 // { "types": ["one", "two", "three"] } | |
108 base::ListValue* inline_enums = new base::ListValue(); | |
109 inline_enums->AppendString("one"); | |
110 inline_enums->AppendString("two"); | |
111 inline_enums->AppendString("three"); | |
112 | |
113 base::ListValue* infile_enums = new base::ListValue(); | |
114 infile_enums->AppendString("one"); | |
115 infile_enums->AppendString("two"); | |
116 infile_enums->AppendString("three"); | |
117 | |
118 base::ListValue* external_enums = new base::ListValue(); | |
119 external_enums->AppendString("one"); | |
120 external_enums->AppendString("two"); | |
121 external_enums->AppendString("three"); | |
122 | |
123 base::DictionaryValue value; | |
124 value.Set("inline_enums", inline_enums); | |
125 value.Set("infile_enums", infile_enums); | |
126 value.Set("external_enums", external_enums); | |
127 | |
128 EnumArrayMixed enum_array_mixed; | |
129 | |
130 // Test Populate. | |
131 ASSERT_TRUE(EnumArrayMixed::Populate(value, &enum_array_mixed)); | |
132 EXPECT_EQ(enum_array_mixed.inline_enums.at(0), | |
133 EnumArrayMixed::INLINE_ENUMS_TYPE_ONE); | |
134 EXPECT_EQ(enum_array_mixed.inline_enums.at(1), | |
135 EnumArrayMixed::INLINE_ENUMS_TYPE_TWO); | |
136 EXPECT_EQ(enum_array_mixed.inline_enums.at(2), | |
137 EnumArrayMixed::INLINE_ENUMS_TYPE_THREE); | |
138 | |
139 EXPECT_EQ(enum_array_mixed.infile_enums.at(0), ENUMERATION_ONE); | |
140 EXPECT_EQ(enum_array_mixed.infile_enums.at(1), ENUMERATION_TWO); | |
141 EXPECT_EQ(enum_array_mixed.infile_enums.at(2), ENUMERATION_THREE); | |
142 | |
143 EXPECT_EQ(enum_array_mixed.external_enums.at(0), | |
144 test::api::enums::ENUMERATION_ONE); | |
145 EXPECT_EQ(enum_array_mixed.external_enums.at(1), | |
146 test::api::enums::ENUMERATION_TWO); | |
147 EXPECT_EQ(enum_array_mixed.external_enums.at(2), | |
148 test::api::enums::ENUMERATION_THREE); | |
149 | |
150 // Test ToValue. | |
151 scoped_ptr<base::Value> as_value(enum_array_mixed.ToValue()); | |
152 EXPECT_TRUE(value.Equals(as_value.get())) << value << " != " << *as_value; | |
153 } | |
154 | |
83 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { | 155 TEST(JsonSchemaCompilerArrayTest, OptionalEnumArrayType) { |
84 { | 156 { |
85 std::vector<OptionalEnumArrayType::TypesType> enums; | 157 std::vector<OptionalEnumArrayType::TypesType> enums; |
86 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); | 158 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_ONE); |
87 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); | 159 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_TWO); |
88 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); | 160 enums.push_back(OptionalEnumArrayType::TYPES_TYPE_THREE); |
89 | 161 |
90 scoped_ptr<base::ListValue> types(new base::ListValue()); | 162 scoped_ptr<base::ListValue> types(new base::ListValue()); |
91 for (size_t i = 0; i < enums.size(); ++i) { | 163 for (size_t i = 0; i < enums.size(); ++i) { |
92 types->Append(new base::StringValue( | 164 types->Append(new base::StringValue( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 base::ListValue* expected_argument = new base::ListValue(); | 298 base::ListValue* expected_argument = new base::ListValue(); |
227 base::DictionaryValue* first = new base::DictionaryValue(); | 299 base::DictionaryValue* first = new base::DictionaryValue(); |
228 first->SetInteger("val", 1); | 300 first->SetInteger("val", 1); |
229 expected_argument->Append(first); | 301 expected_argument->Append(first); |
230 base::DictionaryValue* second = new base::DictionaryValue(); | 302 base::DictionaryValue* second = new base::DictionaryValue(); |
231 second->SetInteger("val", 2); | 303 second->SetInteger("val", 2); |
232 expected_argument->Append(second); | 304 expected_argument->Append(second); |
233 expected.Append(expected_argument); | 305 expected.Append(expected_argument); |
234 EXPECT_TRUE(results->Equals(&expected)); | 306 EXPECT_TRUE(results->Equals(&expected)); |
235 } | 307 } |
OLD | NEW |