OLD | NEW |
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" | 5 #include "base/values.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 ASSERT_NE(mixed_list->end(), mixed_list->Find(sought_value)); | 435 ASSERT_NE(mixed_list->end(), mixed_list->Find(sought_value)); |
436 ASSERT_TRUE((*mixed_list->Find(sought_value)).GetAsInteger(&int_value)); | 436 ASSERT_TRUE((*mixed_list->Find(sought_value)).GetAsInteger(&int_value)); |
437 ASSERT_EQ(42, int_value); | 437 ASSERT_EQ(42, int_value); |
438 ASSERT_EQ(mixed_list->end(), mixed_list->Find(not_found_value)); | 438 ASSERT_EQ(mixed_list->end(), mixed_list->Find(not_found_value)); |
439 } | 439 } |
440 | 440 |
441 TEST(ValuesTest, BinaryValue) { | 441 TEST(ValuesTest, BinaryValue) { |
442 // Default constructor creates a BinaryValue with a buffer of size 0. | 442 // Default constructor creates a BinaryValue with a buffer of size 0. |
443 auto binary = MakeUnique<Value>(Value::Type::BINARY); | 443 auto binary = MakeUnique<Value>(Value::Type::BINARY); |
444 ASSERT_TRUE(binary.get()); | 444 ASSERT_TRUE(binary.get()); |
445 ASSERT_EQ(0U, binary->GetSize()); | 445 ASSERT_TRUE(binary->GetBlob().empty()); |
446 | 446 |
447 // Test the common case of a non-empty buffer | 447 // Test the common case of a non-empty buffer |
448 Value::BlobStorage buffer(15); | 448 Value::BlobStorage buffer(15); |
449 char* original_buffer = buffer.data(); | 449 char* original_buffer = buffer.data(); |
450 binary.reset(new Value(std::move(buffer))); | 450 binary.reset(new Value(std::move(buffer))); |
451 ASSERT_TRUE(binary.get()); | 451 ASSERT_TRUE(binary.get()); |
452 ASSERT_TRUE(binary->GetBuffer()); | 452 ASSERT_TRUE(binary->GetBlob().data()); |
453 ASSERT_EQ(original_buffer, binary->GetBuffer()); | 453 ASSERT_EQ(original_buffer, binary->GetBlob().data()); |
454 ASSERT_EQ(15U, binary->GetSize()); | 454 ASSERT_EQ(15U, binary->GetBlob().size()); |
455 | 455 |
456 char stack_buffer[42]; | 456 char stack_buffer[42]; |
457 memset(stack_buffer, '!', 42); | 457 memset(stack_buffer, '!', 42); |
458 binary = Value::CreateWithCopiedBuffer(stack_buffer, 42); | 458 binary = Value::CreateWithCopiedBuffer(stack_buffer, 42); |
459 ASSERT_TRUE(binary.get()); | 459 ASSERT_TRUE(binary.get()); |
460 ASSERT_TRUE(binary->GetBuffer()); | 460 ASSERT_TRUE(binary->GetBlob().data()); |
461 ASSERT_NE(stack_buffer, binary->GetBuffer()); | 461 ASSERT_NE(stack_buffer, binary->GetBlob().data()); |
462 ASSERT_EQ(42U, binary->GetSize()); | 462 ASSERT_EQ(42U, binary->GetBlob().size()); |
463 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBuffer(), binary->GetSize())); | 463 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBlob().data(), |
| 464 binary->GetBlob().size())); |
464 | 465 |
465 // Test overloaded GetAsBinary. | 466 // Test overloaded GetAsBinary. |
466 Value* narrow_value = binary.get(); | 467 Value* narrow_value = binary.get(); |
467 const Value* narrow_binary = NULL; | 468 const Value* narrow_binary = NULL; |
468 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); | 469 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); |
469 EXPECT_EQ(binary.get(), narrow_binary); | 470 EXPECT_EQ(binary.get(), narrow_binary); |
470 } | 471 } |
471 | 472 |
472 TEST(ValuesTest, StringValue) { | 473 TEST(ValuesTest, StringValue) { |
473 // Test overloaded StringValue constructor. | 474 // Test overloaded StringValue constructor. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 ASSERT_TRUE(copy_string16->GetAsString(©_string_value)); | 748 ASSERT_TRUE(copy_string16->GetAsString(©_string_value)); |
748 ASSERT_TRUE(copy_string16->GetAsString(©_string16_value)); | 749 ASSERT_TRUE(copy_string16->GetAsString(©_string16_value)); |
749 ASSERT_EQ(std::string("hello16"), copy_string_value); | 750 ASSERT_EQ(std::string("hello16"), copy_string_value); |
750 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value); | 751 ASSERT_EQ(ASCIIToUTF16("hello16"), copy_string16_value); |
751 | 752 |
752 Value* copy_binary = NULL; | 753 Value* copy_binary = NULL; |
753 ASSERT_TRUE(copy_dict->Get("binary", ©_binary)); | 754 ASSERT_TRUE(copy_dict->Get("binary", ©_binary)); |
754 ASSERT_TRUE(copy_binary); | 755 ASSERT_TRUE(copy_binary); |
755 ASSERT_NE(copy_binary, original_binary); | 756 ASSERT_NE(copy_binary, original_binary); |
756 ASSERT_TRUE(copy_binary->IsType(Value::Type::BINARY)); | 757 ASSERT_TRUE(copy_binary->IsType(Value::Type::BINARY)); |
757 ASSERT_NE(original_binary->GetBuffer(), copy_binary->GetBuffer()); | 758 ASSERT_NE(original_binary->GetBlob().data(), copy_binary->GetBlob().data()); |
758 ASSERT_EQ(original_binary->GetSize(), copy_binary->GetSize()); | 759 ASSERT_EQ(original_binary->GetBlob(), copy_binary->GetBlob()); |
759 ASSERT_EQ(0, memcmp(original_binary->GetBuffer(), copy_binary->GetBuffer(), | |
760 original_binary->GetSize())); | |
761 | 760 |
762 Value* copy_value = NULL; | 761 Value* copy_value = NULL; |
763 ASSERT_TRUE(copy_dict->Get("list", ©_value)); | 762 ASSERT_TRUE(copy_dict->Get("list", ©_value)); |
764 ASSERT_TRUE(copy_value); | 763 ASSERT_TRUE(copy_value); |
765 ASSERT_NE(copy_value, original_list); | 764 ASSERT_NE(copy_value, original_list); |
766 ASSERT_TRUE(copy_value->IsType(Value::Type::LIST)); | 765 ASSERT_TRUE(copy_value->IsType(Value::Type::LIST)); |
767 ListValue* copy_list = NULL; | 766 ListValue* copy_list = NULL; |
768 ASSERT_TRUE(copy_value->GetAsList(©_list)); | 767 ASSERT_TRUE(copy_value->GetAsList(©_list)); |
769 ASSERT_TRUE(copy_list); | 768 ASSERT_TRUE(copy_list); |
770 ASSERT_EQ(2U, copy_list->GetSize()); | 769 ASSERT_EQ(2U, copy_list->GetSize()); |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1512 EXPECT_FALSE(main_list.GetList(7, NULL)); |
1514 } | 1513 } |
1515 | 1514 |
1516 TEST(ValuesTest, SelfSwap) { | 1515 TEST(ValuesTest, SelfSwap) { |
1517 base::Value test(1); | 1516 base::Value test(1); |
1518 std::swap(test, test); | 1517 std::swap(test, test); |
1519 EXPECT_TRUE(test.GetInt() == 1); | 1518 EXPECT_TRUE(test.GetInt() == 1); |
1520 } | 1519 } |
1521 | 1520 |
1522 } // namespace base | 1521 } // namespace base |
OLD | NEW |