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