Tizen 2.1 base
[platform/upstream/chromium.git] / base / memory / ref_counted_memory_unittest.cc
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.
4
5 #include "base/memory/ref_counted_memory.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10
11 TEST(RefCountedMemoryUnitTest, RefCountedStaticMemory) {
12   scoped_refptr<RefCountedMemory> mem = new RefCountedStaticMemory(
13       reinterpret_cast<const uint8*>("static mem00"), 10);
14
15   EXPECT_EQ(10U, mem->size());
16   EXPECT_EQ("static mem",
17             std::string(reinterpret_cast<const char*>(mem->front()),
18                         mem->size()));
19 }
20
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);
26
27   EXPECT_EQ(0U, data.size());
28
29   EXPECT_EQ(2U, mem->size());
30   EXPECT_EQ(45U, mem->front()[0]);
31   EXPECT_EQ(99U, mem->front()[1]);
32 }
33
34 TEST(RefCountedMemoryUnitTest, RefCountedString) {
35   std::string s("destroy me");
36   scoped_refptr<RefCountedMemory> mem = RefCountedString::TakeString(&s);
37
38   EXPECT_EQ(0U, s.size());
39
40   EXPECT_EQ(10U, mem->size());
41   EXPECT_EQ('d', mem->front()[0]);
42   EXPECT_EQ('e', mem->front()[1]);
43 }
44
45 }  //  namespace base