BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 00005 #ifndef BALL_CONCEPT_AUTODELETABLE_H 00006 # include <BALL/CONCEPT/autoDeletable.h> 00007 #endif 00008 00009 #ifndef BALL_SYSTEM_H 00010 # include <BALL/SYSTEM/file.h> 00011 #endif 00012 00013 #ifndef BALL_DATATYPE_REGULAREXPRESSION_H 00014 # include <BALL/DATATYPE/regularExpression.h> 00015 #endif 00016 00017 #include <string> 00018 #include <list> 00019 00020 #ifdef BALL_HAS_SSTREAM 00021 # include <sstream> 00022 #else 00023 # include <strstream> 00024 #endif 00025 00034 #define PRECISION(a) \ 00035 TEST::precision = (a); 00036 00050 #define START_TEST(class_name)\ 00051 /* define a special namespace for all internal variables */\ 00052 /* to avoid potential collisions */\ 00053 namespace TEST {\ 00054 int verbose = 0;\ 00055 bool all_tests = true;\ 00056 bool test = true;\ 00057 bool this_test;\ 00058 int exception = 0;\ 00059 string exception_name = "";\ 00060 const char* version_string = BALL_RELEASE_STRING;\ 00061 bool newline = false;\ 00062 list<string> tmp_file_list;\ 00063 std::ifstream infile;\ 00064 std::ifstream templatefile;\ 00065 bool equal_files;\ 00066 double precision = 1e-6;\ 00067 }\ 00068 \ 00069 \ 00070 int main(int argc, char **argv)\ 00071 {\ 00072 \ 00073 if (argc == 2) {\ 00074 if (!strcmp(argv[1], "-v"))\ 00075 TEST::verbose = 1;\ 00076 if (!strcmp(argv[1], "-V"))\ 00077 TEST::verbose = 2;\ 00078 };\ 00079 \ 00080 if ((argc > 2) || ((argc == 2) && (TEST::verbose == 0))) {\ 00081 std::cerr << "Checks " #class_name " class" << std::endl;\ 00082 \ 00083 std::cerr << "On successful operation it simply returns OK," << std::endl;\ 00084 std::cerr << "otherwise FAILURE is printed." << std::endl;\ 00085 std::cerr << "If called with an argument of -v, " << argv[0] << " prints detailed" << std::endl;\ 00086 std::cerr << "information about individual tests." << std::endl;\ 00087 std::cerr << "Option -V provides verbose information on" << std::endl;\ 00088 std::cerr << "every subtest." << std::endl;\ 00089 return 1;\ 00090 }\ 00091 \ 00092 if (TEST::verbose > 0)\ 00093 std::cout << "Version: " << TEST::version_string << std::endl;\ 00094 \ 00095 try {\ 00096 00097 00108 #define END_TEST \ 00109 /* global try block */\ 00110 }\ 00111 /* catch FileNotFound exceptions to print out the file name */\ 00112 catch (BALL::Exception::FileNotFound& e)\ 00113 {\ 00114 TEST::this_test = false;\ 00115 TEST::test = false;\ 00116 TEST::all_tests = false;\ 00117 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00118 {\ 00119 if (TEST::exception == 1) /* dummy to avoid compiler warnings */\ 00120 TEST::exception++;\ 00121 std::cout << std::endl << " (caught exception of type ";\ 00122 std::cout << e.getName();\ 00123 if ((e.getLine() > 0) && (!(e.getFile()[0] == '\0')))\ 00124 std::cout << " outside a subtest, which was thrown in line " << e.getLine() << " of file " << e.getFile();\ 00125 std::cout << " while looking for file " << e.getFilename();\ 00126 std::cout << " - unexpected!) " << std::endl;\ 00127 }\ 00128 }\ 00129 /* catch BALL exceptions to retrieve additional information */\ 00130 catch (BALL::Exception::GeneralException& e)\ 00131 {\ 00132 TEST::this_test = false;\ 00133 TEST::test = false;\ 00134 TEST::all_tests = false;\ 00135 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00136 {\ 00137 if (TEST::exception == 1) /* dummy to avoid compiler warnings */\ 00138 TEST::exception++;\ 00139 std::cout << std::endl << " (caught exception of type ";\ 00140 std::cout << e.getName();\ 00141 if ((e.getLine() > 0) && (!(e.getFile()[0] == '\0')))\ 00142 std::cout << " outside a subtest, which was thrown in line " << e.getLine() << " of file " << e.getFile();\ 00143 std::cout << " - unexpected!) " << std::endl;\ 00144 std::cout << " (message is: " << e.getMessage() << ")" << std::endl;\ 00145 }\ 00146 }\ 00147 /* catch all std::exception-derived exceptions */\ 00148 catch (std::exception& e)\ 00149 {\ 00150 TEST::this_test = false;\ 00151 TEST::test = false;\ 00152 TEST::all_tests = false;\ 00153 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00154 {\ 00155 std::cout << std::endl << " (caught expected STL exception outside a subtest: " << e.what() << ")" << std::endl;\ 00156 }\ 00157 }\ 00158 \ 00159 /* catch all non-BALL/non-STL exceptions */\ 00160 catch (...)\ 00161 {\ 00162 TEST::this_test = false;\ 00163 TEST::test = false;\ 00164 TEST::all_tests = false;\ 00165 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00166 {\ 00167 std::cout << std::endl << " (caught unidentified and unexpected exception outside a subtest!) " << std::endl;\ 00168 }\ 00169 }\ 00170 /* clean up all temporary files */\ 00171 while (TEST::tmp_file_list.size() > 0 && TEST::verbose < 1)\ 00172 {\ 00173 ::BALL::File::remove(TEST::tmp_file_list.back());\ 00174 TEST::tmp_file_list.pop_back();\ 00175 }\ 00176 /* check for exit code */\ 00177 if (!TEST::all_tests)\ 00178 {\ 00179 std::cout << "FAILED" << std::endl;\ 00180 return 1;\ 00181 } else {\ 00182 std::cout << "PASSED" << std::endl;\ 00183 return 0;\ 00184 }\ 00185 /* Finally, clean up pointers still pointing to */\ 00186 /* AutoDeletable objects, as this might lead to strange */\ 00187 /* warnings (still reachable) when using valgrind. */\ 00188 BALL::AutoDeletable::clearLastPtr(); \ 00189 }\ 00190 00191 00206 #define CHECK(test_name) \ 00207 TEST::test = true;\ 00208 TEST::newline = false;\ 00209 if (TEST::verbose > 0)\ 00210 std::cout << "checking " << #test_name << "... " << std::flush;\ 00211 try\ 00212 {\ 00213 while (true)\ 00214 {\ 00215 00216 00229 #define STATUS(message)\ 00230 if (TEST::verbose > 1)\ 00231 {\ 00232 if (!TEST::newline) \ 00233 {\ 00234 TEST::newline = true;\ 00235 std::cout << std::endl;\ 00236 }\ 00237 std::cout << " status (line " << __LINE__ << "): " << message << std::endl;\ 00238 }\ 00239 00240 00258 #define RESULT \ 00259 break;\ 00260 }\ 00261 }\ 00262 /* catch FileNotFound exceptions to print out the file name */\ 00263 catch (BALL::Exception::FileNotFound& e)\ 00264 {\ 00265 TEST::this_test = false;\ 00266 TEST::test = false;\ 00267 TEST::all_tests = false;\ 00268 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00269 {\ 00270 if (TEST::exception == 1) /* dummy to avoid compiler warnings */\ 00271 TEST::exception++;\ 00272 std::cout << std::endl << " (caught exception of type ";\ 00273 std::cout << e.getName();\ 00274 if ((e.getLine() > 0) && (!(e.getFile()[0] == '\0')))\ 00275 std::cout << " outside a subtest, which was thrown in line " << e.getLine() << " of file " << e.getFile();\ 00276 std::cout << " while looking for file " << e.getFilename();\ 00277 std::cout << " - unexpected!) " << std::endl;\ 00278 }\ 00279 }\ 00280 catch (::BALL::Exception::GeneralException& e)\ 00281 {\ 00282 TEST::this_test = false;\ 00283 TEST::test = false;\ 00284 TEST::all_tests = false;\ 00285 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00286 {\ 00287 if (!TEST::newline) \ 00288 {\ 00289 TEST::newline = true;\ 00290 std::cout << std::endl;\ 00291 }\ 00292 std::cout << " (caught exception of type ";\ 00293 std::cout << e.getName();\ 00294 if ((e.getLine() > 0) && (!(e.getFile()[0] == '\0')))\ 00295 std::cout << ", which was thrown in line " << e.getLine() << " of file " << e.getFile();\ 00296 std::cout << " - unexpected!) " << std::endl;\ 00297 std::cout << " (message is: " << e.getMessage() << ")" << std::endl;\ 00298 }\ 00299 }\ 00300 catch (...)\ 00301 {\ 00302 TEST::this_test = false;\ 00303 TEST::test = false;\ 00304 TEST::all_tests = false;\ 00305 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00306 {\ 00307 if (!TEST::newline) \ 00308 {\ 00309 TEST::newline = true;\ 00310 std::cout << std::endl;\ 00311 }\ 00312 std::cout << " (caught unidentified and unexpected exception!)" << std::endl;\ 00313 }\ 00314 }\ 00315 \ 00316 TEST::all_tests = TEST::all_tests && TEST::test;\ 00317 if (TEST::verbose > 0){\ 00318 if (TEST::newline)\ 00319 std::cout << " ";\ 00320 if (TEST::test){\ 00321 std::cout << "passed" << std::endl;\ 00322 } else {\ 00323 std::cout << "FAILED" << std::endl;\ 00324 }\ 00325 }\ 00326 00327 00334 #define NEW_TMP_FILE(filename)\ 00335 ::BALL::File::createTemporaryFilename(filename);\ 00336 TEST::tmp_file_list.push_back(filename);\ 00337 if (TEST::verbose > 1)\ 00338 {\ 00339 if (!TEST::newline) \ 00340 {\ 00341 TEST::newline = true;\ 00342 std::cout << std::endl;\ 00343 }\ 00344 std::cout << " creating new temporary file '" << filename << "' (line " << __LINE__ << ")" << std::endl;\ 00345 }\ 00346 00347 00354 #define NEW_TMP_FILE_WITH_SUFFIX(filename, suffix)\ 00355 ::BALL::File::createTemporaryFilename(filename, suffix);\ 00356 TEST::tmp_file_list.push_back(filename);\ 00357 if (TEST::verbose > 1)\ 00358 {\ 00359 if (!TEST::newline) \ 00360 {\ 00361 TEST::newline = true;\ 00362 std::cout << std::endl;\ 00363 }\ 00364 std::cout << " creating new temporary file '" << filename << "' (line " << __LINE__ << ")" << std::endl;\ 00365 }\ 00366 00367 00374 #define TEST_REAL_EQUAL(a,b) \ 00375 TEST::this_test = BALL_REAL_EQUAL((a), (b), TEST::precision); \ 00376 TEST::test = TEST::test && TEST::this_test;\ 00377 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00378 {\ 00379 if (!TEST::newline)\ 00380 {\ 00381 TEST::newline = true;\ 00382 std::cout << std::endl;\ 00383 }\ 00384 std::cout << " (line " << __LINE__ << " TEST_REAL_EQUAL("<< #a << ", " << #b << "): got " << (a) << ", expected " << (b) << ") ";\ 00385 if (TEST::this_test)\ 00386 std::cout << " + " << std::endl;\ 00387 else \ 00388 std::cout << " - " << std::endl;\ 00389 }\ 00390 00391 00401 #define TEST_EQUAL(a,b) \ 00402 {\ 00403 TEST::this_test = ((a) == (b));\ 00404 TEST::test = TEST::test && TEST::this_test;\ 00405 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00406 {\ 00407 if (!TEST::newline)\ 00408 {\ 00409 TEST::newline = true;\ 00410 std::cout << std::endl;\ 00411 }\ 00412 std::cout << " (line " << __LINE__ << " TEST_EQUAL(" << #a << ", " << #b << "): got " << (a) << ", expected " << (b) << ") ";\ 00413 if (TEST::this_test)\ 00414 std::cout << " + " << std::endl;\ 00415 else \ 00416 std::cout << " - " << std::endl;\ 00417 }\ 00418 }\ 00419 00420 00428 #define TEST_NOT_EQUAL(a,b) \ 00429 {\ 00430 TEST::this_test = !((a) == (b));\ 00431 TEST::test = TEST::test && TEST::this_test;\ 00432 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00433 {\ 00434 if (!TEST::newline)\ 00435 {\ 00436 TEST::newline = true;\ 00437 std::cout << std::endl;\ 00438 }\ 00439 std::cout << " (line " << __LINE__ << " TEST_NOT_EQUAL(" << #a << ", " << #b << "): got " << (a) << ", forbidden is " << (b) << ") ";\ 00440 if (TEST::this_test)\ 00441 std::cout << " + " << std::endl;\ 00442 else \ 00443 std::cout << " - " << std::endl;\ 00444 }\ 00445 }\ 00446 00447 00457 #define TEST_EXCEPTION(exception_type, command) \ 00458 {\ 00459 TEST::exception = 0;\ 00460 try\ 00461 {\ 00462 command;\ 00463 }\ 00464 catch (exception_type&)\ 00465 {\ 00466 TEST::exception = 1;\ 00467 }\ 00468 catch (::BALL::Exception::GeneralException& e)\ 00469 {\ 00470 TEST::exception = 2;\ 00471 TEST::exception_name = e.getName();\ 00472 }\ 00473 catch (...)\ 00474 { \ 00475 TEST::exception = 3;\ 00476 }\ 00477 TEST::this_test = (TEST::exception == 1);\ 00478 TEST::test = TEST::test && TEST::this_test;\ 00479 \ 00480 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00481 {\ 00482 if (!TEST::newline)\ 00483 {\ 00484 TEST::newline = true;\ 00485 std::cout << std::endl;\ 00486 }\ 00487 std::cout << " (line " << __LINE__ << " TEST_EXCEPTION(" << #exception_type << ", " << #command << "): ";\ 00488 switch (TEST::exception)\ 00489 {\ 00490 case 0: std::cout << " ERROR: no exception!) "; break;\ 00491 case 1: std::cout << " OK) "; break;\ 00492 case 2: std::cout << " ERROR: wrong exception: " << TEST::exception_name << ") "; break;\ 00493 case 3: std::cout << " ERROR: wrong exception!) "; break;\ 00494 }\ 00495 if (TEST::this_test)\ 00496 std::cout << " + " << std::endl;\ 00497 else \ 00498 std::cout << " - " << std::endl;\ 00499 }\ 00500 }\ 00501 00502 #ifdef BALL_DEBUG 00503 00511 #define TEST_PRECONDITION_EXCEPTION(command) \ 00512 {\ 00513 TEST::exception = 0;\ 00514 try\ 00515 {\ 00516 command;\ 00517 }\ 00518 catch (Exception::Precondition&)\ 00519 {\ 00520 TEST::exception = 1;\ 00521 }\ 00522 catch (::BALL::Exception::GeneralException& e)\ 00523 {\ 00524 TEST::exception = 2;\ 00525 TEST::exception_name = e.getName();\ 00526 }\ 00527 catch (...)\ 00528 { \ 00529 TEST::exception = 3;\ 00530 }\ 00531 TEST::this_test = (TEST::exception == 1);\ 00532 TEST::test = TEST::test && TEST::this_test;\ 00533 \ 00534 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00535 {\ 00536 if (!TEST::newline)\ 00537 {\ 00538 TEST::newline = true;\ 00539 std::cout << std::endl;\ 00540 }\ 00541 std::cout << " (line " << __LINE__ << " TEST_PRECONDITION_EXCEPTION(" << ", " << #command << "): ";\ 00542 switch (TEST::exception)\ 00543 {\ 00544 case 0: std::cout << " ERROR: no exception!) "; break;\ 00545 case 1: std::cout << " OK) "; break;\ 00546 case 2: std::cout << " ERROR: wrong exception: " << TEST::exception_name << ") "; break;\ 00547 case 3: std::cout << " ERROR: wrong exception!) "; break;\ 00548 }\ 00549 if (TEST::this_test)\ 00550 std::cout << " + " << std::endl;\ 00551 else \ 00552 std::cout << " - " << std::endl;\ 00553 }\ 00554 }\ 00555 00556 #else 00557 00558 # define TEST_PRECONDITION_EXCEPTION(command)\ 00559 if (TEST::verbose > 1)\ 00560 {\ 00561 std::cout << " TEST_EXCEPTION_PRECONDITION(" #command ") : (DEBUG mode disabled!)" << std::endl;\ 00562 }\ 00563 00564 #endif // BALL_DEBUG 00565 00571 #define ABORT_IF(condition) \ 00572 if (condition) break; 00573 00581 #define TEST_FILE(filename, templatename) \ 00582 {\ 00583 TEST::equal_files = true;\ 00584 TEST::infile.open(filename, std::ios::in);\ 00585 TEST::templatefile.open(templatename, std::ios::in);\ 00586 \ 00587 if (TEST::infile.good() && TEST::templatefile.good())\ 00588 {\ 00589 String TEST_FILE__template_line;\ 00590 String TEST_FILE__line;\ 00591 \ 00592 while (TEST::infile.good() && TEST::templatefile.good())\ 00593 {\ 00594 TEST_FILE__template_line.getline(TEST::templatefile);\ 00595 TEST_FILE__line.getline(TEST::infile);\ 00596 \ 00597 TEST::equal_files &= (TEST_FILE__template_line == TEST_FILE__line);\ 00598 if (TEST_FILE__template_line != TEST_FILE__line)\ 00599 {\ 00600 if (TEST::verbose > 0)\ 00601 {\ 00602 if (!TEST::newline)\ 00603 {\ 00604 TEST::newline = true;\ 00605 std::cout << std::endl;\ 00606 }\ 00607 \ 00608 std::cout << " TEST_FILE: line mismatch:\n got: '" << TEST_FILE__line << "'\n expected: '" << TEST_FILE__template_line << "'" << std::endl;\ 00609 }\ 00610 }\ 00611 }\ 00612 } else {\ 00613 TEST::equal_files = false;\ 00614 \ 00615 if (TEST::verbose > 0)\ 00616 {\ 00617 if (!TEST::newline)\ 00618 {\ 00619 TEST::newline = true;\ 00620 std::cout << std::endl;\ 00621 }\ 00622 \ 00623 std::cout << " (line " << __LINE__ << ": TEST_FILE(" << #filename << ", " << #templatename ;\ 00624 std::cout << ") : " << " cannot open file: \"";\ 00625 if (!TEST::infile.good())\ 00626 {\ 00627 std::cout << filename << "\" (input file) ";\ 00628 }\ 00629 if (!TEST::templatefile.good())\ 00630 {\ 00631 std::cout << templatename << "\" (template file) ";\ 00632 }\ 00633 std::cout << std::endl;\ 00634 \ 00635 }\ 00636 }\ 00637 TEST::infile.close();\ 00638 TEST::templatefile.close();\ 00639 TEST::infile.clear();\ 00640 TEST::templatefile.clear();\ 00641 \ 00642 TEST::this_test = TEST::equal_files;\ 00643 TEST::test = TEST::test && TEST::this_test;\ 00644 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00645 {\ 00646 if (!TEST::newline)\ 00647 {\ 00648 TEST::newline = true;\ 00649 std::cout << std::endl;\ 00650 }\ 00651 std::cout << " (line " << __LINE__ << ": TEST_FILE("<< #filename << ", " << #templatename << "): ";\ 00652 if (TEST::this_test)\ 00653 {\ 00654 std::cout << "true";\ 00655 } else {\ 00656 std::cout << "false";\ 00657 }\ 00658 \ 00659 if (TEST::this_test)\ 00660 {\ 00661 std::cout << " + " << std::endl;\ 00662 } else {\ 00663 std::cout << " - " << std::endl;\ 00664 }\ 00665 }\ 00666 } 00667 00668 00677 #define TEST_FILE_REGEXP(filename, templatename) \ 00678 {\ 00679 TEST::equal_files = true;\ 00680 TEST::infile.open(filename, std::ios::in);\ 00681 TEST::templatefile.open(templatename, std::ios::in);\ 00682 \ 00683 if (TEST::infile.good() && TEST::templatefile.good())\ 00684 {\ 00685 String TEST_FILE__template_line;\ 00686 String TEST_FILE__line;\ 00687 \ 00688 while (TEST::infile.good() && TEST::templatefile.good())\ 00689 {\ 00690 TEST_FILE__template_line.getline(TEST::templatefile);\ 00691 TEST_FILE__line.getline(TEST::infile);\ 00692 \ 00693 if ((TEST_FILE__template_line.size() > 0) && (TEST_FILE__template_line[0] == '/') && (TEST_FILE__template_line[1] != '/'))\ 00694 {\ 00695 RegularExpression expression(TEST_FILE__template_line(1));\ 00696 bool match = expression.match(TEST_FILE__line);\ 00697 TEST::equal_files &= match;\ 00698 if (!match)\ 00699 {\ 00700 if (TEST::verbose > 0)\ 00701 {\ 00702 if (!TEST::newline)\ 00703 {\ 00704 TEST::newline = true;\ 00705 std::cout << std::endl;\ 00706 }\ 00707 \ 00708 std::cout << " TEST_FILE_REGEXP: regexp mismatch: " << TEST_FILE__line << " did not match " << TEST_FILE__template_line(1) << "." << std::endl;\ 00709 }\ 00710 }\ 00711 } else {\ 00712 TEST::equal_files &= (TEST_FILE__template_line == TEST_FILE__line);\ 00713 if (TEST_FILE__template_line != TEST_FILE__line)\ 00714 {\ 00715 if (TEST::verbose > 0)\ 00716 {\ 00717 if (!TEST::newline)\ 00718 {\ 00719 TEST::newline = true;\ 00720 std::cout << std::endl;\ 00721 }\ 00722 \ 00723 std::cout << " TEST_FILE: line mismatch:\n got: '" << TEST_FILE__line << "'\n expected: '" << TEST_FILE__template_line << "'" << std::endl;\ 00724 }\ 00725 }\ 00726 }\ 00727 }\ 00728 } else {\ 00729 TEST::equal_files = false;\ 00730 \ 00731 if (TEST::verbose > 0)\ 00732 {\ 00733 if (!TEST::newline)\ 00734 {\ 00735 TEST::newline = true;\ 00736 std::cout << std::endl;\ 00737 }\ 00738 \ 00739 std::cout << " (line " << __LINE__ << ": TEST_FILE_REGEXP(" << #filename << ", " << #templatename ;\ 00740 std::cout << ") : " << " cannot open file: \"";\ 00741 if (!TEST::infile.good())\ 00742 {\ 00743 std::cout << filename << "\" (input file) ";\ 00744 }\ 00745 if (!TEST::templatefile.good())\ 00746 {\ 00747 std::cout << templatename << "\" (template file) ";\ 00748 }\ 00749 std::cout << std::endl;\ 00750 \ 00751 }\ 00752 }\ 00753 TEST::infile.close();\ 00754 TEST::templatefile.close();\ 00755 TEST::infile.clear();\ 00756 TEST::templatefile.clear();\ 00757 \ 00758 TEST::this_test = TEST::equal_files;\ 00759 TEST::test = TEST::test && TEST::this_test;\ 00760 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00761 {\ 00762 if (!TEST::newline)\ 00763 {\ 00764 TEST::newline = true;\ 00765 std::cout << std::endl;\ 00766 }\ 00767 std::cout << " (line " << __LINE__ << ": TEST_FILE_REGEXP("<< #filename << ", " << #templatename << "): ";\ 00768 if (TEST::this_test)\ 00769 {\ 00770 std::cout << "true";\ 00771 } else {\ 00772 std::cout << "false";\ 00773 }\ 00774 \ 00775 if (TEST::this_test)\ 00776 {\ 00777 std::cout << " + " << std::endl;\ 00778 } else {\ 00779 std::cout << " - " << std::endl;\ 00780 }\ 00781 }\ 00782 } 00783 00784 00797 #ifdef BALL_HAS_SSTREAM 00798 #define CAPTURE_OUTPUT_LEVEL(level) \ 00799 {\ 00800 std::ostringstream TEST_strstr;\ 00801 Log.remove(std::cout);\ 00802 Log.remove(std::cerr);\ 00803 Log.insert(TEST_strstr, level, level); 00804 #else 00805 #define CAPTURE_OUTPUT_LEVEL(level) \ 00806 {\ 00807 std::ostrstream TEST_strstr;\ 00808 Log.remove(std::cout);\ 00809 Log.remove(std::cerr);\ 00810 Log.insert(TEST_strstr, level, level); 00811 #endif 00812 00825 #ifdef BALL_HAS_SSTREAM 00826 #define CAPTURE_OUTPUT_LEVEL_RANGE(minlevel, maxlevel) \ 00827 {\ 00828 std::ostringstream TEST_strstr;\ 00829 Log.remove(std::cout);\ 00830 Log.remove(std::cerr);\ 00831 Log.insert(TEST_strstr, minlevel, maxlevel); 00832 #else 00833 #define CAPTURE_OUTPUT_LEVEL_RANGE(minlevel, maxlevel) \ 00834 {\ 00835 std::ostrstream TEST_strstr;\ 00836 Log.remove(std::cout);\ 00837 Log.remove(std::cerr);\ 00838 Log.insert(TEST_strstr, minlevel, maxlevel); 00839 #endif 00840 00845 #ifdef BALL_HAS_SSTREAM 00846 #define COMPARE_OUTPUT(text) \ 00847 Log.remove(TEST_strstr);\ 00848 Log.insert(std::cout, LogStream::INFORMATION_LEVEL, LogStream::ERROR_LEVEL - 1);\ 00849 Log.insert(std::cerr, LogStream::ERROR_LEVEL);\ 00850 TEST::this_test = (::strncmp(TEST_strstr.str().c_str(), text, TEST_strstr.str().size()) == 0);\ 00851 TEST::test = TEST::test && TEST::this_test;\ 00852 \ 00853 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00854 {\ 00855 /* reserve space for the null-terminated content of the strstrem */\ 00856 char* TEST_strstr_contents = new char[TEST_strstr.str().size() + 1];\ 00857 ::strncpy(TEST_strstr_contents, TEST_strstr.str().c_str(), TEST_strstr.str().size());\ 00858 TEST_strstr_contents[TEST_strstr.str().size()] = '\0';\ 00859 \ 00860 if (!TEST::newline)\ 00861 {\ 00862 TEST::newline = true;\ 00863 std::cout << std::endl;\ 00864 }\ 00865 std::cout << " (line " << __LINE__ << " COMPARE_OUTPUT(" << #text << "): got '" << (TEST_strstr_contents) << "', expected '" << (text) << ") ";\ 00866 if (TEST::this_test)\ 00867 std::cout << " + " << std::endl;\ 00868 else \ 00869 std::cout << " - " << std::endl;\ 00870 delete [] TEST_strstr_contents;\ 00871 }\ 00872 } 00873 #else 00874 #define COMPARE_OUTPUT(text) \ 00875 Log.remove(TEST_strstr);\ 00876 Log.insert(std::cout, LogStream::INFORMATION_LEVEL, LogStream::ERROR_LEVEL - 1);\ 00877 Log.insert(std::cerr, LogStream::ERROR_LEVEL);\ 00878 TEST::this_test = (::strncmp(TEST_strstr.str(), text, TEST_strstr.str()!=0?strlen(TEST_strstr.str()):0) == 0);\ 00879 TEST::test = TEST::test && TEST::this_test;\ 00880 \ 00881 if ((TEST::verbose > 1) || (!TEST::this_test && (TEST::verbose > 0)))\ 00882 {\ 00883 /* reserve space for the null-terminated content of the strstrem */\ 00884 char* TEST_strstr_contents = new char[TEST_strstr.str()!=0?strlen(TEST_strstr.str()):0 + 1];\ 00885 ::strncpy(TEST_strstr_contents, TEST_strstr.str(), TEST_strstr.str()!=0?strlen(TEST_strstr.str()):0);\ 00886 TEST_strstr_contents[TEST_strstr.str()!=0?strlen(TEST_strstr.str()):0] = '\0';\ 00887 \ 00888 if (!TEST::newline)\ 00889 {\ 00890 TEST::newline = true;\ 00891 std::cout << std::endl;\ 00892 }\ 00893 std::cout << " (line " << __LINE__ << " COMPARE_OUTPUT(" << #text << "): got '" << (TEST_strstr_contents) << "', expected '" << (text) << "') ";\ 00894 if (TEST::this_test)\ 00895 std::cout << " + " << std::endl;\ 00896 else \ 00897 std::cout << " - " << std::endl;\ 00898 delete [] TEST_strstr_contents;\ 00899 }\ 00900 } 00901 00902 #endif