xref: /aoo42x/main/sw/qa/core/Test-BigPtrArray.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #define TIMELOG
31 
32 #include <testshl/simpleheader.hxx>
33 #include <bparr.hxx>
34 #include <string>
35 #include <stdlib.h>
36 #include <rtl/logfile.hxx>
37 
38 #undef ENABLE_DEBUG_OUTPUT
39 
40 using namespace std;
41 
42 
43 namespace /* private */
44 {
45     const int NUM_ENTRIES = 100000;
46 
47     class BigPtrEntryMock : public BigPtrEntry
48     {
49     public:
50         BigPtrEntryMock(int count) : count_(count)
51         {
52         }
53 
54         ~BigPtrEntryMock()
55         {
56         #ifdef ENABLE_DEBUG_OUTPUT
57             printf("Destructor called (%i)\n", count_);
58         #endif
59         }
60 
61         int getCount() const
62         {
63             return count_;
64         }
65 
66         void setCount(int newCount)
67         {
68             count_ = newCount;
69         }
70 
71         sal_uLong Position() const
72         {
73             return GetPos();
74         }
75 
76     private:
77         int count_;
78     };
79 
80     sal_Bool AddToCount(const ElementPtr& rElem, void* pArgs)
81     {
82         BigPtrEntryMock* const pbem = static_cast<BigPtrEntryMock* const>(rElem);
83         pbem->setCount(pbem->getCount() + *((int*)pArgs));
84         return true;
85     }
86 
87     void dumpBigPtrArray(const BigPtrArray& bparr)
88     {
89     #ifdef ENABLE_DEBUG_OUTPUT
90         for (int i = 0; i < bparr.Count(); i++)
91             printf("bparr[%i,%i]: %i\n", i, static_cast<BigPtrEntryMock*>(bparr[i])->Position(), static_cast<BigPtrEntryMock*>(bparr[i])->getCount());
92 
93         printf("\n");
94     #endif
95     }
96 
97     void fillBigPtrArray(BigPtrArray& bparr, sal_uLong numEntries)
98     {
99         for (int i = 0; i < numEntries; i++)
100             bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
101     }
102 
103     void printMethodName(const char* name)
104     {
105     #ifdef ENABLE_DEBUG_OUTPUT
106         printf(name);
107     #endif
108     }
109 
110     bool checkElementPositions(const BigPtrArray& bparr)
111     {
112         for (int i = 0; i < bparr.Count(); i++)
113         {
114             if (static_cast<BigPtrEntryMock*>(bparr[i])->Position() != i)
115                 return false;
116         }
117         return true;
118     }
119 
120     void releaseBigPtrArrayContent(BigPtrArray& bparr)
121     {
122         for (int i = 0; i < bparr.Count(); i++)
123             delete bparr[i];
124     }
125 
126     RTL_LOGFILE_CONTEXT(logFile, "BigPtrArray performance measures" );
127 }
128 
129 class BigPtrArrayUnittest : public CppUnit::TestFixture
130 {
131 public:
132 
133     BigPtrArrayUnittest()
134     {
135     }
136 
137     /** Test constructor/destructor
138         The size of the BigPtrArray
139         aka the 'Count' should be 0
140         initially.
141     */
142     void test_ctor()
143     {
144         printMethodName("test_ctor\n");
145 
146         BigPtrArray bparr;
147 
148         CPPUNIT_ASSERT_MESSAGE
149         (
150             "BigPtrArray ctor failed",
151             bparr.Count() == 0
152         );
153     }
154 
155     void test_insert_entries_at_front()
156     {
157         printMethodName("test_insert_entries_at_front\n");
158 
159         RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_at_front");
160 
161         BigPtrArray bparr;
162 
163         for (int i = 0; i < NUM_ENTRIES; i++)
164         {
165             sal_uLong oldCount = bparr.Count();
166             bparr.Insert(new BigPtrEntryMock(i), 0);
167             CPPUNIT_ASSERT_MESSAGE
168             (
169                 "test_insert_entries_at_front failed",
170                 (bparr.Count() == oldCount + 1)
171             )
172         }
173 
174         RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_at_front");
175 
176         for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
177         {
178             CPPUNIT_ASSERT_MESSAGE
179             (
180                 "test_insert_entries_at_front failed",
181                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j
182             )
183         }
184 
185         CPPUNIT_ASSERT_MESSAGE
186         (
187             "test_insert_entries_at_front failed",
188             checkElementPositions(bparr)
189         )
190 
191         releaseBigPtrArrayContent(bparr);
192         dumpBigPtrArray(bparr);
193     }
194 
195     void test_insert_entries_in_the_middle()
196     {
197         printMethodName("test_insert_entries_in_the_middle\n");
198 
199         RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_in_the_middle");
200 
201         BigPtrArray bparr;
202 
203         fillBigPtrArray(bparr, NUM_ENTRIES);
204         dumpBigPtrArray(bparr);
205 
206         sal_uLong oldCount = bparr.Count();
207 
208         bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count() / 2);
209 
210         RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_in_the_middle");
211 
212         CPPUNIT_ASSERT_MESSAGE
213         (
214             "test_insert_entries_in_the_middle failed",
215             (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount() == NUM_ENTRIES)
216         )
217 
218         CPPUNIT_ASSERT_MESSAGE
219         (
220             "test_insert_entries_in_the_middle failed",
221             checkElementPositions(bparr)
222         )
223 
224         releaseBigPtrArrayContent(bparr);
225         dumpBigPtrArray(bparr);
226     }
227 
228     void test_insert_at_already_used_index()
229     {
230         printMethodName("test_insert_at_already_used_index\n");
231 
232         RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_at_already_used_index");
233 
234         BigPtrArray bparr;
235 
236         fillBigPtrArray(bparr, NUM_ENTRIES);
237         dumpBigPtrArray(bparr);
238 
239         int oldCount = bparr.Count();
240 
241         for (int i = 0, j = -5; i < 5; i++, j++)
242             bparr.Insert(new BigPtrEntryMock(j), i);
243 
244         RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_at_already_used_index");
245 
246         CPPUNIT_ASSERT_MESSAGE
247         (
248             "test_insert_at_already_used_index failed",
249             (oldCount + 5 == bparr.Count())
250         )
251 
252         for (int i = 0, j = -5; i < bparr.Count(); i++, j++)
253         {
254             CPPUNIT_ASSERT_MESSAGE
255             (
256                 "test_insert_at_already_used_index failed",
257                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j
258             )
259         }
260 
261         CPPUNIT_ASSERT_MESSAGE
262         (
263             "test_insert_at_already_used_index failed",
264             checkElementPositions(bparr)
265         )
266 
267         releaseBigPtrArrayContent(bparr);
268         dumpBigPtrArray(bparr);
269     }
270 
271     void test_insert_at_end()
272     {
273         printMethodName("test_insert_at_end\n");
274 
275         BigPtrArray bparr;
276 
277         fillBigPtrArray(bparr, NUM_ENTRIES);
278         dumpBigPtrArray(bparr);
279 
280         sal_uLong oldCount = bparr.Count();
281         bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count());
282 
283         CPPUNIT_ASSERT_MESSAGE
284         (
285             "test_insert_at_end failed",
286             (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count()-1])->getCount() == NUM_ENTRIES)
287         )
288 
289         CPPUNIT_ASSERT_MESSAGE
290         (
291             "test_insert_at_end failed",
292             checkElementPositions(bparr)
293         )
294 
295         releaseBigPtrArrayContent(bparr);
296         dumpBigPtrArray(bparr);
297     }
298 
299     void test_remove_at_front()
300     {
301         printMethodName("test_remove_at_front\n");
302 
303         RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_at_front");
304 
305         BigPtrArray bparr;
306 
307         fillBigPtrArray(bparr, NUM_ENTRIES);
308         dumpBigPtrArray(bparr);
309 
310         for (int i = 0; i < NUM_ENTRIES; i++)
311         {
312             sal_uLong oldCount = bparr.Count();
313 
314             delete bparr[0]; // release content
315             bparr.Remove(0); // remove item from container
316 
317             CPPUNIT_ASSERT_MESSAGE
318             (
319                 "test_remove_at_front failed (wrong count)",
320                 (oldCount - 1 == bparr.Count())
321             )
322 
323             for (int j = 0, k = i + 1; j < bparr.Count(); j++, k++)
324             {
325                 CPPUNIT_ASSERT_MESSAGE
326                 (
327                     "test_remove_at_front failed",
328                     static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == k
329                 )
330             }
331 
332             CPPUNIT_ASSERT_MESSAGE
333             (
334                 "test_remove_at_front failed",
335                 checkElementPositions(bparr)
336             )
337 
338             dumpBigPtrArray(bparr);
339         }
340 
341         RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_at_front");
342     }
343 
344     void test_remove_at_back()
345     {
346         printMethodName("test_remove_at_back\n");
347 
348         BigPtrArray bparr;
349 
350         fillBigPtrArray(bparr, NUM_ENTRIES);
351         dumpBigPtrArray(bparr);
352 
353         for (int i = NUM_ENTRIES - 1; i >= 0; i--)
354         {
355             sal_uLong oldCount = bparr.Count();
356             delete bparr[i];
357             bparr.Remove(i);
358 
359             CPPUNIT_ASSERT_MESSAGE
360             (
361                 "test_remove_at_back failed (wrong count)",
362                 (oldCount - 1 == bparr.Count())
363             )
364 
365             for (int j = 0; j < bparr.Count(); j++)
366             {
367                 CPPUNIT_ASSERT_MESSAGE
368                 (
369                     "test_remove_at_back failed",
370                     static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == j
371                 )
372             }
373 
374             CPPUNIT_ASSERT_MESSAGE
375             (
376                 "test_remove_at_back failed",
377                 checkElementPositions(bparr)
378             )
379 
380             dumpBigPtrArray(bparr);
381         }
382     }
383 
384     void test_remove_in_the_middle()
385     {
386         printMethodName("test_remove_in_the_middle\n");
387 
388         RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_in_the_middle");
389 
390         BigPtrArray bparr;
391 
392         fillBigPtrArray(bparr, NUM_ENTRIES);
393         dumpBigPtrArray(bparr);
394 
395         while (bparr.Count())
396         {
397             sal_uLong oldCount = bparr.Count();
398             int oldElement = static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount();
399 
400             delete bparr[bparr.Count() / 2];
401             bparr.Remove(bparr.Count() / 2);
402 
403             CPPUNIT_ASSERT_MESSAGE
404             (
405                 "test_remove_in_the_middle failed (wrong count)",
406                 (oldCount - 1 == bparr.Count())
407             )
408 
409             for (int i = 0; i < bparr.Count(); i++)
410             {
411                 CPPUNIT_ASSERT_MESSAGE
412                 (
413                     "test_remove_in_the_middle failed",
414                     static_cast<BigPtrEntryMock*>(bparr[i])->getCount() != oldElement
415                 )
416             }
417 
418             CPPUNIT_ASSERT_MESSAGE
419             (
420                 "test_remove_in_the_middle failed",
421                 checkElementPositions(bparr)
422             )
423 
424             dumpBigPtrArray(bparr);
425         }
426         RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_in_the_middle");
427     }
428 
429     void test_remove_multiple_elements_at_once()
430     {
431         printMethodName("test_remove_multiple_elements_at_once\n");
432 
433         BigPtrArray bparr;
434 
435         fillBigPtrArray(bparr, NUM_ENTRIES);
436         dumpBigPtrArray(bparr);
437 
438         while(bparr.Count())
439         {
440             sal_uLong nRemove = (bparr.Count() > 3) ? 3 : bparr.Count();
441             sal_uLong oldCount = bparr.Count();
442 
443             for (int i = 0; i < nRemove; i++)
444                 delete bparr[i];
445 
446             bparr.Remove(0, nRemove);
447 
448             CPPUNIT_ASSERT_MESSAGE
449             (
450                 "test_remove_multiple_elements_at_once failed",
451                 (oldCount - nRemove == bparr.Count())
452             )
453 
454             CPPUNIT_ASSERT_MESSAGE
455             (
456                 "test_remove_multiple_elements_at_once failed",
457                 checkElementPositions(bparr)
458             )
459 
460             dumpBigPtrArray(bparr);
461         }
462     }
463 
464     void test_remove_all_elements_at_once()
465     {
466         printMethodName("test_remove_all_elements_at_once\n");
467 
468         BigPtrArray bparr;
469 
470         fillBigPtrArray(bparr, NUM_ENTRIES);
471         dumpBigPtrArray(bparr);
472 
473         releaseBigPtrArrayContent(bparr);
474         bparr.Remove(0, bparr.Count());
475 
476         CPPUNIT_ASSERT_MESSAGE
477         (
478             "test_remove_all_elements_at_once failed",
479             bparr.Count() == 0
480         )
481 
482         dumpBigPtrArray(bparr);
483     }
484 
485     void test_move_elements_from_lower_to_higher_pos()
486     {
487         printMethodName("test_move_elements_from_lower_to_higher_pos\n");
488 
489         BigPtrArray bparr;
490 
491         fillBigPtrArray(bparr, NUM_ENTRIES);
492         dumpBigPtrArray(bparr);
493 
494         for (int i = 0; i < NUM_ENTRIES - 1; i++)
495         {
496             bparr.Move(i, i + 2);
497             dumpBigPtrArray(bparr);
498         }
499 
500         for (int i = 0; i < (NUM_ENTRIES - 1); i++)
501         {
502             CPPUNIT_ASSERT_MESSAGE
503             (
504                 "test_move_elements_from_lower_to_higher_pos failed",
505                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i + 1)
506             )
507         }
508 
509         CPPUNIT_ASSERT_MESSAGE
510         (
511             "test_move_elements_from_lower_to_higher_pos failed",
512             static_cast<BigPtrEntryMock*>(bparr[NUM_ENTRIES -1])->getCount() == 0
513         )
514 
515         CPPUNIT_ASSERT_MESSAGE
516         (
517             "test_move_elements_from_lower_to_higher_pos failed",
518             checkElementPositions(bparr)
519         )
520 
521         releaseBigPtrArrayContent(bparr);
522     }
523 
524     void test_move_elements_from_higher_to_lower_pos()
525     {
526         printMethodName("test_move_elements_from_higher_to_lower_pos\n");
527 
528         BigPtrArray bparr;
529 
530         fillBigPtrArray(bparr, NUM_ENTRIES);
531         dumpBigPtrArray(bparr);
532 
533         for (int i = NUM_ENTRIES - 1; i >= 1; i--)
534         {
535             bparr.Move(i, i - 1);
536             dumpBigPtrArray(bparr);
537         }
538 
539         CPPUNIT_ASSERT_MESSAGE
540         (
541             "test_move_elements_from_higher_to_lower_pos failed",
542             static_cast<BigPtrEntryMock*>(bparr[0])->getCount() == (NUM_ENTRIES - 1)
543         )
544 
545         for (int i = 1; i < NUM_ENTRIES; i++)
546         {
547             CPPUNIT_ASSERT_MESSAGE
548             (
549                 "test_move_elements_from_higher_to_lower_pos failed",
550                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i - 1)
551             )
552         }
553 
554         CPPUNIT_ASSERT_MESSAGE
555         (
556             "test_move_elements_from_higher_to_lower_pos failed",
557             checkElementPositions(bparr)
558         )
559 
560         releaseBigPtrArrayContent(bparr);
561     }
562 
563     void test_move_to_same_position()
564     {
565         printMethodName("test_move_to_same_position\n");
566 
567         BigPtrArray bparr;
568 
569         fillBigPtrArray(bparr, NUM_ENTRIES);
570         dumpBigPtrArray(bparr);
571 
572         for (int i = 0; i < NUM_ENTRIES; i++)
573         {
574             bparr.Move(i, i);
575         }
576 
577         dumpBigPtrArray(bparr);
578 
579         for (int i = 0; i < NUM_ENTRIES; i++)
580         {
581             CPPUNIT_ASSERT_MESSAGE
582             (
583                 "test_move_to_same_position failed",
584                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i
585             )
586         }
587 
588         CPPUNIT_ASSERT_MESSAGE
589         (
590             "test_move_to_same_position failed",
591             checkElementPositions(bparr)
592         )
593 
594         releaseBigPtrArrayContent(bparr);
595         dumpBigPtrArray(bparr);
596     }
597 
598     void test_replace_elements()
599     {
600         printMethodName("test_replace_elements\n");
601 
602         BigPtrArray bparr;
603 
604         fillBigPtrArray(bparr, NUM_ENTRIES);
605         dumpBigPtrArray(bparr);
606 
607         for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
608         {
609             delete bparr[i];
610             bparr.Replace(i, new BigPtrEntryMock(j));
611             dumpBigPtrArray(bparr);
612         }
613 
614         for (int i = 0; i < NUM_ENTRIES; i++)
615         {
616             CPPUNIT_ASSERT_MESSAGE
617             (
618                 "test_replace_elements failed",
619                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (NUM_ENTRIES - i - 1)
620             )
621         }
622 
623         CPPUNIT_ASSERT_MESSAGE
624         (
625             "test_replace_elements failed",
626             checkElementPositions(bparr)
627         )
628 
629         releaseBigPtrArrayContent(bparr);
630     }
631 
632     void test_for_each()
633     {
634         printMethodName("test_for_each\n");
635 
636         BigPtrArray bparr;
637 
638         fillBigPtrArray(bparr, NUM_ENTRIES);
639         dumpBigPtrArray(bparr);
640 
641         int addCount = 1;
642         bparr.ForEach(AddToCount, &addCount);
643 
644         for (int i = 0; i < NUM_ENTRIES; i++)
645         {
646             CPPUNIT_ASSERT_MESSAGE
647             (
648                 "test_for_each failed",
649                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
650             )
651         }
652 
653         releaseBigPtrArrayContent(bparr);
654         dumpBigPtrArray(bparr);
655     }
656 
657     void test_for_some1()
658     {
659          printMethodName("test_for_some1\n");
660 
661         BigPtrArray bparr;
662 
663         fillBigPtrArray(bparr, NUM_ENTRIES);
664         dumpBigPtrArray(bparr);
665 
666         int addCount = 1;
667         bparr.ForEach(0, NUM_ENTRIES / 2, AddToCount, &addCount);
668 
669         int i = 0;
670         for (/* */; i < NUM_ENTRIES / 2; i++)
671         {
672             CPPUNIT_ASSERT_MESSAGE
673             (
674                 "test_for_some1 failed",
675                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
676             )
677         }
678 
679         for (/* */; i < NUM_ENTRIES; i++)
680         {
681             CPPUNIT_ASSERT_MESSAGE
682             (
683                 "test_for_some1 failed",
684                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)
685             )
686         }
687 
688         releaseBigPtrArrayContent(bparr);
689         dumpBigPtrArray(bparr);
690     }
691 
692     void test_for_some2()
693     {
694         printMethodName("test_for_some2\n");
695 
696         BigPtrArray bparr;
697 
698         fillBigPtrArray(bparr, NUM_ENTRIES);
699         dumpBigPtrArray(bparr);
700 
701         int addCount = 1;
702         bparr.ForEach(NUM_ENTRIES / 2, NUM_ENTRIES, AddToCount, &addCount);
703 
704         int i = 0;
705         for (/* */; i < NUM_ENTRIES / 2; i++)
706         {
707             CPPUNIT_ASSERT_MESSAGE
708             (
709                 "test_for_some2 failed",
710                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)
711             )
712         }
713 
714         for (/* */; i < NUM_ENTRIES; i++)
715         {
716             CPPUNIT_ASSERT_MESSAGE
717             (
718                 "test_for_some2 failed",
719                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
720             )
721         }
722 
723         releaseBigPtrArrayContent(bparr);
724         dumpBigPtrArray(bparr);
725     }
726 
727     void test_for_some3()
728     {
729         printMethodName("test_for_some3\n");
730 
731         BigPtrArray bparr;
732 
733         fillBigPtrArray(bparr, NUM_ENTRIES);
734         dumpBigPtrArray(bparr);
735 
736         int addCount = 1;
737         bparr.ForEach(0, 0, AddToCount, &addCount);
738 
739         for (int i = 0; i < NUM_ENTRIES; i++)
740         {
741             CPPUNIT_ASSERT_MESSAGE
742             (
743                 "test_for_some3 failed",
744                 static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i
745             )
746         }
747         releaseBigPtrArrayContent(bparr);
748     }
749 
750     CPPUNIT_TEST_SUITE(BigPtrArrayUnittest);
751     CPPUNIT_TEST(test_ctor);
752     CPPUNIT_TEST(test_insert_entries_at_front);
753     CPPUNIT_TEST(test_insert_entries_in_the_middle);
754     CPPUNIT_TEST(test_insert_at_already_used_index);
755     CPPUNIT_TEST(test_insert_at_end);
756     CPPUNIT_TEST(test_remove_at_front);
757     CPPUNIT_TEST(test_remove_at_back);
758     CPPUNIT_TEST(test_remove_in_the_middle);
759     CPPUNIT_TEST(test_remove_multiple_elements_at_once);
760     CPPUNIT_TEST(test_remove_all_elements_at_once);
761     CPPUNIT_TEST(test_move_elements_from_lower_to_higher_pos);
762     CPPUNIT_TEST(test_move_elements_from_higher_to_lower_pos);
763     CPPUNIT_TEST(test_replace_elements);
764     CPPUNIT_TEST(test_for_each);
765     CPPUNIT_TEST(test_for_some1);
766     CPPUNIT_TEST(test_for_some2);
767     CPPUNIT_TEST(test_for_some3);
768     CPPUNIT_TEST_SUITE_END();
769 };
770 
771 const char* START = "START: ";
772 const char* END = "END: ";
773 
774 class PerformanceTracer
775 {
776 public:
777 
778 public:
779     PerformanceTracer(const string& methodName) :
780         startString_(START),
781         endString_(END)
782     {
783         startString_ += methodName;
784         endString_ += methodName;
785         RTL_LOGFILE_CONTEXT_TRACE(logFile, startString_.c_str());
786     }
787 
788     ~PerformanceTracer()
789     {
790         RTL_LOGFILE_CONTEXT_TRACE(logFile, endString_.c_str());
791     }
792 
793 private:
794     string startString_;
795     string endString_;
796 };
797 
798 class BigPtrArrayPerformanceTest : public CppUnit::TestFixture
799 {
800 public:
801     BigPtrArrayPerformanceTest()
802     {
803     }
804 
805     void test_insert_at_end_1000()
806     { test_insert_at_end("1000"); }
807 
808     void test_insert_at_end_10000()
809     { test_insert_at_end("10000"); }
810 
811     void test_insert_at_end_100000()
812     { test_insert_at_end("100000"); }
813 
814     void test_insert_at_end_1000000()
815     { test_insert_at_end("1000000"); }
816 
817     void test_insert_at_front_1000()
818     { test_insert_at_front("1000"); }
819 
820     void test_insert_at_front_10000()
821     { test_insert_at_front("10000"); }
822 
823     void test_insert_at_front_100000()
824     { test_insert_at_front("100000"); }
825 
826     void test_insert_at_front_1000000()
827     { test_insert_at_front("1000000"); }
828 
829     CPPUNIT_TEST_SUITE(BigPtrArrayPerformanceTest);
830     CPPUNIT_TEST(test_insert_at_end_1000);
831     CPPUNIT_TEST(test_insert_at_end_10000);
832     CPPUNIT_TEST(test_insert_at_end_100000);
833     CPPUNIT_TEST(test_insert_at_end_1000000);
834     CPPUNIT_TEST(test_insert_at_front_1000);
835     CPPUNIT_TEST(test_insert_at_front_10000);
836     CPPUNIT_TEST(test_insert_at_front_100000);
837     CPPUNIT_TEST(test_insert_at_front_1000000);
838     CPPUNIT_TEST_SUITE_END();
839 
840 private:
841     void test_insert_at_end(const char* numElements)
842     {
843         char buff[100] = { 0 };
844         strcat(buff, "test_insert_at_end ");
845         strcat(buff, numElements);
846         int n = atoi(numElements);
847         PerformanceTracer tracer(buff);
848         BigPtrArray bparr;
849         for (int i = 0; i < n; i++)
850             bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
851 
852         releaseBigPtrArrayContent(bparr);
853     }
854 
855     void test_insert_at_front(const char* numElements)
856     {
857         char buff[100] = { 0 };
858         strcat(buff, "test_insert_at_front ");
859         strcat(buff, numElements);
860         int n = atoi(numElements);
861         PerformanceTracer tracer(buff);
862         BigPtrArray bparr;
863         for (int i = 0; i < n; i++)
864             bparr.Insert(new BigPtrEntryMock(i), 0);
865 
866         releaseBigPtrArrayContent(bparr);
867     }
868 };
869 
870 
871 //#####################################
872 // register test suites
873 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayUnittest, "BigPtrArrayUnittest");
874 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayPerformanceTest, "BigPtrArrayPerformanceTest");
875 
876 NOADDITIONAL;
877 
878