1 # libguestfs Perl bindings -*- perl -*-
2 # Copyright (C) 2011 Red Hat Inc.
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.
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.
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.
20 use Test::More tests => 7;
24 my $h = Sys::Guestfs->new ();
33 chomp $buf if $ev == $Sys::Guestfs::EVENT_APPLIANCE;
35 # We don't get to see this output because it is eaten up by the
36 # test harness, but generate it anyway.
37 printf("perl event logged: event=0x%x eh=%d buf='%s' array=[%s]\n",
38 $ev, $eh, $buf, join (", ", @$array));
41 my $close_invoked = 0;
48 # Register an event callback for all log messages.
49 my $events = $Sys::Guestfs::EVENT_APPLIANCE | $Sys::Guestfs::EVENT_LIBRARY |
50 $Sys::Guestfs::EVENT_TRACE;
52 $eh = $h->set_event_callback (\&log_callback, $events);
55 # Check that the close event is invoked.
56 $h->set_event_callback (\&close_callback, $Sys::Guestfs::EVENT_CLOSE);
59 # Now make sure we see some messages.
65 $h->add_drive_ro ("/dev/null");
69 # Close the handle. The close callback should be invoked.
70 ok ($close_invoked == 0);
72 ok ($close_invoked == 1);