Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CMake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
André Pedro
CMake
Commits
1731b90c
Commit
1731b90c
authored
8 years ago
by
Daniel Pfeifer
Browse files
Options
Downloads
Patches
Plain Diff
TestDriver: Revise C++ coding style using clang-format
parent
3270f763
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Templates/TestDriver.cxx.in
+45
-65
45 additions, 65 deletions
Templates/TestDriver.cxx.in
with
45 additions
and
65 deletions
Templates/TestDriver.cxx.in
+
45
−
65
View file @
1731b90c
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER)
#
pragma warning(disable
:
4996) /* deprecation */
#pragma warning(disable
:
4996) /* deprecation */
#endif
@CMAKE_TESTDRIVER_EXTRA_INCLUDES@
/* Forward declare test functions. */
@CMAKE_FORWARD_DECLARE_TESTS@
/* Create map. */
typedef int (*MainFuncPointer)(int
, char*[]);
typedef int (*MainFuncPointer)(int, char*
[]);
typedef struct
{
const char* name;
...
...
@@ -24,33 +23,31 @@ typedef struct
static functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
@CMAKE_FUNCTION_TABLE_ENTIRES@
{0,
0
}
{
0,
0
}
};
/* Allocate and create a lowercased copy of string
(note that it has to be free'd manually) */
static char* lowercase(const char
*string)
static char* lowercase(const char*
string)
{
char *new_string, *p;
size_t stringSize = 0;
#ifdef __cplusplus
stringSize = static_cast<size_t>(strlen(string) + 1);
new_string = static_cast<char
*>(malloc(sizeof(char) * stringSize));
new_string = static_cast<char*>(malloc(sizeof(char) * stringSize));
#else
stringSize = (size_t)(strlen(string) + 1);
new_string = (char
*)(malloc(sizeof(char) * stringSize));
new_string = (char*)(malloc(sizeof(char) * stringSize));
#endif
if (!new_string)
{
if (!new_string) {
return 0;
}
}
strncpy(new_string, string, stringSize);
p = new_string;
while (*p != 0)
{
while (*p != 0) {
#ifdef __cplusplus
*p = static_cast<char>(tolower(*p));
#else
...
...
@@ -58,11 +55,11 @@ static char* lowercase(const char *string)
#endif
++p;
}
}
return new_string;
}
int main(int ac, char
*av[])
int main(int ac, char*
av[])
{
int i, NumTests, testNum = 0, partial_match;
char *arg, *test_name;
...
...
@@ -71,96 +68,79 @@ int main(int ac, char *av[])
@CMAKE_TESTDRIVER_ARGVC_FUNCTION@
for(count =0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++)
{
}
for (count = 0; cmakeGeneratedFunctionMapEntries[count].name != 0; count++) {
}
NumTests = count;
/* If no test name was given */
/* process command line with user function. */
if (ac < 2)
{
if (ac < 2) {
/* Ask for a test. */
printf("Available tests:\n");
for (i =0; i < NumTests; ++i)
{
for (i = 0; i < NumTests; ++i) {
printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
}
}
printf("To run a test, enter the test number: ");
fflush(stdout);
if( scanf("%d", &testNum) != 1 )
{
if (scanf("%d", &testNum) != 1) {
printf("Couldn't parse that input as a number\n");
return -1;
}
if (testNum >= NumTests)
{
}
if (testNum >= NumTests) {
printf("%3d is an invalid test number.\n", testNum);
return -1;
}
}
testToRun = testNum;
ac--;
av++;
}
}
partial_match = 0;
arg = 0;
/* If partial match is requested. */
if(testToRun == -1 && ac > 1)
{
if (testToRun == -1 && ac > 1) {
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
}
if (partial_match && ac < 3)
{
}
if (partial_match && ac < 3) {
printf("-R needs an additional parameter.\n");
return -1;
}
if(testToRun == -1)
{
}
if (testToRun == -1) {
arg = lowercase(av[1 + partial_match]);
}
for (i =0; i < NumTests && testToRun == -1; ++i)
{
}
for (i = 0; i < NumTests && testToRun == -1; ++i) {
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
if (partial_match && strstr(test_name, arg) != NULL)
{
if (partial_match && strstr(test_name, arg) != NULL) {
testToRun = i;
ac -=2;
ac -=
2;
av += 2;
}
else if (!partial_match && strcmp(test_name, arg) == 0)
{
} else if (!partial_match && strcmp(test_name, arg) == 0) {
testToRun = i;
ac--;
av++;
}
free(test_name);
}
if(arg)
{
free(test_name);
}
if (arg) {
free(arg);
}
if(testToRun != -1)
{
}
if (testToRun != -1) {
int result;
@CMAKE_TESTDRIVER_BEFORE_TESTMAIN@
if (testToRun < 0 || testToRun >= NumTests)
{
printf(
"testToRun was modified by TestDriver code to an invalid value: %3d.\n",
testNum);
if (testToRun < 0 || testToRun >= NumTests) {
printf("testToRun was modified by TestDriver code to an invalid value: "
"%3d.\n",
testNum);
return -1;
}
}
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
@CMAKE_TESTDRIVER_AFTER_TESTMAIN@
return result;
}
}
/* Nothing was run, display the test names. */
printf("Available tests:\n");
for (i =0; i < NumTests; ++i)
{
for (i = 0; i < NumTests; ++i) {
printf("%3d. %s\n", i, cmakeGeneratedFunctionMapEntries[i].name);
}
}
printf("Failed: %s is an invalid test name.\n", av[1]);
return -1;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment