1 #include <freerdp/client.h>
2 #include <freerdp/client/cmdline.h>
3 #include <freerdp/settings.h>
4 #include <winpr/cmdline.h>
5 #include <winpr/spec.h>
6 #include <winpr/strlst.h>
7 #include <winpr/collections.h>
9 typedef BOOL (*validate_settings_pr)(rdpSettings* settings);
11 #define printref() printf("%s:%d: in function %-40s:", __FILE__, __LINE__, __func__)
13 #define TEST_ERROR(format, ...) \
16 (void)fprintf(stderr, format, ##__VA_ARGS__); \
18 (void)printf(format, ##__VA_ARGS__); \
19 (void)fflush(stdout); \
22 #define TEST_FAILURE(format, ...) \
26 (void)printf(" FAILURE "); \
27 (void)printf(format, ##__VA_ARGS__); \
28 (void)fflush(stdout); \
31 static void print_test_title(
int argc,
char** argv)
33 printf(
"Running test:");
35 for (
int i = 0; i < argc; i++)
37 printf(
" %s", argv[i]);
43 static INLINE BOOL testcase(
const char* name,
char** argv,
size_t argc,
int expected_return,
44 validate_settings_pr validate_settings)
47 BOOL valid_settings = TRUE;
50 WINPR_ASSERT(argc <= INT_MAX);
52 print_test_title((
int)argc, argv);
56 TEST_ERROR(
"Test %s could not allocate settings!\n", name);
60 status = freerdp_client_settings_parse_command_line(settings, (
int)argc, argv, FALSE);
62 if (validate_settings)
64 valid_settings = validate_settings(settings);
69 if (status == expected_return)
78 TEST_FAILURE(
"Expected status %d, got status %d\n", expected_return, status);
86 #define DRIVE_REDIRECT_PATH "c:\\Windows"
88 #define DRIVE_REDIRECT_PATH "/tmp"
91 static BOOL check_settings_smartcard_no_redirection(rdpSettings* settings)
97 TEST_FAILURE(
"Expected RedirectSmartCards = FALSE, but RedirectSmartCards = TRUE!\n");
101 if (freerdp_device_collection_find_type(settings, RDPDR_DTYP_SMARTCARD))
103 TEST_FAILURE(
"Expected no SMARTCARD device, but found at least one!\n");
113 validate_settings_pr validate_settings;
114 const char* command_line[128];
118 const char* expected_value;
119 } modified_arguments[8];
123 static const test tests[] = {
124 { COMMAND_LINE_STATUS_PRINT_HELP,
125 check_settings_smartcard_no_redirection,
126 {
"testfreerdp",
"--help", 0 },
128 { COMMAND_LINE_STATUS_PRINT_HELP,
129 check_settings_smartcard_no_redirection,
130 {
"testfreerdp",
"/help", 0 },
132 { COMMAND_LINE_STATUS_PRINT_HELP,
133 check_settings_smartcard_no_redirection,
134 {
"testfreerdp",
"-help", 0 },
136 { COMMAND_LINE_STATUS_PRINT_VERSION,
137 check_settings_smartcard_no_redirection,
138 {
"testfreerdp",
"--version", 0 },
140 { COMMAND_LINE_STATUS_PRINT_VERSION,
141 check_settings_smartcard_no_redirection,
142 {
"testfreerdp",
"/version", 0 },
144 { COMMAND_LINE_STATUS_PRINT_VERSION,
145 check_settings_smartcard_no_redirection,
146 {
"testfreerdp",
"-version", 0 },
149 check_settings_smartcard_no_redirection,
150 {
"testfreerdp",
"-v",
"test.freerdp.com", 0 },
153 check_settings_smartcard_no_redirection,
154 {
"testfreerdp",
"--v",
"test.freerdp.com", 0 },
157 check_settings_smartcard_no_redirection,
158 {
"testfreerdp",
"/v:test.freerdp.com", 0 },
161 check_settings_smartcard_no_redirection,
162 {
"testfreerdp",
"/sound",
"/drive:media," DRIVE_REDIRECT_PATH,
"/v:test.freerdp.com", 0 },
165 check_settings_smartcard_no_redirection,
166 {
"testfreerdp",
"-u",
"test",
"-p",
"test",
"-v",
"test.freerdp.com", 0 },
167 { { 4,
"****" }, { 0 } } },
169 check_settings_smartcard_no_redirection,
170 {
"testfreerdp",
"/u:test",
"/p:test",
"/v:test.freerdp.com", 0 },
171 { { 2,
"/p:****" }, { 0 } } },
172 { COMMAND_LINE_ERROR_NO_KEYWORD,
173 check_settings_smartcard_no_redirection,
174 {
"testfreerdp",
"-invalid", 0 },
176 { COMMAND_LINE_ERROR_NO_KEYWORD,
177 check_settings_smartcard_no_redirection,
178 {
"testfreerdp",
"--invalid", 0 },
180 #if defined(WITH_FREERDP_DEPRECATED_CMDLINE)
181 { COMMAND_LINE_STATUS_PRINT,
182 check_settings_smartcard_no_redirection,
183 {
"testfreerdp",
"/kbd-list", 0 },
185 { COMMAND_LINE_STATUS_PRINT,
186 check_settings_smartcard_no_redirection,
187 {
"testfreerdp",
"/monitor-list", 0 },
190 { COMMAND_LINE_STATUS_PRINT,
191 check_settings_smartcard_no_redirection,
192 {
"testfreerdp",
"/list:kbd", 0 },
194 { COMMAND_LINE_STATUS_PRINT,
195 check_settings_smartcard_no_redirection,
196 {
"testfreerdp",
"/list:monitor", 0 },
199 check_settings_smartcard_no_redirection,
200 {
"testfreerdp",
"/sound",
"/drive:media:" DRIVE_REDIRECT_PATH,
"/v:test.freerdp.com", 0 },
203 check_settings_smartcard_no_redirection,
204 {
"testfreerdp",
"/sound",
"/drive:media,/foo/bar/blabla",
"/v:test.freerdp.com", 0 },
209 COMMAND_LINE_STATUS_PRINT, check_settings_smartcard_no_redirection,
210 {
"testfreerdp",
"-z",
"--plugin",
"cliprdr",
"--plugin",
"rdpsnd",
"--data",
"alsa",
"latency:100",
"--",
"--plugin",
"rdpdr",
"--data",
"disk:w7share:/home/w7share",
"--",
"--plugin",
"drdynvc",
"--data",
"tsmf:decoder:gstreamer",
"--",
"-u",
"test",
"host.example.com", 0},
217 static void check_modified_arguments(
const test* test,
char** command_line,
int* rc)
219 const char* expected_argument = NULL;
221 for (
int k = 0; (expected_argument = test->modified_arguments[k].expected_value); k++)
223 int index = test->modified_arguments[k].index;
224 char* actual_argument = command_line[index];
226 if (0 != strcmp(actual_argument, expected_argument))
229 printf(
"Failure: overridden argument %d is %s but it should be %s\n", index,
230 actual_argument, expected_argument);
231 (void)fflush(stdout);
237 int TestClientCmdLine(
int argc,
char* argv[])
243 for (
size_t i = 0; i <
sizeof(tests) /
sizeof(tests[0]); i++)
245 const test* current = &tests[i];
247 char** command_line = string_list_copy(current->command_line);
249 if (!testcase(__func__, command_line, string_list_length((
const char*
const*)command_line),
250 current->expected_status, current->validate_settings))
252 TEST_FAILURE(
"parsing arguments.\n");
256 check_modified_arguments(current, command_line, &failure);
260 string_list_print(stdout, (
const char*
const*)command_line);
264 string_list_free(command_line);
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API rdpSettings * freerdp_settings_new(DWORD flags)
creates a new setting struct
FREERDP_API void freerdp_settings_free(rdpSettings *settings)
Free a settings struct with all data in it.