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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->GetBlob().data()); | 460 ASSERT_TRUE(binary->GetBlob().data()); |
461 ASSERT_NE(stack_buffer, binary->GetBlob().data()); | 461 ASSERT_NE(stack_buffer, binary->GetBlob().data()); |
462 ASSERT_EQ(42U, binary->GetBlob().size()); | 462 ASSERT_EQ(42U, binary->GetBlob().size()); |
463 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBlob().data(), | 463 ASSERT_EQ(0, memcmp(stack_buffer, binary->GetBlob().data(), |
464 binary->GetBlob().size())); | 464 binary->GetBlob().size())); |
465 | |
466 // Test overloaded GetAsBinary. | |
467 Value* narrow_value = binary.get(); | |
468 const Value* narrow_binary = NULL; | |
469 ASSERT_TRUE(narrow_value->GetAsBinary(&narrow_binary)); | |
470 EXPECT_EQ(binary.get(), narrow_binary); | |
471 } | 465 } |
472 | 466 |
473 TEST(ValuesTest, StringValue) { | 467 TEST(ValuesTest, StringValue) { |
474 // Test overloaded StringValue constructor. | 468 // Test overloaded StringValue constructor. |
475 std::unique_ptr<Value> narrow_value(new Value("narrow")); | 469 std::unique_ptr<Value> narrow_value(new Value("narrow")); |
476 ASSERT_TRUE(narrow_value.get()); | 470 ASSERT_TRUE(narrow_value.get()); |
477 ASSERT_TRUE(narrow_value->IsType(Value::Type::STRING)); | 471 ASSERT_TRUE(narrow_value->IsType(Value::Type::STRING)); |
478 std::unique_ptr<Value> utf16_value(new Value(ASCIIToUTF16("utf16"))); | 472 std::unique_ptr<Value> utf16_value(new Value(ASCIIToUTF16("utf16"))); |
479 ASSERT_TRUE(utf16_value.get()); | 473 ASSERT_TRUE(utf16_value.get()); |
480 ASSERT_TRUE(utf16_value->IsType(Value::Type::STRING)); | 474 ASSERT_TRUE(utf16_value->IsType(Value::Type::STRING)); |
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 EXPECT_FALSE(main_list.GetList(7, NULL)); | 1506 EXPECT_FALSE(main_list.GetList(7, NULL)); |
1513 } | 1507 } |
1514 | 1508 |
1515 TEST(ValuesTest, SelfSwap) { | 1509 TEST(ValuesTest, SelfSwap) { |
1516 base::Value test(1); | 1510 base::Value test(1); |
1517 std::swap(test, test); | 1511 std::swap(test, test); |
1518 EXPECT_TRUE(test.GetInt() == 1); | 1512 EXPECT_TRUE(test.GetInt() == 1); |
1519 } | 1513 } |
1520 | 1514 |
1521 } // namespace base | 1515 } // namespace base |
OLD | NEW |