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

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

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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/objects.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 8
9 #include <utility>
10
7 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/json_schema_compiler/test/objects.h"
10 #include "tools/json_schema_compiler/test/objects_movable.h" 13 #include "tools/json_schema_compiler/test/objects_movable.h"
11 #include "tools/json_schema_compiler/test/objects_movable_json.h" 14 #include "tools/json_schema_compiler/test/objects_movable_json.h"
12 15
13 using namespace test::api::objects; 16 using namespace test::api::objects;
14 using namespace test::api::objects_movable; 17 using namespace test::api::objects_movable;
15 using namespace test::api::objects_movable_json; 18 using namespace test::api::objects_movable_json;
16 19
17 TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) { 20 TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
18 { 21 {
19 std::unique_ptr<base::ListValue> strings(new base::ListValue()); 22 std::unique_ptr<base::ListValue> strings(new base::ListValue());
20 strings->AppendString("one"); 23 strings->AppendString("one");
21 strings->AppendString("two"); 24 strings->AppendString("two");
22 std::unique_ptr<base::DictionaryValue> info_value( 25 std::unique_ptr<base::DictionaryValue> info_value(
23 new base::DictionaryValue()); 26 new base::DictionaryValue());
24 info_value->Set("strings", strings.release()); 27 info_value->Set("strings", strings.release());
25 info_value->Set("integer", new base::FundamentalValue(5)); 28 info_value->Set("integer", new base::FundamentalValue(5));
26 info_value->Set("boolean", new base::FundamentalValue(true)); 29 info_value->Set("boolean", new base::FundamentalValue(true));
27 30
28 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 31 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
29 params_value->Append(info_value.release()); 32 params_value->Append(std::move(info_value));
30 std::unique_ptr<ObjectParam::Params> params( 33 std::unique_ptr<ObjectParam::Params> params(
31 ObjectParam::Params::Create(*params_value)); 34 ObjectParam::Params::Create(*params_value));
32 EXPECT_TRUE(params.get()); 35 EXPECT_TRUE(params.get());
33 EXPECT_EQ((size_t) 2, params->info.strings.size()); 36 EXPECT_EQ((size_t) 2, params->info.strings.size());
34 EXPECT_EQ("one", params->info.strings[0]); 37 EXPECT_EQ("one", params->info.strings[0]);
35 EXPECT_EQ("two", params->info.strings[1]); 38 EXPECT_EQ("two", params->info.strings[1]);
36 EXPECT_EQ(5, params->info.integer); 39 EXPECT_EQ(5, params->info.integer);
37 EXPECT_TRUE(params->info.boolean); 40 EXPECT_TRUE(params->info.boolean);
38 } 41 }
39 { 42 {
40 std::unique_ptr<base::ListValue> strings(new base::ListValue()); 43 std::unique_ptr<base::ListValue> strings(new base::ListValue());
41 strings->AppendString("one"); 44 strings->AppendString("one");
42 strings->AppendString("two"); 45 strings->AppendString("two");
43 std::unique_ptr<base::DictionaryValue> info_value( 46 std::unique_ptr<base::DictionaryValue> info_value(
44 new base::DictionaryValue()); 47 new base::DictionaryValue());
45 info_value->Set("strings", strings.release()); 48 info_value->Set("strings", strings.release());
46 info_value->Set("integer", new base::FundamentalValue(5)); 49 info_value->Set("integer", new base::FundamentalValue(5));
47 50
48 std::unique_ptr<base::ListValue> params_value(new base::ListValue()); 51 std::unique_ptr<base::ListValue> params_value(new base::ListValue());
49 params_value->Append(info_value.release()); 52 params_value->Append(std::move(info_value));
50 std::unique_ptr<ObjectParam::Params> params( 53 std::unique_ptr<ObjectParam::Params> params(
51 ObjectParam::Params::Create(*params_value)); 54 ObjectParam::Params::Create(*params_value));
52 EXPECT_FALSE(params.get()); 55 EXPECT_FALSE(params.get());
53 } 56 }
54 } 57 }
55 58
56 TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) { 59 TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
57 ReturnsObject::Results::Info info; 60 ReturnsObject::Results::Info info;
58 info.state = FIRST_STATE_FOO; 61 info.state = FIRST_STATE_FOO;
59 std::unique_ptr<base::ListValue> results = 62 std::unique_ptr<base::ListValue> results =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 vals2.push_back("vals2a"); 155 vals2.push_back("vals2a");
153 vals2.push_back("vals2b"); 156 vals2.push_back("vals2b");
154 with_additional.additional_properties["key2"] = vals2; 157 with_additional.additional_properties["key2"] = vals2;
155 158
156 MovableWithAdditional with_additional2(std::move(with_additional)); 159 MovableWithAdditional with_additional2(std::move(with_additional));
157 EXPECT_EQ("str", with_additional2.str); 160 EXPECT_EQ("str", with_additional2.str);
158 EXPECT_EQ(2u, with_additional2.additional_properties.size()); 161 EXPECT_EQ(2u, with_additional2.additional_properties.size());
159 EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]); 162 EXPECT_EQ(vals1, with_additional2.additional_properties["key1"]);
160 EXPECT_EQ(vals2, with_additional2.additional_properties["key2"]); 163 EXPECT_EQ(vals2, with_additional2.additional_properties["key2"]);
161 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698