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
)
34 new_string
= static_cast<char *>(malloc(sizeof(char) *
35 static_cast<size_t>(strlen(string
) + 1)));
37 new_string
= (char *)(malloc(sizeof(char) * (size_t)(strlen(string
) + 1)));
44 strcpy(new_string
, string
);
49 *p
= static_cast<char>(tolower(*p
));
51 *p
= (char)(tolower(*p
));
59 int main(int ac
, char *av
[])
61 int i
, NumTests
, testNum
, partial_match
;
62 char *arg
, *test_name
;
66 @CMAKE_TESTDRIVER_ARGVC_FUNCTION@
68 for(count
=0; cmakeGeneratedFunctionMapEntries
[count
].name
!= 0; count
++)
72 /* If no test name was given */
73 /* process command line with user function. */
77 printf("Available tests:\n");
78 for (i
=0; i
< NumTests
; ++i
)
80 printf("%3d. %s\n", i
, cmakeGeneratedFunctionMapEntries
[i
].name
);
82 printf("To run a test, enter the test number: ");
85 if( scanf("%d", &testNum
) != 1 )
87 printf("Couldn't parse that input as a number\n");
90 if (testNum
>= NumTests
)
92 printf("%3d is an invalid test number.\n", testNum
);
101 /* If partial match is requested. */
102 if(testToRun
== -1 && ac
> 1)
104 partial_match
= (strcmp(av
[1], "-R") == 0) ? 1 : 0;
106 if (partial_match
&& ac
< 3)
108 printf("-R needs an additional parameter.\n");
113 arg
= lowercase(av
[1 + partial_match
]);
115 for (i
=0; i
< NumTests
&& testToRun
== -1; ++i
)
117 test_name
= lowercase(cmakeGeneratedFunctionMapEntries
[i
].name
);
118 if (partial_match
&& strstr(test_name
, arg
) != NULL
)
124 else if (!partial_match
&& strcmp(test_name
, arg
) == 0)
139 @CMAKE_TESTDRIVER_BEFORE_TESTMAIN@
140 result
= (*cmakeGeneratedFunctionMapEntries
[testToRun
].func
)(ac
, av
);
141 @CMAKE_TESTDRIVER_AFTER_TESTMAIN@
146 /* Nothing was run, display the test names. */
147 printf("Available tests:\n");
148 for (i
=0; i
< NumTests
; ++i
)
150 printf("%3d. %s\n", i
, cmakeGeneratedFunctionMapEntries
[i
].name
);
152 printf("Failed: %s is an invalid test name.\n", av
[1]);