File: bindtests-retvalues.js

package info (click to toggle)
libguestfs 1%3A1.40.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,660 kB
  • sloc: ansic: 460,074; ml: 63,059; sh: 14,955; java: 9,512; makefile: 9,133; cs: 6,300; haskell: 5,652; python: 3,856; perl: 3,619; erlang: 2,435; xml: 1,683; ruby: 350; pascal: 255; lex: 135; yacc: 128; cpp: 10
file content (110 lines) | stat: -rw-r--r-- 3,180 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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;