summaryrefslogtreecommitdiff
path: root/regress/lib/libfuse/fuse-opt-match.c
blob: 5b38cb4e1e413b5928d0e740a97373a1f97ebd39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* $OpenBSD: fuse-opt-match.c,v 1.5 2018/07/20 12:05:08 helg Exp $ */
/*
 * Copyright (c) 2017 Helg Bredow <xx404@msn.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <assert.h>
#include <stddef.h>
#include <fuse_opt.h>

static const struct fuse_opt emptyopts[] = {
	FUSE_OPT_END
};

static const struct fuse_opt opts[] = {
	FUSE_OPT_KEY("-p ",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-C",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-V",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("--version",	FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-h",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("const=false",	FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("cache=no",	FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("cache=yes",	FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("debug",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("ro",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("--foo=",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("bars=%s",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("--fool=%lu",	FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-x ",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-n %u",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_KEY("-P",		FUSE_OPT_KEY_DISCARD),
	FUSE_OPT_END
};

int
main(void)
{
	assert(fuse_opt_match(emptyopts, "debug")	==	0);

	assert(fuse_opt_match(opts, NULL)		==	0);
	assert(fuse_opt_match(opts, "-p ")		==	1);
	assert(fuse_opt_match(opts, "-C")		==	1);
	assert(fuse_opt_match(opts, "-c")		==	0);
	assert(fuse_opt_match(opts, "-V")		==	1);
	assert(fuse_opt_match(opts, "--version")	==	1);
	assert(fuse_opt_match(opts, "-h")		==	1);
	assert(fuse_opt_match(opts, "const=false")	==	1);
	assert(fuse_opt_match(opts, "const=falsefalse")	==	0);
	assert(fuse_opt_match(opts, "cache=no")		==	1);
	assert(fuse_opt_match(opts, "cache=yes")	==	1);
	assert(fuse_opt_match(opts, "debug")		==	1);
	assert(fuse_opt_match(opts, "ro")		==	1);
	assert(fuse_opt_match(opts, "ro_fallback")	==	0);
	assert(fuse_opt_match(opts, "--foo=bar")	==	1);
	assert(fuse_opt_match(opts, "bars=foo")		==	1);
	assert(fuse_opt_match(opts, "--fool=bool")	==	1);
	assert(fuse_opt_match(opts, "--fool=1")		==	1);
	assert(fuse_opt_match(opts, "-x bar")		==	1);
	assert(fuse_opt_match(opts, "-xbar")		==	1);
	assert(fuse_opt_match(opts, "-n 100")		==	1);
	assert(fuse_opt_match(opts, "-n100")		==	1);
	assert(fuse_opt_match(opts, "-P")		==	1);

	return (0);
}