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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "tools/json_schema_compiler/test/enums.h" | 14 #include "tools/json_schema_compiler/test/enums.h" |
14 | 15 |
15 using namespace test::api::arrays; | 16 using namespace test::api::arrays; |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // TODO(calamity): Change to AppendString etc once kalman's patch goes through | 20 // TODO(calamity): Change to AppendString etc once kalman's patch goes through |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get())); | 180 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get())); |
180 } | 181 } |
181 } | 182 } |
182 | 183 |
183 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) { | 184 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) { |
184 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 185 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
185 std::unique_ptr<base::ListValue> integer_array(new base::ListValue()); | 186 std::unique_ptr<base::ListValue> integer_array(new base::ListValue()); |
186 integer_array->AppendInteger(2); | 187 integer_array->AppendInteger(2); |
187 integer_array->AppendInteger(4); | 188 integer_array->AppendInteger(4); |
188 integer_array->AppendInteger(8); | 189 integer_array->AppendInteger(8); |
189 params_value->Append(integer_array.release()); | 190 params_value->Append(std::move(integer_array)); |
190 std::unique_ptr<IntegerArray::Params> params( | 191 std::unique_ptr<IntegerArray::Params> params( |
191 IntegerArray::Params::Create(*params_value)); | 192 IntegerArray::Params::Create(*params_value)); |
192 EXPECT_TRUE(params.get()); | 193 EXPECT_TRUE(params.get()); |
193 ASSERT_EQ(3u, params->nums.size()); | 194 ASSERT_EQ(3u, params->nums.size()); |
194 EXPECT_EQ(2, params->nums[0]); | 195 EXPECT_EQ(2, params->nums[0]); |
195 EXPECT_EQ(4, params->nums[1]); | 196 EXPECT_EQ(4, params->nums[1]); |
196 EXPECT_EQ(8, params->nums[2]); | 197 EXPECT_EQ(8, params->nums[2]); |
197 } | 198 } |
198 | 199 |
199 TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) { | 200 TEST(JsonSchemaCompilerArrayTest, AnyArrayParamsCreate) { |
200 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 201 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
201 std::unique_ptr<base::ListValue> any_array(new base::ListValue()); | 202 std::unique_ptr<base::ListValue> any_array(new base::ListValue()); |
202 any_array->AppendInteger(1); | 203 any_array->AppendInteger(1); |
203 any_array->AppendString("test"); | 204 any_array->AppendString("test"); |
204 any_array->Append(CreateItemValue(2)); | 205 any_array->Append(CreateItemValue(2)); |
205 params_value->Append(any_array.release()); | 206 params_value->Append(std::move(any_array)); |
206 std::unique_ptr<AnyArray::Params> params( | 207 std::unique_ptr<AnyArray::Params> params( |
207 AnyArray::Params::Create(*params_value)); | 208 AnyArray::Params::Create(*params_value)); |
208 EXPECT_TRUE(params.get()); | 209 EXPECT_TRUE(params.get()); |
209 ASSERT_EQ(3u, params->anys.size()); | 210 ASSERT_EQ(3u, params->anys.size()); |
210 int int_temp = 0; | 211 int int_temp = 0; |
211 EXPECT_TRUE(params->anys[0]->GetAsInteger(&int_temp)); | 212 EXPECT_TRUE(params->anys[0]->GetAsInteger(&int_temp)); |
212 EXPECT_EQ(1, int_temp); | 213 EXPECT_EQ(1, int_temp); |
213 } | 214 } |
214 | 215 |
215 TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) { | 216 TEST(JsonSchemaCompilerArrayTest, ObjectArrayParamsCreate) { |
216 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 217 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
217 std::unique_ptr<base::ListValue> item_array(new base::ListValue()); | 218 std::unique_ptr<base::ListValue> item_array(new base::ListValue()); |
218 item_array->Append(CreateItemValue(1)); | 219 item_array->Append(CreateItemValue(1)); |
219 item_array->Append(CreateItemValue(2)); | 220 item_array->Append(CreateItemValue(2)); |
220 params_value->Append(item_array.release()); | 221 params_value->Append(std::move(item_array)); |
221 std::unique_ptr<ObjectArray::Params> params( | 222 std::unique_ptr<ObjectArray::Params> params( |
222 ObjectArray::Params::Create(*params_value)); | 223 ObjectArray::Params::Create(*params_value)); |
223 EXPECT_TRUE(params.get()); | 224 EXPECT_TRUE(params.get()); |
224 ASSERT_EQ(2u, params->objects.size()); | 225 ASSERT_EQ(2u, params->objects.size()); |
225 EXPECT_EQ(1, params->objects[0].additional_properties["val"]); | 226 EXPECT_EQ(1, params->objects[0].additional_properties["val"]); |
226 EXPECT_EQ(2, params->objects[1].additional_properties["val"]); | 227 EXPECT_EQ(2, params->objects[1].additional_properties["val"]); |
227 } | 228 } |
228 | 229 |
229 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) { | 230 TEST(JsonSchemaCompilerArrayTest, RefArrayParamsCreate) { |
230 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); | 231 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
231 std::unique_ptr<base::ListValue> item_array(new base::ListValue()); | 232 std::unique_ptr<base::ListValue> item_array(new base::ListValue()); |
232 item_array->Append(CreateItemValue(1)); | 233 item_array->Append(CreateItemValue(1)); |
233 item_array->Append(CreateItemValue(2)); | 234 item_array->Append(CreateItemValue(2)); |
234 params_value->Append(item_array.release()); | 235 params_value->Append(std::move(item_array)); |
235 std::unique_ptr<RefArray::Params> params( | 236 std::unique_ptr<RefArray::Params> params( |
236 RefArray::Params::Create(*params_value)); | 237 RefArray::Params::Create(*params_value)); |
237 EXPECT_TRUE(params.get()); | 238 EXPECT_TRUE(params.get()); |
238 ASSERT_EQ(2u, params->refs.size()); | 239 ASSERT_EQ(2u, params->refs.size()); |
239 EXPECT_EQ(1, params->refs[0].val); | 240 EXPECT_EQ(1, params->refs[0].val); |
240 EXPECT_EQ(2, params->refs[1].val); | 241 EXPECT_EQ(2, params->refs[1].val); |
241 } | 242 } |
242 | 243 |
243 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) { | 244 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) { |
244 std::vector<int> integers; | 245 std::vector<int> integers; |
(...skipping 23 matching lines...) Expand all Loading... |
268 base::ListValue* expected_argument = new base::ListValue(); | 269 base::ListValue* expected_argument = new base::ListValue(); |
269 base::DictionaryValue* first = new base::DictionaryValue(); | 270 base::DictionaryValue* first = new base::DictionaryValue(); |
270 first->SetInteger("val", 1); | 271 first->SetInteger("val", 1); |
271 expected_argument->Append(first); | 272 expected_argument->Append(first); |
272 base::DictionaryValue* second = new base::DictionaryValue(); | 273 base::DictionaryValue* second = new base::DictionaryValue(); |
273 second->SetInteger("val", 2); | 274 second->SetInteger("val", 2); |
274 expected_argument->Append(second); | 275 expected_argument->Append(second); |
275 expected.Append(expected_argument); | 276 expected.Append(expected_argument); |
276 EXPECT_TRUE(results->Equals(&expected)); | 277 EXPECT_TRUE(results->Equals(&expected)); |
277 } | 278 } |
OLD | NEW |