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