t_refuse_opt.c revision 1.2 1 /* $NetBSD: t_refuse_opt.c,v 1.2 2016/11/14 17:19:29 pho Exp $ */
2
3 /*-
4 * Copyright (c) 2016 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include <sys/cdefs.h>
29 __RCSID("$NetBSD: t_refuse_opt.c,v 1.2 2016/11/14 17:19:29 pho Exp $");
30
31 #include <atf-c.h>
32
33 #include <fuse.h>
34
35 #include "../../h_macros.h"
36
37 ATF_TC(efuse_opt_add_arg);
38 ATF_TC_HEAD(efuse_opt_add_arg, tc)
39 {
40 atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_arg(3) works");
41 }
42
43 ATF_TC_BODY(efuse_opt_add_arg, tc)
44 {
45 struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
46
47 RZ(fuse_opt_add_arg(&args, "foo"));
48 RZ(fuse_opt_add_arg(&args, "bar"));
49
50 ATF_REQUIRE_EQ(args.argc, 2);
51 ATF_CHECK_STREQ(args.argv[0], "foo");
52 ATF_CHECK_STREQ(args.argv[1], "bar");
53 ATF_CHECK(args.allocated != 0);
54 }
55
56 ATF_TC(efuse_opt_insert_arg);
57 ATF_TC_HEAD(efuse_opt_insert_arg, tc)
58 {
59 atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_insert_arg(3) works");
60 }
61
62 ATF_TC_BODY(efuse_opt_insert_arg, tc)
63 {
64 struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
65
66 RZ(fuse_opt_insert_arg(&args, 0, "foo"));
67 RZ(fuse_opt_insert_arg(&args, 0, "bar"));
68
69 ATF_REQUIRE_EQ(args.argc, 2);
70 ATF_CHECK_STREQ(args.argv[0], "bar");
71 ATF_CHECK_STREQ(args.argv[1], "foo");
72 ATF_CHECK(args.allocated != 0);
73 }
74
75 ATF_TC(efuse_opt_add_opt);
76 ATF_TC_HEAD(efuse_opt_add_opt, tc)
77 {
78 atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_opt(3) works");
79 }
80
81 ATF_TC_BODY(efuse_opt_add_opt, tc)
82 {
83 char* opt = NULL;
84
85 RZ(fuse_opt_add_opt(&opt, "fo\\o"));
86 ATF_CHECK_STREQ(opt, "fo\\o");
87
88 RZ(fuse_opt_add_opt(&opt, "ba,r"));
89 ATF_CHECK_STREQ(opt, "fo\\o,ba,r");
90 }
91
92 ATF_TC(efuse_opt_add_opt_escaped);
93 ATF_TC_HEAD(efuse_opt_add_opt_escaped, tc)
94 {
95 atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_opt_escaped(3) works");
96 }
97
98 ATF_TC_BODY(efuse_opt_add_opt_escaped, tc)
99 {
100 char* opt = NULL;
101
102 RZ(fuse_opt_add_opt_escaped(&opt, "fo\\o"));
103 ATF_CHECK_STREQ(opt, "fo\\\\o");
104
105 RZ(fuse_opt_add_opt_escaped(&opt, "ba,r"));
106 ATF_CHECK_STREQ(opt, "fo\\\\o,ba\\,r");
107 }
108
109 ATF_TP_ADD_TCS(tp)
110 {
111 ATF_TP_ADD_TC(tp, efuse_opt_add_arg);
112 ATF_TP_ADD_TC(tp, efuse_opt_insert_arg);
113 ATF_TP_ADD_TC(tp, efuse_opt_add_opt);
114 ATF_TP_ADD_TC(tp, efuse_opt_add_opt_escaped);
115
116 return atf_no_error();
117 }
118