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

Side by Side Diff: base/values_unittest.cc

Issue 3035045: Add dictionary comparing functions and unit tests (Closed)
Patch Set: merge with latest Created 10 years, 4 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') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <limits> 5 #include <limits>
6 6
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 class ValuesTest: public testing::Test { 14 class ValuesTest: public testing::Test {
15 protected:
16 void CompareDictionariesAndCheckResult(
17 const DictionaryValue* dict1,
18 const DictionaryValue* dict2,
19 const char* expected_paths[],
20 size_t expected_paths_count) {
21 std::vector<std::string> differing_paths;
22 std::vector<std::string> expected_paths_vector(expected_paths,
23 expected_paths+expected_paths_count);
24 // All comparisons should be commutative, check dict1 against dict2
25 // and vice-versa.
26 dict1->GetDifferingPaths(dict2, &differing_paths);
27 ASSERT_EQ(expected_paths_count, differing_paths.size());
28 EXPECT_TRUE(equal(differing_paths.begin(), differing_paths.end(),
29 expected_paths_vector.begin()));
30 dict2->GetDifferingPaths(dict1, &differing_paths);
31 ASSERT_EQ(expected_paths_count, differing_paths.size());
32 EXPECT_TRUE(equal(differing_paths.begin(), differing_paths.end(),
33 expected_paths_vector.begin()));
34 }
15 }; 35 };
16 36
17 // TODO(viettrungluu): I changed the keys for DictionaryValue from std::wstring 37 // TODO(viettrungluu): I changed the keys for DictionaryValue from std::wstring
18 // to std::string. I've temporarily kept the old methods taking std::wstring for 38 // to std::string. I've temporarily kept the old methods taking std::wstring for
19 // compatibility. The ...Deprecated tests are the old tests which use these 39 // compatibility. The ...Deprecated tests are the old tests which use these
20 // methods, and remain to test compatibility. They will be removed once the old 40 // methods, and remain to test compatibility. They will be removed once the old
21 // methods are removed. There are also parts of tests marked DEPRECATED which 41 // methods are removed. There are also parts of tests marked DEPRECATED which
22 // are to be deleted. 42 // are to be deleted.
23 43
24 TEST(ValuesTest, Basic) { 44 TEST_F(ValuesTest, Basic) {
25 // Test basic dictionary getting/setting 45 // Test basic dictionary getting/setting
26 DictionaryValue settings; 46 DictionaryValue settings;
27 std::string homepage = "http://google.com"; 47 std::string homepage = "http://google.com";
28 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); 48 ASSERT_FALSE(settings.GetString("global.homepage", &homepage));
29 ASSERT_EQ(std::string("http://google.com"), homepage); 49 ASSERT_EQ(std::string("http://google.com"), homepage);
30 50
31 ASSERT_FALSE(settings.Get("global", NULL)); 51 ASSERT_FALSE(settings.Get("global", NULL));
32 settings.Set("global", Value::CreateBooleanValue(true)); 52 settings.Set("global", Value::CreateBooleanValue(true));
33 ASSERT_TRUE(settings.Get("global", NULL)); 53 ASSERT_TRUE(settings.Get("global", NULL));
34 settings.SetString("global.homepage", "http://scurvy.com"); 54 settings.SetString("global.homepage", "http://scurvy.com");
(...skipping 23 matching lines...) Expand all
58 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); 78 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark));
59 std::string bookmark_name = "Unnamed"; 79 std::string bookmark_name = "Unnamed";
60 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); 80 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name));
61 ASSERT_EQ(std::string("Froogle"), bookmark_name); 81 ASSERT_EQ(std::string("Froogle"), bookmark_name);
62 std::string bookmark_url; 82 std::string bookmark_url;
63 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url)); 83 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url));
64 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); 84 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url);
65 } 85 }
66 86
67 // TODO(viettrungluu): deprecate: 87 // TODO(viettrungluu): deprecate:
68 TEST(ValuesTest, BasicDeprecated) { 88 TEST_F(ValuesTest, BasicDeprecated) {
69 // Test basic dictionary getting/setting 89 // Test basic dictionary getting/setting
70 DictionaryValue settings; 90 DictionaryValue settings;
71 std::wstring homepage = L"http://google.com"; 91 std::wstring homepage = L"http://google.com";
72 ASSERT_FALSE( 92 ASSERT_FALSE(
73 settings.GetString(L"global.homepage", &homepage)); 93 settings.GetString(L"global.homepage", &homepage));
74 ASSERT_EQ(std::wstring(L"http://google.com"), homepage); 94 ASSERT_EQ(std::wstring(L"http://google.com"), homepage);
75 95
76 ASSERT_FALSE(settings.Get(L"global", NULL)); 96 ASSERT_FALSE(settings.Get(L"global", NULL));
77 settings.Set(L"global", Value::CreateBooleanValue(true)); 97 settings.Set(L"global", Value::CreateBooleanValue(true));
78 ASSERT_TRUE(settings.Get(L"global", NULL)); 98 ASSERT_TRUE(settings.Get(L"global", NULL));
(...skipping 24 matching lines...) Expand all
103 ASSERT_EQ(1U, bookmark_list->GetSize()); 123 ASSERT_EQ(1U, bookmark_list->GetSize());
104 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); 124 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark));
105 std::wstring bookmark_name = L"Unnamed"; 125 std::wstring bookmark_name = L"Unnamed";
106 ASSERT_TRUE(bookmark->GetString(L"name", &bookmark_name)); 126 ASSERT_TRUE(bookmark->GetString(L"name", &bookmark_name));
107 ASSERT_EQ(std::wstring(L"Froogle"), bookmark_name); 127 ASSERT_EQ(std::wstring(L"Froogle"), bookmark_name);
108 std::wstring bookmark_url; 128 std::wstring bookmark_url;
109 ASSERT_TRUE(bookmark->GetString(L"url", &bookmark_url)); 129 ASSERT_TRUE(bookmark->GetString(L"url", &bookmark_url));
110 ASSERT_EQ(std::wstring(L"http://froogle.com"), bookmark_url); 130 ASSERT_EQ(std::wstring(L"http://froogle.com"), bookmark_url);
111 } 131 }
112 132
113 TEST(ValuesTest, List) { 133 TEST_F(ValuesTest, List) {
114 scoped_ptr<ListValue> mixed_list(new ListValue()); 134 scoped_ptr<ListValue> mixed_list(new ListValue());
115 mixed_list->Set(0, Value::CreateBooleanValue(true)); 135 mixed_list->Set(0, Value::CreateBooleanValue(true));
116 mixed_list->Set(1, Value::CreateIntegerValue(42)); 136 mixed_list->Set(1, Value::CreateIntegerValue(42));
117 mixed_list->Set(2, Value::CreateRealValue(88.8)); 137 mixed_list->Set(2, Value::CreateRealValue(88.8));
118 mixed_list->Set(3, Value::CreateStringValue("foo")); 138 mixed_list->Set(3, Value::CreateStringValue("foo"));
119 ASSERT_EQ(4u, mixed_list->GetSize()); 139 ASSERT_EQ(4u, mixed_list->GetSize());
120 140
121 Value *value = NULL; 141 Value *value = NULL;
122 bool bool_value = false; 142 bool bool_value = false;
123 int int_value = 0; 143 int int_value = 0;
(...skipping 14 matching lines...) Expand all
138 ASSERT_TRUE(mixed_list->GetBoolean(0, &bool_value)); 158 ASSERT_TRUE(mixed_list->GetBoolean(0, &bool_value));
139 ASSERT_EQ(true, bool_value); 159 ASSERT_EQ(true, bool_value);
140 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value)); 160 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value));
141 ASSERT_EQ(42, int_value); 161 ASSERT_EQ(42, int_value);
142 ASSERT_TRUE(mixed_list->GetReal(2, &double_value)); 162 ASSERT_TRUE(mixed_list->GetReal(2, &double_value));
143 ASSERT_EQ(88.8, double_value); 163 ASSERT_EQ(88.8, double_value);
144 ASSERT_TRUE(mixed_list->GetString(3, &string_value)); 164 ASSERT_TRUE(mixed_list->GetString(3, &string_value));
145 ASSERT_EQ("foo", string_value); 165 ASSERT_EQ("foo", string_value);
146 } 166 }
147 167
148 TEST(ValuesTest, BinaryValue) { 168 TEST_F(ValuesTest, BinaryValue) {
149 char* buffer = NULL; 169 char* buffer = NULL;
150 // Passing a null buffer pointer doesn't yield a BinaryValue 170 // Passing a null buffer pointer doesn't yield a BinaryValue
151 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0)); 171 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0));
152 ASSERT_FALSE(binary.get()); 172 ASSERT_FALSE(binary.get());
153 173
154 // If you want to represent an empty binary value, use a zero-length buffer. 174 // If you want to represent an empty binary value, use a zero-length buffer.
155 buffer = new char[1]; 175 buffer = new char[1];
156 ASSERT_TRUE(buffer); 176 ASSERT_TRUE(buffer);
157 binary.reset(BinaryValue::Create(buffer, 0)); 177 binary.reset(BinaryValue::Create(buffer, 0));
158 ASSERT_TRUE(binary.get()); 178 ASSERT_TRUE(binary.get());
(...skipping 12 matching lines...) Expand all
171 char stack_buffer[42]; 191 char stack_buffer[42];
172 memset(stack_buffer, '!', 42); 192 memset(stack_buffer, '!', 42);
173 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); 193 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42));
174 ASSERT_TRUE(binary.get()); 194 ASSERT_TRUE(binary.get());
175 ASSERT_TRUE(binary->GetBuffer()); 195 ASSERT_TRUE(binary->GetBuffer());
176 ASSERT_NE(stack_buffer, binary->GetBuffer()); 196 ASSERT_NE(stack_buffer, binary->GetBuffer());
177 ASSERT_EQ(42U, binary->GetSize()); 197 ASSERT_EQ(42U, binary->GetSize());
178 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); 198 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize()));
179 } 199 }
180 200
181 TEST(ValuesTest, StringValue) { 201 TEST_F(ValuesTest, StringValue) {
182 // Test overloaded CreateStringValue. 202 // Test overloaded CreateStringValue.
183 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); 203 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow"));
184 ASSERT_TRUE(narrow_value.get()); 204 ASSERT_TRUE(narrow_value.get());
185 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); 205 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
186 scoped_ptr<Value> utf16_value( 206 scoped_ptr<Value> utf16_value(
187 Value::CreateStringValue(ASCIIToUTF16("utf16"))); 207 Value::CreateStringValue(ASCIIToUTF16("utf16")));
188 ASSERT_TRUE(utf16_value.get()); 208 ASSERT_TRUE(utf16_value.get());
189 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); 209 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING));
190 210
191 // Test overloaded GetString. 211 // Test overloaded GetString.
192 std::string narrow = "http://google.com"; 212 std::string narrow = "http://google.com";
193 string16 utf16 = ASCIIToUTF16("http://google.com"); 213 string16 utf16 = ASCIIToUTF16("http://google.com");
194 ASSERT_TRUE(narrow_value->GetAsString(&narrow)); 214 ASSERT_TRUE(narrow_value->GetAsString(&narrow));
195 ASSERT_TRUE(narrow_value->GetAsString(&utf16)); 215 ASSERT_TRUE(narrow_value->GetAsString(&utf16));
196 ASSERT_EQ(std::string("narrow"), narrow); 216 ASSERT_EQ(std::string("narrow"), narrow);
197 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16); 217 ASSERT_EQ(ASCIIToUTF16("narrow"), utf16);
198 218
199 ASSERT_TRUE(utf16_value->GetAsString(&narrow)); 219 ASSERT_TRUE(utf16_value->GetAsString(&narrow));
200 ASSERT_TRUE(utf16_value->GetAsString(&utf16)); 220 ASSERT_TRUE(utf16_value->GetAsString(&utf16));
201 ASSERT_EQ(std::string("utf16"), narrow); 221 ASSERT_EQ(std::string("utf16"), narrow);
202 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16); 222 ASSERT_EQ(ASCIIToUTF16("utf16"), utf16);
203 } 223 }
204 224
205 // TODO(viettrungluu): deprecate: 225 // TODO(viettrungluu): deprecate:
206 TEST(ValuesTest, StringValueDeprecated) { 226 TEST_F(ValuesTest, StringValueDeprecated) {
207 // Test overloaded CreateStringValue. 227 // Test overloaded CreateStringValue.
208 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); 228 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow"));
209 ASSERT_TRUE(narrow_value.get()); 229 ASSERT_TRUE(narrow_value.get());
210 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); 230 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING));
211 scoped_ptr<Value> wide_value(Value::CreateStringValue(L"wide")); 231 scoped_ptr<Value> wide_value(Value::CreateStringValue(L"wide"));
212 ASSERT_TRUE(wide_value.get()); 232 ASSERT_TRUE(wide_value.get());
213 ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING)); 233 ASSERT_TRUE(wide_value->IsType(Value::TYPE_STRING));
214 scoped_ptr<Value> utf16_value( 234 scoped_ptr<Value> utf16_value(
215 Value::CreateStringValue(ASCIIToUTF16("utf16"))); 235 Value::CreateStringValue(ASCIIToUTF16("utf16")));
216 ASSERT_TRUE(utf16_value.get()); 236 ASSERT_TRUE(utf16_value.get());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 277 }
258 278
259 ~DeletionTestValue() { 279 ~DeletionTestValue() {
260 *deletion_flag_ = true; 280 *deletion_flag_ = true;
261 } 281 }
262 282
263 private: 283 private:
264 bool* deletion_flag_; 284 bool* deletion_flag_;
265 }; 285 };
266 286
267 TEST(ValuesTest, ListDeletion) { 287 TEST_F(ValuesTest, ListDeletion) {
268 bool deletion_flag = true; 288 bool deletion_flag = true;
269 289
270 { 290 {
271 ListValue list; 291 ListValue list;
272 list.Append(new DeletionTestValue(&deletion_flag)); 292 list.Append(new DeletionTestValue(&deletion_flag));
273 EXPECT_FALSE(deletion_flag); 293 EXPECT_FALSE(deletion_flag);
274 } 294 }
275 EXPECT_TRUE(deletion_flag); 295 EXPECT_TRUE(deletion_flag);
276 296
277 { 297 {
278 ListValue list; 298 ListValue list;
279 list.Append(new DeletionTestValue(&deletion_flag)); 299 list.Append(new DeletionTestValue(&deletion_flag));
280 EXPECT_FALSE(deletion_flag); 300 EXPECT_FALSE(deletion_flag);
281 list.Clear(); 301 list.Clear();
282 EXPECT_TRUE(deletion_flag); 302 EXPECT_TRUE(deletion_flag);
283 } 303 }
284 304
285 { 305 {
286 ListValue list; 306 ListValue list;
287 list.Append(new DeletionTestValue(&deletion_flag)); 307 list.Append(new DeletionTestValue(&deletion_flag));
288 EXPECT_FALSE(deletion_flag); 308 EXPECT_FALSE(deletion_flag);
289 EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); 309 EXPECT_TRUE(list.Set(0, Value::CreateNullValue()));
290 EXPECT_TRUE(deletion_flag); 310 EXPECT_TRUE(deletion_flag);
291 } 311 }
292 } 312 }
293 313
294 TEST(ValuesTest, ListRemoval) { 314 TEST_F(ValuesTest, ListRemoval) {
295 bool deletion_flag = true; 315 bool deletion_flag = true;
296 Value* removed_item = NULL; 316 Value* removed_item = NULL;
297 317
298 { 318 {
299 ListValue list; 319 ListValue list;
300 list.Append(new DeletionTestValue(&deletion_flag)); 320 list.Append(new DeletionTestValue(&deletion_flag));
301 EXPECT_FALSE(deletion_flag); 321 EXPECT_FALSE(deletion_flag);
302 EXPECT_EQ(1U, list.GetSize()); 322 EXPECT_EQ(1U, list.GetSize());
303 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), 323 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(),
304 &removed_item)); 324 &removed_item));
(...skipping 20 matching lines...) Expand all
325 ListValue list; 345 ListValue list;
326 DeletionTestValue* value = new DeletionTestValue(&deletion_flag); 346 DeletionTestValue* value = new DeletionTestValue(&deletion_flag);
327 list.Append(value); 347 list.Append(value);
328 EXPECT_FALSE(deletion_flag); 348 EXPECT_FALSE(deletion_flag);
329 EXPECT_EQ(0, list.Remove(*value)); 349 EXPECT_EQ(0, list.Remove(*value));
330 EXPECT_TRUE(deletion_flag); 350 EXPECT_TRUE(deletion_flag);
331 EXPECT_EQ(0U, list.GetSize()); 351 EXPECT_EQ(0U, list.GetSize());
332 } 352 }
333 } 353 }
334 354
335 TEST(ValuesTest, DictionaryDeletion) { 355 TEST_F(ValuesTest, DictionaryDeletion) {
336 std::string key = "test"; 356 std::string key = "test";
337 bool deletion_flag = true; 357 bool deletion_flag = true;
338 358
339 { 359 {
340 DictionaryValue dict; 360 DictionaryValue dict;
341 dict.Set(key, new DeletionTestValue(&deletion_flag)); 361 dict.Set(key, new DeletionTestValue(&deletion_flag));
342 EXPECT_FALSE(deletion_flag); 362 EXPECT_FALSE(deletion_flag);
343 } 363 }
344 EXPECT_TRUE(deletion_flag); 364 EXPECT_TRUE(deletion_flag);
345 365
346 { 366 {
347 DictionaryValue dict; 367 DictionaryValue dict;
348 dict.Set(key, new DeletionTestValue(&deletion_flag)); 368 dict.Set(key, new DeletionTestValue(&deletion_flag));
349 EXPECT_FALSE(deletion_flag); 369 EXPECT_FALSE(deletion_flag);
350 dict.Clear(); 370 dict.Clear();
351 EXPECT_TRUE(deletion_flag); 371 EXPECT_TRUE(deletion_flag);
352 } 372 }
353 373
354 { 374 {
355 DictionaryValue dict; 375 DictionaryValue dict;
356 dict.Set(key, new DeletionTestValue(&deletion_flag)); 376 dict.Set(key, new DeletionTestValue(&deletion_flag));
357 EXPECT_FALSE(deletion_flag); 377 EXPECT_FALSE(deletion_flag);
358 dict.Set(key, Value::CreateNullValue()); 378 dict.Set(key, Value::CreateNullValue());
359 EXPECT_TRUE(deletion_flag); 379 EXPECT_TRUE(deletion_flag);
360 } 380 }
361 } 381 }
362 382
363 // TODO(viettrungluu): deprecate: 383 // TODO(viettrungluu): deprecate:
364 TEST(ValuesTest, DictionaryDeletionDeprecated) { 384 TEST_F(ValuesTest, DictionaryDeletionDeprecated) {
365 std::wstring key = L"test"; 385 std::wstring key = L"test";
366 bool deletion_flag = true; 386 bool deletion_flag = true;
367 387
368 { 388 {
369 DictionaryValue dict; 389 DictionaryValue dict;
370 dict.Set(key, new DeletionTestValue(&deletion_flag)); 390 dict.Set(key, new DeletionTestValue(&deletion_flag));
371 EXPECT_FALSE(deletion_flag); 391 EXPECT_FALSE(deletion_flag);
372 } 392 }
373 EXPECT_TRUE(deletion_flag); 393 EXPECT_TRUE(deletion_flag);
374 394
375 { 395 {
376 DictionaryValue dict; 396 DictionaryValue dict;
377 dict.Set(key, new DeletionTestValue(&deletion_flag)); 397 dict.Set(key, new DeletionTestValue(&deletion_flag));
378 EXPECT_FALSE(deletion_flag); 398 EXPECT_FALSE(deletion_flag);
379 dict.Clear(); 399 dict.Clear();
380 EXPECT_TRUE(deletion_flag); 400 EXPECT_TRUE(deletion_flag);
381 } 401 }
382 402
383 { 403 {
384 DictionaryValue dict; 404 DictionaryValue dict;
385 dict.Set(key, new DeletionTestValue(&deletion_flag)); 405 dict.Set(key, new DeletionTestValue(&deletion_flag));
386 EXPECT_FALSE(deletion_flag); 406 EXPECT_FALSE(deletion_flag);
387 dict.Set(key, Value::CreateNullValue()); 407 dict.Set(key, Value::CreateNullValue());
388 EXPECT_TRUE(deletion_flag); 408 EXPECT_TRUE(deletion_flag);
389 } 409 }
390 } 410 }
391 411
392 TEST(ValuesTest, DictionaryRemoval) { 412 TEST_F(ValuesTest, DictionaryRemoval) {
393 std::string key = "test"; 413 std::string key = "test";
394 bool deletion_flag = true; 414 bool deletion_flag = true;
395 Value* removed_item = NULL; 415 Value* removed_item = NULL;
396 416
397 { 417 {
398 DictionaryValue dict; 418 DictionaryValue dict;
399 dict.Set(key, new DeletionTestValue(&deletion_flag)); 419 dict.Set(key, new DeletionTestValue(&deletion_flag));
400 EXPECT_FALSE(deletion_flag); 420 EXPECT_FALSE(deletion_flag);
401 EXPECT_TRUE(dict.HasKey(key)); 421 EXPECT_TRUE(dict.HasKey(key));
402 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); 422 EXPECT_FALSE(dict.Remove("absent key", &removed_item));
(...skipping 11 matching lines...) Expand all
414 dict.Set(key, new DeletionTestValue(&deletion_flag)); 434 dict.Set(key, new DeletionTestValue(&deletion_flag));
415 EXPECT_FALSE(deletion_flag); 435 EXPECT_FALSE(deletion_flag);
416 EXPECT_TRUE(dict.HasKey(key)); 436 EXPECT_TRUE(dict.HasKey(key));
417 EXPECT_TRUE(dict.Remove(key, NULL)); 437 EXPECT_TRUE(dict.Remove(key, NULL));
418 EXPECT_TRUE(deletion_flag); 438 EXPECT_TRUE(deletion_flag);
419 EXPECT_FALSE(dict.HasKey(key)); 439 EXPECT_FALSE(dict.HasKey(key));
420 } 440 }
421 } 441 }
422 442
423 // TODO(viettrungluu): deprecate: 443 // TODO(viettrungluu): deprecate:
424 TEST(ValuesTest, DictionaryRemovalDeprecated) { 444 TEST_F(ValuesTest, DictionaryRemovalDeprecated) {
425 std::wstring key = L"test"; 445 std::wstring key = L"test";
426 bool deletion_flag = true; 446 bool deletion_flag = true;
427 Value* removed_item = NULL; 447 Value* removed_item = NULL;
428 448
429 { 449 {
430 DictionaryValue dict; 450 DictionaryValue dict;
431 dict.Set(key, new DeletionTestValue(&deletion_flag)); 451 dict.Set(key, new DeletionTestValue(&deletion_flag));
432 EXPECT_FALSE(deletion_flag); 452 EXPECT_FALSE(deletion_flag);
433 EXPECT_TRUE(dict.HasKey(key)); 453 EXPECT_TRUE(dict.HasKey(key));
434 EXPECT_FALSE(dict.Remove(L"absent key", &removed_item)); 454 EXPECT_FALSE(dict.Remove(L"absent key", &removed_item));
(...skipping 10 matching lines...) Expand all
445 DictionaryValue dict; 465 DictionaryValue dict;
446 dict.Set(key, new DeletionTestValue(&deletion_flag)); 466 dict.Set(key, new DeletionTestValue(&deletion_flag));
447 EXPECT_FALSE(deletion_flag); 467 EXPECT_FALSE(deletion_flag);
448 EXPECT_TRUE(dict.HasKey(key)); 468 EXPECT_TRUE(dict.HasKey(key));
449 EXPECT_TRUE(dict.Remove(key, NULL)); 469 EXPECT_TRUE(dict.Remove(key, NULL));
450 EXPECT_TRUE(deletion_flag); 470 EXPECT_TRUE(deletion_flag);
451 EXPECT_FALSE(dict.HasKey(key)); 471 EXPECT_FALSE(dict.HasKey(key));
452 } 472 }
453 } 473 }
454 474
455 TEST(ValuesTest, DictionaryWithoutPathExpansion) { 475 TEST_F(ValuesTest, DictionaryWithoutPathExpansion) {
456 DictionaryValue dict; 476 DictionaryValue dict;
457 dict.Set("this.is.expanded", Value::CreateNullValue()); 477 dict.Set("this.is.expanded", Value::CreateNullValue());
458 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue()); 478 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue());
459 479
460 EXPECT_FALSE(dict.HasKey("this.is.expanded")); 480 EXPECT_FALSE(dict.HasKey("this.is.expanded"));
461 EXPECT_TRUE(dict.HasKey("this")); 481 EXPECT_TRUE(dict.HasKey("this"));
462 Value* value1; 482 Value* value1;
463 EXPECT_TRUE(dict.Get("this", &value1)); 483 EXPECT_TRUE(dict.Get("this", &value1));
464 DictionaryValue* value2; 484 DictionaryValue* value2;
465 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2)); 485 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2));
466 EXPECT_EQ(value1, value2); 486 EXPECT_EQ(value1, value2);
467 EXPECT_EQ(1U, value2->size()); 487 EXPECT_EQ(1U, value2->size());
468 488
469 EXPECT_TRUE(dict.HasKey("this.isnt.expanded")); 489 EXPECT_TRUE(dict.HasKey("this.isnt.expanded"));
470 Value* value3; 490 Value* value3;
471 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3)); 491 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3));
472 Value* value4; 492 Value* value4;
473 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4)); 493 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4));
474 EXPECT_EQ(Value::TYPE_NULL, value4->GetType()); 494 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
475 } 495 }
476 496
477 // TODO(viettrungluu): deprecate: 497 // TODO(viettrungluu): deprecate:
478 TEST(ValuesTest, DictionaryWithoutPathExpansionDeprecated) { 498 TEST_F(ValuesTest, DictionaryWithoutPathExpansionDeprecated) {
479 DictionaryValue dict; 499 DictionaryValue dict;
480 dict.Set(L"this.is.expanded", Value::CreateNullValue()); 500 dict.Set(L"this.is.expanded", Value::CreateNullValue());
481 dict.SetWithoutPathExpansion(L"this.isnt.expanded", Value::CreateNullValue()); 501 dict.SetWithoutPathExpansion(L"this.isnt.expanded", Value::CreateNullValue());
482 502
483 EXPECT_FALSE(dict.HasKey(L"this.is.expanded")); 503 EXPECT_FALSE(dict.HasKey(L"this.is.expanded"));
484 EXPECT_TRUE(dict.HasKey(L"this")); 504 EXPECT_TRUE(dict.HasKey(L"this"));
485 Value* value1; 505 Value* value1;
486 EXPECT_TRUE(dict.Get(L"this", &value1)); 506 EXPECT_TRUE(dict.Get(L"this", &value1));
487 DictionaryValue* value2; 507 DictionaryValue* value2;
488 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion(L"this", &value2)); 508 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion(L"this", &value2));
489 EXPECT_EQ(value1, value2); 509 EXPECT_EQ(value1, value2);
490 EXPECT_EQ(1U, value2->size()); 510 EXPECT_EQ(1U, value2->size());
491 511
492 EXPECT_TRUE(dict.HasKey(L"this.isnt.expanded")); 512 EXPECT_TRUE(dict.HasKey(L"this.isnt.expanded"));
493 Value* value3; 513 Value* value3;
494 EXPECT_FALSE(dict.Get(L"this.isnt.expanded", &value3)); 514 EXPECT_FALSE(dict.Get(L"this.isnt.expanded", &value3));
495 Value* value4; 515 Value* value4;
496 ASSERT_TRUE(dict.GetWithoutPathExpansion(L"this.isnt.expanded", &value4)); 516 ASSERT_TRUE(dict.GetWithoutPathExpansion(L"this.isnt.expanded", &value4));
497 EXPECT_EQ(Value::TYPE_NULL, value4->GetType()); 517 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
498 } 518 }
499 519
500 TEST(ValuesTest, DeepCopy) { 520 TEST_F(ValuesTest, DeepCopy) {
501 DictionaryValue original_dict; 521 DictionaryValue original_dict;
502 Value* original_null = Value::CreateNullValue(); 522 Value* original_null = Value::CreateNullValue();
503 original_dict.Set("null", original_null); 523 original_dict.Set("null", original_null);
504 Value* original_bool = Value::CreateBooleanValue(true); 524 Value* original_bool = Value::CreateBooleanValue(true);
505 original_dict.Set("bool", original_bool); 525 original_dict.Set("bool", original_bool);
506 Value* original_int = Value::CreateIntegerValue(42); 526 Value* original_int = Value::CreateIntegerValue(42);
507 original_dict.Set("int", original_int); 527 original_dict.Set("int", original_int);
508 Value* original_real = Value::CreateRealValue(3.14); 528 Value* original_real = Value::CreateRealValue(3.14);
509 original_dict.Set("real", original_real); 529 original_dict.Set("real", original_real);
510 Value* original_string = Value::CreateStringValue("hello"); 530 Value* original_string = Value::CreateStringValue("hello");
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 Value* copy_list_element_1; 636 Value* copy_list_element_1;
617 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1)); 637 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
618 ASSERT_TRUE(copy_list_element_1); 638 ASSERT_TRUE(copy_list_element_1);
619 ASSERT_NE(copy_list_element_1, original_list_element_1); 639 ASSERT_NE(copy_list_element_1, original_list_element_1);
620 int copy_list_element_1_value; 640 int copy_list_element_1_value;
621 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value)); 641 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
622 ASSERT_EQ(1, copy_list_element_1_value); 642 ASSERT_EQ(1, copy_list_element_1_value);
623 } 643 }
624 644
625 // TODO(viettrungluu): deprecate: 645 // TODO(viettrungluu): deprecate:
626 TEST(ValuesTest, DeepCopyDeprecated) { 646 TEST_F(ValuesTest, DeepCopyDeprecated) {
627 DictionaryValue original_dict; 647 DictionaryValue original_dict;
628 Value* original_null = Value::CreateNullValue(); 648 Value* original_null = Value::CreateNullValue();
629 original_dict.Set(L"null", original_null); 649 original_dict.Set(L"null", original_null);
630 Value* original_bool = Value::CreateBooleanValue(true); 650 Value* original_bool = Value::CreateBooleanValue(true);
631 original_dict.Set(L"bool", original_bool); 651 original_dict.Set(L"bool", original_bool);
632 Value* original_int = Value::CreateIntegerValue(42); 652 Value* original_int = Value::CreateIntegerValue(42);
633 original_dict.Set(L"int", original_int); 653 original_dict.Set(L"int", original_int);
634 Value* original_real = Value::CreateRealValue(3.14); 654 Value* original_real = Value::CreateRealValue(3.14);
635 original_dict.Set(L"real", original_real); 655 original_dict.Set(L"real", original_real);
636 Value* original_string = Value::CreateStringValue("hello"); 656 Value* original_string = Value::CreateStringValue("hello");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 780
761 Value* copy_list_element_1; 781 Value* copy_list_element_1;
762 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1)); 782 ASSERT_TRUE(copy_list->Get(1, &copy_list_element_1));
763 ASSERT_TRUE(copy_list_element_1); 783 ASSERT_TRUE(copy_list_element_1);
764 ASSERT_NE(copy_list_element_1, original_list_element_1); 784 ASSERT_NE(copy_list_element_1, original_list_element_1);
765 int copy_list_element_1_value; 785 int copy_list_element_1_value;
766 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value)); 786 ASSERT_TRUE(copy_list_element_1->GetAsInteger(&copy_list_element_1_value));
767 ASSERT_EQ(1, copy_list_element_1_value); 787 ASSERT_EQ(1, copy_list_element_1_value);
768 } 788 }
769 789
770 TEST(ValuesTest, Equals) { 790 TEST_F(ValuesTest, Equals) {
771 Value* null1 = Value::CreateNullValue(); 791 Value* null1 = Value::CreateNullValue();
772 Value* null2 = Value::CreateNullValue(); 792 Value* null2 = Value::CreateNullValue();
773 EXPECT_NE(null1, null2); 793 EXPECT_NE(null1, null2);
774 EXPECT_TRUE(null1->Equals(null2)); 794 EXPECT_TRUE(null1->Equals(null2));
775 795
776 Value* boolean = Value::CreateBooleanValue(false); 796 Value* boolean = Value::CreateBooleanValue(false);
777 EXPECT_FALSE(null1->Equals(boolean)); 797 EXPECT_FALSE(null1->Equals(boolean));
778 delete null1; 798 delete null1;
779 delete null2; 799 delete null2;
780 delete boolean; 800 delete boolean;
(...skipping 17 matching lines...) Expand all
798 EXPECT_FALSE(dv.Equals(copy)); 818 EXPECT_FALSE(dv.Equals(copy));
799 copy->Set("f", list->DeepCopy()); 819 copy->Set("f", list->DeepCopy());
800 EXPECT_TRUE(dv.Equals(copy)); 820 EXPECT_TRUE(dv.Equals(copy));
801 821
802 list->Append(Value::CreateBooleanValue(true)); 822 list->Append(Value::CreateBooleanValue(true));
803 EXPECT_FALSE(dv.Equals(copy)); 823 EXPECT_FALSE(dv.Equals(copy));
804 delete copy; 824 delete copy;
805 } 825 }
806 826
807 // TODO(viettrungluu): deprecate: 827 // TODO(viettrungluu): deprecate:
808 TEST(ValuesTest, EqualsDeprecated) { 828 TEST_F(ValuesTest, EqualsDeprecated) {
809 Value* null1 = Value::CreateNullValue(); 829 Value* null1 = Value::CreateNullValue();
810 Value* null2 = Value::CreateNullValue(); 830 Value* null2 = Value::CreateNullValue();
811 EXPECT_NE(null1, null2); 831 EXPECT_NE(null1, null2);
812 EXPECT_TRUE(null1->Equals(null2)); 832 EXPECT_TRUE(null1->Equals(null2));
813 833
814 Value* boolean = Value::CreateBooleanValue(false); 834 Value* boolean = Value::CreateBooleanValue(false);
815 EXPECT_FALSE(null1->Equals(boolean)); 835 EXPECT_FALSE(null1->Equals(boolean));
816 delete null1; 836 delete null1;
817 delete null2; 837 delete null2;
818 delete boolean; 838 delete boolean;
(...skipping 16 matching lines...) Expand all
835 855
836 EXPECT_FALSE(dv.Equals(copy)); 856 EXPECT_FALSE(dv.Equals(copy));
837 copy->Set(L"f", list->DeepCopy()); 857 copy->Set(L"f", list->DeepCopy());
838 EXPECT_TRUE(dv.Equals(copy)); 858 EXPECT_TRUE(dv.Equals(copy));
839 859
840 list->Append(Value::CreateBooleanValue(true)); 860 list->Append(Value::CreateBooleanValue(true));
841 EXPECT_FALSE(dv.Equals(copy)); 861 EXPECT_FALSE(dv.Equals(copy));
842 delete copy; 862 delete copy;
843 } 863 }
844 864
845 TEST(ValuesTest, RemoveEmptyChildren) { 865 TEST_F(ValuesTest, RemoveEmptyChildren) {
846 scoped_ptr<DictionaryValue> root(new DictionaryValue); 866 scoped_ptr<DictionaryValue> root(new DictionaryValue);
847 // Remove empty lists and dictionaries. 867 // Remove empty lists and dictionaries.
848 root->Set("empty_dict", new DictionaryValue); 868 root->Set("empty_dict", new DictionaryValue);
849 root->Set("empty_list", new ListValue); 869 root->Set("empty_list", new ListValue);
850 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue); 870 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue);
851 root.reset(root->DeepCopyWithoutEmptyChildren()); 871 root.reset(root->DeepCopyWithoutEmptyChildren());
852 EXPECT_TRUE(root->empty()); 872 EXPECT_TRUE(root->empty());
853 873
854 // Make sure we don't prune too much. 874 // Make sure we don't prune too much.
855 root->SetBoolean("bool", true); 875 root->SetBoolean("bool", true);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 root.reset(root->DeepCopyWithoutEmptyChildren()); 931 root.reset(root->DeepCopyWithoutEmptyChildren());
912 EXPECT_EQ(3U, root->size()); 932 EXPECT_EQ(3U, root->size());
913 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner)); 933 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner));
914 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. 934 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
915 EXPECT_TRUE(inner->GetList(0, &inner2)); 935 EXPECT_TRUE(inner->GetList(0, &inner2));
916 EXPECT_EQ(1U, inner2->GetSize()); 936 EXPECT_EQ(1U, inner2->GetSize());
917 } 937 }
918 } 938 }
919 939
920 // TODO(viettrungluu): deprecate: 940 // TODO(viettrungluu): deprecate:
921 TEST(ValuesTest, RemoveEmptyChildrenDeprecated) { 941 TEST_F(ValuesTest, RemoveEmptyChildrenDeprecated) {
922 scoped_ptr<DictionaryValue> root(new DictionaryValue); 942 scoped_ptr<DictionaryValue> root(new DictionaryValue);
923 // Remove empty lists and dictionaries. 943 // Remove empty lists and dictionaries.
924 root->Set(L"empty_dict", new DictionaryValue); 944 root->Set(L"empty_dict", new DictionaryValue);
925 root->Set(L"empty_list", new ListValue); 945 root->Set(L"empty_list", new ListValue);
926 root->SetWithoutPathExpansion(L"a.b.c.d.e", new DictionaryValue); 946 root->SetWithoutPathExpansion(L"a.b.c.d.e", new DictionaryValue);
927 root.reset(root->DeepCopyWithoutEmptyChildren()); 947 root.reset(root->DeepCopyWithoutEmptyChildren());
928 EXPECT_TRUE(root->empty()); 948 EXPECT_TRUE(root->empty());
929 949
930 // Make sure we don't prune too much. 950 // Make sure we don't prune too much.
931 root->SetBoolean(L"bool", true); 951 root->SetBoolean(L"bool", true);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 inner2->Append(Value::CreateStringValue("hello")); 1006 inner2->Append(Value::CreateStringValue("hello"));
987 root.reset(root->DeepCopyWithoutEmptyChildren()); 1007 root.reset(root->DeepCopyWithoutEmptyChildren());
988 EXPECT_EQ(3U, root->size()); 1008 EXPECT_EQ(3U, root->size());
989 EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner)); 1009 EXPECT_TRUE(root->GetList(L"list_with_empty_children", &inner));
990 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. 1010 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned.
991 EXPECT_TRUE(inner->GetList(0, &inner2)); 1011 EXPECT_TRUE(inner->GetList(0, &inner2));
992 EXPECT_EQ(1U, inner2->GetSize()); 1012 EXPECT_EQ(1U, inner2->GetSize());
993 } 1013 }
994 } 1014 }
995 1015
996 TEST(ValuesTest, MergeDictionary) { 1016 TEST_F(ValuesTest, MergeDictionary) {
997 scoped_ptr<DictionaryValue> base(new DictionaryValue); 1017 scoped_ptr<DictionaryValue> base(new DictionaryValue);
998 base->SetString("base_key", "base_key_value_base"); 1018 base->SetString("base_key", "base_key_value_base");
999 base->SetString("collide_key", "collide_key_value_base"); 1019 base->SetString("collide_key", "collide_key_value_base");
1000 DictionaryValue* base_sub_dict = new DictionaryValue; 1020 DictionaryValue* base_sub_dict = new DictionaryValue;
1001 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); 1021 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base");
1002 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); 1022 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base");
1003 base->Set("sub_dict_key", base_sub_dict); 1023 base->Set("sub_dict_key", base_sub_dict);
1004 1024
1005 scoped_ptr<DictionaryValue> merge(new DictionaryValue); 1025 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
1006 merge->SetString("merge_key", "merge_key_value_merge"); 1026 merge->SetString("merge_key", "merge_key_value_merge");
(...skipping 25 matching lines...) Expand all
1032 std::string sub_collide_key_value; 1052 std::string sub_collide_key_value;
1033 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", 1053 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key",
1034 &sub_collide_key_value)); 1054 &sub_collide_key_value));
1035 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. 1055 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
1036 std::string sub_merge_key_value; 1056 std::string sub_merge_key_value;
1037 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); 1057 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value));
1038 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. 1058 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
1039 } 1059 }
1040 1060
1041 // TODO(viettrungluu): deprecate: 1061 // TODO(viettrungluu): deprecate:
1042 TEST(ValuesTest, MergeDictionaryDeprecated) { 1062 TEST_F(ValuesTest, MergeDictionaryDeprecated) {
1043 scoped_ptr<DictionaryValue> base(new DictionaryValue); 1063 scoped_ptr<DictionaryValue> base(new DictionaryValue);
1044 base->SetString(L"base_key", "base_key_value_base"); 1064 base->SetString(L"base_key", "base_key_value_base");
1045 base->SetString(L"collide_key", "collide_key_value_base"); 1065 base->SetString(L"collide_key", "collide_key_value_base");
1046 DictionaryValue* base_sub_dict = new DictionaryValue; 1066 DictionaryValue* base_sub_dict = new DictionaryValue;
1047 base_sub_dict->SetString(L"sub_base_key", "sub_base_key_value_base"); 1067 base_sub_dict->SetString(L"sub_base_key", "sub_base_key_value_base");
1048 base_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_base"); 1068 base_sub_dict->SetString(L"sub_collide_key", "sub_collide_key_value_base");
1049 base->Set(L"sub_dict_key", base_sub_dict); 1069 base->Set(L"sub_dict_key", base_sub_dict);
1050 1070
1051 scoped_ptr<DictionaryValue> merge(new DictionaryValue); 1071 scoped_ptr<DictionaryValue> merge(new DictionaryValue);
1052 merge->SetString(L"merge_key", "merge_key_value_merge"); 1072 merge->SetString(L"merge_key", "merge_key_value_merge");
(...skipping 23 matching lines...) Expand all
1076 EXPECT_TRUE(res_sub_dict->GetString(L"sub_base_key", &sub_base_key_value)); 1096 EXPECT_TRUE(res_sub_dict->GetString(L"sub_base_key", &sub_base_key_value));
1077 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved. 1097 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved.
1078 std::string sub_collide_key_value; 1098 std::string sub_collide_key_value;
1079 EXPECT_TRUE(res_sub_dict->GetString(L"sub_collide_key", 1099 EXPECT_TRUE(res_sub_dict->GetString(L"sub_collide_key",
1080 &sub_collide_key_value)); 1100 &sub_collide_key_value));
1081 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. 1101 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced.
1082 std::string sub_merge_key_value; 1102 std::string sub_merge_key_value;
1083 EXPECT_TRUE(res_sub_dict->GetString(L"sub_merge_key", &sub_merge_key_value)); 1103 EXPECT_TRUE(res_sub_dict->GetString(L"sub_merge_key", &sub_merge_key_value));
1084 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. 1104 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in.
1085 } 1105 }
1106
1107 TEST_F(ValuesTest, GetDifferingPaths) {
1108 scoped_ptr<DictionaryValue> dict1(new DictionaryValue());
1109 scoped_ptr<DictionaryValue> dict2(new DictionaryValue());
1110 std::vector<std::string> differing_paths;
1111
1112 // Test comparing empty dictionaries.
1113 dict1->GetDifferingPaths(dict2.get(), &differing_paths);
1114 EXPECT_EQ(differing_paths.size(), 0UL);
1115
1116 // Compare an empty dictionary with various non-empty dictionaries.
1117 static const char* expected_paths1[] = {
1118 "segment1"
1119 };
1120 dict1->SetString("segment1", "value1");
1121 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths1,
1122 arraysize(expected_paths1));
1123
1124 static const char* expected_paths2[] = {
1125 "segment1",
1126 "segment2",
1127 "segment2.segment3"
1128 };
1129 dict1->SetString("segment2.segment3", "value2");
1130 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths2,
1131 arraysize(expected_paths2));
1132
1133 static const char* expected_paths3[] = {
1134 "segment1",
1135 "segment2",
1136 "segment2.segment3",
1137 "segment4",
1138 "segment4.segment5"
1139 };
1140 dict1->SetString("segment4.segment5", "value3");
1141 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths3,
1142 arraysize(expected_paths3));
1143
1144 // Now various tests with two populated dictionaries.
1145 static const char* expected_paths4[] = {
1146 "segment1",
1147 "segment2",
1148 "segment2.segment3",
1149 "segment4",
1150 "segment4.segment5"
1151 };
1152 dict2->Set("segment2", new DictionaryValue());
1153 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths4,
1154 arraysize(expected_paths4));
1155
1156 static const char* expected_paths5[] = {
1157 "segment1",
1158 "segment4",
1159 "segment4.segment5"
1160 };
1161 dict2->SetString("segment2.segment3", "value2");
1162 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths5,
1163 arraysize(expected_paths5));
1164
1165 dict2->SetBoolean("segment2.segment3", true);
1166 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths4,
1167 arraysize(expected_paths4));
1168
1169 // Test two identical dictionaries.
1170 dict2.reset(static_cast<DictionaryValue*>(dict1->DeepCopy()));
1171 dict2->GetDifferingPaths(dict1.get(), &differing_paths);
1172 EXPECT_EQ(differing_paths.size(), 0UL);
1173
1174 // Test a deep dictionary structure.
1175 static const char* expected_paths6[] = {
1176 "s1",
1177 "s1.s2",
1178 "s1.s2.s3",
1179 "s1.s2.s3.s4",
1180 "s1.s2.s3.s4.s5"
1181 };
1182 dict1.reset(new DictionaryValue());
1183 dict2.reset(new DictionaryValue());
1184 dict1->Set("s1.s2.s3.s4.s5", new DictionaryValue());
1185 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths6,
1186 arraysize(expected_paths6));
1187
1188 // Make sure disjoint dictionaries generate the right differing path list.
1189 static const char* expected_paths7[] = {
1190 "a",
1191 "b",
1192 "c",
1193 "d"
1194 };
1195 dict1.reset(new DictionaryValue());
1196 dict1->SetBoolean("a", true);
1197 dict1->SetBoolean("c", true);
1198 dict2.reset(new DictionaryValue());
1199 dict1->SetBoolean("b", true);
1200 dict1->SetBoolean("d", true);
1201 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths7,
1202 arraysize(expected_paths7));
1203
1204 // For code coverage completeness. Make sure that all branches
1205 // that were not covered are executed.
1206 static const char* expected_paths8[] = {
1207 "s1",
1208 "s1.s2"
1209 };
1210 dict1.reset(new DictionaryValue());
1211 dict1->Set("s1.s2", new DictionaryValue());
1212 dict2.reset(new DictionaryValue());
1213 dict2->SetInteger("s1", 1);
1214 CompareDictionariesAndCheckResult(dict1.get(), dict2.get(), expected_paths8,
1215 arraysize(expected_paths8));
1216 }
OLDNEW
« no previous file with comments | « base/values.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698