summaryrefslogtreecommitdiffstats
path: root/capitests
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-11-03 16:56:34 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-11-03 17:44:30 +0000
commitb535363e7e7a000cca3651790f911b2d0605968f (patch)
tree827e8b6b502c7e5113d8bddae85290bf1d2c48e0 /capitests
parent162c89ed497212859d748506209ffc1b88763ab2 (diff)
downloadlibguestfs-b535363e7e7a000cca3651790f911b2d0605968f.tar.gz
libguestfs-b535363e7e7a000cca3651790f911b2d0605968f.tar.xz
libguestfs-b535363e7e7a000cca3651790f911b2d0605968f.zip
capitests: Test some basic aspects of the C API.
Diffstat (limited to 'capitests')
-rw-r--r--capitests/Makefile.am50
-rw-r--r--capitests/test-config.c68
-rw-r--r--capitests/test-create-handle.c42
3 files changed, 145 insertions, 15 deletions
diff --git a/capitests/Makefile.am b/capitests/Makefile.am
index 65a7240c..1374d9bf 100644
--- a/capitests/Makefile.am
+++ b/capitests/Makefile.am
@@ -1,5 +1,5 @@
# libguestfs
-# Copyright (C) 2009 Red Hat Inc.
+# Copyright (C) 2009-2010 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
@@ -23,17 +23,16 @@ BUILT_SOURCES = $(generator_built)
EXTRA_DIST = $(BUILT_SOURCES)
-# Tests. These are auto-generated from the test descriptions
-# in the generator.
+check_PROGRAMS = \
+ tests \
+ test-command \
+ test-create-handle \
+ test-config
-check_PROGRAMS = tests test-command
-
-tests_SOURCES = tests.c
-tests_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src \
- $(WARN_CFLAGS) $(WERROR_CFLAGS)
-tests_LDADD = $(top_builddir)/src/libguestfs.la
-
-TESTS = tests
+TESTS = \
+ tests \
+ test-create-handle \
+ test-config
TESTS_ENVIRONMENT = \
SKIP_TEST_COMMAND=$(shell ldd test-command | grep -sq 'not a dynamic executable' || echo 1) \
SKIP_TEST_COMMAND_LINES=$(shell ldd test-command | grep -sq 'not a dynamic executable' || echo 1) \
@@ -41,13 +40,34 @@ TESTS_ENVIRONMENT = \
LIBGUESTFS_PATH=$(top_builddir)/appliance \
$(VG)
-# Run the tests under valgrind.
-
-valgrind:
- $(MAKE) check VG="valgrind --quiet --leak-check=full"
+tests_SOURCES = tests.c
+tests_CFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS)
+tests_LDADD = $(top_builddir)/src/libguestfs.la
# This binary must be statically linked. It is used for testing
# the "guestfs_command" and "guestfs_command_lines" functions.
test_command_SOURCES = test-command.c
test_command_LDFLAGS = -all-static
+
+# Hand-written C API tests.
+
+test_create_handle_SOURCES = test-create-handle.c
+test_create_handle_CFLAGS = \
+ -I$(top_srcdir)/src -I$(top_builddir)/src \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS)
+test_create_handle_LDADD = \
+ $(top_builddir)/src/libguestfs.la
+
+test_config_SOURCES = test-config.c
+test_config_CFLAGS = \
+ -I$(top_srcdir)/src -I$(top_builddir)/src \
+ $(WARN_CFLAGS) $(WERROR_CFLAGS)
+test_config_LDADD = \
+ $(top_builddir)/src/libguestfs.la
+
+# Run the tests under valgrind.
+
+valgrind:
+ $(MAKE) check VG="valgrind --quiet --leak-check=full"
diff --git a/capitests/test-config.c b/capitests/test-config.c
new file mode 100644
index 00000000..c5411232
--- /dev/null
+++ b/capitests/test-config.c
@@ -0,0 +1,68 @@
+/* libguestfs
+ * Copyright (C) 2010 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 <unistd.h>
+
+#include "guestfs.h"
+
+int
+main (int argc, char *argv[])
+{
+ guestfs_h *g;
+ int r;
+
+ g = guestfs_create ();
+ if (g == NULL) {
+ fprintf (stderr, "failed to create handle\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* If these fail, the default error handler will print an error
+ * message to stderr, so we don't need to print anything. This code
+ * is very pedantic, but after all we are testing the details of the
+ * C API.
+ */
+
+ if (guestfs_set_verbose (g, 1) == -1)
+ exit (EXIT_FAILURE);
+ r = guestfs_get_verbose (g);
+ if (r == -1)
+ exit (EXIT_FAILURE);
+ if (!r) {
+ fprintf (stderr, "set_verbose not true\n");
+ exit (EXIT_FAILURE);
+ }
+ if (guestfs_set_verbose (g, 0) == -1)
+ exit (EXIT_FAILURE);
+ r = guestfs_get_verbose (g);
+ if (r == -1)
+ exit (EXIT_FAILURE);
+ if (r) {
+ fprintf (stderr, "set_verbose not false\n");
+ exit (EXIT_FAILURE);
+ }
+
+ guestfs_close (g);
+
+ exit (EXIT_SUCCESS);
+}
diff --git a/capitests/test-create-handle.c b/capitests/test-create-handle.c
new file mode 100644
index 00000000..edea19f6
--- /dev/null
+++ b/capitests/test-create-handle.c
@@ -0,0 +1,42 @@
+/* libguestfs
+ * Copyright (C) 2010 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 <unistd.h>
+
+#include "guestfs.h"
+
+int
+main (int argc, char *argv[])
+{
+ guestfs_h *g;
+
+ g = guestfs_create ();
+ if (g == NULL) {
+ fprintf (stderr, "failed to create handle\n");
+ exit (EXIT_FAILURE);
+ }
+
+ guestfs_close (g);
+
+ exit (EXIT_SUCCESS);
+}