summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bdac0e7)
raw | patch | inline | side by side (parent: bdac0e7)
author | Florian Forster <octo@collectd.org> | |
Wed, 28 Aug 2013 13:15:40 +0000 (15:15 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 28 Jul 2014 13:06:35 +0000 (15:06 +0200) |
Github: #412
src/Makefile.am | patch | blob | history | |
src/tests/utils_mount_test.c | [new file with mode: 0644] | patch | blob |
diff --git a/src/Makefile.am b/src/Makefile.am
index 9d3379dd942cf87454db82066c8bc3f7263ee694..fc3dc6c35f93100090ddeca44e339d2eb4dd2960 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
rm -f $(DESTDIR)$(sysconfdir)/collectd.conf
rm -f $(DESTDIR)$(pkgdatadir)/postgresql_default.conf;
-check_PROGRAMS = common_test utils_avltree_test utils_heap_test utils_vl_lookup_test
+check_PROGRAMS = common_test utils_avltree_test utils_heap_test utils_mount_test utils_vl_lookup_test
common_test_SOURCES = tests/common_test.c \
common.h common.c \
utils_heap_test_LDFLAGS = -export-dynamic
utils_heap_test_LDADD =
+utils_mount_test_SOURCES = tests/utils_mount_test.c \
+ utils_mount.c utils_mount.h \
+ common.c common.h \
+ tests/mock/plugin.c \
+ tests/mock/utils_cache.c \
+ tests/mock/utils_time.c
+utils_mount_test_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
+utils_mount_test_LDFLAGS = -export-dynamic
+utils_mount_test_LDADD =
+
utils_vl_lookup_test_SOURCES = tests/utils_vl_lookup_test.c \
utils_vl_lookup.h utils_vl_lookup.c \
utils_avltree.c utils_avltree.h \
utils_vl_lookup_test_LDFLAGS = -export-dynamic
utils_vl_lookup_test_LDADD =
-TESTS = common_test utils_avltree_test utils_heap_test utils_vl_lookup_test
+TESTS = common_test utils_avltree_test utils_heap_test utils_mount_test utils_vl_lookup_test
diff --git a/src/tests/utils_mount_test.c b/src/tests/utils_mount_test.c
--- /dev/null
@@ -0,0 +1,102 @@
+/**
+ * collectd - src/utils_mount_test.c
+ *
+ * Copyright (C) 2013 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "tests/macros.h"
+#include "collectd.h"
+#include "utils_mount.h"
+
+DEF_TEST(cu_mount_checkoption)
+{
+ char line_opts[] = "foo=one,bar=two,qux=three";
+ char *foo = strstr (line_opts, "foo");
+ char *bar = strstr (line_opts, "bar");
+ char *qux = strstr (line_opts, "qux");
+
+ char line_bool[] = "one,two,three";
+ char *one = strstr (line_bool, "one");
+ char *two = strstr (line_bool, "two");
+ char *three = strstr (line_bool, "three");
+
+ /* Normal operation */
+ OK (foo == cu_mount_checkoption (line_opts, "foo", 0));
+ OK (bar == cu_mount_checkoption (line_opts, "bar", 0));
+ OK (qux == cu_mount_checkoption (line_opts, "qux", 0));
+ OK (NULL == cu_mount_checkoption (line_opts, "unknown", 0));
+
+ OK (one == cu_mount_checkoption (line_bool, "one", 0));
+ OK (two == cu_mount_checkoption (line_bool, "two", 0));
+ OK (three == cu_mount_checkoption (line_bool, "three", 0));
+ OK (NULL == cu_mount_checkoption (line_bool, "four", 0));
+
+ /* Shorter and longer parts */
+ OK (foo == cu_mount_checkoption (line_opts, "fo", 0));
+ OK (bar == cu_mount_checkoption (line_opts, "bar=", 0));
+ OK (qux == cu_mount_checkoption (line_opts, "qux=thr", 0));
+
+ OK (one == cu_mount_checkoption (line_bool, "o", 0));
+ OK (two == cu_mount_checkoption (line_bool, "tw", 0));
+ OK (three == cu_mount_checkoption (line_bool, "thr", 0));
+
+ /* "full" flag */
+ OK (one == cu_mount_checkoption (line_bool, "one", 1));
+ OK (two == cu_mount_checkoption (line_bool, "two", 1));
+ OK (three == cu_mount_checkoption (line_bool, "three", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "four", 1));
+
+ OK (NULL == cu_mount_checkoption (line_bool, "o", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "tw", 1));
+ OK (NULL == cu_mount_checkoption (line_bool, "thr", 1));
+
+ return (0);
+}
+DEF_TEST(cu_mount_getoptionvalue)
+{
+ char line_opts[] = "foo=one,bar=two,qux=three";
+ char line_bool[] = "one,two,three";
+
+ STREQ ("one", cu_mount_getoptionvalue (line_opts, "foo="));
+ STREQ ("two", cu_mount_getoptionvalue (line_opts, "bar="));
+ STREQ ("three", cu_mount_getoptionvalue (line_opts, "qux="));
+ OK (NULL == cu_mount_getoptionvalue (line_opts, "unknown="));
+
+ STREQ ("", cu_mount_getoptionvalue (line_bool, "one"));
+ STREQ ("", cu_mount_getoptionvalue (line_bool, "two"));
+ STREQ ("", cu_mount_getoptionvalue (line_bool, "three"));
+ OK (NULL == cu_mount_getoptionvalue (line_bool, "four"));
+
+ return (0);
+}
+
+int main (void)
+{
+ RUN_TEST(cu_mount_checkoption);
+ RUN_TEST(cu_mount_getoptionvalue);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */