00001 #include <ctype.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 #include <stdlib.h>
00005
00006 #include "mitkCoreExtObjectFactory.h"
00007
00008
00009
00010
00011 int mitkAutoCropImageFilterTest(int, char*[]);
00012 int mitkBoundingObjectCutterTest(int, char*[]);
00013 int mitkContourMapper2DTest(int, char*[]);
00014 int mitkContourTest(int, char*[]);
00015 int mitkCoreExtObjectFactoryTest(int, char*[]);
00016 int mitkDataNodeExtTest(int, char*[]);
00017 int mitkExternalToolsTest(int, char*[]);
00018 int mitkMeshTest(int, char*[]);
00019 int mitkMultiStepperTest(int, char*[]);
00020 int mitkOrganTypePropertyTest(int, char*[]);
00021 int mitkPipelineSmartPointerCorrectnessTest(int, char*[]);
00022 int mitkPlaneFitTest(int, char*[]);
00023 int mitkPointLocatorTest(int, char*[]);
00024 int mitkToolManagerTest(int, char*[]);
00025 int mitkUnstructuredGridVtkWriterTest(int, char*[]);
00026 int mitkCompressedImageContainerTest(int, char*[]);
00027 int mitkCylindricToCartesianFilterTest(int, char*[]);
00028 int mitkExtractImageFilterTest(int, char*[]);
00029 int mitkManualSegmentationToSurfaceFilterTest(int, char*[]);
00030 int mitkOverwriteSliceImageFilterTest(int, char*[]);
00031 int mitkSurfaceToImageFilterTest(int, char*[]);
00032 int mitkLabeledImageToSurfaceFilterTest(int, char*[]);
00033
00034
00035
00036
00037 typedef int (*MainFuncPointer)(int , char*[]);
00038 typedef struct
00039 {
00040 const char* name;
00041 MainFuncPointer func;
00042 } functionMapEntry;
00043
00044 functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
00045 {
00046 "mitkAutoCropImageFilterTest",
00047 mitkAutoCropImageFilterTest
00048 },
00049 {
00050 "mitkBoundingObjectCutterTest",
00051 mitkBoundingObjectCutterTest
00052 },
00053 {
00054 "mitkContourMapper2DTest",
00055 mitkContourMapper2DTest
00056 },
00057 {
00058 "mitkContourTest",
00059 mitkContourTest
00060 },
00061 {
00062 "mitkCoreExtObjectFactoryTest",
00063 mitkCoreExtObjectFactoryTest
00064 },
00065 {
00066 "mitkDataNodeExtTest",
00067 mitkDataNodeExtTest
00068 },
00069 {
00070 "mitkExternalToolsTest",
00071 mitkExternalToolsTest
00072 },
00073 {
00074 "mitkMeshTest",
00075 mitkMeshTest
00076 },
00077 {
00078 "mitkMultiStepperTest",
00079 mitkMultiStepperTest
00080 },
00081 {
00082 "mitkOrganTypePropertyTest",
00083 mitkOrganTypePropertyTest
00084 },
00085 {
00086 "mitkPipelineSmartPointerCorrectnessTest",
00087 mitkPipelineSmartPointerCorrectnessTest
00088 },
00089 {
00090 "mitkPlaneFitTest",
00091 mitkPlaneFitTest
00092 },
00093 {
00094 "mitkPointLocatorTest",
00095 mitkPointLocatorTest
00096 },
00097 {
00098 "mitkToolManagerTest",
00099 mitkToolManagerTest
00100 },
00101 {
00102 "mitkUnstructuredGridVtkWriterTest",
00103 mitkUnstructuredGridVtkWriterTest
00104 },
00105 {
00106 "mitkCompressedImageContainerTest",
00107 mitkCompressedImageContainerTest
00108 },
00109 {
00110 "mitkCylindricToCartesianFilterTest",
00111 mitkCylindricToCartesianFilterTest
00112 },
00113 {
00114 "mitkExtractImageFilterTest",
00115 mitkExtractImageFilterTest
00116 },
00117 {
00118 "mitkManualSegmentationToSurfaceFilterTest",
00119 mitkManualSegmentationToSurfaceFilterTest
00120 },
00121 {
00122 "mitkOverwriteSliceImageFilterTest",
00123 mitkOverwriteSliceImageFilterTest
00124 },
00125 {
00126 "mitkSurfaceToImageFilterTest",
00127 mitkSurfaceToImageFilterTest
00128 },
00129 {
00130 "mitkLabeledImageToSurfaceFilterTest",
00131 mitkLabeledImageToSurfaceFilterTest
00132 },
00133
00134 {0,0}
00135 };
00136
00137
00138
00139
00140 char* lowercase(const char *string)
00141 {
00142 char *new_string, *p;
00143
00144 #ifdef __cplusplus
00145 new_string = static_cast<char *>(malloc(sizeof(char) *
00146 static_cast<size_t>(strlen(string) + 1)));
00147 #else
00148 new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
00149 #endif
00150
00151 if (!new_string)
00152 {
00153 return 0;
00154 }
00155 strcpy(new_string, string);
00156 p = new_string;
00157 while (*p != 0)
00158 {
00159 #ifdef __cplusplus
00160 *p = static_cast<char>(tolower(*p));
00161 #else
00162 *p = (char)(tolower(*p));
00163 #endif
00164
00165 ++p;
00166 }
00167 return new_string;
00168 }
00169
00170 int main(int ac, char *av[])
00171 {
00172 int i, NumTests, testNum, partial_match;
00173 char *arg, *test_name;
00174 int count;
00175 int testToRun = -1;
00176
00177
00178
00179 for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
00180 {
00181 }
00182 NumTests = count;
00183
00184
00185 if (ac < 2)
00186 {
00187
00188 printf("Available tests:\n");
00189 for (i =0; i < NumTests; ++i)
00190 {
00191 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00192 }
00193 printf("To run a test, enter the test number: ");
00194 fflush(stdout);
00195 testNum = 0;
00196 if( scanf("%d", &testNum) != 1 )
00197 {
00198 printf("Couldn't parse that input as a number\n");
00199 return -1;
00200 }
00201 if (testNum >= NumTests)
00202 {
00203 printf("%3d is an invalid test number.\n", testNum);
00204 return -1;
00205 }
00206 testToRun = testNum;
00207 ac--;
00208 av++;
00209 }
00210 partial_match = 0;
00211 arg = 0;
00212
00213 if(testToRun == -1 && ac > 1)
00214 {
00215 partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
00216 }
00217 if (partial_match && ac < 3)
00218 {
00219 printf("-R needs an additional parameter.\n");
00220 return -1;
00221 }
00222 if(testToRun == -1)
00223 {
00224 arg = lowercase(av[1 + partial_match]);
00225 }
00226 for (i =0; i < NumTests && testToRun == -1; ++i)
00227 {
00228 test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
00229 if (partial_match && strstr(test_name, arg) != NULL)
00230 {
00231 testToRun = i;
00232 ac -=2;
00233 av += 2;
00234 }
00235 else if (!partial_match && strcmp(test_name, arg) == 0)
00236 {
00237 testToRun = i;
00238 ac--;
00239 av++;
00240 }
00241 free(test_name);
00242 }
00243 if(arg)
00244 {
00245 free(arg);
00246 }
00247 if(testToRun != -1)
00248 {
00249 int result;
00250 mitk::LoggingBackend::Register(); RegisterCoreExtObjectFactory();
00251 result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
00252 mitk::LoggingBackend::Unregister();
00253 return result;
00254 }
00255
00256
00257
00258 printf("Available tests:\n");
00259 for (i =0; i < NumTests; ++i)
00260 {
00261 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00262 }
00263 printf("Failed: %s is an invalid test name.\n", av[1]);
00264
00265 return -1;
00266 }