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