summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvestre Gallon <syl@cvs.openbsd.org>2013-08-09 16:20:11 +0000
committerSylvestre Gallon <syl@cvs.openbsd.org>2013-08-09 16:20:11 +0000
commit36760a658f4b528a63cd07a3967b25005fb7963e (patch)
tree587f4acf974af3f3e7d2bd420ca2ff3003f9cc06
parentccd7609add1e162892d9f4fb56b9bb75253ed446 (diff)
Add regress test for fuse_opt.
-rw-r--r--regress/lib/libfuse/Makefile29
-rw-r--r--regress/lib/libfuse/fuse-opt-add-arg.c61
-rw-r--r--regress/lib/libfuse/fuse-opt-add-opt-escaped.c49
-rw-r--r--regress/lib/libfuse/fuse-opt-add-opt.c53
-rw-r--r--regress/lib/libfuse/fuse-opt-insert-arg.c70
-rw-r--r--regress/lib/libfuse/fuse-opt-match.c70
6 files changed, 332 insertions, 0 deletions
diff --git a/regress/lib/libfuse/Makefile b/regress/lib/libfuse/Makefile
new file mode 100644
index 00000000000..050d67c0b60
--- /dev/null
+++ b/regress/lib/libfuse/Makefile
@@ -0,0 +1,29 @@
+# $OpenBSD: Makefile,v 1.1 2013/08/09 16:20:10 syl Exp $
+
+REGRESS_TARGETS= run-fuse-opt-add-opt
+REGRESS_TARGETS+= run-fuse-opt-add-opt-escaped
+REGRESS_TARGETS+= run-fuse-opt-add-arg
+REGRESS_TARGETS+= run-fuse-opt-insert-arg
+REGRESS_TARGETS+= run-fuse-opt-match
+
+LDFLAGS+= -lfuse
+CLEANFILES= fuse-opt-add-opt
+CLEANFILES+=fuse-opt-add-opt-escaped
+CLEANFILES+=fuse-opt-add-arg
+CLEANFILES+=fuse-opt-insert-arg
+CLEANFILES+=fuse-opt-match
+
+.PHONY: ${REGRESS_TARGETS}
+
+run-fuse-opt-add-opt: fuse-opt-add-opt
+ ./fuse-opt-add-opt
+run-fuse-opt-add-opt-escaped: fuse-opt-add-opt-escaped
+ ./fuse-opt-add-opt-escaped
+run-fuse-opt-add-arg: fuse-opt-add-arg
+ ./fuse-opt-add-arg
+run-fuse-opt-insert-arg: fuse-opt-insert-arg
+ ./fuse-opt-insert-arg
+run-fuse-opt-match: fuse-opt-match
+ ./fuse-opt-match
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libfuse/fuse-opt-add-arg.c b/regress/lib/libfuse/fuse-opt-add-arg.c
new file mode 100644
index 00000000000..eb28060a1e8
--- /dev/null
+++ b/regress/lib/libfuse/fuse-opt-add-arg.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.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 <string.h>
+#include <fuse_opt.h>
+
+#define ADD_ARG(fa, a) if (fuse_opt_add_arg(fa, a) != 0) \
+ return (1);
+
+char *argstest[] = {
+ "-d",
+ "test",
+ "--test",
+ "-o foo",
+ "barfoo"
+};
+
+int
+main(int ac, char **av)
+{
+ struct fuse_args args = FUSE_ARGS_INIT(ac, av);
+ int len, i;
+
+ len = sizeof(argstest) / sizeof(*argstest);
+
+ for (i = 0; i < len; i++)
+ ADD_ARG(&args, argstest[i]);
+
+ if (!args.allocated)
+ return (1);
+ if (fuse_opt_add_arg(&args, NULL) != -1)
+ return (1);
+ if (fuse_opt_add_arg(&args, "") != -1)
+ return (1);
+
+ for (i = 0; i < len; i++)
+ if (strcmp(args.argv[i+1], argstest[i]) != 0)
+ return (1);
+
+ if (args.argc != len + 1)
+ return (1);
+
+ fuse_opt_free_args(&args);
+ if (args.allocated)
+ return (1);
+ return (0);
+}
+
diff --git a/regress/lib/libfuse/fuse-opt-add-opt-escaped.c b/regress/lib/libfuse/fuse-opt-add-opt-escaped.c
new file mode 100644
index 00000000000..b9c3711bfea
--- /dev/null
+++ b/regress/lib/libfuse/fuse-opt-add-opt-escaped.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.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 <string.h>
+#include <fuse_opt.h>
+
+int
+main(int ac, char **av)
+{
+ char *opt = NULL;
+ char *opt2;
+
+ opt2 = strdup("-a,\\,a\\,b\\,c,\\\\\\,\\\\\\,\\,\\,\\,\\\\\\\\\\,");
+ if (opt2 == NULL)
+ return (0);
+
+ if (fuse_opt_add_opt_escaped(&opt2, "test") != 0)
+ return (1);
+
+ if (fuse_opt_add_opt_escaped(&opt, "-a") != 0)
+ return (1);
+ if (fuse_opt_add_opt_escaped(&opt, ",a,b,c") != 0)
+ return (1);
+ if (fuse_opt_add_opt_escaped(&opt, "\\,\\,,,,\\\\,") != 0)
+ return (1);
+ if (fuse_opt_add_opt_escaped(&opt, "test") != 0)
+ return (1);
+
+ if (fuse_opt_add_opt_escaped(&opt, NULL) != -1)
+ return (1);
+ if (fuse_opt_add_opt_escaped(&opt, "") != -1)
+ return (1);
+
+ return (strcmp(opt, opt2));
+}
+
diff --git a/regress/lib/libfuse/fuse-opt-add-opt.c b/regress/lib/libfuse/fuse-opt-add-opt.c
new file mode 100644
index 00000000000..449afcef30f
--- /dev/null
+++ b/regress/lib/libfuse/fuse-opt-add-opt.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.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 <string.h>
+#include <fuse_opt.h>
+
+int
+main(int ac, char **av)
+{
+ char *opt = NULL;
+ char *opt2;
+
+ opt2 = strdup("-a,--bc,01234,-56789,-o test1");
+ if (opt2 == NULL)
+ return (0);
+
+ if (fuse_opt_add_opt(&opt2, "test") != 0)
+ return (1);
+
+ if (fuse_opt_add_opt(&opt, "-a") != 0)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "--bc") != 0)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "01234") != 0)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "-56789") != 0)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "-o test1") != 0)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "test") != 0)
+ return (1);
+
+ if (fuse_opt_add_opt(&opt, NULL) != -1)
+ return (1);
+ if (fuse_opt_add_opt(&opt, "") != -1)
+ return (1);
+
+ return (strcmp(opt, opt2));
+}
+
diff --git a/regress/lib/libfuse/fuse-opt-insert-arg.c b/regress/lib/libfuse/fuse-opt-insert-arg.c
new file mode 100644
index 00000000000..f3505f7a2c3
--- /dev/null
+++ b/regress/lib/libfuse/fuse-opt-insert-arg.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.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 <string.h>
+#include <fuse_opt.h>
+
+char *argstest[] = {
+ "-d",
+ "test",
+ "--test",
+ "-o foo",
+ "barfoo"
+};
+
+int
+main(int ac, char **av)
+{
+ struct fuse_args args = FUSE_ARGS_INIT(ac, av);
+ int len, i;
+
+ len = sizeof(argstest) / sizeof(*argstest);
+
+ if (fuse_opt_insert_arg(&args, 1, "test") != 0)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 1, "-d") != 0)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 3, "barfoo") != 0)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 3, "--test") != 0)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 4, "-o foo") != 0)
+ return (1);
+
+ if (!args.allocated)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 1, NULL) != -1)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 1, "") != -1)
+ return (1);
+ if (fuse_opt_insert_arg(&args, -1, "foo") != -1)
+ return (1);
+ if (fuse_opt_insert_arg(&args, 42, "foo") != -1)
+ return (1);
+
+ for (i = 0; i < len; i++)
+ if (strcmp(args.argv[i+1], argstest[i]) != 0)
+ return (1);
+
+ if (args.argc != len + 1)
+ return (1);
+
+ fuse_opt_free_args(&args);
+ if (args.allocated)
+ return (1);
+ return (0);
+}
+
diff --git a/regress/lib/libfuse/fuse-opt-match.c b/regress/lib/libfuse/fuse-opt-match.c
new file mode 100644
index 00000000000..3dacdd11d00
--- /dev/null
+++ b/regress/lib/libfuse/fuse-opt-match.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) Sylvestre Gallon <ccna.syl@gmail.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 <string.h>
+#include <fuse_opt.h>
+
+const struct fuse_opt nullopts[] = {
+ FUSE_OPT_END
+};
+
+const int nullresults[] = {
+ 0, 0, 0, 0, 0, 0
+};
+
+const struct fuse_opt badopts[] = {
+ FUSE_OPT_KEY("-p ", 0),
+ FUSE_OPT_KEY("-C", 1),
+ FUSE_OPT_KEY("-V", 3),
+ FUSE_OPT_KEY("--version", 3),
+ FUSE_OPT_KEY("-h", 2),
+ FUSE_OPT_END
+};
+
+static int
+match_opts(const struct fuse_opt *opts, const int *results)
+{
+ if (fuse_opt_match(opts, NULL) != 0)
+ return (1);
+ if (fuse_opt_match(opts, "") != 0)
+ return (1);
+
+ if (fuse_opt_match(opts, "bar=") != results[0])
+ return (1);
+ if (fuse_opt_match(opts, "--foo=") != results[1])
+ return (1);
+ if (fuse_opt_match(opts, "bar=%s") != results[2])
+ return (1);
+ if (fuse_opt_match(opts, "--foo=%lu") != results[3])
+ return (1);
+ if (fuse_opt_match(opts, "-x ") != results[4])
+ return (1);
+ if (fuse_opt_match(opts, "-x %s") != results[5])
+ return (1);
+
+ return (0);
+}
+
+int
+main(int ac, char **av)
+{
+ if (match_opts(nullopts, nullresults) != 0)
+ return (1);
+ if (match_opts(badopts, nullresults) != 0)
+ return (1);
+ return (0);
+}
+