| 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<DictionaryValue> CreateTestTypeDictionary() { |
| 14 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 14 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 15 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1)); | 15 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1)); |
| 16 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4)); | 16 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4)); |
| 17 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling")); | 17 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling")); |
| 18 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true)); | 18 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true)); |
| 19 return value.Pass(); | 19 return value.Pass(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { | 24 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerResultCreate) { |
| 25 scoped_ptr<Value> result(IncrementInteger::Result::Create(5)); | 25 scoped_ptr<ListValue> results = IncrementInteger::Results::Create(5); |
| 26 int temp = 0; | 26 ListValue expected; |
| 27 EXPECT_TRUE(result->GetAsInteger(&temp)); | 27 expected.Append(Value::CreateIntegerValue(5)); |
| 28 EXPECT_EQ(5, temp); | 28 EXPECT_TRUE(results->Equals(&expected)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { | 31 TEST(JsonSchemaCompilerSimpleTest, IncrementIntegerParamsCreate) { |
| 32 scoped_ptr<ListValue> params_value(new ListValue()); | 32 scoped_ptr<ListValue> params_value(new ListValue()); |
| 33 params_value->Append(Value::CreateIntegerValue(6)); | 33 params_value->Append(Value::CreateIntegerValue(6)); |
| 34 scoped_ptr<IncrementInteger::Params> params( | 34 scoped_ptr<IncrementInteger::Params> params( |
| 35 IncrementInteger::Params::Create(*params_value)); | 35 IncrementInteger::Params::Create(*params_value)); |
| 36 EXPECT_TRUE(params.get()); | 36 EXPECT_TRUE(params.get()); |
| 37 EXPECT_EQ(6, params->num); | 37 EXPECT_EQ(6, params->num); |
| 38 } | 38 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 params_value->Append(Value::CreateStringValue("asdf")); | 101 params_value->Append(Value::CreateStringValue("asdf")); |
| 102 scoped_ptr<OptionalBeforeRequired::Params> params( | 102 scoped_ptr<OptionalBeforeRequired::Params> params( |
| 103 OptionalBeforeRequired::Params::Create(*params_value)); | 103 OptionalBeforeRequired::Params::Create(*params_value)); |
| 104 EXPECT_TRUE(params.get()); | 104 EXPECT_TRUE(params.get()); |
| 105 EXPECT_FALSE(params->first.get()); | 105 EXPECT_FALSE(params->first.get()); |
| 106 EXPECT_EQ("asdf", params->second); | 106 EXPECT_EQ("asdf", params->second); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { | 110 TEST(JsonSchemaCompilerSimpleTest, NoParamsResultCreate) { |
| 111 scoped_ptr<Value> result(OptionalString::Result::Create()); | 111 scoped_ptr<ListValue> results = OptionalString::Results::Create(); |
| 112 scoped_ptr<Value> expected(Value::CreateNullValue()); | 112 ListValue expected; |
| 113 EXPECT_TRUE(Value::Equals(result.get(), expected.get())); | 113 EXPECT_TRUE(results->Equals(&expected)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { | 116 TEST(JsonSchemaCompilerSimpleTest, TestTypePopulate) { |
| 117 { | 117 { |
| 118 scoped_ptr<TestType> test_type(new TestType()); | 118 scoped_ptr<TestType> test_type(new TestType()); |
| 119 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 119 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); |
| 120 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); | 120 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); |
| 121 EXPECT_EQ("bling", test_type->string); | 121 EXPECT_EQ("bling", test_type->string); |
| 122 EXPECT_EQ(1.1, test_type->number); | 122 EXPECT_EQ(1.1, test_type->number); |
| 123 EXPECT_EQ(4, test_type->integer); | 123 EXPECT_EQ(4, test_type->integer); |
| 124 EXPECT_EQ(true, test_type->boolean); | 124 EXPECT_EQ(true, test_type->boolean); |
| 125 EXPECT_TRUE(value->Equals(test_type->ToValue().get())); | 125 EXPECT_TRUE(value->Equals(test_type->ToValue().get())); |
| 126 } | 126 } |
| 127 { | 127 { |
| 128 scoped_ptr<TestType> test_type(new TestType()); | 128 scoped_ptr<TestType> test_type(new TestType()); |
| 129 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 129 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); |
| 130 value->Remove("number", NULL); | 130 value->Remove("number", NULL); |
| 131 EXPECT_FALSE(TestType::Populate(*value, test_type.get())); | 131 EXPECT_FALSE(TestType::Populate(*value, test_type.get())); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST(JsonSchemaCompilerSimpleTest, GetTestType) { | 135 TEST(JsonSchemaCompilerSimpleTest, GetTestType) { |
| 136 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 136 { |
| 137 scoped_ptr<TestType> test_type(new TestType()); | 137 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); |
| 138 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); | 138 scoped_ptr<TestType> test_type(new TestType()); |
| 139 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type)); | 139 EXPECT_TRUE(TestType::Populate(*value, test_type.get())); |
| 140 EXPECT_TRUE(value->Equals(result.get())); | 140 scoped_ptr<ListValue> results = GetTestType::Results::Create(*test_type); |
| 141 |
| 142 DictionaryValue* result = NULL; |
| 143 results->GetDictionary(0, &result); |
| 144 EXPECT_TRUE(result->Equals(value.get())); |
| 145 } |
| 141 } | 146 } |
| 142 | 147 |
| 148 TEST(JsonSchemaCompilerSimpleTest, OnIntegerFiredCreate) { |
| 149 { |
| 150 scoped_ptr<ListValue> results(OnIntegerFired::Create(5)); |
| 151 ListValue expected; |
| 152 expected.Append(Value::CreateIntegerValue(5)); |
| 153 EXPECT_TRUE(results->Equals(&expected)); |
| 154 } |
| 155 } |
| 156 |
| 157 TEST(JsonSchemaCompilerSimpleTest, OnStringFiredCreate) { |
| 158 { |
| 159 scoped_ptr<ListValue> results(OnStringFired::Create("yo dawg")); |
| 160 ListValue expected; |
| 161 expected.Append(Value::CreateStringValue("yo dawg")); |
| 162 EXPECT_TRUE(results->Equals(&expected)); |
| 163 } |
| 164 } |
| 165 |
| 166 TEST(JsonSchemaCompilerSimpleTest, OnTestTypeFiredCreate) { |
| 167 { |
| 168 TestType some_test_type; |
| 169 scoped_ptr<DictionaryValue> expected = CreateTestTypeDictionary(); |
| 170 ASSERT_TRUE(expected->GetDouble("number", &some_test_type.number)); |
| 171 ASSERT_TRUE(expected->GetString("string", &some_test_type.string)); |
| 172 ASSERT_TRUE(expected->GetInteger("integer", &some_test_type.integer)); |
| 173 ASSERT_TRUE(expected->GetBoolean("boolean", &some_test_type.boolean)); |
| 174 |
| 175 scoped_ptr<ListValue> results(OnTestTypeFired::Create(some_test_type)); |
| 176 DictionaryValue* result = NULL; |
| 177 results->GetDictionary(0, &result); |
| 178 EXPECT_TRUE(result->Equals(expected.get())); |
| 179 } |
| 180 } |
| OLD | NEW |