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

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

Issue 9415001: Add tests to tools/json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 10 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
not at google - send to devlin 2012/02/19 23:19:59 These files should all be _unittest.cc not _test.c
calamity 2012/02/20 05:03:37 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "tools/json_schema_compiler/test/array.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using namespace test::api::array;
10
11 namespace {
12
13 DictionaryValue* CreateBasicArrayTypeDictionary() {
14 DictionaryValue* value = new DictionaryValue();
15 ListValue* strings_value = new ListValue();
16 strings_value->Append(Value::CreateStringValue("a"));
17 strings_value->Append(Value::CreateStringValue("b"));
18 strings_value->Append(Value::CreateStringValue("c"));
not at google - send to devlin 2012/02/18 03:29:02 You're calling things like this a lot, and presuma
not at google - send to devlin 2012/02/19 23:19:59 Don't worry about this, I'm going to add it to bas
calamity 2012/02/20 05:03:37 Added a TODO for when your patch goes through.
19 strings_value->Append(Value::CreateStringValue("it's easy as"));
20 ListValue* integers_value = new ListValue();
21 integers_value->Append(Value::CreateIntegerValue(1));
22 integers_value->Append(Value::CreateIntegerValue(2));
23 integers_value->Append(Value::CreateIntegerValue(3));
24 ListValue* booleans_value = new ListValue();
25 booleans_value->Append(Value::CreateBooleanValue(false));
26 booleans_value->Append(Value::CreateBooleanValue(true));
27 ListValue* numbers_value = new ListValue();
28 numbers_value->Append(Value::CreateDoubleValue(6.1));
29 value->SetWithoutPathExpansion("numbers", numbers_value);
30 value->SetWithoutPathExpansion("booleans", booleans_value);
31 value->SetWithoutPathExpansion("strings", strings_value);
32 value->SetWithoutPathExpansion("integers", integers_value);
33 return value;
not at google - send to devlin 2012/02/18 03:29:02 Should return a scoped ptr
calamity 2012/02/20 05:03:37 Done.
34 }
35
36 Value* CreateItemValue(int val) {
37 scoped_ptr<DictionaryValue> value(new DictionaryValue());
not at google - send to devlin 2012/02/18 03:29:02 Heh, scoped_ptr here but not above? Do one or the
calamity 2012/02/20 05:03:37 Done.
38 value->SetWithoutPathExpansion("val", Value::CreateIntegerValue(val));
not at google - send to devlin 2012/02/18 03:29:02 Can definitely do just value->SetString("val", val
calamity 2012/02/20 05:03:37 Done.
39 return value.release();
40 }
41
42 } // namespace
43
44 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
45 {
46 scoped_ptr<DictionaryValue> value(CreateBasicArrayTypeDictionary());
47 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
48 EXPECT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
49 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get()));
50 }
51 }
52
53 TEST(JsonSchemaCompilerArrayTest, RefArrayType) {
54 {
55 scoped_ptr<DictionaryValue> value(new DictionaryValue());
56 scoped_ptr<ListValue> ref_array(new ListValue());
57 ref_array->Append(CreateItemValue(1));
58 ref_array->Append(CreateItemValue(2));
59 ref_array->Append(CreateItemValue(3));
60 value->SetWithoutPathExpansion("refs", ref_array.release());
61 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
62 EXPECT_TRUE(RefArrayType::Populate(*value, ref_array_type.get()));
63 EXPECT_EQ(1, ref_array_type->refs[0]->val);
not at google - send to devlin 2012/02/19 23:19:59 Should test size == 3 too (same elsewhere where ap
calamity 2012/02/20 05:03:37 Done.
64 EXPECT_EQ(2, ref_array_type->refs[1]->val);
65 EXPECT_EQ(3, ref_array_type->refs[2]->val);
66 }
67 {
68 scoped_ptr<DictionaryValue> value(new DictionaryValue());
69 scoped_ptr<ListValue> not_ref_array(new ListValue());
70 not_ref_array->Append(CreateItemValue(1));
71 not_ref_array->Append(Value::CreateIntegerValue(3));
72 value->SetWithoutPathExpansion("refs", not_ref_array.release());
73 scoped_ptr<RefArrayType> ref_array_type(new RefArrayType());
74 EXPECT_FALSE(RefArrayType::Populate(*value, ref_array_type.get()));
75 }
76 }
77
78 TEST(JsonSchemaCompilerArrayTest, IntegerArrayParamsCreate) {
79 {
not at google - send to devlin 2012/02/18 03:29:02 If you're only testing 1 atomic unit, probably no
calamity 2012/02/20 05:03:37 Done.
80 scoped_ptr<ListValue> params_value(new ListValue());
81 scoped_ptr<ListValue> integer_array(new ListValue());
82 integer_array->Append(Value::CreateIntegerValue(2));
83 integer_array->Append(Value::CreateIntegerValue(4));
84 integer_array->Append(Value::CreateIntegerValue(8));
85 params_value->Append(integer_array.release());
86 scoped_ptr<IntegerArray::Params> params(
87 IntegerArray::Params::Create(*params_value));
88 EXPECT_TRUE(params.get());
89 EXPECT_EQ(2, params->nums[0]);
90 EXPECT_EQ(4, params->nums[1]);
91 EXPECT_EQ(8, params->nums[2]);
92 }
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698