1 /*
2  * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.com>
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 <string.h>
18 #include <fuse_opt.h>
19 
20 const struct fuse_opt nullopts[] = {
21 	FUSE_OPT_END
22 };
23 
24 const int nullresults[] = {
25 	0, 0, 0, 0, 0, 0
26 };
27 
28 const struct fuse_opt badopts[] = {
29 	FUSE_OPT_KEY("-p ", 0),
30 	FUSE_OPT_KEY("-C", 1),
31 	FUSE_OPT_KEY("-V", 3),
32 	FUSE_OPT_KEY("--version", 3),
33 	FUSE_OPT_KEY("-h", 2),
34 	FUSE_OPT_END
35 };
36 
37 static int
38 match_opts(const struct fuse_opt *opts, const int *results)
39 {
40 	if (fuse_opt_match(opts, NULL) != 0)
41 		return (1);
42 	if (fuse_opt_match(opts, "") != 0)
43 		return (1);
44 
45 	if (fuse_opt_match(opts, "bar=") != results[0])
46 		return (1);
47 	if (fuse_opt_match(opts, "--foo=") != results[1])
48 		return (1);
49 	if (fuse_opt_match(opts, "bar=%s") != results[2])
50 		return (1);
51 	if (fuse_opt_match(opts, "--foo=%lu") != results[3])
52 		return (1);
53 	if (fuse_opt_match(opts, "-x ") != results[4])
54 		return (1);
55 	if (fuse_opt_match(opts, "-x %s") != results[5])
56 		return (1);
57 
58 	return (0);
59 }
60 
61 int
62 main(int ac, char **av)
63 {
64 	if (match_opts(nullopts, nullresults) != 0)
65 		return (1);
66 	if (match_opts(badopts, nullresults) != 0)
67 		return (1);
68 	return (0);
69 }
70 
71