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 <memory> |
5 #include <utility> | 6 #include <utility> |
6 | 7 |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/json_schema_compiler/test/idl_basics.h" | 10 #include "tools/json_schema_compiler/test/idl_basics.h" |
10 #include "tools/json_schema_compiler/test/idl_object_types.h" | 11 #include "tools/json_schema_compiler/test/idl_object_types.h" |
11 | 12 |
12 using test::api::idl_basics::MyType1; | 13 using test::api::idl_basics::MyType1; |
13 using test::api::idl_object_types::BarType; | 14 using test::api::idl_object_types::BarType; |
14 using test::api::idl_object_types::FooType; | 15 using test::api::idl_object_types::FooType; |
(...skipping 23 matching lines...) Expand all Loading... |
38 | 39 |
39 // Test Function2, which takes an integer parameter. | 40 // Test Function2, which takes an integer parameter. |
40 base::ListValue list; | 41 base::ListValue list; |
41 list.AppendInteger(5); | 42 list.AppendInteger(5); |
42 std::unique_ptr<Function2::Params> f2_params = | 43 std::unique_ptr<Function2::Params> f2_params = |
43 Function2::Params::Create(list); | 44 Function2::Params::Create(list); |
44 EXPECT_EQ(5, f2_params->x); | 45 EXPECT_EQ(5, f2_params->x); |
45 | 46 |
46 // Test Function3, which takes a MyType1 parameter. | 47 // Test Function3, which takes a MyType1 parameter. |
47 list.Clear(); | 48 list.Clear(); |
48 base::DictionaryValue* tmp = new base::DictionaryValue(); | 49 std::unique_ptr<base::DictionaryValue> tmp(new base::DictionaryValue()); |
49 tmp->SetInteger("x", 17); | 50 tmp->SetInteger("x", 17); |
50 tmp->SetString("y", "hello"); | 51 tmp->SetString("y", "hello"); |
51 tmp->SetString("z", "zstring"); | 52 tmp->SetString("z", "zstring"); |
52 tmp->SetString("a", "astring"); | 53 tmp->SetString("a", "astring"); |
53 tmp->SetString("b", "bstring"); | 54 tmp->SetString("b", "bstring"); |
54 tmp->SetString("c", "cstring"); | 55 tmp->SetString("c", "cstring"); |
55 list.Append(tmp); | 56 list.Append(std::move(tmp)); |
56 std::unique_ptr<Function3::Params> f3_params = | 57 std::unique_ptr<Function3::Params> f3_params = |
57 Function3::Params::Create(list); | 58 Function3::Params::Create(list); |
58 EXPECT_EQ(17, f3_params->arg.x); | 59 EXPECT_EQ(17, f3_params->arg.x); |
59 EXPECT_EQ("hello", f3_params->arg.y); | 60 EXPECT_EQ("hello", f3_params->arg.y); |
60 | 61 |
61 // Test functions that take a callback function as a parameter, with varying | 62 // Test functions that take a callback function as a parameter, with varying |
62 // callback signatures. | 63 // callback signatures. |
63 std::unique_ptr<base::ListValue> f4_results = Function4::Results::Create(); | 64 std::unique_ptr<base::ListValue> f4_results = Function4::Results::Create(); |
64 base::ListValue expected; | 65 base::ListValue expected; |
65 EXPECT_TRUE(f4_results->Equals(&expected)); | 66 EXPECT_TRUE(f4_results->Equals(&expected)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 f8_params = Function8::Params::Create(list); | 102 f8_params = Function8::Params::Create(list); |
102 EXPECT_EQ(8, f8_params->arg1); | 103 EXPECT_EQ(8, f8_params->arg1); |
103 EXPECT_EQ("foo", *(f8_params->arg2)); | 104 EXPECT_EQ("foo", *(f8_params->arg2)); |
104 | 105 |
105 // Test a function with an optional argument of custom type. | 106 // Test a function with an optional argument of custom type. |
106 list.Clear(); | 107 list.Clear(); |
107 std::unique_ptr<Function9::Params> f9_params = | 108 std::unique_ptr<Function9::Params> f9_params = |
108 Function9::Params::Create(list); | 109 Function9::Params::Create(list); |
109 EXPECT_EQ(NULL, f9_params->arg.get()); | 110 EXPECT_EQ(NULL, f9_params->arg.get()); |
110 list.Clear(); | 111 list.Clear(); |
111 base::DictionaryValue* tmp = new base::DictionaryValue(); | 112 std::unique_ptr<base::DictionaryValue> tmp(new base::DictionaryValue()); |
112 tmp->SetInteger("x", 17); | 113 tmp->SetInteger("x", 17); |
113 tmp->SetString("y", "hello"); | 114 tmp->SetString("y", "hello"); |
114 tmp->SetString("z", "zstring"); | 115 tmp->SetString("z", "zstring"); |
115 tmp->SetString("a", "astring"); | 116 tmp->SetString("a", "astring"); |
116 tmp->SetString("b", "bstring"); | 117 tmp->SetString("b", "bstring"); |
117 tmp->SetString("c", "cstring"); | 118 tmp->SetString("c", "cstring"); |
118 list.Append(tmp); | 119 list.Append(std::move(tmp)); |
119 f9_params = Function9::Params::Create(list); | 120 f9_params = Function9::Params::Create(list); |
120 ASSERT_TRUE(f9_params->arg.get() != NULL); | 121 ASSERT_TRUE(f9_params->arg.get() != NULL); |
121 MyType1* t1 = f9_params->arg.get(); | 122 MyType1* t1 = f9_params->arg.get(); |
122 EXPECT_EQ(17, t1->x); | 123 EXPECT_EQ(17, t1->x); |
123 EXPECT_EQ("hello", t1->y); | 124 EXPECT_EQ("hello", t1->y); |
124 } | 125 } |
125 | 126 |
126 TEST(IdlCompiler, ArrayTypes) { | 127 TEST(IdlCompiler, ArrayTypes) { |
127 // Tests of a function that takes an integer and an array of integers. First | 128 // Tests of a function that takes an integer and an array of integers. First |
128 // use an empty array. | 129 // use an empty array. |
129 base::ListValue list; | 130 base::ListValue list; |
130 list.AppendInteger(33); | 131 list.AppendInteger(33); |
131 list.Append(new base::ListValue); | 132 list.Append(new base::ListValue); |
132 std::unique_ptr<Function10::Params> f10_params = | 133 std::unique_ptr<Function10::Params> f10_params = |
133 Function10::Params::Create(list); | 134 Function10::Params::Create(list); |
134 ASSERT_TRUE(f10_params != NULL); | 135 ASSERT_TRUE(f10_params != NULL); |
135 EXPECT_EQ(33, f10_params->x); | 136 EXPECT_EQ(33, f10_params->x); |
136 EXPECT_TRUE(f10_params->y.empty()); | 137 EXPECT_TRUE(f10_params->y.empty()); |
137 | 138 |
138 // Same function, but this time with 2 values in the array. | 139 // Same function, but this time with 2 values in the array. |
139 list.Clear(); | 140 list.Clear(); |
140 list.AppendInteger(33); | 141 list.AppendInteger(33); |
141 base::ListValue* sublist = new base::ListValue; | 142 std::unique_ptr<base::ListValue> sublist(new base::ListValue); |
142 sublist->AppendInteger(34); | 143 sublist->AppendInteger(34); |
143 sublist->AppendInteger(35); | 144 sublist->AppendInteger(35); |
144 list.Append(sublist); | 145 list.Append(std::move(sublist)); |
145 f10_params = Function10::Params::Create(list); | 146 f10_params = Function10::Params::Create(list); |
146 ASSERT_TRUE(f10_params != NULL); | 147 ASSERT_TRUE(f10_params != NULL); |
147 EXPECT_EQ(33, f10_params->x); | 148 EXPECT_EQ(33, f10_params->x); |
148 ASSERT_EQ(2u, f10_params->y.size()); | 149 ASSERT_EQ(2u, f10_params->y.size()); |
149 EXPECT_EQ(34, f10_params->y[0]); | 150 EXPECT_EQ(34, f10_params->y[0]); |
150 EXPECT_EQ(35, f10_params->y[1]); | 151 EXPECT_EQ(35, f10_params->y[1]); |
151 | 152 |
152 // Now test a function which takes an array of a defined type. | 153 // Now test a function which takes an array of a defined type. |
153 list.Clear(); | 154 list.Clear(); |
154 MyType1 a; | 155 MyType1 a; |
155 MyType1 b; | 156 MyType1 b; |
156 a.x = 5; | 157 a.x = 5; |
157 b.x = 6; | 158 b.x = 6; |
158 a.y = std::string("foo"); | 159 a.y = std::string("foo"); |
159 b.y = std::string("bar"); | 160 b.y = std::string("bar"); |
160 base::ListValue* sublist2 = new base::ListValue; | 161 std::unique_ptr<base::ListValue> sublist2(new base::ListValue); |
161 sublist2->Append(a.ToValue()); | 162 sublist2->Append(a.ToValue()); |
162 sublist2->Append(b.ToValue()); | 163 sublist2->Append(b.ToValue()); |
163 list.Append(sublist2); | 164 list.Append(std::move(sublist2)); |
164 std::unique_ptr<Function11::Params> f11_params = | 165 std::unique_ptr<Function11::Params> f11_params = |
165 Function11::Params::Create(list); | 166 Function11::Params::Create(list); |
166 ASSERT_TRUE(f11_params != NULL); | 167 ASSERT_TRUE(f11_params != NULL); |
167 ASSERT_EQ(2u, f11_params->arg.size()); | 168 ASSERT_EQ(2u, f11_params->arg.size()); |
168 EXPECT_EQ(5, f11_params->arg[0].x); | 169 EXPECT_EQ(5, f11_params->arg[0].x); |
169 EXPECT_EQ("foo", f11_params->arg[0].y); | 170 EXPECT_EQ("foo", f11_params->arg[0].y); |
170 EXPECT_EQ(6, f11_params->arg[1].x); | 171 EXPECT_EQ(6, f11_params->arg[1].x); |
171 EXPECT_EQ("bar", f11_params->arg[1].y); | 172 EXPECT_EQ("bar", f11_params->arg[1].y); |
172 } | 173 } |
173 | 174 |
(...skipping 25 matching lines...) Expand all Loading... |
199 &icon)); | 200 &icon)); |
200 base::ListValue list; | 201 base::ListValue list; |
201 list.Append(std::move(icon_props)); | 202 list.Append(std::move(icon_props)); |
202 std::unique_ptr<ObjectFunction1::Params> params = | 203 std::unique_ptr<ObjectFunction1::Params> params = |
203 ObjectFunction1::Params::Create(list); | 204 ObjectFunction1::Params::Create(list); |
204 ASSERT_TRUE(params.get() != NULL); | 205 ASSERT_TRUE(params.get() != NULL); |
205 std::string tmp; | 206 std::string tmp; |
206 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); | 207 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); |
207 EXPECT_EQ("world", tmp); | 208 EXPECT_EQ("world", tmp); |
208 } | 209 } |
OLD | NEW |