Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: cc/base/random_access_list_container_unittest.cc

Issue 1340703002: cc: Add RandomAccessListContainer, which has more restricted API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/base/random_access_list_container.h ('k') | cc/cc.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "cc/base/random_access_list_container.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace cc {
14 namespace {
15
16 class Base {
17 public:
18 virtual ~Base() {}
19 int get_value() const { return value_; }
20
21 protected:
22 explicit Base(int value) : value_(value) {}
23
24 int value_;
25 };
26
27 const int kMagicNumberOne = 1;
28 const int kMagicNumberTwo = 2;
29 const int kMagicNumberThree = 3;
30
31 class Derived1 : public Base {
32 public:
33 Derived1() : Base(kMagicNumberOne) {}
34 };
35
36 class Derived2 : public Base {
37 public:
38 Derived2() : Base(kMagicNumberTwo) {}
39 };
40
41 class Derived3 : public Base {
42 public:
43 Derived3() : Base(kMagicNumberThree) {}
44 };
45
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);
52 }
53
54 TEST(RandomAccessListContainerTest, RandomAccess) {
55 RandomAccessListContainer<Base> list(LargestDerivedElementSize(), 1);
56
57 list.AllocateAndConstruct<Derived1>();
58 list.AllocateAndConstruct<Derived2>();
59 list.AllocateAndConstruct<Derived3>();
60 list.AllocateAndConstruct<Derived1>();
61 list.AllocateAndConstruct<Derived2>();
62 list.AllocateAndConstruct<Derived3>();
63
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());
70
71 list.RemoveLast();
72 list.RemoveLast();
73 list.RemoveLast();
74
75 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
76 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
77 EXPECT_EQ(kMagicNumberThree, list[2]->get_value());
78
79 list.AllocateAndConstruct<Derived3>();
80 list.AllocateAndConstruct<Derived2>();
81 list.AllocateAndConstruct<Derived1>();
82
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());
89 }
90
91 TEST(RandomAccessListContainerTest, Clear) {
92 RandomAccessListContainer<Base> list(LargestDerivedElementSize(), 1);
93
94 list.AllocateAndConstruct<Derived1>();
95 list.AllocateAndConstruct<Derived2>();
96
97 EXPECT_EQ(kMagicNumberOne, list[0]->get_value());
98 EXPECT_EQ(kMagicNumberTwo, list[1]->get_value());
99
100 list.clear();
101 list.AllocateAndConstruct<Derived3>();
102
103 EXPECT_EQ(kMagicNumberThree, list[0]->get_value());
104 }
105
106 } // namespace
107 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/random_access_list_container.h ('k') | cc/cc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698