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