libwinpr: fix build of tests on Windows
This commit is contained in:
parent
d5b635c9e8
commit
1ee21f558e
215
build/winpr/libwinpr/asn1/test/TestAsn1.c
Normal file
215
build/winpr/libwinpr/asn1/test/TestAsn1.c
Normal file
@ -0,0 +1,215 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestAsn1Module(int, char*[]);
|
||||
int TestAsn1Encoder(int, char*[]);
|
||||
int TestAsn1Decoder(int, char*[]);
|
||||
int TestAsn1Encode(int, char*[]);
|
||||
int TestAsn1Decode(int, char*[]);
|
||||
int TestAsn1String(int, char*[]);
|
||||
int TestAsn1Integer(int, char*[]);
|
||||
int TestAsn1Compare(int, char*[]);
|
||||
int TestAsn1BerEnc(int, char*[]);
|
||||
int TestAsn1BerDec(int, char*[]);
|
||||
int TestAsn1DerEnc(int, char*[]);
|
||||
int TestAsn1DerDec(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestAsn1Module",
|
||||
TestAsn1Module
|
||||
},
|
||||
{
|
||||
"TestAsn1Encoder",
|
||||
TestAsn1Encoder
|
||||
},
|
||||
{
|
||||
"TestAsn1Decoder",
|
||||
TestAsn1Decoder
|
||||
},
|
||||
{
|
||||
"TestAsn1Encode",
|
||||
TestAsn1Encode
|
||||
},
|
||||
{
|
||||
"TestAsn1Decode",
|
||||
TestAsn1Decode
|
||||
},
|
||||
{
|
||||
"TestAsn1String",
|
||||
TestAsn1String
|
||||
},
|
||||
{
|
||||
"TestAsn1Integer",
|
||||
TestAsn1Integer
|
||||
},
|
||||
{
|
||||
"TestAsn1Compare",
|
||||
TestAsn1Compare
|
||||
},
|
||||
{
|
||||
"TestAsn1BerEnc",
|
||||
TestAsn1BerEnc
|
||||
},
|
||||
{
|
||||
"TestAsn1BerDec",
|
||||
TestAsn1BerDec
|
||||
},
|
||||
{
|
||||
"TestAsn1DerEnc",
|
||||
TestAsn1DerEnc
|
||||
},
|
||||
{
|
||||
"TestAsn1DerDec",
|
||||
TestAsn1DerDec
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
160
build/winpr/libwinpr/crt/test/TestCrt.c
Normal file
160
build/winpr/libwinpr/crt/test/TestCrt.c
Normal file
@ -0,0 +1,160 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestAlignment(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestAlignment",
|
||||
TestAlignment
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
190
build/winpr/libwinpr/file/test/TestFile.c
Normal file
190
build/winpr/libwinpr/file/test/TestFile.c
Normal file
@ -0,0 +1,190 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestFileCreateFile(int, char*[]);
|
||||
int TestFileDeleteFile(int, char*[]);
|
||||
int TestFileReadFile(int, char*[]);
|
||||
int TestFileWriteFile(int, char*[]);
|
||||
int TestFileFindFirstFile(int, char*[]);
|
||||
int TestFileFindFirstFileEx(int, char*[]);
|
||||
int TestFileFindNextFile(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestFileCreateFile",
|
||||
TestFileCreateFile
|
||||
},
|
||||
{
|
||||
"TestFileDeleteFile",
|
||||
TestFileDeleteFile
|
||||
},
|
||||
{
|
||||
"TestFileReadFile",
|
||||
TestFileReadFile
|
||||
},
|
||||
{
|
||||
"TestFileWriteFile",
|
||||
TestFileWriteFile
|
||||
},
|
||||
{
|
||||
"TestFileFindFirstFile",
|
||||
TestFileFindFirstFile
|
||||
},
|
||||
{
|
||||
"TestFileFindFirstFileEx",
|
||||
TestFileFindFirstFileEx
|
||||
},
|
||||
{
|
||||
"TestFileFindNextFile",
|
||||
TestFileFindNextFile
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
170
build/winpr/libwinpr/interlocked/test/TestInterlocked.c
Normal file
170
build/winpr/libwinpr/interlocked/test/TestInterlocked.c
Normal file
@ -0,0 +1,170 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestInterlockedAccess(int, char*[]);
|
||||
int TestInterlockedSList(int, char*[]);
|
||||
int TestInterlockedDList(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestInterlockedAccess",
|
||||
TestInterlockedAccess
|
||||
},
|
||||
{
|
||||
"TestInterlockedSList",
|
||||
TestInterlockedSList
|
||||
},
|
||||
{
|
||||
"TestInterlockedDList",
|
||||
TestInterlockedDList
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
160
build/winpr/libwinpr/io/test/TestIo.c
Normal file
160
build/winpr/libwinpr/io/test/TestIo.c
Normal file
@ -0,0 +1,160 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestIoGetOverlappedResult(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestIoGetOverlappedResult",
|
||||
TestIoGetOverlappedResult
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
185
build/winpr/libwinpr/library/test/TestLibrary.c
Normal file
185
build/winpr/libwinpr/library/test/TestLibrary.c
Normal file
@ -0,0 +1,185 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestLibraryAddDllDirectory(int, char*[]);
|
||||
int TestLibraryRemoveDllDirectory(int, char*[]);
|
||||
int TestLibrarySetDefaultDllDirectories(int, char*[]);
|
||||
int TestLibraryLoadLibrary(int, char*[]);
|
||||
int TestLibraryFreeLibrary(int, char*[]);
|
||||
int TestLibraryGetProcAddress(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestLibraryAddDllDirectory",
|
||||
TestLibraryAddDllDirectory
|
||||
},
|
||||
{
|
||||
"TestLibraryRemoveDllDirectory",
|
||||
TestLibraryRemoveDllDirectory
|
||||
},
|
||||
{
|
||||
"TestLibrarySetDefaultDllDirectories",
|
||||
TestLibrarySetDefaultDllDirectories
|
||||
},
|
||||
{
|
||||
"TestLibraryLoadLibrary",
|
||||
TestLibraryLoadLibrary
|
||||
},
|
||||
{
|
||||
"TestLibraryFreeLibrary",
|
||||
TestLibraryFreeLibrary
|
||||
},
|
||||
{
|
||||
"TestLibraryGetProcAddress",
|
||||
TestLibraryGetProcAddress
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
265
build/winpr/libwinpr/path/test/TestPath.c
Normal file
265
build/winpr/libwinpr/path/test/TestPath.c
Normal file
@ -0,0 +1,265 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestPathCchAddBackslash(int, char*[]);
|
||||
int TestPathCchRemoveBackslash(int, char*[]);
|
||||
int TestPathCchAddBackslashEx(int, char*[]);
|
||||
int TestPathCchRemoveBackslashEx(int, char*[]);
|
||||
int TestPathCchAddExtension(int, char*[]);
|
||||
int TestPathCchAppend(int, char*[]);
|
||||
int TestPathCchAppendEx(int, char*[]);
|
||||
int TestPathCchCanonicalize(int, char*[]);
|
||||
int TestPathCchCanonicalizeEx(int, char*[]);
|
||||
int TestPathAllocCanonicalize(int, char*[]);
|
||||
int TestPathCchCombine(int, char*[]);
|
||||
int TestPathCchCombineEx(int, char*[]);
|
||||
int TestPathAllocCombine(int, char*[]);
|
||||
int TestPathCchFindExtension(int, char*[]);
|
||||
int TestPathCchRenameExtension(int, char*[]);
|
||||
int TestPathCchRemoveExtension(int, char*[]);
|
||||
int TestPathCchIsRoot(int, char*[]);
|
||||
int TestPathIsUNCEx(int, char*[]);
|
||||
int TestPathCchSkipRoot(int, char*[]);
|
||||
int TestPathCchStripToRoot(int, char*[]);
|
||||
int TestPathCchStripPrefix(int, char*[]);
|
||||
int TestPathCchRemoveFileSpec(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestPathCchAddBackslash",
|
||||
TestPathCchAddBackslash
|
||||
},
|
||||
{
|
||||
"TestPathCchRemoveBackslash",
|
||||
TestPathCchRemoveBackslash
|
||||
},
|
||||
{
|
||||
"TestPathCchAddBackslashEx",
|
||||
TestPathCchAddBackslashEx
|
||||
},
|
||||
{
|
||||
"TestPathCchRemoveBackslashEx",
|
||||
TestPathCchRemoveBackslashEx
|
||||
},
|
||||
{
|
||||
"TestPathCchAddExtension",
|
||||
TestPathCchAddExtension
|
||||
},
|
||||
{
|
||||
"TestPathCchAppend",
|
||||
TestPathCchAppend
|
||||
},
|
||||
{
|
||||
"TestPathCchAppendEx",
|
||||
TestPathCchAppendEx
|
||||
},
|
||||
{
|
||||
"TestPathCchCanonicalize",
|
||||
TestPathCchCanonicalize
|
||||
},
|
||||
{
|
||||
"TestPathCchCanonicalizeEx",
|
||||
TestPathCchCanonicalizeEx
|
||||
},
|
||||
{
|
||||
"TestPathAllocCanonicalize",
|
||||
TestPathAllocCanonicalize
|
||||
},
|
||||
{
|
||||
"TestPathCchCombine",
|
||||
TestPathCchCombine
|
||||
},
|
||||
{
|
||||
"TestPathCchCombineEx",
|
||||
TestPathCchCombineEx
|
||||
},
|
||||
{
|
||||
"TestPathAllocCombine",
|
||||
TestPathAllocCombine
|
||||
},
|
||||
{
|
||||
"TestPathCchFindExtension",
|
||||
TestPathCchFindExtension
|
||||
},
|
||||
{
|
||||
"TestPathCchRenameExtension",
|
||||
TestPathCchRenameExtension
|
||||
},
|
||||
{
|
||||
"TestPathCchRemoveExtension",
|
||||
TestPathCchRemoveExtension
|
||||
},
|
||||
{
|
||||
"TestPathCchIsRoot",
|
||||
TestPathCchIsRoot
|
||||
},
|
||||
{
|
||||
"TestPathIsUNCEx",
|
||||
TestPathIsUNCEx
|
||||
},
|
||||
{
|
||||
"TestPathCchSkipRoot",
|
||||
TestPathCchSkipRoot
|
||||
},
|
||||
{
|
||||
"TestPathCchStripToRoot",
|
||||
TestPathCchStripToRoot
|
||||
},
|
||||
{
|
||||
"TestPathCchStripPrefix",
|
||||
TestPathCchStripPrefix
|
||||
},
|
||||
{
|
||||
"TestPathCchRemoveFileSpec",
|
||||
TestPathCchRemoveFileSpec
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
160
build/winpr/libwinpr/pipe/test/TestPipe.c
Normal file
160
build/winpr/libwinpr/pipe/test/TestPipe.c
Normal file
@ -0,0 +1,160 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestPipeCreatePipe(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestPipeCreatePipe",
|
||||
TestPipeCreatePipe
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
175
build/winpr/libwinpr/sspi/test/TestSspi.c
Normal file
175
build/winpr/libwinpr/sspi/test/TestSspi.c
Normal file
@ -0,0 +1,175 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* Forward declare test functions. */
|
||||
int TestQuerySecurityPackageInfo(int, char*[]);
|
||||
int TestEnumerateSecurityPackages(int, char*[]);
|
||||
int TestInitializeSecurityContext(int, char*[]);
|
||||
int TestAcquireCredentialsHandle(int, char*[]);
|
||||
|
||||
|
||||
/* Create map. */
|
||||
|
||||
typedef int (*MainFuncPointer)(int , char*[]);
|
||||
typedef struct
|
||||
{
|
||||
const char* name;
|
||||
MainFuncPointer func;
|
||||
} functionMapEntry;
|
||||
|
||||
functionMapEntry cmakeGeneratedFunctionMapEntries[] = {
|
||||
{
|
||||
"TestQuerySecurityPackageInfo",
|
||||
TestQuerySecurityPackageInfo
|
||||
},
|
||||
{
|
||||
"TestEnumerateSecurityPackages",
|
||||
TestEnumerateSecurityPackages
|
||||
},
|
||||
{
|
||||
"TestInitializeSecurityContext",
|
||||
TestInitializeSecurityContext
|
||||
},
|
||||
{
|
||||
"TestAcquireCredentialsHandle",
|
||||
TestAcquireCredentialsHandle
|
||||
},
|
||||
|
||||
{0,0}
|
||||
};
|
||||
|
||||
/* Allocate and create a lowercased copy of string
|
||||
(note that it has to be free'd manually) */
|
||||
|
||||
char* lowercase(const char *string)
|
||||
{
|
||||
char *new_string, *p;
|
||||
|
||||
#ifdef __cplusplus
|
||||
new_string = static_cast<char *>(malloc(sizeof(char) *
|
||||
static_cast<size_t>(strlen(string) + 1)));
|
||||
#else
|
||||
new_string = (char *)(malloc(sizeof(char) * (size_t)(strlen(string) + 1)));
|
||||
#endif
|
||||
|
||||
if (!new_string)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
strcpy(new_string, string);
|
||||
p = new_string;
|
||||
while (*p != 0)
|
||||
{
|
||||
#ifdef __cplusplus
|
||||
*p = static_cast<char>(tolower(*p));
|
||||
#else
|
||||
*p = (char)(tolower(*p));
|
||||
#endif
|
||||
|
||||
++p;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
|
||||
int main(int ac, char *av[])
|
||||
{
|
||||
int i, NumTests, testNum, partial_match;
|
||||
char *arg, *test_name;
|
||||
int count;
|
||||
int testToRun = -1;
|
||||
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
/* Ask for a test. */
|
||||
printf("Available tests:\n");
|
||||
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);
|
||||
testNum = 0;
|
||||
if( scanf("%d", &testNum) != 1 )
|
||||
{
|
||||
printf("Couldn't parse that input as a number\n");
|
||||
return -1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
partial_match = (strcmp(av[1], "-R") == 0) ? 1 : 0;
|
||||
}
|
||||
if (partial_match && ac < 3)
|
||||
{
|
||||
printf("-R needs an additional parameter.\n");
|
||||
return -1;
|
||||
}
|
||||
if(testToRun == -1)
|
||||
{
|
||||
arg = lowercase(av[1 + partial_match]);
|
||||
}
|
||||
for (i =0; i < NumTests && testToRun == -1; ++i)
|
||||
{
|
||||
test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
|
||||
if (partial_match && strstr(test_name, arg) != NULL)
|
||||
{
|
||||
testToRun = i;
|
||||
ac -=2;
|
||||
av += 2;
|
||||
}
|
||||
else if (!partial_match && strcmp(test_name, arg) == 0)
|
||||
{
|
||||
testToRun = i;
|
||||
ac--;
|
||||
av++;
|
||||
}
|
||||
free(test_name);
|
||||
}
|
||||
if(arg)
|
||||
{
|
||||
free(arg);
|
||||
}
|
||||
if(testToRun != -1)
|
||||
{
|
||||
int result;
|
||||
|
||||
result = (*cmakeGeneratedFunctionMapEntries[testToRun].func)(ac, av);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Nothing was run, display the test names. */
|
||||
printf("Available tests:\n");
|
||||
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;
|
||||
}
|
@ -22,7 +22,7 @@ add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
|
||||
MONOLITHIC ${MONOLITHIC_BUILD}
|
||||
MODULE winpr
|
||||
MODULES winpr-file)
|
||||
MODULES winpr-file winpr-path)
|
||||
|
||||
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
||||
|
||||
|
@ -21,6 +21,10 @@ set(MODULE_PREFIX "WINPR_IO")
|
||||
set(${MODULE_PREFIX}_SRCS
|
||||
io.c)
|
||||
|
||||
if(MSVC AND (NOT MONOLITHIC_BUILD))
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)
|
||||
endif()
|
||||
|
||||
add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT"
|
||||
MONOLITHIC ${MONOLITHIC_BUILD}
|
||||
SOURCES ${${MODULE_PREFIX}_SRCS})
|
||||
|
2
winpr/libwinpr/io/module.def
Normal file
2
winpr/libwinpr/io/module.def
Normal file
@ -0,0 +1,2 @@
|
||||
LIBRARY "libwinpr-io"
|
||||
EXPORTS
|
@ -16,8 +16,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
set(MODULE_NAME "TestLibraryA")
|
||||
set(MODULE_PREFIX "TEST_LIBRARY_A")
|
||||
|
||||
add_library(${MODULE_NAME} TestLibraryA.c)
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} TestLibraryA.c)
|
||||
|
||||
if(MSVC)
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)
|
||||
endif()
|
||||
|
||||
add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
|
4
winpr/libwinpr/library/test/TestLibraryA/module.def
Normal file
4
winpr/libwinpr/library/test/TestLibraryA/module.def
Normal file
@ -0,0 +1,4 @@
|
||||
LIBRARY "TestLibraryA"
|
||||
EXPORTS
|
||||
FunctionA @1
|
||||
FunctionB @2
|
@ -16,8 +16,15 @@
|
||||
# limitations under the License.
|
||||
|
||||
set(MODULE_NAME "TestLibraryB")
|
||||
set(MODULE_PREFIX "TEST_LIBRARY_B")
|
||||
|
||||
add_library(${MODULE_NAME} TestLibraryB.c)
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} TestLibraryB.c)
|
||||
|
||||
if(MSVC)
|
||||
set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def)
|
||||
endif()
|
||||
|
||||
add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "")
|
||||
|
||||
|
4
winpr/libwinpr/library/test/TestLibraryB/module.def
Normal file
4
winpr/libwinpr/library/test/TestLibraryB/module.def
Normal file
@ -0,0 +1,4 @@
|
||||
LIBRARY "TestLibraryB"
|
||||
EXPORTS
|
||||
FunctionA @1
|
||||
FunctionB @2
|
Loading…
Reference in New Issue
Block a user