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 "base/memory/ref_counted_memory.h" | 5 #include "base/memory/ref_counted_memory.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 std::string s("destroy me"); | 35 std::string s("destroy me"); |
36 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); | 36 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); |
37 | 37 |
38 EXPECT_EQ(0U, s.size()); | 38 EXPECT_EQ(0U, s.size()); |
39 | 39 |
40 EXPECT_EQ(10U, mem->size()); | 40 EXPECT_EQ(10U, mem->size()); |
41 EXPECT_EQ('d', mem->front()[0]); | 41 EXPECT_EQ('d', mem->front()[0]); |
42 EXPECT_EQ('e', mem->front()[1]); | 42 EXPECT_EQ('e', mem->front()[1]); |
43 } | 43 } |
44 | 44 |
| 45 TEST(RefCountedMemoryUnitTest, Equals) { |
| 46 std::string s1("same"); |
| 47 scoped_refptr<RefCountedMemory> mem1 = RefCountedString::TakeString(&s1); |
| 48 |
| 49 std::vector<unsigned char> d2; |
| 50 d2.push_back('s'); |
| 51 d2.push_back('a'); |
| 52 d2.push_back('m'); |
| 53 d2.push_back('e'); |
| 54 scoped_refptr<RefCountedMemory> mem2 = RefCountedBytes::TakeVector(&d2); |
| 55 |
| 56 EXPECT_TRUE(mem1->Equals(mem2)); |
| 57 |
| 58 std::string s3("diff"); |
| 59 scoped_refptr<RefCountedMemory> mem3 = RefCountedString::TakeString(&s3); |
| 60 |
| 61 EXPECT_FALSE(mem1->Equals(mem3)); |
| 62 EXPECT_FALSE(mem2->Equals(mem3)); |
| 63 } |
| 64 |
| 65 TEST(RefCountedMemoryUnitTest, EqualsNull) { |
| 66 std::string s("str"); |
| 67 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); |
| 68 EXPECT_FALSE(mem->Equals(NULL)); |
| 69 } |
| 70 |
45 } // namespace base | 71 } // namespace base |
OLD | NEW |