Changeset 435 for branches/streaming-rework/src/libutil
- Timestamp:
- 03/11/07 06:20:31 (16 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/streaming-rework/src/libutil/unittests.cpp
r419 r435 28 28 using namespace Util; 29 29 30 #define TEST_SHOULD_RETURN_TRUE(test) \ 31 (test ? true : printf( "'" #test "' should return true\n") && false ) 32 #define TEST_SHOULD_RETURN_FALSE(test) \ 33 (test ? printf( "'" #test "' should return true\n") && false : true ) 34 30 35 /////////////////////////////////////// 31 36 … … 416 421 417 422 Option op1=Option(); 418 if(addOption(op1)) { 419 printf( "adding an empty option should not succeed\n" ); 420 result=false; 421 } 423 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 422 424 423 425 op1=Option("option1"); 424 if(addOption(op1)) { 425 printf( "adding an option without a value should not succeed\n" ); 426 result=false; 427 } 428 426 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 427 429 428 op1=Option("option1", (float)(1.0)); 430 if(!addOption(op1)) { 431 printf( "could not add valid option (1)\n" ); 432 result=false; 433 } 434 if(addOption(op1)) { 435 printf( "adding the same option twice should not succeed\n" ); 436 result=false; 437 } 438 if(!removeOption(op1)) { 439 printf( "could not remove option by reference\n" ); 440 result=false; 441 } 442 if(hasOption(op1)) { 443 printf( "option not removed (by reference)\n" ); 444 result=false; 445 } 429 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 430 result &= TEST_SHOULD_RETURN_FALSE(addOption(op1)); 431 result &= TEST_SHOULD_RETURN_TRUE(removeOption(op1)); 432 result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); 433 446 434 447 435 op1=Option("option1", (int64_t)1); 448 if(!addOption(op1)) { 449 printf( "could not add valid option (2)\n" ); 450 result=false; 451 } 452 if(!removeOption("option1")) { 453 printf( "could not remove option by name\n" ); 454 result=false; 455 } 456 if(hasOption(op1)) { 457 printf( "option not removed (by name)\n" ); 458 result=false; 459 } 436 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 437 438 result &= TEST_SHOULD_RETURN_TRUE(removeOption("option1")); 439 440 result &= TEST_SHOULD_RETURN_FALSE(hasOption(op1)); 441 460 442 461 443 op1=Option("option1", (int64_t)(-1)); 462 if(!addOption(op1)) { 463 printf( "could not add valid option (3)\n" ); 464 result=false; 465 } 444 result &= TEST_SHOULD_RETURN_TRUE(addOption(op1)); 445 466 446 Option op2=Option("option1", (double)(1.75)); 467 if(addOption(op2)) { 468 printf( "adding two options with the same name should not be allowed\n" ); 469 result=false; 470 } 447 result &= TEST_SHOULD_RETURN_FALSE(addOption(op2)); 448 471 449 472 450 op2=Option("option2", (double)(1.75)); 473 if(!addOption(op2)) { 474 printf( "adding an option with a different name should be allowed (1)\n" ); 475 result=false; 476 } 451 result &= TEST_SHOULD_RETURN_TRUE(addOption(op2)); 452 477 453 Option op3=Option("option3", (int64_t)(1.75)); 478 if(!addOption(op3)) { 479 printf( "adding an option with a different name should be allowed (2)\n" ); 480 result=false; 481 } 482 483 if(countOptions() != 3) { 484 printf( "countOptions failed\n" ); 485 result=false; 486 } 487 454 result &= TEST_SHOULD_RETURN_TRUE(addOption(op3)); 455 456 457 result &= TEST_SHOULD_RETURN_TRUE(countOptions() == 3); 458 488 459 int i=0; 489 460 for ( OptionContainer::iterator it = begin(); … … 494 465 i++; 495 466 } 496 if(i!=3) { 497 printf( "did not iterate through the right amount of options\n" ); 498 result=false; 499 } 467 result &= TEST_SHOULD_RETURN_TRUE(i==3); 500 468 501 469 clearOptions(); … … 525 493 bool result=true; 526 494 testOC oc; 527 if(!oc.test()) { 528 printf( "OptionContainer test failed\n" ); 529 result=false; 530 } 495 result &= TEST_SHOULD_RETURN_TRUE(oc.test()); 531 496 532 497 // now manipulate it externally 533 498 oc.prepare(); 534 499 535 if(!oc.hasOption("option1")) { 536 printf( "option1 should be present\n" ); 537 result=false; 538 } 539 if(!oc.hasOption("option2")) { 540 printf( "option2 should be present\n" ); 541 result=false; 542 } 543 if(!oc.hasOption("option3")) { 544 printf( "option3 should be present\n" ); 545 result=false; 546 } 547 if(oc.hasOption("option4")) { 548 printf( "option4 should not be present\n" ); 549 result=false; 550 } 551 500 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option1")); 501 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option2")); 502 result &= TEST_SHOULD_RETURN_TRUE(oc.hasOption("option3")); 503 result &= TEST_SHOULD_RETURN_FALSE(oc.hasOption("option4")); 504 552 505 oc.setOption("option1", 1024); 553 506 int tst; 554 if (!oc.getOption("option1", tst)) { 555 printf( "could not get option1 value\n" ); 556 result=false; 557 } 558 559 if(tst != 1024) { 560 printf( "option1 should be 1024\n" ); 561 result=false; 562 } 507 result &= TEST_SHOULD_RETURN_TRUE(oc.getOption("option1", tst)); 508 result &= TEST_SHOULD_RETURN_TRUE(tst == 1024); 563 509 564 510 return result;