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

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

Issue 10054039: Support array types for function and callback arguments in IDL APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 8 years, 8 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 | Annotate | Revision Log
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/any.h" 6 #include "tools/json_schema_compiler/any.h"
7 #include "tools/json_schema_compiler/test/idl_basics.h" 7 #include "tools/json_schema_compiler/test/idl_basics.h"
8 #include "tools/json_schema_compiler/test/idl_object_types.h" 8 #include "tools/json_schema_compiler/test/idl_object_types.h"
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 using test::api::idl_basics::MyType1; 12 using test::api::idl_basics::MyType1;
13 using test::api::idl_object_types::BarType; 13 using test::api::idl_object_types::BarType;
14 using test::api::idl_object_types::FooType; 14 using test::api::idl_object_types::FooType;
15 15
16 namespace Function2 = test::api::idl_basics::Function2; 16 namespace Function2 = test::api::idl_basics::Function2;
17 namespace Function3 = test::api::idl_basics::Function3; 17 namespace Function3 = test::api::idl_basics::Function3;
18 namespace Function4 = test::api::idl_basics::Function4; 18 namespace Function4 = test::api::idl_basics::Function4;
19 namespace Function5 = test::api::idl_basics::Function5; 19 namespace Function5 = test::api::idl_basics::Function5;
20 namespace Function6 = test::api::idl_basics::Function6; 20 namespace Function6 = test::api::idl_basics::Function6;
21 namespace Function7 = test::api::idl_basics::Function7; 21 namespace Function7 = test::api::idl_basics::Function7;
22 namespace Function8 = test::api::idl_basics::Function8; 22 namespace Function8 = test::api::idl_basics::Function8;
23 namespace Function9 = test::api::idl_basics::Function9; 23 namespace Function9 = test::api::idl_basics::Function9;
24 namespace Function10 = test::api::idl_basics::Function10;
25 namespace Function11 = test::api::idl_basics::Function11;
24 namespace ObjectFunction1 = test::api::idl_object_types::ObjectFunction1; 26 namespace ObjectFunction1 = test::api::idl_object_types::ObjectFunction1;
25 27
26 TEST(IdlCompiler, Basics) { 28 TEST(IdlCompiler, Basics) {
27 // Test MyType1. 29 // Test MyType1.
28 MyType1 a; 30 MyType1 a;
29 a.x = 5; 31 a.x = 5;
30 a.y = std::string("foo"); 32 a.y = std::string("foo");
31 scoped_ptr<DictionaryValue> serialized = a.ToValue(); 33 scoped_ptr<DictionaryValue> serialized = a.ToValue();
32 MyType1 b; 34 MyType1 b;
33 EXPECT_TRUE(MyType1::Populate(*serialized.get(), &b)); 35 EXPECT_TRUE(MyType1::Populate(*serialized.get(), &b));
(...skipping 25 matching lines...) Expand all
59 EXPECT_TRUE(f5_result->IsType(Value::TYPE_INTEGER)); 61 EXPECT_TRUE(f5_result->IsType(Value::TYPE_INTEGER));
60 62
61 scoped_ptr<Value> f6_result(Function6::Result::Create(a)); 63 scoped_ptr<Value> f6_result(Function6::Result::Create(a));
62 MyType1 c; 64 MyType1 c;
63 EXPECT_TRUE(MyType1::Populate(*f6_result, &c)); 65 EXPECT_TRUE(MyType1::Populate(*f6_result, &c));
64 EXPECT_EQ(a.x, c.x); 66 EXPECT_EQ(a.x, c.x);
65 EXPECT_EQ(a.y, c.y); 67 EXPECT_EQ(a.y, c.y);
66 } 68 }
67 69
68 TEST(IdlCompiler, OptionalArguments) { 70 TEST(IdlCompiler, OptionalArguments) {
69 // Test a function that takes one optional argument, but without and with 71 // Test a function that takes one optional argument, both without and with
70 // that argument. 72 // that argument.
71 ListValue list; 73 ListValue list;
72 scoped_ptr<Function7::Params> f7_params = Function7::Params::Create(list); 74 scoped_ptr<Function7::Params> f7_params = Function7::Params::Create(list);
73 EXPECT_EQ(NULL, f7_params->arg.get()); 75 EXPECT_EQ(NULL, f7_params->arg.get());
74 list.Append(Value::CreateIntegerValue(7)); 76 list.Append(Value::CreateIntegerValue(7));
75 f7_params = Function7::Params::Create(list); 77 f7_params = Function7::Params::Create(list);
76 EXPECT_EQ(7, *(f7_params->arg)); 78 EXPECT_EQ(7, *(f7_params->arg));
77 79
78 // Similar to above, but a function with one required and one optional 80 // Similar to above, but a function with one required and one optional
79 // argument. 81 // argument.
(...skipping 16 matching lines...) Expand all
96 tmp->SetInteger("x", 17); 98 tmp->SetInteger("x", 17);
97 tmp->SetString("y", "hello"); 99 tmp->SetString("y", "hello");
98 list.Append(tmp); 100 list.Append(tmp);
99 f9_params = Function9::Params::Create(list); 101 f9_params = Function9::Params::Create(list);
100 ASSERT_TRUE(f9_params->arg.get() != NULL); 102 ASSERT_TRUE(f9_params->arg.get() != NULL);
101 MyType1* t1 = f9_params->arg.get(); 103 MyType1* t1 = f9_params->arg.get();
102 EXPECT_EQ(17, t1->x); 104 EXPECT_EQ(17, t1->x);
103 EXPECT_EQ("hello", t1->y); 105 EXPECT_EQ("hello", t1->y);
104 } 106 }
105 107
108 TEST(IdlCompiler, ArrayTypes) {
109 // Tests of a function that takes an integer and an array of integers. First
110 // use an empty array.
111 ListValue list;
112 list.Append(Value::CreateIntegerValue(33));
113 list.Append(new ListValue);
114 scoped_ptr<Function10::Params> f10_params = Function10::Params::Create(list);
115 ASSERT_TRUE(f10_params != NULL);
116 EXPECT_EQ(33, f10_params->x);
117 EXPECT_TRUE(f10_params->y.empty());
118
119 // Same function, but this time with 2 values in the array.
120 list.Clear();
121 list.Append(Value::CreateIntegerValue(33));
122 ListValue* sublist = new ListValue;
123 sublist->Append(Value::CreateIntegerValue(34));
124 sublist->Append(Value::CreateIntegerValue(35));
125 list.Append(sublist);
126 f10_params = Function10::Params::Create(list);
127 ASSERT_TRUE(f10_params != NULL);
128 EXPECT_EQ(33, f10_params->x);
129 ASSERT_EQ(2u, f10_params->y.size());
130 EXPECT_EQ(34, f10_params->y[0]);
131 EXPECT_EQ(35, f10_params->y[1]);
132
133 // Now test a function which takes an array of a defined type.
134 list.Clear();
135 MyType1 a;
136 MyType1 b;
137 a.x = 5;
138 b.x = 6;
139 a.y = std::string("foo");
140 b.y = std::string("bar");
141 ListValue* sublist2 = new ListValue;
142 sublist2->Append(a.ToValue().release());
143 sublist2->Append(b.ToValue().release());
144 list.Append(sublist2);
145 scoped_ptr<Function11::Params> f11_params = Function11::Params::Create(list);
146 ASSERT_TRUE(f11_params != NULL);
147 ASSERT_EQ(2u, f11_params->arg.size());
148 EXPECT_EQ(5, f11_params->arg[0]->x);
149 EXPECT_EQ("foo", f11_params->arg[0]->y);
150 EXPECT_EQ(6, f11_params->arg[1]->x);
151 EXPECT_EQ("bar", f11_params->arg[1]->y);
152 }
153
106 TEST(IdlCompiler, ObjectTypes) { 154 TEST(IdlCompiler, ObjectTypes) {
107 // Test the FooType type. 155 // Test the FooType type.
108 FooType f1; 156 FooType f1;
109 f1.x = 3; 157 f1.x = 3;
110 scoped_ptr<DictionaryValue> serialized_foo = f1.ToValue(); 158 scoped_ptr<DictionaryValue> serialized_foo = f1.ToValue();
111 FooType f2; 159 FooType f2;
112 EXPECT_TRUE(FooType::Populate(*serialized_foo.get(), &f2)); 160 EXPECT_TRUE(FooType::Populate(*serialized_foo.get(), &f2));
113 EXPECT_EQ(f1.x, f2.x); 161 EXPECT_EQ(f1.x, f2.x);
114 162
115 // Test the BarType type. 163 // Test the BarType type.
(...skipping 15 matching lines...) Expand all
131 &icon)); 179 &icon));
132 ListValue list; 180 ListValue list;
133 list.Append(icon_props.release()); 181 list.Append(icon_props.release());
134 scoped_ptr<ObjectFunction1::Params> params = 182 scoped_ptr<ObjectFunction1::Params> params =
135 ObjectFunction1::Params::Create(list); 183 ObjectFunction1::Params::Create(list);
136 ASSERT_TRUE(params.get() != NULL); 184 ASSERT_TRUE(params.get() != NULL);
137 std::string tmp; 185 std::string tmp;
138 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); 186 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp));
139 EXPECT_EQ("world", tmp); 187 EXPECT_EQ("world", tmp);
140 } 188 }
OLDNEW
« tools/json_schema_compiler/idl_schema.py ('K') | « tools/json_schema_compiler/test/idl_basics.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698