| 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 |
| 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::Results::State state = ReturnsEnum::Results::STATE_FOO; |
| 31 scoped_ptr<Value> result = ReturnsEnum::Results::CreateEnumValue(state); |
| 32 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); |
| 33 EXPECT_TRUE(result->Equals(expected.get())); |
| 34 } |
| 35 { |
| 36 ReturnsEnum::Results::State state = ReturnsEnum::Results::STATE_FOO; |
| 37 scoped_ptr<ListValue> results = ReturnsEnum::Results::Create(state); |
| 38 ListValue expected; |
| 39 expected.Append(Value::CreateStringValue("foo")); |
| 40 EXPECT_TRUE(results->Equals(&expected)); |
| 41 } |
| 42 } |
| 43 |
| 44 TEST(JsonSchemaCompilerEnumsTest, ReturnsTwoEnumsCreate) { |
| 45 { |
| 46 scoped_ptr<ListValue> results = ReturnsTwoEnums::Results::Create( |
| 47 ReturnsTwoEnums::Results::FIRST_STATE_FOO, |
| 48 ReturnsTwoEnums::Results::SECOND_STATE_HAM); |
| 49 ListValue expected; |
| 50 expected.Append(Value::CreateStringValue("foo")); |
| 51 expected.Append(Value::CreateStringValue("ham")); |
| 52 EXPECT_TRUE(results->Equals(&expected)); |
| 53 } |
| 54 } |
| 55 |
| 28 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { | 56 TEST(JsonSchemaCompilerEnumsTest, OptionalEnumTypePopulate) { |
| 29 { | 57 { |
| 30 scoped_ptr<OptionalEnumType> enum_type(new OptionalEnumType()); | 58 scoped_ptr<OptionalEnumType> enum_type(new OptionalEnumType()); |
| 31 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 59 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 32 value->Set("type", Value::CreateStringValue("two")); | 60 value->Set("type", Value::CreateStringValue("two")); |
| 33 EXPECT_TRUE(OptionalEnumType::Populate(*value, enum_type.get())); | 61 EXPECT_TRUE(OptionalEnumType::Populate(*value, enum_type.get())); |
| 34 EXPECT_EQ(OptionalEnumType::TYPE_TWO, enum_type->type); | 62 EXPECT_EQ(OptionalEnumType::TYPE_TWO, enum_type->type); |
| 35 EXPECT_TRUE(value->Equals(enum_type->ToValue().get())); | 63 EXPECT_TRUE(value->Equals(enum_type->ToValue().get())); |
| 36 } | 64 } |
| 37 { | 65 { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 150 } |
| 123 { | 151 { |
| 124 scoped_ptr<ListValue> params_value(new ListValue()); | 152 scoped_ptr<ListValue> params_value(new ListValue()); |
| 125 params_value->Append(Value::CreateStringValue("baz")); | 153 params_value->Append(Value::CreateStringValue("baz")); |
| 126 params_value->Append(Value::CreateStringValue("invalid")); | 154 params_value->Append(Value::CreateStringValue("invalid")); |
| 127 scoped_ptr<TakesMultipleOptionalEnums::Params> params( | 155 scoped_ptr<TakesMultipleOptionalEnums::Params> params( |
| 128 TakesMultipleOptionalEnums::Params::Create(*params_value)); | 156 TakesMultipleOptionalEnums::Params::Create(*params_value)); |
| 129 EXPECT_FALSE(params.get()); | 157 EXPECT_FALSE(params.get()); |
| 130 } | 158 } |
| 131 } | 159 } |
| 160 |
| 161 TEST(JsonSchemaCompilerEnumsTest, OnEnumFiredCreate) { |
| 162 { |
| 163 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
| 164 scoped_ptr<Value> result(OnEnumFired::CreateEnumValue(some_enum)); |
| 165 scoped_ptr<Value> expected(Value::CreateStringValue("foo")); |
| 166 EXPECT_TRUE(result->Equals(expected.get())); |
| 167 } |
| 168 { |
| 169 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
| 170 scoped_ptr<ListValue> results(OnEnumFired::Create(some_enum)); |
| 171 ListValue expected; |
| 172 expected.Append(Value::CreateStringValue("foo")); |
| 173 EXPECT_TRUE(results->Equals(&expected)); |
| 174 } |
| 175 } |
| 176 |
| 177 TEST(JsonSchemaCompilerEnumsTest, OnTwoEnumsFiredCreate) { |
| 178 { |
| 179 scoped_ptr<Value> results(OnTwoEnumsFired::Create( |
| 180 OnTwoEnumsFired::FIRST_ENUM_FOO, |
| 181 OnTwoEnumsFired::SECOND_ENUM_HAM)); |
| 182 ListValue expected; |
| 183 expected.Append(Value::CreateStringValue("foo")); |
| 184 expected.Append(Value::CreateStringValue("ham")); |
| 185 EXPECT_TRUE(results->Equals(&expected)); |
| 186 } |
| 187 } |
| OLD | NEW |