1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #define TIMELOG
27
28 #include "gtest/gtest.h"
29 #include <bparr.hxx>
30 #include <string>
31 #include <stdlib.h>
32 #include <rtl/logfile.hxx>
33
34 #undef ENABLE_DEBUG_OUTPUT
35
36 // FIXME:
37 #define RUN_OLD_FAILING_TESTS 0
38
39 using namespace std;
40
41
42 namespace /* private */
43 {
44 const int NUM_ENTRIES = 1000;
45
46 class BigPtrEntryMock : public BigPtrEntry
47 {
48 public:
BigPtrEntryMock(int count)49 BigPtrEntryMock(int count) : count_(count)
50 {
51 }
52
~BigPtrEntryMock()53 ~BigPtrEntryMock()
54 {
55 #ifdef ENABLE_DEBUG_OUTPUT
56 printf("Destructor called (%i)\n", count_);
57 #endif
58 }
59
getCount() const60 int getCount() const
61 {
62 return count_;
63 }
64
setCount(int newCount)65 void setCount(int newCount)
66 {
67 count_ = newCount;
68 }
69
Position() const70 sal_uLong Position() const
71 {
72 return GetPos();
73 }
74
75 private:
76 int count_;
77 };
78
AddToCount(const ElementPtr & rElem,void * pArgs)79 sal_Bool AddToCount(const ElementPtr& rElem, void* pArgs)
80 {
81 BigPtrEntryMock* const pbem = static_cast<BigPtrEntryMock* const>(rElem);
82 pbem->setCount(pbem->getCount() + *((int*)pArgs));
83 return true;
84 }
85
dumpBigPtrArray(const BigPtrArray & bparr)86 void dumpBigPtrArray(const BigPtrArray& bparr)
87 {
88 #ifdef ENABLE_DEBUG_OUTPUT
89 for (int i = 0; i < bparr.Count(); i++)
90 printf("bparr[%i,%i]: %i\n", i, static_cast<BigPtrEntryMock*>(bparr[i])->Position(), static_cast<BigPtrEntryMock*>(bparr[i])->getCount());
91
92 printf("\n");
93 #endif
94 }
95
fillBigPtrArray(BigPtrArray & bparr,sal_uLong numEntries)96 void fillBigPtrArray(BigPtrArray& bparr, sal_uLong numEntries)
97 {
98 for (int i = 0; i < numEntries; i++)
99 bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
100 }
101
printMethodName(const char * name)102 void printMethodName(const char* name)
103 {
104 #ifdef ENABLE_DEBUG_OUTPUT
105 printf(name);
106 #endif
107 }
108
checkElementPositions(const BigPtrArray & bparr)109 bool checkElementPositions(const BigPtrArray& bparr)
110 {
111 for (int i = 0; i < bparr.Count(); i++)
112 {
113 if (static_cast<BigPtrEntryMock*>(bparr[i])->Position() != i)
114 return false;
115 }
116 return true;
117 }
118
releaseBigPtrArrayContent(BigPtrArray & bparr)119 void releaseBigPtrArrayContent(BigPtrArray& bparr)
120 {
121 for (int i = 0; i < bparr.Count(); i++)
122 delete bparr[i];
123 }
124
125 RTL_LOGFILE_CONTEXT(logFile, "BigPtrArray performance measures" );
126 }
127
128 class BigPtrArrayUnittest : public ::testing::Test
129 {
130 public:
131
BigPtrArrayUnittest()132 BigPtrArrayUnittest()
133 {
134 }
135 };
136
137 /** Test constructor/destructor
138 The size of the BigPtrArray
139 aka the 'Count' should be 0
140 initially.
141 */
TEST_F(BigPtrArrayUnittest,test_ctor)142 TEST_F(BigPtrArrayUnittest, test_ctor)
143 {
144 printMethodName("test_ctor\n");
145
146 BigPtrArray bparr;
147
148 ASSERT_TRUE(bparr.Count() == 0) << "BigPtrArray ctor failed";;
149 }
150
TEST_F(BigPtrArrayUnittest,test_insert_entries_at_front)151 TEST_F(BigPtrArrayUnittest, test_insert_entries_at_front)
152 {
153 printMethodName("test_insert_entries_at_front\n");
154
155 RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_at_front");
156
157 BigPtrArray bparr;
158
159 for (int i = 0; i < NUM_ENTRIES; i++)
160 {
161 sal_uLong oldCount = bparr.Count();
162 bparr.Insert(new BigPtrEntryMock(i), 0);
163 ASSERT_TRUE((bparr.Count() == oldCount + 1)) << "test_insert_entries_at_front failed";
164 }
165
166 RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_at_front");
167
168 for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
169 {
170 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j) << "test_insert_entries_at_front failed";
171 }
172
173 ASSERT_TRUE(checkElementPositions(bparr)) << "test_insert_entries_at_front failed";
174
175 releaseBigPtrArrayContent(bparr);
176 dumpBigPtrArray(bparr);
177 }
178
TEST_F(BigPtrArrayUnittest,test_insert_entries_in_the_middle)179 TEST_F(BigPtrArrayUnittest, test_insert_entries_in_the_middle)
180 {
181 printMethodName("test_insert_entries_in_the_middle\n");
182
183 RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_in_the_middle");
184
185 BigPtrArray bparr;
186
187 fillBigPtrArray(bparr, NUM_ENTRIES);
188 dumpBigPtrArray(bparr);
189
190 sal_uLong oldCount = bparr.Count();
191
192 bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count() / 2);
193
194 RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_in_the_middle");
195
196 ASSERT_TRUE((oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount() == NUM_ENTRIES)) << "test_insert_entries_in_the_middle failed";
197
198 ASSERT_TRUE(checkElementPositions(bparr)) << "test_insert_entries_in_the_middle failed";
199
200 releaseBigPtrArrayContent(bparr);
201 dumpBigPtrArray(bparr);
202 }
203
TEST_F(BigPtrArrayUnittest,test_insert_at_already_used_index)204 TEST_F(BigPtrArrayUnittest, test_insert_at_already_used_index)
205 {
206 printMethodName("test_insert_at_already_used_index\n");
207
208 RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_at_already_used_index");
209
210 BigPtrArray bparr;
211
212 fillBigPtrArray(bparr, NUM_ENTRIES);
213 dumpBigPtrArray(bparr);
214
215 int oldCount = bparr.Count();
216
217 for (int i = 0, j = -5; i < 5; i++, j++)
218 bparr.Insert(new BigPtrEntryMock(j), i);
219
220 RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_at_already_used_index");
221
222 ASSERT_TRUE((oldCount + 5 == bparr.Count())) << "test_insert_at_already_used_index failed";
223
224 for (int i = 0, j = -5; i < bparr.Count(); i++, j++)
225 {
226 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j) << "test_insert_at_already_used_index failed";
227 }
228
229 ASSERT_TRUE(checkElementPositions(bparr)) << "test_insert_at_already_used_index failed";
230
231 releaseBigPtrArrayContent(bparr);
232 dumpBigPtrArray(bparr);
233 }
234
TEST_F(BigPtrArrayUnittest,test_insert_at_end)235 TEST_F(BigPtrArrayUnittest, test_insert_at_end)
236 {
237 printMethodName("test_insert_at_end\n");
238
239 BigPtrArray bparr;
240
241 fillBigPtrArray(bparr, NUM_ENTRIES);
242 dumpBigPtrArray(bparr);
243
244 sal_uLong oldCount = bparr.Count();
245 bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count());
246
247 ASSERT_TRUE((oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count()-1])->getCount() == NUM_ENTRIES)) << "test_insert_at_end failed";
248
249 ASSERT_TRUE(checkElementPositions(bparr)) << "test_insert_at_end failed";
250
251 releaseBigPtrArrayContent(bparr);
252 dumpBigPtrArray(bparr);
253 }
254
TEST_F(BigPtrArrayUnittest,test_remove_at_front)255 TEST_F(BigPtrArrayUnittest, test_remove_at_front)
256 {
257 printMethodName("test_remove_at_front\n");
258
259 RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_at_front");
260
261 BigPtrArray bparr;
262
263 fillBigPtrArray(bparr, NUM_ENTRIES);
264 dumpBigPtrArray(bparr);
265
266 for (int i = 0; i < NUM_ENTRIES; i++)
267 {
268 sal_uLong oldCount = bparr.Count();
269
270 delete bparr[0]; // release content
271 bparr.Remove(0); // remove item from container
272
273 ASSERT_TRUE((oldCount - 1 == bparr.Count())) << "test_remove_at_front failed (wrong count)";
274
275 for (int j = 0, k = i + 1; j < bparr.Count(); j++, k++)
276 {
277 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == k) << "test_remove_at_front failed";
278 }
279
280 ASSERT_TRUE(checkElementPositions(bparr)) << "test_remove_at_front failed";
281
282 dumpBigPtrArray(bparr);
283 }
284
285 RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_at_front");
286 }
287
TEST_F(BigPtrArrayUnittest,test_remove_at_back)288 TEST_F(BigPtrArrayUnittest, test_remove_at_back)
289 {
290 printMethodName("test_remove_at_back\n");
291
292 BigPtrArray bparr;
293
294 fillBigPtrArray(bparr, NUM_ENTRIES);
295 dumpBigPtrArray(bparr);
296
297 for (int i = NUM_ENTRIES - 1; i >= 0; i--)
298 {
299 sal_uLong oldCount = bparr.Count();
300 delete bparr[i];
301 bparr.Remove(i);
302
303 ASSERT_TRUE((oldCount - 1 == bparr.Count())) << "test_remove_at_back failed (wrong count)";
304
305 for (int j = 0; j < bparr.Count(); j++)
306 {
307 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == j) << "test_remove_at_back failed";
308 }
309
310 ASSERT_TRUE(checkElementPositions(bparr)) << "test_remove_at_back failed";
311
312 dumpBigPtrArray(bparr);
313 }
314 }
315
TEST_F(BigPtrArrayUnittest,test_remove_in_the_middle)316 TEST_F(BigPtrArrayUnittest, test_remove_in_the_middle)
317 {
318 printMethodName("test_remove_in_the_middle\n");
319
320 RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_in_the_middle");
321
322 BigPtrArray bparr;
323
324 fillBigPtrArray(bparr, NUM_ENTRIES);
325 dumpBigPtrArray(bparr);
326
327 while (bparr.Count())
328 {
329 sal_uLong oldCount = bparr.Count();
330 int oldElement = static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount();
331
332 delete bparr[bparr.Count() / 2];
333 bparr.Remove(bparr.Count() / 2);
334
335 ASSERT_TRUE((oldCount - 1 == bparr.Count())) << "test_remove_in_the_middle failed (wrong count)";
336
337 for (int i = 0; i < bparr.Count(); i++)
338 {
339 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() != oldElement) << "test_remove_in_the_middle failed";
340 }
341
342 ASSERT_TRUE(checkElementPositions(bparr)) << "test_remove_in_the_middle failed";
343
344 dumpBigPtrArray(bparr);
345 }
346 RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_in_the_middle");
347 }
348
TEST_F(BigPtrArrayUnittest,test_remove_multiple_elements_at_once)349 TEST_F(BigPtrArrayUnittest, test_remove_multiple_elements_at_once)
350 {
351 printMethodName("test_remove_multiple_elements_at_once\n");
352
353 BigPtrArray bparr;
354
355 fillBigPtrArray(bparr, NUM_ENTRIES);
356 dumpBigPtrArray(bparr);
357
358 while(bparr.Count())
359 {
360 sal_uLong nRemove = (bparr.Count() > 3) ? 3 : bparr.Count();
361 sal_uLong oldCount = bparr.Count();
362
363 for (int i = 0; i < nRemove; i++)
364 delete bparr[i];
365
366 bparr.Remove(0, nRemove);
367
368 ASSERT_TRUE((oldCount - nRemove == bparr.Count())) << "test_remove_multiple_elements_at_once failed";
369
370 ASSERT_TRUE(checkElementPositions(bparr)) << "test_remove_multiple_elements_at_once failed";
371
372 dumpBigPtrArray(bparr);
373 }
374 }
375
TEST_F(BigPtrArrayUnittest,test_remove_all_elements_at_once)376 TEST_F(BigPtrArrayUnittest, test_remove_all_elements_at_once)
377 {
378 printMethodName("test_remove_all_elements_at_once\n");
379
380 BigPtrArray bparr;
381
382 fillBigPtrArray(bparr, NUM_ENTRIES);
383 dumpBigPtrArray(bparr);
384
385 releaseBigPtrArrayContent(bparr);
386 bparr.Remove(0, bparr.Count());
387
388 ASSERT_TRUE(bparr.Count() == 0) << "test_remove_all_elements_at_once failed";
389
390 dumpBigPtrArray(bparr);
391 }
392
TEST_F(BigPtrArrayUnittest,test_move_elements_from_lower_to_higher_pos)393 TEST_F(BigPtrArrayUnittest, test_move_elements_from_lower_to_higher_pos)
394 {
395 printMethodName("test_move_elements_from_lower_to_higher_pos\n");
396
397 BigPtrArray bparr;
398
399 fillBigPtrArray(bparr, NUM_ENTRIES);
400 dumpBigPtrArray(bparr);
401
402 for (int i = 0; i < NUM_ENTRIES - 1; i++)
403 {
404 bparr.Move(i, i + 2);
405 dumpBigPtrArray(bparr);
406 }
407
408 for (int i = 0; i < (NUM_ENTRIES - 1); i++)
409 {
410 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i + 1)) << "test_move_elements_from_lower_to_higher_pos failed";
411 }
412
413 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[NUM_ENTRIES -1])->getCount() == 0) << "test_move_elements_from_lower_to_higher_pos failed";
414
415 ASSERT_TRUE(checkElementPositions(bparr)) << "test_move_elements_from_lower_to_higher_pos failed";
416
417 releaseBigPtrArrayContent(bparr);
418 }
419
TEST_F(BigPtrArrayUnittest,test_move_elements_from_higher_to_lower_pos)420 TEST_F(BigPtrArrayUnittest, test_move_elements_from_higher_to_lower_pos)
421 {
422 printMethodName("test_move_elements_from_higher_to_lower_pos\n");
423
424 BigPtrArray bparr;
425
426 fillBigPtrArray(bparr, NUM_ENTRIES);
427 dumpBigPtrArray(bparr);
428
429 for (int i = NUM_ENTRIES - 1; i >= 1; i--)
430 {
431 bparr.Move(i, i - 1);
432 dumpBigPtrArray(bparr);
433 }
434
435 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[0])->getCount() == (NUM_ENTRIES - 1)) << "test_move_elements_from_higher_to_lower_pos failed";
436
437 for (int i = 1; i < NUM_ENTRIES; i++)
438 {
439 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i - 1)) << "test_move_elements_from_higher_to_lower_pos failed";
440 }
441
442 ASSERT_TRUE(checkElementPositions(bparr)) << "test_move_elements_from_higher_to_lower_pos failed";
443
444 releaseBigPtrArrayContent(bparr);
445 }
446
TEST_F(BigPtrArrayUnittest,test_move_to_same_position)447 TEST_F(BigPtrArrayUnittest, test_move_to_same_position)
448 {
449 printMethodName("test_move_to_same_position\n");
450
451 BigPtrArray bparr;
452
453 fillBigPtrArray(bparr, NUM_ENTRIES);
454 dumpBigPtrArray(bparr);
455
456 for (int i = 0; i < NUM_ENTRIES; i++)
457 {
458 bparr.Move(i, i);
459 }
460
461 #if RUN_OLD_FAILING_TESTS
462 ASSERT_TRUE(checkElementPositions(bparr)) << "test_move_to_same_position failed";
463 #endif
464
465 dumpBigPtrArray(bparr);
466
467 for (int i = 0; i < NUM_ENTRIES; i++)
468 {
469 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i) << "test_move_to_same_position failed";
470 }
471
472 #if RUN_OLD_FAILING_TESTS
473 ASSERT_TRUE(checkElementPositions(bparr)) << "test_move_to_same_position failed";
474 #endif
475
476 releaseBigPtrArrayContent(bparr);
477 dumpBigPtrArray(bparr);
478 }
479
TEST_F(BigPtrArrayUnittest,test_replace_elements)480 TEST_F(BigPtrArrayUnittest, test_replace_elements)
481 {
482 printMethodName("test_replace_elements\n");
483
484 BigPtrArray bparr;
485
486 fillBigPtrArray(bparr, NUM_ENTRIES);
487 dumpBigPtrArray(bparr);
488
489 for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
490 {
491 delete bparr[i];
492 bparr.Replace(i, new BigPtrEntryMock(j));
493 dumpBigPtrArray(bparr);
494 }
495
496 for (int i = 0; i < NUM_ENTRIES; i++)
497 {
498 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (NUM_ENTRIES - i - 1)) << "test_replace_elements failed";
499 }
500
501 ASSERT_TRUE(checkElementPositions(bparr)) << "test_replace_elements failed";
502
503 releaseBigPtrArrayContent(bparr);
504 }
505
TEST_F(BigPtrArrayUnittest,test_for_each)506 TEST_F(BigPtrArrayUnittest, test_for_each)
507 {
508 printMethodName("test_for_each\n");
509
510 BigPtrArray bparr;
511
512 fillBigPtrArray(bparr, NUM_ENTRIES);
513 dumpBigPtrArray(bparr);
514
515 int addCount = 1;
516 bparr.ForEach(AddToCount, &addCount);
517
518 for (int i = 0; i < NUM_ENTRIES; i++)
519 {
520 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)) << "test_for_each failed";
521 }
522
523 releaseBigPtrArrayContent(bparr);
524 dumpBigPtrArray(bparr);
525 }
526
TEST_F(BigPtrArrayUnittest,test_for_some1)527 TEST_F(BigPtrArrayUnittest, test_for_some1)
528 {
529 printMethodName("test_for_some1\n");
530
531 BigPtrArray bparr;
532
533 fillBigPtrArray(bparr, NUM_ENTRIES);
534 dumpBigPtrArray(bparr);
535
536 int addCount = 1;
537 bparr.ForEach(0, NUM_ENTRIES / 2, AddToCount, &addCount);
538
539 int i = 0;
540 for (/* */; i < NUM_ENTRIES / 2; i++)
541 {
542 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)) << "test_for_some1 failed";
543 }
544
545 for (/* */; i < NUM_ENTRIES; i++)
546 {
547 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)) << "test_for_some1 failed";
548 }
549
550 releaseBigPtrArrayContent(bparr);
551 dumpBigPtrArray(bparr);
552 }
553
TEST_F(BigPtrArrayUnittest,test_for_some2)554 TEST_F(BigPtrArrayUnittest, test_for_some2)
555 {
556 printMethodName("test_for_some2\n");
557
558 BigPtrArray bparr;
559
560 fillBigPtrArray(bparr, NUM_ENTRIES);
561 dumpBigPtrArray(bparr);
562
563 int addCount = 1;
564 bparr.ForEach(NUM_ENTRIES / 2, NUM_ENTRIES, AddToCount, &addCount);
565
566 int i = 0;
567 for (/* */; i < NUM_ENTRIES / 2; i++)
568 {
569 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)) << "test_for_some2 failed";
570 }
571
572 for (/* */; i < NUM_ENTRIES; i++)
573 {
574 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)) << "test_for_some2 failed";
575 }
576
577 releaseBigPtrArrayContent(bparr);
578 dumpBigPtrArray(bparr);
579 }
580
TEST_F(BigPtrArrayUnittest,test_for_some3)581 TEST_F(BigPtrArrayUnittest, test_for_some3)
582 {
583 printMethodName("test_for_some3\n");
584
585 BigPtrArray bparr;
586
587 fillBigPtrArray(bparr, NUM_ENTRIES);
588 dumpBigPtrArray(bparr);
589
590 int addCount = 1;
591 bparr.ForEach(0, 0, AddToCount, &addCount);
592
593 for (int i = 0; i < NUM_ENTRIES; i++)
594 {
595 ASSERT_TRUE(static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i) << "test_for_some3 failed";
596 }
597 releaseBigPtrArrayContent(bparr);
598 }
599
600
601 const char* START = "START: ";
602 const char* END = "END: ";
603
604 class PerformanceTracer
605 {
606 public:
607
608 public:
PerformanceTracer(const string & methodName)609 PerformanceTracer(const string& methodName) :
610 startString_(START),
611 endString_(END)
612 {
613 startString_ += methodName;
614 endString_ += methodName;
615 RTL_LOGFILE_CONTEXT_TRACE(logFile, startString_.c_str());
616 }
617
~PerformanceTracer()618 ~PerformanceTracer()
619 {
620 RTL_LOGFILE_CONTEXT_TRACE(logFile, endString_.c_str());
621 }
622
623 private:
624 string startString_;
625 string endString_;
626 };
627
628 class BigPtrArrayPerformanceTest : public ::testing::Test
629 {
630 public:
BigPtrArrayPerformanceTest()631 BigPtrArrayPerformanceTest()
632 {
633 }
634
635 protected:
test_insert_at_end(const char * numElements)636 void test_insert_at_end(const char* numElements)
637 {
638 char buff[100] = { 0 };
639 strcat(buff, "test_insert_at_end ");
640 strcat(buff, numElements);
641 int n = atoi(numElements);
642 PerformanceTracer tracer(buff);
643 BigPtrArray bparr;
644 for (int i = 0; i < n; i++)
645 bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
646
647 releaseBigPtrArrayContent(bparr);
648 }
649
test_insert_at_front(const char * numElements)650 void test_insert_at_front(const char* numElements)
651 {
652 char buff[100] = { 0 };
653 strcat(buff, "test_insert_at_front ");
654 strcat(buff, numElements);
655 int n = atoi(numElements);
656 PerformanceTracer tracer(buff);
657 BigPtrArray bparr;
658 for (int i = 0; i < n; i++)
659 bparr.Insert(new BigPtrEntryMock(i), 0);
660
661 releaseBigPtrArrayContent(bparr);
662 }
663 };
664
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_end_1000)665 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_end_1000)
666 { test_insert_at_end("1000"); }
667
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_end_10000)668 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_end_10000)
669 { test_insert_at_end("10000"); }
670
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_end_100000)671 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_end_100000)
672 { test_insert_at_end("100000"); }
673
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_end_1000000)674 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_end_1000000)
675 { test_insert_at_end("1000000"); }
676
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_front_1000)677 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_front_1000)
678 { test_insert_at_front("1000"); }
679
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_front_10000)680 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_front_10000)
681 { test_insert_at_front("10000"); }
682
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_front_100000)683 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_front_100000)
684 { test_insert_at_front("100000"); }
685
TEST_F(BigPtrArrayPerformanceTest,test_insert_at_front_1000000)686 TEST_F(BigPtrArrayPerformanceTest, test_insert_at_front_1000000)
687 { test_insert_at_front("1000000"); }
688
689
690 //#####################################
691
main(int argc,char ** argv)692 int main(int argc, char **argv)
693 {
694 ::testing::InitGoogleTest(&argc, argv);
695 return RUN_ALL_TESTS();
696 }
697