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 |
11 TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) { | 11 TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) { |
12 scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory( | 12 scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory( |
13 reinterpret_cast<const uint8*>("static mem00"), 10); | 13 "static mem00", 10); |
14 | 14 |
15 EXPECT_EQ(10U, mem->size()); | 15 EXPECT_EQ(10U, mem->size()); |
16 EXPECT_EQ("static mem", | 16 EXPECT_EQ("static mem", std::string(mem->front_as<char>(), mem->size())); |
17 std::string(reinterpret_cast<const char*>(mem->front()), | |
18 mem->size())); | |
19 } | 17 } |
20 | 18 |
21 TEST(RefCountedMemoryUnitTest, RefCountedBytes) { | 19 TEST(RefCountedMemoryUnitTest, RefCountedBytes) { |
22 std::vector<uint8> data; | 20 std::vector<uint8> data; |
23 data.push_back(45); | 21 data.push_back(45); |
24 data.push_back(99); | 22 data.push_back(99); |
25 scoped_refptr<RefCountedMemory> mem = RefCountedBytes::TakeVector(&data); | 23 scoped_refptr<RefCountedMemory> mem = RefCountedBytes::TakeVector(&data); |
26 | 24 |
27 EXPECT_EQ(0U, data.size()); | 25 EXPECT_EQ(0U, data.size()); |
28 | 26 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 EXPECT_FALSE(mem2->Equals(mem3)); | 70 EXPECT_FALSE(mem2->Equals(mem3)); |
73 } | 71 } |
74 | 72 |
75 TEST(RefCountedMemoryUnitTest, EqualsNull) { | 73 TEST(RefCountedMemoryUnitTest, EqualsNull) { |
76 std::string s("str"); | 74 std::string s("str"); |
77 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); | 75 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s); |
78 EXPECT_FALSE(mem->Equals(NULL)); | 76 EXPECT_FALSE(mem->Equals(NULL)); |
79 } | 77 } |
80 | 78 |
81 } // namespace base | 79 } // namespace base |
OLD | NEW |