Introduce a new kind of bindings tests, 090-retvalues, to check all the
possible return values in bindings; start implementing them for
scripting languages such as GObject introspection, Perl, PHP, Python,
and Ruby, reusing existing implementations where existing.
---
docs/guestfs-hacking.pod | 1 +
gobject/Makefile.am | 4 +-
gobject/bindtests-manual.js | 110 ---------
gobject/bindtests-retvalues.js | 110 +++++++++
gobject/run-tests | 2 -
gobject/run-tests-retvalues | 26 +++
perl/t/090-retvalues.t | 125 +++++++++++
php/extension/tests/guestfs_090_retvalues.phpt | 294 +++++++++++++++++++++++++
python/t/090-retvalues.py | 138 ++++++++++++
python/t/900-python-dict.py | 40 ----
ruby/t/tc_090_retvalues.rb | 141 ++++++++++++
11 files changed, 838 insertions(+), 153 deletions(-)
delete mode 100644 gobject/bindtests-manual.js
create mode 100644 gobject/bindtests-retvalues.js
create mode 100755 gobject/run-tests-retvalues
create mode 100644 perl/t/090-retvalues.t
create mode 100644 php/extension/tests/guestfs_090_retvalues.phpt
create mode 100644 python/t/090-retvalues.py
delete mode 100644 python/t/900-python-dict.py
create mode 100644 ruby/t/tc_090_retvalues.rb
diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod
index ecd10bf..c357717 100644
--- a/docs/guestfs-hacking.pod
+++ b/docs/guestfs-hacking.pod
@@ -202,6 +202,7 @@ This is the numbering scheme used by the tests:
065 implicit close (in GC'd languages)
070 optargs
080 version
+ 090 retvalues
- 100 launch, create partitions and LVs and filesystems
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index b7e7f10..1f523b7 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -90,7 +90,9 @@ gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
-TESTS = run-tests
+TESTS = \
+ run-tests \
+ run-tests-retvalues
if ENABLE_APPLIANCE
TESTS += run-live-tests
diff --git a/gobject/bindtests-manual.js b/gobject/bindtests-manual.js
deleted file mode 100644
index d7bbe5f..0000000
--- a/gobject/bindtests-manual.js
+++ /dev/null
@@ -1,110 +0,0 @@
-// libguestfs manually written gobject binding tests
-// 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.
-
-const Guestfs = imports.gi.Guestfs;
-
-var fail = false;
-
-function check_error(f) {
- var threw = false;
-
- try {
- g[f]();
- } catch (error) {
- threw = true;
- if (!error.message.match(/error$/)) {
- print(f + " threw unexpected error: " + error.message);
- fail = true;
- }
- }
- if (!threw) {
- print(f + " failed to throw an error");
- fail = true;
- }
-}
-
-function eq_fail(f, v) {
- print(f + " returned unexpected value: " + v);
- fail = true;
-}
-
-var g = new Guestfs.Session();
-
-var v;
-var eq;
-
-v = g.internal_test_rint('1');
-v == 1 || eq_fail('internal_test_rint', v);
-check_error('internal_test_rinterr');
-
-v = g.internal_test_rint64('1');
-v == 1 || eq_fail('internal_test_rint64', v);
-check_error('internal_test_rint64err');
-
-v = g.internal_test_rbool('true');
-v == 1 || eq_fail('internal_test_rbool', v);
-check_error('internal_test_rboolerr');
-
-v = g.internal_test_rconststring('1');
-v == 'static string' || eq_fail('internal_test_rconststring', v);
-check_error('internal_test_rconststringerr');
-
-v = g.internal_test_rconstoptstring('1');
-v == 'static string' || eq_fail('internal_test_rconstoptstring', v);
-//check_error('internal_test_rconstoptstringerr');
-
-v = g.internal_test_rstring('string');
-v == 'string' || eq_fail('internal_test_rstring', v);
-check_error('internal_test_rstringerr');
-
-v = g.internal_test_rstringlist('5');
-eq = v.length == 5;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i] != i) eq = false;
-}
-eq || eq_fail('internal_test_rstringlist', v.join(' '));
-check_error('internal_test_rstringlisterr');
-
-v = g.internal_test_rstruct('1');
-v.pv_size == 0 || eq_fail('internal_test_rstruct', v);
-check_error('internal_test_rstructerr');
-
-v = g.internal_test_rstructlist('5');
-eq = v.length == 5;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i].pv_size != i) eq = false;
-}
-eq || eq_fail('internal_test_rstructlist', v);
-check_error('internal_test_rstructlisterr');
-
-v = g.internal_test_rhashtable('5');
-eq = true;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i] != i) eq = false;
-}
-eq || eq_fail('internal_test_rhashtable', v);
-check_error('internal_test_rhashtableerr');
-
-v = g.internal_test_rbufferout("01234");
-eq = v.length == 5;
-for (var i = 0; i < v.length; i++) {
- if (v[i] != 48 + i) eq = false; // 48 = ascii '0'
-}
-eq || eq_fail('internal_test_rbufferout', v);
-check_error('internal_test_rbufferouterr');
-
-fail ? 1 : 0;
diff --git a/gobject/bindtests-retvalues.js b/gobject/bindtests-retvalues.js
new file mode 100644
index 0000000..d7bbe5f
--- /dev/null
+++ b/gobject/bindtests-retvalues.js
@@ -0,0 +1,110 @@
+// libguestfs manually written gobject binding tests
+// 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.
+
+const Guestfs = imports.gi.Guestfs;
+
+var fail = false;
+
+function check_error(f) {
+ var threw = false;
+
+ try {
+ g[f]();
+ } catch (error) {
+ threw = true;
+ if (!error.message.match(/error$/)) {
+ print(f + " threw unexpected error: " + error.message);
+ fail = true;
+ }
+ }
+ if (!threw) {
+ print(f + " failed to throw an error");
+ fail = true;
+ }
+}
+
+function eq_fail(f, v) {
+ print(f + " returned unexpected value: " + v);
+ fail = true;
+}
+
+var g = new Guestfs.Session();
+
+var v;
+var eq;
+
+v = g.internal_test_rint('1');
+v == 1 || eq_fail('internal_test_rint', v);
+check_error('internal_test_rinterr');
+
+v = g.internal_test_rint64('1');
+v == 1 || eq_fail('internal_test_rint64', v);
+check_error('internal_test_rint64err');
+
+v = g.internal_test_rbool('true');
+v == 1 || eq_fail('internal_test_rbool', v);
+check_error('internal_test_rboolerr');
+
+v = g.internal_test_rconststring('1');
+v == 'static string' || eq_fail('internal_test_rconststring', v);
+check_error('internal_test_rconststringerr');
+
+v = g.internal_test_rconstoptstring('1');
+v == 'static string' || eq_fail('internal_test_rconstoptstring', v);
+//check_error('internal_test_rconstoptstringerr');
+
+v = g.internal_test_rstring('string');
+v == 'string' || eq_fail('internal_test_rstring', v);
+check_error('internal_test_rstringerr');
+
+v = g.internal_test_rstringlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('internal_test_rstringlist', v.join(' '));
+check_error('internal_test_rstringlisterr');
+
+v = g.internal_test_rstruct('1');
+v.pv_size == 0 || eq_fail('internal_test_rstruct', v);
+check_error('internal_test_rstructerr');
+
+v = g.internal_test_rstructlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i].pv_size != i) eq = false;
+}
+eq || eq_fail('internal_test_rstructlist', v);
+check_error('internal_test_rstructlisterr');
+
+v = g.internal_test_rhashtable('5');
+eq = true;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('internal_test_rhashtable', v);
+check_error('internal_test_rhashtableerr');
+
+v = g.internal_test_rbufferout("01234");
+eq = v.length == 5;
+for (var i = 0; i < v.length; i++) {
+ if (v[i] != 48 + i) eq = false; // 48 = ascii '0'
+}
+eq || eq_fail('internal_test_rbufferout', v);
+check_error('internal_test_rbufferouterr');
+
+fail ? 1 : 0;
diff --git a/gobject/run-tests b/gobject/run-tests
index aa1aaa6..7393e73 100755
--- a/gobject/run-tests
+++ b/gobject/run-tests
@@ -31,6 +31,4 @@ rm -f bindtests.tmp
$GJS $srcdir/bindtests.js > bindtests.tmp
diff -u ${srcdir}/../bindtests bindtests.tmp
-$GJS $srcdir/bindtests-manual.js 2>/dev/null
-
rm bindtests.tmp
diff --git a/gobject/run-tests-retvalues b/gobject/run-tests-retvalues
new file mode 100755
index 0000000..b4f4d4b
--- /dev/null
+++ b/gobject/run-tests-retvalues
@@ -0,0 +1,26 @@
+#!/bin/sh -
+# libguestfs GObject bindings
+# Copyright (C) 2012-2016 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 77
+fi
+
+$GJS $srcdir/bindtests-retvalues.js 2>/dev/null
diff --git a/perl/t/090-retvalues.t b/perl/t/090-retvalues.t
new file mode 100644
index 0000000..c339316
--- /dev/null
+++ b/perl/t/090-retvalues.t
@@ -0,0 +1,125 @@
+# libguestfs Perl bindings -*- perl -*-
+# Copyright (C) 2016 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 warnings;
+use Test::More tests => 42;
+
+use Sys::Guestfs;
+
+my $g = Sys::Guestfs->new ();
+ok ($g);
+
+# rint
+is ($g->internal_test_rint ("10"), 10, "rint");
+eval {
+ my $foo = $g->internal_test_rinterr ();
+};
+like ($@, qr/error/, "rinterr");
+
+# rint64
+is ($g->internal_test_rint64 ("10"), 10, "rint64");
+eval {
+ my $foo = $g->internal_test_rint64err ();
+};
+like ($@, qr/error/, "rint64err");
+
+# rbool
+is ($g->internal_test_rbool ("true"), 1, "rbool/true");
+is ($g->internal_test_rbool ("false"), 0, "rbool/false");
+eval {
+ my $foo = $g->internal_test_rboolerr ();
+};
+like ($@, qr/error/, "rboolerr");
+
+# rconststring
+is ($g->internal_test_rconststring ("test"), "static string",
"rconststring");
+eval {
+ my $foo = $g->internal_test_rconststringerr ();
+};
+like ($@, qr/error/, "rconststringerr");
+
+# rconstoptstring
+is ($g->internal_test_rconstoptstring ("test"), "static string",
"rconstoptstring");
+# this never fails
+eval {
+ my $foo = $g->internal_test_rconstoptstringerr ();
+};
+unlike ($@, qr/error/, "rconstoptstringerr");
+
+# rstring
+is ($g->internal_test_rstring ("test"), "test",
"rstring");
+eval {
+ my $foo = $g->internal_test_rstringerr ();
+};
+like ($@, qr/error/, "rstringerr");
+
+# rstringlist
+my @l = $g->internal_test_rstringlist ("0");
+is (@l, 0, "rstringlist/empty");
+@l = $g->internal_test_rstringlist ("5");
+is (@l, 5, "rstringlist/5/size");
+for (my $i = 0; $i < @l; $i++) {
+ is ($l[$i], $i, "rstringlist/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rstringlisterr ();
+};
+like ($@, qr/error/, "rstringlisterr");
+
+# rstruct
+my %s = $g->internal_test_rstruct ("unused");
+is ($s{'pv_name'}, "pv0", "rstruct/0");
+eval {
+ my $foo = $g->internal_test_rstructerr ();
+};
+like ($@, qr/error/, "rstructerr");
+
+# rstructlist
+my @sl = $g->internal_test_rstructlist ("0");
+is (@sl, 0, "rstructlist/empty");
+@sl = $g->internal_test_rstructlist ("5");
+is (@sl, 5, "rstructlist/5/size");
+for (my $i = 0; $i < @sl; $i++) {
+ is ($sl[$i]{'pv_name'}, "pv$i", "rstructlist/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rstructlisterr ();
+};
+like ($@, qr/error/, "rstructlisterr");
+
+# rhashtable
+my %sl = $g->internal_test_rhashtable ("0");
+my $sls = keys %sl;
+is ($sls, 0, "rhashtable/empty");
+%sl = $g->internal_test_rhashtable ("5");
+$sls = keys %sl;
+is ($sls, 5, "rhashtable/5/size");
+for (my $i = 0; $i < $sls; $i++) {
+ is ($sl{$i}, $i, "rhashtable/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rhashtableerr ();
+};
+like ($@, qr/error/, "rhashtableerr");
+
+# rbufferout
+is ($g->internal_test_rbufferout ("test"), "test",
"rbufferout");
+eval {
+ my $foo = $g->internal_test_rbufferouterr ();
+};
+like ($@, qr/error/, "rbufferouterr");
diff --git a/php/extension/tests/guestfs_090_retvalues.phpt
b/php/extension/tests/guestfs_090_retvalues.phpt
new file mode 100644
index 0000000..0be5755
--- /dev/null
+++ b/php/extension/tests/guestfs_090_retvalues.phpt
@@ -0,0 +1,294 @@
+--TEST--
+Check all the kind of return values.
+--FILE--
+<?php
+$g = guestfs_create ();
+
+# rint
+var_dump (guestfs_internal_test_rint ($g, "10"));
+var_dump (guestfs_internal_test_rinterr ($g));
+
+# rint64
+var_dump (guestfs_internal_test_rint64 ($g, "10"));
+var_dump (guestfs_internal_test_rint64err ($g));
+
+# rbool
+var_dump (guestfs_internal_test_rbool ($g, "true"));
+var_dump (guestfs_internal_test_rbool ($g, "false"));
+var_dump (guestfs_internal_test_rboolerr ($g));
+
+# rconststring
+var_dump (guestfs_internal_test_rconststring ($g, "test"));
+var_dump (guestfs_internal_test_rconststringerr ($g));
+
+# rconstoptstring
+var_dump (guestfs_internal_test_rconstoptstring ($g, "test"));
+var_dump (guestfs_internal_test_rconstoptstringerr ($g));
+
+# rstring
+var_dump (guestfs_internal_test_rstring ($g, "test"));
+var_dump (guestfs_internal_test_rstringerr ($g));
+
+# rstringlist
+var_dump (guestfs_internal_test_rstringlist ($g, "0"));
+var_dump (guestfs_internal_test_rstringlist ($g, "5"));
+var_dump (guestfs_internal_test_rstringlisterr ($g));
+
+# rstruct
+var_dump (guestfs_internal_test_rstruct ($g, "unused"));
+var_dump (guestfs_internal_test_rstructerr ($g));
+
+# rstructlist
+var_dump (guestfs_internal_test_rstructlist ($g, "0"));
+var_dump (guestfs_internal_test_rstructlist ($g, "5"));
+var_dump (guestfs_internal_test_rstructlisterr ($g));
+
+# rhashtable
+var_dump (guestfs_internal_test_rhashtable ($g, "0"));
+var_dump (guestfs_internal_test_rhashtable ($g, "5"));
+var_dump (guestfs_internal_test_rhashtableerr ($g));
+
+# rbufferout
+var_dump (guestfs_internal_test_rbufferout ($g, "test"));
+var_dump (guestfs_internal_test_rbufferouterr ($g));
+
+echo ("OK\n");
+?>
+--EXPECT--
+int(10)
+bool(false)
+int(10)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+string(13) "static string"
+bool(false)
+string(13) "static string"
+NULL
+string(4) "test"
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ string(1) "0"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+ [4]=>
+ string(1) "4"
+}
+bool(false)
+array(14) {
+ ["pv_name"]=>
+ string(3) "pv0"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(0)
+ ["dev_size"]=>
+ int(0)
+ ["pv_free"]=>
+ int(0)
+ ["pv_used"]=>
+ int(0)
+ ["pv_attr"]=>
+ string(5) "attr0"
+ ["pv_pe_count"]=>
+ int(0)
+ ["pv_pe_alloc_count"]=>
+ int(0)
+ ["pv_tags"]=>
+ string(4) "tag0"
+ ["pe_start"]=>
+ int(0)
+ ["pv_mda_count"]=>
+ int(0)
+ ["pv_mda_free"]=>
+ int(0)
+}
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv0"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(0)
+ ["dev_size"]=>
+ int(0)
+ ["pv_free"]=>
+ int(0)
+ ["pv_used"]=>
+ int(0)
+ ["pv_attr"]=>
+ string(5) "attr0"
+ ["pv_pe_count"]=>
+ int(0)
+ ["pv_pe_alloc_count"]=>
+ int(0)
+ ["pv_tags"]=>
+ string(4) "tag0"
+ ["pe_start"]=>
+ int(0)
+ ["pv_mda_count"]=>
+ int(0)
+ ["pv_mda_free"]=>
+ int(0)
+ }
+ [1]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv1"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(1)
+ ["dev_size"]=>
+ int(1)
+ ["pv_free"]=>
+ int(1)
+ ["pv_used"]=>
+ int(1)
+ ["pv_attr"]=>
+ string(5) "attr1"
+ ["pv_pe_count"]=>
+ int(1)
+ ["pv_pe_alloc_count"]=>
+ int(1)
+ ["pv_tags"]=>
+ string(4) "tag1"
+ ["pe_start"]=>
+ int(1)
+ ["pv_mda_count"]=>
+ int(1)
+ ["pv_mda_free"]=>
+ int(1)
+ }
+ [2]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv2"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(2)
+ ["dev_size"]=>
+ int(2)
+ ["pv_free"]=>
+ int(2)
+ ["pv_used"]=>
+ int(2)
+ ["pv_attr"]=>
+ string(5) "attr2"
+ ["pv_pe_count"]=>
+ int(2)
+ ["pv_pe_alloc_count"]=>
+ int(2)
+ ["pv_tags"]=>
+ string(4) "tag2"
+ ["pe_start"]=>
+ int(2)
+ ["pv_mda_count"]=>
+ int(2)
+ ["pv_mda_free"]=>
+ int(2)
+ }
+ [3]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv3"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(3)
+ ["dev_size"]=>
+ int(3)
+ ["pv_free"]=>
+ int(3)
+ ["pv_used"]=>
+ int(3)
+ ["pv_attr"]=>
+ string(5) "attr3"
+ ["pv_pe_count"]=>
+ int(3)
+ ["pv_pe_alloc_count"]=>
+ int(3)
+ ["pv_tags"]=>
+ string(4) "tag3"
+ ["pe_start"]=>
+ int(3)
+ ["pv_mda_count"]=>
+ int(3)
+ ["pv_mda_free"]=>
+ int(3)
+ }
+ [4]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv4"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(4)
+ ["dev_size"]=>
+ int(4)
+ ["pv_free"]=>
+ int(4)
+ ["pv_used"]=>
+ int(4)
+ ["pv_attr"]=>
+ string(5) "attr4"
+ ["pv_pe_count"]=>
+ int(4)
+ ["pv_pe_alloc_count"]=>
+ int(4)
+ ["pv_tags"]=>
+ string(4) "tag4"
+ ["pe_start"]=>
+ int(4)
+ ["pv_mda_count"]=>
+ int(4)
+ ["pv_mda_free"]=>
+ int(4)
+ }
+}
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ string(1) "0"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+ [4]=>
+ string(1) "4"
+}
+bool(false)
+string(4) "test"
+bool(false)
+OK
diff --git a/python/t/090-retvalues.py b/python/t/090-retvalues.py
new file mode 100644
index 0000000..8a5c912
--- /dev/null
+++ b/python/t/090-retvalues.py
@@ -0,0 +1,138 @@
+# libguestfs Python bindings
+# Copyright (C) 2013-2016 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.
+
+# Test all the different return values.
+
+import unittest
+import guestfs
+
+
+class Test090PythonRetValues (unittest.TestCase):
+ def test_rint (self):
+ g = guestfs.GuestFS ()
+
+ self.assertAlmostEqual (g.internal_test_rint ("10"), 10, places=1)
+
+ self.assertRaises (RuntimeError, g.internal_test_rinterr)
+
+
+ def test_rint64 (self):
+ g = guestfs.GuestFS ()
+
+ self.assertAlmostEqual (g.internal_test_rint64 ("10"), 10L, places=1)
+
+ self.assertRaises (RuntimeError, g.internal_test_rint64err)
+
+
+ def test_rbool (self):
+ g = guestfs.GuestFS ()
+
+ self.assertTrue (g.internal_test_rbool ("true"))
+ self.assertFalse (g.internal_test_rbool ("false"))
+
+ self.assertRaises (RuntimeError, g.internal_test_rboolerr)
+
+
+ def test_rconststring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rconststring ("test"), "static
string")
+
+ self.assertRaises (RuntimeError, g.internal_test_rconststringerr)
+
+
+ def test_rconstoptstring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rconstoptstring ("test"),
"static string")
+
+ # this never fails
+ self.assertIsNone (g.internal_test_rconstoptstringerr ())
+
+
+ def test_rstring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstring ("test"), "test")
+
+ self.assertRaises (RuntimeError, g.internal_test_rstringerr)
+
+
+ def test_rstringlist (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstringlist ("0"), [])
+ self.assertEqual (g.internal_test_rstringlist ("5"), ["0",
"1", "2", "3", "4"])
+
+ self.assertRaises (RuntimeError, g.internal_test_rstringlisterr)
+
+
+ def test_rstruct (self):
+ g = guestfs.GuestFS ()
+
+ s = g.internal_test_rstruct ("unused")
+ self.assertIsInstance (s, dict)
+ self.assertEqual (s["pv_name"], "pv0")
+
+ self.assertRaises (RuntimeError, g.internal_test_rstructerr)
+
+
+ def test_rstructlist (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstructlist ("0"), [])
+ l = g.internal_test_rstructlist ("5")
+ self.assertIsInstance (l, list)
+ self.assertEqual (len (l), 5)
+ for i in range (0, 5):
+ self.assertIsInstance (l[i], dict)
+ self.assertEqual (l[i]["pv_name"], "pv%d" % i)
+
+ self.assertRaises (RuntimeError, g.internal_test_rstructlisterr)
+
+
+ def test_rhashtable_list (self):
+ g = guestfs.GuestFS (python_return_dict=False)
+
+ self.assertEqual (g.internal_test_rhashtable ("0"), [])
+ r = g.internal_test_rhashtable ("5")
+ self.assertEqual (r, [ ("0","0"),
("1","1"), ("2","2"),
+ ("3","3"),
("4","4") ])
+
+ self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
+
+
+ def test_rhashtable_dict (self):
+ g = guestfs.GuestFS (python_return_dict=True)
+
+ self.assertEqual (g.internal_test_rhashtable ("0"), {})
+ r = g.internal_test_rhashtable ("5")
+ self.assertEqual (r, {"0": "0", "1": "1",
"2": "2", "3": "3", "4":
"4"})
+
+ self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
+
+
+ def test_rbufferout (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rbufferout ("test"),
b'test')
+
+ self.assertRaises (RuntimeError, g.internal_test_rbufferouterr)
+
+
+if __name__ == '__main__':
+ unittest.main ()
diff --git a/python/t/900-python-dict.py b/python/t/900-python-dict.py
deleted file mode 100644
index 5ea5a53..0000000
--- a/python/t/900-python-dict.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# libguestfs Python bindings
-# Copyright (C) 2013 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.
-
-# Test python-specific python_return_dict parameter.
-
-from types import *
-import unittest
-import os
-import guestfs
-
-class Test900PythonDict (unittest.TestCase):
- def test_python_no_dict (self):
- g = guestfs.GuestFS (python_return_dict=False)
-
- r = g.internal_test_rhashtable ("5")
- self.assertEqual (r, [ ("0","0"),
("1","1"), ("2","2"),
- ("3","3"),
("4","4") ])
-
- def test_python_dict (self):
- g = guestfs.GuestFS (python_return_dict=True)
-
- r = g.internal_test_rhashtable ("5")
- self.assertEqual (r, {"0": "0", "1": "1",
"2": "2", "3": "3", "4":
"4"})
-
-if __name__ == '__main__':
- unittest.main ()
diff --git a/ruby/t/tc_090_retvalues.rb b/ruby/t/tc_090_retvalues.rb
new file mode 100644
index 0000000..1fcc12d
--- /dev/null
+++ b/ruby/t/tc_090_retvalues.rb
@@ -0,0 +1,141 @@
+# libguestfs Ruby bindings -*- ruby -*-
+# Copyright (C) 2016 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 File::join(File::dirname(__FILE__), 'test_helper')
+
+class TestLoad < MiniTest::Unit::TestCase
+ def test_rint
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 10, g.internal_test_rint("10")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rinterr()
+ }
+ end
+
+ def test_rint64
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 10, g.internal_test_rint64("10")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rint64err()
+ }
+ end
+
+ def test_rbool
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 1, g.internal_test_rbool("true")
+ assert_equal 0, g.internal_test_rbool("false")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rboolerr()
+ }
+ end
+
+ def test_rconststring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "static string",
g.internal_test_rconststring("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rconststringerr()
+ }
+ end
+
+ def test_rconstoptstring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "static string",
g.internal_test_rconstoptstring("test")
+
+ # this never fails
+ assert_nil g.internal_test_rconstoptstringerr()
+ end
+
+ def test_rstring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "test", g.internal_test_rstring("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstringerr()
+ }
+ end
+
+ def test_rstringlist
+ g = Guestfs::Guestfs.new()
+
+ assert_equal [], g.internal_test_rstringlist("0")
+ assert_equal ["0", "1", "2", "3",
"4"], g.internal_test_rstringlist("5")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstringlisterr()
+ }
+ end
+
+ def test_rstruct
+ g = Guestfs::Guestfs.new()
+
+ s = g.internal_test_rstruct("unused")
+ assert_instance_of Hash, s
+ assert_equal "pv0", s["pv_name"]
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstructerr()
+ }
+ end
+
+ def test_rstructlist
+ g = Guestfs::Guestfs.new()
+
+ assert_equal [], g.internal_test_rstructlist("0")
+ l = g.internal_test_rstructlist("5")
+ assert_instance_of Array, l
+ assert_equal 5, l.length
+ for i in 0..4
+ assert_instance_of Hash, l[i]
+ assert_equal "pv#{i}", l[i]["pv_name"]
+ end
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstructlisterr()
+ }
+ end
+
+ def test_rhashtable
+ g = Guestfs::Guestfs.new()
+
+ assert_equal Hash[], g.internal_test_rhashtable("0")
+ assert_equal
Hash["0"=>"0","1"=>"1","2"=>"2","3"=>"3","4"=>"4"],
g.internal_test_rhashtable("5")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rhashtableerr()
+ }
+ end
+
+ def test_rbufferout
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "test", g.internal_test_rbufferout("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rbufferouterr()
+ }
+ end
+end
--
2.5.0