2 #include <winpr/crypto.h>
4 #include <freerdp/settings.h>
6 static BOOL test_alloc(
void)
10 const char* param[] = {
"foo:",
"bar",
"bla",
"rdp", NULL };
17 arg1 = freerdp_addin_argv_new(0, NULL);
18 if (!arg1 || (arg1->argc != 0) || (arg1->argv))
22 winpr_RAND(&rng,
sizeof(rng));
23 rng = abs(rng % 8192) + 1;
25 arg2 = freerdp_addin_argv_new(rng, NULL);
26 if (!arg2 || (arg2->argc != rng) || (!arg2->argv))
28 for (
int x = 0; x < arg2->argc; x++)
35 arg3 = freerdp_addin_argv_new(ARRAYSIZE(param) - 1, param);
36 if (!arg3 || (arg3->argc != ARRAYSIZE(param) - 1) || (!arg3->argv))
39 for (
int x = 0; x < arg3->argc; x++)
41 if (strcmp(arg3->argv[x], param[x]) != 0)
46 arg4 = freerdp_addin_argv_new(ARRAYSIZE(param), param);
51 freerdp_addin_argv_free(arg1);
52 freerdp_addin_argv_free(arg2);
53 freerdp_addin_argv_free(arg3);
54 freerdp_addin_argv_free(arg4);
55 printf(
"%s: %d\n", __func__, rc);
59 static BOOL test_clone(
void)
62 const char* param[] = {
"foo:",
"bar",
"bla",
"rdp" };
67 arg = freerdp_addin_argv_new(ARRAYSIZE(param), param);
68 if (!arg || (arg->argc != ARRAYSIZE(param)))
70 clone = freerdp_addin_argv_clone(arg);
71 if (!clone || (clone->argc != arg->argc))
74 for (
int x = 0; x < arg->argc; x++)
76 if (strcmp(param[x], arg->argv[x]) != 0)
78 if (strcmp(param[x], clone->argv[x]) != 0)
82 clone2 = freerdp_addin_argv_clone(NULL);
87 freerdp_addin_argv_free(arg);
88 freerdp_addin_argv_free(clone);
89 freerdp_addin_argv_free(clone2);
90 printf(
"%s: %d\n", __func__, rc);
94 static BOOL test_add_remove(
void)
96 const char* args[] = {
"foo",
"bar",
"bla",
"gaga" };
98 ADDIN_ARGV* arg = freerdp_addin_argv_new(0, NULL);
100 if (!arg || (arg->argc != 0) || arg->argv)
102 for (
size_t y = 0; y < ARRAYSIZE(args); y++)
104 const char* param = args[y];
105 if (!freerdp_addin_argv_add_argument(arg, param))
107 if (arg->argc != (
int)y + 1)
111 if (strcmp(arg->argv[y], param) != 0)
116 if (freerdp_addin_argv_del_argument(arg,
"foobar"))
120 if (freerdp_addin_argv_del_argument(NULL,
"foobar"))
124 if (freerdp_addin_argv_del_argument(arg, NULL))
128 for (
size_t y = 0; y < ARRAYSIZE(args); y++)
130 const char* param = args[y];
131 if (!freerdp_addin_argv_del_argument(arg, param))
133 for (
size_t x = y + 1; x < ARRAYSIZE(args); x++)
135 if (strcmp(arg->argv[x - y - 1], args[x]) != 0)
141 freerdp_addin_argv_free(arg);
142 printf(
"%s: %d\n", __func__, rc);
146 static BOOL test_set_argument(
void)
149 const char* newarg =
"foobar";
150 const char* args[] = {
"foo",
"bar",
"bla",
"gaga" };
154 arg = freerdp_addin_argv_new(ARRAYSIZE(args), args);
155 if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv)
159 ret = freerdp_addin_set_argument(NULL,
"foo");
162 ret = freerdp_addin_set_argument(arg, NULL);
167 ret = freerdp_addin_set_argument(arg,
"foo");
168 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)))
172 ret = freerdp_addin_set_argument(arg, newarg);
173 if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) ||
174 (strcmp(newarg, arg->argv[ARRAYSIZE(args)]) != 0))
179 freerdp_addin_argv_free(arg);
180 printf(
"%s: %d\n", __func__, rc);
184 static BOOL test_replace_argument(
void)
187 const char* newarg =
"foobar";
188 const char* args[] = {
"foo",
"bar",
"bla",
"gaga" };
192 arg = freerdp_addin_argv_new(ARRAYSIZE(args), args);
193 if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv)
197 ret = freerdp_addin_replace_argument(NULL,
"foo", newarg);
200 ret = freerdp_addin_replace_argument(arg, NULL, newarg);
203 ret = freerdp_addin_replace_argument(arg,
"foo", NULL);
208 ret = freerdp_addin_replace_argument(arg,
"foo", newarg);
209 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[0], newarg) != 0))
213 ret = freerdp_addin_replace_argument(arg,
"lalala", newarg);
214 if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) ||
215 (strcmp(newarg, arg->argv[ARRAYSIZE(args)]) != 0))
220 freerdp_addin_argv_free(arg);
221 printf(
"%s: %d\n", __func__, rc);
225 static BOOL test_set_argument_value(
void)
228 const char* newarg1 =
"foobar";
229 const char* newarg2 =
"lalala";
230 const char* fullnewarg1 =
"foo:foobar";
231 const char* fullnewarg2 =
"foo:lalala";
232 const char* fullnewvalue =
"lalala:foobar";
233 const char* args[] = {
"foo",
"foo:",
"bar",
"bla",
"gaga" };
237 arg = freerdp_addin_argv_new(ARRAYSIZE(args), args);
238 if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv)
242 ret = freerdp_addin_set_argument_value(NULL,
"foo", newarg1);
245 ret = freerdp_addin_set_argument_value(arg, NULL, newarg1);
248 ret = freerdp_addin_set_argument_value(arg,
"foo", NULL);
253 ret = freerdp_addin_set_argument_value(arg,
"foo", newarg1);
254 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[1], fullnewarg1) != 0))
256 ret = freerdp_addin_set_argument_value(arg,
"foo", newarg2);
257 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[1], fullnewarg2) != 0))
261 ret = freerdp_addin_set_argument_value(arg, newarg2, newarg1);
262 if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) ||
263 (strcmp(fullnewvalue, arg->argv[ARRAYSIZE(args)]) != 0))
268 freerdp_addin_argv_free(arg);
269 printf(
"%s: %d\n", __func__, rc);
273 static BOOL test_replace_argument_value(
void)
276 const char* newarg1 =
"foobar";
277 const char* newarg2 =
"lalala";
278 const char* fullnewarg1 =
"foo:foobar";
279 const char* fullnewarg2 =
"foo:lalala";
280 const char* fullnewvalue =
"lalala:foobar";
281 const char* args[] = {
"foo",
"foo:",
"bar",
"bla",
"gaga" };
285 arg = freerdp_addin_argv_new(ARRAYSIZE(args), args);
286 if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv)
290 ret = freerdp_addin_replace_argument_value(NULL,
"bar",
"foo", newarg1);
293 ret = freerdp_addin_replace_argument_value(arg, NULL,
"foo", newarg1);
296 ret = freerdp_addin_replace_argument_value(arg,
"foo", NULL, newarg1);
299 ret = freerdp_addin_replace_argument_value(arg,
"bar",
"foo", NULL);
304 ret = freerdp_addin_replace_argument_value(arg,
"bla",
"foo", newarg1);
305 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[3], fullnewarg1) != 0))
307 ret = freerdp_addin_replace_argument_value(arg,
"foo",
"foo", newarg2);
308 if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[0], fullnewarg2) != 0))
312 ret = freerdp_addin_replace_argument_value(arg,
"hahaha", newarg2, newarg1);
313 if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) ||
314 (strcmp(fullnewvalue, arg->argv[ARRAYSIZE(args)]) != 0))
319 freerdp_addin_argv_free(arg);
320 printf(
"%s: %d\n", __func__, rc);
324 int TestAddinArgv(
int argc,
char* argv[])
334 if (!test_add_remove())
336 if (!test_set_argument())
338 if (!test_replace_argument())
340 if (!test_set_argument_value())
342 if (!test_replace_argument_value())