mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Start adding return values tests for bindings
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
26
gobject/run-tests-retvalues
Executable file
26
gobject/run-tests-retvalues
Executable file
@@ -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
|
||||
125
perl/t/090-retvalues.t
Normal file
125
perl/t/090-retvalues.t
Normal file
@@ -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");
|
||||
294
php/extension/tests/guestfs_090_retvalues.phpt
Normal file
294
php/extension/tests/guestfs_090_retvalues.phpt
Normal file
@@ -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
|
||||
138
python/t/090-retvalues.py
Normal file
138
python/t/090-retvalues.py
Normal file
@@ -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 ()
|
||||
@@ -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 ()
|
||||
141
ruby/t/tc_090_retvalues.rb
Normal file
141
ruby/t/tc_090_retvalues.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user