2 * collectd - src/tests/test_utils_mount.c
3 * Copyright (C) 2013 Florian octo Forster
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 * Florian octo Forster <octo at collectd.org>
31 #include "utils_mount.h"
39 #endif /* HAVE_LIBKSTAT */
41 DEF_TEST(cu_mount_checkoption) {
42 char line_opts[] = "foo=one,bar=two,qux=three";
43 char *foo = strstr(line_opts, "foo");
44 char *bar = strstr(line_opts, "bar");
45 char *qux = strstr(line_opts, "qux");
47 char line_bool[] = "one,two,three";
48 char *one = strstr(line_bool, "one");
49 char *two = strstr(line_bool, "two");
50 char *three = strstr(line_bool, "three");
52 /* Normal operation */
53 OK(foo == cu_mount_checkoption(line_opts, "foo", 0));
54 OK(bar == cu_mount_checkoption(line_opts, "bar", 0));
55 OK(qux == cu_mount_checkoption(line_opts, "qux", 0));
56 OK(NULL == cu_mount_checkoption(line_opts, "unknown", 0));
58 OK(one == cu_mount_checkoption(line_bool, "one", 0));
59 OK(two == cu_mount_checkoption(line_bool, "two", 0));
60 OK(three == cu_mount_checkoption(line_bool, "three", 0));
61 OK(NULL == cu_mount_checkoption(line_bool, "four", 0));
63 /* Shorter and longer parts */
64 OK(foo == cu_mount_checkoption(line_opts, "fo", 0));
65 OK(bar == cu_mount_checkoption(line_opts, "bar=", 0));
66 OK(qux == cu_mount_checkoption(line_opts, "qux=thr", 0));
68 OK(one == cu_mount_checkoption(line_bool, "o", 0));
69 OK(two == cu_mount_checkoption(line_bool, "tw", 0));
70 OK(three == cu_mount_checkoption(line_bool, "thr", 0));
73 OK(one == cu_mount_checkoption(line_bool, "one", 1));
74 OK(two == cu_mount_checkoption(line_bool, "two", 1));
75 OK(three == cu_mount_checkoption(line_bool, "three", 1));
76 OK(NULL == cu_mount_checkoption(line_bool, "four", 1));
78 OK(NULL == cu_mount_checkoption(line_bool, "o", 1));
79 OK(NULL == cu_mount_checkoption(line_bool, "tw", 1));
80 OK(NULL == cu_mount_checkoption(line_bool, "thr", 1));
84 DEF_TEST(cu_mount_getoptionvalue) {
85 char line_opts[] = "foo=one,bar=two,qux=three";
86 char line_bool[] = "one,two,three";
89 EXPECT_EQ_STR("one", v = cu_mount_getoptionvalue(line_opts, "foo="));
91 EXPECT_EQ_STR("two", v = cu_mount_getoptionvalue(line_opts, "bar="));
93 EXPECT_EQ_STR("three", v = cu_mount_getoptionvalue(line_opts, "qux="));
95 OK(NULL == (v = cu_mount_getoptionvalue(line_opts, "unknown=")));
98 EXPECT_EQ_STR("", v = cu_mount_getoptionvalue(line_bool, "one"));
100 EXPECT_EQ_STR("", v = cu_mount_getoptionvalue(line_bool, "two"));
102 EXPECT_EQ_STR("", v = cu_mount_getoptionvalue(line_bool, "three"));
104 OK(NULL == (v = cu_mount_getoptionvalue(line_bool, "four")));
111 RUN_TEST(cu_mount_checkoption);
112 RUN_TEST(cu_mount_getoptionvalue);