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

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

Issue 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Tested GetAllPossibleParameterLists better. Created 8 years, 5 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 "tools/json_schema_compiler/test/arrays.h" 5 #include "tools/json_schema_compiler/test/arrays.h"
6 6
7 #include "chrome/common/extensions/value_builder.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 using namespace test::api::arrays; 10 using namespace test::api::arrays;
11 using namespace extensions;
10 12
11 namespace { 13 namespace {
12 14
13 // TODO(calamity): Change to AppendString etc once kalman's patch goes through
14 static scoped_ptr<DictionaryValue> CreateBasicArrayTypeDictionary() { 15 static scoped_ptr<DictionaryValue> CreateBasicArrayTypeDictionary() {
15 DictionaryValue* value = new DictionaryValue(); 16 return DictionaryBuilder()
16 ListValue* strings_value = new ListValue(); 17 .Set("numbers", ListBuilder().Append(6.1))
17 strings_value->Append(Value::CreateStringValue("a")); 18 .Set("booleans", ListBuilder().AppendBoolean(false).AppendBoolean(true))
18 strings_value->Append(Value::CreateStringValue("b")); 19 .Set("strings", ListBuilder().Append("a").Append("b").Append("c")
19 strings_value->Append(Value::CreateStringValue("c")); 20 .Append("it's easy as"))
20 strings_value->Append(Value::CreateStringValue("it's easy as")); 21 .Set("integers", ListBuilder().Append(1).Append(2).Append(3))
21 ListValue* integers_value = new ListValue(); 22 .Build().Pass();
22 integers_value->Append(Value::CreateIntegerValue(1));
23 integers_value->Append(Value::CreateIntegerValue(2));
24 integers_value->Append(Value::CreateIntegerValue(3));
25 ListValue* booleans_value = new ListValue();
26 booleans_value->Append(Value::CreateBooleanValue(false));
27 booleans_value->Append(Value::CreateBooleanValue(true));
28 ListValue* numbers_value = new ListValue();
29 numbers_value->Append(Value::CreateDoubleValue(6.1));
30 value->Set("numbers", numbers_value);
31 value->Set("booleans", booleans_value);
32 value->Set("strings", strings_value);
33 value->Set("integers", integers_value);
34 return scoped_ptr<DictionaryValue>(value);
35 } 23 }
36 24
37 static Value* CreateItemValue(int val) { 25 static Value* CreateItemValue(int val) {
38 DictionaryValue* value(new DictionaryValue()); 26 return DictionaryBuilder().Set("val", val).Build().release();
39 value->Set("val", Value::CreateIntegerValue(val));
40 return value;
41 } 27 }
42 28
43 } // namespace 29 } // namespace
44 30
45 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) { 31 TEST(JsonSchemaCompilerArrayTest, BasicArrayType) {
46 { 32 {
47 scoped_ptr<DictionaryValue> value = CreateBasicArrayTypeDictionary(); 33 scoped_ptr<DictionaryValue> value = CreateBasicArrayTypeDictionary();
48 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType()); 34 scoped_ptr<BasicArrayType> basic_array_type(new BasicArrayType());
49 EXPECT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get())); 35 EXPECT_TRUE(BasicArrayType::Populate(*value, basic_array_type.get()));
50 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get())); 36 EXPECT_TRUE(value->Equals(basic_array_type->ToValue().get()));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_TRUE(params.get()); 173 EXPECT_TRUE(params.get());
188 ASSERT_EQ(2u, params->refs.size()); 174 ASSERT_EQ(2u, params->refs.size());
189 EXPECT_EQ(1, params->refs[0]->val); 175 EXPECT_EQ(1, params->refs[0]->val);
190 EXPECT_EQ(2, params->refs[1]->val); 176 EXPECT_EQ(2, params->refs[1]->val);
191 } 177 }
192 178
193 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) { 179 TEST(JsonSchemaCompilerArrayTest, ReturnIntegerArrayResultCreate) {
194 std::vector<int> integers; 180 std::vector<int> integers;
195 integers.push_back(1); 181 integers.push_back(1);
196 integers.push_back(2); 182 integers.push_back(2);
197 scoped_ptr<Value> result(ReturnIntegerArray::Result::Create(integers)); 183 scoped_ptr<Value> results(ReturnIntegerArray::Result::Create(integers));
198 ListValue* list = NULL; 184
199 EXPECT_TRUE(result->GetAsList(&list)); 185 ListValue expected;
200 int temp; 186 ListValue* expected_argument = new ListValue();
201 ASSERT_EQ(2u, list->GetSize()); 187 expected_argument->Append(Value::CreateIntegerValue(1));
202 EXPECT_TRUE(list->GetInteger(0, &temp)); 188 expected_argument->Append(Value::CreateIntegerValue(2));
203 EXPECT_EQ(1, temp); 189 expected.Append(expected_argument);
204 EXPECT_TRUE(list->GetInteger(1, &temp)); 190 EXPECT_TRUE(results->Equals(&expected));
205 EXPECT_EQ(2, temp);
206 } 191 }
207 192
208 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) { 193 TEST(JsonSchemaCompilerArrayTest, ReturnRefArrayResultCreate) {
209 std::vector<linked_ptr<Item> > items; 194 std::vector<linked_ptr<Item> > items;
210 items.push_back(linked_ptr<Item>(new Item())); 195 items.push_back(linked_ptr<Item>(new Item()));
211 items.push_back(linked_ptr<Item>(new Item())); 196 items.push_back(linked_ptr<Item>(new Item()));
212 items[0]->val = 1; 197 items[0]->val = 1;
213 items[1]->val = 2; 198 items[1]->val = 2;
214 scoped_ptr<Value> result(ReturnRefArray::Result::Create(items)); 199 scoped_ptr<Value> results(ReturnRefArray::Result::Create(items));
215 ListValue* list = NULL; 200
216 EXPECT_TRUE(result->GetAsList(&list)); 201 ListValue expected;
217 ASSERT_EQ(2u, list->GetSize()); 202 ListValue* expected_argument = new ListValue();
218 DictionaryValue* item_value = NULL; 203 DictionaryValue* first = new DictionaryValue();
219 int temp; 204 first->SetInteger("val", 1);
220 EXPECT_TRUE(list->GetDictionary(0, &item_value)); 205 expected_argument->Append(first);
221 EXPECT_TRUE(item_value->GetInteger("val", &temp)); 206 DictionaryValue* second = new DictionaryValue();
222 EXPECT_EQ(1, temp); 207 second->SetInteger("val", 2);
223 EXPECT_TRUE(list->GetDictionary(1, &item_value)); 208 expected_argument->Append(second);
224 EXPECT_TRUE(item_value->GetInteger("val", &temp)); 209 expected.Append(expected_argument);
225 EXPECT_EQ(2, temp); 210 EXPECT_TRUE(results->Equals(&expected));
226 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698