| 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<base::DictionaryValue> CreateTestTypeDictionary() { | 13 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() { |
| 14 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 14 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 15 value->SetWithoutPathExpansion("number", | 15 value->SetWithoutPathExpansion("number", |
| 16 base::Value::CreateDoubleValue(1.1)); | 16 base::Value::CreateDoubleValue(1.1)); |
| 17 value->SetWithoutPathExpansion("integer", | 17 value->SetWithoutPathExpansion("integer", |
| 18 base::Value::CreateIntegerValue(4)); | 18 base::Value::CreateIntegerValue(4)); |
| 19 value->SetWithoutPathExpansion("string", | 19 value->SetWithoutPathExpansion("string", new base::StringValue("bling")); |
| 20 base::Value::CreateStringValue("bling")); | |
| 21 value->SetWithoutPathExpansion("boolean", | 20 value->SetWithoutPathExpansion("boolean", |
| 22 base::Value::CreateBooleanValue(true)); | 21 base::Value::CreateBooleanValue(true)); |
| 23 return value.Pass(); | 22 return value.Pass(); |
| 24 } | 23 } |
| 25 | 24 |
| 26 } // namespace | 25 } // namespace |
| 27 | 26 |
| 28 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { | 27 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { |
| 29 scoped_ptr<base::ListValue> results = IncrementInteger::Results::Create(5); | 28 scoped_ptr<base::ListValue> results = IncrementInteger::Results::Create(5); |
| 30 base::ListValue expected; | 29 base::ListValue expected; |
| 31 expected.Append(base::Value::CreateIntegerValue(5)); | 30 expected.Append(base::Value::CreateIntegerValue(5)); |
| 32 EXPECT_TRUE(results->Equals(&expected)); | 31 EXPECT_TRUE(results->Equals(&expected)); |
| 33 } | 32 } |
| 34 | 33 |
| 35 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { | 34 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { |
| 36 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 35 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 37 params_value->Append(base::Value::CreateIntegerValue(6)); | 36 params_value->Append(base::Value::CreateIntegerValue(6)); |
| 38 scoped_ptr<IncrementInteger::Params> params( | 37 scoped_ptr<IncrementInteger::Params> params( |
| 39 IncrementInteger::Params::Create(*params_value)); | 38 IncrementInteger::Params::Create(*params_value)); |
| 40 EXPECT_TRUE(params.get()); | 39 EXPECT_TRUE(params.get()); |
| 41 EXPECT_EQ(6, params->num); | 40 EXPECT_EQ(6, params->num); |
| 42 } | 41 } |
| 43 | 42 |
| 44 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { | 43 TEST(JsonSchemaCompilerSimpleTest, NumberOfParams) { |
| 45 { | 44 { |
| 46 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 45 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 47 params_value->Append(base::Value::CreateStringValue("text")); | 46 params_value->Append(new base::StringValue("text")); |
| 48 params_value->Append(base::Value::CreateStringValue("text")); | 47 params_value->Append(new base::StringValue("text")); |
| 49 scoped_ptr<OptionalString::Params> params( | 48 scoped_ptr<OptionalString::Params> params( |
| 50 OptionalString::Params::Create(*params_value)); | 49 OptionalString::Params::Create(*params_value)); |
| 51 EXPECT_FALSE(params.get()); | 50 EXPECT_FALSE(params.get()); |
| 52 } | 51 } |
| 53 { | 52 { |
| 54 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 53 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 55 scoped_ptr<IncrementInteger::Params> params( | 54 scoped_ptr<IncrementInteger::Params> params( |
| 56 IncrementInteger::Params::Create(*params_value)); | 55 IncrementInteger::Params::Create(*params_value)); |
| 57 EXPECT_FALSE(params.get()); | 56 EXPECT_FALSE(params.get()); |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { | 60 TEST(JsonSchemaCompilerSimpleTest, OptionalStringParamsCreate) { |
| 62 { | 61 { |
| 63 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 62 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 64 scoped_ptr<OptionalString::Params> params( | 63 scoped_ptr<OptionalString::Params> params( |
| 65 OptionalString::Params::Create(*params_value)); | 64 OptionalString::Params::Create(*params_value)); |
| 66 EXPECT_TRUE(params.get()); | 65 EXPECT_TRUE(params.get()); |
| 67 EXPECT_FALSE(params->str.get()); | 66 EXPECT_FALSE(params->str.get()); |
| 68 } | 67 } |
| 69 { | 68 { |
| 70 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 69 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 71 params_value->Append(base::Value::CreateStringValue("asdf")); | 70 params_value->Append(new base::StringValue("asdf")); |
| 72 scoped_ptr<OptionalString::Params> params( | 71 scoped_ptr<OptionalString::Params> params( |
| 73 OptionalString::Params::Create(*params_value)); | 72 OptionalString::Params::Create(*params_value)); |
| 74 EXPECT_TRUE(params.get()); | 73 EXPECT_TRUE(params.get()); |
| 75 EXPECT_TRUE(params->str.get()); | 74 EXPECT_TRUE(params->str.get()); |
| 76 EXPECT_EQ("asdf", *params->str); | 75 EXPECT_EQ("asdf", *params->str); |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| 80 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { | 79 TEST(JsonSchemaCompilerSimpleTest, OptionalParamsTakingNull) { |
| 81 { | 80 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 95 scoped_ptr<OptionalString::Params> params( | 94 scoped_ptr<OptionalString::Params> params( |
| 96 OptionalString::Params::Create(*params_value)); | 95 OptionalString::Params::Create(*params_value)); |
| 97 EXPECT_FALSE(params.get()); | 96 EXPECT_FALSE(params.get()); |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { | 100 TEST(JsonSchemaCompilerSimpleTest, OptionalBeforeRequired) { |
| 102 { | 101 { |
| 103 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 102 scoped_ptr<base::ListValue> params_value(new base::ListValue()); |
| 104 params_value->Append(base::Value::CreateNullValue()); | 103 params_value->Append(base::Value::CreateNullValue()); |
| 105 params_value->Append(base::Value::CreateStringValue("asdf")); | 104 params_value->Append(new base::StringValue("asdf")); |
| 106 scoped_ptr<OptionalBeforeRequired::Params> params( | 105 scoped_ptr<OptionalBeforeRequired::Params> params( |
| 107 OptionalBeforeRequired::Params::Create(*params_value)); | 106 OptionalBeforeRequired::Params::Create(*params_value)); |
| 108 EXPECT_TRUE(params.get()); | 107 EXPECT_TRUE(params.get()); |
| 109 EXPECT_FALSE(params->first.get()); | 108 EXPECT_FALSE(params->first.get()); |
| 110 EXPECT_EQ("asdf", params->second); | 109 EXPECT_EQ("asdf", params->second); |
| 111 } | 110 } |
| 112 } | 111 } |
| 113 | 112 |
| 114 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { | 113 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { |
| 115 scoped_ptr<base::ListValue> results = OptionalString::Results::Create(); | 114 scoped_ptr<base::ListValue> results = OptionalString::Results::Create(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 base::ListValue expected; | 155 base::ListValue expected; |
| 157 expected.Append(base::Value::CreateIntegerValue(5)); | 156 expected.Append(base::Value::CreateIntegerValue(5)); |
| 158 EXPECT_TRUE(results->Equals(&expected)); | 157 EXPECT_TRUE(results->Equals(&expected)); |
| 159 } | 158 } |
| 160 } | 159 } |
| 161 | 160 |
| 162 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { | 161 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { |
| 163 { | 162 { |
| 164 scoped_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); | 163 scoped_ptr<base::ListValue> results(OnStringFired::Create("yo dawg")); |
| 165 base::ListValue expected; | 164 base::ListValue expected; |
| 166 expected.Append(base::Value::CreateStringValue("yo dawg")); | 165 expected.Append(new base::StringValue("yo dawg")); |
| 167 EXPECT_TRUE(results->Equals(&expected)); | 166 EXPECT_TRUE(results->Equals(&expected)); |
| 168 } | 167 } |
| 169 } | 168 } |
| 170 | 169 |
| 171 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { | 170 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { |
| 172 { | 171 { |
| 173 TestType some_test_type; | 172 TestType some_test_type; |
| 174 scoped_ptr<base::DictionaryValue> expected = CreateTestTypeDictionary(); | 173 scoped_ptr<base::DictionaryValue> expected = CreateTestTypeDictionary(); |
| 175 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); | 174 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); |
| 176 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); | 175 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); |
| 177 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); | 176 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); |
| 178 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); | 177 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); |
| 179 | 178 |
| 180 scoped_ptr<base::ListValue> results( | 179 scoped_ptr<base::ListValue> results( |
| 181 OnTestTypeFired::Create(some_test_type)); | 180 OnTestTypeFired::Create(some_test_type)); |
| 182 base::DictionaryValue* result = NULL; | 181 base::DictionaryValue* result = NULL; |
| 183 results->GetDictionary(0, &result); | 182 results->GetDictionary(0, &result); |
| 184 EXPECT_TRUE(result->Equals(expected.get())); | 183 EXPECT_TRUE(result->Equals(expected.get())); |
| 185 } | 184 } |
| 186 } | 185 } |
| OLD | NEW |