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

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#define TIMELOG

#include <cppunit/simpleheader.hxx>
#include <bparr.hxx>
#include <string>
#include <stdlib.h>
#include <rtl/logfile.hxx>

#undef ENABLE_DEBUG_OUTPUT

using namespace std;


namespace /* private */
{
    const int NUM_ENTRIES = 100000;            
    
    class BigPtrEntryMock : public BigPtrEntry
    {
    public:
        BigPtrEntryMock(int count) : count_(count)
        {
        }
        
        ~BigPtrEntryMock()
        {
        #ifdef ENABLE_DEBUG_OUTPUT
            printf("Destructor called (%i)\n", count_);
        #endif
        }
        
        int getCount() const
        {
            return count_;
        }
        
        void setCount(int newCount)
        {
            count_ = newCount;
        }
        
        ULONG Position() const
        {
            return GetPos();
        }
        
    private:
        int count_;
    };

    BOOL AddToCount(const ElementPtr& rElem, void* pArgs)
    {
        BigPtrEntryMock* const pbem = static_cast<BigPtrEntryMock* const>(rElem);
        pbem->setCount(pbem->getCount() + *((int*)pArgs));
        return true;
    }
    
    void dumpBigPtrArray(const BigPtrArray& bparr)
    {
    #ifdef ENABLE_DEBUG_OUTPUT
        for (int i = 0; i < bparr.Count(); i++)       
            printf("bparr[%i,%i]: %i\n", i, static_cast<BigPtrEntryMock*>(bparr[i])->Position(), static_cast<BigPtrEntryMock*>(bparr[i])->getCount());
        
        printf("\n"); 
    #endif
    }
    
    void fillBigPtrArray(BigPtrArray& bparr, ULONG numEntries)
    {        
        for (int i = 0; i < numEntries; i++)
            bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
    }
    
    void printMethodName(const char* name)
    {
    #ifdef ENABLE_DEBUG_OUTPUT
        printf(name);
    #endif
    }
    
    bool checkElementPositions(const BigPtrArray& bparr)
    {
        for (int i = 0; i < bparr.Count(); i++)
        {
            if (static_cast<BigPtrEntryMock*>(bparr[i])->Position() != i)
                return false;
        }
        return true;
    }        
    
    void releaseBigPtrArrayContent(BigPtrArray& bparr)
    {
        for (int i = 0; i < bparr.Count(); i++)
            delete bparr[i];       
    }

    RTL_LOGFILE_CONTEXT(logFile, "BigPtrArray performance measures" );
}

class BigPtrArrayUnittest : public CppUnit::TestFixture
{
public:
    
    BigPtrArrayUnittest()
    {
    }
    
    /** Test constructor/destructor
        The size of the BigPtrArray 
        aka the 'Count' should be 0 
        initially.
    */
    void test_ctor()
    {               
        printMethodName("test_ctor\n");               
        
        BigPtrArray bparr;                
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "BigPtrArray ctor failed", 
            bparr.Count() == 0
        );            
    }   
    
    void test_insert_entries_at_front()
    {        
        printMethodName("test_insert_entries_at_front\n");
        
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_at_front");
        
        BigPtrArray bparr;                
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            ULONG oldCount = bparr.Count();
            bparr.Insert(new BigPtrEntryMock(i), 0);
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_insert_entries_at_front failed",
                (bparr.Count() == oldCount + 1)
            )
        }
        
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_at_front");
        
        for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_insert_entries_at_front failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_entries_at_front failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);               
    }
    
    void test_insert_entries_in_the_middle()
    {
        printMethodName("test_insert_entries_in_the_middle\n");

        RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_in_the_middle");
        
        BigPtrArray bparr;               
        
        fillBigPtrArray(bparr, NUM_ENTRIES);        
        dumpBigPtrArray(bparr);
        
        ULONG oldCount = bparr.Count();
        
        bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count() / 2);

        RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_in_the_middle");
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_entries_in_the_middle failed",
            (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount() == NUM_ENTRIES)
        )
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_entries_in_the_middle failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);    
    }
    
    void test_insert_at_already_used_index()
    {
        printMethodName("test_insert_at_already_used_index\n");
    
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_at_already_used_index");
        
        BigPtrArray bparr;
                
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        int oldCount = bparr.Count();
        
        for (int i = 0, j = -5; i < 5; i++, j++)
            bparr.Insert(new BigPtrEntryMock(j), i);
        
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_at_already_used_index");
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_at_already_used_index failed",
            (oldCount + 5 == bparr.Count())
        )
        
        for (int i = 0, j = -5; i < bparr.Count(); i++, j++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_insert_at_already_used_index failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_at_already_used_index failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }
    
    void test_insert_at_end()
    {
        printMethodName("test_insert_at_end\n");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        ULONG oldCount = bparr.Count();
        bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count());
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_at_end failed",
            (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count()-1])->getCount() == NUM_ENTRIES)
        )
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_insert_at_end failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }
    
    void test_remove_at_front()
    {
        printMethodName("test_remove_at_front\n");

        RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_at_front");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {   
            ULONG oldCount = bparr.Count();
            
            delete bparr[0]; // release content 
            bparr.Remove(0); // remove item from container      
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_at_front failed (wrong count)",
                (oldCount - 1 == bparr.Count())
            )
            
            for (int j = 0, k = i + 1; j < bparr.Count(); j++, k++)
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    "test_remove_at_front failed",
                    static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == k
                )
            }
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_at_front failed",
                checkElementPositions(bparr)
            )
        
            dumpBigPtrArray(bparr);
        }
        
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_at_front");        
    }
    
    void test_remove_at_back()
    {
        printMethodName("test_remove_at_back\n");
                
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = NUM_ENTRIES - 1; i >= 0; i--)
        {
            ULONG oldCount = bparr.Count();
            delete bparr[i];
            bparr.Remove(i);
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_at_back failed (wrong count)",
                (oldCount - 1 == bparr.Count())
            )
            
            for (int j = 0; j < bparr.Count(); j++)
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    "test_remove_at_back failed",
                    static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == j
                )
            }
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_at_back failed",
                checkElementPositions(bparr)
            )
        
            dumpBigPtrArray(bparr);
        }
    }
    
    void test_remove_in_the_middle()
    {
        printMethodName("test_remove_in_the_middle\n");

        RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_in_the_middle");
        
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        while (bparr.Count())
        {
            ULONG oldCount = bparr.Count();
            int oldElement = static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount();
            
            delete bparr[bparr.Count() / 2];
            bparr.Remove(bparr.Count() / 2);
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_in_the_middle failed (wrong count)",
                (oldCount - 1 == bparr.Count())
            )
            
            for (int i = 0; i < bparr.Count(); i++)
            {
                CPPUNIT_ASSERT_MESSAGE
                (
                    "test_remove_in_the_middle failed",
                    static_cast<BigPtrEntryMock*>(bparr[i])->getCount() != oldElement
                )
            }
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_in_the_middle failed",
                checkElementPositions(bparr)
            )
        
            dumpBigPtrArray(bparr);
        }
        RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_in_the_middle");
    }
    
    void test_remove_multiple_elements_at_once()
    {
        printMethodName("test_remove_multiple_elements_at_once\n");
                
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        while(bparr.Count())
        {
            ULONG nRemove = (bparr.Count() > 3) ? 3 : bparr.Count();
            ULONG oldCount = bparr.Count();
            
            for (int i = 0; i < nRemove; i++)
                delete bparr[i];
            
            bparr.Remove(0, nRemove);      
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_multiple_elements_at_once failed",
                (oldCount - nRemove == bparr.Count())
            )
            
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_remove_multiple_elements_at_once failed",
                checkElementPositions(bparr)
            )
        
            dumpBigPtrArray(bparr);
        }
    }
    
    void test_remove_all_elements_at_once()
    {
        printMethodName("test_remove_all_elements_at_once\n");
        
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        releaseBigPtrArrayContent(bparr);
        bparr.Remove(0, bparr.Count());
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_remove_all_elements_at_once failed",
            bparr.Count() == 0
        )
        
        dumpBigPtrArray(bparr);
    }
   
    void test_move_elements_from_lower_to_higher_pos()
    {
        printMethodName("test_move_elements_from_lower_to_higher_pos\n");
                
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = 0; i < NUM_ENTRIES - 1; i++)
        {
            bparr.Move(i, i + 2);
            dumpBigPtrArray(bparr);
        }        
                
        for (int i = 0; i < (NUM_ENTRIES - 1); i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_move_elements_from_lower_to_higher_pos failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i + 1)
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_move_elements_from_lower_to_higher_pos failed",
            static_cast<BigPtrEntryMock*>(bparr[NUM_ENTRIES -1])->getCount() == 0
        )
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_move_elements_from_lower_to_higher_pos failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
    }
    
    void test_move_elements_from_higher_to_lower_pos()
    {
        printMethodName("test_move_elements_from_higher_to_lower_pos\n");
                
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = NUM_ENTRIES - 1; i >= 1; i--)
        {
            bparr.Move(i, i - 1);
            dumpBigPtrArray(bparr);
        }        
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_move_elements_from_higher_to_lower_pos failed",
            static_cast<BigPtrEntryMock*>(bparr[0])->getCount() == (NUM_ENTRIES - 1)
        )
        
        for (int i = 1; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_move_elements_from_higher_to_lower_pos failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i - 1)
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_move_elements_from_higher_to_lower_pos failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
    }
    
    void test_move_to_same_position()
    {
        printMethodName("test_move_to_same_position\n");
                
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            bparr.Move(i, i);            
        }                
        
        dumpBigPtrArray(bparr);
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_move_to_same_position failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_move_to_same_position failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }
    
    void test_replace_elements()
    {
        printMethodName("test_replace_elements\n");
                
        BigPtrArray bparr;                
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--)
        {
            delete bparr[i];
            bparr.Replace(i, new BigPtrEntryMock(j));
            dumpBigPtrArray(bparr);
        }
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_replace_elements failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (NUM_ENTRIES - i - 1)
            )
        }
        
        CPPUNIT_ASSERT_MESSAGE
        (
            "test_replace_elements failed",
            checkElementPositions(bparr)
        )
        
        releaseBigPtrArrayContent(bparr);
    }
    
    void test_for_each()
    {
        printMethodName("test_for_each\n");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        int addCount = 1;
        bparr.ForEach(AddToCount, &addCount);        
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_each failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
            )
        }
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }

    void test_for_some1()
    {
         printMethodName("test_for_some1\n");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        int addCount = 1;
        bparr.ForEach(0, NUM_ENTRIES / 2, AddToCount, &addCount);        
        
        int i = 0;
        for (/* */; i < NUM_ENTRIES / 2; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_some1 failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
            )
        }
        
        for (/* */; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_some1 failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)
            )
        }
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }
    
    void test_for_some2()
    {
        printMethodName("test_for_some2\n");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        int addCount = 1;
        bparr.ForEach(NUM_ENTRIES / 2, NUM_ENTRIES, AddToCount, &addCount);        
                
        int i = 0;
        for (/* */; i < NUM_ENTRIES / 2; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_some2 failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i)
            )
        }
        
        for (/* */; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_some2 failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1)
            )
        }
        
        releaseBigPtrArrayContent(bparr);
        dumpBigPtrArray(bparr);
    }
    
    void test_for_some3()
    {
        printMethodName("test_for_some3\n");
        
        BigPtrArray bparr;
        
        fillBigPtrArray(bparr, NUM_ENTRIES);
        dumpBigPtrArray(bparr);
        
        int addCount = 1;
        bparr.ForEach(0, 0, AddToCount, &addCount);                      
        
        for (int i = 0; i < NUM_ENTRIES; i++)
        {
            CPPUNIT_ASSERT_MESSAGE
            (
                "test_for_some3 failed",
                static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i
            )
        }
        releaseBigPtrArrayContent(bparr);
    }
    
    CPPUNIT_TEST_SUITE(BigPtrArrayUnittest);
    CPPUNIT_TEST(test_ctor);    
    CPPUNIT_TEST(test_insert_entries_at_front);
    CPPUNIT_TEST(test_insert_entries_in_the_middle);    
    CPPUNIT_TEST(test_insert_at_already_used_index);
    CPPUNIT_TEST(test_insert_at_end);    
    CPPUNIT_TEST(test_remove_at_front);
    CPPUNIT_TEST(test_remove_at_back);
    CPPUNIT_TEST(test_remove_in_the_middle);
    CPPUNIT_TEST(test_remove_multiple_elements_at_once);
    CPPUNIT_TEST(test_remove_all_elements_at_once);
    CPPUNIT_TEST(test_move_elements_from_lower_to_higher_pos);
    CPPUNIT_TEST(test_move_elements_from_higher_to_lower_pos);
    CPPUNIT_TEST(test_replace_elements);    
    CPPUNIT_TEST(test_for_each);
    CPPUNIT_TEST(test_for_some1);
    CPPUNIT_TEST(test_for_some2);
    CPPUNIT_TEST(test_for_some3);
    CPPUNIT_TEST_SUITE_END();
};

const char* START = "START: ";
const char* END = "END: ";
    
class PerformanceTracer
{
public:    
    
public:
    PerformanceTracer(const string& methodName) :
        startString_(START),
        endString_(END)
    { 
        startString_ += methodName;
        endString_ += methodName;
        RTL_LOGFILE_CONTEXT_TRACE(logFile, startString_.c_str()); 
    }
    
    ~PerformanceTracer()
    { 
        RTL_LOGFILE_CONTEXT_TRACE(logFile, endString_.c_str()); 
    }
    
private:
    string startString_;
    string endString_;
};

class BigPtrArrayPerformanceTest : public CppUnit::TestFixture
{
public:
    BigPtrArrayPerformanceTest()
    {
    }
    
    void test_insert_at_end_1000()
    { test_insert_at_end("1000"); }    
    
    void test_insert_at_end_10000()
    { test_insert_at_end("10000"); }
    
    void test_insert_at_end_100000()
    { test_insert_at_end("100000"); }
    
    void test_insert_at_end_1000000()
    { test_insert_at_end("1000000"); }
    
    void test_insert_at_front_1000()
    { test_insert_at_front("1000"); }    
    
    void test_insert_at_front_10000()
    { test_insert_at_front("10000"); }
    
    void test_insert_at_front_100000()
    { test_insert_at_front("100000"); }
    
    void test_insert_at_front_1000000()
    { test_insert_at_front("1000000"); }
    
    CPPUNIT_TEST_SUITE(BigPtrArrayPerformanceTest);
    CPPUNIT_TEST(test_insert_at_end_1000);
    CPPUNIT_TEST(test_insert_at_end_10000);
    CPPUNIT_TEST(test_insert_at_end_100000);
    CPPUNIT_TEST(test_insert_at_end_1000000);
    CPPUNIT_TEST(test_insert_at_front_1000);
    CPPUNIT_TEST(test_insert_at_front_10000);
    CPPUNIT_TEST(test_insert_at_front_100000);
    CPPUNIT_TEST(test_insert_at_front_1000000);
    CPPUNIT_TEST_SUITE_END();
    
private:
    void test_insert_at_end(const char* numElements)
    {
        char buff[100] = { 0 };
        strcat(buff, "test_insert_at_end ");
        strcat(buff, numElements);
        int n = atoi(numElements);
        PerformanceTracer tracer(buff);
        BigPtrArray bparr;
        for (int i = 0; i < n; i++)
            bparr.Insert(new BigPtrEntryMock(i), bparr.Count());
        
        releaseBigPtrArrayContent(bparr);
    }
    
    void test_insert_at_front(const char* numElements)
    {
        char buff[100] = { 0 };
        strcat(buff, "test_insert_at_front ");
        strcat(buff, numElements);
        int n = atoi(numElements);
        PerformanceTracer tracer(buff);
        BigPtrArray bparr;
        for (int i = 0; i < n; i++)
            bparr.Insert(new BigPtrEntryMock(i), 0);
        
        releaseBigPtrArrayContent(bparr);
    }
};


//#####################################
// register test suites
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayUnittest, "BigPtrArrayUnittest");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayPerformanceTest, "BigPtrArrayPerformanceTest");

NOADDITIONAL;