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

Side by Side Diff: blimp/common/compositor/reference_tracker_unittest.cc

Issue 2626423004: Remove all //blimp code. (Closed)
Patch Set: One last(?) `git merge` for good measure. Created 3 years, 11 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 | « blimp/common/compositor/reference_tracker.cc ('k') | blimp/common/create_blimp_message.h » ('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 2016 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 "blimp/common/compositor/reference_tracker.h"
6
7 #include <stdint.h>
8 #include <algorithm>
9 #include <unordered_set>
10 #include <vector>
11
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace blimp {
16 namespace {
17
18 class ReferenceTrackerTest : public testing::Test {
19 public:
20 ReferenceTrackerTest() = default;
21 ~ReferenceTrackerTest() override = default;
22
23 protected:
24 ReferenceTracker tracker_;
25 std::vector<uint32_t> added_;
26 std::vector<uint32_t> removed_;
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(ReferenceTrackerTest);
30 };
31
32 TEST_F(ReferenceTrackerTest, SingleItemCommitFlow) {
33 tracker_.CommitRefCounts(&added_, &removed_);
34 EXPECT_TRUE(added_.empty());
35 EXPECT_TRUE(removed_.empty());
36
37 uint32_t item = 1;
38 tracker_.IncrementRefCount(item);
39 tracker_.CommitRefCounts(&added_, &removed_);
40 EXPECT_THAT(added_, testing::UnorderedElementsAre(item));
41 EXPECT_TRUE(removed_.empty());
42 added_.clear();
43
44 tracker_.CommitRefCounts(&added_, &removed_);
45 EXPECT_TRUE(added_.empty());
46 EXPECT_TRUE(removed_.empty());
47
48 tracker_.DecrementRefCount(item);
49 tracker_.CommitRefCounts(&added_, &removed_);
50 EXPECT_TRUE(added_.empty());
51 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item));
52 }
53
54 TEST_F(ReferenceTrackerTest, SingleItemMultipleTimesInSingleCommit) {
55 uint32_t item = 1;
56 tracker_.IncrementRefCount(item);
57 tracker_.IncrementRefCount(item);
58 tracker_.CommitRefCounts(&added_, &removed_);
59 EXPECT_THAT(added_, testing::UnorderedElementsAre(item));
60 EXPECT_TRUE(removed_.empty());
61 added_.clear();
62
63 tracker_.CommitRefCounts(&added_, &removed_);
64 EXPECT_TRUE(added_.empty());
65 EXPECT_TRUE(removed_.empty());
66
67 tracker_.DecrementRefCount(item);
68 tracker_.DecrementRefCount(item);
69 tracker_.CommitRefCounts(&added_, &removed_);
70 EXPECT_TRUE(added_.empty());
71 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item));
72 }
73
74 TEST_F(ReferenceTrackerTest, SingleItemMultipleTimesAcrossCommits) {
75 uint32_t item = 1;
76 tracker_.IncrementRefCount(item);
77 tracker_.CommitRefCounts(&added_, &removed_);
78 EXPECT_THAT(added_, testing::UnorderedElementsAre(item));
79 EXPECT_TRUE(removed_.empty());
80 added_.clear();
81
82 tracker_.IncrementRefCount(item);
83 tracker_.CommitRefCounts(&added_, &removed_);
84 EXPECT_TRUE(added_.empty());
85 EXPECT_TRUE(removed_.empty());
86
87 tracker_.DecrementRefCount(item);
88 tracker_.CommitRefCounts(&added_, &removed_);
89 EXPECT_TRUE(added_.empty());
90 EXPECT_TRUE(removed_.empty());
91
92 tracker_.DecrementRefCount(item);
93 tracker_.CommitRefCounts(&added_, &removed_);
94 EXPECT_TRUE(added_.empty());
95 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item));
96 }
97
98 TEST_F(ReferenceTrackerTest, SingleItemComplexInteractions) {
99 uint32_t item = 1;
100 tracker_.IncrementRefCount(item);
101 tracker_.DecrementRefCount(item);
102 tracker_.CommitRefCounts(&added_, &removed_);
103 EXPECT_TRUE(added_.empty());
104 EXPECT_TRUE(removed_.empty());
105
106 tracker_.IncrementRefCount(item);
107 tracker_.DecrementRefCount(item);
108 tracker_.IncrementRefCount(item);
109 tracker_.CommitRefCounts(&added_, &removed_);
110 EXPECT_THAT(added_, testing::UnorderedElementsAre(item));
111 EXPECT_TRUE(removed_.empty());
112 added_.clear();
113
114 tracker_.DecrementRefCount(item);
115 tracker_.IncrementRefCount(item);
116 tracker_.DecrementRefCount(item);
117 tracker_.CommitRefCounts(&added_, &removed_);
118 EXPECT_TRUE(added_.empty());
119 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item));
120 }
121
122 TEST_F(ReferenceTrackerTest, MultipleItems) {
123 uint32_t item1 = 1;
124 uint32_t item2 = 2;
125 uint32_t item3 = 3;
126 tracker_.IncrementRefCount(item1);
127 tracker_.IncrementRefCount(item2);
128 tracker_.IncrementRefCount(item3);
129 tracker_.CommitRefCounts(&added_, &removed_);
130 EXPECT_THAT(added_, testing::UnorderedElementsAre(item1, item2, item3));
131 EXPECT_TRUE(removed_.empty());
132 added_.clear();
133
134 tracker_.DecrementRefCount(item3);
135 tracker_.CommitRefCounts(&added_, &removed_);
136 EXPECT_TRUE(added_.empty());
137 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item3));
138 removed_.clear();
139
140 tracker_.DecrementRefCount(item2);
141 tracker_.IncrementRefCount(item3);
142 tracker_.CommitRefCounts(&added_, &removed_);
143 EXPECT_THAT(added_, testing::UnorderedElementsAre(item3));
144 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item2));
145 added_.clear();
146 removed_.clear();
147
148 tracker_.IncrementRefCount(item2);
149 tracker_.CommitRefCounts(&added_, &removed_);
150 EXPECT_THAT(added_, testing::UnorderedElementsAre(item2));
151 EXPECT_TRUE(removed_.empty());
152 added_.clear();
153
154 tracker_.DecrementRefCount(item1);
155 tracker_.DecrementRefCount(item2);
156 tracker_.DecrementRefCount(item3);
157 tracker_.CommitRefCounts(&added_, &removed_);
158 EXPECT_TRUE(added_.empty());
159 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item1, item2, item3));
160 }
161
162 TEST_F(ReferenceTrackerTest, MultipleItemsWithClear) {
163 uint32_t item1 = 1;
164 uint32_t item2 = 2;
165 tracker_.IncrementRefCount(item1);
166 tracker_.IncrementRefCount(item2);
167 tracker_.ClearRefCounts();
168 tracker_.CommitRefCounts(&added_, &removed_);
169 EXPECT_TRUE(added_.empty());
170 EXPECT_TRUE(removed_.empty());
171
172 tracker_.IncrementRefCount(item1);
173 tracker_.IncrementRefCount(item2);
174 tracker_.ClearRefCounts();
175 tracker_.IncrementRefCount(item1);
176 tracker_.CommitRefCounts(&added_, &removed_);
177 EXPECT_THAT(added_, testing::UnorderedElementsAre(item1));
178 EXPECT_TRUE(removed_.empty());
179 added_.clear();
180
181 tracker_.ClearRefCounts();
182 tracker_.IncrementRefCount(item2);
183 tracker_.CommitRefCounts(&added_, &removed_);
184 EXPECT_THAT(added_, testing::UnorderedElementsAre(item2));
185 EXPECT_THAT(removed_, testing::UnorderedElementsAre(item1));
186 added_.clear();
187 removed_.clear();
188
189 tracker_.ClearRefCounts();
190 tracker_.IncrementRefCount(item1);
191 tracker_.IncrementRefCount(item2);
192 tracker_.CommitRefCounts(&added_, &removed_);
193 EXPECT_THAT(added_, testing::UnorderedElementsAre(item1));
194 EXPECT_TRUE(removed_.empty());
195 added_.clear();
196 }
197
198 } // namespace
199 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/common/compositor/reference_tracker.cc ('k') | blimp/common/create_blimp_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698