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