| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 std::string s("destroy me"); | 45 std::string s("destroy me"); |
| 46 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); | 46 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); |
| 47 | 47 |
| 48 EXPECT_EQ(0U, s.size()); | 48 EXPECT_EQ(0U, s.size()); |
| 49 | 49 |
| 50 EXPECT_EQ(10U, mem->size()); | 50 EXPECT_EQ(10U, mem->size()); |
| 51 EXPECT_EQ('d', mem->front()[0]); | 51 EXPECT_EQ('d', mem->front()[0]); |
| 52 EXPECT_EQ('e', mem->front()[1]); | 52 EXPECT_EQ('e', mem->front()[1]); |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST(RefCountedMemoryUnitTest, RefCountedMallocedMemory) { | |
| 56 void* data = malloc(6); | |
| 57 memcpy(data, "hello", 6); | |
| 58 | |
| 59 scoped_refptr<RefCountedMemory> mem = new RefCountedMallocedMemory(data, 6); | |
| 60 | |
| 61 EXPECT_EQ(6U, mem->size()); | |
| 62 EXPECT_EQ(0, memcmp("hello", mem->front(), 6)); | |
| 63 } | |
| 64 | |
| 65 TEST(RefCountedMemoryUnitTest, Equals) { | 55 TEST(RefCountedMemoryUnitTest, Equals) { |
| 66 std::string s1("same"); | 56 std::string s1("same"); |
| 67 scoped_refptr<RefCountedMemory> mem1 = RefCountedString::TakeString(&s1); | 57 scoped_refptr<RefCountedMemory> mem1 = RefCountedString::TakeString(&s1); |
| 68 | 58 |
| 69 std::vector<unsigned char> d2; | 59 std::vector<unsigned char> d2; |
| 70 d2.push_back('s'); | 60 d2.push_back('s'); |
| 71 d2.push_back('a'); | 61 d2.push_back('a'); |
| 72 d2.push_back('m'); | 62 d2.push_back('m'); |
| 73 d2.push_back('e'); | 63 d2.push_back('e'); |
| 74 scoped_refptr<RefCountedMemory> mem2 = RefCountedBytes::TakeVector(&d2); | 64 scoped_refptr<RefCountedMemory> mem2 = RefCountedBytes::TakeVector(&d2); |
| 75 | 65 |
| 76 EXPECT_TRUE(mem1->Equals(mem2)); | 66 EXPECT_TRUE(mem1->Equals(mem2)); |
| 77 | 67 |
| 78 std::string s3("diff"); | 68 std::string s3("diff"); |
| 79 scoped_refptr<RefCountedMemory> mem3 = RefCountedString::TakeString(&s3); | 69 scoped_refptr<RefCountedMemory> mem3 = RefCountedString::TakeString(&s3); |
| 80 | 70 |
| 81 EXPECT_FALSE(mem1->Equals(mem3)); | 71 EXPECT_FALSE(mem1->Equals(mem3)); |
| 82 EXPECT_FALSE(mem2->Equals(mem3)); | 72 EXPECT_FALSE(mem2->Equals(mem3)); |
| 83 } | 73 } |
| 84 | 74 |
| 85 TEST(RefCountedMemoryUnitTest, EqualsNull) { | 75 TEST(RefCountedMemoryUnitTest, EqualsNull) { |
| 86 std::string s("str"); | 76 std::string s("str"); |
| 87 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); | 77 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); |
| 88 EXPECT_FALSE(mem->Equals(NULL)); | 78 EXPECT_FALSE(mem->Equals(NULL)); |
| 89 } | 79 } |
| 90 | 80 |
| 91 } // namespace base | 81 } // namespace base |
| OLD | NEW |