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

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: More IWYU fails and revert GN cleanup so the right overload is called 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
9 #include "base/memory/ptr_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "tools/json_schema_compiler/test/simple_api.h"
9 12
10 using namespace test::api; 13 using namespace test::api;
11 14
12 namespace { 15 namespace {
13 16
14 scoped_ptr<base::DictionaryValue> CreateTestTypeValue() { 17 std::unique_ptr<base::DictionaryValue> CreateTestTypeValue() {
15 base::DictionaryValue* value(new base::DictionaryValue()); 18 base::DictionaryValue* value(new base::DictionaryValue());
Devlin 2016/04/07 04:15:59 here too
dcheng 2016/04/07 04:24:03 Done.
16 value->Set("number", new base::FundamentalValue(1.1)); 19 value->Set("number", new base::FundamentalValue(1.1));
17 value->Set("integer", new base::FundamentalValue(4)); 20 value->Set("integer", new base::FundamentalValue(4));
18 value->Set("string", new base::StringValue("bling")); 21 value->Set("string", new base::StringValue("bling"));
19 value->Set("boolean", new base::FundamentalValue(true)); 22 value->Set("boolean", new base::FundamentalValue(true));
20 return scoped_ptr<base::DictionaryValue>(value); 23 return base::WrapUnique(value);
21 } 24 }
22 25
23 } // namespace 26 } // namespace
24 27
25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) { 28 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulateAndToValue) {
26 base::DictionaryValue crossref_orig; 29 base::DictionaryValue crossref_orig;
27 crossref_orig.Set("testType", CreateTestTypeValue().release()); 30 crossref_orig.Set("testType", CreateTestTypeValue().release());
28 crossref_orig.Set("testEnumRequired", new base::StringValue("one")); 31 crossref_orig.Set("testEnumRequired", new base::StringValue("one"));
29 crossref_orig.Set("testEnumOptional", new base::StringValue("two")); 32 crossref_orig.Set("testEnumOptional", new base::StringValue("two"));
30 33
31 // Test Populate of the value --> compiled type. 34 // Test Populate of the value --> compiled type.
32 crossref::CrossrefType crossref_type; 35 crossref::CrossrefType crossref_type;
33 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type)); 36 ASSERT_TRUE(crossref::CrossrefType::Populate(crossref_orig, &crossref_type));
34 EXPECT_EQ(1.1, crossref_type.test_type.number); 37 EXPECT_EQ(1.1, crossref_type.test_type.number);
35 EXPECT_EQ(4, crossref_type.test_type.integer); 38 EXPECT_EQ(4, crossref_type.test_type.integer);
36 EXPECT_EQ("bling", crossref_type.test_type.string); 39 EXPECT_EQ("bling", crossref_type.test_type.string);
37 EXPECT_EQ(true, crossref_type.test_type.boolean); 40 EXPECT_EQ(true, crossref_type.test_type.boolean);
38 EXPECT_EQ(simple_api::TEST_ENUM_ONE, crossref_type.test_enum_required); 41 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); 42 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); 43 EXPECT_EQ(simple_api::TEST_ENUM_NONE, crossref_type.test_enum_optional_extra);
41 44
42 // Test ToValue of the compiled type --> value. 45 // Test ToValue of the compiled type --> value.
43 scoped_ptr<base::DictionaryValue> crossref_value = crossref_type.ToValue(); 46 std::unique_ptr<base::DictionaryValue> crossref_value =
47 crossref_type.ToValue();
44 ASSERT_TRUE(crossref_value); 48 ASSERT_TRUE(crossref_value);
45 EXPECT_TRUE(crossref_orig.Equals(crossref_value.get())); 49 EXPECT_TRUE(crossref_orig.Equals(crossref_value.get()));
46 } 50 }
47 51
48 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) { 52 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
49 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 53 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
50 params_value->Append(CreateTestTypeValue().release()); 54 params_value->Append(CreateTestTypeValue().release());
51 scoped_ptr<crossref::TestTypeOptionalParam::Params> params( 55 std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
52 crossref::TestTypeOptionalParam::Params::Create(*params_value)); 56 crossref::TestTypeOptionalParam::Params::Create(*params_value));
53 EXPECT_TRUE(params.get()); 57 EXPECT_TRUE(params.get());
54 EXPECT_TRUE(params->test_type.get()); 58 EXPECT_TRUE(params->test_type.get());
55 EXPECT_TRUE( 59 EXPECT_TRUE(
56 CreateTestTypeValue()->Equals(params->test_type->ToValue().get())); 60 CreateTestTypeValue()->Equals(params->test_type->ToValue().get()));
57 } 61 }
58 62
59 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) { 63 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
60 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 64 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
61 scoped_ptr<base::DictionaryValue> test_type_value = CreateTestTypeValue(); 65 std::unique_ptr<base::DictionaryValue> test_type_value =
66 CreateTestTypeValue();
62 test_type_value->RemoveWithoutPathExpansion("number", NULL); 67 test_type_value->RemoveWithoutPathExpansion("number", NULL);
63 params_value->Append(test_type_value.release()); 68 params_value->Append(test_type_value.release());
64 scoped_ptr<crossref::TestTypeOptionalParam::Params> params( 69 std::unique_ptr<crossref::TestTypeOptionalParam::Params> params(
65 crossref::TestTypeOptionalParam::Params::Create(*params_value)); 70 crossref::TestTypeOptionalParam::Params::Create(*params_value));
66 EXPECT_FALSE(params.get()); 71 EXPECT_FALSE(params.get());
67 } 72 }
68 73
69 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) { 74 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
70 scoped_ptr<base::DictionaryValue> value = CreateTestTypeValue(); 75 std::unique_ptr<base::DictionaryValue> value = CreateTestTypeValue();
71 scoped_ptr<simple_api::TestType> test_type(new simple_api::TestType()); 76 std::unique_ptr<simple_api::TestType> test_type(new simple_api::TestType());
72 EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get())); 77 EXPECT_TRUE(simple_api::TestType::Populate(*value, test_type.get()));
73 78
74 scoped_ptr<base::ListValue> results = 79 std::unique_ptr<base::ListValue> results =
75 crossref::GetTestType::Results::Create(*test_type); 80 crossref::GetTestType::Results::Create(*test_type);
76 base::DictionaryValue* result_dict = NULL; 81 base::DictionaryValue* result_dict = NULL;
77 results->GetDictionary(0, &result_dict); 82 results->GetDictionary(0, &result_dict);
78 EXPECT_TRUE(value->Equals(result_dict)); 83 EXPECT_TRUE(value->Equals(result_dict));
79 } 84 }
80 85
81 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) { 86 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
82 { 87 {
83 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 88 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
84 scoped_ptr<base::DictionaryValue> param_object_value( 89 std::unique_ptr<base::DictionaryValue> param_object_value(
85 new base::DictionaryValue()); 90 new base::DictionaryValue());
86 param_object_value->Set("testType", CreateTestTypeValue().release()); 91 param_object_value->Set("testType", CreateTestTypeValue().release());
87 param_object_value->Set("boolean", new base::FundamentalValue(true)); 92 param_object_value->Set("boolean", new base::FundamentalValue(true));
88 params_value->Append(param_object_value.release()); 93 params_value->Append(param_object_value.release());
89 scoped_ptr<crossref::TestTypeInObject::Params> params( 94 std::unique_ptr<crossref::TestTypeInObject::Params> params(
90 crossref::TestTypeInObject::Params::Create(*params_value)); 95 crossref::TestTypeInObject::Params::Create(*params_value));
91 EXPECT_TRUE(params.get()); 96 EXPECT_TRUE(params.get());
92 EXPECT_TRUE(params->param_object.test_type.get()); 97 EXPECT_TRUE(params->param_object.test_type.get());
93 EXPECT_TRUE(params->param_object.boolean); 98 EXPECT_TRUE(params->param_object.boolean);
94 EXPECT_TRUE(CreateTestTypeValue()->Equals( 99 EXPECT_TRUE(CreateTestTypeValue()->Equals(
95 params->param_object.test_type->ToValue().get())); 100 params->param_object.test_type->ToValue().get()));
96 } 101 }
97 { 102 {
98 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 103 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
99 scoped_ptr<base::DictionaryValue> param_object_value( 104 std::unique_ptr<base::DictionaryValue> param_object_value(
100 new base::DictionaryValue()); 105 new base::DictionaryValue());
101 param_object_value->Set("boolean", new base::FundamentalValue(true)); 106 param_object_value->Set("boolean", new base::FundamentalValue(true));
102 params_value->Append(param_object_value.release()); 107 params_value->Append(param_object_value.release());
103 scoped_ptr<crossref::TestTypeInObject::Params> params( 108 std::unique_ptr<crossref::TestTypeInObject::Params> params(
104 crossref::TestTypeInObject::Params::Create(*params_value)); 109 crossref::TestTypeInObject::Params::Create(*params_value));
105 EXPECT_TRUE(params.get()); 110 EXPECT_TRUE(params.get());
106 EXPECT_FALSE(params->param_object.test_type.get()); 111 EXPECT_FALSE(params->param_object.test_type.get());
107 EXPECT_TRUE(params->param_object.boolean); 112 EXPECT_TRUE(params->param_object.boolean);
108 } 113 }
109 { 114 {
110 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 115 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
111 scoped_ptr<base::DictionaryValue> param_object_value( 116 std::unique_ptr<base::DictionaryValue> param_object_value(
112 new base::DictionaryValue()); 117 new base::DictionaryValue());
113 param_object_value->Set("testType", new base::StringValue("invalid")); 118 param_object_value->Set("testType", new base::StringValue("invalid"));
114 param_object_value->Set("boolean", new base::FundamentalValue(true)); 119 param_object_value->Set("boolean", new base::FundamentalValue(true));
115 params_value->Append(param_object_value.release()); 120 params_value->Append(param_object_value.release());
116 scoped_ptr<crossref::TestTypeInObject::Params> params( 121 std::unique_ptr<crossref::TestTypeInObject::Params> params(
117 crossref::TestTypeInObject::Params::Create(*params_value)); 122 crossref::TestTypeInObject::Params::Create(*params_value));
118 EXPECT_FALSE(params.get()); 123 EXPECT_FALSE(params.get());
119 } 124 }
120 { 125 {
121 scoped_ptr<base::ListValue> params_value(new base::ListValue()); 126 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
122 scoped_ptr<base::DictionaryValue> param_object_value( 127 std::unique_ptr<base::DictionaryValue> param_object_value(
123 new base::DictionaryValue()); 128 new base::DictionaryValue());
124 param_object_value->Set("testType", CreateTestTypeValue().release()); 129 param_object_value->Set("testType", CreateTestTypeValue().release());
125 params_value->Append(param_object_value.release()); 130 params_value->Append(param_object_value.release());
126 scoped_ptr<crossref::TestTypeInObject::Params> params( 131 std::unique_ptr<crossref::TestTypeInObject::Params> params(
127 crossref::TestTypeInObject::Params::Create(*params_value)); 132 crossref::TestTypeInObject::Params::Create(*params_value));
128 EXPECT_FALSE(params.get()); 133 EXPECT_FALSE(params.get());
129 } 134 }
130 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698