Chromium Code Reviews| 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> test_type_value = CreateTestTypeDictionary(); | |
| 28 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | |
| 29 value->Set("testType", test_type_value.release()); | |
|
not at google - send to devlin
2012/02/24 03:53:05
inline CreateTestTypeDictionary()?
calamity
2012/02/24 15:10:40
Done.
| |
| 30 EXPECT_TRUE(CrossrefType::Populate(*value, crossref_type.get())); | |
| 31 EXPECT_TRUE(crossref_type->test_type.get()); | |
| 32 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( | |
| 33 crossref_type->test_type->ToValue().get())); | |
| 34 EXPECT_TRUE(value->Equals(crossref_type->ToValue().get())); | |
| 35 } | |
| 36 | |
| 25 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { | 37 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { |
| 26 scoped_ptr<ListValue> params_value(new ListValue()); | 38 scoped_ptr<ListValue> params_value(new ListValue()); |
| 27 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); | 39 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); |
| 28 params_value->Append(test_type_value.release()); | 40 params_value->Append(test_type_value.release()); |
| 29 scoped_ptr<TestTypeOptionalParam::Params> params( | 41 scoped_ptr<TestTypeOptionalParam::Params> params( |
| 30 TestTypeOptionalParam::Params::Create(*params_value)); | 42 TestTypeOptionalParam::Params::Create(*params_value)); |
| 31 EXPECT_TRUE(params.get()); | 43 EXPECT_TRUE(params.get()); |
| 32 EXPECT_TRUE(params->test_type.get()); | 44 EXPECT_TRUE(params->test_type.get()); |
| 33 EXPECT_TRUE( | 45 EXPECT_TRUE( |
| 34 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get())); | 46 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get())); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 46 | 58 |
| 47 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { | 59 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { |
| 48 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); | 60 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary(); |
| 49 scoped_ptr<test::api::simple_api::TestType> test_type( | 61 scoped_ptr<test::api::simple_api::TestType> test_type( |
| 50 new test::api::simple_api::TestType()); | 62 new test::api::simple_api::TestType()); |
| 51 EXPECT_TRUE( | 63 EXPECT_TRUE( |
| 52 test::api::simple_api::TestType::Populate(*value, test_type.get())); | 64 test::api::simple_api::TestType::Populate(*value, test_type.get())); |
| 53 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type)); | 65 scoped_ptr<Value> result(GetTestType::Result::Create(*test_type)); |
| 54 EXPECT_TRUE(value->Equals(result.get())); | 66 EXPECT_TRUE(value->Equals(result.get())); |
| 55 } | 67 } |
| 68 | |
| 69 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { | |
| 70 { | |
| 71 scoped_ptr<ListValue> params_value(new ListValue()); | |
| 72 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); | |
| 73 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); | |
| 74 param_object_value->Set("testType", test_type_value.release()); | |
|
not at google - send to devlin
2012/02/24 03:53:05
ditto (and everywhere else)
calamity
2012/02/24 15:10:40
Done.
| |
| 75 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); | |
| 76 params_value->Append(param_object_value.release()); | |
| 77 scoped_ptr<TestTypeInObject::Params> params( | |
| 78 TestTypeInObject::Params::Create(*params_value)); | |
| 79 EXPECT_TRUE(params.get()); | |
| 80 EXPECT_TRUE(params->param_object.test_type.get()); | |
| 81 EXPECT_TRUE(params->param_object.boolean); | |
| 82 EXPECT_TRUE(CreateTestTypeDictionary()->Equals( | |
| 83 params->param_object.test_type->ToValue().get())); | |
| 84 } | |
| 85 { | |
| 86 scoped_ptr<ListValue> params_value(new ListValue()); | |
| 87 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); | |
| 88 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); | |
| 89 params_value->Append(param_object_value.release()); | |
| 90 scoped_ptr<TestTypeInObject::Params> params( | |
| 91 TestTypeInObject::Params::Create(*params_value)); | |
| 92 EXPECT_TRUE(params.get()); | |
| 93 EXPECT_FALSE(params->param_object.test_type.get()); | |
| 94 EXPECT_TRUE(params->param_object.boolean); | |
| 95 } | |
| 96 { | |
| 97 scoped_ptr<ListValue> params_value(new ListValue()); | |
| 98 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); | |
| 99 param_object_value->Set("testType", Value::CreateStringValue("invalid")); | |
| 100 param_object_value->Set("boolean", Value::CreateBooleanValue(true)); | |
| 101 params_value->Append(param_object_value.release()); | |
| 102 scoped_ptr<TestTypeInObject::Params> params( | |
| 103 TestTypeInObject::Params::Create(*params_value)); | |
| 104 EXPECT_FALSE(params.get()); | |
| 105 } | |
| 106 { | |
| 107 scoped_ptr<ListValue> params_value(new ListValue()); | |
| 108 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary(); | |
| 109 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue()); | |
| 110 param_object_value->Set("testType", test_type_value.release()); | |
| 111 params_value->Append(param_object_value.release()); | |
| 112 scoped_ptr<TestTypeInObject::Params> params( | |
| 113 TestTypeInObject::Params::Create(*params_value)); | |
| 114 EXPECT_FALSE(params.get()); | |
| 115 } | |
| 116 } | |
| OLD | NEW |