ec5cf49fd373ec58ebaf63200d0cb0fb221ba01a
[libguestfs.git] / ruby / tests / tc_rhbz664558c6.rb
1 # libguestfs Ruby bindings -*- ruby -*-
2 # Copyright (C) 2011 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # Test that throwing an exception in a callback doesn't cause
19 # the interpreter to segfault.  See:
20 # https://bugzilla.redhat.com/show_bug.cgi?id=664558#c6
21
22 require 'test/unit'
23 $:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
24 $:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "guestfs"))
25 require 'guestfs'
26
27 class TestLoad < Test::Unit::TestCase
28   def test_rhbz664558c6
29     g = Guestfs::create()
30
31     close_invoked = 0
32     close = Proc.new {| event, event_handle, buf, array |
33       close_invoked += 1
34       # Raising an exception used to cause the interpreter to
35       # segfault.  It should just cause an error message to be
36       # printed on stderr.
37       raise "ignore this error"
38     }
39     g.set_event_callback(close, Guestfs::EVENT_CLOSE)
40
41     # This should call the close callback.
42     g.close()
43
44     if close_invoked != 1
45       raise "close_invoked should be 1"
46     end
47   end
48 end