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