--- 9.t 18 Jan 2008 10:48:13 +1100 1.16 +++ 9.t 27 Aug 2008 10:28:35 +1000 @@ -8,7 +8,7 @@ use warnings; use Config; -print "1..25\n"; +print "1..30\n"; use Glib qw/:constants/; @@ -188,6 +188,64 @@ print "ok 25 # skip\n"; } + +{ + my $pid = fork(); + if (! defined $pid || $pid < 0) { + my $reason; + if (! defined $pid) { + $reason = "error $!"; + } else { + $reason = "perlfork fakery"; + waitpid ($pid, 0); + } + print "ok 26 # skip, no fork: $reason\n"; + print "ok 27 # skip\n"; + print "ok 28 # skip\n"; + print "ok 29 # skip\n"; + print "ok 30 # skip\n"; + goto SKIP_CHILD_TESTS; + } + if ($pid == 0) { + # child + require POSIX; + POSIX::_exit(42); + } + # parent + my $loop = Glib::MainLoop->new; + my $userdata = [ 'hello' ]; + my $id = Glib::Child->watch_add ($pid, sub { die; }, $userdata); + require Scalar::Util; + Scalar::Util::weaken ($userdata); + print '', (defined $userdata ? 'ok' : 'not ok'), + " 26 - child userdata kept alive\n"; + print '', (Glib::Source->remove($id) ? 'ok' : 'not ok'), + " 27 - child source removal\n"; + print '', (! defined $userdata ? 'ok' : 'not ok'), + " 28 - child userdata now gone\n"; + + # No test of $status here, yet, since it may be a raw number on ms-dos, + # instead of a waitpid() style "code*256". Believe there's no + # POSIX::WIFEXITED() etc on dos either to help examining the value. + my $timer_id; + Glib::Child->watch_add ($pid, + sub { + my ($pid, $status, $userdata) = @_; + print '', ($userdata eq 'hello' ? 'ok' : 'not ok'), + " 29 - child callback userdata value\n"; + print "ok 30 - child callback\n"; + $loop->quit; + }, + 'hello'); + $timer_id = Glib::Timeout->add + (30_000, # 30 seconds should be more than enough for child exit + sub { die "Oops, child watch callback didn't run\n"; }); + $loop->run; + Glib::Source->remove ($timer_id); +} +SKIP_CHILD_TESTS: + + __END__ Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the