OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 class ValuesTest : public testing::Test { | 13 namespace base { |
14 }; | |
15 | 14 |
16 TEST_F(ValuesTest, Basic) { | 15 TEST(ValuesTest, Basic) { |
17 // Test basic dictionary getting/setting | 16 // Test basic dictionary getting/setting |
18 DictionaryValue settings; | 17 DictionaryValue settings; |
19 std::string homepage = "http://google.com"; | 18 std::string homepage = "http://google.com"; |
20 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); | 19 ASSERT_FALSE(settings.GetString("global.homepage", &homepage)); |
21 ASSERT_EQ(std::string("http://google.com"), homepage); | 20 ASSERT_EQ(std::string("http://google.com"), homepage); |
22 | 21 |
23 ASSERT_FALSE(settings.Get("global", NULL)); | 22 ASSERT_FALSE(settings.Get("global", NULL)); |
24 settings.Set("global", Value::CreateBooleanValue(true)); | 23 settings.Set("global", Value::CreateBooleanValue(true)); |
25 ASSERT_TRUE(settings.Get("global", NULL)); | 24 ASSERT_TRUE(settings.Get("global", NULL)); |
26 settings.SetString("global.homepage", "http://scurvy.com"); | 25 settings.SetString("global.homepage", "http://scurvy.com"); |
(...skipping 22 matching lines...) Expand all Loading... |
49 ASSERT_EQ(1U, bookmark_list->GetSize()); | 48 ASSERT_EQ(1U, bookmark_list->GetSize()); |
50 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); | 49 ASSERT_TRUE(bookmark_list->GetDictionary(0, &bookmark)); |
51 std::string bookmark_name = "Unnamed"; | 50 std::string bookmark_name = "Unnamed"; |
52 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); | 51 ASSERT_TRUE(bookmark->GetString("name", &bookmark_name)); |
53 ASSERT_EQ(std::string("Froogle"), bookmark_name); | 52 ASSERT_EQ(std::string("Froogle"), bookmark_name); |
54 std::string bookmark_url; | 53 std::string bookmark_url; |
55 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url)); | 54 ASSERT_TRUE(bookmark->GetString("url", &bookmark_url)); |
56 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); | 55 ASSERT_EQ(std::string("http://froogle.com"), bookmark_url); |
57 } | 56 } |
58 | 57 |
59 TEST_F(ValuesTest, List) { | 58 TEST(ValuesTest, List) { |
60 scoped_ptr<ListValue> mixed_list(new ListValue()); | 59 scoped_ptr<ListValue> mixed_list(new ListValue()); |
61 mixed_list->Set(0, Value::CreateBooleanValue(true)); | 60 mixed_list->Set(0, Value::CreateBooleanValue(true)); |
62 mixed_list->Set(1, Value::CreateIntegerValue(42)); | 61 mixed_list->Set(1, Value::CreateIntegerValue(42)); |
63 mixed_list->Set(2, Value::CreateDoubleValue(88.8)); | 62 mixed_list->Set(2, Value::CreateDoubleValue(88.8)); |
64 mixed_list->Set(3, Value::CreateStringValue("foo")); | 63 mixed_list->Set(3, Value::CreateStringValue("foo")); |
65 ASSERT_EQ(4u, mixed_list->GetSize()); | 64 ASSERT_EQ(4u, mixed_list->GetSize()); |
66 | 65 |
67 Value *value = NULL; | 66 Value *value = NULL; |
68 bool bool_value = false; | 67 bool bool_value = false; |
69 int int_value = 0; | 68 int int_value = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
89 ASSERT_EQ(42, int_value); | 88 ASSERT_EQ(42, int_value); |
90 // implicit conversion from Integer to Double should be possible. | 89 // implicit conversion from Integer to Double should be possible. |
91 ASSERT_TRUE(mixed_list->GetDouble(1, &double_value)); | 90 ASSERT_TRUE(mixed_list->GetDouble(1, &double_value)); |
92 ASSERT_EQ(42, double_value); | 91 ASSERT_EQ(42, double_value); |
93 ASSERT_TRUE(mixed_list->GetDouble(2, &double_value)); | 92 ASSERT_TRUE(mixed_list->GetDouble(2, &double_value)); |
94 ASSERT_EQ(88.8, double_value); | 93 ASSERT_EQ(88.8, double_value); |
95 ASSERT_TRUE(mixed_list->GetString(3, &string_value)); | 94 ASSERT_TRUE(mixed_list->GetString(3, &string_value)); |
96 ASSERT_EQ("foo", string_value); | 95 ASSERT_EQ("foo", string_value); |
97 } | 96 } |
98 | 97 |
99 TEST_F(ValuesTest, BinaryValue) { | 98 TEST(ValuesTest, BinaryValue) { |
100 char* buffer = NULL; | 99 char* buffer = NULL; |
101 // Passing a null buffer pointer doesn't yield a BinaryValue | 100 // Passing a null buffer pointer doesn't yield a BinaryValue |
102 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0)); | 101 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0)); |
103 ASSERT_FALSE(binary.get()); | 102 ASSERT_FALSE(binary.get()); |
104 | 103 |
105 // If you want to represent an empty binary value, use a zero-length buffer. | 104 // If you want to represent an empty binary value, use a zero-length buffer. |
106 buffer = new char[1]; | 105 buffer = new char[1]; |
107 ASSERT_TRUE(buffer); | 106 ASSERT_TRUE(buffer); |
108 binary.reset(BinaryValue::Create(buffer, 0)); | 107 binary.reset(BinaryValue::Create(buffer, 0)); |
109 ASSERT_TRUE(binary.get()); | 108 ASSERT_TRUE(binary.get()); |
(...skipping 12 matching lines...) Expand all Loading... |
122 char stack_buffer[42]; | 121 char stack_buffer[42]; |
123 memset(stack_buffer, '!', 42); | 122 memset(stack_buffer, '!', 42); |
124 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); | 123 binary.reset(BinaryValue::CreateWithCopiedBuffer(stack_buffer, 42)); |
125 ASSERT_TRUE(binary.get()); | 124 ASSERT_TRUE(binary.get()); |
126 ASSERT_TRUE(binary->GetBuffer()); | 125 ASSERT_TRUE(binary->GetBuffer()); |
127 ASSERT_NE(stack_buffer, binary->GetBuffer()); | 126 ASSERT_NE(stack_buffer, binary->GetBuffer()); |
128 ASSERT_EQ(42U, binary->GetSize()); | 127 ASSERT_EQ(42U, binary->GetSize()); |
129 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); | 128 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); |
130 } | 129 } |
131 | 130 |
132 TEST_F(ValuesTest, StringValue) { | 131 TEST(ValuesTest, StringValue) { |
133 // Test overloaded CreateStringValue. | 132 // Test overloaded CreateStringValue. |
134 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); | 133 scoped_ptr<Value> narrow_value(Value::CreateStringValue("narrow")); |
135 ASSERT_TRUE(narrow_value.get()); | 134 ASSERT_TRUE(narrow_value.get()); |
136 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); | 135 ASSERT_TRUE(narrow_value->IsType(Value::TYPE_STRING)); |
137 scoped_ptr<Value> utf16_value( | 136 scoped_ptr<Value> utf16_value( |
138 Value::CreateStringValue(ASCIIToUTF16("utf16"))); | 137 Value::CreateStringValue(ASCIIToUTF16("utf16"))); |
139 ASSERT_TRUE(utf16_value.get()); | 138 ASSERT_TRUE(utf16_value.get()); |
140 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); | 139 ASSERT_TRUE(utf16_value->IsType(Value::TYPE_STRING)); |
141 | 140 |
142 // Test overloaded GetString. | 141 // Test overloaded GetString. |
(...skipping 25 matching lines...) Expand all Loading... |
168 } | 167 } |
169 | 168 |
170 ~DeletionTestValue() { | 169 ~DeletionTestValue() { |
171 *deletion_flag_ = true; | 170 *deletion_flag_ = true; |
172 } | 171 } |
173 | 172 |
174 private: | 173 private: |
175 bool* deletion_flag_; | 174 bool* deletion_flag_; |
176 }; | 175 }; |
177 | 176 |
178 TEST_F(ValuesTest, ListDeletion) { | 177 TEST(ValuesTest, ListDeletion) { |
179 bool deletion_flag = true; | 178 bool deletion_flag = true; |
180 | 179 |
181 { | 180 { |
182 ListValue list; | 181 ListValue list; |
183 list.Append(new DeletionTestValue(&deletion_flag)); | 182 list.Append(new DeletionTestValue(&deletion_flag)); |
184 EXPECT_FALSE(deletion_flag); | 183 EXPECT_FALSE(deletion_flag); |
185 } | 184 } |
186 EXPECT_TRUE(deletion_flag); | 185 EXPECT_TRUE(deletion_flag); |
187 | 186 |
188 { | 187 { |
189 ListValue list; | 188 ListValue list; |
190 list.Append(new DeletionTestValue(&deletion_flag)); | 189 list.Append(new DeletionTestValue(&deletion_flag)); |
191 EXPECT_FALSE(deletion_flag); | 190 EXPECT_FALSE(deletion_flag); |
192 list.Clear(); | 191 list.Clear(); |
193 EXPECT_TRUE(deletion_flag); | 192 EXPECT_TRUE(deletion_flag); |
194 } | 193 } |
195 | 194 |
196 { | 195 { |
197 ListValue list; | 196 ListValue list; |
198 list.Append(new DeletionTestValue(&deletion_flag)); | 197 list.Append(new DeletionTestValue(&deletion_flag)); |
199 EXPECT_FALSE(deletion_flag); | 198 EXPECT_FALSE(deletion_flag); |
200 EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); | 199 EXPECT_TRUE(list.Set(0, Value::CreateNullValue())); |
201 EXPECT_TRUE(deletion_flag); | 200 EXPECT_TRUE(deletion_flag); |
202 } | 201 } |
203 } | 202 } |
204 | 203 |
205 TEST_F(ValuesTest, ListRemoval) { | 204 TEST(ValuesTest, ListRemoval) { |
206 bool deletion_flag = true; | 205 bool deletion_flag = true; |
207 Value* removed_item = NULL; | 206 Value* removed_item = NULL; |
208 | 207 |
209 { | 208 { |
210 ListValue list; | 209 ListValue list; |
211 list.Append(new DeletionTestValue(&deletion_flag)); | 210 list.Append(new DeletionTestValue(&deletion_flag)); |
212 EXPECT_FALSE(deletion_flag); | 211 EXPECT_FALSE(deletion_flag); |
213 EXPECT_EQ(1U, list.GetSize()); | 212 EXPECT_EQ(1U, list.GetSize()); |
214 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), | 213 EXPECT_FALSE(list.Remove(std::numeric_limits<size_t>::max(), |
215 &removed_item)); | 214 &removed_item)); |
(...skipping 20 matching lines...) Expand all Loading... |
236 ListValue list; | 235 ListValue list; |
237 DeletionTestValue* value = new DeletionTestValue(&deletion_flag); | 236 DeletionTestValue* value = new DeletionTestValue(&deletion_flag); |
238 list.Append(value); | 237 list.Append(value); |
239 EXPECT_FALSE(deletion_flag); | 238 EXPECT_FALSE(deletion_flag); |
240 EXPECT_EQ(0, list.Remove(*value)); | 239 EXPECT_EQ(0, list.Remove(*value)); |
241 EXPECT_TRUE(deletion_flag); | 240 EXPECT_TRUE(deletion_flag); |
242 EXPECT_EQ(0U, list.GetSize()); | 241 EXPECT_EQ(0U, list.GetSize()); |
243 } | 242 } |
244 } | 243 } |
245 | 244 |
246 TEST_F(ValuesTest, DictionaryDeletion) { | 245 TEST(ValuesTest, DictionaryDeletion) { |
247 std::string key = "test"; | 246 std::string key = "test"; |
248 bool deletion_flag = true; | 247 bool deletion_flag = true; |
249 | 248 |
250 { | 249 { |
251 DictionaryValue dict; | 250 DictionaryValue dict; |
252 dict.Set(key, new DeletionTestValue(&deletion_flag)); | 251 dict.Set(key, new DeletionTestValue(&deletion_flag)); |
253 EXPECT_FALSE(deletion_flag); | 252 EXPECT_FALSE(deletion_flag); |
254 } | 253 } |
255 EXPECT_TRUE(deletion_flag); | 254 EXPECT_TRUE(deletion_flag); |
256 | 255 |
257 { | 256 { |
258 DictionaryValue dict; | 257 DictionaryValue dict; |
259 dict.Set(key, new DeletionTestValue(&deletion_flag)); | 258 dict.Set(key, new DeletionTestValue(&deletion_flag)); |
260 EXPECT_FALSE(deletion_flag); | 259 EXPECT_FALSE(deletion_flag); |
261 dict.Clear(); | 260 dict.Clear(); |
262 EXPECT_TRUE(deletion_flag); | 261 EXPECT_TRUE(deletion_flag); |
263 } | 262 } |
264 | 263 |
265 { | 264 { |
266 DictionaryValue dict; | 265 DictionaryValue dict; |
267 dict.Set(key, new DeletionTestValue(&deletion_flag)); | 266 dict.Set(key, new DeletionTestValue(&deletion_flag)); |
268 EXPECT_FALSE(deletion_flag); | 267 EXPECT_FALSE(deletion_flag); |
269 dict.Set(key, Value::CreateNullValue()); | 268 dict.Set(key, Value::CreateNullValue()); |
270 EXPECT_TRUE(deletion_flag); | 269 EXPECT_TRUE(deletion_flag); |
271 } | 270 } |
272 } | 271 } |
273 | 272 |
274 TEST_F(ValuesTest, DictionaryRemoval) { | 273 TEST(ValuesTest, DictionaryRemoval) { |
275 std::string key = "test"; | 274 std::string key = "test"; |
276 bool deletion_flag = true; | 275 bool deletion_flag = true; |
277 Value* removed_item = NULL; | 276 Value* removed_item = NULL; |
278 | 277 |
279 { | 278 { |
280 DictionaryValue dict; | 279 DictionaryValue dict; |
281 dict.Set(key, new DeletionTestValue(&deletion_flag)); | 280 dict.Set(key, new DeletionTestValue(&deletion_flag)); |
282 EXPECT_FALSE(deletion_flag); | 281 EXPECT_FALSE(deletion_flag); |
283 EXPECT_TRUE(dict.HasKey(key)); | 282 EXPECT_TRUE(dict.HasKey(key)); |
284 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); | 283 EXPECT_FALSE(dict.Remove("absent key", &removed_item)); |
(...skipping 10 matching lines...) Expand all Loading... |
295 DictionaryValue dict; | 294 DictionaryValue dict; |
296 dict.Set(key, new DeletionTestValue(&deletion_flag)); | 295 dict.Set(key, new DeletionTestValue(&deletion_flag)); |
297 EXPECT_FALSE(deletion_flag); | 296 EXPECT_FALSE(deletion_flag); |
298 EXPECT_TRUE(dict.HasKey(key)); | 297 EXPECT_TRUE(dict.HasKey(key)); |
299 EXPECT_TRUE(dict.Remove(key, NULL)); | 298 EXPECT_TRUE(dict.Remove(key, NULL)); |
300 EXPECT_TRUE(deletion_flag); | 299 EXPECT_TRUE(deletion_flag); |
301 EXPECT_FALSE(dict.HasKey(key)); | 300 EXPECT_FALSE(dict.HasKey(key)); |
302 } | 301 } |
303 } | 302 } |
304 | 303 |
305 TEST_F(ValuesTest, DictionaryWithoutPathExpansion) { | 304 TEST(ValuesTest, DictionaryWithoutPathExpansion) { |
306 DictionaryValue dict; | 305 DictionaryValue dict; |
307 dict.Set("this.is.expanded", Value::CreateNullValue()); | 306 dict.Set("this.is.expanded", Value::CreateNullValue()); |
308 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue()); | 307 dict.SetWithoutPathExpansion("this.isnt.expanded", Value::CreateNullValue()); |
309 | 308 |
310 EXPECT_FALSE(dict.HasKey("this.is.expanded")); | 309 EXPECT_FALSE(dict.HasKey("this.is.expanded")); |
311 EXPECT_TRUE(dict.HasKey("this")); | 310 EXPECT_TRUE(dict.HasKey("this")); |
312 Value* value1; | 311 Value* value1; |
313 EXPECT_TRUE(dict.Get("this", &value1)); | 312 EXPECT_TRUE(dict.Get("this", &value1)); |
314 DictionaryValue* value2; | 313 DictionaryValue* value2; |
315 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2)); | 314 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion("this", &value2)); |
316 EXPECT_EQ(value1, value2); | 315 EXPECT_EQ(value1, value2); |
317 EXPECT_EQ(1U, value2->size()); | 316 EXPECT_EQ(1U, value2->size()); |
318 | 317 |
319 EXPECT_TRUE(dict.HasKey("this.isnt.expanded")); | 318 EXPECT_TRUE(dict.HasKey("this.isnt.expanded")); |
320 Value* value3; | 319 Value* value3; |
321 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3)); | 320 EXPECT_FALSE(dict.Get("this.isnt.expanded", &value3)); |
322 Value* value4; | 321 Value* value4; |
323 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4)); | 322 ASSERT_TRUE(dict.GetWithoutPathExpansion("this.isnt.expanded", &value4)); |
324 EXPECT_EQ(Value::TYPE_NULL, value4->GetType()); | 323 EXPECT_EQ(Value::TYPE_NULL, value4->GetType()); |
325 } | 324 } |
326 | 325 |
327 TEST_F(ValuesTest, DeepCopy) { | 326 TEST(ValuesTest, DeepCopy) { |
328 DictionaryValue original_dict; | 327 DictionaryValue original_dict; |
329 Value* original_null = Value::CreateNullValue(); | 328 Value* original_null = Value::CreateNullValue(); |
330 original_dict.Set("null", original_null); | 329 original_dict.Set("null", original_null); |
331 FundamentalValue* original_bool = Value::CreateBooleanValue(true); | 330 FundamentalValue* original_bool = Value::CreateBooleanValue(true); |
332 original_dict.Set("bool", original_bool); | 331 original_dict.Set("bool", original_bool); |
333 FundamentalValue* original_int = Value::CreateIntegerValue(42); | 332 FundamentalValue* original_int = Value::CreateIntegerValue(42); |
334 original_dict.Set("int", original_int); | 333 original_dict.Set("int", original_int); |
335 FundamentalValue* original_double = Value::CreateDoubleValue(3.14); | 334 FundamentalValue* original_double = Value::CreateDoubleValue(3.14); |
336 original_dict.Set("double", original_double); | 335 original_dict.Set("double", original_double); |
337 StringValue* original_string = Value::CreateStringValue("hello"); | 336 StringValue* original_string = Value::CreateStringValue("hello"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 441 |
443 Value* copy_list_element_1; | 442 Value* copy_list_element_1; |
444 ASSERT_TRUE(copy_list->Get(1, ©_list_element_1)); | 443 ASSERT_TRUE(copy_list->Get(1, ©_list_element_1)); |
445 ASSERT_TRUE(copy_list_element_1); | 444 ASSERT_TRUE(copy_list_element_1); |
446 ASSERT_NE(copy_list_element_1, original_list_element_1); | 445 ASSERT_NE(copy_list_element_1, original_list_element_1); |
447 int copy_list_element_1_value; | 446 int copy_list_element_1_value; |
448 ASSERT_TRUE(copy_list_element_1->GetAsInteger(©_list_element_1_value)); | 447 ASSERT_TRUE(copy_list_element_1->GetAsInteger(©_list_element_1_value)); |
449 ASSERT_EQ(1, copy_list_element_1_value); | 448 ASSERT_EQ(1, copy_list_element_1_value); |
450 } | 449 } |
451 | 450 |
452 TEST_F(ValuesTest, Equals) { | 451 TEST(ValuesTest, Equals) { |
453 Value* null1 = Value::CreateNullValue(); | 452 Value* null1 = Value::CreateNullValue(); |
454 Value* null2 = Value::CreateNullValue(); | 453 Value* null2 = Value::CreateNullValue(); |
455 EXPECT_NE(null1, null2); | 454 EXPECT_NE(null1, null2); |
456 EXPECT_TRUE(null1->Equals(null2)); | 455 EXPECT_TRUE(null1->Equals(null2)); |
457 | 456 |
458 Value* boolean = Value::CreateBooleanValue(false); | 457 Value* boolean = Value::CreateBooleanValue(false); |
459 EXPECT_FALSE(null1->Equals(boolean)); | 458 EXPECT_FALSE(null1->Equals(boolean)); |
460 delete null1; | 459 delete null1; |
461 delete null2; | 460 delete null2; |
462 delete boolean; | 461 delete boolean; |
(...skipping 23 matching lines...) Expand all Loading... |
486 EXPECT_FALSE(dv.Equals(copy.get())); | 485 EXPECT_FALSE(dv.Equals(copy.get())); |
487 | 486 |
488 // Check if Equals detects differences in only the keys. | 487 // Check if Equals detects differences in only the keys. |
489 copy.reset(dv.DeepCopy()); | 488 copy.reset(dv.DeepCopy()); |
490 EXPECT_TRUE(dv.Equals(copy.get())); | 489 EXPECT_TRUE(dv.Equals(copy.get())); |
491 copy->Remove("a", NULL); | 490 copy->Remove("a", NULL); |
492 copy->SetBoolean("aa", false); | 491 copy->SetBoolean("aa", false); |
493 EXPECT_FALSE(dv.Equals(copy.get())); | 492 EXPECT_FALSE(dv.Equals(copy.get())); |
494 } | 493 } |
495 | 494 |
496 TEST_F(ValuesTest, StaticEquals) { | 495 TEST(ValuesTest, StaticEquals) { |
497 scoped_ptr<Value> null1(Value::CreateNullValue()); | 496 scoped_ptr<Value> null1(Value::CreateNullValue()); |
498 scoped_ptr<Value> null2(Value::CreateNullValue()); | 497 scoped_ptr<Value> null2(Value::CreateNullValue()); |
499 EXPECT_TRUE(Value::Equals(null1.get(), null2.get())); | 498 EXPECT_TRUE(Value::Equals(null1.get(), null2.get())); |
500 EXPECT_TRUE(Value::Equals(NULL, NULL)); | 499 EXPECT_TRUE(Value::Equals(NULL, NULL)); |
501 | 500 |
502 scoped_ptr<Value> i42(Value::CreateIntegerValue(42)); | 501 scoped_ptr<Value> i42(Value::CreateIntegerValue(42)); |
503 scoped_ptr<Value> j42(Value::CreateIntegerValue(42)); | 502 scoped_ptr<Value> j42(Value::CreateIntegerValue(42)); |
504 scoped_ptr<Value> i17(Value::CreateIntegerValue(17)); | 503 scoped_ptr<Value> i17(Value::CreateIntegerValue(17)); |
505 EXPECT_TRUE(Value::Equals(i42.get(), i42.get())); | 504 EXPECT_TRUE(Value::Equals(i42.get(), i42.get())); |
506 EXPECT_TRUE(Value::Equals(j42.get(), i42.get())); | 505 EXPECT_TRUE(Value::Equals(j42.get(), i42.get())); |
507 EXPECT_TRUE(Value::Equals(i42.get(), j42.get())); | 506 EXPECT_TRUE(Value::Equals(i42.get(), j42.get())); |
508 EXPECT_FALSE(Value::Equals(i42.get(), i17.get())); | 507 EXPECT_FALSE(Value::Equals(i42.get(), i17.get())); |
509 EXPECT_FALSE(Value::Equals(i42.get(), NULL)); | 508 EXPECT_FALSE(Value::Equals(i42.get(), NULL)); |
510 EXPECT_FALSE(Value::Equals(NULL, i42.get())); | 509 EXPECT_FALSE(Value::Equals(NULL, i42.get())); |
511 | 510 |
512 // NULL and Value::CreateNullValue() are intentionally different: We need | 511 // NULL and Value::CreateNullValue() are intentionally different: We need |
513 // support for NULL as a return value for "undefined" without caring for | 512 // support for NULL as a return value for "undefined" without caring for |
514 // ownership of the pointer. | 513 // ownership of the pointer. |
515 EXPECT_FALSE(Value::Equals(null1.get(), NULL)); | 514 EXPECT_FALSE(Value::Equals(null1.get(), NULL)); |
516 EXPECT_FALSE(Value::Equals(NULL, null1.get())); | 515 EXPECT_FALSE(Value::Equals(NULL, null1.get())); |
517 } | 516 } |
518 | 517 |
519 TEST_F(ValuesTest, DeepCopyCovariantReturnTypes) { | 518 TEST(ValuesTest, DeepCopyCovariantReturnTypes) { |
520 DictionaryValue original_dict; | 519 DictionaryValue original_dict; |
521 Value* original_null = Value::CreateNullValue(); | 520 Value* original_null = Value::CreateNullValue(); |
522 original_dict.Set("null", original_null); | 521 original_dict.Set("null", original_null); |
523 FundamentalValue* original_bool = Value::CreateBooleanValue(true); | 522 FundamentalValue* original_bool = Value::CreateBooleanValue(true); |
524 original_dict.Set("bool", original_bool); | 523 original_dict.Set("bool", original_bool); |
525 FundamentalValue* original_int = Value::CreateIntegerValue(42); | 524 FundamentalValue* original_int = Value::CreateIntegerValue(42); |
526 original_dict.Set("int", original_int); | 525 original_dict.Set("int", original_int); |
527 FundamentalValue* original_double = Value::CreateDoubleValue(3.14); | 526 FundamentalValue* original_double = Value::CreateDoubleValue(3.14); |
528 original_dict.Set("double", original_double); | 527 original_dict.Set("double", original_double); |
529 StringValue* original_string = Value::CreateStringValue("hello"); | 528 StringValue* original_string = Value::CreateStringValue("hello"); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 EXPECT_TRUE(original_dict_value->Equals(copy_dict_value.get())); | 564 EXPECT_TRUE(original_dict_value->Equals(copy_dict_value.get())); |
566 EXPECT_TRUE(original_bool_value->Equals(copy_bool_value.get())); | 565 EXPECT_TRUE(original_bool_value->Equals(copy_bool_value.get())); |
567 EXPECT_TRUE(original_int_value->Equals(copy_int_value.get())); | 566 EXPECT_TRUE(original_int_value->Equals(copy_int_value.get())); |
568 EXPECT_TRUE(original_double_value->Equals(copy_double_value.get())); | 567 EXPECT_TRUE(original_double_value->Equals(copy_double_value.get())); |
569 EXPECT_TRUE(original_string_value->Equals(copy_string_value.get())); | 568 EXPECT_TRUE(original_string_value->Equals(copy_string_value.get())); |
570 EXPECT_TRUE(original_string16_value->Equals(copy_string16_value.get())); | 569 EXPECT_TRUE(original_string16_value->Equals(copy_string16_value.get())); |
571 EXPECT_TRUE(original_binary_value->Equals(copy_binary_value.get())); | 570 EXPECT_TRUE(original_binary_value->Equals(copy_binary_value.get())); |
572 EXPECT_TRUE(original_list_value->Equals(copy_list_value.get())); | 571 EXPECT_TRUE(original_list_value->Equals(copy_list_value.get())); |
573 } | 572 } |
574 | 573 |
575 TEST_F(ValuesTest, RemoveEmptyChildren) { | 574 TEST(ValuesTest, RemoveEmptyChildren) { |
576 scoped_ptr<DictionaryValue> root(new DictionaryValue); | 575 scoped_ptr<DictionaryValue> root(new DictionaryValue); |
577 // Remove empty lists and dictionaries. | 576 // Remove empty lists and dictionaries. |
578 root->Set("empty_dict", new DictionaryValue); | 577 root->Set("empty_dict", new DictionaryValue); |
579 root->Set("empty_list", new ListValue); | 578 root->Set("empty_list", new ListValue); |
580 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue); | 579 root->SetWithoutPathExpansion("a.b.c.d.e", new DictionaryValue); |
581 root.reset(root->DeepCopyWithoutEmptyChildren()); | 580 root.reset(root->DeepCopyWithoutEmptyChildren()); |
582 EXPECT_TRUE(root->empty()); | 581 EXPECT_TRUE(root->empty()); |
583 | 582 |
584 // Make sure we don't prune too much. | 583 // Make sure we don't prune too much. |
585 root->SetBoolean("bool", true); | 584 root->SetBoolean("bool", true); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 inner2->Append(Value::CreateStringValue("hello")); | 639 inner2->Append(Value::CreateStringValue("hello")); |
641 root.reset(root->DeepCopyWithoutEmptyChildren()); | 640 root.reset(root->DeepCopyWithoutEmptyChildren()); |
642 EXPECT_EQ(3U, root->size()); | 641 EXPECT_EQ(3U, root->size()); |
643 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner)); | 642 EXPECT_TRUE(root->GetList("list_with_empty_children", &inner)); |
644 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. | 643 EXPECT_EQ(1U, inner->GetSize()); // Dictionary was pruned. |
645 EXPECT_TRUE(inner->GetList(0, &inner2)); | 644 EXPECT_TRUE(inner->GetList(0, &inner2)); |
646 EXPECT_EQ(1U, inner2->GetSize()); | 645 EXPECT_EQ(1U, inner2->GetSize()); |
647 } | 646 } |
648 } | 647 } |
649 | 648 |
650 TEST_F(ValuesTest, MergeDictionary) { | 649 TEST(ValuesTest, MergeDictionary) { |
651 scoped_ptr<DictionaryValue> base(new DictionaryValue); | 650 scoped_ptr<DictionaryValue> base(new DictionaryValue); |
652 base->SetString("base_key", "base_key_value_base"); | 651 base->SetString("base_key", "base_key_value_base"); |
653 base->SetString("collide_key", "collide_key_value_base"); | 652 base->SetString("collide_key", "collide_key_value_base"); |
654 DictionaryValue* base_sub_dict = new DictionaryValue; | 653 DictionaryValue* base_sub_dict = new DictionaryValue; |
655 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); | 654 base_sub_dict->SetString("sub_base_key", "sub_base_key_value_base"); |
656 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); | 655 base_sub_dict->SetString("sub_collide_key", "sub_collide_key_value_base"); |
657 base->Set("sub_dict_key", base_sub_dict); | 656 base->Set("sub_dict_key", base_sub_dict); |
658 | 657 |
659 scoped_ptr<DictionaryValue> merge(new DictionaryValue); | 658 scoped_ptr<DictionaryValue> merge(new DictionaryValue); |
660 merge->SetString("merge_key", "merge_key_value_merge"); | 659 merge->SetString("merge_key", "merge_key_value_merge"); |
(...skipping 23 matching lines...) Expand all Loading... |
684 EXPECT_TRUE(res_sub_dict->GetString("sub_base_key", &sub_base_key_value)); | 683 EXPECT_TRUE(res_sub_dict->GetString("sub_base_key", &sub_base_key_value)); |
685 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved. | 684 EXPECT_EQ("sub_base_key_value_base", sub_base_key_value); // Preserved. |
686 std::string sub_collide_key_value; | 685 std::string sub_collide_key_value; |
687 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", | 686 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", |
688 &sub_collide_key_value)); | 687 &sub_collide_key_value)); |
689 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. | 688 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. |
690 std::string sub_merge_key_value; | 689 std::string sub_merge_key_value; |
691 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); | 690 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); |
692 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. | 691 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. |
693 } | 692 } |
| 693 |
| 694 } // namespace base |
OLD | NEW |