16 #ifndef _BASIS_TESTDRIVER_HXX 17 #define _BASIS_TESTDRIVER_HXX 23 # include <Winsock2.h> 27 # pragma comment(lib, "Ws2_32.lib") 46 #ifdef TESTDRIVER_NAME 47 name = TESTDRIVER_NAME;
52 name +=
" build with ITK ";
62 "This program alters the environment, runs a test and " 63 "compares the output image to one or more baseline images.",
65 "EXENAME GaussFilter --compare output.nii baseline.nii" 67 "Runs the test GaussFilter which presumably writes the" 68 " gaussian smoothed image to the image file output.nii." 69 " Compares the image produced by the test to the reference" 70 " image named baseline.nii with default intensity tolerance.",
72 RELEASE,
"2011, 2012 University of Pennsylvania");
90 #ifdef BASIS_STANDALONE_TESTDRIVER 98 cmd.parse(*argc, *argv);
103 for (
unsigned int i = 0; i <
testcmd.getValue().size(); i++) {
104 for (
int j = 1; j < (*argc); j++) {
105 if (
testcmd.getValue()[i] == (*argv)[j]) {
106 (*argv)[i + 1] = (*argv)[j];
111 *argc =
static_cast<int>(
testcmd.getValue().size()) + 1;
112 (*argv)[*argc] = NULL;
122 TCLAP::Arg::stopIgnoring();
127 cerr << e.error() << endl;
133 char hostname[256] =
"unknown";
136 WSAStartup(MAKEWORD(2, 2), &wsaData);
137 gethostname(hostname,
sizeof(hostname));
140 gethostname(hostname,
sizeof(hostname));
142 hostname[255] =
'\0';
144 cout <<
"<DartMeasurement name=\"Host Name\" type=\"string\">";
146 cout <<
"</DartMeasurement>" << endl;
148 cout <<
"<DartMeasurement name=\"Working Directory\" type=\"string\">";
150 cout <<
"</DartMeasurement>" << endl;
153 cout <<
"<DartMeasurement name=\"ITK Version\" type=\"string\">";
155 cout <<
"</DartMeasurement>" << endl;
192 ifstream ift(testfile, ios::binary);
193 ifstream ifb(baseline, ios::binary);
196 istream_iterator<unsigned char> eos;
197 istream_iterator<unsigned char> it(ift);
198 istream_iterator<unsigned char> ib(ifb);
199 while (it != eos && ib != eos) {
200 if (*it != *ib)
break;
204 if (it != eos || ib != eos) retval = 1;
233 ifstream ift(testfile);
234 ifstream ifb(baseline);
238 while (getline(ift, tline) && getline(ifb, bline)) {
239 if (tline != bline) retval++;
241 if (static_cast<unsigned int>(retval) <= max_number_of_differences) retval = 0;
242 if (getline(ift, tline) || getline(ifb, bline)) retval = 1000;
274 vector<string> baselines;
276 ifstream ifs(filename_template.c_str());
277 if (ifs) baselines.push_back(filename_template);
280 string::size_type pos = filename_template.rfind(
".");
283 if (pos != string::npos) {
284 suffix = filename_template.substr(pos);
285 filename_template.erase(pos);
288 ostringstream filename;
289 filename << filename_template <<
'.' << x << suffix;
290 ifstream ifs(filename.str().c_str());
293 baselines.push_back(filename.str());
300 const char* baseline,
312 max_number_of_differences,
314 orientation_insensitive);
317 "Not implemented yet! Use ITK implementation instead, i.e.," 318 <<
" install ITK 3.14 or greater (including versions after 4.0)" 319 <<
" and reconfigure the build tree of " <<
PROJECT <<
". Ensure that" 320 <<
" the ITK_DIR variable is set to the directory of the ITKConfig.cmake file" 321 <<
" and that the variable USE_ITK is set to ON. Then rebuild " <<
PROJECT 322 <<
" and optionally install it again.");
327 #endif // _BASIS_TESTDRIVER_HXX PositionalArgs testcmd("testcmd", "The name of the test to run and optional arguments." " Displays a list of available tests if this argument is omitted" " and waits for the user to input the number of the test to run." " Exist with error if an invalid test was specified." " Note that if the -- option is not given before the test name," " labeled arguments following the test name will be considered" " to be options of the test driver if known by the test driver." " Otherwise, if the option is unknown to the test driver or the" " -- option has been given before the test name, the remaining" " arguments are passed on to the test.", false, "", "[--] [<test name> [<arg>...]]")
SwitchArg orientation_insensitive("", "orientation-insensitive", "Allow the test and baseline images to have different orientation." " When this option is given, the orientation of both images is made" " identical before they are compared. It is suitable if the test" " and baseline images are simply stored with different orientation," " but with proper orientation information in the file header.")
MultiStringArg diff("", "diff", "Compare the <test> file to the <baseline> file byte by byte." " Can by used to compare any files including text files." " For images, the --compare option should be used instead.", false, "<test> <baseline>", 2, false, &diff_visitor)
std::string getcwd()
Get absolute path of the (current) working directory.
int binary_diff(const char *testfile, const char *baseline)
Compare two files byte by byte.
unsigned int tolerance_radius
string PROJECT
Project name.
#define assert(condition)
Assertion without custom message.
SwitchArg full_output("", "full-output", "Causes the full output of the test to be passed to CDash.", false)
int text_diff_lines(const char *testfile, const char *baseline, unsigned int max_number_of_differences)
Compare two text files line by line.
DoubleArg intensity_tolerance("", "intensity-tolerance", "The accepted maximum difference between image intensities" " to use for the following regression tests." " (default: 2.0)", false, 2.0, "<float>", true)
void testdriversetup(int *argc, char **argv[])
Parse command-line arguments and initialize test driver.
#define BASIS_THROW(type, msg)
Throw exception with given message.
TCLAP::SpecificationException CmdLineException
Exception thrown when command-line specification is wrong.
SwitchArg clean_cwd_before_test("", "clean-cwd-before", "Request the removal of all files and directories from the current" " working directory before the execution of the test. This option is" " in particular useful if the test writes any results to the current" " working directory.", false)
UIntArg max_number_of_differences("", "max-number-of-differences", "When comparing images specified with the following --compare option(s)," " allow the given number of image elements to differ.", false, 0, "<n>", true)
string RELEASE
Project release.
UIntArg max_number_of_threads("", "max-number-of-threads", "Use at most <n> threads. Set explicitly to n=1 to disable" " multi-threading. Note that the test itself still may use" " more threads, but the regression tests will not.", false, 0, "<n>")
unsigned int max_number_of_differences
int RegressionTestImage(const char *testImageFilename, const char *baselineImageFilename, int reportErrors, double intensityTolerance, unsigned int numberOfPixelsTolerance, unsigned int radiusTolerance, bool orientationInsensitive)
void RegisterRequiredFactories()
MultiStringArg diff_lines("", "diff-lines", "Compare the <test> file to the <baseline> file line by line." " Can by used to compare text files. The current --max-number-of-differences" " setting determines the number of lines which may differ between the files." " For binary files, consider the --diff option instead.", false, "<test> <baseline>", 2, false, &diff_lines_visitor)
UIntArg tolerance_radius("", "tolerance-radius", "At most one image element in the neighborhood specified by the" " given radius has to fulfill the criteria of the following" " regression tests", false, 0, "<int>", true)
Structure holding arguments to regression test options and currently set tolerances to be used for th...
StringArg redirect_output("", "redirect-output", "Redirects the test output to the specified file.", false, "", "<file>")
MultiSwitchArg verbose("v", "verbose", "Increase verbosity of output messages.", false)
MultiStringArg add_before_libpath("", "add-before-libpath", "Add a path to the library path environment. This option takes" " care of choosing the right environment variable for your system.", false, "<dir>")
ITK-based implementation of test driver.
int image_regression_test(const char *imagefile, const char *baseline, double intensity_tolerance, unsigned int max_number_of_differences, unsigned int tolerance_radius, bool orientation_insensitive, int report)
Compare output image to baseline image.
MultiStringArg add_before_env("", "add-before-env", "Add an environment variable named <name> with the given value." " The seperator used is the default one on the system.", false, "<name> <value>", 2)
vector< string > get_baseline_filenames(string filename_template)
SwitchArg clean_cwd_after_test("", "clean-cwd-after", "Request the removal of all files and directories from the current" " working directory after the successful execution of the test." " This option is in particular useful if the test writes any results" " to the current working directory.", false)
bool orientation_insensitive
double intensity_tolerance
MultiStringArg compare("", "compare", "Compare the <test> image to the <baseline> image using the" " current tolerances. If the test image should be compared to" " to more than one baseline image, specify the file name of" " the main baseline image and name the other baseline images" " similarly with only a numerical suffix appended to the" " basename of the image file path using a dot (.) as separator." " For example, name your baseline images baseline.nii," " baseline.1.nii, baseline.2.nii,..., and specify baseline.nii" " second argument value.", false, "<test> <baseline>", 2, false, &compare_visitor)
vector< RegressionTest > regression_tests
Container storing added regression tests.