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

Side by Side Diff: tools/json_schema_compiler/test/objects_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/objects.h" 5 #include "tools/json_schema_compiler/test/objects.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::objects; 10 using namespace test::api::objects;
11 using namespace extensions;
10 12
11 TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { 13 TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
12 { 14 {
13 scoped_ptr<ListValue> strings(new ListValue()); 15 scoped_ptr<ListValue> params_value(ListBuilder()
14 strings->Append(Value::CreateStringValue("one")); 16 .Append(DictionaryBuilder()
15 strings->Append(Value::CreateStringValue("two")); 17 .Set("strings", ListBuilder().Append("one").Append("two"))
16 scoped_ptr<DictionaryValue> info_value(new DictionaryValue()); 18 .Set("integer", 5).SetBoolean("boolean", true)).Build());
17 info_value->Set("strings", strings.release());
18 info_value->Set("integer", Value::CreateIntegerValue(5));
19 info_value->Set("boolean", Value::CreateBooleanValue(true));
20
21 scoped_ptr<ListValue> params_value(new ListValue());
22 params_value->Append(info_value.release());
23 scoped_ptr<ObjectParam::Params> params( 19 scoped_ptr<ObjectParam::Params> params(
24 ObjectParam::Params::Create(*params_value)); 20 ObjectParam::Params::Create(*params_value));
25 EXPECT_TRUE(params.get()); 21 ASSERT_TRUE(params.get());
26 EXPECT_EQ((size_t) 2, params->info.strings.size()); 22 EXPECT_EQ((size_t) 2, params->info.strings.size());
27 EXPECT_EQ("one", params->info.strings[0]); 23 EXPECT_EQ("one", params->info.strings[0]);
28 EXPECT_EQ("two", params->info.strings[1]); 24 EXPECT_EQ("two", params->info.strings[1]);
29 EXPECT_EQ(5, params->info.integer); 25 EXPECT_EQ(5, params->info.integer);
30 EXPECT_TRUE(params->info.boolean); 26 EXPECT_TRUE(params->info.boolean);
31 } 27 }
32 { 28 {
33 scoped_ptr<ListValue> strings(new ListValue()); 29 scoped_ptr<ListValue> params_value(ListBuilder()
34 strings->Append(Value::CreateStringValue("one")); 30 .Append(DictionaryBuilder()
35 strings->Append(Value::CreateStringValue("two")); 31 .Set("strings", ListBuilder().Append("one").Append("two"))
36 scoped_ptr<DictionaryValue> info_value(new DictionaryValue()); 32 .Set("integer", 5)).Build());
37 info_value->Set("strings", strings.release());
38 info_value->Set("integer", Value::CreateIntegerValue(5));
39
40 scoped_ptr<ListValue> params_value(new ListValue());
41 params_value->Append(info_value.release());
42 scoped_ptr<ObjectParam::Params> params( 33 scoped_ptr<ObjectParam::Params> params(
43 ObjectParam::Params::Create(*params_value)); 34 ObjectParam::Params::Create(*params_value));
44 EXPECT_FALSE(params.get()); 35 EXPECT_FALSE(params.get());
45 } 36 }
46 } 37 }
47 38
48 TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { 39 TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
49 scoped_ptr<ReturnsObject::Result::Info> info( 40 ReturnsObject::Result::Info info;
50 new ReturnsObject::Result::Info()); 41 info.state = ReturnsObject::Result::Info::STATE_FOO;
51 info->state = ReturnsObject::Result::Info::STATE_FOO; 42 scoped_ptr<ListValue> results(ReturnsObject::Result::Create(info));
52 scoped_ptr<Value> result_value( 43
53 ReturnsObject::Result::Create(*info)); 44 scoped_ptr<ListValue> expected(ListBuilder().Append(DictionaryBuilder()
54 DictionaryValue* result_dict = NULL; 45 .Set("state", "foo")).Build());
55 EXPECT_TRUE(result_value->GetAsDictionary(&result_dict)); 46 ASSERT_TRUE(results->Equals(expected.get()));
56 std::string state;
57 EXPECT_TRUE(result_dict->GetString("state", &state));
58 EXPECT_EQ("foo", state);
59 } 47 }
48
49 TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
50 OnObjectFired::SomeObject object;
51 object.state = OnObjectFired::SomeObject::STATE_BAR;
52 scoped_ptr<ListValue> results(OnObjectFired::Create(object));
53
54 scoped_ptr<ListValue> expected(ListBuilder().Append(DictionaryBuilder()
55 .Set("state", "bar")).Build());
56 ASSERT_TRUE(results->Equals(expected.get()));
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698