[Pkg-libvirt-commits] [libguestfs] 70/233: utils: Add regression test for C utility functions.
Hilko Bengen
bengen at moszumanska.debian.org
Wed Feb 19 21:10:56 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 815e739d1230ce067b6a09d644257dac031c0ddc
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Sat Jan 18 15:56:25 2014 +0000
utils: Add regression test for C utility functions.
---
.gitignore | 1 +
po/POTFILES | 1 +
src/Makefile.am | 22 ++++++++
src/test-utils.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+)
diff --git a/.gitignore b/.gitignore
index 27ce4d6..28e5591 100644
--- a/.gitignore
+++ b/.gitignore
@@ -421,6 +421,7 @@ Makefile.in
/src/structs-compare.c
/src/structs-copy.c
/src/structs-free.c
+/src/test-utils
/stamp-guestfs-release-notes.pod
/stamp-h1
/sysprep/.depend
diff --git a/po/POTFILES b/po/POTFILES
index b18f18c..4df7515 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -305,6 +305,7 @@ src/structs-cleanup.c
src/structs-compare.c
src/structs-copy.c
src/structs-free.c
+src/test-utils.c
src/tmpdirs.c
src/utils.c
test-tool/test-tool.c
diff --git a/src/Makefile.am b/src/Makefile.am
index fbfb1a5..b1022e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -226,6 +226,28 @@ libutils_la_SOURCES = \
libutils_la_CPPFLAGS = $(libguestfs_la_CPPFLAGS)
libutils_la_CFLAGS = $(libguestfs_la_CFLAGS)
+# Tests: main tests are in tests/c-api. Here we just have some
+# internal tests of utility functions.
+
+TESTS_ENVIRONMENT = $(top_builddir)/run --test $(VG)
+
+TESTS = test-utils
+check_PROGRAMS = test-utils
+
+test_utils_SOURCES = test-utils.c
+test_utils_CPPFLAGS = \
+ -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+ -I$(top_srcdir)/src -I.
+test_utils_CFLAGS = \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(GPROF_CFLAGS) $(GCOV_CFLAGS)
+test_utils_LDADD = \
+ libutils.la \
+ $(top_builddir)/gnulib/lib/libgnu.la
+
+check-valgrind:
+ $(MAKE) VG="@VG@" check
+
# Pkgconfig.
pkgconfigdir = $(libdir)/pkgconfig
diff --git a/src/test-utils.c b/src/test-utils.c
new file mode 100644
index 0000000..8ee2873
--- /dev/null
+++ b/src/test-utils.c
@@ -0,0 +1,156 @@
+/* libguestfs
+ * Copyright (C) 2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "guestfs.h"
+#include "guestfs-internal-frontend.h"
+
+/* Test guestfs___split_string. */
+static void
+test_split (void)
+{
+ char **ret;
+
+ ret = guestfs___split_string (':', "");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 0);
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', "a");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 1);
+ assert (STREQ (ret[0], "a"));
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', ":");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 2);
+ assert (STREQ (ret[0], ""));
+ assert (STREQ (ret[1], ""));
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', "::");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 3);
+ assert (STREQ (ret[0], ""));
+ assert (STREQ (ret[1], ""));
+ assert (STREQ (ret[2], ""));
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', ":a");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 2);
+ assert (STREQ (ret[0], ""));
+ assert (STREQ (ret[1], "a"));
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', "a:");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 2);
+ assert (STREQ (ret[0], "a"));
+ assert (STREQ (ret[1], ""));
+ guestfs___free_string_list (ret);
+
+ ret = guestfs___split_string (':', "a:b:c");
+ assert (ret);
+ assert (guestfs___count_strings (ret) == 3);
+ assert (STREQ (ret[0], "a"));
+ assert (STREQ (ret[1], "b"));
+ assert (STREQ (ret[2], "c"));
+ guestfs___free_string_list (ret);
+}
+
+/* Test guestfs___concat_strings. */
+static void
+test_concat (void)
+{
+ char *ret;
+ const char *test1[] = { NULL };
+ const char *test2[] = { "", NULL };
+ const char *test3[] = { "a", NULL };
+ const char *test4[] = { "a", "", NULL };
+ const char *test5[] = { "a", "b", NULL };
+
+ ret = guestfs___concat_strings ((char **) test1);
+ assert (STREQ (ret, ""));
+ free (ret);
+
+ ret = guestfs___concat_strings ((char **) test2);
+ assert (STREQ (ret, ""));
+ free (ret);
+
+ ret = guestfs___concat_strings ((char **) test3);
+ assert (STREQ (ret, "a"));
+ free (ret);
+
+ ret = guestfs___concat_strings ((char **) test4);
+ assert (STREQ (ret, "a"));
+ free (ret);
+
+ ret = guestfs___concat_strings ((char **) test5);
+ assert (STREQ (ret, "ab"));
+ free (ret);
+}
+
+/* Test guestfs___join_strings. */
+static void
+test_join (void)
+{
+ char *ret;
+ const char *test1[] = { NULL };
+ const char *test2[] = { "", NULL };
+ const char *test3[] = { "a", NULL };
+ const char *test4[] = { "a", "", NULL };
+ const char *test5[] = { "a", "b", NULL };
+
+ ret = guestfs___join_strings (":!", (char **) test1);
+ assert (STREQ (ret, ""));
+ free (ret);
+
+ ret = guestfs___join_strings (":!", (char **) test2);
+ assert (STREQ (ret, ""));
+ free (ret);
+
+ ret = guestfs___join_strings (":!", (char **) test3);
+ assert (STREQ (ret, "a"));
+ free (ret);
+
+ ret = guestfs___join_strings (":!", (char **) test4);
+ assert (STREQ (ret, "a:!"));
+ free (ret);
+
+ ret = guestfs___join_strings (":!", (char **) test5);
+ assert (STREQ (ret, "a:!b"));
+ free (ret);
+}
+
+int
+main (int argc, char *argv[])
+{
+ test_split ();
+ test_concat ();
+ test_join ();
+
+ exit (EXIT_SUCCESS);
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list