summaryrefslogtreecommitdiffstats
path: root/gobject
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2012-01-19 16:51:01 +0000
committerMatthew Booth <mbooth@redhat.com>2012-01-20 18:43:51 +0000
commit93b0769ec7929a909678411d75840f81bed55a81 (patch)
tree358729ba73d02d327b9b17be99dc92527a68d44f /gobject
parent02ccef7684b0e0ec7c0e9435393f24b0c6b417f4 (diff)
downloadlibguestfs-93b0769ec7929a909678411d75840f81bed55a81.tar.gz
libguestfs-93b0769ec7929a909678411d75840f81bed55a81.tar.xz
libguestfs-93b0769ec7929a909678411d75840f81bed55a81.zip
gobject: Add bindtests for return values
Diffstat (limited to 'gobject')
-rw-r--r--gobject/bindtests-manual.js110
-rwxr-xr-xgobject/run-bindtests1
2 files changed, 111 insertions, 0 deletions
diff --git a/gobject/bindtests-manual.js b/gobject/bindtests-manual.js
new file mode 100644
index 00000000..84a1546a
--- /dev/null
+++ b/gobject/bindtests-manual.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.test0rint('1');
+v == 1 || eq_fail('test0rint', v);
+check_error('test0rinterr');
+
+v = g.test0rint64('1');
+v == 1 || eq_fail('test0rint64', v);
+check_error('test0rint64err');
+
+v = g.test0rbool('true');
+v == 1 || eq_fail('test0rbool', v);
+check_error('test0rboolerr');
+
+v = g.test0rconststring('1');
+v == 'static string' || eq_fail('test0rconststring', v);
+check_error('test0rconststringerr');
+
+v = g.test0rconstoptstring('1');
+v == 'static string' || eq_fail('test0rconstoptstring', v);
+//check_error('test0rconstoptstringerr');
+
+v = g.test0rstring('string');
+v == 'string' || eq_fail('test0rstring', v);
+check_error('test0rstringerr');
+
+v = g.test0rstringlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('test0rstringlist', v.join(' '));
+check_error('test0rstringlisterr');
+
+v = g.test0rstruct('1');
+v.pv_size == 0 || eq_fail('test0rstruct', v);
+check_error('test0rstructerr');
+
+v = g.test0rstructlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i].pv_size != i) eq = false;
+}
+eq || eq_fail('test0rstructlist', v);
+check_error('test0rstructlisterr');
+
+v = g.test0rhashtable('5');
+eq = true;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('test0rhashtable', v);
+check_error('test0rhashtableerr');
+
+v = g.test0rbufferout("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('test0rbufferout', v);
+check_error('test0rbufferouterr');
+
+fail ? 1 : 0;
diff --git a/gobject/run-bindtests b/gobject/run-bindtests
index 3d27c144..48578cf1 100755
--- a/gobject/run-bindtests
+++ b/gobject/run-bindtests
@@ -25,3 +25,4 @@ fi
../run $GJS bindtests.js > bindtests.tmp
diff -u ${srcdir}/../bindtests bindtests.tmp
+../run $GJS bindtests-manual.js 2>/dev/null