capitests: Test some basic aspects of the C API.
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 3 Nov 2010 16:56:34 +0000 (16:56 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 3 Nov 2010 17:44:30 +0000 (17:44 +0000)
.gitignore
capitests/Makefile.am
capitests/test-config.c [new file with mode: 0644]
capitests/test-create-handle.c [new file with mode: 0644]

index 527335d..406e756 100644 (file)
@@ -21,6 +21,8 @@ autom4te.cache
 *.bak
 bindtests.tmp
 capitests/test-command
 *.bak
 bindtests.tmp
 capitests/test-command
+capitests/test-config
+capitests/test-create-handle
 capitests/test*.img
 capitests/tests
 capitests/tests.c
 capitests/test*.img
 capitests/tests
 capitests/tests.c
index 65a7240..1374d9b 100644 (file)
@@ -1,5 +1,5 @@
 # libguestfs
 # 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
 #
 # 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)
 
 
 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) \
 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)
 
        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
 
 # 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 (file)
index 0000000..c541123
--- /dev/null
@@ -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 (file)
index 0000000..edea19f
--- /dev/null
@@ -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);
+}