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