Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
MitkPhotoacousticsLibTestDriver_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 mitkSlicedVolumeGeneratorTest(int, char*[]);
15 int mitkPhotoacousticTissueGeneratorTest(int, char*[]);
16 int mitkPhotoacousticVectorTest(int, char*[]);
17 int mitkPhotoacoustic3dVolumeTest(int, char*[]);
18 int mitkPhotoacousticVesselTreeTest(int, char*[]);
19 int mitkMcxyzXmlTest(int, char*[]);
20 int mitkPhotoacousticComposedVolumeTest(int, char*[]);
21 int mitkPhotoacousticNoiseGeneratorTest(int, char*[]);
22 int mitkSimulationBatchGeneratorTest(int, char*[]);
23 int mitkPropertyCalculatorTest(int, char*[]);
25 int mitkPhotoacousticVesselTest(int, char*[]);
26 
27 
28 #ifdef __cplusplus
29 #define CM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)
30 #else
31 #define CM_CAST(TYPE, EXPR) (TYPE)(EXPR)
32 #endif
33 
34 /* Create map. */
35 
36 typedef int (*MainFuncPointer)(int, char* []); /* NOLINT */
37 typedef struct /* NOLINT */
38 {
39  const char* name;
40  MainFuncPointer func;
41 } functionMapEntry;
42 
43 static functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
44  {
45  "mitkSlicedVolumeGeneratorTest",
47  },
48  {
49  "mitkPhotoacousticTissueGeneratorTest",
51  },
52  {
53  "mitkPhotoacousticVectorTest",
55  },
56  {
57  "mitkPhotoacoustic3dVolumeTest",
59  },
60  {
61  "mitkPhotoacousticVesselTreeTest",
63  },
64  {
65  "mitkMcxyzXmlTest",
67  },
68  {
69  "mitkPhotoacousticComposedVolumeTest",
71  },
72  {
73  "mitkPhotoacousticNoiseGeneratorTest",
75  },
76  {
77  "mitkSimulationBatchGeneratorTest",
79  },
80  {
81  "mitkPropertyCalculatorTest",
83  },
84  {
85  "mitkPhotoacousticVesselMeanderStrategyTest",
87  },
88  {
89  "mitkPhotoacousticVesselTest",
91  },
92 
93  { NULL, NULL } /* NOLINT */
94 };
95 
96 static const int NumTests = CM_CAST(int,
97  sizeof(cmakeGeneratedFunctionMapEntries) / sizeof(functionMapEntry)) - 1;
98 
99 /* Allocate and create a lowercased copy of string
100  (note that it has to be free'd manually) */
101 static char* lowercase(const char* string)
102 {
103  char *new_string, *p;
104  size_t stringSize;
105 
106  stringSize = CM_CAST(size_t, strlen(string) + 1);
107  new_string = CM_CAST(char*, malloc(sizeof(char) * stringSize));
108 
109  if (new_string == NULL) { /* NOLINT */
110  return NULL; /* NOLINT */
111  }
112  strcpy(new_string, string);
113  for (p = new_string; *p != 0; ++p) {
114  *p = CM_CAST(char, tolower(*p));
115  }
116  return new_string;
117 }
118 
119 int main(int ac, char* av[])
120 {
121  int i, testNum = 0, partial_match;
122  char *arg;
123  int testToRun = -1;
124 
125 
126 
127  /* If no test name was given */
128  /* process command line with user function. */
129  if (ac < 2) {
130  /* Ask for a test. */
131  printf("Available tests:\n");
132  for (i = 0; i < NumTests; ++i) {
133  printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
134  }
135  printf("To run a test, enter the test number: ");
136  fflush(stdout);
137  if (scanf("%d", &testNum) != 1) {
138  printf("Couldn't parse that input as a number\n");
139  return -1;
140  }
141  if (testNum >= NumTests) {
142  printf("%3d is an invalid test number.\n", testNum);
143  return -1;
144  }
145  testToRun = testNum;
146  ac--;
147  av++;
148  }
149  partial_match = 0;
150  arg = NULL; /* NOLINT */
151  /* If partial match is requested. */
152  if (testToRun == -1 && ac > 1) {
153  partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
154  }
155  if (partial_match != 0 && ac < 3) {
156  printf("-R needs an additional parameter.\n");
157  return -1;
158  }
159  if (testToRun == -1) {
160  arg = lowercase(av[1 + partial_match]);
161  }
162  for (i = 0; i < NumTests && testToRun == -1; ++i) {
163  char *test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
164  if (partial_match != 0 && strstr(test_name, arg) != NULL) { /* NOLINT */
165  testToRun = i;
166  ac -= 2;
167  av += 2;
168  } else if (partial_match == 0 && strcmp(test_name, arg) == 0) {
169  testToRun = i;
170  ac--;
171  av++;
172  }
173  free(test_name);
174  }
175  free(arg);
176  if (testToRun != -1) {
177  int result;
178 
179 for (int avIndex = 1; avIndex < ac; ++avIndex) globalCmdLineArgs.push_back(av[avIndex]);
181 ;
182  if (testToRun < 0 || testToRun >= NumTests) {
183  printf("testToRun was modified by TestDriver code to an invalid value: "
184  "%3d.\n",
185  testNum);
186  return -1;
187  }
188  result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
190  return result;
191  }
192 
193  /* Nothing was run, display the test names. */
194  printf("Available tests:\n");
195  for (i = 0; i < NumTests; ++i) {
196  printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
197  }
198  printf("Failed: %s is an invalid test name.\n", av[1]);
199 
200  return -1;
201 }
int mitkPhotoacousticTissueGeneratorTest(int, char *[])
static void Register()
registers MITK logging backend at mbilog
Definition: mitkLog.cpp:71
int mitkPhotoacousticVesselMeanderStrategyTest(int, char *[])
int mitkPhotoacousticVectorTest(int, char *[])
static const int NumTests
int mitkPhotoacoustic3dVolumeTest(int, char *[])
static functionMapEntry cmakeGeneratedFunctionMapEntries[]
int mitkPropertyCalculatorTest(int, char *[])
int mitkPhotoacousticVesselTreeTest(int, char *[])
int mitkSimulationBatchGeneratorTest(int, char *[])
static char * lowercase(const char *string)
int mitkPhotoacousticNoiseGeneratorTest(int, char *[])
int mitkPhotoacousticVesselTest(int, char *[])
int mitkMcxyzXmlTest(int, char *[])
int(* MainFuncPointer)(int, char *[])
#define CM_CAST(TYPE, EXPR)
int mitkSlicedVolumeGeneratorTest(int, char *[])
int main(int ac, char *av[])
static void Unregister()
Unregisters MITK logging backend at mbilog.
Definition: mitkLog.cpp:79
int mitkPhotoacousticComposedVolumeTest(int, char *[])
std::vector< std::string > globalCmdLineArgs