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