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" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ASSERT_TRUE(bool_value); | 86 ASSERT_TRUE(bool_value); |
87 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value)); | 87 ASSERT_TRUE(mixed_list->GetInteger(1, &int_value)); |
88 ASSERT_EQ(42, int_value); | 88 ASSERT_EQ(42, int_value); |
89 // implicit conversion from Integer to Double should be possible. | 89 // implicit conversion from Integer to Double should be possible. |
90 ASSERT_TRUE(mixed_list->GetDouble(1, &double_value)); | 90 ASSERT_TRUE(mixed_list->GetDouble(1, &double_value)); |
91 ASSERT_EQ(42, double_value); | 91 ASSERT_EQ(42, double_value); |
92 ASSERT_TRUE(mixed_list->GetDouble(2, &double_value)); | 92 ASSERT_TRUE(mixed_list->GetDouble(2, &double_value)); |
93 ASSERT_EQ(88.8, double_value); | 93 ASSERT_EQ(88.8, double_value); |
94 ASSERT_TRUE(mixed_list->GetString(3, &string_value)); | 94 ASSERT_TRUE(mixed_list->GetString(3, &string_value)); |
95 ASSERT_EQ("foo", string_value); | 95 ASSERT_EQ("foo", string_value); |
| 96 |
| 97 // Try searching in the mixed list. |
| 98 scoped_ptr<Value> sought_value(Value::CreateIntegerValue(42)); |
| 99 scoped_ptr<Value> not_found_value(Value::CreateBooleanValue(false)); |
| 100 |
| 101 ASSERT_NE(mixed_list->end(), mixed_list->Find(*sought_value)); |
| 102 ASSERT_TRUE((*mixed_list->Find(*sought_value))->GetAsInteger(&int_value)); |
| 103 ASSERT_EQ(42, int_value); |
| 104 ASSERT_EQ(mixed_list->end(), mixed_list->Find(*not_found_value)); |
96 } | 105 } |
97 | 106 |
98 TEST(ValuesTest, BinaryValue) { | 107 TEST(ValuesTest, BinaryValue) { |
99 char* buffer = NULL; | 108 char* buffer = NULL; |
100 // Passing a null buffer pointer doesn't yield a BinaryValue | 109 // Passing a null buffer pointer doesn't yield a BinaryValue |
101 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0)); | 110 scoped_ptr<BinaryValue> binary(BinaryValue::Create(buffer, 0)); |
102 ASSERT_FALSE(binary.get()); | 111 ASSERT_FALSE(binary.get()); |
103 | 112 |
104 // If you want to represent an empty binary value, use a zero-length buffer. | 113 // If you want to represent an empty binary value, use a zero-length buffer. |
105 buffer = new char[1]; | 114 buffer = new char[1]; |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 std::string sub_collide_key_value; | 696 std::string sub_collide_key_value; |
688 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", | 697 EXPECT_TRUE(res_sub_dict->GetString("sub_collide_key", |
689 &sub_collide_key_value)); | 698 &sub_collide_key_value)); |
690 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. | 699 EXPECT_EQ("sub_collide_key_value_merge", sub_collide_key_value); // Replaced. |
691 std::string sub_merge_key_value; | 700 std::string sub_merge_key_value; |
692 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); | 701 EXPECT_TRUE(res_sub_dict->GetString("sub_merge_key", &sub_merge_key_value)); |
693 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. | 702 EXPECT_EQ("sub_merge_key_value_merge", sub_merge_key_value); // Merged in. |
694 } | 703 } |
695 | 704 |
696 } // namespace base | 705 } // namespace base |
OLD | NEW |