File: tc_090_retvalues.rb

package info (click to toggle)
libguestfs 1%3A1.54.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 98,892 kB
  • sloc: ansic: 379,443; ml: 38,771; sh: 10,329; java: 9,631; cs: 6,377; haskell: 5,729; makefile: 5,178; python: 3,821; perl: 2,467; erlang: 2,461; ruby: 349; xml: 275; pascal: 257; javascript: 157; cpp: 10
file content (142 lines) | stat: -rw-r--r-- 3,530 bytes parent folder | download
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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 'minitest/autorun'
require 'guestfs'

class Test090RetValues < Minitest::Test
  def test_090_retvalues
    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