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