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

Side by Side Diff: tools/json_schema_compiler/test/idl_schemas_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 <utility>
6
5 #include "base/values.h" 7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/json_schema_compiler/test/idl_basics.h" 9 #include "tools/json_schema_compiler/test/idl_basics.h"
7 #include "tools/json_schema_compiler/test/idl_object_types.h" 10 #include "tools/json_schema_compiler/test/idl_object_types.h"
8 11
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using test::api::idl_basics::MyType1; 12 using test::api::idl_basics::MyType1;
12 using test::api::idl_object_types::BarType; 13 using test::api::idl_object_types::BarType;
13 using test::api::idl_object_types::FooType; 14 using test::api::idl_object_types::FooType;
14 15
15 namespace Function2 = test::api::idl_basics::Function2; 16 namespace Function2 = test::api::idl_basics::Function2;
16 namespace Function3 = test::api::idl_basics::Function3; 17 namespace Function3 = test::api::idl_basics::Function3;
17 namespace Function4 = test::api::idl_basics::Function4; 18 namespace Function4 = test::api::idl_basics::Function4;
18 namespace Function5 = test::api::idl_basics::Function5; 19 namespace Function5 = test::api::idl_basics::Function5;
19 namespace Function6 = test::api::idl_basics::Function6; 20 namespace Function6 = test::api::idl_basics::Function6;
20 namespace Function7 = test::api::idl_basics::Function7; 21 namespace Function7 = test::api::idl_basics::Function7;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 151
151 // Now test a function which takes an array of a defined type. 152 // Now test a function which takes an array of a defined type.
152 list.Clear(); 153 list.Clear();
153 MyType1 a; 154 MyType1 a;
154 MyType1 b; 155 MyType1 b;
155 a.x = 5; 156 a.x = 5;
156 b.x = 6; 157 b.x = 6;
157 a.y = std::string("foo"); 158 a.y = std::string("foo");
158 b.y = std::string("bar"); 159 b.y = std::string("bar");
159 base::ListValue* sublist2 = new base::ListValue; 160 base::ListValue* sublist2 = new base::ListValue;
160 sublist2->Append(a.ToValue().release()); 161 sublist2->Append(a.ToValue());
161 sublist2->Append(b.ToValue().release()); 162 sublist2->Append(b.ToValue());
162 list.Append(sublist2); 163 list.Append(sublist2);
163 std::unique_ptr<Function11::Params> f11_params = 164 std::unique_ptr<Function11::Params> f11_params =
164 Function11::Params::Create(list); 165 Function11::Params::Create(list);
165 ASSERT_TRUE(f11_params != NULL); 166 ASSERT_TRUE(f11_params != NULL);
166 ASSERT_EQ(2u, f11_params->arg.size()); 167 ASSERT_EQ(2u, f11_params->arg.size());
167 EXPECT_EQ(5, f11_params->arg[0].x); 168 EXPECT_EQ(5, f11_params->arg[0].x);
168 EXPECT_EQ("foo", f11_params->arg[0].y); 169 EXPECT_EQ("foo", f11_params->arg[0].y);
169 EXPECT_EQ(6, f11_params->arg[1].x); 170 EXPECT_EQ(6, f11_params->arg[1].x);
170 EXPECT_EQ("bar", f11_params->arg[1].y); 171 EXPECT_EQ("bar", f11_params->arg[1].y);
171 } 172 }
(...skipping 18 matching lines...) Expand all
190 EXPECT_EQ(7, tmp_int); 191 EXPECT_EQ(7, tmp_int);
191 192
192 // Test the params to the ObjectFunction1 function. 193 // Test the params to the ObjectFunction1 function.
193 std::unique_ptr<base::DictionaryValue> icon_props( 194 std::unique_ptr<base::DictionaryValue> icon_props(
194 new base::DictionaryValue()); 195 new base::DictionaryValue());
195 icon_props->SetString("hello", "world"); 196 icon_props->SetString("hello", "world");
196 ObjectFunction1::Params::Icon icon; 197 ObjectFunction1::Params::Icon icon;
197 EXPECT_TRUE(ObjectFunction1::Params::Icon::Populate(*(icon_props.get()), 198 EXPECT_TRUE(ObjectFunction1::Params::Icon::Populate(*(icon_props.get()),
198 &icon)); 199 &icon));
199 base::ListValue list; 200 base::ListValue list;
200 list.Append(icon_props.release()); 201 list.Append(std::move(icon_props));
201 std::unique_ptr<ObjectFunction1::Params> params = 202 std::unique_ptr<ObjectFunction1::Params> params =
202 ObjectFunction1::Params::Create(list); 203 ObjectFunction1::Params::Create(list);
203 ASSERT_TRUE(params.get() != NULL); 204 ASSERT_TRUE(params.get() != NULL);
204 std::string tmp; 205 std::string tmp;
205 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp)); 206 EXPECT_TRUE(params->icon.additional_properties.GetString("hello", &tmp));
206 EXPECT_EQ("world", tmp); 207 EXPECT_EQ("world", tmp);
207 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698