Go to the documentation of this file.00001 #include <ctype.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005
00006 #include "mitkLog.h"
00007
00008
00009
00010
00011 int mitkDemonsRegistrationTest(int, char*[]);
00012 int mitkHistogramMatchingTest(int, char*[]);
00013 int mitkSymmetricForcesDemonsRegistrationTest(int, char*[]);
00014
00015
00016
00017
00018 typedef int (*MainFuncPointer)(int , char*[]);
00019 typedef struct
00020 {
00021 const char* name;
00022 MainFuncPointer func;
00023 } functionMapEntry;
00024
00025 functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
00026 {
00027 "mitkDemonsRegistrationTest",
00028 mitkDemonsRegistrationTest
00029 },
00030 {
00031 "mitkHistogramMatchingTest",
00032 mitkHistogramMatchingTest
00033 },
00034 {
00035 "mitkSymmetricForcesDemonsRegistrationTest",
00036 mitkSymmetricForcesDemonsRegistrationTest
00037 },
00038
00039 {0,0}
00040 };
00041
00042
00043
00044
00045 char* lowercase(const char *string)
00046 {
00047 char *new_string, *p;
00048
00049 #ifdef __cplusplus
00050 new_string = static_cast<char *>(malloc(sizeof(char) *
00051 static_cast<size_t>(strlen(string) + 1)));
00052 #else
00053 new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
00054 #endif
00055
00056 if (!new_string)
00057 {
00058 return 0;
00059 }
00060 strcpy(new_string, string);
00061 p = new_string;
00062 while (*p != 0)
00063 {
00064 #ifdef __cplusplus
00065 *p = static_cast<char>(tolower(*p));
00066 #else
00067 *p = (char)(tolower(*p));
00068 #endif
00069
00070 ++p;
00071 }
00072 return new_string;
00073 }
00074
00075 int main(int ac, char *av[])
00076 {
00077 int i, NumTests, testNum, partial_match;
00078 char *arg, *test_name;
00079 int count;
00080 int testToRun = -1;
00081
00082
00083
00084 for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
00085 {
00086 }
00087 NumTests = count;
00088
00089
00090 if (ac < 2)
00091 {
00092
00093 printf("Available tests:\n");
00094 for (i =0; i < NumTests; ++i)
00095 {
00096 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00097 }
00098 printf("To run a test, enter the test number: ");
00099 fflush(stdout);
00100 testNum = 0;
00101 if( scanf("%d", &testNum) != 1 )
00102 {
00103 printf("Couldn't parse that input as a number\n");
00104 return -1;
00105 }
00106 if (testNum >= NumTests)
00107 {
00108 printf("%3d is an invalid test number.\n", testNum);
00109 return -1;
00110 }
00111 testToRun = testNum;
00112 ac--;
00113 av++;
00114 }
00115 partial_match = 0;
00116 arg = 0;
00117
00118 if(testToRun == -1 && ac > 1)
00119 {
00120 partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
00121 }
00122 if (partial_match && ac < 3)
00123 {
00124 printf("-R needs an additional parameter.\n");
00125 return -1;
00126 }
00127 if(testToRun == -1)
00128 {
00129 arg = lowercase(av[1 + partial_match]);
00130 }
00131 for (i =0; i < NumTests && testToRun == -1; ++i)
00132 {
00133 test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
00134 if (partial_match && strstr(test_name, arg) != NULL)
00135 {
00136 testToRun = i;
00137 ac -=2;
00138 av += 2;
00139 }
00140 else if (!partial_match && strcmp(test_name, arg) == 0)
00141 {
00142 testToRun = i;
00143 ac--;
00144 av++;
00145 }
00146 free(test_name);
00147 }
00148 if(arg)
00149 {
00150 free(arg);
00151 }
00152 if(testToRun != -1)
00153 {
00154 int result;
00155 mitk::LoggingBackend::Register(); ;
00156 result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
00157 mitk::LoggingBackend::Unregister();
00158 return result;
00159 }
00160
00161
00162
00163 printf("Available tests:\n");
00164 for (i =0; i < NumTests; ++i)
00165 {
00166 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00167 }
00168 printf("Failed: %s is an invalid test name.\n", av[1]);
00169
00170 return -1;
00171 }