Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / base / memory / ref_counted_memory_unittest.cc
blobc6f2b9c3d1c8f0878dca40c5f91fd91a7a8c8a9b
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
3 // found in the LICENSE file.
5 #include "base/memory/ref_counted_memory.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace base {
11 TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) {
12 scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory(
13 reinterpret_cast<const uint8*>("static mem00"), 10);
15 EXPECT_EQ(10U, mem->size());
16 EXPECT_EQ("static mem",
17 std::string(reinterpret_cast<const char*>(mem->front()),
18 mem->size()));
21 TEST(RefCountedMemoryUnitTest, RefCountedBytes) {
22 std::vector<uint8> data;
23 data.push_back(45);
24 data.push_back(99);
25 scoped_refptr<RefCountedMemory> mem = RefCountedBytes::TakeVector(&data);
27 EXPECT_EQ(0U, data.size());
29 EXPECT_EQ(2U, mem->size());
30 EXPECT_EQ(45U, mem->front()[0]);
31 EXPECT_EQ(99U, mem->front()[1]);
34 TEST(RefCountedMemoryUnitTest, RefCountedString) {
35 std::string s("destroy me");
36 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s);
38 EXPECT_EQ(0U, s.size());
40 EXPECT_EQ(10U, mem->size());
41 EXPECT_EQ('d', mem->front()[0]);
42 EXPECT_EQ('e', mem->front()[1]);
45 TEST(RefCountedMemoryUnitTest, Equals) {
46 std::string s1("same");
47 scoped_refptr<RefCountedMemory> mem1 = RefCountedString::TakeString(&s1);
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);
56 EXPECT_TRUE(mem1->Equals(mem2));
58 std::string s3("diff");
59 scoped_refptr<RefCountedMemory> mem3 = RefCountedString::TakeString(&s3);
61 EXPECT_FALSE(mem1->Equals(mem3));
62 EXPECT_FALSE(mem2->Equals(mem3));
65 TEST(RefCountedMemoryUnitTest, EqualsNull) {
66 std::string s("str");
67 scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s);
68 EXPECT_FALSE(mem->Equals(NULL));
71 } // namespace base