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

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

Issue 10701012: JSON Schema Compiler: Added event compilation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added more testing for event compilation. 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/enums.h" 5 #include "tools/json_schema_compiler/test/enums.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 using namespace test::api::enums; 9 using namespace test::api::enums;
10 10
11 TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) { 11 TEST(JsonSchemaCompilerEnumsTest, EnumTypePopulate) {
12 { 12 {
13 scoped_ptr<EnumType> enum_type(new EnumType()); 13 scoped_ptr<EnumType> enum_type(new EnumType());
14 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 14 scoped_ptr<DictionaryValue> value(new DictionaryValue());
15 value->Set("type", Value::CreateStringValue("one")); 15 value->Set("type", Value::CreateStringValue("one"));
16 EXPECT_TRUE(EnumType::Populate(*value, enum_type.get())); 16 EXPECT_TRUE(EnumType::Populate(*value, enum_type.get()));
17 EXPECT_EQ(EnumType::TYPE_ONE, enum_type->type); 17 EXPECT_EQ(EnumType::TYPE_ONE, enum_type->type);
18 EXPECT_TRUE(value->Equals(enum_type->ToValue().get())); 18 EXPECT_TRUE(value->Equals(enum_type->ToValue().get()));
19 } 19 }
20 { 20 {
21 scoped_ptr<EnumType> enum_type(new EnumType()); 21 scoped_ptr<EnumType> enum_type(new EnumType());
22 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 22 scoped_ptr<DictionaryValue> value(new DictionaryValue());
23 value->Set("type", Value::CreateStringValue("invalid")); 23 value->Set("type", Value::CreateStringValue("invalid"));
24 EXPECT_FALSE(EnumType::Populate(*value, enum_type.get())); 24 EXPECT_FALSE(EnumType::Populate(*value, enum_type.get()));
25 } 25 }
26 } 26 }
27 27
28 TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) {
29 {
30 ReturnsEnum::Result::State state = ReturnsEnum::Result::STATE_FOO;
31 scoped_ptr<Value> state_value = ReturnsEnum::Result::CreateEnumValue(state);
32 std::string result;
33 state_value->GetAsString(&result);
34 EXPECT_EQ("foo", result);
35 }
36 {
37 ReturnsEnum::Result::State state = ReturnsEnum::Result::STATE_FOO;
38 scoped_ptr<Value> state_value(ReturnsEnum::Result::Create(state));
39 std::string result;
40 state_value->GetAsString(&result);
41 EXPECT_EQ("foo", result);
42 }
43 }
44
28 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { 45 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) {
29 { 46 {
30 scoped_ptr<OptionalEnumType> enum_type(new OptionalEnumType()); 47 scoped_ptr<OptionalEnumType> enum_type(new OptionalEnumType());
31 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 48 scoped_ptr<DictionaryValue> value(new DictionaryValue());
32 value->Set("type", Value::CreateStringValue("two")); 49 value->Set("type", Value::CreateStringValue("two"));
33 EXPECT_TRUE(OptionalEnumType::Populate(*value, enum_type.get())); 50 EXPECT_TRUE(OptionalEnumType::Populate(*value, enum_type.get()));
34 EXPECT_EQ(OptionalEnumType::TYPE_TWO, enum_type->type); 51 EXPECT_EQ(OptionalEnumType::TYPE_TWO, enum_type->type);
35 EXPECT_TRUE(value->Equals(enum_type->ToValue().get())); 52 EXPECT_TRUE(value->Equals(enum_type->ToValue().get()));
36 } 53 }
37 { 54 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 139 }
123 { 140 {
124 scoped_ptr<ListValue> params_value(new ListValue()); 141 scoped_ptr<ListValue> params_value(new ListValue());
125 params_value->Append(Value::CreateStringValue("baz")); 142 params_value->Append(Value::CreateStringValue("baz"));
126 params_value->Append(Value::CreateStringValue("invalid")); 143 params_value->Append(Value::CreateStringValue("invalid"));
127 scoped_ptr<TakesMultipleOptionalEnums::Params> params( 144 scoped_ptr<TakesMultipleOptionalEnums::Params> params(
128 TakesMultipleOptionalEnums::Params::Create(*params_value)); 145 TakesMultipleOptionalEnums::Params::Create(*params_value));
129 EXPECT_FALSE(params.get()); 146 EXPECT_FALSE(params.get());
130 } 147 }
131 } 148 }
149
150 TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) {
Matt Tytel 2012/06/29 01:15:52 Erp. Fixing.
151 {
152 }
153 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/enums.json ('k') | tools/json_schema_compiler/test/objects.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698