1 /**
2 * collectd - src/tests/test_utils_mount.c
3 * Copyright (C) 2013 Florian octo Forster
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Florian octo Forster <octo at collectd.org>
25 */
27 #include "collectd.h"
28 #include "testing.h"
29 #include "utils_mount.h"
31 #if HAVE_LIBKSTAT
32 kstat_ctl_t *kc;
33 #endif /* HAVE_LIBKSTAT */
35 DEF_TEST(cu_mount_checkoption)
36 {
37 char line_opts[] = "foo=one,bar=two,qux=three";
38 char *foo = strstr (line_opts, "foo");
39 char *bar = strstr (line_opts, "bar");
40 char *qux = strstr (line_opts, "qux");
42 char line_bool[] = "one,two,three";
43 char *one = strstr (line_bool, "one");
44 char *two = strstr (line_bool, "two");
45 char *three = strstr (line_bool, "three");
47 /* Normal operation */
48 OK (foo == cu_mount_checkoption (line_opts, "foo", 0));
49 OK (bar == cu_mount_checkoption (line_opts, "bar", 0));
50 OK (qux == cu_mount_checkoption (line_opts, "qux", 0));
51 OK (NULL == cu_mount_checkoption (line_opts, "unknown", 0));
53 OK (one == cu_mount_checkoption (line_bool, "one", 0));
54 OK (two == cu_mount_checkoption (line_bool, "two", 0));
55 OK (three == cu_mount_checkoption (line_bool, "three", 0));
56 OK (NULL == cu_mount_checkoption (line_bool, "four", 0));
58 /* Shorter and longer parts */
59 OK (foo == cu_mount_checkoption (line_opts, "fo", 0));
60 OK (bar == cu_mount_checkoption (line_opts, "bar=", 0));
61 OK (qux == cu_mount_checkoption (line_opts, "qux=thr", 0));
63 OK (one == cu_mount_checkoption (line_bool, "o", 0));
64 OK (two == cu_mount_checkoption (line_bool, "tw", 0));
65 OK (three == cu_mount_checkoption (line_bool, "thr", 0));
67 /* "full" flag */
68 OK (one == cu_mount_checkoption (line_bool, "one", 1));
69 OK (two == cu_mount_checkoption (line_bool, "two", 1));
70 OK (three == cu_mount_checkoption (line_bool, "three", 1));
71 OK (NULL == cu_mount_checkoption (line_bool, "four", 1));
73 OK (NULL == cu_mount_checkoption (line_bool, "o", 1));
74 OK (NULL == cu_mount_checkoption (line_bool, "tw", 1));
75 OK (NULL == cu_mount_checkoption (line_bool, "thr", 1));
77 return (0);
78 }
79 DEF_TEST(cu_mount_getoptionvalue)
80 {
81 char line_opts[] = "foo=one,bar=two,qux=three";
82 char line_bool[] = "one,two,three";
84 EXPECT_EQ_STR ("one", cu_mount_getoptionvalue (line_opts, "foo="));
85 EXPECT_EQ_STR ("two", cu_mount_getoptionvalue (line_opts, "bar="));
86 EXPECT_EQ_STR ("three", cu_mount_getoptionvalue (line_opts, "qux="));
87 OK (NULL == cu_mount_getoptionvalue (line_opts, "unknown="));
89 EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "one"));
90 EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "two"));
91 EXPECT_EQ_STR ("", cu_mount_getoptionvalue (line_bool, "three"));
92 OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
94 return (0);
95 }
97 int main (void)
98 {
99 RUN_TEST(cu_mount_checkoption);
100 RUN_TEST(cu_mount_getoptionvalue);
102 END_TEST;
103 }
105 /* vim: set sw=2 sts=2 et : */