Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: tools/json_schema_compiler/test/crossref_unittest.cc

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
6 #include "tools/json_schema_compiler/test/crossref.h" 5 #include "tools/json_schema_compiler/test/crossref.h"
7 6
7 #include <memory>
8
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/json_schema_compiler/test/simple_api.h"
9 11
10 using namespace test::api; 12 using namespace test::api;
11 13
12 namespace { 14 namespace {
13 15
14 scoped_ptr<base::DictionaryValue> CreateTestTypeValue() { 16 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() {
15 base::DictionaryValue* value(new base::DictionaryValue()); 17 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
16 value->Set("number", new base::FundamentalValue(1.1)); 18 value->Set("number", new base::FundamentalValue(1.1));
17 value->Set("integer", new base::FundamentalValue(4)); 19 value->Set("integer", new base::FundamentalValue(4));
18 value->Set("string", new base::StringValue("bling")); 20 value->Set("string", new base::StringValue("bling"));
19 value->Set("boolean", new base::FundamentalValue(true)); 21 value->Set("boolean", new base::FundamentalValue(true));
20 return scoped_ptr<base::DictionaryValue>(value); 22 return value;
21 } 23 }
22 24
23 } // namespace 25 } // namespace
24 26
25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { 27 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
26 base::DictionaryValue crossref_orig; 28 base::DictionaryValue crossref_orig;
27 crossref_orig.Set("testType", CreateTestTypeValue().release()); 29 crossref_orig.Set("testType", CreateTestTypeValue().release());
28 crossref_orig.Set("testEnumRequired", new base::StringValue("one")); 30 crossref_orig.Set("testEnumRequired", new base::StringValue("one"));
29 crossref_orig.Set("testEnumOptional", new base::StringValue("two")); 31 crossref_orig.Set("testEnumOptional", new base::StringValue("two"));
30 32
31 // Test Populate of the value --> compiled type. 33 // Test Populate of the value --> compiled type.
32 crossref::CrossrefType crossref_type; 34 crossref::CrossrefType crossref_type;
33 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type)); 35 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type));
34 EXPECT_EQ(1.1, crossref_type.test_type.number); 36 EXPECT_EQ(1.1, crossref_type.test_type.number);
35 EXPECT_EQ(4, crossref_type.test_type.integer); 37 EXPECT_EQ(4, crossref_type.test_type.integer);
36 EXPECT_EQ("bling", crossref_type.test_type.string); 38 EXPECT_EQ("bling", crossref_type.test_type.string);
37 EXPECT_EQ(true, crossref_type.test_type.boolean); 39 EXPECT_EQ(true, crossref_type.test_type.boolean);
38 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required); 40 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required);
39 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional); 41 EXPECT_EQ(simple_api::TEST_ENUM_TWO, crossref_type.test_enum_optional);
40 EXPECT_EQ(simple_api::TEST_ENUM_NONE, crossref_type.test_enum_optional_extra); 42 EXPECT_EQ(simple_api::TEST_ENUM_NONE, crossref_type.test_enum_optional_extra);
41 43
42 // Test ToValue of the compiled type --> value. 44 // Test ToValue of the compiled type --> value.
43 scoped_ptr<base::DictionaryValue> crossref_value = crossref_type.ToValue(); 45 std::unique_ptr<base::DictionaryValue> crossref_value =
46 crossref_type.ToValue();
44 ASSERT_TRUE(crossref_value); 47 ASSERT_TRUE(crossref_value);
45 EXPECT_TRUE(crossref_orig.Equals(crossref_value.get())); 48 EXPECT_TRUE(crossref_orig.Equals(crossref_value.get()));
46 } 49 }
47 50
48 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { 51 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
49 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 52 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
50 params_value->Append(CreateTestTypeValue().release()); 53 params_value->Append(CreateTestTypeValue().release());
51 scoped_ptr<crossref::TestTypeOptionalParam::Params> params( 54 std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
52 crossref::TestTypeOptionalParam::Params::Create(*params_value)); 55 crossref::TestTypeOptionalParam::Params::Create(*params_value));
53 EXPECT_TRUE(params.get()); 56 EXPECT_TRUE(params.get());
54 EXPECT_TRUE(params->test_type.get()); 57 EXPECT_TRUE(params->test_type.get());
55 EXPECT_TRUE( 58 EXPECT_TRUE(
56 CreateTestTypeValue()->Equals(params->test_type->ToValue().get())); 59 CreateTestTypeValue()->Equals(params->test_type->ToValue().get()));
57 } 60 }
58 61
59 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { 62 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
60 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 63 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
61 scoped_ptr<base::DictionaryValue> test_type_value = CreateTestTypeValue(); 64 std::unique_ptr<base::DictionaryValue> test_type_value =
65 CreateTestTypeValue();
62 test_type_value->RemoveWithoutPathExpansion("number", NULL); 66 test_type_value->RemoveWithoutPathExpansion("number", NULL);
63 params_value->Append(test_type_value.release()); 67 params_value->Append(test_type_value.release());
64 scoped_ptr<crossref::TestTypeOptionalParam::Params> params( 68 std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
65 crossref::TestTypeOptionalParam::Params::Create(*params_value)); 69 crossref::TestTypeOptionalParam::Params::Create(*params_value));
66 EXPECT_FALSE(params.get()); 70 EXPECT_FALSE(params.get());
67 } 71 }
68 72
69 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { 73 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
70 scoped_ptr<base::DictionaryValue> value = CreateTestTypeValue(); 74 std::unique_ptr<base::DictionaryValue> value = CreateTestTypeValue();
71 scoped_ptr<simple_api::TestType> test_type(new simple_api::TestType()); 75 std::unique_ptr<simple_api::TestType> test_type(new simple_api::TestType());
72 EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get())); 76 EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
73 77
74 scoped_ptr<base::ListValue> results = 78 std::unique_ptr<base::ListValue> results =
75 crossref::GetTestType::Results::Create(*test_type); 79 crossref::GetTestType::Results::Create(*test_type);
76 base::DictionaryValue* result_dict = NULL; 80 base::DictionaryValue* result_dict = NULL;
77 results->GetDictionary(0, &result_dict); 81 results->GetDictionary(0, &result_dict);
78 EXPECT_TRUE(value->Equals(result_dict)); 82 EXPECT_TRUE(value->Equals(result_dict));
79 } 83 }
80 84
81 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { 85 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
82 { 86 {
83 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 87 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
84 scoped_ptr<base::DictionaryValue> param_object_value( 88 std::unique_ptr<base::DictionaryValue> param_object_value(
85 new base::DictionaryValue()); 89 new base::DictionaryValue());
86 param_object_value->Set("testType", CreateTestTypeValue().release()); 90 param_object_value->Set("testType", CreateTestTypeValue().release());
87 param_object_value->Set("boolean", new base::FundamentalValue(true)); 91 param_object_value->Set("boolean", new base::FundamentalValue(true));
88 params_value->Append(param_object_value.release()); 92 params_value->Append(param_object_value.release());
89 scoped_ptr<crossref::TestTypeInObject::Params> params( 93 std::unique_ptr<crossref::TestTypeInObject::Params> params(
90 crossref::TestTypeInObject::Params::Create(*params_value)); 94 crossref::TestTypeInObject::Params::Create(*params_value));
91 EXPECT_TRUE(params.get()); 95 EXPECT_TRUE(params.get());
92 EXPECT_TRUE(params->param_object.test_type.get()); 96 EXPECT_TRUE(params->param_object.test_type.get());
93 EXPECT_TRUE(params->param_object.boolean); 97 EXPECT_TRUE(params->param_object.boolean);
94 EXPECT_TRUE(CreateTestTypeValue()->Equals( 98 EXPECT_TRUE(CreateTestTypeValue()->Equals(
95 params->param_object.test_type->ToValue().get())); 99 params->param_object.test_type->ToValue().get()));
96 } 100 }
97 { 101 {
98 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 102 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
99 scoped_ptr<base::DictionaryValue> param_object_value( 103 std::unique_ptr<base::DictionaryValue> param_object_value(
100 new base::DictionaryValue()); 104 new base::DictionaryValue());
101 param_object_value->Set("boolean", new base::FundamentalValue(true)); 105 param_object_value->Set("boolean", new base::FundamentalValue(true));
102 params_value->Append(param_object_value.release()); 106 params_value->Append(param_object_value.release());
103 scoped_ptr<crossref::TestTypeInObject::Params> params( 107 std::unique_ptr<crossref::TestTypeInObject::Params> params(
104 crossref::TestTypeInObject::Params::Create(*params_value)); 108 crossref::TestTypeInObject::Params::Create(*params_value));
105 EXPECT_TRUE(params.get()); 109 EXPECT_TRUE(params.get());
106 EXPECT_FALSE(params->param_object.test_type.get()); 110 EXPECT_FALSE(params->param_object.test_type.get());
107 EXPECT_TRUE(params->param_object.boolean); 111 EXPECT_TRUE(params->param_object.boolean);
108 } 112 }
109 { 113 {
110 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 114 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
111 scoped_ptr<base::DictionaryValue> param_object_value( 115 std::unique_ptr<base::DictionaryValue> param_object_value(
112 new base::DictionaryValue()); 116 new base::DictionaryValue());
113 param_object_value->Set("testType", new base::StringValue("invalid")); 117 param_object_value->Set("testType", new base::StringValue("invalid"));
114 param_object_value->Set("boolean", new base::FundamentalValue(true)); 118 param_object_value->Set("boolean", new base::FundamentalValue(true));
115 params_value->Append(param_object_value.release()); 119 params_value->Append(param_object_value.release());
116 scoped_ptr<crossref::TestTypeInObject::Params> params( 120 std::unique_ptr<crossref::TestTypeInObject::Params> params(
117 crossref::TestTypeInObject::Params::Create(*params_value)); 121 crossref::TestTypeInObject::Params::Create(*params_value));
118 EXPECT_FALSE(params.get()); 122 EXPECT_FALSE(params.get());
119 } 123 }
120 { 124 {
121 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 125 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
122 scoped_ptr<base::DictionaryValue> param_object_value( 126 std::unique_ptr<base::DictionaryValue> param_object_value(
123 new base::DictionaryValue()); 127 new base::DictionaryValue());
124 param_object_value->Set("testType", CreateTestTypeValue().release()); 128 param_object_value->Set("testType", CreateTestTypeValue().release());
125 params_value->Append(param_object_value.release()); 129 params_value->Append(param_object_value.release());
126 scoped_ptr<crossref::TestTypeInObject::Params> params( 130 std::unique_ptr<crossref::TestTypeInObject::Params> params(
127 crossref::TestTypeInObject::Params::Create(*params_value)); 131 crossref::TestTypeInObject::Params::Create(*params_value));
128 EXPECT_FALSE(params.get()); 132 EXPECT_FALSE(params.get());
129 } 133 }
130 } 134 }
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/test/choices_unittest.cc ('k') | tools/json_schema_compiler/test/enums_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698