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