gobject: Add basic bindtests

This commit is contained in:
Matthew Booth
2012-01-17 16:41:07 +00:00
parent cce1bbb345
commit e99a6a8483
6 changed files with 78 additions and 2 deletions

1
.gitignore vendored
View File

@@ -120,6 +120,7 @@ generator/stamp-generator
.git-module-status
/gnulib
/GNUmakefile
gobject/bindtests.js
gobject/Guestfs-1.0.gir
gobject/Guestfs-1.0.typelib
gobject/guestfs-gobject.c

View File

@@ -1017,6 +1017,12 @@ AS_IF(
)
AM_CONDITIONAL([HAVE_GOBJECT],[test "x$GOBJECT_LIBS" != "x"])
AC_CHECK_PROG([GJS],[gjs],[gjs])
AS_IF(
[test "x$GJS" = "x"],
[AC_MSG_WARN([gjs not found, gobject bindtests will not run])]
)
dnl gobject introspection
GOBJECT_INTROSPECTION_CHECK([1.30.0])

View File

@@ -425,6 +425,40 @@ main = do
pr " putStrLn \"EOF\"\n"
and generate_gobject_js_bindtests () =
generate_header CPlusPlusStyle GPLv2plus;
pr "\
const Guestfs = imports.gi.Guestfs;
var g = new Guestfs.Session();
";
let mkargs args =
String.concat ", " (
(List.map (
function
| CallString s -> "\"" ^ s ^ "\""
| CallOptString None -> "null"
| CallOptString (Some s) -> "\"" ^ s ^ "\""
| CallStringList xs ->
"[" ^ String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "]"
| CallInt i -> string_of_int i
| CallInt64 i -> Int64.to_string i
| CallBool true -> "true"
| CallBool false -> "false"
| CallBuffer s -> "\"" ^ c_quote s ^ "\""
) args)
@ ["null"]
)
in
generate_lang_bindtests (
fun f args -> pr "g.%s(%s);\n" f (mkargs args)
);
pr "\nprint(\"EOF\");\n"
(* Language-independent bindings tests - we do it this way to
* ensure there is parity in testing bindings across all languages.
*)

View File

@@ -137,6 +137,7 @@ Run it from the top source directory using the command
output_to "php/extension/guestfs_php.c" generate_php_c;
output_to "erlang/guestfs.erl" generate_erlang_erl;
output_to "erlang/erl-guestfs.c" generate_erlang_c;
output_to "gobject/bindtests.js" generate_gobject_js_bindtests;
output_to "gobject/guestfs-gobject.h" generate_gobject_header;
output_to "gobject/guestfs-gobject.c" generate_gobject_c;

View File

@@ -15,8 +15,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
BUILT_SOURCES = guestfs-gobject.h guestfs-gobject.c
EXTRA_DIST = $(BUILT_SOURCES)
BUILT_SOURCES = guestfs-gobject.h guestfs-gobject.c bindtests.js
EXTRA_DIST = \
$(BUILT_SOURCES) \
run-bindtests
libname = libguestfs-gobject-1.0.la
@@ -54,5 +56,10 @@ gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
TESTS = run-bindtests
TESTS_ENVIRONMENT = GJS=$(GJS)
$(TESTS): $(typelib_DATA)
CLEANFILES = $(gir_DATA) $(typelib_DATA)
endif

27
gobject/run-bindtests Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh -
# libguestfs GObject bindings
# Copyright (C) 2012 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.
set -e
if [ -z "$GJS" ]; then
echo "GObject bind tests skipped: gjs is missing"
exit 0
fi
../run $GJS bindtests.js > bindtests.tmp
diff -u ${srcdir}/../bindtests bindtests.tmp