Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / cc / base / random_access_list_container_unittest.cc
blob78004b4a8f4d78184a6b295cf1535dbbca9531f9
1 // Copyright 2015 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 "cc/base/random_access_list_container.h"
7 #include <algorithm>
8 #include <vector>
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
14 namespace {
16 class Base {
17 public:
18 virtual ~Base() {}
19 int get_value() const { return value_; }
21 protected:
22 explicit Base(int value) : value_(value) {}
24 int value_;
27 const int kMagicNumberOne = 1;
28 const int kMagicNumberTwo = 2;
29 const int kMagicNumberThree = 3;
31 class Derived1 : public Base {
32 public:
33 Derived1() : Base(kMagicNumberOne) {}
36 class Derived2 : public Base {
37 public:
38 Derived2() : Base(kMagicNumberTwo) {}
41 class Derived3 : public Base {
42 public:
43 Derived3() : Base(kMagicNumberThree) {}
46 size_t LargestDerivedElementSize() {
47 static_assert(sizeof(Derived1) >= sizeof(Derived2),
48 "Derived2 is larger than Derived1");
49 static_assert(sizeof(Derived1) >= sizeof(Derived3),
50 "Derived3 is larger than Derived1");
51 return sizeof(Derived1);
54 TEST(RandomAccessListContainerTest, RandomAccess) {
55 RandomAccessListContainer<Base> list(LargestDerivedElementSize(), 1);
57 list.AllocateAndConstruct<Derived1>();
58 list.AllocateAndConstruct<Derived2>();
59 list.AllocateAndConstruct<Derived3>();
60 list.AllocateAndConstruct<Derived1>();
61 list.AllocateAndConstruct<Derived2>();
62 list.AllocateAndConstruct<Derived3>();
64 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
65 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
66 EXPECT_EQ(kMagicNumberThree, list[2]->get_value());
67 EXPECT_EQ(kMagicNumberOne, list[3]->get_value());
68 EXPECT_EQ(kMagicNumberTwo, list[4]->get_value());
69 EXPECT_EQ(kMagicNumberThree, list[5]->get_value());
71 list.RemoveLast();
72 list.RemoveLast();
73 list.RemoveLast();
75 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
76 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
77 EXPECT_EQ(kMagicNumberThree, list[2]->get_value());
79 list.AllocateAndConstruct<Derived3>();
80 list.AllocateAndConstruct<Derived2>();
81 list.AllocateAndConstruct<Derived1>();
83 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
84 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
85 EXPECT_EQ(kMagicNumberThree, list[2]->get_value());
86 EXPECT_EQ(kMagicNumberThree, list[3]->get_value());
87 EXPECT_EQ(kMagicNumberTwo, list[4]->get_value());
88 EXPECT_EQ(kMagicNumberOne, list[5]->get_value());
91 TEST(RandomAccessListContainerTest, Clear) {
92 RandomAccessListContainer<Base> list(LargestDerivedElementSize(), 1);
94 list.AllocateAndConstruct<Derived1>();
95 list.AllocateAndConstruct<Derived2>();
97 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
98 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
100 list.clear();
101 list.AllocateAndConstruct<Derived3>();
103 EXPECT_EQ(kMagicNumberThree, list[0]->get_value());
106 } // namespace
107 } // namespace cc