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