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