BASIS  version 1.2.3 (revision 2104)
testdriver-after-test.inc
Go to the documentation of this file.
00001 /**
00002  * @file  testdriver-after-test.inc
00003  * @brief Default implementation of test driver.
00004  *
00005  * This file is included in the test driver generated by the CMake command
00006  * <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:create_test_sourcelist">
00007  * create_test_sourcelist()</a> directly after the call to the test main function.
00008  * It performs regression testing if requested.
00009  *
00010  * This file is a modified version of the itkTestDriverBeforeTest.inc file
00011  * which is part of the TestKernel module of the ITK 4 project.
00012  *
00013  * Copyright (c) 2011 University of Pennsylvania.<br />
00014  * Copyright Insight Software Consortium.<br />
00015  * All rights reserved.
00016  *
00017  * Licensed under the Apache License, Version 2.0 (the "License");
00018  * you may not use this file except in compliance with the License.
00019  * You may obtain a copy of the License at
00020  *
00021  *        http://www.apache.org/licenses/LICENSE-2.0.txt
00022  *
00023  * Unless required by applicable law or agreed to in writing, software
00024  * distributed under the License is distributed on an "AS IS" BASIS,
00025  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00026  * See the License for the specific language governing permissions and
00027  * limitations under the License.
00028  *
00029  * Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00030  */
00031 
00032 //int main(int, char*)
00033 //{
00034     // #include <sbia/basis/testdriver-before-test.inc> -> try {
00035         // [...]
00036 
00037         // revert redirection of output
00038         if (oldcoutbuf) {
00039             cout.rdbuf(oldcoutbuf);
00040             redirectstream.close();
00041         }
00042         // perform regression tests of output image(s)
00043         if (result == 0) {
00044             if (!regression_tests.empty() && verbose.getValue() > 0) {
00045                 cout << "Performing regression tests" << endl;
00046             }
00047             for (size_t i = 0; i < regression_tests.size(); i++) {
00048                 const char*    test_image_file      = regression_tests[i].test_image_file.c_str();
00049                 const char*    baseline_image_file  = regression_tests[i].baseline_image_file.c_str();
00050                 vector<string> baseline_image_files = get_baseline_filenames(baseline_image_file);
00051                 string         bestmatch  = baseline_image_file;
00052                 int            beststatus = numeric_limits<int>::max();
00053                 if (baseline_image_files.empty()) {
00054                     bestmatch += " not found";
00055                     cerr << "No baseline images found given file path " << baseline_image_file << "!" << endl;
00056                 } else {
00057                     for (size_t j = 0; j < baseline_image_files.size(); j++) {
00058                         int status = image_regression_test(
00059                                 test_image_file,
00060                                 baseline_image_files[j].c_str(),
00061                                 regression_tests[i].intensity_tolerance,
00062                                 regression_tests[i].max_number_of_differences,
00063                                 regression_tests[i].tolerance_radius);
00064                         if (status < beststatus) {
00065                             bestmatch  = baseline_image_files[j];
00066                             beststatus = status;
00067                         }
00068                         if (beststatus == 0) {
00069                             // perfect test result
00070                             break;
00071                         }
00072                     }
00073                     // if the best we can do still has errors...
00074                     if (beststatus != 0) {
00075                         image_regression_test(
00076                                 test_image_file,
00077                                 baseline_image_files[0].c_str(),
00078                                 regression_tests[i].intensity_tolerance,
00079                                 regression_tests[i].max_number_of_differences,
00080                                 regression_tests[i].tolerance_radius,
00081                                 1); // ...generate error images
00082                     }
00083                 }
00084                 // output the matching baseline for submission to the dashboard
00085                 cout << "<DartMeasurement name=\"BaselineImageName\" type=\"text/string\">";
00086                 cout << get_file_name(bestmatch);
00087                 cout << "</DartMeasurement>" << std::endl;
00088                 result += beststatus;
00089             }
00090             // empty current working directory
00091             if (clean_cwd_after_test.getValue()) {
00092                 clear_directory(get_working_directory().c_str());
00093             }
00094         }
00095 
00096     // catch any exceptions
00097     } catch (const exception& e) {
00098         cerr << "Test driver caught an exception:\n";
00099         cerr << e.what() << "\n";
00100         result = -1;
00101     } catch (...) {
00102         cerr << "Test driver caught an unknown exception!!!\n";
00103         result = -1;
00104     }
00105 //} end of main()