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 "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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) { | 28 TEST(JsonSchemaCompilerEnumsTest, EnumsAsTypes) { |
29 { | 29 { |
30 ListValue args; | 30 ListValue args; |
31 args.Append(Value::CreateStringValue("one")); | 31 args.Append(Value::CreateStringValue("one")); |
32 | 32 |
33 scoped_ptr<TakesEnumAsType::Params> params( | 33 scoped_ptr<TakesEnumAsType::Params> params( |
34 TakesEnumAsType::Params::Create(args)); | 34 TakesEnumAsType::Params::Create(args)); |
35 ASSERT_TRUE(params.get()); | 35 ASSERT_TRUE(params.get()); |
36 EXPECT_EQ(ENUMS_ENUMERATION_ONE, params->enumeration); | 36 EXPECT_EQ(ENUMERATION_ONE, params->enumeration); |
37 | 37 |
38 EXPECT_TRUE(args.Equals(ReturnsEnumAsType::Results::Create( | 38 EXPECT_TRUE(args.Equals(ReturnsEnumAsType::Results::Create( |
39 ENUMS_ENUMERATION_ONE).get())); | 39 ENUMERATION_ONE).get())); |
40 } | 40 } |
41 { | 41 { |
42 HasEnumeration enumeration; | 42 HasEnumeration enumeration; |
43 DictionaryValue value; | 43 DictionaryValue value; |
44 ASSERT_FALSE(HasEnumeration::Populate(value, &enumeration)); | 44 ASSERT_FALSE(HasEnumeration::Populate(value, &enumeration)); |
45 | 45 |
46 value.Set("enumeration", Value::CreateStringValue("one")); | 46 value.Set("enumeration", Value::CreateStringValue("one")); |
47 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); | 47 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); |
48 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); | 48 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); |
49 | 49 |
50 value.Set("optional_enumeration", Value::CreateStringValue("two")); | 50 value.Set("optional_enumeration", Value::CreateStringValue("two")); |
51 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); | 51 ASSERT_TRUE(HasEnumeration::Populate(value, &enumeration)); |
52 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); | 52 EXPECT_TRUE(value.Equals(enumeration.ToValue().get())); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) { | 56 TEST(JsonSchemaCompilerEnumsTest, ReturnsEnumCreate) { |
57 { | 57 { |
58 ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; | 58 ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; |
59 scoped_ptr<Value> result = ReturnsEnum::Results::CreateEnumValue(state); | 59 scoped_ptr<Value> result( |
| 60 new base::StringValue(ReturnsEnum::Results::ToString(state))); |
60 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); | 61 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); |
61 EXPECT_TRUE(result->Equals(expected.get())); | 62 EXPECT_TRUE(result->Equals(expected.get())); |
62 } | 63 } |
63 { | 64 { |
64 ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; | 65 ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; |
65 scoped_ptr<ListValue> results = ReturnsEnum::Results::Create(state); | 66 scoped_ptr<ListValue> results = ReturnsEnum::Results::Create(state); |
66 ListValue expected; | 67 ListValue expected; |
67 expected.Append(Value::CreateStringValue("foo")); | 68 expected.Append(Value::CreateStringValue("foo")); |
68 EXPECT_TRUE(results->Equals(&expected)); | 69 EXPECT_TRUE(results->Equals(&expected)); |
69 } | 70 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 params_value.Append(Value::CreateStringValue("invalid")); | 183 params_value.Append(Value::CreateStringValue("invalid")); |
183 scoped_ptr<TakesMultipleOptionalEnums::Params> params( | 184 scoped_ptr<TakesMultipleOptionalEnums::Params> params( |
184 TakesMultipleOptionalEnums::Params::Create(params_value)); | 185 TakesMultipleOptionalEnums::Params::Create(params_value)); |
185 EXPECT_FALSE(params.get()); | 186 EXPECT_FALSE(params.get()); |
186 } | 187 } |
187 } | 188 } |
188 | 189 |
189 TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) { | 190 TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) { |
190 { | 191 { |
191 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; | 192 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
192 scoped_ptr<Value> result(OnEnumFired::CreateEnumValue(some_enum)); | 193 scoped_ptr<Value> result( |
| 194 new base::StringValue(OnEnumFired::ToString(some_enum))); |
193 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); | 195 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); |
194 EXPECT_TRUE(result->Equals(expected.get())); | 196 EXPECT_TRUE(result->Equals(expected.get())); |
195 } | 197 } |
196 { | 198 { |
197 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; | 199 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
198 scoped_ptr<ListValue> results(OnEnumFired::Create(some_enum)); | 200 scoped_ptr<ListValue> results(OnEnumFired::Create(some_enum)); |
199 ListValue expected; | 201 ListValue expected; |
200 expected.Append(Value::CreateStringValue("foo")); | 202 expected.Append(Value::CreateStringValue("foo")); |
201 EXPECT_TRUE(results->Equals(&expected)); | 203 EXPECT_TRUE(results->Equals(&expected)); |
202 } | 204 } |
203 } | 205 } |
204 | 206 |
205 TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) { | 207 TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) { |
206 { | 208 { |
207 scoped_ptr<Value> results(OnTwoEnumsFired::Create( | 209 scoped_ptr<Value> results(OnTwoEnumsFired::Create( |
208 OnTwoEnumsFired::FIRST_ENUM_FOO, | 210 OnTwoEnumsFired::FIRST_ENUM_FOO, |
209 OnTwoEnumsFired::SECOND_ENUM_HAM)); | 211 OnTwoEnumsFired::SECOND_ENUM_HAM)); |
210 ListValue expected; | 212 ListValue expected; |
211 expected.Append(Value::CreateStringValue("foo")); | 213 expected.Append(Value::CreateStringValue("foo")); |
212 expected.Append(Value::CreateStringValue("ham")); | 214 expected.Append(Value::CreateStringValue("ham")); |
213 EXPECT_TRUE(results->Equals(&expected)); | 215 EXPECT_TRUE(results->Equals(&expected)); |
214 } | 216 } |
215 } | 217 } |
OLD | NEW |