xref: /openbsd-src/regress/lib/libfuse/fuse-parse-cmdline.c (revision 0e9b8da4717409b081343114078c116a9e830baf)
1 /*
2  * Copyright (c) 2017 Helg Bredow <helg@openbsd.org>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #include <fuse.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 static int
22 test_null_args(void)
23 {
24 	if (fuse_parse_cmdline(NULL, NULL, NULL, NULL) == 0)
25 		exit(__LINE__);
26 
27 	return (0);
28 }
29 
30 static int
31 test_all_args(char **dir, int *multithreaded, int *foreground)
32 {
33 	char *argv[] = {
34 		"progname",
35 		"-odebug",
36 		/* read-only mount not supported yet */
37 		/*fuse_opt_add_arg(args, "-odebug,ro");*/
38 		/*fuse_opt_add_arg(args, "-r");*/
39 		"-d",
40 		"-f",
41 		"/mnt",
42 		"-s"
43 	};
44 	struct fuse_args args = FUSE_ARGS_INIT(6, argv);
45 
46 	if (dir != NULL)
47 		*dir = NULL;
48 
49 	if (multithreaded != NULL)
50 		*multithreaded = 0;
51 
52 	if (foreground != NULL)
53 		*foreground = 0;
54 
55 	if (fuse_parse_cmdline(&args, dir, multithreaded, foreground) != 0)
56 		exit (__LINE__);
57 
58 	if (dir != NULL && strcmp(*dir, "/mnt") != 0)
59 		exit(__LINE__);
60 	if (multithreaded != NULL && *multithreaded == 1)
61 		exit(__LINE__);
62 /* TODO Not implemented yet
63 	if (foreground != NULL && *foreground == 0)
64 		exit(__LINE__);
65 */
66 
67 	if (args.argc != 1)
68 		exit(__LINE__);
69 	if (strcmp(args.argv[0], "progname") != 0)
70 		exit(__LINE__);
71 
72 	return (0);
73 }
74 
75 int
76 main(void)
77 {
78 	char *dir;
79 	int multithreaded, foreground;
80 
81 	test_null_args();
82 	test_all_args(NULL, NULL, NULL);
83 	test_all_args(&dir, NULL, NULL);
84 	test_all_args(&dir, &multithreaded, NULL);
85 	test_all_args(&dir, &multithreaded, &foreground);
86 
87 	return (0);
88 }
89