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