xref: /haiku/src/tests/system/libroot/posix/getsubopt_test.cpp (revision 338ddd836f8bc1473d6911e931d31e2253872a3b)
1 /*
2  * Copyright 2010, Oliver Tappe <zooey@hirschkaefer.de>.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 
12 int
main()13 main()
14 {
15 	char* const keys[] = {
16 		"mode", "be-lenient", NULL
17 	};
18 
19 	char* option = strdup("mode=readwrite,unknown,be-lenient");
20 	char* value = NULL;
21 	int result = getsubopt(&option, keys, &value);
22 	if (result != 0)
23 		fprintf(stderr, "failed 1: result=%d, expected %d\n", result, 0);
24 	if (value == NULL || strcmp(value, "readwrite") != 0)
25 		fprintf(stderr, "failed 2: value=%s, expected 'readwrite'\n", value);
26 	result = getsubopt(&option, keys, &value);
27 	if (result != -1)
28 		fprintf(stderr, "failed 3: result=%d, expected %d\n", result, -1);
29 	if (value != NULL)
30 		fprintf(stderr, "failed 4: value=%p, expected NULL\n", value);
31 	result = getsubopt(&option, keys, &value);
32 	if (result != 1)
33 		fprintf(stderr, "failed 5: result=%d, expected %d\n", result, 1);
34 	if (value != NULL)
35 		fprintf(stderr, "failed 6: value=%p, expected NULL\n", value);
36 
37 	return 0;
38 }
39