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