From babc0846cc911b01a58a7385d30ad25889b7175a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 28 May 2009 20:15:51 +0100 Subject: [PATCH] Add tests for bindings parameters, fix several broken bindings. --- .gitignore | 2 + bindtests | 92 ++++++++++ configure.ac | 2 +- haskell/bindtests.hs | 0 java/Bindtests.java | 50 ++++++ java/Makefile.am | 16 +- java/com_redhat_et_libguestfs_GuestFS.c | 15 +- java/run-bindtests | 22 +++ java/run-java-tests | 24 +++ ocaml/.depend | 2 + ocaml/Makefile.am | 11 +- ocaml/bindtests.ml | 37 ++++ java/run-java-test => ocaml/run-bindtests | 8 +- perl/Guestfs.xs | 6 +- perl/Makefile.am | 7 +- perl/bindtests.pl | 40 +++++ perl/run-bindtests | 23 +++ perl/run-perl-tests | 4 +- po/libguestfs.pot | 40 ++--- po/pl.po | 40 ++--- python/Makefile.am | 9 +- python/bindtests.py | 37 ++++ python/run-bindtests | 22 +++ python/run-python-tests | 24 +++ ruby/Makefile.am | 7 +- ruby/bindtests.rb | 37 ++++ ruby/ext/guestfs/_guestfs.c | 18 +- ruby/run-bindtests | 22 +++ ruby/run-ruby-tests | 4 +- src/generator.ml | 283 ++++++++++++++++++++++++++++-- src/guestfs-bindtests.c | 2 + 31 files changed, 817 insertions(+), 89 deletions(-) create mode 100644 bindtests create mode 100644 haskell/bindtests.hs create mode 100644 java/Bindtests.java create mode 100755 java/run-bindtests create mode 100755 java/run-java-tests create mode 100644 ocaml/bindtests.ml rename java/run-java-test => ocaml/run-bindtests (86%) mode change 100755 => 100644 create mode 100644 perl/bindtests.pl create mode 100755 perl/run-bindtests create mode 100644 python/bindtests.py create mode 100755 python/run-bindtests create mode 100755 python/run-python-tests create mode 100644 ruby/bindtests.rb create mode 100755 ruby/run-bindtests diff --git a/.gitignore b/.gitignore index 0d52da3..10faaab 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.class *.jar *.hi +bindtests.tmp ChangeLog Makefile.in Makefile @@ -73,6 +74,7 @@ m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 ocaml/META +ocaml/bindtests ocaml/examples/lvs ocaml/t/guestfs_005_load ocaml/t/guestfs_010_launch diff --git a/bindtests b/bindtests new file mode 100644 index 0000000..6fbec99 --- /dev/null +++ b/bindtests @@ -0,0 +1,92 @@ +abc +def +[] +false +0 +123 +456 +abc +null +[] +false +0 +123 +456 + +def +[] +false +0 +123 +456 + + +[] +false +0 +123 +456 +abc +def +["1"] +false +0 +123 +456 +abc +def +["1", "2"] +false +0 +123 +456 +abc +def +["1"] +true +0 +123 +456 +abc +def +["1"] +false +-1 +123 +456 +abc +def +["1"] +false +-2 +123 +456 +abc +def +["1"] +false +1 +123 +456 +abc +def +["1"] +false +2 +123 +456 +abc +def +["1"] +false +4095 +123 +456 +abc +def +["1"] +false +0 + + +EOF diff --git a/configure.ac b/configure.ac index 2d91872..3028ecf 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -AC_INIT([libguestfs],[1.0.34]) +AC_INIT([libguestfs],[1.0.35]) AM_INIT_AUTOMAKE AC_CONFIG_MACRO_DIR([m4]) diff --git a/haskell/bindtests.hs b/haskell/bindtests.hs new file mode 100644 index 0000000..e69de29 diff --git a/java/Bindtests.java b/java/Bindtests.java new file mode 100644 index 0000000..c12fbb9 --- /dev/null +++ b/java/Bindtests.java @@ -0,0 +1,50 @@ +/* libguestfs generated file + * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. + * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. + * + * Copyright (C) 2009 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. + */ + +import com.redhat.et.libguestfs.*; + +public class Bindtests { + public static void main (String[] argv) + { + try { + GuestFS g = new GuestFS (); + g.test0 ("abc", "def", new String[]{}, false, 0, "123", "456"); + g.test0 ("abc", null, new String[]{}, false, 0, "123", "456"); + g.test0 ("", "def", new String[]{}, false, 0, "123", "456"); + g.test0 ("", "", new String[]{}, false, 0, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, 0, "123", "456"); + g.test0 ("abc", "def", new String[]{"1","2"}, false, 0, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, true, 0, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, -1, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, -2, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, 1, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, 2, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, 4095, "123", "456"); + g.test0 ("abc", "def", new String[]{"1"}, false, 0, "", ""); + + System.out.println ("EOF"); + } + catch (Exception exn) { + System.err.println (exn); + System.exit (1); + } + } +} diff --git a/java/Makefile.am b/java/Makefile.am index cc9891b..633ecda 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -28,6 +28,7 @@ java_sources = \ $(CPTH)/GuestFS.java java_tests = \ + Bindtests.java \ t/GuestFS005Load.java \ t/GuestFS010Launch.java \ t/GuestFS050LVCreate.java @@ -35,7 +36,8 @@ java_tests = \ EXTRA_DIST = \ $(java_sources) \ $(java_tests) \ - run-java-test + run-bindtests \ + run-java-tests CLEANFILES = doc-stamp @@ -86,16 +88,20 @@ install-data-hook: # Tests (not comprehensive). -TESTS = $(java_tests:.java=.class) +TESTS = run-bindtests run-java-tests TESTS_ENVIRONMENT = \ JAVA=$(JAVA) \ - CLASSPATH=t:libguestfs-$(VERSION).jar \ - LIBGUESTFS_PATH=$(top_builddir)/appliance \ - ./run-java-test + CLASSPATH=.:t:libguestfs-$(VERSION).jar \ + LIBGUESTFS_PATH=$(top_builddir)/appliance + +noinst_DATA = Bindtests.class $(java_tests:.java=.class) t/%.class: t/%.java $(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar $< +Bindtests.class: Bindtests.java + $(JAVAC) $(JAVAC_FLAGS) -classpath libguestfs-$(VERSION).jar $< + endif # Tell version 3.79 and up of GNU make to not build goals in this diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c index 37683bf..c5971c5 100644 --- a/java/com_redhat_et_libguestfs_GuestFS.c +++ b/java/com_redhat_et_libguestfs_GuestFS.c @@ -78,7 +78,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1test0 int i; str = (*env)->GetStringUTFChars (env, jstr, NULL); - optstr = (*env)->GetStringUTFChars (env, joptstr, NULL); + optstr = joptstr ? (*env)->GetStringUTFChars (env, joptstr, NULL) : NULL; strlist_len = (*env)->GetArrayLength (env, jstrlist); strlist = guestfs_safe_malloc (g, sizeof (char *) * (strlist_len+1)); for (i = 0; i < strlist_len; ++i) { @@ -92,7 +92,8 @@ Java_com_redhat_et_libguestfs_GuestFS__1test0 fileout = (*env)->GetStringUTFChars (env, jfileout, NULL); r = guestfs_test0 (g, str, optstr, strlist, b, integer, filein, fileout); (*env)->ReleaseStringUTFChars (env, jstr, str); - (*env)->ReleaseStringUTFChars (env, joptstr, optstr); + if (joptstr) + (*env)->ReleaseStringUTFChars (env, joptstr, optstr); for (i = 0; i < strlist_len; ++i) { jobject o = (*env)->GetObjectArrayElement (env, jstrlist, i); (*env)->ReleaseStringUTFChars (env, o, strlist[i]); @@ -1097,10 +1098,11 @@ Java_com_redhat_et_libguestfs_GuestFS__1config const char *qemuvalue; qemuparam = (*env)->GetStringUTFChars (env, jqemuparam, NULL); - qemuvalue = (*env)->GetStringUTFChars (env, jqemuvalue, NULL); + qemuvalue = jqemuvalue ? (*env)->GetStringUTFChars (env, jqemuvalue, NULL) : NULL; r = guestfs_config (g, qemuparam, qemuvalue); (*env)->ReleaseStringUTFChars (env, jqemuparam, qemuparam); - (*env)->ReleaseStringUTFChars (env, jqemuvalue, qemuvalue); + if (jqemuvalue) + (*env)->ReleaseStringUTFChars (env, jqemuvalue, qemuvalue); if (r == -1) { throw_exception (env, guestfs_last_error (g)); return ; @@ -1928,10 +1930,11 @@ Java_com_redhat_et_libguestfs_GuestFS__1aug_1defvar const char *expr; name = (*env)->GetStringUTFChars (env, jname, NULL); - expr = (*env)->GetStringUTFChars (env, jexpr, NULL); + expr = jexpr ? (*env)->GetStringUTFChars (env, jexpr, NULL) : NULL; r = guestfs_aug_defvar (g, name, expr); (*env)->ReleaseStringUTFChars (env, jname, name); - (*env)->ReleaseStringUTFChars (env, jexpr, expr); + if (jexpr) + (*env)->ReleaseStringUTFChars (env, jexpr, expr); if (r == -1) { throw_exception (env, guestfs_last_error (g)); return 0; diff --git a/java/run-bindtests b/java/run-bindtests new file mode 100755 index 0000000..b80c4dc --- /dev/null +++ b/java/run-bindtests @@ -0,0 +1,22 @@ +#!/bin/sh - +# libguestfs Perl bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +$JAVA -Djava.library.path=.libs Bindtests > bindtests.tmp +diff -u ../bindtests bindtests.tmp diff --git a/java/run-java-tests b/java/run-java-tests new file mode 100755 index 0000000..8447160 --- /dev/null +++ b/java/run-java-tests @@ -0,0 +1,24 @@ +#!/bin/sh - +# libguestfs Perl bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +for f in t/*.class; do + classname=$(basename $f .class) + $JAVA -Djava.library.path=.libs $classname +done \ No newline at end of file diff --git a/ocaml/.depend b/ocaml/.depend index 084f4f6..5074667 100644 --- a/ocaml/.depend +++ b/ocaml/.depend @@ -1,3 +1,5 @@ guestfs.cmi: +bindtests.cmo: guestfs.cmi +bindtests.cmx: guestfs.cmx guestfs.cmo: guestfs.cmi guestfs.cmx: guestfs.cmi diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index b43049a..739e542 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -19,6 +19,8 @@ EXTRA_DIST = \ guestfs.mli guestfs.ml \ guestfs_c.c guestfs_c.h guestfs_c_actions.c \ .depend META.in \ + bindtests.ml \ + run-bindtests \ t/*.ml SUBDIRS = examples @@ -47,8 +49,13 @@ TESTS_ENVIRONMENT = \ LIBGUESTFS_PATH=$(top_builddir)/appliance \ $(VG) -TESTS = t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate -noinst_DATA += $(TESTS) +TESTS = run-bindtests \ + t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate +noinst_DATA += bindtests \ + t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate + +bindtests: bindtests.ml mlguestfs.cmxa + $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@ t/guestfs_005_load: t/guestfs_005_load.ml mlguestfs.cmxa $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@ diff --git a/ocaml/bindtests.ml b/ocaml/bindtests.ml new file mode 100644 index 0000000..2f39bfc --- /dev/null +++ b/ocaml/bindtests.ml @@ -0,0 +1,37 @@ +(* libguestfs generated file + * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. + * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. + * + * Copyright (C) 2009 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. + *) + +let () = + let g = Guestfs.create () in + Guestfs.test0 g "abc" (Some "def") [||] false 0 "123" "456"; + Guestfs.test0 g "abc" None [||] false 0 "123" "456"; + Guestfs.test0 g "" (Some "def") [||] false 0 "123" "456"; + Guestfs.test0 g "" (Some "") [||] false 0 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false 0 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1";"2"|] false 0 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] true 0 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false (-1) "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false (-2) "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false 1 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false 2 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false 4095 "123" "456"; + Guestfs.test0 g "abc" (Some "def") [|"1"|] false 0 "" ""; +print_endline "EOF" diff --git a/java/run-java-test b/ocaml/run-bindtests old mode 100755 new mode 100644 similarity index 86% rename from java/run-java-test rename to ocaml/run-bindtests index 905360d..a9162c9 --- a/java/run-java-test +++ b/ocaml/run-bindtests @@ -1,5 +1,5 @@ #!/bin/sh - -# libguestfs Java bindings +# libguestfs OCaml bindings # Copyright (C) 2009 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify @@ -16,6 +16,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -cmd=$(echo $1 | sed -e 's,^./t/,,' -e 's,.class$,,') +set -e + +./bindtests > bindtests.tmp +diff -u ../bindtests bindtests.tmp -$JAVA -Djava.library.path=.libs $cmd diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs index fcf62f7..0f90aff 100644 --- a/perl/Guestfs.xs +++ b/perl/Guestfs.xs @@ -110,7 +110,7 @@ void test0 (g, str, optstr, strlist, b, integer, filein, fileout) guestfs_h *g; char *str; - char *optstr; + char *optstr = SvOK(ST(2)) ? SvPV_nolen(ST(2)) : NULL; char **strlist; int b; int integer; @@ -727,7 +727,7 @@ void config (g, qemuparam, qemuvalue) guestfs_h *g; char *qemuparam; - char *qemuvalue; + char *qemuvalue = SvOK(ST(2)) ? SvPV_nolen(ST(2)) : NULL; PREINIT: int r; PPCODE: @@ -1270,7 +1270,7 @@ SV * aug_defvar (g, name, expr) guestfs_h *g; char *name; - char *expr; + char *expr = SvOK(ST(2)) ? SvPV_nolen(ST(2)) : NULL; PREINIT: int nrnodes; CODE: diff --git a/perl/Makefile.am b/perl/Makefile.am index 52a6a09..5d661ce 100644 --- a/perl/Makefile.am +++ b/perl/Makefile.am @@ -22,6 +22,7 @@ EXTRA_DIST = \ examples/LICENSE \ examples/*.pl \ lib/Sys/Guestfs.pm \ + run-bindtests \ run-perl-tests \ t/*.t \ typemap @@ -31,7 +32,11 @@ if HAVE_PERL # Interfacing automake and ExtUtils::MakeMaker known to be # a nightmare, news at 11. -TESTS = run-perl-tests +TESTS = run-bindtests run-perl-tests + +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=../src/.libs \ + LIBGUESTFS_PATH=../appliance INSTALLDIRS = site diff --git a/perl/bindtests.pl b/perl/bindtests.pl new file mode 100644 index 0000000..76d76f9 --- /dev/null +++ b/perl/bindtests.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w +# libguestfs generated file +# WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. +# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. +# +# Copyright (C) 2009 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. + +use strict; + +use Sys::Guestfs; + +my $g = Sys::Guestfs->new (); +$g->test0 ("abc", "def", [], 0, 0, "123", "456"); +$g->test0 ("abc", undef, [], 0, 0, "123", "456"); +$g->test0 ("", "def", [], 0, 0, "123", "456"); +$g->test0 ("", "", [], 0, 0, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, 0, "123", "456"); +$g->test0 ("abc", "def", ["1","2"], 0, 0, "123", "456"); +$g->test0 ("abc", "def", ["1"], 1, 0, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, -1, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, -2, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, 1, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, 2, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, 4095, "123", "456"); +$g->test0 ("abc", "def", ["1"], 0, 0, "", ""); +print "EOF\n" diff --git a/perl/run-bindtests b/perl/run-bindtests new file mode 100755 index 0000000..d9d1ca3 --- /dev/null +++ b/perl/run-bindtests @@ -0,0 +1,23 @@ +#!/bin/sh - +# libguestfs Perl bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +export PERL5LIB=$(pwd)/blib/lib:$(pwd)/blib/arch +perl bindtests.pl > bindtests.tmp +diff -u ../bindtests bindtests.tmp diff --git a/perl/run-perl-tests b/perl/run-perl-tests index e3f315e..c290742 100755 --- a/perl/run-perl-tests +++ b/perl/run-perl-tests @@ -16,6 +16,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -export LD_LIBRARY_PATH=../src/.libs -export LIBGUESTFS_PATH=../appliance +set -e + make -f Makefile-pl test "$@" diff --git a/po/libguestfs.pot b/po/libguestfs.pot index 92d383a..16c4598 100644 --- a/po/libguestfs.pot +++ b/po/libguestfs.pot @@ -9,7 +9,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://bugzilla.redhat.com/enter_bug.cgi?" "component=libguestfs&product=Virtualization+Tools\n" -"POT-Creation-Date: 2009-05-27 17:12+0100\n" +"POT-Creation-Date: 2009-05-28 20:04+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -69,12 +69,12 @@ msgstr "" msgid "guestfs_create: failed to create handle\n" msgstr "" -#: fish/fish.c:214 +#: fish/fish.c:215 #, c-format msgid "guestfish: unexpected command line option 0x%x\n" msgstr "" -#: fish/fish.c:341 +#: fish/fish.c:342 #, c-format msgid "" "\n" @@ -86,57 +86,57 @@ msgid "" "\n" msgstr "" -#: fish/fish.c:418 +#: fish/fish.c:419 #, c-format msgid "guestfish: unterminated double quote\n" msgstr "" -#: fish/fish.c:423 fish/fish.c:438 +#: fish/fish.c:424 fish/fish.c:439 #, c-format msgid "guestfish: command arguments not separated by whitespace\n" msgstr "" -#: fish/fish.c:433 +#: fish/fish.c:434 #, c-format msgid "guestfish: unterminated single quote\n" msgstr "" -#: fish/fish.c:474 +#: fish/fish.c:475 #, c-format msgid "guestfish: internal error parsing string at '%s'\n" msgstr "" -#: fish/fish.c:487 +#: fish/fish.c:488 #, c-format msgid "guestfish: too many arguments\n" msgstr "" -#: fish/fish.c:514 +#: fish/fish.c:515 #, c-format msgid "guestfish: empty command on command line\n" msgstr "" -#: fish/fish.c:571 +#: fish/fish.c:572 msgid "display a list of commands or help on a command" msgstr "" -#: fish/fish.c:573 +#: fish/fish.c:574 msgid "quit guestfish" msgstr "" -#: fish/fish.c:576 +#: fish/fish.c:577 msgid "allocate an image" msgstr "" -#: fish/fish.c:578 +#: fish/fish.c:579 msgid "display a line of text" msgstr "" -#: fish/fish.c:580 +#: fish/fish.c:581 msgid "edit a file in the image" msgstr "" -#: fish/fish.c:592 +#: fish/fish.c:593 #, c-format msgid "" "alloc - allocate an image\n" @@ -156,7 +156,7 @@ msgid "" " sects number of 512 byte sectors\n" msgstr "" -#: fish/fish.c:608 +#: fish/fish.c:609 #, c-format msgid "" "echo - display a line of text\n" @@ -165,7 +165,7 @@ msgid "" " This echos the parameters to the terminal.\n" msgstr "" -#: fish/fish.c:615 +#: fish/fish.c:616 #, c-format msgid "" "edit - edit a file in the image\n" @@ -183,7 +183,7 @@ msgid "" " (> 2 MB) or binary files containing \\0 bytes.\n" msgstr "" -#: fish/fish.c:629 +#: fish/fish.c:630 #, c-format msgid "" "help - display a list of commands or help on a command\n" @@ -191,14 +191,14 @@ msgid "" " help\n" msgstr "" -#: fish/fish.c:635 +#: fish/fish.c:636 #, c-format msgid "" "quit - quit guestfish\n" " quit\n" msgstr "" -#: fish/fish.c:638 +#: fish/fish.c:639 #, c-format msgid "%s: command not known, use -h to list all commands\n" msgstr "" diff --git a/po/pl.po b/po/pl.po index d3543f7..158b1fb 100644 --- a/po/pl.po +++ b/po/pl.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: libguestfs 1.0.31\n" "Report-Msgid-Bugs-To: https://bugzilla.redhat.com/enter_bug.cgi?" "component=libguestfs&product=Virtualization+Tools\n" -"POT-Creation-Date: 2009-05-27 17:12+0100\n" +"POT-Creation-Date: 2009-05-28 20:04+0100\n" "PO-Revision-Date: 2009-05-26 00:50+0200\n" "Last-Translator: Piotr Drąg \n" "Language-Team: Polish \n" @@ -88,12 +88,12 @@ msgstr "" msgid "guestfs_create: failed to create handle\n" msgstr "guestfs_create: utworzenie programu obsługi nie powiodło się\n" -#: fish/fish.c:214 +#: fish/fish.c:215 #, c-format msgid "guestfish: unexpected command line option 0x%x\n" msgstr "guestfish: nieoczekiwane polecenie wiersza poleceń 0x%x\n" -#: fish/fish.c:341 +#: fish/fish.c:342 #, c-format msgid "" "\n" @@ -112,57 +112,57 @@ msgstr "" " \"quit\", aby zakończyć powłokę\n" "\n" -#: fish/fish.c:418 +#: fish/fish.c:419 #, c-format msgid "guestfish: unterminated double quote\n" msgstr "guestfish: niezakończony podwójny cudzysłów\n" -#: fish/fish.c:423 fish/fish.c:438 +#: fish/fish.c:424 fish/fish.c:439 #, c-format msgid "guestfish: command arguments not separated by whitespace\n" msgstr "guestfish: parametry poleceń nie są oddzielone spacjami\n" -#: fish/fish.c:433 +#: fish/fish.c:434 #, c-format msgid "guestfish: unterminated single quote\n" msgstr "guestfish: niezakończony pojedynczy cudzysłów\n" -#: fish/fish.c:474 +#: fish/fish.c:475 #, c-format msgid "guestfish: internal error parsing string at '%s'\n" msgstr "guestfish: wewnętrzny błąd analizowania łańcucha \"%s\"\n" -#: fish/fish.c:487 +#: fish/fish.c:488 #, c-format msgid "guestfish: too many arguments\n" msgstr "guestfish: za dużo parametrów\n" -#: fish/fish.c:514 +#: fish/fish.c:515 #, c-format msgid "guestfish: empty command on command line\n" msgstr "guestfish: puste polecenie wiersza poleceń\n" -#: fish/fish.c:571 +#: fish/fish.c:572 msgid "display a list of commands or help on a command" msgstr "wyświetla listę poleceń lub pomoc polecenia" -#: fish/fish.c:573 +#: fish/fish.c:574 msgid "quit guestfish" msgstr "kończy pracę guestfish" -#: fish/fish.c:576 +#: fish/fish.c:577 msgid "allocate an image" msgstr "przydziela obraz" -#: fish/fish.c:578 +#: fish/fish.c:579 msgid "display a line of text" msgstr "wyświetla wiersz tekstu" -#: fish/fish.c:580 +#: fish/fish.c:581 msgid "edit a file in the image" msgstr "modyfikuje plik w obrazie" -#: fish/fish.c:592 +#: fish/fish.c:593 #, c-format msgid "" "alloc - allocate an image\n" @@ -198,7 +198,7 @@ msgstr "" " G lub GB liczba gigabajtów\n" " sektory liczba 512 bajtowych sektorów\n" -#: fish/fish.c:608 +#: fish/fish.c:609 #, c-format msgid "" "echo - display a line of text\n" @@ -211,7 +211,7 @@ msgstr "" "\n" " Wyświetla ostatnie parametry w terminalu.\n" -#: fish/fish.c:615 +#: fish/fish.c:616 #, c-format msgid "" "edit - edit a file in the image\n" @@ -243,7 +243,7 @@ msgstr "" " UWAGA: nie będzie działało poprawnie dla dużych plików\n" " (> 2 MB) lub plików binarnych zawierających \\0 bajtów.\n" -#: fish/fish.c:629 +#: fish/fish.c:630 #, c-format msgid "" "help - display a list of commands or help on a command\n" @@ -254,7 +254,7 @@ msgstr "" " help polecenie\n" " help\n" -#: fish/fish.c:635 +#: fish/fish.c:636 #, c-format msgid "" "quit - quit guestfish\n" @@ -263,7 +263,7 @@ msgstr "" "quit - kończy pracę guestfish\n" " quit\n" -#: fish/fish.c:638 +#: fish/fish.c:639 #, c-format msgid "%s: command not known, use -h to list all commands\n" msgstr "" diff --git a/python/Makefile.am b/python/Makefile.am index 4c72bbd..dcd0625 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -18,6 +18,9 @@ EXTRA_DIST = \ guestfs.py \ guestfs-py.c \ + bindtests.py \ + run-bindtests \ + run-python-tests \ t/*.py if HAVE_PYTHON @@ -34,8 +37,8 @@ libguestfsmod_la_LIBADD = $(top_builddir)/src/libguestfs.la TESTS_ENVIRONMENT = \ LIBGUESTFS_PATH=$(top_builddir)/appliance \ - PYTHONPATH=$(top_builddir)/python:$(top_builddir)/python/.libs \ - $(PYTHON) -TESTS = t/005-import.py t/010-launch.py t/050-lvcreate.py + PYTHONPATH=$(top_builddir)/python:$(top_builddir)/python/.libs + +TESTS = run-bindtests run-python-tests endif diff --git a/python/bindtests.py b/python/bindtests.py new file mode 100644 index 0000000..09f5d5e --- /dev/null +++ b/python/bindtests.py @@ -0,0 +1,37 @@ +# libguestfs generated file +# WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. +# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. +# +# Copyright (C) 2009 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. + +import guestfs + +g = guestfs.GuestFS () +g.test0 ("abc", "def", [], 0, 0, "123", "456") +g.test0 ("abc", None, [], 0, 0, "123", "456") +g.test0 ("", "def", [], 0, 0, "123", "456") +g.test0 ("", "", [], 0, 0, "123", "456") +g.test0 ("abc", "def", ["1"], 0, 0, "123", "456") +g.test0 ("abc", "def", ["1","2"], 0, 0, "123", "456") +g.test0 ("abc", "def", ["1"], 1, 0, "123", "456") +g.test0 ("abc", "def", ["1"], 0, -1, "123", "456") +g.test0 ("abc", "def", ["1"], 0, -2, "123", "456") +g.test0 ("abc", "def", ["1"], 0, 1, "123", "456") +g.test0 ("abc", "def", ["1"], 0, 2, "123", "456") +g.test0 ("abc", "def", ["1"], 0, 4095, "123", "456") +g.test0 ("abc", "def", ["1"], 0, 0, "", "") +print "EOF" diff --git a/python/run-bindtests b/python/run-bindtests new file mode 100755 index 0000000..17448c3 --- /dev/null +++ b/python/run-bindtests @@ -0,0 +1,22 @@ +#!/bin/sh - +# libguestfs Perl bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +python bindtests.py > bindtests.tmp +diff -u ../bindtests bindtests.tmp diff --git a/python/run-python-tests b/python/run-python-tests new file mode 100755 index 0000000..90e38b3 --- /dev/null +++ b/python/run-python-tests @@ -0,0 +1,24 @@ +#!/bin/sh - +# libguestfs Perl bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +for f in t/*.py; do + python $f +done + diff --git a/ruby/Makefile.am b/ruby/Makefile.am index 9ee0ae5..ad9fa2f 100644 --- a/ruby/Makefile.am +++ b/ruby/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ ext/guestfs/_guestfs.c \ ext/guestfs/extconf.rb \ lib/guestfs.rb \ + run-bindtests \ run-ruby-tests \ tests/tc_*.rb @@ -35,7 +36,11 @@ CLEANFILES = \ if HAVE_RUBY -TESTS = run-ruby-tests +TESTS = run-bindtests run-ruby-tests + +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=../src/.libs \ + LIBGUESTFS_PATH=../appliance all: rake build diff --git a/ruby/bindtests.rb b/ruby/bindtests.rb new file mode 100644 index 0000000..11e3c3f --- /dev/null +++ b/ruby/bindtests.rb @@ -0,0 +1,37 @@ +# libguestfs generated file +# WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'. +# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST. +# +# Copyright (C) 2009 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. + +require 'guestfs' + +g = Guestfs::create() +g.test0("abc", "def", [], false, 0, "123", "456") +g.test0("abc", nil, [], false, 0, "123", "456") +g.test0("", "def", [], false, 0, "123", "456") +g.test0("", "", [], false, 0, "123", "456") +g.test0("abc", "def", ["1"], false, 0, "123", "456") +g.test0("abc", "def", ["1","2"], false, 0, "123", "456") +g.test0("abc", "def", ["1"], true, 0, "123", "456") +g.test0("abc", "def", ["1"], false, -1, "123", "456") +g.test0("abc", "def", ["1"], false, -2, "123", "456") +g.test0("abc", "def", ["1"], false, 1, "123", "456") +g.test0("abc", "def", ["1"], false, 2, "123", "456") +g.test0("abc", "def", ["1"], false, 4095, "123", "456") +g.test0("abc", "def", ["1"], false, 0, "", "") +print "EOF\n" diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index 58f7532..6fb2608 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -82,7 +82,7 @@ static VALUE ruby_guestfs_test0 (VALUE gv, VALUE strv, VALUE optstrv, VALUE strl if (!str) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "str", "test0"); - const char *optstr = StringValueCStr (optstrv); + const char *optstr = !NIL_P (optstrv) ? StringValueCStr (optstrv) : NULL; char **strlist; { int i, len; len = RARRAY_LEN (strlistv); @@ -93,7 +93,7 @@ static VALUE ruby_guestfs_test0 (VALUE gv, VALUE strv, VALUE optstrv, VALUE strl } strlist[len] = NULL; } - int b = NUM2INT (bv); + int b = RTEST (bv); int integer = NUM2INT (integerv); const char *filein = StringValueCStr (fileinv); if (!filein) @@ -952,7 +952,7 @@ static VALUE ruby_guestfs_config (VALUE gv, VALUE qemuparamv, VALUE qemuvaluev) if (!qemuparam) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "qemuparam", "config"); - const char *qemuvalue = StringValueCStr (qemuvaluev); + const char *qemuvalue = !NIL_P (qemuvaluev) ? StringValueCStr (qemuvaluev) : NULL; int r; @@ -1084,7 +1084,7 @@ static VALUE ruby_guestfs_set_autosync (VALUE gv, VALUE autosyncv) if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "set_autosync"); - int autosync = NUM2INT (autosyncv); + int autosync = RTEST (autosyncv); int r; @@ -1119,7 +1119,7 @@ static VALUE ruby_guestfs_set_verbose (VALUE gv, VALUE verbosev) if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "set_verbose"); - int verbose = NUM2INT (verbosev); + int verbose = RTEST (verbosev); int r; @@ -1746,7 +1746,7 @@ static VALUE ruby_guestfs_aug_defvar (VALUE gv, VALUE namev, VALUE exprv) if (!name) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "name", "aug_defvar"); - const char *expr = StringValueCStr (exprv); + const char *expr = !NIL_P (exprv) ? StringValueCStr (exprv) : NULL; int r; @@ -1853,7 +1853,7 @@ static VALUE ruby_guestfs_aug_insert (VALUE gv, VALUE pathv, VALUE labelv, VALUE if (!label) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "label", "aug_insert"); - int before = NUM2INT (beforev); + int before = RTEST (beforev); int r; @@ -3809,7 +3809,7 @@ static VALUE ruby_guestfs_vg_activate_all (VALUE gv, VALUE activatev) if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "vg_activate_all"); - int activate = NUM2INT (activatev); + int activate = RTEST (activatev); int r; @@ -3827,7 +3827,7 @@ static VALUE ruby_guestfs_vg_activate (VALUE gv, VALUE activatev, VALUE volgroup if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "vg_activate"); - int activate = NUM2INT (activatev); + int activate = RTEST (activatev); char **volgroups; { int i, len; len = RARRAY_LEN (volgroupsv); diff --git a/ruby/run-bindtests b/ruby/run-bindtests new file mode 100755 index 0000000..803d4c6 --- /dev/null +++ b/ruby/run-bindtests @@ -0,0 +1,22 @@ +#!/bin/sh - +# libguestfs Ruby bindings +# Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +set -e + +ruby -Ilib -Iext/guestfs bindtests.rb > bindtests.tmp +diff -u ../bindtests bindtests.tmp diff --git a/ruby/run-ruby-tests b/ruby/run-ruby-tests index 8232b29..b371bfb 100755 --- a/ruby/run-ruby-tests +++ b/ruby/run-ruby-tests @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -export LD_LIBRARY_PATH=../src/.libs -export LIBGUESTFS_PATH=../appliance +set -e + rake test "$@" diff --git a/src/generator.ml b/src/generator.ml index 9e17d6e..2cf96ee 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2373,6 +2373,14 @@ let statvfs_cols = [ "namemax", `Int; ] +(* Used for testing language bindings. *) +type callt = + | CallString of string + | CallOptString of string option + | CallStringList of string list + | CallInt of int + | CallBool of bool + (* Useful functions. * Note we don't want to use any external OCaml libraries which * makes this a bit harder than it should be. @@ -5395,13 +5403,19 @@ DESTROY (g) generate_call_args ~handle:"g" (snd style); pr "\n"; pr " guestfs_h *g;\n"; - List.iter ( - function - | String n | FileIn n | FileOut n -> pr " char *%s;\n" n - | OptString n -> pr " char *%s;\n" n - | StringList n -> pr " char **%s;\n" n - | Bool n -> pr " int %s;\n" n - | Int n -> pr " int %s;\n" n + iteri ( + fun i -> + function + | String n | FileIn n | FileOut n -> pr " char *%s;\n" n + | OptString n -> + (* http://www.perlmonks.org/?node_id=554277 + * Note that the implicit handle argument means we have + * to add 1 to the ST(x) operator. + *) + pr " char *%s = SvOK(ST(%d)) ? SvPV_nolen(ST(%d)) : NULL;\n" n (i+1) (i+1) + | StringList n -> pr " char **%s;\n" n + | Bool n -> pr " int %s;\n" n + | Int n -> pr " int %s;\n" n ) (snd style); let do_cleanups () = @@ -6335,7 +6349,7 @@ static VALUE ruby_guestfs_close (VALUE gv) pr " rb_raise (rb_eTypeError, \"expected string for parameter %%s of %%s\",\n"; pr " \"%s\", \"%s\");\n" n name | OptString n -> - pr " const char *%s = StringValueCStr (%sv);\n" n n + pr " const char *%s = !NIL_P (%sv) ? StringValueCStr (%sv) : NULL;\n" n n n | StringList n -> pr " char **%s;" n; pr " {\n"; @@ -6349,7 +6363,8 @@ static VALUE ruby_guestfs_close (VALUE gv) pr " }\n"; pr " %s[len] = NULL;\n" n; pr " }\n"; - | Bool n + | Bool n -> + pr " int %s = RTEST (%sv);\n" n n | Int n -> pr " int %s = NUM2INT (%sv);\n" n n ) (snd style); @@ -6863,10 +6878,14 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | String n - | OptString n | FileIn n | FileOut n -> pr " %s = (*env)->GetStringUTFChars (env, j%s, NULL);\n" n n + | OptString n -> + (* This is completely undocumented, but Java null becomes + * a NULL parameter. + *) + pr " %s = j%s ? (*env)->GetStringUTFChars (env, j%s, NULL) : NULL;\n" n n n | StringList n -> pr " %s_len = (*env)->GetArrayLength (env, j%s);\n" n n; pr " %s = guestfs_safe_malloc (g, sizeof (char *) * (%s_len+1));\n" n n; @@ -6890,10 +6909,12 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | String n - | OptString n | FileIn n | FileOut n -> pr " (*env)->ReleaseStringUTFChars (env, j%s, %s);\n" n n + | OptString n -> + pr " if (j%s)\n" n; + pr " (*env)->ReleaseStringUTFChars (env, j%s, %s);\n" n n | StringList n -> pr " for (i = 0; i < %s_len; ++i) {\n" n; pr " jobject o = (*env)->GetObjectArrayElement (env, j%s, i);\n" @@ -7264,6 +7285,8 @@ print_strings (char * const* const argv) | Bool n -> pr " printf (\"%%s\\n\", %s ? \"true\" : \"false\");\n" n | Int n -> pr " printf (\"%%d\\n\", %s);\n" n ) (snd style); + pr " /* Java changes stdout line buffering so we need this: */\n"; + pr " fflush (stdout);\n"; pr " return 0;\n"; pr "}\n"; pr "\n" in @@ -7392,6 +7415,220 @@ print_strings (char * const* const argv) ) ) tests +and generate_ocaml_bindtests () = + generate_header OCamlStyle GPLv2; + + pr "\ +let () = + let g = Guestfs.create () in +"; + + let mkargs args = + String.concat " " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "None" + | CallOptString (Some s) -> sprintf "(Some \"%s\")" s + | CallStringList xs -> + "[|" ^ String.concat ";" (List.map (sprintf "\"%s\"") xs) ^ "|]" + | CallInt i when i >= 0 -> string_of_int i + | CallInt i (* when i < 0 *) -> "(" ^ string_of_int i ^ ")" + | CallBool b -> string_of_bool b + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr " Guestfs.%s g %s;\n" f (mkargs args) + ); + + pr "print_endline \"EOF\"\n" + +and generate_perl_bindtests () = + pr "#!/usr/bin/perl -w\n"; + generate_header HashStyle GPLv2; + + pr "\ +use strict; + +use Sys::Guestfs; + +my $g = Sys::Guestfs->new (); +"; + + let mkargs args = + String.concat ", " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "undef" + | CallOptString (Some s) -> sprintf "\"%s\"" s + | CallStringList xs -> + "[" ^ String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "]" + | CallInt i -> string_of_int i + | CallBool b -> if b then "1" else "0" + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr "$g->%s (%s);\n" f (mkargs args) + ); + + pr "print \"EOF\\n\"\n" + +and generate_python_bindtests () = + generate_header HashStyle GPLv2; + + pr "\ +import guestfs + +g = guestfs.GuestFS () +"; + + let mkargs args = + String.concat ", " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "None" + | CallOptString (Some s) -> sprintf "\"%s\"" s + | CallStringList xs -> + "[" ^ String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "]" + | CallInt i -> string_of_int i + | CallBool b -> if b then "1" else "0" + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr "g.%s (%s)\n" f (mkargs args) + ); + + pr "print \"EOF\"\n" + +and generate_ruby_bindtests () = + generate_header HashStyle GPLv2; + + pr "\ +require 'guestfs' + +g = Guestfs::create() +"; + + let mkargs args = + String.concat ", " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "nil" + | CallOptString (Some s) -> sprintf "\"%s\"" s + | CallStringList xs -> + "[" ^ String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "]" + | CallInt i -> string_of_int i + | CallBool b -> string_of_bool b + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr "g.%s(%s)\n" f (mkargs args) + ); + + pr "print \"EOF\\n\"\n" + +and generate_java_bindtests () = + generate_header CStyle GPLv2; + + pr "\ +import com.redhat.et.libguestfs.*; + +public class Bindtests { + public static void main (String[] argv) + { + try { + GuestFS g = new GuestFS (); +"; + + let mkargs args = + String.concat ", " ( + List.map ( + function + | CallString s -> "\"" ^ s ^ "\"" + | CallOptString None -> "null" + | CallOptString (Some s) -> sprintf "\"%s\"" s + | CallStringList xs -> + "new String[]{" ^ + String.concat "," (List.map (sprintf "\"%s\"") xs) ^ "}" + | CallInt i -> string_of_int i + | CallBool b -> string_of_bool b + ) args + ) + in + + generate_lang_bindtests ( + fun f args -> pr " g.%s (%s);\n" f (mkargs args) + ); + + pr " + System.out.println (\"EOF\"); + } + catch (Exception exn) { + System.err.println (exn); + System.exit (1); + } + } +} +" + +and generate_haskell_bindtests () = + () (* XXX Haskell bindings need to be fleshed out. *) + +(* Language-independent bindings tests - we do it this way to + * ensure there is parity in testing bindings across all languages. + *) +and generate_lang_bindtests call = + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList []; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString None; + CallStringList []; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString ""; CallOptString (Some "def"); + CallStringList []; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString ""; CallOptString (Some ""); + CallStringList []; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"; "2"]; CallBool false; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool true; + CallInt 0; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt (-1); CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt (-2); CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt 1; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt 2; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt 4095; CallString "123"; CallString "456"]; + call "test0" [CallString "abc"; CallOptString (Some "def"); + CallStringList ["1"]; CallBool false; + CallInt 0; CallString ""; CallString ""] + let output_to filename = let filename_new = filename ^ ".new" in chan := open_out filename_new; @@ -7489,6 +7726,10 @@ Run it from the top source directory using the command generate_ocaml_c (); close (); + let close = output_to "ocaml/bindtests.ml" in + generate_ocaml_bindtests (); + close (); + let close = output_to "perl/Guestfs.xs" in generate_perl_xs (); close (); @@ -7497,6 +7738,10 @@ Run it from the top source directory using the command generate_perl_pm (); close (); + let close = output_to "perl/bindtests.pl" in + generate_perl_bindtests (); + close (); + let close = output_to "python/guestfs-py.c" in generate_python_c (); close (); @@ -7505,10 +7750,18 @@ Run it from the top source directory using the command generate_python_py (); close (); + let close = output_to "python/bindtests.py" in + generate_python_bindtests (); + close (); + let close = output_to "ruby/ext/guestfs/_guestfs.c" in generate_ruby_c (); close (); + let close = output_to "ruby/bindtests.rb" in + generate_ruby_bindtests (); + close (); + let close = output_to "java/com/redhat/et/libguestfs/GuestFS.java" in generate_java_java (); close (); @@ -7537,6 +7790,14 @@ Run it from the top source directory using the command generate_java_c (); close (); + let close = output_to "java/Bindtests.java" in + generate_java_bindtests (); + close (); + let close = output_to "haskell/Guestfs.hs" in generate_haskell_hs (); close (); + + let close = output_to "haskell/bindtests.hs" in + generate_haskell_bindtests (); + close (); diff --git a/src/guestfs-bindtests.c b/src/guestfs-bindtests.c index 7279f56..a472bca 100644 --- a/src/guestfs-bindtests.c +++ b/src/guestfs-bindtests.c @@ -59,6 +59,8 @@ int guestfs_test0 (guestfs_h *g, printf ("%d\n", integer); printf ("%s\n", filein); printf ("%s\n", fileout); + /* Java changes stdout line buffering so we need this: */ + fflush (stdout); return 0; } -- 1.8.3.1