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 mitkCoreObjectFactoryTest(int, char*[]);
00012 int mitkPointSetWriterTest(int, char*[]);
00013 int mitkMaterialTest(int, char*[]);
00014 int mitkDataNodeTest(int, char*[]);
00015 int mitkActionTest(int, char*[]);
00016 int mitkDataStorageTest(int, char*[]);
00017 int mitkEnumerationPropertyTest(int, char*[]);
00018 int mitkEventMapperTest(int, char*[]);
00019 int mitkEventTest(int, char*[]);
00020 int mitkFocusManagerTest(int, char*[]);
00021 int mitkGenericPropertyTest(int, char*[]);
00022 int mitkGeometry3DTest(int, char*[]);
00023 int mitkGeometryDataToSurfaceFilterTest(int, char*[]);
00024 int mitkGlobalInteractionTest(int, char*[]);
00025 int mitkImageDataItemTest(int, char*[]);
00026 int mitkImageTest(int, char*[]);
00027 int mitkBaseDataTest(int, char*[]);
00028 int mitkInteractorTest(int, char*[]);
00029 int mitkITKThreadingTest(int, char*[]);
00030 int mitkLevelWindowTest(int, char*[]);
00031 int mitkMessageTest(int, char*[]);
00032 int mitkPixelTypeTest(int, char*[]);
00033 int mitkPlaneGeometryTest(int, char*[]);
00034 int mitkPointSetFileIOTest(int, char*[]);
00035 int mitkPointSetTest(int, char*[]);
00036 int mitkPointSetInteractorTest(int, char*[]);
00037 int mitkPropertyListTest(int, char*[]);
00038 int mitkSlicedGeometry3DTest(int, char*[]);
00039 int mitkSliceNavigationControllerTest(int, char*[]);
00040 int mitkStateMachineTest(int, char*[]);
00041 int mitkStateMachineFactoryTest(int, char*[]);
00042 int mitkStateTest(int, char*[]);
00043 int mitkSurfaceTest(int, char*[]);
00044 int mitkSurfaceToSurfaceFilterTest(int, char*[]);
00045 int mitkTimeSlicedGeometryTest(int, char*[]);
00046 int mitkTransitionTest(int, char*[]);
00047 int mitkUndoControllerTest(int, char*[]);
00048 int mitkVtkWidgetRenderingTest(int, char*[]);
00049 int mitkVerboseLimitedLinearUndoTest(int, char*[]);
00050 int mitkWeakPointerTest(int, char*[]);
00051 int mitkTransferFunctionTest(int, char*[]);
00052 int mitkStepperTest(int, char*[]);
00053 int itkTotalVariationDenoisingImageFilterTest(int, char*[]);
00054 int mitkDICOMLocaleTest(int, char*[]);
00055 int mitkPointSetLocaleTest(int, char*[]);
00056 int mitkRenderingManagerTest(int, char*[]);
00057 int vtkMitkThickSlicesFilterTest(int, char*[]);
00058 int mitkSurfaceVtkWriterTest(int, char*[]);
00059 int mitkPicFileWriterTest(int, char*[]);
00060 int mitkImageWriterTest(int, char*[]);
00061 int mitkImageTimeSelectorTest(int, char*[]);
00062 int mitkPicFileReaderTest(int, char*[]);
00063 int mitkDataNodeFactoryTest(int, char*[]);
00064
00065
00066
00067
00068 typedef int (*MainFuncPointer)(int , char*[]);
00069 typedef struct
00070 {
00071 const char* name;
00072 MainFuncPointer func;
00073 } functionMapEntry;
00074
00075 functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
00076 {
00077 "mitkCoreObjectFactoryTest",
00078 mitkCoreObjectFactoryTest
00079 },
00080 {
00081 "mitkPointSetWriterTest",
00082 mitkPointSetWriterTest
00083 },
00084 {
00085 "mitkMaterialTest",
00086 mitkMaterialTest
00087 },
00088 {
00089 "mitkDataNodeTest",
00090 mitkDataNodeTest
00091 },
00092 {
00093 "mitkActionTest",
00094 mitkActionTest
00095 },
00096 {
00097 "mitkDataStorageTest",
00098 mitkDataStorageTest
00099 },
00100 {
00101 "mitkEnumerationPropertyTest",
00102 mitkEnumerationPropertyTest
00103 },
00104 {
00105 "mitkEventMapperTest",
00106 mitkEventMapperTest
00107 },
00108 {
00109 "mitkEventTest",
00110 mitkEventTest
00111 },
00112 {
00113 "mitkFocusManagerTest",
00114 mitkFocusManagerTest
00115 },
00116 {
00117 "mitkGenericPropertyTest",
00118 mitkGenericPropertyTest
00119 },
00120 {
00121 "mitkGeometry3DTest",
00122 mitkGeometry3DTest
00123 },
00124 {
00125 "mitkGeometryDataToSurfaceFilterTest",
00126 mitkGeometryDataToSurfaceFilterTest
00127 },
00128 {
00129 "mitkGlobalInteractionTest",
00130 mitkGlobalInteractionTest
00131 },
00132 {
00133 "mitkImageDataItemTest",
00134 mitkImageDataItemTest
00135 },
00136 {
00137 "mitkImageTest",
00138 mitkImageTest
00139 },
00140 {
00141 "mitkBaseDataTest",
00142 mitkBaseDataTest
00143 },
00144 {
00145 "mitkInteractorTest",
00146 mitkInteractorTest
00147 },
00148 {
00149 "mitkITKThreadingTest",
00150 mitkITKThreadingTest
00151 },
00152 {
00153 "mitkLevelWindowTest",
00154 mitkLevelWindowTest
00155 },
00156 {
00157 "mitkMessageTest",
00158 mitkMessageTest
00159 },
00160 {
00161 "mitkPixelTypeTest",
00162 mitkPixelTypeTest
00163 },
00164 {
00165 "mitkPlaneGeometryTest",
00166 mitkPlaneGeometryTest
00167 },
00168 {
00169 "mitkPointSetFileIOTest",
00170 mitkPointSetFileIOTest
00171 },
00172 {
00173 "mitkPointSetTest",
00174 mitkPointSetTest
00175 },
00176 {
00177 "mitkPointSetInteractorTest",
00178 mitkPointSetInteractorTest
00179 },
00180 {
00181 "mitkPropertyListTest",
00182 mitkPropertyListTest
00183 },
00184 {
00185 "mitkSlicedGeometry3DTest",
00186 mitkSlicedGeometry3DTest
00187 },
00188 {
00189 "mitkSliceNavigationControllerTest",
00190 mitkSliceNavigationControllerTest
00191 },
00192 {
00193 "mitkStateMachineTest",
00194 mitkStateMachineTest
00195 },
00196 {
00197 "mitkStateMachineFactoryTest",
00198 mitkStateMachineFactoryTest
00199 },
00200 {
00201 "mitkStateTest",
00202 mitkStateTest
00203 },
00204 {
00205 "mitkSurfaceTest",
00206 mitkSurfaceTest
00207 },
00208 {
00209 "mitkSurfaceToSurfaceFilterTest",
00210 mitkSurfaceToSurfaceFilterTest
00211 },
00212 {
00213 "mitkTimeSlicedGeometryTest",
00214 mitkTimeSlicedGeometryTest
00215 },
00216 {
00217 "mitkTransitionTest",
00218 mitkTransitionTest
00219 },
00220 {
00221 "mitkUndoControllerTest",
00222 mitkUndoControllerTest
00223 },
00224 {
00225 "mitkVtkWidgetRenderingTest",
00226 mitkVtkWidgetRenderingTest
00227 },
00228 {
00229 "mitkVerboseLimitedLinearUndoTest",
00230 mitkVerboseLimitedLinearUndoTest
00231 },
00232 {
00233 "mitkWeakPointerTest",
00234 mitkWeakPointerTest
00235 },
00236 {
00237 "mitkTransferFunctionTest",
00238 mitkTransferFunctionTest
00239 },
00240 {
00241 "mitkStepperTest",
00242 mitkStepperTest
00243 },
00244 {
00245 "itkTotalVariationDenoisingImageFilterTest",
00246 itkTotalVariationDenoisingImageFilterTest
00247 },
00248 {
00249 "mitkDICOMLocaleTest",
00250 mitkDICOMLocaleTest
00251 },
00252 {
00253 "mitkPointSetLocaleTest",
00254 mitkPointSetLocaleTest
00255 },
00256 {
00257 "mitkRenderingManagerTest",
00258 mitkRenderingManagerTest
00259 },
00260 {
00261 "vtkMitkThickSlicesFilterTest",
00262 vtkMitkThickSlicesFilterTest
00263 },
00264 {
00265 "mitkSurfaceVtkWriterTest",
00266 mitkSurfaceVtkWriterTest
00267 },
00268 {
00269 "mitkPicFileWriterTest",
00270 mitkPicFileWriterTest
00271 },
00272 {
00273 "mitkImageWriterTest",
00274 mitkImageWriterTest
00275 },
00276 {
00277 "mitkImageTimeSelectorTest",
00278 mitkImageTimeSelectorTest
00279 },
00280 {
00281 "mitkPicFileReaderTest",
00282 mitkPicFileReaderTest
00283 },
00284 {
00285 "mitkDataNodeFactoryTest",
00286 mitkDataNodeFactoryTest
00287 },
00288
00289 {0,0}
00290 };
00291
00292
00293
00294
00295 char* lowercase(const char *string)
00296 {
00297 char *new_string, *p;
00298
00299 #ifdef __cplusplus
00300 new_string = static_cast<char *>(malloc(sizeof(char) *
00301 static_cast<size_t>(strlen(string) + 1)));
00302 #else
00303 new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
00304 #endif
00305
00306 if (!new_string)
00307 {
00308 return 0;
00309 }
00310 strcpy(new_string, string);
00311 p = new_string;
00312 while (*p != 0)
00313 {
00314 #ifdef __cplusplus
00315 *p = static_cast<char>(tolower(*p));
00316 #else
00317 *p = (char)(tolower(*p));
00318 #endif
00319
00320 ++p;
00321 }
00322 return new_string;
00323 }
00324
00325 int main(int ac, char *av[])
00326 {
00327 int i, NumTests, testNum, partial_match;
00328 char *arg, *test_name;
00329 int count;
00330 int testToRun = -1;
00331
00332
00333
00334 for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
00335 {
00336 }
00337 NumTests = count;
00338
00339
00340 if (ac < 2)
00341 {
00342
00343 printf("Available tests:\n");
00344 for (i =0; i < NumTests; ++i)
00345 {
00346 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00347 }
00348 printf("To run a test, enter the test number: ");
00349 fflush(stdout);
00350 testNum = 0;
00351 if( scanf("%d", &testNum) != 1 )
00352 {
00353 printf("Couldn't parse that input as a number\n");
00354 return -1;
00355 }
00356 if (testNum >= NumTests)
00357 {
00358 printf("%3d is an invalid test number.\n", testNum);
00359 return -1;
00360 }
00361 testToRun = testNum;
00362 ac--;
00363 av++;
00364 }
00365 partial_match = 0;
00366 arg = 0;
00367
00368 if(testToRun == -1 && ac > 1)
00369 {
00370 partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
00371 }
00372 if (partial_match && ac < 3)
00373 {
00374 printf("-R needs an additional parameter.\n");
00375 return -1;
00376 }
00377 if(testToRun == -1)
00378 {
00379 arg = lowercase(av[1 + partial_match]);
00380 }
00381 for (i =0; i < NumTests && testToRun == -1; ++i)
00382 {
00383 test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
00384 if (partial_match && strstr(test_name, arg) != NULL)
00385 {
00386 testToRun = i;
00387 ac -=2;
00388 av += 2;
00389 }
00390 else if (!partial_match && strcmp(test_name, arg) == 0)
00391 {
00392 testToRun = i;
00393 ac--;
00394 av++;
00395 }
00396 free(test_name);
00397 }
00398 if(arg)
00399 {
00400 free(arg);
00401 }
00402 if(testToRun != -1)
00403 {
00404 int result;
00405 mitk::LoggingBackend::Register(); ;
00406 result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
00407 mitk::LoggingBackend::Unregister();
00408 return result;
00409 }
00410
00411
00412
00413 printf("Available tests:\n");
00414 for (i =0; i < NumTests; ++i)
00415 {
00416 printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
00417 }
00418 printf("Failed: %s is an invalid test name.\n", av[1]);
00419
00420 return -1;
00421 }