| 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 #include "tools/json_schema_compiler/test/crossref.h" | 6 #include "tools/json_schema_compiler/test/crossref.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 using namespace test::api::crossref; | 10 using namespace test::api::crossref; |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 static scoped_ptr<DictionaryValue> CreateTestTypeDictionary() { | 14 static scoped_ptr<DictionaryValue> CreateTestTypeDictionary() { |
| 15 DictionaryValue* value(new DictionaryValue()); | 15 DictionaryValue* value(new DictionaryValue()); |
| 16 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1)); | 16 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1)); |
| 17 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4)); | 17 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4)); |
| 18 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling")); | 18 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling")); |
| 19 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true)); | 19 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true)); |
| 20 return scoped_ptr<DictionaryValue>(value); | 20 return scoped_ptr<DictionaryValue>(value); |
| 21 } | 21 } |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulate) { |
| 26 scoped_ptr<CrossrefType> crossref_type(new CrossrefType()); |
| 27 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 28 value->Set("testType", CreateTestTypeDictionary().release()); |
| 29 EXPECT_TRUE(CrossrefType::Populate(*value, crossref_type.get())); |
| 30 EXPECT_TRUE(crossref_type->test_type.get()); |
| 31 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( |
| 32 crossref_type->test_type->ToValue().get())); |
| 33 EXPECT_TRUE(value->Equals(crossref_type->ToValue().get())); |
| 34 } |
| 35 |
| 25 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { | 36 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { |
| 26 scoped_ptr<ListValue> params_value(new ListValue()); | 37 scoped_ptr<ListValue> params_value(new ListValue()); |
| 27 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); | 38 params_value->Append(CreateTestTypeDictionary().release()); |
| 28 params_value->Append(test_type_value.release()); | |
| 29 scoped_ptr<TestTypeOptionalParam::Params> params( | 39 scoped_ptr<TestTypeOptionalParam::Params> params( |
| 30 TestTypeOptionalParam::Params::Create(*params_value)); | 40 TestTypeOptionalParam::Params::Create(*params_value)); |
| 31 EXPECT_TRUE(params.get()); | 41 EXPECT_TRUE(params.get()); |
| 32 EXPECT_TRUE(params->test_type.get()); | 42 EXPECT_TRUE(params->test_type.get()); |
| 33 EXPECT_TRUE( | 43 EXPECT_TRUE( |
| 34 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get())); | 44 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get())); |
| 35 } | 45 } |
| 36 | 46 |
| 37 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { | 47 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { |
| 38 scoped_ptr<ListValue> params_value(new ListValue()); | 48 scoped_ptr<ListValue> params_value(new ListValue()); |
| 39 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); | 49 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); |
| 40 test_type_value->RemoveWithoutPathExpansion("number", NULL); | 50 test_type_value->RemoveWithoutPathExpansion("number", NULL); |
| 41 params_value->Append(test_type_value.release()); | 51 params_value->Append(test_type_value.release()); |
| 42 scoped_ptr<TestTypeOptionalParam::Params> params( | 52 scoped_ptr<TestTypeOptionalParam::Params> params( |
| 43 TestTypeOptionalParam::Params::Create(*params_value)); | 53 TestTypeOptionalParam::Params::Create(*params_value)); |
| 44 EXPECT_FALSE(params.get()); | 54 EXPECT_FALSE(params.get()); |
| 45 } | 55 } |
| 46 | 56 |
| 47 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { | 57 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { |
| 48 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 58 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); |
| 49 scoped_ptr<test::api::simple_api::TestType> test_type( | 59 scoped_ptr<test::api::simple_api::TestType> test_type( |
| 50 new test::api::simple_api::TestType()); | 60 new test::api::simple_api::TestType()); |
| 51 EXPECT_TRUE( | 61 EXPECT_TRUE( |
| 52 test::api::simple_api::TestType::Populate(*value, test_type.get())); | 62 test::api::simple_api::TestType::Populate(*value, test_type.get())); |
| 53 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type)); | 63 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type)); |
| 54 EXPECT_TRUE(value->Equals(result.get())); | 64 EXPECT_TRUE(value->Equals(result.get())); |
| 55 } | 65 } |
| 66 |
| 67 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { |
| 68 { |
| 69 scoped_ptr<ListValue> params_value(new ListValue()); |
| 70 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); |
| 71 param_object_value->Set("testType", CreateTestTypeDictionary().release()); |
| 72 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); |
| 73 params_value->Append(param_object_value.release()); |
| 74 scoped_ptr<TestTypeInObject::Params> params( |
| 75 TestTypeInObject::Params::Create(*params_value)); |
| 76 EXPECT_TRUE(params.get()); |
| 77 EXPECT_TRUE(params->param_object.test_type.get()); |
| 78 EXPECT_TRUE(params->param_object.boolean); |
| 79 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( |
| 80 params->param_object.test_type->ToValue().get())); |
| 81 } |
| 82 { |
| 83 scoped_ptr<ListValue> params_value(new ListValue()); |
| 84 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); |
| 85 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); |
| 86 params_value->Append(param_object_value.release()); |
| 87 scoped_ptr<TestTypeInObject::Params> params( |
| 88 TestTypeInObject::Params::Create(*params_value)); |
| 89 EXPECT_TRUE(params.get()); |
| 90 EXPECT_FALSE(params->param_object.test_type.get()); |
| 91 EXPECT_TRUE(params->param_object.boolean); |
| 92 } |
| 93 { |
| 94 scoped_ptr<ListValue> params_value(new ListValue()); |
| 95 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); |
| 96 param_object_value->Set("testType", Value::CreateStringValue("invalid")); |
| 97 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); |
| 98 params_value->Append(param_object_value.release()); |
| 99 scoped_ptr<TestTypeInObject::Params> params( |
| 100 TestTypeInObject::Params::Create(*params_value)); |
| 101 EXPECT_FALSE(params.get()); |
| 102 } |
| 103 { |
| 104 scoped_ptr<ListValue> params_value(new ListValue()); |
| 105 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); |
| 106 param_object_value->Set("testType", CreateTestTypeDictionary().release()); |
| 107 params_value->Append(param_object_value.release()); |
| 108 scoped_ptr<TestTypeInObject::Params> params( |
| 109 TestTypeInObject::Params::Create(*params_value)); |
| 110 EXPECT_FALSE(params.get()); |
| 111 } |
| 112 } |
| OLD | NEW |