Add tests for bindings parameters, fix several broken bindings.

This commit is contained in:
Richard W.M. Jones
2009-05-28 20:15:51 +01:00
parent c41fe04a65
commit babc0846cc
31 changed files with 817 additions and 89 deletions

View File

@@ -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

37
ruby/bindtests.rb Normal file
View File

@@ -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"

View File

@@ -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);

22
ruby/run-bindtests Executable file
View File

@@ -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

View File

@@ -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 "$@"