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