| 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/additional_properties.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "tools/json_schema_compiler/test/additional_properties.h" | |
| 7 | 10 |
| 8 using namespace test::api::additional_properties; | 11 using namespace test::api::additional_properties; |
| 9 | 12 |
| 10 TEST(JsonSchemaCompilerAdditionalPropertiesTest, | 13 TEST(JsonSchemaCompilerAdditionalPropertiesTest, |
| 11 AdditionalPropertiesTypePopulate) { | 14 AdditionalPropertiesTypePopulate) { |
| 12 { | 15 { |
| 13 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | 16 std::unique_ptr<base::ListValue> list_value(new base::ListValue()); |
| 14 list_value->Append(new base::StringValue("asdf")); | 17 list_value->Append(new base::StringValue("asdf")); |
| 15 list_value->Append(new base::FundamentalValue(4)); | 18 list_value->Append(new base::FundamentalValue(4)); |
| 16 scoped_ptr<base::DictionaryValue> type_value(new base::DictionaryValue()); | 19 std::unique_ptr<base::DictionaryValue> type_value( |
| 20 new base::DictionaryValue()); |
| 17 type_value->SetString("string", "value"); | 21 type_value->SetString("string", "value"); |
| 18 type_value->SetInteger("other", 9); | 22 type_value->SetInteger("other", 9); |
| 19 type_value->Set("another", list_value.release()); | 23 type_value->Set("another", list_value.release()); |
| 20 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType()); | 24 std::unique_ptr<AdditionalPropertiesType> type( |
| 25 new AdditionalPropertiesType()); |
| 21 ASSERT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get())); | 26 ASSERT_TRUE(AdditionalPropertiesType::Populate(*type_value, type.get())); |
| 22 EXPECT_TRUE(type->additional_properties.Equals(type_value.get())); | 27 EXPECT_TRUE(type->additional_properties.Equals(type_value.get())); |
| 23 } | 28 } |
| 24 { | 29 { |
| 25 scoped_ptr<base::DictionaryValue> type_value(new base::DictionaryValue()); | 30 std::unique_ptr<base::DictionaryValue> type_value( |
| 31 new base::DictionaryValue()); |
| 26 type_value->SetInteger("string", 3); | 32 type_value->SetInteger("string", 3); |
| 27 scoped_ptr<AdditionalPropertiesType> type(new AdditionalPropertiesType()); | 33 std::unique_ptr<AdditionalPropertiesType> type( |
| 34 new AdditionalPropertiesType()); |
| 28 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get())); | 35 EXPECT_FALSE(AdditionalPropertiesType::Populate(*type_value, type.get())); |
| 29 } | 36 } |
| 30 } | 37 } |
| 31 | 38 |
| 32 TEST(JsonSchemaCompilerAdditionalPropertiesTest, | 39 TEST(JsonSchemaCompilerAdditionalPropertiesTest, |
| 33 AdditionalPropertiesParamsCreate) { | 40 AdditionalPropertiesParamsCreate) { |
| 34 scoped_ptr<base::DictionaryValue> param_object_value( | 41 std::unique_ptr<base::DictionaryValue> param_object_value( |
| 35 new base::DictionaryValue()); | 42 new base::DictionaryValue()); |
| 36 param_object_value->SetString("str", "a"); | 43 param_object_value->SetString("str", "a"); |
| 37 param_object_value->SetInteger("num", 1); | 44 param_object_value->SetInteger("num", 1); |
| 38 scoped_ptr<base::ListValue> params_value(new base::ListValue()); | 45 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); |
| 39 params_value->Append(param_object_value->DeepCopy()); | 46 params_value->Append(param_object_value->DeepCopy()); |
| 40 scoped_ptr<AdditionalProperties::Params> params( | 47 std::unique_ptr<AdditionalProperties::Params> params( |
| 41 AdditionalProperties::Params::Create(*params_value)); | 48 AdditionalProperties::Params::Create(*params_value)); |
| 42 EXPECT_TRUE(params.get()); | 49 EXPECT_TRUE(params.get()); |
| 43 EXPECT_TRUE(params->param_object.additional_properties.Equals( | 50 EXPECT_TRUE(params->param_object.additional_properties.Equals( |
| 44 param_object_value.get())); | 51 param_object_value.get())); |
| 45 } | 52 } |
| 46 | 53 |
| 47 TEST(JsonSchemaCompilerAdditionalPropertiesTest, | 54 TEST(JsonSchemaCompilerAdditionalPropertiesTest, |
| 48 ReturnAdditionalPropertiesResultCreate) { | 55 ReturnAdditionalPropertiesResultCreate) { |
| 49 ReturnAdditionalProperties::Results::ResultObject result_object; | 56 ReturnAdditionalProperties::Results::ResultObject result_object; |
| 50 result_object.integer = 5; | 57 result_object.integer = 5; |
| 51 result_object.additional_properties["key"] = "value"; | 58 result_object.additional_properties["key"] = "value"; |
| 52 | 59 |
| 53 base::ListValue expected; | 60 base::ListValue expected; |
| 54 { | 61 { |
| 55 base::DictionaryValue* dict = new base::DictionaryValue(); | 62 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 56 dict->SetInteger("integer", 5); | 63 dict->SetInteger("integer", 5); |
| 57 dict->SetString("key", "value"); | 64 dict->SetString("key", "value"); |
| 58 expected.Append(dict); | 65 expected.Append(dict); |
| 59 } | 66 } |
| 60 | 67 |
| 61 EXPECT_TRUE(base::Value::Equals( | 68 EXPECT_TRUE(base::Value::Equals( |
| 62 ReturnAdditionalProperties::Results::Create(result_object).get(), | 69 ReturnAdditionalProperties::Results::Create(result_object).get(), |
| 63 &expected)); | 70 &expected)); |
| 64 } | 71 } |
| OLD | NEW |