Trying to fix broken timer test with eval
[sdlgit/SDL_perl.git] / t / timerpm.t
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) 2003 Tels
4 # Copyright (C) 2004 David J. Goehrig
5 #
6 # Copyright (C) 2005 David J. Goehrig <dgoehrig\@cpan.org>
7 #
8 # ------------------------------------------------------------------------------
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # Lesser General Public License for more details.
19
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 # ------------------------------------------------------------------------------
25 #
26 # Please feel free to send questions, suggestions or improvements to:
27 #
28 #       David J. Goehrig
29 #       dgoehrig\@cpan.org
30 #
31 #
32 # basic testing of SDL::Timer
33
34 use strict;
35 use SDL;
36 use SDL::Config;
37 use Test::More;
38
39 BEGIN {
40         unshift @INC, 'blib/lib','blib/arch';
41 }
42
43 sub check_fail_timer
44 {       
45         my $ret = 0;
46         eval
47         {
48                 $ret = SDL::Init(SDL_INIT_TIMER);
49                 die "as";
50         };
51         return 1 if (@_ or $ret == -1);
52         return 0;
53 }
54
55 if( check_fail_timer() )
56 {
57          plan( skip_all => "Cannot initialize timer!!" );
58 }
59
60 plan ( tests => 4 );
61
62 use_ok( 'SDL::Timer' ); 
63   
64 can_ok ('SDL::Timer', qw/
65         new run stop
66         /);
67
68 my $fired = 0;
69
70
71 my $timer = new SDL::Timer 
72         sub { $fired++ }, -delay => 30, -times => 1;
73
74 isa_ok($timer, 'SDL::Timer');
75
76 SDL::Delay(100);
77 is ($fired, 1,'timer fired once');