| 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/simple_api.h" | 5 #include "tools/json_schema_compiler/test/simple_api.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::simple_api; | 9 using namespace test::api::simple_api; |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 static scoped_ptr<DictionaryValue> CreateTestTypeDictionary() { | 13 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() { |
| 14 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 14 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 15 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1)); | 15 value->SetWithoutPathExpansion("number", |
| 16 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4)); | 16 base::Value::CreateDoubleValue(1.1)); |
| 17 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling")); | 17 value->SetWithoutPathExpansion("integer", |
| 18 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true)); | 18 base::Value::CreateIntegerValue(4)); |
| 19 value->SetWithoutPathExpansion("string", |
| 20 base::Value::CreateStringValue("bling")); |
| 21 value->SetWithoutPathExpansion("boolean", |
| 22 base::Value::CreateBooleanValue(true)); |
| 19 return value.Pass(); | 23 return value.Pass(); |
| 20 } | 24 } |
| 21 | 25 |
| 22 } // namespace | 26 } // namespace |
| 23 | 27 |
| 24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { | 28 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { |
| 25 scoped_ptr<ListValue> results = IncrementInteger::Results::Create(5); | 29 scoped_ptr<base::ListValue> results = IncrementInteger::Results::Create(5); |
| 26 ListValue expected; | 30 base::ListValue expected; |
| 27 expected.Append(Value::CreateIntegerValue(5)); | 31 expected.Append(base::Value::CreateIntegerValue(5)); |
| 28 EXPECT_TRUE(results->Equals(&expected)); | 32 EXPECT_TRUE(results->Equals(&expected)); |
| 29 } | 33 } |
| 30 | 34 |
| 31 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { | 35 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { |
| 32 scoped_ptr<ListValue> params_value(new ListValue()); | 36 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 33 params_value->Append(Value::CreateIntegerValue(6)); | 37 params_value->Append(base::Value::CreateIntegerValue(6)); |
| 34 scoped_ptr<IncrementInteger::Params> params( | 38 scoped_ptr<IncrementInteger::Params> params( |
| 35 IncrementInteger::Params::Create(*params_value)); | 39 IncrementInteger::Params::Create(*params_value)); |
| 36 EXPECT_TRUE(params.get()); | 40 EXPECT_TRUE(params.get()); |
| 37 EXPECT_EQ(6, params->num); | 41 EXPECT_EQ(6, params->num); |
| 38 } | 42 } |
| 39 | 43 |
| 40 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { | 44 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { |
| 41 { | 45 { |
| 42 scoped_ptr<ListValue> params_value(new ListValue()); | 46 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 43 params_value->Append(Value::CreateStringValue("text")); | 47 params_value->Append(base::Value::CreateStringValue("text")); |
| 44 params_value->Append(Value::CreateStringValue("text")); | 48 params_value->Append(base::Value::CreateStringValue("text")); |
| 45 scoped_ptr<OptionalString::Params> params( | 49 scoped_ptr<OptionalString::Params> params( |
| 46 OptionalString::Params::Create(*params_value)); | 50 OptionalString::Params::Create(*params_value)); |
| 47 EXPECT_FALSE(params.get()); | 51 EXPECT_FALSE(params.get()); |
| 48 } | 52 } |
| 49 { | 53 { |
| 50 scoped_ptr<ListValue> params_value(new ListValue()); | 54 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 51 scoped_ptr<IncrementInteger::Params> params( | 55 scoped_ptr<IncrementInteger::Params> params( |
| 52 IncrementInteger::Params::Create(*params_value)); | 56 IncrementInteger::Params::Create(*params_value)); |
| 53 EXPECT_FALSE(params.get()); | 57 EXPECT_FALSE(params.get()); |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 | 60 |
| 57 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { | 61 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { |
| 58 { | 62 { |
| 59 scoped_ptr<ListValue> params_value(new ListValue()); | 63 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 60 scoped_ptr<OptionalString::Params> params( | 64 scoped_ptr<OptionalString::Params> params( |
| 61 OptionalString::Params::Create(*params_value)); | 65 OptionalString::Params::Create(*params_value)); |
| 62 EXPECT_TRUE(params.get()); | 66 EXPECT_TRUE(params.get()); |
| 63 EXPECT_FALSE(params->str.get()); | 67 EXPECT_FALSE(params->str.get()); |
| 64 } | 68 } |
| 65 { | 69 { |
| 66 scoped_ptr<ListValue> params_value(new ListValue()); | 70 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 67 params_value->Append(Value::CreateStringValue("asdf")); | 71 params_value->Append(base::Value::CreateStringValue("asdf")); |
| 68 scoped_ptr<OptionalString::Params> params( | 72 scoped_ptr<OptionalString::Params> params( |
| 69 OptionalString::Params::Create(*params_value)); | 73 OptionalString::Params::Create(*params_value)); |
| 70 EXPECT_TRUE(params.get()); | 74 EXPECT_TRUE(params.get()); |
| 71 EXPECT_TRUE(params->str.get()); | 75 EXPECT_TRUE(params->str.get()); |
| 72 EXPECT_EQ("asdf", *params->str); | 76 EXPECT_EQ("asdf", *params->str); |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 | 79 |
| 76 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { | 80 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { |
| 77 { | 81 { |
| 78 scoped_ptr<ListValue> params_value(new ListValue()); | 82 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 79 params_value->Append(Value::CreateNullValue()); | 83 params_value->Append(base::Value::CreateNullValue()); |
| 80 scoped_ptr<OptionalString::Params> params( | 84 scoped_ptr<OptionalString::Params> params( |
| 81 OptionalString::Params::Create(*params_value)); | 85 OptionalString::Params::Create(*params_value)); |
| 82 EXPECT_TRUE(params.get()); | 86 EXPECT_TRUE(params.get()); |
| 83 EXPECT_FALSE(params->str.get()); | 87 EXPECT_FALSE(params->str.get()); |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 | 90 |
| 87 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) { | 91 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsWrongType) { |
| 88 { | 92 { |
| 89 scoped_ptr<ListValue> params_value(new ListValue()); | 93 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 90 params_value->Append(Value::CreateIntegerValue(5)); | 94 params_value->Append(base::Value::CreateIntegerValue(5)); |
| 91 scoped_ptr<OptionalString::Params> params( | 95 scoped_ptr<OptionalString::Params> params( |
| 92 OptionalString::Params::Create(*params_value)); | 96 OptionalString::Params::Create(*params_value)); |
| 93 EXPECT_FALSE(params.get()); | 97 EXPECT_FALSE(params.get()); |
| 94 } | 98 } |
| 95 } | 99 } |
| 96 | 100 |
| 97 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { | 101 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { |
| 98 { | 102 { |
| 99 scoped_ptr<ListValue> params_value(new ListValue()); | 103 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 100 params_value->Append(Value::CreateNullValue()); | 104 params_value->Append(base::Value::CreateNullValue()); |
| 101 params_value->Append(Value::CreateStringValue("asdf")); | 105 params_value->Append(base::Value::CreateStringValue("asdf")); |
| 102 scoped_ptr<OptionalBeforeRequired::Params> params( | 106 scoped_ptr<OptionalBeforeRequired::Params> params( |
| 103 OptionalBeforeRequired::Params::Create(*params_value)); | 107 OptionalBeforeRequired::Params::Create(*params_value)); |
| 104 EXPECT_TRUE(params.get()); | 108 EXPECT_TRUE(params.get()); |
| 105 EXPECT_FALSE(params->first.get()); | 109 EXPECT_FALSE(params->first.get()); |
| 106 EXPECT_EQ("asdf", params->second); | 110 EXPECT_EQ("asdf", params->second); |
| 107 } | 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { | 114 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { |
| 111 scoped_ptr<ListValue> results = OptionalString::Results::Create(); | 115 scoped_ptr<base::ListValue> results = OptionalString::Results::Create(); |
| 112 ListValue expected; | 116 base::ListValue expected; |
| 113 EXPECT_TRUE(results->Equals(&expected)); | 117 EXPECT_TRUE(results->Equals(&expected)); |
| 114 } | 118 } |
| 115 | 119 |
| 116 TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { | 120 TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { |
| 117 { | 121 { |
| 118 scoped_ptr<TestType> test_type(new TestType()); | 122 scoped_ptr<TestType> test_type(new TestType()); |
| 119 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 123 scoped_ptr<base::DictionaryValue> value = CreateTestTypeDictionary(); |
| 120 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); | 124 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); |
| 121 EXPECT_EQ("bling", test_type->string); | 125 EXPECT_EQ("bling", test_type->string); |
| 122 EXPECT_EQ(1.1, test_type->number); | 126 EXPECT_EQ(1.1, test_type->number); |
| 123 EXPECT_EQ(4, test_type->integer); | 127 EXPECT_EQ(4, test_type->integer); |
| 124 EXPECT_EQ(true, test_type->boolean); | 128 EXPECT_EQ(true, test_type->boolean); |
| 125 EXPECT_TRUE(value->Equals(test_type->ToValue().get())); | 129 EXPECT_TRUE(value->Equals(test_type->ToValue().get())); |
| 126 } | 130 } |
| 127 { | 131 { |
| 128 scoped_ptr<TestType> test_type(new TestType()); | 132 scoped_ptr<TestType> test_type(new TestType()); |
| 129 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 133 scoped_ptr<base::DictionaryValue> value = CreateTestTypeDictionary(); |
| 130 value->Remove("number", NULL); | 134 value->Remove("number", NULL); |
| 131 EXPECT_FALSE(TestType::Populate(*value, test_type.get())); | 135 EXPECT_FALSE(TestType::Populate(*value, test_type.get())); |
| 132 } | 136 } |
| 133 } | 137 } |
| 134 | 138 |
| 135 TEST(JsonSchemaCompilerSimpleTest, GetTestType) { | 139 TEST(JsonSchemaCompilerSimpleTest, GetTestType) { |
| 136 { | 140 { |
| 137 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 141 scoped_ptr<base::DictionaryValue> value = CreateTestTypeDictionary(); |
| 138 scoped_ptr<TestType> test_type(new TestType()); | 142 scoped_ptr<TestType> test_type(new TestType()); |
| 139 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); | 143 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); |
| 140 scoped_ptr<ListValue> results = GetTestType::Results::Create(*test_type); | 144 scoped_ptr<base::ListValue> results = |
| 145 GetTestType::Results::Create(*test_type); |
| 141 | 146 |
| 142 DictionaryValue* result = NULL; | 147 base::DictionaryValue* result = NULL; |
| 143 results->GetDictionary(0, &result); | 148 results->GetDictionary(0, &result); |
| 144 EXPECT_TRUE(result->Equals(value.get())); | 149 EXPECT_TRUE(result->Equals(value.get())); |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 | 152 |
| 148 TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { | 153 TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { |
| 149 { | 154 { |
| 150 scoped_ptr<ListValue> results(OnIntegerFired::Create(5)); | 155 scoped_ptr<base::ListValue> results(OnIntegerFired::Create(5)); |
| 151 ListValue expected; | 156 base::ListValue expected; |
| 152 expected.Append(Value::CreateIntegerValue(5)); | 157 expected.Append(base::Value::CreateIntegerValue(5)); |
| 153 EXPECT_TRUE(results->Equals(&expected)); | 158 EXPECT_TRUE(results->Equals(&expected)); |
| 154 } | 159 } |
| 155 } | 160 } |
| 156 | 161 |
| 157 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { | 162 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { |
| 158 { | 163 { |
| 159 scoped_ptr<ListValue> results(OnStringFired::Create("yo dawg")); | 164 scoped_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); |
| 160 ListValue expected; | 165 base::ListValue expected; |
| 161 expected.Append(Value::CreateStringValue("yo dawg")); | 166 expected.Append(base::Value::CreateStringValue("yo dawg")); |
| 162 EXPECT_TRUE(results->Equals(&expected)); | 167 EXPECT_TRUE(results->Equals(&expected)); |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { | 171 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { |
| 167 { | 172 { |
| 168 TestType some_test_type; | 173 TestType some_test_type; |
| 169 scoped_ptr<DictionaryValue> expected = CreateTestTypeDictionary(); | 174 scoped_ptr<base::DictionaryValue> expected = CreateTestTypeDictionary(); |
| 170 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); | 175 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); |
| 171 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); | 176 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); |
| 172 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); | 177 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); |
| 173 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); | 178 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); |
| 174 | 179 |
| 175 scoped_ptr<ListValue> results(OnTestTypeFired::Create(some_test_type)); | 180 scoped_ptr<base::ListValue> results( |
| 176 DictionaryValue* result = NULL; | 181 OnTestTypeFired::Create(some_test_type)); |
| 182 base::DictionaryValue* result = NULL; |
| 177 results->GetDictionary(0, &result); | 183 results->GetDictionary(0, &result); |
| 178 EXPECT_TRUE(result->Equals(expected.get())); | 184 EXPECT_TRUE(result->Equals(expected.get())); |
| 179 } | 185 } |
| 180 } | 186 } |
| OLD | NEW |