6 @CMAKE_TESTDRIVER_EXTRA_INCLUDES@
9 /* Forward declare test functions. */
10 @CMAKE_FORWARD_DECLARE_TESTS@
14 typedef int (*MainFuncPointer
)(int , char*[]);
21 functionMapEntry cmakeGeneratedFunctionMapEntries
[] = {
22 @CMAKE_FUNCTION_TABLE_ENTIRES@
26 /* Allocate and create a lowercased copy of string
27 (note that it has to be free'd manually) */
29 char* lowercase(const char *string
)
32 new_string
= (char *)malloc(sizeof(char) * (size_t)(strlen(string
) + 1));
37 strcpy(new_string
, string
);
41 *p
= (char)tolower(*p
);
47 int main(int ac
, char *av
[])
49 int i
, NumTests
, testNum
, partial_match
;
50 char *arg
, *test_name
;
54 @CMAKE_TESTDRIVER_ARGVC_FUNCTION@
56 for(count
=0; cmakeGeneratedFunctionMapEntries
[count
].name
!= 0; count
++)
60 /* If no test name was given */
61 /* process command line with user function. */
65 printf("Available tests:\n");
66 for (i
=0; i
< NumTests
; ++i
)
68 printf("%3d. %s\n", i
, cmakeGeneratedFunctionMapEntries
[i
].name
);
70 printf("To run a test, enter the test number: ");
73 scanf("%d", &testNum
);
74 if (testNum
>= NumTests
)
76 printf("%3d is an invalid test number.\n", testNum
);
85 /* If partial match is requested. */
86 if(testToRun
== -1 && ac
> 1)
88 partial_match
= (strcmp(av
[1], "-R") == 0) ? 1 : 0;
90 if (partial_match
&& ac
< 3)
92 printf("-R needs an additional parameter.\n");
97 arg
= lowercase(av
[1 + partial_match
]);
99 for (i
=0; i
< NumTests
&& testToRun
== -1; ++i
)
101 test_name
= lowercase(cmakeGeneratedFunctionMapEntries
[i
].name
);
102 if (partial_match
&& strstr(test_name
, arg
) != NULL
)
108 else if (!partial_match
&& strcmp(test_name
, arg
) == 0)
123 @CMAKE_TESTDRIVER_BEFORE_TESTMAIN@
124 result
= (*cmakeGeneratedFunctionMapEntries
[testToRun
].func
)(ac
, av
);
125 @CMAKE_TESTDRIVER_AFTER_TESTMAIN@
130 /* Nothing was run, display the test names. */
131 printf("Available tests:\n");
132 for (i
=0; i
< NumTests
; ++i
)
134 printf("%3d. %s\n", i
, cmakeGeneratedFunctionMapEntries
[i
].name
);
136 printf("Failed: %s is an invalid test name.\n", av
[1]);