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

Side by Side Diff: base/values_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 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
« no previous file with comments | « base/values.cc ('k') | base/win/enum_variant.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/values.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 8
7 #include <limits> 9 #include <limits>
10 #include <memory>
8 #include <utility> 11 #include <utility>
9 12
10 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/ptr_util.h"
11 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace base { 18 namespace base {
17 19
18 TEST(ValuesTest, Basic) { 20 TEST(ValuesTest, Basic) {
19 // Test basic dictionary getting/setting 21 // Test basic dictionary getting/setting
20 DictionaryValue settings; 22 DictionaryValue settings;
21 std::string homepage = "http://google.com"; 23 std::string homepage = "http://google.com";
22 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); 24 ASSERT_FALSE(settings.GetString("global.homepage", &homepage));
23 ASSERT_EQ(std::string("http://google.com"), homepage); 25 ASSERT_EQ(std::string("http://google.com"), homepage);
24 26
25 ASSERT_FALSE(settings.Get("global", NULL)); 27 ASSERT_FALSE(settings.Get("global", NULL));
26 settings.SetBoolean("global", true); 28 settings.SetBoolean("global", true);
27 ASSERT_TRUE(settings.Get("global", NULL)); 29 ASSERT_TRUE(settings.Get("global", NULL));
28 settings.SetString("global.homepage", "http://scurvy.com"); 30 settings.SetString("global.homepage", "http://scurvy.com");
29 ASSERT_TRUE(settings.Get("global", NULL)); 31 ASSERT_TRUE(settings.Get("global", NULL));
30 homepage = "http://google.com"; 32 homepage = "http://google.com";
31 ASSERT_TRUE(settings.GetString("global.homepage", &homepage)); 33 ASSERT_TRUE(settings.GetString("global.homepage", &homepage));
32 ASSERT_EQ(std::string("http://scurvy.com"), homepage); 34 ASSERT_EQ(std::string("http://scurvy.com"), homepage);
33 35
34 // Test storing a dictionary in a list. 36 // Test storing a dictionary in a list.
35 ListValue* toolbar_bookmarks; 37 ListValue* toolbar_bookmarks;
36 ASSERT_FALSE( 38 ASSERT_FALSE(
37 settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); 39 settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks));
38 40
39 scoped_ptr<ListValue> new_toolbar_bookmarks(new ListValue); 41 std::unique_ptr<ListValue> new_toolbar_bookmarks(new ListValue);
40 settings.Set("global.toolbar.bookmarks", std::move(new_toolbar_bookmarks)); 42 settings.Set("global.toolbar.bookmarks", std::move(new_toolbar_bookmarks));
41 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks)); 43 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &toolbar_bookmarks));
42 44
43 scoped_ptr<DictionaryValue> new_bookmark(new DictionaryValue); 45 std::unique_ptr<DictionaryValue> new_bookmark(new DictionaryValue);
44 new_bookmark->SetString("name", "Froogle"); 46 new_bookmark->SetString("name", "Froogle");
45 new_bookmark->SetString("url", "http://froogle.com"); 47 new_bookmark->SetString("url", "http://froogle.com");
46 toolbar_bookmarks->Append(std::move(new_bookmark)); 48 toolbar_bookmarks->Append(std::move(new_bookmark));
47 49
48 ListValue* bookmark_list; 50 ListValue* bookmark_list;
49 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &bookmark_list)); 51 ASSERT_TRUE(settings.GetList("global.toolbar.bookmarks", &bookmark_list));
50 DictionaryValue* bookmark; 52 DictionaryValue* bookmark;
51 ASSERT_EQ(1U, bookmark_list->GetSize()); 53 ASSERT_EQ(1U, bookmark_list->GetSize());
52 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); 54 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark));
53 std::string bookmark_name = "Unnamed"; 55 std::string bookmark_name = "Unnamed";
54 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); 56 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name));
55 ASSERT_EQ(std::string("Froogle"), bookmark_name); 57 ASSERT_EQ(std::string("Froogle"), bookmark_name);
56 std::string bookmark_url; 58 std::string bookmark_url;
57 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url)); 59 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url));
58 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); 60 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url);
59 } 61 }
60 62
61 TEST(ValuesTest, List) { 63 TEST(ValuesTest, List) {
62 scoped_ptr<ListValue> mixed_list(new ListValue()); 64 std::unique_ptr<ListValue> mixed_list(new ListValue());
63 mixed_list->Set(0, make_scoped_ptr(new FundamentalValue(true))); 65 mixed_list->Set(0, WrapUnique(new FundamentalValue(true)));
64 mixed_list->Set(1, make_scoped_ptr(new FundamentalValue(42))); 66 mixed_list->Set(1, WrapUnique(new FundamentalValue(42)));
65 mixed_list->Set(2, make_scoped_ptr(new FundamentalValue(88.8))); 67 mixed_list->Set(2, WrapUnique(new FundamentalValue(88.8)));
66 mixed_list->Set(3, make_scoped_ptr(new StringValue("foo"))); 68 mixed_list->Set(3, WrapUnique(new StringValue("foo")));
67 ASSERT_EQ(4u, mixed_list->GetSize()); 69 ASSERT_EQ(4u, mixed_list->GetSize());
68 70
69 Value *value = NULL; 71 Value *value = NULL;
70 bool bool_value = false; 72 bool bool_value = false;
71 int int_value = 0; 73 int int_value = 0;
72 double double_value = 0.0; 74 double double_value = 0.0;
73 std::string string_value; 75 std::string string_value;
74 76
75 ASSERT_FALSE(mixed_list->Get(4, &value)); 77 ASSERT_FALSE(mixed_list->Get(4, &value));
76 78
(...skipping 25 matching lines...) Expand all
102 base::FundamentalValue not_found_value(false); 104 base::FundamentalValue not_found_value(false);
103 105
104 ASSERT_NE(mixed_list->end(), mixed_list->Find(sought_value)); 106 ASSERT_NE(mixed_list->end(), mixed_list->Find(sought_value));
105 ASSERT_TRUE((*mixed_list->Find(sought_value))->GetAsInteger(&int_value)); 107 ASSERT_TRUE((*mixed_list->Find(sought_value))->GetAsInteger(&int_value));
106 ASSERT_EQ(42, int_value); 108 ASSERT_EQ(42, int_value);
107 ASSERT_EQ(mixed_list->end(), mixed_list->Find(not_found_value)); 109 ASSERT_EQ(mixed_list->end(), mixed_list->Find(not_found_value));
108 } 110 }
109 111
110 TEST(ValuesTest, BinaryValue) { 112 TEST(ValuesTest, BinaryValue) {
111 // Default constructor creates a BinaryValue with a null buffer and size 0. 113 // Default constructor creates a BinaryValue with a null buffer and size 0.
112 scoped_ptr<BinaryValue> binary(new BinaryValue()); 114 std::unique_ptr<BinaryValue> binary(new BinaryValue());
113 ASSERT_TRUE(binary.get()); 115 ASSERT_TRUE(binary.get());
114 ASSERT_EQ(NULL, binary->GetBuffer()); 116 ASSERT_EQ(NULL, binary->GetBuffer());
115 ASSERT_EQ(0U, binary->GetSize()); 117 ASSERT_EQ(0U, binary->GetSize());
116 118
117 // Test the common case of a non-empty buffer 119 // Test the common case of a non-empty buffer
118 scoped_ptr<char[]> buffer(new char[15]); 120 std::unique_ptr<char[]> buffer(new char[15]);
119 char* original_buffer = buffer.get(); 121 char* original_buffer = buffer.get();
120 binary.reset(new BinaryValue(std::move(buffer), 15)); 122 binary.reset(new BinaryValue(std::move(buffer), 15));
121 ASSERT_TRUE(binary.get()); 123 ASSERT_TRUE(binary.get());
122 ASSERT_TRUE(binary->GetBuffer()); 124 ASSERT_TRUE(binary->GetBuffer());
123 ASSERT_EQ(original_buffer, binary->GetBuffer()); 125 ASSERT_EQ(original_buffer, binary->GetBuffer());
124 ASSERT_EQ(15U, binary->GetSize()); 126 ASSERT_EQ(15U, binary->GetSize());
125 127
126 char stack_buffer[42]; 128 char stack_buffer[42];
127 memset(stack_buffer, '!', 42); 129 memset(stack_buffer, '!', 42);
128 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); 130 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42));
129 ASSERT_TRUE(binary.get()); 131 ASSERT_TRUE(binary.get());
130 ASSERT_TRUE(binary->GetBuffer()); 132 ASSERT_TRUE(binary->GetBuffer());
131 ASSERT_NE(stack_buffer, binary->GetBuffer()); 133 ASSERT_NE(stack_buffer, binary->GetBuffer());
132 ASSERT_EQ(42U, binary->GetSize()); 134 ASSERT_EQ(42U, binary->GetSize());
133 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); 135 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
134 136
135 // Test overloaded GetAsBinary. 137 // Test overloaded GetAsBinary.
136 Value* narrow_value = binary.get(); 138 Value* narrow_value = binary.get();
137 const BinaryValue* narrow_binary = NULL; 139 const BinaryValue* narrow_binary = NULL;
138 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); 140 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary));
139 EXPECT_EQ(binary.get(), narrow_binary); 141 EXPECT_EQ(binary.get(), narrow_binary);
140 } 142 }
141 143
142 TEST(ValuesTest, StringValue) { 144 TEST(ValuesTest, StringValue) {
143 // Test overloaded StringValue constructor. 145 // Test overloaded StringValue constructor.
144 scoped_ptr<Value> narrow_value(new StringValue("narrow")); 146 std::unique_ptr<Value> narrow_value(new StringValue("narrow"));
145 ASSERT_TRUE(narrow_value.get()); 147 ASSERT_TRUE(narrow_value.get());
146 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); 148 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
147 scoped_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16"))); 149 std::unique_ptr<Value> utf16_value(new StringValue(ASCIIToUTF16("utf16")));
148 ASSERT_TRUE(utf16_value.get()); 150 ASSERT_TRUE(utf16_value.get());
149 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); 151 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
150 152
151 // Test overloaded GetAsString. 153 // Test overloaded GetAsString.
152 std::string narrow = "http://google.com"; 154 std::string narrow = "http://google.com";
153 string16 utf16 = ASCIIToUTF16("http://google.com"); 155 string16 utf16 = ASCIIToUTF16("http://google.com");
154 const StringValue* string_value = NULL; 156 const StringValue* string_value = NULL;
155 ASSERT_TRUE(narrow_value->GetAsString(&narrow)); 157 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
156 ASSERT_TRUE(narrow_value->GetAsString(&utf16)); 158 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
157 ASSERT_TRUE(narrow_value->GetAsString(&string_value)); 159 ASSERT_TRUE(narrow_value->GetAsString(&string_value));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 193
192 private: 194 private:
193 bool* deletion_flag_; 195 bool* deletion_flag_;
194 }; 196 };
195 197
196 TEST(ValuesTest, ListDeletion) { 198 TEST(ValuesTest, ListDeletion) {
197 bool deletion_flag = true; 199 bool deletion_flag = true;
198 200
199 { 201 {
200 ListValue list; 202 ListValue list;
201 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 203 list.Append(WrapUnique(new DeletionTestValue(&deletion_flag)));
202 EXPECT_FALSE(deletion_flag); 204 EXPECT_FALSE(deletion_flag);
203 } 205 }
204 EXPECT_TRUE(deletion_flag); 206 EXPECT_TRUE(deletion_flag);
205 207
206 { 208 {
207 ListValue list; 209 ListValue list;
208 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 210 list.Append(WrapUnique(new DeletionTestValue(&deletion_flag)));
209 EXPECT_FALSE(deletion_flag); 211 EXPECT_FALSE(deletion_flag);
210 list.Clear(); 212 list.Clear();
211 EXPECT_TRUE(deletion_flag); 213 EXPECT_TRUE(deletion_flag);
212 } 214 }
213 215
214 { 216 {
215 ListValue list; 217 ListValue list;
216 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 218 list.Append(WrapUnique(new DeletionTestValue(&deletion_flag)));
217 EXPECT_FALSE(deletion_flag); 219 EXPECT_FALSE(deletion_flag);
218 EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); 220 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
219 EXPECT_TRUE(deletion_flag); 221 EXPECT_TRUE(deletion_flag);
220 } 222 }
221 } 223 }
222 224
223 TEST(ValuesTest, ListRemoval) { 225 TEST(ValuesTest, ListRemoval) {
224 bool deletion_flag = true; 226 bool deletion_flag = true;
225 scoped_ptr<Value> removed_item; 227 std::unique_ptr<Value> removed_item;
226 228
227 { 229 {
228 ListValue list; 230 ListValue list;
229 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 231 list.Append(WrapUnique(new DeletionTestValue(&deletion_flag)));
230 EXPECT_FALSE(deletion_flag); 232 EXPECT_FALSE(deletion_flag);
231 EXPECT_EQ(1U, list.GetSize()); 233 EXPECT_EQ(1U, list.GetSize());
232 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), 234 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
233 &removed_item)); 235 &removed_item));
234 EXPECT_FALSE(list.Remove(1, &removed_item)); 236 EXPECT_FALSE(list.Remove(1, &removed_item));
235 EXPECT_TRUE(list.Remove(0, &removed_item)); 237 EXPECT_TRUE(list.Remove(0, &removed_item));
236 ASSERT_TRUE(removed_item); 238 ASSERT_TRUE(removed_item);
237 EXPECT_EQ(0U, list.GetSize()); 239 EXPECT_EQ(0U, list.GetSize());
238 } 240 }
239 EXPECT_FALSE(deletion_flag); 241 EXPECT_FALSE(deletion_flag);
240 removed_item.reset(); 242 removed_item.reset();
241 EXPECT_TRUE(deletion_flag); 243 EXPECT_TRUE(deletion_flag);
242 244
243 { 245 {
244 ListValue list; 246 ListValue list;
245 list.Append(make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 247 list.Append(WrapUnique(new DeletionTestValue(&deletion_flag)));
246 EXPECT_FALSE(deletion_flag); 248 EXPECT_FALSE(deletion_flag);
247 EXPECT_TRUE(list.Remove(0, NULL)); 249 EXPECT_TRUE(list.Remove(0, NULL));
248 EXPECT_TRUE(deletion_flag); 250 EXPECT_TRUE(deletion_flag);
249 EXPECT_EQ(0U, list.GetSize()); 251 EXPECT_EQ(0U, list.GetSize());
250 } 252 }
251 253
252 { 254 {
253 ListValue list; 255 ListValue list;
254 scoped_ptr<DeletionTestValue> value(new DeletionTestValue(&deletion_flag)); 256 std::unique_ptr<DeletionTestValue> value(
257 new DeletionTestValue(&deletion_flag));
255 DeletionTestValue* original_value = value.get(); 258 DeletionTestValue* original_value = value.get();
256 list.Append(std::move(value)); 259 list.Append(std::move(value));
257 EXPECT_FALSE(deletion_flag); 260 EXPECT_FALSE(deletion_flag);
258 size_t index = 0; 261 size_t index = 0;
259 list.Remove(*original_value, &index); 262 list.Remove(*original_value, &index);
260 EXPECT_EQ(0U, index); 263 EXPECT_EQ(0U, index);
261 EXPECT_TRUE(deletion_flag); 264 EXPECT_TRUE(deletion_flag);
262 EXPECT_EQ(0U, list.GetSize()); 265 EXPECT_EQ(0U, list.GetSize());
263 } 266 }
264 } 267 }
265 268
266 TEST(ValuesTest, DictionaryDeletion) { 269 TEST(ValuesTest, DictionaryDeletion) {
267 std::string key = "test"; 270 std::string key = "test";
268 bool deletion_flag = true; 271 bool deletion_flag = true;
269 272
270 { 273 {
271 DictionaryValue dict; 274 DictionaryValue dict;
272 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 275 dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag)));
273 EXPECT_FALSE(deletion_flag); 276 EXPECT_FALSE(deletion_flag);
274 } 277 }
275 EXPECT_TRUE(deletion_flag); 278 EXPECT_TRUE(deletion_flag);
276 279
277 { 280 {
278 DictionaryValue dict; 281 DictionaryValue dict;
279 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 282 dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag)));
280 EXPECT_FALSE(deletion_flag); 283 EXPECT_FALSE(deletion_flag);
281 dict.Clear(); 284 dict.Clear();
282 EXPECT_TRUE(deletion_flag); 285 EXPECT_TRUE(deletion_flag);
283 } 286 }
284 287
285 { 288 {
286 DictionaryValue dict; 289 DictionaryValue dict;
287 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 290 dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag)));
288 EXPECT_FALSE(deletion_flag); 291 EXPECT_FALSE(deletion_flag);
289 dict.Set(key, Value::CreateNullValue()); 292 dict.Set(key, Value::CreateNullValue());
290 EXPECT_TRUE(deletion_flag); 293 EXPECT_TRUE(deletion_flag);
291 } 294 }
292 } 295 }
293 296
294 TEST(ValuesTest, DictionaryRemoval) { 297 TEST(ValuesTest, DictionaryRemoval) {
295 std::string key = "test"; 298 std::string key = "test";
296 bool deletion_flag = true; 299 bool deletion_flag = true;
297 scoped_ptr<Value> removed_item; 300 std::unique_ptr<Value> removed_item;
298 301
299 { 302 {
300 DictionaryValue dict; 303 DictionaryValue dict;
301 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 304 dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag)));
302 EXPECT_FALSE(deletion_flag); 305 EXPECT_FALSE(deletion_flag);
303 EXPECT_TRUE(dict.HasKey(key)); 306 EXPECT_TRUE(dict.HasKey(key));
304 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); 307 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
305 EXPECT_TRUE(dict.Remove(key, &removed_item)); 308 EXPECT_TRUE(dict.Remove(key, &removed_item));
306 EXPECT_FALSE(dict.HasKey(key)); 309 EXPECT_FALSE(dict.HasKey(key));
307 ASSERT_TRUE(removed_item); 310 ASSERT_TRUE(removed_item);
308 } 311 }
309 EXPECT_FALSE(deletion_flag); 312 EXPECT_FALSE(deletion_flag);
310 removed_item.reset(); 313 removed_item.reset();
311 EXPECT_TRUE(deletion_flag); 314 EXPECT_TRUE(deletion_flag);
312 315
313 { 316 {
314 DictionaryValue dict; 317 DictionaryValue dict;
315 dict.Set(key, make_scoped_ptr(new DeletionTestValue(&deletion_flag))); 318 dict.Set(key, WrapUnique(new DeletionTestValue(&deletion_flag)));
316 EXPECT_FALSE(deletion_flag); 319 EXPECT_FALSE(deletion_flag);
317 EXPECT_TRUE(dict.HasKey(key)); 320 EXPECT_TRUE(dict.HasKey(key));
318 EXPECT_TRUE(dict.Remove(key, NULL)); 321 EXPECT_TRUE(dict.Remove(key, NULL));
319 EXPECT_TRUE(deletion_flag); 322 EXPECT_TRUE(deletion_flag);
320 EXPECT_FALSE(dict.HasKey(key)); 323 EXPECT_FALSE(dict.HasKey(key));
321 } 324 }
322 } 325 }
323 326
324 TEST(ValuesTest, DictionaryWithoutPathExpansion) { 327 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
325 DictionaryValue dict; 328 DictionaryValue dict;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 Value* value4; 368 Value* value4;
366 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4)); 369 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
367 EXPECT_EQ(Value::TYPE_NULL, value4->GetType()); 370 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
368 } 371 }
369 372
370 TEST(ValuesTest, DictionaryRemovePath) { 373 TEST(ValuesTest, DictionaryRemovePath) {
371 DictionaryValue dict; 374 DictionaryValue dict;
372 dict.SetInteger("a.long.way.down", 1); 375 dict.SetInteger("a.long.way.down", 1);
373 dict.SetBoolean("a.long.key.path", true); 376 dict.SetBoolean("a.long.key.path", true);
374 377
375 scoped_ptr<Value> removed_item; 378 std::unique_ptr<Value> removed_item;
376 EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item)); 379 EXPECT_TRUE(dict.RemovePath("a.long.way.down", &removed_item));
377 ASSERT_TRUE(removed_item); 380 ASSERT_TRUE(removed_item);
378 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER)); 381 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_INTEGER));
379 EXPECT_FALSE(dict.HasKey("a.long.way.down")); 382 EXPECT_FALSE(dict.HasKey("a.long.way.down"));
380 EXPECT_FALSE(dict.HasKey("a.long.way")); 383 EXPECT_FALSE(dict.HasKey("a.long.way"));
381 EXPECT_TRUE(dict.Get("a.long.key.path", NULL)); 384 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
382 385
383 removed_item.reset(); 386 removed_item.reset();
384 EXPECT_FALSE(dict.RemovePath("a.long.way.down", &removed_item)); 387 EXPECT_FALSE(dict.RemovePath("a.long.way.down", &removed_item));
385 EXPECT_FALSE(removed_item); 388 EXPECT_FALSE(removed_item);
386 EXPECT_TRUE(dict.Get("a.long.key.path", NULL)); 389 EXPECT_TRUE(dict.Get("a.long.key.path", NULL));
387 390
388 removed_item.reset(); 391 removed_item.reset();
389 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item)); 392 EXPECT_TRUE(dict.RemovePath("a.long.key.path", &removed_item));
390 ASSERT_TRUE(removed_item); 393 ASSERT_TRUE(removed_item);
391 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN)); 394 EXPECT_TRUE(removed_item->IsType(base::Value::TYPE_BOOLEAN));
392 EXPECT_TRUE(dict.empty()); 395 EXPECT_TRUE(dict.empty());
393 } 396 }
394 397
395 TEST(ValuesTest, DeepCopy) { 398 TEST(ValuesTest, DeepCopy) {
396 DictionaryValue original_dict; 399 DictionaryValue original_dict;
397 scoped_ptr<Value> scoped_null = Value::CreateNullValue(); 400 std::unique_ptr<Value> scoped_null = Value::CreateNullValue();
398 Value* original_null = scoped_null.get(); 401 Value* original_null = scoped_null.get();
399 original_dict.Set("null", std::move(scoped_null)); 402 original_dict.Set("null", std::move(scoped_null));
400 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); 403 std::unique_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true));
401 FundamentalValue* original_bool = scoped_bool.get(); 404 FundamentalValue* original_bool = scoped_bool.get();
402 original_dict.Set("bool", std::move(scoped_bool)); 405 original_dict.Set("bool", std::move(scoped_bool));
403 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); 406 std::unique_ptr<FundamentalValue> scoped_int(new FundamentalValue(42));
404 FundamentalValue* original_int = scoped_int.get(); 407 FundamentalValue* original_int = scoped_int.get();
405 original_dict.Set("int", std::move(scoped_int)); 408 original_dict.Set("int", std::move(scoped_int));
406 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); 409 std::unique_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14));
407 FundamentalValue* original_double = scoped_double.get(); 410 FundamentalValue* original_double = scoped_double.get();
408 original_dict.Set("double", std::move(scoped_double)); 411 original_dict.Set("double", std::move(scoped_double));
409 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); 412 std::unique_ptr<StringValue> scoped_string(new StringValue("hello"));
410 StringValue* original_string = scoped_string.get(); 413 StringValue* original_string = scoped_string.get();
411 original_dict.Set("string", std::move(scoped_string)); 414 original_dict.Set("string", std::move(scoped_string));
412 scoped_ptr<StringValue> scoped_string16( 415 std::unique_ptr<StringValue> scoped_string16(
413 new StringValue(ASCIIToUTF16("hello16"))); 416 new StringValue(ASCIIToUTF16("hello16")));
414 StringValue* original_string16 = scoped_string16.get(); 417 StringValue* original_string16 = scoped_string16.get();
415 original_dict.Set("string16", std::move(scoped_string16)); 418 original_dict.Set("string16", std::move(scoped_string16));
416 419
417 scoped_ptr<char[]> original_buffer(new char[42]); 420 std::unique_ptr<char[]> original_buffer(new char[42]);
418 memset(original_buffer.get(), '!', 42); 421 memset(original_buffer.get(), '!', 42);
419 scoped_ptr<BinaryValue> scoped_binary( 422 std::unique_ptr<BinaryValue> scoped_binary(
420 new BinaryValue(std::move(original_buffer), 42)); 423 new BinaryValue(std::move(original_buffer), 42));
421 BinaryValue* original_binary = scoped_binary.get(); 424 BinaryValue* original_binary = scoped_binary.get();
422 original_dict.Set("binary", std::move(scoped_binary)); 425 original_dict.Set("binary", std::move(scoped_binary));
423 426
424 scoped_ptr<ListValue> scoped_list(new ListValue()); 427 std::unique_ptr<ListValue> scoped_list(new ListValue());
425 Value* original_list = scoped_list.get(); 428 Value* original_list = scoped_list.get();
426 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); 429 std::unique_ptr<FundamentalValue> scoped_list_element_0(
430 new FundamentalValue(0));
427 Value* original_list_element_0 = scoped_list_element_0.get(); 431 Value* original_list_element_0 = scoped_list_element_0.get();
428 scoped_list->Append(std::move(scoped_list_element_0)); 432 scoped_list->Append(std::move(scoped_list_element_0));
429 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); 433 std::unique_ptr<FundamentalValue> scoped_list_element_1(
434 new FundamentalValue(1));
430 Value* original_list_element_1 = scoped_list_element_1.get(); 435 Value* original_list_element_1 = scoped_list_element_1.get();
431 scoped_list->Append(std::move(scoped_list_element_1)); 436 scoped_list->Append(std::move(scoped_list_element_1));
432 original_dict.Set("list", std::move(scoped_list)); 437 original_dict.Set("list", std::move(scoped_list));
433 438
434 scoped_ptr<DictionaryValue> scoped_nested_dictionary(new DictionaryValue()); 439 std::unique_ptr<DictionaryValue> scoped_nested_dictionary(
440 new DictionaryValue());
435 Value* original_nested_dictionary = scoped_nested_dictionary.get(); 441 Value* original_nested_dictionary = scoped_nested_dictionary.get();
436 scoped_nested_dictionary->SetString("key", "value"); 442 scoped_nested_dictionary->SetString("key", "value");
437 original_dict.Set("dictionary", std::move(scoped_nested_dictionary)); 443 original_dict.Set("dictionary", std::move(scoped_nested_dictionary));
438 444
439 scoped_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy(); 445 std::unique_ptr<DictionaryValue> copy_dict = original_dict.CreateDeepCopy();
440 ASSERT_TRUE(copy_dict.get()); 446 ASSERT_TRUE(copy_dict.get());
441 ASSERT_NE(copy_dict.get(), &original_dict); 447 ASSERT_NE(copy_dict.get(), &original_dict);
442 448
443 Value* copy_null = NULL; 449 Value* copy_null = NULL;
444 ASSERT_TRUE(copy_dict->Get("null", &copy_null)); 450 ASSERT_TRUE(copy_dict->Get("null", &copy_null));
445 ASSERT_TRUE(copy_null); 451 ASSERT_TRUE(copy_null);
446 ASSERT_NE(copy_null, original_null); 452 ASSERT_NE(copy_null, original_null);
447 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL)); 453 ASSERT_TRUE(copy_null->IsType(Value::TYPE_NULL));
448 454
449 Value* copy_bool = NULL; 455 Value* copy_bool = NULL;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 ASSERT_TRUE(copy_value); 545 ASSERT_TRUE(copy_value);
540 ASSERT_NE(copy_value, original_nested_dictionary); 546 ASSERT_NE(copy_value, original_nested_dictionary);
541 ASSERT_TRUE(copy_value->IsType(Value::TYPE_DICTIONARY)); 547 ASSERT_TRUE(copy_value->IsType(Value::TYPE_DICTIONARY));
542 DictionaryValue* copy_nested_dictionary = NULL; 548 DictionaryValue* copy_nested_dictionary = NULL;
543 ASSERT_TRUE(copy_value->GetAsDictionary(&copy_nested_dictionary)); 549 ASSERT_TRUE(copy_value->GetAsDictionary(&copy_nested_dictionary));
544 ASSERT_TRUE(copy_nested_dictionary); 550 ASSERT_TRUE(copy_nested_dictionary);
545 EXPECT_TRUE(copy_nested_dictionary->HasKey("key")); 551 EXPECT_TRUE(copy_nested_dictionary->HasKey("key"));
546 } 552 }
547 553
548 TEST(ValuesTest, Equals) { 554 TEST(ValuesTest, Equals) {
549 scoped_ptr<Value> null1(Value::CreateNullValue()); 555 std::unique_ptr<Value> null1(Value::CreateNullValue());
550 scoped_ptr<Value> null2(Value::CreateNullValue()); 556 std::unique_ptr<Value> null2(Value::CreateNullValue());
551 EXPECT_NE(null1.get(), null2.get()); 557 EXPECT_NE(null1.get(), null2.get());
552 EXPECT_TRUE(null1->Equals(null2.get())); 558 EXPECT_TRUE(null1->Equals(null2.get()));
553 559
554 FundamentalValue boolean(false); 560 FundamentalValue boolean(false);
555 EXPECT_FALSE(null1->Equals(&boolean)); 561 EXPECT_FALSE(null1->Equals(&boolean));
556 562
557 DictionaryValue dv; 563 DictionaryValue dv;
558 dv.SetBoolean("a", false); 564 dv.SetBoolean("a", false);
559 dv.SetInteger("b", 2); 565 dv.SetInteger("b", 2);
560 dv.SetDouble("c", 2.5); 566 dv.SetDouble("c", 2.5);
561 dv.SetString("d1", "string"); 567 dv.SetString("d1", "string");
562 dv.SetString("d2", ASCIIToUTF16("http://google.com")); 568 dv.SetString("d2", ASCIIToUTF16("http://google.com"));
563 dv.Set("e", Value::CreateNullValue()); 569 dv.Set("e", Value::CreateNullValue());
564 570
565 scoped_ptr<DictionaryValue> copy = dv.CreateDeepCopy(); 571 std::unique_ptr<DictionaryValue> copy = dv.CreateDeepCopy();
566 EXPECT_TRUE(dv.Equals(copy.get())); 572 EXPECT_TRUE(dv.Equals(copy.get()));
567 573
568 scoped_ptr<ListValue> list(new ListValue); 574 std::unique_ptr<ListValue> list(new ListValue);
569 ListValue* original_list = list.get(); 575 ListValue* original_list = list.get();
570 list->Append(Value::CreateNullValue()); 576 list->Append(Value::CreateNullValue());
571 list->Append(make_scoped_ptr(new DictionaryValue)); 577 list->Append(WrapUnique(new DictionaryValue));
572 scoped_ptr<Value> list_copy(list->CreateDeepCopy()); 578 std::unique_ptr<Value> list_copy(list->CreateDeepCopy());
573 579
574 dv.Set("f", std::move(list)); 580 dv.Set("f", std::move(list));
575 EXPECT_FALSE(dv.Equals(copy.get())); 581 EXPECT_FALSE(dv.Equals(copy.get()));
576 copy->Set("f", std::move(list_copy)); 582 copy->Set("f", std::move(list_copy));
577 EXPECT_TRUE(dv.Equals(copy.get())); 583 EXPECT_TRUE(dv.Equals(copy.get()));
578 584
579 original_list->Append(make_scoped_ptr(new FundamentalValue(true))); 585 original_list->Append(WrapUnique(new FundamentalValue(true)));
580 EXPECT_FALSE(dv.Equals(copy.get())); 586 EXPECT_FALSE(dv.Equals(copy.get()));
581 587
582 // Check if Equals detects differences in only the keys. 588 // Check if Equals detects differences in only the keys.
583 copy = dv.CreateDeepCopy(); 589 copy = dv.CreateDeepCopy();
584 EXPECT_TRUE(dv.Equals(copy.get())); 590 EXPECT_TRUE(dv.Equals(copy.get()));
585 copy->Remove("a", NULL); 591 copy->Remove("a", NULL);
586 copy->SetBoolean("aa", false); 592 copy->SetBoolean("aa", false);
587 EXPECT_FALSE(dv.Equals(copy.get())); 593 EXPECT_FALSE(dv.Equals(copy.get()));
588 } 594 }
589 595
590 TEST(ValuesTest, StaticEquals) { 596 TEST(ValuesTest, StaticEquals) {
591 scoped_ptr<Value> null1(Value::CreateNullValue()); 597 std::unique_ptr<Value> null1(Value::CreateNullValue());
592 scoped_ptr<Value> null2(Value::CreateNullValue()); 598 std::unique_ptr<Value> null2(Value::CreateNullValue());
593 EXPECT_TRUE(Value::Equals(null1.get(), null2.get())); 599 EXPECT_TRUE(Value::Equals(null1.get(), null2.get()));
594 EXPECT_TRUE(Value::Equals(NULL, NULL)); 600 EXPECT_TRUE(Value::Equals(NULL, NULL));
595 601
596 scoped_ptr<Value> i42(new FundamentalValue(42)); 602 std::unique_ptr<Value> i42(new FundamentalValue(42));
597 scoped_ptr<Value> j42(new FundamentalValue(42)); 603 std::unique_ptr<Value> j42(new FundamentalValue(42));
598 scoped_ptr<Value> i17(new FundamentalValue(17)); 604 std::unique_ptr<Value> i17(new FundamentalValue(17));
599 EXPECT_TRUE(Value::Equals(i42.get(), i42.get())); 605 EXPECT_TRUE(Value::Equals(i42.get(), i42.get()));
600 EXPECT_TRUE(Value::Equals(j42.get(), i42.get())); 606 EXPECT_TRUE(Value::Equals(j42.get(), i42.get()));
601 EXPECT_TRUE(Value::Equals(i42.get(), j42.get())); 607 EXPECT_TRUE(Value::Equals(i42.get(), j42.get()));
602 EXPECT_FALSE(Value::Equals(i42.get(), i17.get())); 608 EXPECT_FALSE(Value::Equals(i42.get(), i17.get()));
603 EXPECT_FALSE(Value::Equals(i42.get(), NULL)); 609 EXPECT_FALSE(Value::Equals(i42.get(), NULL));
604 EXPECT_FALSE(Value::Equals(NULL, i42.get())); 610 EXPECT_FALSE(Value::Equals(NULL, i42.get()));
605 611
606 // NULL and Value::CreateNullValue() are intentionally different: We need 612 // NULL and Value::CreateNullValue() are intentionally different: We need
607 // support for NULL as a return value for "undefined" without caring for 613 // support for NULL as a return value for "undefined" without caring for
608 // ownership of the pointer. 614 // ownership of the pointer.
609 EXPECT_FALSE(Value::Equals(null1.get(), NULL)); 615 EXPECT_FALSE(Value::Equals(null1.get(), NULL));
610 EXPECT_FALSE(Value::Equals(NULL, null1.get())); 616 EXPECT_FALSE(Value::Equals(NULL, null1.get()));
611 } 617 }
612 618
613 TEST(ValuesTest, DeepCopyCovariantReturnTypes) { 619 TEST(ValuesTest, DeepCopyCovariantReturnTypes) {
614 DictionaryValue original_dict; 620 DictionaryValue original_dict;
615 scoped_ptr<Value> scoped_null(Value::CreateNullValue()); 621 std::unique_ptr<Value> scoped_null(Value::CreateNullValue());
616 Value* original_null = scoped_null.get(); 622 Value* original_null = scoped_null.get();
617 original_dict.Set("null", std::move(scoped_null)); 623 original_dict.Set("null", std::move(scoped_null));
618 scoped_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true)); 624 std::unique_ptr<FundamentalValue> scoped_bool(new FundamentalValue(true));
619 Value* original_bool = scoped_bool.get(); 625 Value* original_bool = scoped_bool.get();
620 original_dict.Set("bool", std::move(scoped_bool)); 626 original_dict.Set("bool", std::move(scoped_bool));
621 scoped_ptr<FundamentalValue> scoped_int(new FundamentalValue(42)); 627 std::unique_ptr<FundamentalValue> scoped_int(new FundamentalValue(42));
622 Value* original_int = scoped_int.get(); 628 Value* original_int = scoped_int.get();
623 original_dict.Set("int", std::move(scoped_int)); 629 original_dict.Set("int", std::move(scoped_int));
624 scoped_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14)); 630 std::unique_ptr<FundamentalValue> scoped_double(new FundamentalValue(3.14));
625 Value* original_double = scoped_double.get(); 631 Value* original_double = scoped_double.get();
626 original_dict.Set("double", std::move(scoped_double)); 632 original_dict.Set("double", std::move(scoped_double));
627 scoped_ptr<StringValue> scoped_string(new StringValue("hello")); 633 std::unique_ptr<StringValue> scoped_string(new StringValue("hello"));
628 Value* original_string = scoped_string.get(); 634 Value* original_string = scoped_string.get();
629 original_dict.Set("string", std::move(scoped_string)); 635 original_dict.Set("string", std::move(scoped_string));
630 scoped_ptr<StringValue> scoped_string16( 636 std::unique_ptr<StringValue> scoped_string16(
631 new StringValue(ASCIIToUTF16("hello16"))); 637 new StringValue(ASCIIToUTF16("hello16")));
632 Value* original_string16 = scoped_string16.get(); 638 Value* original_string16 = scoped_string16.get();
633 original_dict.Set("string16", std::move(scoped_string16)); 639 original_dict.Set("string16", std::move(scoped_string16));
634 640
635 scoped_ptr<char[]> original_buffer(new char[42]); 641 std::unique_ptr<char[]> original_buffer(new char[42]);
636 memset(original_buffer.get(), '!', 42); 642 memset(original_buffer.get(), '!', 42);
637 scoped_ptr<BinaryValue> scoped_binary( 643 std::unique_ptr<BinaryValue> scoped_binary(
638 new BinaryValue(std::move(original_buffer), 42)); 644 new BinaryValue(std::move(original_buffer), 42));
639 Value* original_binary = scoped_binary.get(); 645 Value* original_binary = scoped_binary.get();
640 original_dict.Set("binary", std::move(scoped_binary)); 646 original_dict.Set("binary", std::move(scoped_binary));
641 647
642 scoped_ptr<ListValue> scoped_list(new ListValue()); 648 std::unique_ptr<ListValue> scoped_list(new ListValue());
643 Value* original_list = scoped_list.get(); 649 Value* original_list = scoped_list.get();
644 scoped_ptr<FundamentalValue> scoped_list_element_0(new FundamentalValue(0)); 650 std::unique_ptr<FundamentalValue> scoped_list_element_0(
651 new FundamentalValue(0));
645 scoped_list->Append(std::move(scoped_list_element_0)); 652 scoped_list->Append(std::move(scoped_list_element_0));
646 scoped_ptr<FundamentalValue> scoped_list_element_1(new FundamentalValue(1)); 653 std::unique_ptr<FundamentalValue> scoped_list_element_1(
654 new FundamentalValue(1));
647 scoped_list->Append(std::move(scoped_list_element_1)); 655 scoped_list->Append(std::move(scoped_list_element_1));
648 original_dict.Set("list", std::move(scoped_list)); 656 original_dict.Set("list", std::move(scoped_list));
649 657
650 scoped_ptr<Value> copy_dict = original_dict.CreateDeepCopy(); 658 std::unique_ptr<Value> copy_dict = original_dict.CreateDeepCopy();
651 scoped_ptr<Value> copy_null = original_null->CreateDeepCopy(); 659 std::unique_ptr<Value> copy_null = original_null->CreateDeepCopy();
652 scoped_ptr<Value> copy_bool = original_bool->CreateDeepCopy(); 660 std::unique_ptr<Value> copy_bool = original_bool->CreateDeepCopy();
653 scoped_ptr<Value> copy_int = original_int->CreateDeepCopy(); 661 std::unique_ptr<Value> copy_int = original_int->CreateDeepCopy();
654 scoped_ptr<Value> copy_double = original_double->CreateDeepCopy(); 662 std::unique_ptr<Value> copy_double = original_double->CreateDeepCopy();
655 scoped_ptr<Value> copy_string = original_string->CreateDeepCopy(); 663 std::unique_ptr<Value> copy_string = original_string->CreateDeepCopy();
656 scoped_ptr<Value> copy_string16 = original_string16->CreateDeepCopy(); 664 std::unique_ptr<Value> copy_string16 = original_string16->CreateDeepCopy();
657 scoped_ptr<Value> copy_binary = original_binary->CreateDeepCopy(); 665 std::unique_ptr<Value> copy_binary = original_binary->CreateDeepCopy();
658 scoped_ptr<Value> copy_list = original_list->CreateDeepCopy(); 666 std::unique_ptr<Value> copy_list = original_list->CreateDeepCopy();
659 667
660 EXPECT_TRUE(original_dict.Equals(copy_dict.get())); 668 EXPECT_TRUE(original_dict.Equals(copy_dict.get()));
661 EXPECT_TRUE(original_null->Equals(copy_null.get())); 669 EXPECT_TRUE(original_null->Equals(copy_null.get()));
662 EXPECT_TRUE(original_bool->Equals(copy_bool.get())); 670 EXPECT_TRUE(original_bool->Equals(copy_bool.get()));
663 EXPECT_TRUE(original_int->Equals(copy_int.get())); 671 EXPECT_TRUE(original_int->Equals(copy_int.get()));
664 EXPECT_TRUE(original_double->Equals(copy_double.get())); 672 EXPECT_TRUE(original_double->Equals(copy_double.get()));
665 EXPECT_TRUE(original_string->Equals(copy_string.get())); 673 EXPECT_TRUE(original_string->Equals(copy_string.get()));
666 EXPECT_TRUE(original_string16->Equals(copy_string16.get())); 674 EXPECT_TRUE(original_string16->Equals(copy_string16.get()));
667 EXPECT_TRUE(original_binary->Equals(copy_binary.get())); 675 EXPECT_TRUE(original_binary->Equals(copy_binary.get()));
668 EXPECT_TRUE(original_list->Equals(copy_list.get())); 676 EXPECT_TRUE(original_list->Equals(copy_list.get()));
669 } 677 }
670 678
671 TEST(ValuesTest, RemoveEmptyChildren) { 679 TEST(ValuesTest, RemoveEmptyChildren) {
672 scoped_ptr<DictionaryValue> root(new DictionaryValue); 680 std::unique_ptr<DictionaryValue> root(new DictionaryValue);
673 // Remove empty lists and dictionaries. 681 // Remove empty lists and dictionaries.
674 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); 682 root->Set("empty_dict", WrapUnique(new DictionaryValue));
675 root->Set("empty_list", make_scoped_ptr(new ListValue)); 683 root->Set("empty_list", WrapUnique(new ListValue));
676 root->SetWithoutPathExpansion("a.b.c.d.e", 684 root->SetWithoutPathExpansion("a.b.c.d.e",
677 make_scoped_ptr(new DictionaryValue)); 685 WrapUnique(new DictionaryValue));
678 root = root->DeepCopyWithoutEmptyChildren(); 686 root = root->DeepCopyWithoutEmptyChildren();
679 EXPECT_TRUE(root->empty()); 687 EXPECT_TRUE(root->empty());
680 688
681 // Make sure we don't prune too much. 689 // Make sure we don't prune too much.
682 root->SetBoolean("bool", true); 690 root->SetBoolean("bool", true);
683 root->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); 691 root->Set("empty_dict", WrapUnique(new DictionaryValue));
684 root->SetString("empty_string", std::string()); 692 root->SetString("empty_string", std::string());
685 root = root->DeepCopyWithoutEmptyChildren(); 693 root = root->DeepCopyWithoutEmptyChildren();
686 EXPECT_EQ(2U, root->size()); 694 EXPECT_EQ(2U, root->size());
687 695
688 // Should do nothing. 696 // Should do nothing.
689 root = root->DeepCopyWithoutEmptyChildren(); 697 root = root->DeepCopyWithoutEmptyChildren();
690 EXPECT_EQ(2U, root->size()); 698 EXPECT_EQ(2U, root->size());
691 699
692 // Nested test cases. These should all reduce back to the bool and string 700 // Nested test cases. These should all reduce back to the bool and string
693 // set above. 701 // set above.
694 { 702 {
695 root->Set("a.b.c.d.e", make_scoped_ptr(new DictionaryValue)); 703 root->Set("a.b.c.d.e", WrapUnique(new DictionaryValue));
696 root = root->DeepCopyWithoutEmptyChildren(); 704 root = root->DeepCopyWithoutEmptyChildren();
697 EXPECT_EQ(2U, root->size()); 705 EXPECT_EQ(2U, root->size());
698 } 706 }
699 { 707 {
700 scoped_ptr<DictionaryValue> inner(new DictionaryValue); 708 std::unique_ptr<DictionaryValue> inner(new DictionaryValue);
701 inner->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); 709 inner->Set("empty_dict", WrapUnique(new DictionaryValue));
702 inner->Set("empty_list", make_scoped_ptr(new ListValue)); 710 inner->Set("empty_list", WrapUnique(new ListValue));
703 root->Set("dict_with_empty_children", std::move(inner)); 711 root->Set("dict_with_empty_children", std::move(inner));
704 root = root->DeepCopyWithoutEmptyChildren(); 712 root = root->DeepCopyWithoutEmptyChildren();
705 EXPECT_EQ(2U, root->size()); 713 EXPECT_EQ(2U, root->size());
706 } 714 }
707 { 715 {
708 scoped_ptr<ListValue> inner(new ListValue); 716 std::unique_ptr<ListValue> inner(new ListValue);
709 inner->Append(make_scoped_ptr(new DictionaryValue)); 717 inner->Append(WrapUnique(new DictionaryValue));
710 inner->Append(make_scoped_ptr(new ListValue)); 718 inner->Append(WrapUnique(new ListValue));
711 root->Set("list_with_empty_children", std::move(inner)); 719 root->Set("list_with_empty_children", std::move(inner));
712 root = root->DeepCopyWithoutEmptyChildren(); 720 root = root->DeepCopyWithoutEmptyChildren();
713 EXPECT_EQ(2U, root->size()); 721 EXPECT_EQ(2U, root->size());
714 } 722 }
715 723
716 // Nested with siblings. 724 // Nested with siblings.
717 { 725 {
718 scoped_ptr<ListValue> inner(new ListValue()); 726 std::unique_ptr<ListValue> inner(new ListValue());
719 inner->Append(make_scoped_ptr(new DictionaryValue)); 727 inner->Append(WrapUnique(new DictionaryValue));
720 inner->Append(make_scoped_ptr(new ListValue)); 728 inner->Append(WrapUnique(new ListValue));
721 root->Set("list_with_empty_children", std::move(inner)); 729 root->Set("list_with_empty_children", std::move(inner));
722 scoped_ptr<DictionaryValue> inner2(new DictionaryValue); 730 std::unique_ptr<DictionaryValue> inner2(new DictionaryValue);
723 inner2->Set("empty_dict", make_scoped_ptr(new DictionaryValue)); 731 inner2->Set("empty_dict", WrapUnique(new DictionaryValue));
724 inner2->Set("empty_list", make_scoped_ptr(new ListValue)); 732 inner2->Set("empty_list", WrapUnique(new ListValue));
725 root->Set("dict_with_empty_children", std::move(inner2)); 733 root->Set("dict_with_empty_children", std::move(inner2));
726 root = root->DeepCopyWithoutEmptyChildren(); 734 root = root->DeepCopyWithoutEmptyChildren();
727 EXPECT_EQ(2U, root->size()); 735 EXPECT_EQ(2U, root->size());
728 } 736 }
729 737
730 // Make sure nested values don't get pruned. 738 // Make sure nested values don't get pruned.
731 { 739 {
732 scoped_ptr<ListValue> inner(new ListValue); 740 std::unique_ptr<ListValue> inner(new ListValue);
733 scoped_ptr<ListValue> inner2(new ListValue); 741 std::unique_ptr<ListValue> inner2(new ListValue);
734 inner2->Append(make_scoped_ptr(new StringValue("hello"))); 742 inner2->Append(WrapUnique(new StringValue("hello")));
735 inner->Append(make_scoped_ptr(new DictionaryValue)); 743 inner->Append(WrapUnique(new DictionaryValue));
736 inner->Append(std::move(inner2)); 744 inner->Append(std::move(inner2));
737 root->Set("list_with_empty_children", std::move(inner)); 745 root->Set("list_with_empty_children", std::move(inner));
738 root = root->DeepCopyWithoutEmptyChildren(); 746 root = root->DeepCopyWithoutEmptyChildren();
739 EXPECT_EQ(3U, root->size()); 747 EXPECT_EQ(3U, root->size());
740 748
741 ListValue* inner_value, *inner_value2; 749 ListValue* inner_value, *inner_value2;
742 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value)); 750 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner_value));
743 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned. 751 EXPECT_EQ(1U, inner_value->GetSize()); // Dictionary was pruned.
744 EXPECT_TRUE(inner_value->GetList(0, &inner_value2)); 752 EXPECT_TRUE(inner_value->GetList(0, &inner_value2));
745 EXPECT_EQ(1U, inner_value2->GetSize()); 753 EXPECT_EQ(1U, inner_value2->GetSize());
746 } 754 }
747 } 755 }
748 756
749 TEST(ValuesTest, MergeDictionary) { 757 TEST(ValuesTest, MergeDictionary) {
750 scoped_ptr<DictionaryValue> base(new DictionaryValue); 758 std::unique_ptr<DictionaryValue> base(new DictionaryValue);
751 base->SetString("base_key", "base_key_value_base"); 759 base->SetString("base_key", "base_key_value_base");
752 base->SetString("collide_key", "collide_key_value_base"); 760 base->SetString("collide_key", "collide_key_value_base");
753 scoped_ptr<DictionaryValue> base_sub_dict(new DictionaryValue); 761 std::unique_ptr<DictionaryValue> base_sub_dict(new DictionaryValue);
754 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); 762 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base");
755 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); 763 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base");
756 base->Set("sub_dict_key", std::move(base_sub_dict)); 764 base->Set("sub_dict_key", std::move(base_sub_dict));
757 765
758 scoped_ptr<DictionaryValue> merge(new DictionaryValue); 766 std::unique_ptr<DictionaryValue> merge(new DictionaryValue);
759 merge->SetString("merge_key", "merge_key_value_merge"); 767 merge->SetString("merge_key", "merge_key_value_merge");
760 merge->SetString("collide_key", "collide_key_value_merge"); 768 merge->SetString("collide_key", "collide_key_value_merge");
761 scoped_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue); 769 std::unique_ptr<DictionaryValue> merge_sub_dict(new DictionaryValue);
762 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge"); 770 merge_sub_dict->SetString("sub_merge_key", "sub_merge_key_value_merge");
763 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge"); 771 merge_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_merge");
764 merge->Set("sub_dict_key", std::move(merge_sub_dict)); 772 merge->Set("sub_dict_key", std::move(merge_sub_dict));
765 773
766 base->MergeDictionary(merge.get()); 774 base->MergeDictionary(merge.get());
767 775
768 EXPECT_EQ(4U, base->size()); 776 EXPECT_EQ(4U, base->size());
769 std::string base_key_value; 777 std::string base_key_value;
770 EXPECT_TRUE(base->GetString("base_key", &base_key_value)); 778 EXPECT_TRUE(base->GetString("base_key", &base_key_value));
771 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved. 779 EXPECT_EQ("base_key_value_base", base_key_value); // Base value preserved.
(...skipping 13 matching lines...) Expand all
785 std::string sub_collide_key_value; 793 std::string sub_collide_key_value;
786 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", 794 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key",
787 &sub_collide_key_value)); 795 &sub_collide_key_value));
788 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. 796 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
789 std::string sub_merge_key_value; 797 std::string sub_merge_key_value;
790 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); 798 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
791 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. 799 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
792 } 800 }
793 801
794 TEST(ValuesTest, MergeDictionaryDeepCopy) { 802 TEST(ValuesTest, MergeDictionaryDeepCopy) {
795 scoped_ptr<DictionaryValue> child(new DictionaryValue); 803 std::unique_ptr<DictionaryValue> child(new DictionaryValue);
796 DictionaryValue* original_child = child.get(); 804 DictionaryValue* original_child = child.get();
797 child->SetString("test", "value"); 805 child->SetString("test", "value");
798 EXPECT_EQ(1U, child->size()); 806 EXPECT_EQ(1U, child->size());
799 807
800 std::string value; 808 std::string value;
801 EXPECT_TRUE(child->GetString("test", &value)); 809 EXPECT_TRUE(child->GetString("test", &value));
802 EXPECT_EQ("value", value); 810 EXPECT_EQ("value", value);
803 811
804 scoped_ptr<DictionaryValue> base(new DictionaryValue); 812 std::unique_ptr<DictionaryValue> base(new DictionaryValue);
805 base->Set("dict", std::move(child)); 813 base->Set("dict", std::move(child));
806 EXPECT_EQ(1U, base->size()); 814 EXPECT_EQ(1U, base->size());
807 815
808 DictionaryValue* ptr; 816 DictionaryValue* ptr;
809 EXPECT_TRUE(base->GetDictionary("dict", &ptr)); 817 EXPECT_TRUE(base->GetDictionary("dict", &ptr));
810 EXPECT_EQ(original_child, ptr); 818 EXPECT_EQ(original_child, ptr);
811 819
812 scoped_ptr<DictionaryValue> merged(new DictionaryValue); 820 std::unique_ptr<DictionaryValue> merged(new DictionaryValue);
813 merged->MergeDictionary(base.get()); 821 merged->MergeDictionary(base.get());
814 EXPECT_EQ(1U, merged->size()); 822 EXPECT_EQ(1U, merged->size());
815 EXPECT_TRUE(merged->GetDictionary("dict", &ptr)); 823 EXPECT_TRUE(merged->GetDictionary("dict", &ptr));
816 EXPECT_NE(original_child, ptr); 824 EXPECT_NE(original_child, ptr);
817 EXPECT_TRUE(ptr->GetString("test", &value)); 825 EXPECT_TRUE(ptr->GetString("test", &value));
818 EXPECT_EQ("value", value); 826 EXPECT_EQ("value", value);
819 827
820 original_child->SetString("test", "overwrite"); 828 original_child->SetString("test", "overwrite");
821 base.reset(); 829 base.reset();
822 EXPECT_TRUE(ptr->GetString("test", &value)); 830 EXPECT_TRUE(ptr->GetString("test", &value));
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 EXPECT_FALSE(main_list.GetList(1, NULL)); 1147 EXPECT_FALSE(main_list.GetList(1, NULL));
1140 EXPECT_FALSE(main_list.GetList(2, NULL)); 1148 EXPECT_FALSE(main_list.GetList(2, NULL));
1141 EXPECT_FALSE(main_list.GetList(3, NULL)); 1149 EXPECT_FALSE(main_list.GetList(3, NULL));
1142 EXPECT_FALSE(main_list.GetList(4, NULL)); 1150 EXPECT_FALSE(main_list.GetList(4, NULL));
1143 EXPECT_FALSE(main_list.GetList(5, NULL)); 1151 EXPECT_FALSE(main_list.GetList(5, NULL));
1144 EXPECT_TRUE(main_list.GetList(6, NULL)); 1152 EXPECT_TRUE(main_list.GetList(6, NULL));
1145 EXPECT_FALSE(main_list.GetList(7, NULL)); 1153 EXPECT_FALSE(main_list.GetList(7, NULL));
1146 } 1154 }
1147 1155
1148 } // namespace base 1156 } // namespace base
OLDNEW
« no previous file with comments | « base/values.cc ('k') | base/win/enum_variant.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698