testdriver-before-test.inc
Go to the documentation of this file.
00001 /** 00002 * @file testdriver-before-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 before the call to the test main function. 00008 * 00009 * This file is a modified version of the itkTestDriverBeforeTest.inc file 00010 * which is part of the TestKernel module of the ITK 4 project. 00011 * 00012 * Copyright (c) 2011 University of Pennsylvania.<br /> 00013 * Copyright Insight Software Consortium.<br /> 00014 * All rights reserved. 00015 * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); 00017 * you may not use this file except in compliance with the License. 00018 * You may obtain a copy of the License at 00019 * 00020 * http://www.apache.org/licenses/LICENSE-2.0.txt 00021 * 00022 * Unless required by applicable law or agreed to in writing, software 00023 * distributed under the License is distributed on an "AS IS" BASIS, 00024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00025 * See the License for the specific language governing permissions and 00026 * limitations under the License. 00027 * 00028 * Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00029 */ 00030 00031 //int main(int, char*) 00032 //{ 00033 // [...] 00034 try { 00035 // redirect standard output to file 00036 ofstream redirectstream; 00037 streambuf* redirectbuf = NULL; 00038 streambuf* oldcoutbuf = NULL; 00039 if (redirect_output.isSet()) { 00040 cout << "Test output has been redirected to: " << redirect_output.getValue() << endl; 00041 redirectstream.open(redirect_output.getValue().c_str(), ios::out); 00042 redirectbuf = redirectstream.rdbuf(); 00043 oldcoutbuf = cout.rdbuf(); 00044 cout.rdbuf(redirectbuf); 00045 } 00046 // empty current working directory 00047 if (clean_cwd_before_test.getValue()) { 00048 os::emptydir(os::getcwd().c_str()); 00049 } 00050 // remove all test output images if existent from previous test run 00051 if (testcmd.isSet()) { 00052 for (size_t i = 0; i < regression_tests.size(); i++) { 00053 const char* test_file = regression_tests[i].test_file.c_str(); 00054 if (os::path::isfile(test_file)) { 00055 if (remove(test_file) == 0) { 00056 if (verbose.getValue() > 0) { 00057 cout << "Removed already existing test output file " << test_file << endl; 00058 } 00059 } else { 00060 cerr << "Warning: Failed to remove already existing output image " << test_file << endl; 00061 } 00062 } 00063 } 00064 } 00065 // execute test in a try block 00066 // [...] 00067 // #include <sbia/basis/testdriver-after-test.inc> 00068 //}