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

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

Issue 2036013002: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 "base/values.h" 5 #include "base/values.h"
6 #include "tools/json_schema_compiler/test/idl_basics.h" 6 #include "tools/json_schema_compiler/test/idl_basics.h"
7 #include "tools/json_schema_compiler/test/idl_object_types.h" 7 #include "tools/json_schema_compiler/test/idl_object_types.h"
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 19 matching lines...) Expand all
30 a.x = 5; 30 a.x = 5;
31 a.y = std::string("foo"); 31 a.y = std::string("foo");
32 std::unique_ptr<base::DictionaryValue> serialized = a.ToValue(); 32 std::unique_ptr<base::DictionaryValue> serialized = a.ToValue();
33 MyType1 b; 33 MyType1 b;
34 EXPECT_TRUE(MyType1::Populate(*serialized.get(), &b)); 34 EXPECT_TRUE(MyType1::Populate(*serialized.get(), &b));
35 EXPECT_EQ(a.x, b.x); 35 EXPECT_EQ(a.x, b.x);
36 EXPECT_EQ(a.y, b.y); 36 EXPECT_EQ(a.y, b.y);
37 37
38 // Test Function2, which takes an integer parameter. 38 // Test Function2, which takes an integer parameter.
39 base::ListValue list; 39 base::ListValue list;
40 list.Append(new base::FundamentalValue(5)); 40 list.AppendInteger(5);
41 std::unique_ptr<Function2::Params> f2_params = 41 std::unique_ptr<Function2::Params> f2_params =
42 Function2::Params::Create(list); 42 Function2::Params::Create(list);
43 EXPECT_EQ(5, f2_params->x); 43 EXPECT_EQ(5, f2_params->x);
44 44
45 // Test Function3, which takes a MyType1 parameter. 45 // Test Function3, which takes a MyType1 parameter.
46 list.Clear(); 46 list.Clear();
47 base::DictionaryValue* tmp = new base::DictionaryValue(); 47 base::DictionaryValue* tmp = new base::DictionaryValue();
48 tmp->SetInteger("x", 17); 48 tmp->SetInteger("x", 17);
49 tmp->SetString("y", "hello"); 49 tmp->SetString("y", "hello");
50 tmp->SetString("z", "zstring"); 50 tmp->SetString("z", "zstring");
(...skipping 26 matching lines...) Expand all
77 EXPECT_EQ(a.y, c.y); 77 EXPECT_EQ(a.y, c.y);
78 } 78 }
79 79
80 TEST(IdlCompiler, OptionalArguments) { 80 TEST(IdlCompiler, OptionalArguments) {
81 // Test a function that takes one optional argument, both without and with 81 // Test a function that takes one optional argument, both without and with
82 // that argument. 82 // that argument.
83 base::ListValue list; 83 base::ListValue list;
84 std::unique_ptr<Function7::Params> f7_params = 84 std::unique_ptr<Function7::Params> f7_params =
85 Function7::Params::Create(list); 85 Function7::Params::Create(list);
86 EXPECT_EQ(NULL, f7_params->arg.get()); 86 EXPECT_EQ(NULL, f7_params->arg.get());
87 list.Append(new base::FundamentalValue(7)); 87 list.AppendInteger(7);
88 f7_params = Function7::Params::Create(list); 88 f7_params = Function7::Params::Create(list);
89 EXPECT_EQ(7, *(f7_params->arg)); 89 EXPECT_EQ(7, *(f7_params->arg));
90 90
91 // Similar to above, but a function with one required and one optional 91 // Similar to above, but a function with one required and one optional
92 // argument. 92 // argument.
93 list.Clear(); 93 list.Clear();
94 list.Append(new base::FundamentalValue(8)); 94 list.AppendInteger(8);
95 std::unique_ptr<Function8::Params> f8_params = 95 std::unique_ptr<Function8::Params> f8_params =
96 Function8::Params::Create(list); 96 Function8::Params::Create(list);
97 EXPECT_EQ(8, f8_params->arg1); 97 EXPECT_EQ(8, f8_params->arg1);
98 EXPECT_EQ(NULL, f8_params->arg2.get()); 98 EXPECT_EQ(NULL, f8_params->arg2.get());
99 list.Append(new base::StringValue("foo")); 99 list.AppendString("foo");
100 f8_params = Function8::Params::Create(list); 100 f8_params = Function8::Params::Create(list);
101 EXPECT_EQ(8, f8_params->arg1); 101 EXPECT_EQ(8, f8_params->arg1);
102 EXPECT_EQ("foo", *(f8_params->arg2)); 102 EXPECT_EQ("foo", *(f8_params->arg2));
103 103
104 // Test a function with an optional argument of custom type. 104 // Test a function with an optional argument of custom type.
105 list.Clear(); 105 list.Clear();
106 std::unique_ptr<Function9::Params> f9_params = 106 std::unique_ptr<Function9::Params> f9_params =
107 Function9::Params::Create(list); 107 Function9::Params::Create(list);
108 EXPECT_EQ(NULL, f9_params->arg.get()); 108 EXPECT_EQ(NULL, f9_params->arg.get());
109 list.Clear(); 109 list.Clear();
110 base::DictionaryValue* tmp = new base::DictionaryValue(); 110 base::DictionaryValue* tmp = new base::DictionaryValue();
111 tmp->SetInteger("x", 17); 111 tmp->SetInteger("x", 17);
112 tmp->SetString("y", "hello"); 112 tmp->SetString("y", "hello");
113 tmp->SetString("z", "zstring"); 113 tmp->SetString("z", "zstring");
114 tmp->SetString("a", "astring"); 114 tmp->SetString("a", "astring");
115 tmp->SetString("b", "bstring"); 115 tmp->SetString("b", "bstring");
116 tmp->SetString("c", "cstring"); 116 tmp->SetString("c", "cstring");
117 list.Append(tmp); 117 list.Append(tmp);
118 f9_params = Function9::Params::Create(list); 118 f9_params = Function9::Params::Create(list);
119 ASSERT_TRUE(f9_params->arg.get() != NULL); 119 ASSERT_TRUE(f9_params->arg.get() != NULL);
120 MyType1* t1 = f9_params->arg.get(); 120 MyType1* t1 = f9_params->arg.get();
121 EXPECT_EQ(17, t1->x); 121 EXPECT_EQ(17, t1->x);
122 EXPECT_EQ("hello", t1->y); 122 EXPECT_EQ("hello", t1->y);
123 } 123 }
124 124
125 TEST(IdlCompiler, ArrayTypes) { 125 TEST(IdlCompiler, ArrayTypes) {
126 // Tests of a function that takes an integer and an array of integers. First 126 // Tests of a function that takes an integer and an array of integers. First
127 // use an empty array. 127 // use an empty array.
128 base::ListValue list; 128 base::ListValue list;
129 list.Append(new base::FundamentalValue(33)); 129 list.AppendInteger(33);
130 list.Append(new base::ListValue); 130 list.Append(new base::ListValue);
131 std::unique_ptr<Function10::Params> f10_params = 131 std::unique_ptr<Function10::Params> f10_params =
132 Function10::Params::Create(list); 132 Function10::Params::Create(list);
133 ASSERT_TRUE(f10_params != NULL); 133 ASSERT_TRUE(f10_params != NULL);
134 EXPECT_EQ(33, f10_params->x); 134 EXPECT_EQ(33, f10_params->x);
135 EXPECT_TRUE(f10_params->y.empty()); 135 EXPECT_TRUE(f10_params->y.empty());
136 136
137 // Same function, but this time with 2 values in the array. 137 // Same function, but this time with 2 values in the array.
138 list.Clear(); 138 list.Clear();
139 list.Append(new base::FundamentalValue(33)); 139 list.AppendInteger(33);
140 base::ListValue* sublist = new base::ListValue; 140 base::ListValue* sublist = new base::ListValue;
141 sublist->Append(new base::FundamentalValue(34)); 141 sublist->AppendInteger(34);
142 sublist->Append(new base::FundamentalValue(35)); 142 sublist->AppendInteger(35);
143 list.Append(sublist); 143 list.Append(sublist);
144 f10_params = Function10::Params::Create(list); 144 f10_params = Function10::Params::Create(list);
145 ASSERT_TRUE(f10_params != NULL); 145 ASSERT_TRUE(f10_params != NULL);
146 EXPECT_EQ(33, f10_params->x); 146 EXPECT_EQ(33, f10_params->x);
147 ASSERT_EQ(2u, f10_params->y.size()); 147 ASSERT_EQ(2u, f10_params->y.size());
148 EXPECT_EQ(34, f10_params->y[0]); 148 EXPECT_EQ(34, f10_params->y[0]);
149 EXPECT_EQ(35, f10_params->y[1]); 149 EXPECT_EQ(35, f10_params->y[1]);
150 150
151 // Now test a function which takes an array of a defined type. 151 // Now test a function which takes an array of a defined type.
152 list.Clear(); 152 list.Clear();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 &icon)); 198 &icon));
199 base::ListValue list; 199 base::ListValue list;
200 list.Append(icon_props.release()); 200 list.Append(icon_props.release());
201 std::unique_ptr<ObjectFunction1::Params> params = 201 std::unique_ptr<ObjectFunction1::Params> params =
202 ObjectFunction1::Params::Create(list); 202 ObjectFunction1::Params::Create(list);
203 ASSERT_TRUE(params.get() != NULL); 203 ASSERT_TRUE(params.get() != NULL);
204 std::string tmp; 204 std::string tmp;
205 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); 205 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp));
206 EXPECT_EQ("world", tmp); 206 EXPECT_EQ("world", tmp);
207 } 207 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/functions_on_types_unittest.cc ('k') | tools/json_schema_compiler/test/objects_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698