Merge pull request #1830 from rubenk/move-collectd-header
[collectd.git] / src / utils_mount_test.c
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  */
26
27 #include "collectd.h"
28
29 #include "common.h"
30 #include "testing.h"
31 #include "utils_mount.h"
32
33 #if HAVE_LIBKSTAT
34 kstat_ctl_t *kc;
35 #endif /* HAVE_LIBKSTAT */
36
37 DEF_TEST(cu_mount_checkoption)
38 {
39   char line_opts[] = "foo=one,bar=two,qux=three";
40   char *foo = strstr (line_opts, "foo");
41   char *bar = strstr (line_opts, "bar");
42   char *qux = strstr (line_opts, "qux");
43
44   char line_bool[] = "one,two,three";
45   char *one = strstr (line_bool, "one");
46   char *two = strstr (line_bool, "two");
47   char *three = strstr (line_bool, "three");
48
49   /* Normal operation */
50   OK (foo == cu_mount_checkoption (line_opts, "foo", 0));
51   OK (bar == cu_mount_checkoption (line_opts, "bar", 0));
52   OK (qux == cu_mount_checkoption (line_opts, "qux", 0));
53   OK (NULL == cu_mount_checkoption (line_opts, "unknown", 0));
54
55   OK (one == cu_mount_checkoption (line_bool, "one", 0));
56   OK (two == cu_mount_checkoption (line_bool, "two", 0));
57   OK (three == cu_mount_checkoption (line_bool, "three", 0));
58   OK (NULL == cu_mount_checkoption (line_bool, "four", 0));
59
60   /* Shorter and longer parts */
61   OK (foo == cu_mount_checkoption (line_opts, "fo", 0));
62   OK (bar == cu_mount_checkoption (line_opts, "bar=", 0));
63   OK (qux == cu_mount_checkoption (line_opts, "qux=thr", 0));
64
65   OK (one == cu_mount_checkoption (line_bool, "o", 0));
66   OK (two == cu_mount_checkoption (line_bool, "tw", 0));
67   OK (three == cu_mount_checkoption (line_bool, "thr", 0));
68
69   /* "full" flag */
70   OK (one == cu_mount_checkoption (line_bool, "one", 1));
71   OK (two == cu_mount_checkoption (line_bool, "two", 1));
72   OK (three == cu_mount_checkoption (line_bool, "three", 1));
73   OK (NULL == cu_mount_checkoption (line_bool, "four", 1));
74
75   OK (NULL == cu_mount_checkoption (line_bool, "o", 1));
76   OK (NULL == cu_mount_checkoption (line_bool, "tw", 1));
77   OK (NULL == cu_mount_checkoption (line_bool, "thr", 1));
78
79   return (0);
80 }
81 DEF_TEST(cu_mount_getoptionvalue)
82 {
83   char line_opts[] = "foo=one,bar=two,qux=three";
84   char line_bool[] = "one,two,three";
85   char *v;
86
87   EXPECT_EQ_STR ("one", v = cu_mount_getoptionvalue (line_opts, "foo="));
88   sfree (v);
89   EXPECT_EQ_STR ("two", v = cu_mount_getoptionvalue (line_opts, "bar="));
90   sfree (v);
91   EXPECT_EQ_STR ("three", v = cu_mount_getoptionvalue (line_opts, "qux="));
92   sfree (v);
93   OK (NULL == (v = cu_mount_getoptionvalue (line_opts, "unknown=")));
94   sfree (v);
95
96   EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "one"));
97   sfree (v);
98   EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "two"));
99   sfree (v);
100   EXPECT_EQ_STR ("", v = cu_mount_getoptionvalue (line_bool, "three"));
101   sfree (v);
102   OK (NULL == (v = cu_mount_getoptionvalue (line_bool, "four")));
103   sfree (v);
104
105   return (0);
106 }
107
108 int main (void)
109 {
110   RUN_TEST(cu_mount_checkoption);
111   RUN_TEST(cu_mount_getoptionvalue);
112
113   END_TEST;
114 }
115
116 /* vim: set sw=2 sts=2 et : */