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