| 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::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 Loading... |
| 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) { |
| 151 { |
| 152 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
| 153 scoped_ptr<Value> some_enum_value = OnEnumFired::CreateEnumValue(some_enum); |
| 154 std::string result; |
| 155 some_enum_value->GetAsString(&result); |
| 156 EXPECT_EQ("foo", result); |
| 157 } |
| 158 { |
| 159 OnEnumFired::SomeEnum some_enum = OnEnumFired::SOME_ENUM_FOO; |
| 160 scoped_ptr<Value> some_enum_value(OnEnumFired::Create(some_enum)); |
| 161 std::string result; |
| 162 some_enum_value->GetAsString(&result); |
| 163 EXPECT_EQ("foo", result); |
| 164 } |
| 165 } |
| OLD | NEW |