Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
MitkAlgorithmsExtTestDriver_main.cpp
Go to the documentation of this file.
1 #include <ctype.h> /* NOLINT */
2 #include <stdio.h> /* NOLINT */
3 #include <stdlib.h> /* NOLINT */
4 #include <string.h> /* NOLINT */
5 
6 #if defined(_MSC_VER)
7 #pragma warning(disable : 4996) /* deprecation */
8 #endif
9 
11 
12 
13 /* Forward declare test functions. */
14 int mitkAutoCropImageFilterTest(int, char*[]);
15 int mitkBoundingObjectCutterTest(int, char*[]);
17 int mitkPlaneFitTest(int, char*[]);
18 int mitkSimpleHistogramTest(int, char*[]);
19 int mitkCovarianceMatrixCalculatorTest(int, char*[]);
23 int mitkCropTimestepsImageFilterTest(int, char*[]);
24 int mitkLabeledImageToSurfaceFilterTest(int, char*[]);
25 
26 
27 #ifdef __cplusplus
28 #define CM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)
29 #else
30 #define CM_CAST(TYPE, EXPR) (TYPE)(EXPR)
31 #endif
32 
33 /* Create map. */
34 
35 typedef int (*MainFuncPointer)(int, char* []); /* NOLINT */
36 typedef struct /* NOLINT */
37 {
38  const char* name;
39  MainFuncPointer func;
40 } functionMapEntry;
41 
42 static functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
43  {
44  "mitkAutoCropImageFilterTest",
46  },
47  {
48  "mitkBoundingObjectCutterTest",
50  },
51  {
52  "mitkImageToUnstructuredGridFilterTest",
54  },
55  {
56  "mitkPlaneFitTest",
58  },
59  {
60  "mitkSimpleHistogramTest",
62  },
63  {
64  "mitkCovarianceMatrixCalculatorTest",
66  },
67  {
68  "mitkAnisotropicIterativeClosestPointRegistrationTest",
70  },
71  {
72  "mitkUnstructuredGridClusteringFilterTest",
74  },
75  {
76  "mitkUnstructuredGridToUnstructuredGridFilterTest",
78  },
79  {
80  "mitkCropTimestepsImageFilterTest",
82  },
83  {
84  "mitkLabeledImageToSurfaceFilterTest",
86  },
87 
88  { NULL, NULL } /* NOLINT */
89 };
90 
91 static const int NumTests = CM_CAST(int,
92  sizeof(cmakeGeneratedFunctionMapEntries) / sizeof(functionMapEntry)) - 1;
93 
94 /* Allocate and create a lowercased copy of string
95  (note that it has to be free'd manually) */
96 static char* lowercase(const char* string)
97 {
98  char *new_string, *p;
99  size_t stringSize;
100 
101  stringSize = CM_CAST(size_t, strlen(string) + 1);
102  new_string = CM_CAST(char*, malloc(sizeof(char) * stringSize));
103 
104  if (new_string == NULL) { /* NOLINT */
105  return NULL; /* NOLINT */
106  }
107  strcpy(new_string, string);
108  for (p = new_string; *p != 0; ++p) {
109  *p = CM_CAST(char, tolower(*p));
110  }
111  return new_string;
112 }
113 
114 int main(int ac, char* av[])
115 {
116  int i, testNum = 0, partial_match;
117  char *arg;
118  int testToRun = -1;
119 
120 
121 
122  /* If no test name was given */
123  /* process command line with user function. */
124  if (ac < 2) {
125  /* Ask for a test. */
126  printf("Available tests:\n");
127  for (i = 0; i < NumTests; ++i) {
128  printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
129  }
130  printf("To run a test, enter the test number: ");
131  fflush(stdout);
132  if (scanf("%d", &testNum) != 1) {
133  printf("Couldn't parse that input as a number\n");
134  return -1;
135  }
136  if (testNum >= NumTests) {
137  printf("%3d is an invalid test number.\n", testNum);
138  return -1;
139  }
140  testToRun = testNum;
141  ac--;
142  av++;
143  }
144  partial_match = 0;
145  arg = NULL; /* NOLINT */
146  /* If partial match is requested. */
147  if (testToRun == -1 && ac > 1) {
148  partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
149  }
150  if (partial_match != 0 && ac < 3) {
151  printf("-R needs an additional parameter.\n");
152  return -1;
153  }
154  if (testToRun == -1) {
155  arg = lowercase(av[1 + partial_match]);
156  }
157  for (i = 0; i < NumTests && testToRun == -1; ++i) {
158  char *test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
159  if (partial_match != 0 && strstr(test_name, arg) != NULL) { /* NOLINT */
160  testToRun = i;
161  ac -= 2;
162  av += 2;
163  } else if (partial_match == 0 && strcmp(test_name, arg) == 0) {
164  testToRun = i;
165  ac--;
166  av++;
167  }
168  free(test_name);
169  }
170  free(arg);
171  if (testToRun != -1) {
172  int result;
173 
174 for (int avIndex = 1; avIndex < ac; ++avIndex) globalCmdLineArgs.push_back(av[avIndex]);
176 ;
177  if (testToRun < 0 || testToRun >= NumTests) {
178  printf("testToRun was modified by TestDriver code to an invalid value: "
179  "%3d.\n",
180  testNum);
181  return -1;
182  }
183  result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
185  return result;
186  }
187 
188  /* Nothing was run, display the test names. */
189  printf("Available tests:\n");
190  for (i = 0; i < NumTests; ++i) {
191  printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
192  }
193  printf("Failed: %s is an invalid test name.\n", av[1]);
194 
195  return -1;
196 }
#define CM_CAST(TYPE, EXPR)
int mitkAutoCropImageFilterTest(int, char *[])
static void Register()
registers MITK logging backend at mbilog
Definition: mitkLog.cpp:71
int mitkUnstructuredGridClusteringFilterTest(int, char *[])
int mitkLabeledImageToSurfaceFilterTest(int, char *[])
static char * lowercase(const char *string)
static const int NumTests
int(* MainFuncPointer)(int, char *[])
int mitkUnstructuredGridToUnstructuredGridFilterTest(int, char *[])
static functionMapEntry cmakeGeneratedFunctionMapEntries[]
int mitkPlaneFitTest(int, char *[])
int main(int ac, char *av[])
int mitkAnisotropicIterativeClosestPointRegistrationTest(int, char *[])
int mitkCropTimestepsImageFilterTest(int, char *[])
int mitkCovarianceMatrixCalculatorTest(int, char *[])
int mitkBoundingObjectCutterTest(int, char *[])
int mitkImageToUnstructuredGridFilterTest(int, char *[])
static void Unregister()
Unregisters MITK logging backend at mbilog.
Definition: mitkLog.cpp:79
int mitkSimpleHistogramTest(int, char *[])
std::vector< std::string > globalCmdLineArgs