test: Add unit test for CommandLineParseCommaSeparatedValuesEx

This commit is contained in:
Martin Fleisz 2021-07-06 11:35:43 +02:00 committed by akallabeth
parent a29cffbb6d
commit 74c6ad9906
1 changed files with 48 additions and 4 deletions

View File

@ -4,10 +4,19 @@
#include <winpr/cmdline.h>
#include <winpr/strlst.h>
static const char* testArgv[] = {
"mstsc.exe", "+z", "/w:1024", "/h:768", "/bpp:32", "/admin", "/multimon",
"+fonts", "-wallpaper", "/v:localhost:3389", 0
};
static const char* testArgv[] = { "mstsc.exe",
"+z",
"/w:1024",
"/h:768",
"/bpp:32",
"/admin",
"/multimon",
"+fonts",
"-wallpaper",
"/v:localhost:3389",
"/valuelist:value1,value2",
"/valuelist-empty:",
0 };
int TestCmdLine(int argc, char* argv[])
{
@ -64,6 +73,11 @@ int TestCmdLine(int argc, char* argv[])
"certificate name" },
{ "cert-ignore", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL,
"ignore certificate" },
{ "valuelist", COMMAND_LINE_VALUE_REQUIRED, "<val1>,<val2>", NULL, NULL, -1, NULL,
"List of comma separated values." },
{ "valuelist-empty", COMMAND_LINE_VALUE_REQUIRED, "<val1>,<val2>", NULL, NULL, -1, NULL,
"List of comma separated values. Used to test correct behavior if an empty list was "
"passed." },
{ "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1,
NULL, "print version" },
{ "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?",
@ -187,6 +201,36 @@ int TestCmdLine(int argc, char* argv[])
if (errno != 0)
goto out;
}
CommandLineSwitchCase(arg, "valuelist")
{
char** p;
size_t count;
p = CommandLineParseCommaSeparatedValuesEx(arg->Name, arg->Value, &count);
free(p);
if (!p || count != 3)
{
printf("CommandLineParseCommaSeparatedValuesEx: invalid p or count (%" PRIuz
"!=3)\n",
count);
goto out;
}
}
CommandLineSwitchCase(arg, "valuelist-empty")
{
char** p;
size_t count;
p = CommandLineParseCommaSeparatedValuesEx(arg->Name, arg->Value, &count);
free(p);
if (!p || count != 1)
{
printf("CommandLineParseCommaSeparatedValuesEx: invalid p or count (%" PRIuz
"!=1)\n",
count);
goto out;
}
}
CommandLineSwitchDefault(arg)
{
}