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"
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()),
21 TEST(RefCountedMemoryUnitTest, RefCountedBytes) {
22 std::vector<uint8> data;
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]);