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