diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2009-05-28 20:15:51 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2009-05-28 20:15:51 +0100 |
commit | babc0846cc911b01a58a7385d30ad25889b7175a (patch) | |
tree | e8f67f7fc096185e0febbad35396ba3972eaa432 /ruby | |
parent | c41fe04a652437c920acb0e820762c53bf44a139 (diff) | |
download | libguestfs-babc0846cc911b01a58a7385d30ad25889b7175a.tar.gz libguestfs-babc0846cc911b01a58a7385d30ad25889b7175a.tar.xz libguestfs-babc0846cc911b01a58a7385d30ad25889b7175a.zip |
Add tests for bindings parameters, fix several broken bindings.
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/Makefile.am | 7 | ||||
-rw-r--r-- | ruby/bindtests.rb | 37 | ||||
-rw-r--r-- | ruby/ext/guestfs/_guestfs.c | 18 | ||||
-rwxr-xr-x | ruby/run-bindtests | 22 | ||||
-rwxr-xr-x | ruby/run-ruby-tests | 4 |
5 files changed, 76 insertions, 12 deletions
diff --git a/ruby/Makefile.am b/ruby/Makefile.am index 9ee0ae50..ad9fa2f9 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 00000000..11e3c3fd --- /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 58f75327..6fb26089 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 00000000..803d4c6f --- /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 8232b29a..b371bfb9 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 "$@" |