OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/quads/list_container.h" | 5 #include "cc/base/list_container.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include "cc/quads/draw_quad.h" | 8 #include "cc/quads/draw_quad.h" |
9 #include "cc/quads/largest_draw_quad.h" | 9 #include "cc/quads/largest_draw_quad.h" |
10 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
11 #include "cc/quads/shared_quad_state.h" | 11 #include "cc/quads/shared_quad_state.h" |
12 #include "cc/quads/stream_video_draw_quad.h" | 12 #include "cc/quads/stream_video_draw_quad.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 }; | 61 }; |
62 | 62 |
63 class MockDrawQuadSubclass : public MockDrawQuad { | 63 class MockDrawQuadSubclass : public MockDrawQuad { |
64 public: | 64 public: |
65 MockDrawQuadSubclass() { set_value(kMagicNumberToUseForDrawQuadTwo); } | 65 MockDrawQuadSubclass() { set_value(kMagicNumberToUseForDrawQuadTwo); } |
66 }; | 66 }; |
67 | 67 |
68 const size_t kLargestQuadSize = | 68 const size_t kLargestQuadSize = |
69 std::max(LargestDrawQuadSize(), sizeof(MockDrawQuadSubclass)); | 69 std::max(LargestDrawQuadSize(), sizeof(MockDrawQuadSubclass)); |
70 | 70 |
71 TEST(ListContainerTest, ConstructorCalledInAllocateAndConstruct) { | 71 TEST(QuadListContainerTest, ConstructorCalledInAllocateAndConstruct) { |
enne (OOO)
2015/05/26 18:31:28
I think these are really testing the list containe
prashant.n
2015/05/26 19:11:48
Ok I can revert this. But again problem comes, as
| |
72 ListContainer<DrawQuad> list(kLargestQuadSize); | 72 ListContainer<DrawQuad> list(kLargestQuadSize); |
73 | 73 |
74 size_t size = 2; | 74 size_t size = 2; |
75 SimpleDrawQuadConstructMagicNumberOne* dq_1 = | 75 SimpleDrawQuadConstructMagicNumberOne* dq_1 = |
76 list.AllocateAndConstruct<SimpleDrawQuadConstructMagicNumberOne>(); | 76 list.AllocateAndConstruct<SimpleDrawQuadConstructMagicNumberOne>(); |
77 SimpleDrawQuadConstructMagicNumberTwo* dq_2 = | 77 SimpleDrawQuadConstructMagicNumberTwo* dq_2 = |
78 list.AllocateAndConstruct<SimpleDrawQuadConstructMagicNumberTwo>(); | 78 list.AllocateAndConstruct<SimpleDrawQuadConstructMagicNumberTwo>(); |
79 | 79 |
80 EXPECT_EQ(size, list.size()); | 80 EXPECT_EQ(size, list.size()); |
81 EXPECT_EQ(dq_1, list.front()); | 81 EXPECT_EQ(dq_1, list.front()); |
82 EXPECT_EQ(dq_2, list.back()); | 82 EXPECT_EQ(dq_2, list.back()); |
83 | 83 |
84 EXPECT_EQ(kMagicNumberToUseForDrawQuadOne, dq_1->get_value()); | 84 EXPECT_EQ(kMagicNumberToUseForDrawQuadOne, dq_1->get_value()); |
85 EXPECT_EQ(kMagicNumberToUseForDrawQuadTwo, dq_2->get_value()); | 85 EXPECT_EQ(kMagicNumberToUseForDrawQuadTwo, dq_2->get_value()); |
86 } | 86 } |
87 | 87 |
88 TEST(ListContainerTest, DestructorCalled) { | 88 TEST(QuadListContainerTest, DestructorCalled) { |
89 ListContainer<DrawQuad> list(kLargestQuadSize); | 89 ListContainer<DrawQuad> list(kLargestQuadSize); |
90 | 90 |
91 size_t size = 1; | 91 size_t size = 1; |
92 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); | 92 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); |
93 | 93 |
94 EXPECT_CALL(*dq_1, Destruct()); | 94 EXPECT_CALL(*dq_1, Destruct()); |
95 EXPECT_EQ(size, list.size()); | 95 EXPECT_EQ(size, list.size()); |
96 EXPECT_EQ(dq_1, list.front()); | 96 EXPECT_EQ(dq_1, list.front()); |
97 } | 97 } |
98 | 98 |
99 TEST(ListContainerTest, DestructorCalledOnceWhenClear) { | 99 TEST(QuadListContainerTest, DestructorCalledOnceWhenClear) { |
100 ListContainer<DrawQuad> list(kLargestQuadSize); | 100 ListContainer<DrawQuad> list(kLargestQuadSize); |
101 size_t size = 1; | 101 size_t size = 1; |
102 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); | 102 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); |
103 | 103 |
104 EXPECT_EQ(size, list.size()); | 104 EXPECT_EQ(size, list.size()); |
105 EXPECT_EQ(dq_1, list.front()); | 105 EXPECT_EQ(dq_1, list.front()); |
106 | 106 |
107 // Make sure destructor is called once during clear, and won't be called | 107 // Make sure destructor is called once during clear, and won't be called |
108 // again. | 108 // again. |
109 testing::MockFunction<void()> separator; | 109 testing::MockFunction<void()> separator; |
110 { | 110 { |
111 testing::InSequence s; | 111 testing::InSequence s; |
112 EXPECT_CALL(*dq_1, Destruct()); | 112 EXPECT_CALL(*dq_1, Destruct()); |
113 EXPECT_CALL(separator, Call()); | 113 EXPECT_CALL(separator, Call()); |
114 EXPECT_CALL(*dq_1, Destruct()).Times(0); | 114 EXPECT_CALL(*dq_1, Destruct()).Times(0); |
115 } | 115 } |
116 | 116 |
117 list.clear(); | 117 list.clear(); |
118 separator.Call(); | 118 separator.Call(); |
119 } | 119 } |
120 | 120 |
121 TEST(ListContainerTest, ReplaceExistingElement) { | 121 TEST(QuadListContainerTest, ReplaceExistingElement) { |
122 ListContainer<DrawQuad> list(kLargestQuadSize); | 122 ListContainer<DrawQuad> list(kLargestQuadSize); |
123 size_t size = 1; | 123 size_t size = 1; |
124 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); | 124 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); |
125 | 125 |
126 EXPECT_EQ(size, list.size()); | 126 EXPECT_EQ(size, list.size()); |
127 EXPECT_EQ(dq_1, list.front()); | 127 EXPECT_EQ(dq_1, list.front()); |
128 | 128 |
129 // Make sure destructor is called once during clear, and won't be called | 129 // Make sure destructor is called once during clear, and won't be called |
130 // again. | 130 // again. |
131 testing::MockFunction<void()> separator; | 131 testing::MockFunction<void()> separator; |
132 { | 132 { |
133 testing::InSequence s; | 133 testing::InSequence s; |
134 EXPECT_CALL(*dq_1, Destruct()); | 134 EXPECT_CALL(*dq_1, Destruct()); |
135 EXPECT_CALL(separator, Call()); | 135 EXPECT_CALL(separator, Call()); |
136 EXPECT_CALL(*dq_1, Destruct()).Times(0); | 136 EXPECT_CALL(*dq_1, Destruct()).Times(0); |
137 } | 137 } |
138 | 138 |
139 list.ReplaceExistingElement<MockDrawQuadSubclass>(list.begin()); | 139 list.ReplaceExistingElement<MockDrawQuadSubclass>(list.begin()); |
140 EXPECT_EQ(kMagicNumberToUseForDrawQuadTwo, dq_1->get_value()); | 140 EXPECT_EQ(kMagicNumberToUseForDrawQuadTwo, dq_1->get_value()); |
141 separator.Call(); | 141 separator.Call(); |
142 | 142 |
143 EXPECT_CALL(*dq_1, Destruct()); | 143 EXPECT_CALL(*dq_1, Destruct()); |
144 list.clear(); | 144 list.clear(); |
145 } | 145 } |
146 | 146 |
147 TEST(ListContainerTest, DestructorCalledOnceWhenErase) { | 147 TEST(QuadListContainerTest, DestructorCalledOnceWhenErase) { |
148 ListContainer<DrawQuad> list(kLargestQuadSize); | 148 ListContainer<DrawQuad> list(kLargestQuadSize); |
149 size_t size = 1; | 149 size_t size = 1; |
150 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); | 150 MockDrawQuad* dq_1 = list.AllocateAndConstruct<MockDrawQuad>(); |
151 | 151 |
152 EXPECT_EQ(size, list.size()); | 152 EXPECT_EQ(size, list.size()); |
153 EXPECT_EQ(dq_1, list.front()); | 153 EXPECT_EQ(dq_1, list.front()); |
154 | 154 |
155 // Make sure destructor is called once during clear, and won't be called | 155 // Make sure destructor is called once during clear, and won't be called |
156 // again. | 156 // again. |
157 testing::MockFunction<void()> separator; | 157 testing::MockFunction<void()> separator; |
158 { | 158 { |
159 testing::InSequence s; | 159 testing::InSequence s; |
160 EXPECT_CALL(*dq_1, Destruct()); | 160 EXPECT_CALL(*dq_1, Destruct()); |
161 EXPECT_CALL(separator, Call()); | 161 EXPECT_CALL(separator, Call()); |
162 EXPECT_CALL(*dq_1, Destruct()).Times(0); | 162 EXPECT_CALL(*dq_1, Destruct()).Times(0); |
163 } | 163 } |
164 | 164 |
165 list.EraseAndInvalidateAllPointers(list.begin()); | 165 list.EraseAndInvalidateAllPointers(list.begin()); |
166 separator.Call(); | 166 separator.Call(); |
167 } | 167 } |
168 | 168 |
169 TEST(ListContainerTest, SimpleIndexAccessSharedQuadState) { | 169 TEST(QuadListContainerTest, SimpleIndexAccessSharedQuadState) { |
170 ListContainer<SharedQuadState> list; | 170 ListContainer<SharedQuadState> list; |
171 | 171 |
172 size_t size = 3; | 172 size_t size = 3; |
173 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); | 173 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); |
174 SharedQuadState* sqs_2 = list.AllocateAndConstruct<SharedQuadState>(); | 174 SharedQuadState* sqs_2 = list.AllocateAndConstruct<SharedQuadState>(); |
175 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); | 175 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); |
176 | 176 |
177 EXPECT_EQ(size, list.size()); | 177 EXPECT_EQ(size, list.size()); |
178 EXPECT_EQ(sqs_1, list.front()); | 178 EXPECT_EQ(sqs_1, list.front()); |
179 EXPECT_EQ(sqs_3, list.back()); | 179 EXPECT_EQ(sqs_3, list.back()); |
180 EXPECT_EQ(list.front(), list.ElementAt(0)); | 180 EXPECT_EQ(list.front(), list.ElementAt(0)); |
181 EXPECT_EQ(sqs_2, list.ElementAt(1)); | 181 EXPECT_EQ(sqs_2, list.ElementAt(1)); |
182 EXPECT_EQ(list.back(), list.ElementAt(2)); | 182 EXPECT_EQ(list.back(), list.ElementAt(2)); |
183 } | 183 } |
184 | 184 |
185 TEST(ListContainerTest, SimpleInsertionSharedQuadState) { | 185 TEST(QuadListContainerTest, SimpleInsertionSharedQuadState) { |
186 ListContainer<SharedQuadState> list; | 186 ListContainer<SharedQuadState> list; |
187 | 187 |
188 size_t size = 3; | 188 size_t size = 3; |
189 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); | 189 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); |
190 list.AllocateAndConstruct<SharedQuadState>(); | 190 list.AllocateAndConstruct<SharedQuadState>(); |
191 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); | 191 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); |
192 | 192 |
193 EXPECT_EQ(size, list.size()); | 193 EXPECT_EQ(size, list.size()); |
194 EXPECT_EQ(sqs_1, list.front()); | 194 EXPECT_EQ(sqs_1, list.front()); |
195 EXPECT_EQ(sqs_3, list.back()); | 195 EXPECT_EQ(sqs_3, list.back()); |
196 } | 196 } |
197 | 197 |
198 TEST(ListContainerTest, SimpleInsertionAndClearSharedQuadState) { | 198 TEST(QuadListContainerTest, SimpleInsertionAndClearSharedQuadState) { |
199 ListContainer<SharedQuadState> list; | 199 ListContainer<SharedQuadState> list; |
200 EXPECT_TRUE(list.empty()); | 200 EXPECT_TRUE(list.empty()); |
201 EXPECT_EQ(0u, list.size()); | 201 EXPECT_EQ(0u, list.size()); |
202 | 202 |
203 size_t size = 3; | 203 size_t size = 3; |
204 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); | 204 SharedQuadState* sqs_1 = list.AllocateAndConstruct<SharedQuadState>(); |
205 list.AllocateAndConstruct<SharedQuadState>(); | 205 list.AllocateAndConstruct<SharedQuadState>(); |
206 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); | 206 SharedQuadState* sqs_3 = list.AllocateAndConstruct<SharedQuadState>(); |
207 | 207 |
208 EXPECT_EQ(size, list.size()); | 208 EXPECT_EQ(size, list.size()); |
209 EXPECT_EQ(sqs_1, list.front()); | 209 EXPECT_EQ(sqs_1, list.front()); |
210 EXPECT_EQ(sqs_3, list.back()); | 210 EXPECT_EQ(sqs_3, list.back()); |
211 EXPECT_FALSE(list.empty()); | 211 EXPECT_FALSE(list.empty()); |
212 | 212 |
213 list.clear(); | 213 list.clear(); |
214 EXPECT_TRUE(list.empty()); | 214 EXPECT_TRUE(list.empty()); |
215 EXPECT_EQ(0u, list.size()); | 215 EXPECT_EQ(0u, list.size()); |
216 } | 216 } |
217 | 217 |
218 TEST(ListContainerTest, SimpleInsertionClearAndInsertAgainSharedQuadState) { | 218 TEST(QuadListContainerTest, SimpleInsertionClearAndInsertAgainSharedQuadState) { |
219 ListContainer<SharedQuadState> list; | 219 ListContainer<SharedQuadState> list; |
220 EXPECT_TRUE(list.empty()); | 220 EXPECT_TRUE(list.empty()); |
221 EXPECT_EQ(0u, list.size()); | 221 EXPECT_EQ(0u, list.size()); |
222 | 222 |
223 size_t size = 2; | 223 size_t size = 2; |
224 SharedQuadState* sqs_front = list.AllocateAndConstruct<SharedQuadState>(); | 224 SharedQuadState* sqs_front = list.AllocateAndConstruct<SharedQuadState>(); |
225 SharedQuadState* sqs_back = list.AllocateAndConstruct<SharedQuadState>(); | 225 SharedQuadState* sqs_back = list.AllocateAndConstruct<SharedQuadState>(); |
226 | 226 |
227 EXPECT_EQ(size, list.size()); | 227 EXPECT_EQ(size, list.size()); |
228 EXPECT_EQ(sqs_front, list.front()); | 228 EXPECT_EQ(sqs_front, list.front()); |
(...skipping 10 matching lines...) Expand all Loading... | |
239 sqs_back = list.AllocateAndConstruct<SharedQuadState>(); | 239 sqs_back = list.AllocateAndConstruct<SharedQuadState>(); |
240 | 240 |
241 EXPECT_EQ(size, list.size()); | 241 EXPECT_EQ(size, list.size()); |
242 EXPECT_EQ(sqs_front, list.front()); | 242 EXPECT_EQ(sqs_front, list.front()); |
243 EXPECT_EQ(sqs_back, list.back()); | 243 EXPECT_EQ(sqs_back, list.back()); |
244 EXPECT_FALSE(list.empty()); | 244 EXPECT_FALSE(list.empty()); |
245 } | 245 } |
246 | 246 |
247 // This test is used to test when there is more than one allocation needed | 247 // This test is used to test when there is more than one allocation needed |
248 // for, ListContainer can still perform like normal vector. | 248 // for, ListContainer can still perform like normal vector. |
249 TEST(ListContainerTest, | 249 TEST(QuadListContainerTest, |
250 SimpleInsertionTriggerMoreThanOneAllocationSharedQuadState) { | 250 SimpleInsertionTriggerMoreThanOneAllocationSharedQuadState) { |
251 ListContainer<SharedQuadState> list(sizeof(SharedQuadState), 2); | 251 ListContainer<SharedQuadState> list(sizeof(SharedQuadState), 2); |
252 std::vector<SharedQuadState*> sqs_list; | 252 std::vector<SharedQuadState*> sqs_list; |
253 size_t size = 10; | 253 size_t size = 10; |
254 for (size_t i = 0; i < size; ++i) { | 254 for (size_t i = 0; i < size; ++i) { |
255 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); | 255 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); |
256 } | 256 } |
257 EXPECT_EQ(size, list.size()); | 257 EXPECT_EQ(size, list.size()); |
258 | 258 |
259 ListContainer<SharedQuadState>::Iterator iter = list.begin(); | 259 ListContainer<SharedQuadState>::Iterator iter = list.begin(); |
260 for (std::vector<SharedQuadState*>::const_iterator sqs_iter = | 260 for (std::vector<SharedQuadState*>::const_iterator sqs_iter = |
261 sqs_list.begin(); | 261 sqs_list.begin(); |
262 sqs_iter != sqs_list.end(); | 262 sqs_iter != sqs_list.end(); |
263 ++sqs_iter) { | 263 ++sqs_iter) { |
264 EXPECT_EQ(*sqs_iter, *iter); | 264 EXPECT_EQ(*sqs_iter, *iter); |
265 ++iter; | 265 ++iter; |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 TEST(ListContainerTest, | 269 TEST(QuadListContainerTest, |
270 CorrectAllocationSizeForMoreThanOneAllocationSharedQuadState) { | 270 CorrectAllocationSizeForMoreThanOneAllocationSharedQuadState) { |
271 // Constructor sets the allocation size to 2. Every time ListContainer needs | 271 // Constructor sets the allocation size to 2. Every time ListContainer needs |
272 // to allocate again, it doubles allocation size. In this test, 10 elements is | 272 // to allocate again, it doubles allocation size. In this test, 10 elements is |
273 // needed, thus ListContainerShould allocate spaces 2, 4 and 8 elements. | 273 // needed, thus ListContainerShould allocate spaces 2, 4 and 8 elements. |
274 ListContainer<SharedQuadState> list(sizeof(SharedQuadState), 2); | 274 ListContainer<SharedQuadState> list(sizeof(SharedQuadState), 2); |
275 std::vector<SharedQuadState*> sqs_list; | 275 std::vector<SharedQuadState*> sqs_list; |
276 size_t size = 10; | 276 size_t size = 10; |
277 for (size_t i = 0; i < size; ++i) { | 277 for (size_t i = 0; i < size; ++i) { |
278 // Before asking for a new element, space available without another | 278 // Before asking for a new element, space available without another |
279 // allocation follows. | 279 // allocation follows. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 ListContainer<SharedQuadState>::Iterator iter = list.begin(); | 344 ListContainer<SharedQuadState>::Iterator iter = list.begin(); |
345 for (std::vector<SharedQuadState*>::const_iterator sqs_iter = | 345 for (std::vector<SharedQuadState*>::const_iterator sqs_iter = |
346 sqs_list.begin(); | 346 sqs_list.begin(); |
347 sqs_iter != sqs_list.end(); | 347 sqs_iter != sqs_list.end(); |
348 ++sqs_iter) { | 348 ++sqs_iter) { |
349 EXPECT_EQ(*sqs_iter, *iter); | 349 EXPECT_EQ(*sqs_iter, *iter); |
350 ++iter; | 350 ++iter; |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 TEST(ListContainerTest, SimpleIterationSharedQuadState) { | 354 TEST(QuadListContainerTest, SimpleIterationSharedQuadState) { |
355 ListContainer<SharedQuadState> list; | 355 ListContainer<SharedQuadState> list; |
356 std::vector<SharedQuadState*> sqs_list; | 356 std::vector<SharedQuadState*> sqs_list; |
357 size_t size = 10; | 357 size_t size = 10; |
358 for (size_t i = 0; i < size; ++i) { | 358 for (size_t i = 0; i < size; ++i) { |
359 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); | 359 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); |
360 } | 360 } |
361 EXPECT_EQ(size, list.size()); | 361 EXPECT_EQ(size, list.size()); |
362 | 362 |
363 size_t num_iters_in_list = 0; | 363 size_t num_iters_in_list = 0; |
364 { | 364 { |
(...skipping 16 matching lines...) Expand all Loading... | |
381 ++sqs_iter) { | 381 ++sqs_iter) { |
382 EXPECT_EQ(*sqs_iter, *iter); | 382 EXPECT_EQ(*sqs_iter, *iter); |
383 ++num_iters_in_vector; | 383 ++num_iters_in_vector; |
384 ++iter; | 384 ++iter; |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 EXPECT_EQ(num_iters_in_vector, num_iters_in_list); | 388 EXPECT_EQ(num_iters_in_vector, num_iters_in_list); |
389 } | 389 } |
390 | 390 |
391 TEST(ListContainerTest, SimpleConstIteratorIterationSharedQuadState) { | 391 TEST(QuadListContainerTest, SimpleConstIteratorIterationSharedQuadState) { |
392 ListContainer<SharedQuadState> list; | 392 ListContainer<SharedQuadState> list; |
393 std::vector<const SharedQuadState*> sqs_list; | 393 std::vector<const SharedQuadState*> sqs_list; |
394 size_t size = 10; | 394 size_t size = 10; |
395 for (size_t i = 0; i < size; ++i) { | 395 for (size_t i = 0; i < size; ++i) { |
396 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); | 396 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); |
397 } | 397 } |
398 EXPECT_EQ(size, list.size()); | 398 EXPECT_EQ(size, list.size()); |
399 | 399 |
400 { | 400 { |
401 std::vector<const SharedQuadState*>::const_iterator sqs_iter = | 401 std::vector<const SharedQuadState*>::const_iterator sqs_iter = |
(...skipping 24 matching lines...) Expand all Loading... | |
426 for (std::vector<const SharedQuadState*>::const_iterator sqs_iter = | 426 for (std::vector<const SharedQuadState*>::const_iterator sqs_iter = |
427 sqs_list.begin(); | 427 sqs_list.begin(); |
428 sqs_iter != sqs_list.end(); | 428 sqs_iter != sqs_list.end(); |
429 ++sqs_iter) { | 429 ++sqs_iter) { |
430 EXPECT_EQ(*sqs_iter, *iter); | 430 EXPECT_EQ(*sqs_iter, *iter); |
431 ++iter; | 431 ++iter; |
432 } | 432 } |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 TEST(ListContainerTest, SimpleReverseInsertionSharedQuadState) { | 436 TEST(QuadListContainerTest, SimpleReverseInsertionSharedQuadState) { |
437 ListContainer<SharedQuadState> list; | 437 ListContainer<SharedQuadState> list; |
438 std::vector<SharedQuadState*> sqs_list; | 438 std::vector<SharedQuadState*> sqs_list; |
439 size_t size = 10; | 439 size_t size = 10; |
440 for (size_t i = 0; i < size; ++i) { | 440 for (size_t i = 0; i < size; ++i) { |
441 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); | 441 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); |
442 } | 442 } |
443 EXPECT_EQ(size, list.size()); | 443 EXPECT_EQ(size, list.size()); |
444 | 444 |
445 { | 445 { |
446 std::vector<SharedQuadState*>::const_reverse_iterator sqs_iter = | 446 std::vector<SharedQuadState*>::const_reverse_iterator sqs_iter = |
(...skipping 11 matching lines...) Expand all Loading... | |
458 for (std::vector<SharedQuadState*>::reverse_iterator sqs_iter = | 458 for (std::vector<SharedQuadState*>::reverse_iterator sqs_iter = |
459 sqs_list.rbegin(); | 459 sqs_list.rbegin(); |
460 sqs_iter != sqs_list.rend(); | 460 sqs_iter != sqs_list.rend(); |
461 ++sqs_iter) { | 461 ++sqs_iter) { |
462 EXPECT_EQ(*sqs_iter, *iter); | 462 EXPECT_EQ(*sqs_iter, *iter); |
463 ++iter; | 463 ++iter; |
464 } | 464 } |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 TEST(ListContainerTest, SimpleDeletion) { | 468 TEST(QuadListContainerTest, SimpleDeletion) { |
469 ListContainer<DrawQuad> list(kLargestQuadSize); | 469 ListContainer<DrawQuad> list(kLargestQuadSize); |
470 std::vector<SimpleDrawQuad*> sdq_list; | 470 std::vector<SimpleDrawQuad*> sdq_list; |
471 size_t size = 10; | 471 size_t size = 10; |
472 for (size_t i = 0; i < size; ++i) { | 472 for (size_t i = 0; i < size; ++i) { |
473 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); | 473 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); |
474 sdq_list.back()->set_value(i); | 474 sdq_list.back()->set_value(i); |
475 } | 475 } |
476 EXPECT_EQ(size, list.size()); | 476 EXPECT_EQ(size, list.size()); |
477 | 477 |
478 list.EraseAndInvalidateAllPointers(list.begin()); | 478 list.EraseAndInvalidateAllPointers(list.begin()); |
479 --size; | 479 --size; |
480 EXPECT_EQ(size, list.size()); | 480 EXPECT_EQ(size, list.size()); |
481 int i = 1; | 481 int i = 1; |
482 for (ListContainer<DrawQuad>::Iterator iter = list.begin(); | 482 for (ListContainer<DrawQuad>::Iterator iter = list.begin(); |
483 iter != list.end(); | 483 iter != list.end(); |
484 ++iter) { | 484 ++iter) { |
485 EXPECT_EQ(i, static_cast<SimpleDrawQuad*>(*iter)->get_value()); | 485 EXPECT_EQ(i, static_cast<SimpleDrawQuad*>(*iter)->get_value()); |
486 ++i; | 486 ++i; |
487 } | 487 } |
488 } | 488 } |
489 | 489 |
490 TEST(ListContainerTest, DeletionAllInAllocation) { | 490 TEST(QuadListContainerTest, DeletionAllInAllocation) { |
491 const size_t kReserve = 10; | 491 const size_t kReserve = 10; |
492 ListContainer<DrawQuad> list(kLargestQuadSize, kReserve); | 492 ListContainer<DrawQuad> list(kLargestQuadSize, kReserve); |
493 std::vector<SimpleDrawQuad*> sdq_list; | 493 std::vector<SimpleDrawQuad*> sdq_list; |
494 // Add enough quads to cause another allocation. | 494 // Add enough quads to cause another allocation. |
495 for (size_t i = 0; i < kReserve + 1; ++i) { | 495 for (size_t i = 0; i < kReserve + 1; ++i) { |
496 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); | 496 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); |
497 sdq_list.back()->set_value(static_cast<int>(i)); | 497 sdq_list.back()->set_value(static_cast<int>(i)); |
498 } | 498 } |
499 EXPECT_EQ(kReserve + 1, list.size()); | 499 EXPECT_EQ(kReserve + 1, list.size()); |
500 | 500 |
501 // Remove everything in the first allocation. | 501 // Remove everything in the first allocation. |
502 for (size_t i = 0; i < kReserve; ++i) | 502 for (size_t i = 0; i < kReserve; ++i) |
503 list.EraseAndInvalidateAllPointers(list.begin()); | 503 list.EraseAndInvalidateAllPointers(list.begin()); |
504 EXPECT_EQ(1u, list.size()); | 504 EXPECT_EQ(1u, list.size()); |
505 | 505 |
506 // The last quad is left. | 506 // The last quad is left. |
507 SimpleDrawQuad* quad = static_cast<SimpleDrawQuad*>(*list.begin()); | 507 SimpleDrawQuad* quad = static_cast<SimpleDrawQuad*>(*list.begin()); |
508 EXPECT_EQ(static_cast<int>(kReserve), quad->get_value()); | 508 EXPECT_EQ(static_cast<int>(kReserve), quad->get_value()); |
509 | 509 |
510 // Remove the quad from the 2nd allocation. | 510 // Remove the quad from the 2nd allocation. |
511 list.EraseAndInvalidateAllPointers(list.begin()); | 511 list.EraseAndInvalidateAllPointers(list.begin()); |
512 EXPECT_EQ(0u, list.size()); | 512 EXPECT_EQ(0u, list.size()); |
513 } | 513 } |
514 | 514 |
515 TEST(ListContainerTest, DeletionAllInAllocationReversed) { | 515 TEST(QuadListContainerTest, DeletionAllInAllocationReversed) { |
516 const size_t kReserve = 10; | 516 const size_t kReserve = 10; |
517 ListContainer<DrawQuad> list(kLargestQuadSize, kReserve); | 517 ListContainer<DrawQuad> list(kLargestQuadSize, kReserve); |
518 std::vector<SimpleDrawQuad*> sdq_list; | 518 std::vector<SimpleDrawQuad*> sdq_list; |
519 // Add enough quads to cause another allocation. | 519 // Add enough quads to cause another allocation. |
520 for (size_t i = 0; i < kReserve + 1; ++i) { | 520 for (size_t i = 0; i < kReserve + 1; ++i) { |
521 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); | 521 sdq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); |
522 sdq_list.back()->set_value(static_cast<int>(i)); | 522 sdq_list.back()->set_value(static_cast<int>(i)); |
523 } | 523 } |
524 EXPECT_EQ(kReserve + 1, list.size()); | 524 EXPECT_EQ(kReserve + 1, list.size()); |
525 | 525 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 | 561 |
562 // Can forward iterate too. | 562 // Can forward iterate too. |
563 i = 0; | 563 i = 0; |
564 for (auto it = list.begin(); it != list.end(); ++it) { | 564 for (auto it = list.begin(); it != list.end(); ++it) { |
565 SimpleDrawQuad* quad = static_cast<SimpleDrawQuad*>(*it); | 565 SimpleDrawQuad* quad = static_cast<SimpleDrawQuad*>(*it); |
566 EXPECT_EQ(static_cast<int>(i), quad->get_value()); | 566 EXPECT_EQ(static_cast<int>(i), quad->get_value()); |
567 ++i; | 567 ++i; |
568 } | 568 } |
569 } | 569 } |
570 | 570 |
571 TEST(ListContainerTest, SimpleIterationAndManipulation) { | 571 TEST(QuadListContainerTest, SimpleIterationAndManipulation) { |
572 ListContainer<DrawQuad> list(kLargestQuadSize); | 572 ListContainer<DrawQuad> list(kLargestQuadSize); |
573 std::vector<SimpleDrawQuad*> sdq_list; | 573 std::vector<SimpleDrawQuad*> sdq_list; |
574 size_t size = 10; | 574 size_t size = 10; |
575 for (size_t i = 0; i < size; ++i) { | 575 for (size_t i = 0; i < size; ++i) { |
576 SimpleDrawQuad* simple_dq = list.AllocateAndConstruct<SimpleDrawQuad>(); | 576 SimpleDrawQuad* simple_dq = list.AllocateAndConstruct<SimpleDrawQuad>(); |
577 sdq_list.push_back(simple_dq); | 577 sdq_list.push_back(simple_dq); |
578 } | 578 } |
579 EXPECT_EQ(size, list.size()); | 579 EXPECT_EQ(size, list.size()); |
580 | 580 |
581 ListContainer<DrawQuad>::Iterator iter = list.begin(); | 581 ListContainer<DrawQuad>::Iterator iter = list.begin(); |
582 for (int i = 0; i < 10; ++i) { | 582 for (int i = 0; i < 10; ++i) { |
583 static_cast<SimpleDrawQuad*>(*iter)->set_value(i); | 583 static_cast<SimpleDrawQuad*>(*iter)->set_value(i); |
584 ++iter; | 584 ++iter; |
585 } | 585 } |
586 | 586 |
587 int i = 0; | 587 int i = 0; |
588 for (std::vector<SimpleDrawQuad*>::const_iterator sdq_iter = sdq_list.begin(); | 588 for (std::vector<SimpleDrawQuad*>::const_iterator sdq_iter = sdq_list.begin(); |
589 sdq_iter < sdq_list.end(); | 589 sdq_iter < sdq_list.end(); |
590 ++sdq_iter) { | 590 ++sdq_iter) { |
591 EXPECT_EQ(i, (*sdq_iter)->get_value()); | 591 EXPECT_EQ(i, (*sdq_iter)->get_value()); |
592 ++i; | 592 ++i; |
593 } | 593 } |
594 } | 594 } |
595 | 595 |
596 TEST(ListContainerTest, SimpleManipulationWithIndexSimpleDrawQuad) { | 596 TEST(QuadListContainerTest, SimpleManipulationWithIndexSimpleDrawQuad) { |
597 ListContainer<DrawQuad> list(kLargestQuadSize); | 597 ListContainer<DrawQuad> list(kLargestQuadSize); |
598 std::vector<SimpleDrawQuad*> dq_list; | 598 std::vector<SimpleDrawQuad*> dq_list; |
599 size_t size = 10; | 599 size_t size = 10; |
600 for (size_t i = 0; i < size; ++i) { | 600 for (size_t i = 0; i < size; ++i) { |
601 dq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); | 601 dq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); |
602 } | 602 } |
603 EXPECT_EQ(size, list.size()); | 603 EXPECT_EQ(size, list.size()); |
604 | 604 |
605 for (size_t i = 0; i < size; ++i) { | 605 for (size_t i = 0; i < size; ++i) { |
606 static_cast<SimpleDrawQuad*>(list.ElementAt(i))->set_value(i); | 606 static_cast<SimpleDrawQuad*>(list.ElementAt(i))->set_value(i); |
607 } | 607 } |
608 | 608 |
609 int i = 0; | 609 int i = 0; |
610 for (std::vector<SimpleDrawQuad*>::const_iterator dq_iter = dq_list.begin(); | 610 for (std::vector<SimpleDrawQuad*>::const_iterator dq_iter = dq_list.begin(); |
611 dq_iter != dq_list.end(); | 611 dq_iter != dq_list.end(); |
612 ++dq_iter, ++i) { | 612 ++dq_iter, ++i) { |
613 EXPECT_EQ(i, (*dq_iter)->get_value()); | 613 EXPECT_EQ(i, (*dq_iter)->get_value()); |
614 } | 614 } |
615 } | 615 } |
616 | 616 |
617 TEST(ListContainerTest, | 617 TEST(QuadListContainerTest, |
618 SimpleManipulationWithIndexMoreThanOneAllocationSimpleDrawQuad) { | 618 SimpleManipulationWithIndexMoreThanOneAllocationSimpleDrawQuad) { |
619 ListContainer<DrawQuad> list(LargestDrawQuadSize(), 2); | 619 ListContainer<DrawQuad> list(LargestDrawQuadSize(), 2); |
620 std::vector<SimpleDrawQuad*> dq_list; | 620 std::vector<SimpleDrawQuad*> dq_list; |
621 size_t size = 10; | 621 size_t size = 10; |
622 for (size_t i = 0; i < size; ++i) { | 622 for (size_t i = 0; i < size; ++i) { |
623 dq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); | 623 dq_list.push_back(list.AllocateAndConstruct<SimpleDrawQuad>()); |
624 } | 624 } |
625 EXPECT_EQ(size, list.size()); | 625 EXPECT_EQ(size, list.size()); |
626 | 626 |
627 for (size_t i = 0; i < size; ++i) { | 627 for (size_t i = 0; i < size; ++i) { |
628 static_cast<SimpleDrawQuad*>(list.ElementAt(i))->set_value(i); | 628 static_cast<SimpleDrawQuad*>(list.ElementAt(i))->set_value(i); |
629 } | 629 } |
630 | 630 |
631 int i = 0; | 631 int i = 0; |
632 for (std::vector<SimpleDrawQuad*>::const_iterator dq_iter = dq_list.begin(); | 632 for (std::vector<SimpleDrawQuad*>::const_iterator dq_iter = dq_list.begin(); |
633 dq_iter != dq_list.end(); | 633 dq_iter != dq_list.end(); |
634 ++dq_iter, ++i) { | 634 ++dq_iter, ++i) { |
635 EXPECT_EQ(i, (*dq_iter)->get_value()); | 635 EXPECT_EQ(i, (*dq_iter)->get_value()); |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
639 TEST(ListContainerTest, | 639 TEST(QuadListContainerTest, |
640 SimpleIterationAndReverseIterationWithIndexSharedQuadState) { | 640 SimpleIterationAndReverseIterationWithIndexSharedQuadState) { |
641 ListContainer<SharedQuadState> list; | 641 ListContainer<SharedQuadState> list; |
642 std::vector<SharedQuadState*> sqs_list; | 642 std::vector<SharedQuadState*> sqs_list; |
643 size_t size = 10; | 643 size_t size = 10; |
644 for (size_t i = 0; i < size; ++i) { | 644 for (size_t i = 0; i < size; ++i) { |
645 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); | 645 sqs_list.push_back(list.AllocateAndConstruct<SharedQuadState>()); |
646 } | 646 } |
647 EXPECT_EQ(size, list.size()); | 647 EXPECT_EQ(size, list.size()); |
648 | 648 |
649 size_t i = 0; | 649 size_t i = 0; |
650 for (ListContainer<SharedQuadState>::Iterator iter = list.begin(); | 650 for (ListContainer<SharedQuadState>::Iterator iter = list.begin(); |
651 iter != list.end(); | 651 iter != list.end(); |
652 ++iter) { | 652 ++iter) { |
653 EXPECT_EQ(i, iter.index()); | 653 EXPECT_EQ(i, iter.index()); |
654 ++i; | 654 ++i; |
655 } | 655 } |
656 | 656 |
657 i = 0; | 657 i = 0; |
658 for (ListContainer<SharedQuadState>::ReverseIterator iter = list.rbegin(); | 658 for (ListContainer<SharedQuadState>::ReverseIterator iter = list.rbegin(); |
659 iter != list.rend(); | 659 iter != list.rend(); |
660 ++iter) { | 660 ++iter) { |
661 EXPECT_EQ(i, iter.index()); | 661 EXPECT_EQ(i, iter.index()); |
662 ++i; | 662 ++i; |
663 } | 663 } |
664 } | 664 } |
665 | 665 |
666 } // namespace | 666 } // namespace |
667 } // namespace cc | 667 } // namespace cc |
OLD | NEW |