3
# Create and test the task manager
12
######################################################################
13
# This test requires a DISPLAY to run
15
unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) {
16
plan skip_all => 'Needs DISPLAY';
25
use Padre::Wx::App ();
26
use Padre::Wx::Main ();
27
use Padre::TaskManager ();
28
use Padre::Task::Addition ();
29
use t::lib::Padre::NullWindow ();
31
use constant TIMER_LASTRESORT => Wx::NewId();
33
use_ok('Test::NoWarnings');
37
######################################################################
40
# We will need a running application so the main thread can
41
# receive events thrown from the child thread.
42
my $wxapp = Padre::Wx::App->new;
43
isa_ok( $wxapp, 'Padre::Wx::App' );
45
# We also need a main window of some kind to handle events
46
my $window = t::lib::Padre::NullWindow->new;
47
isa_ok( $window, 't::lib::Padre::NullWindow' );
49
my $manager = Padre::TaskManager->new(
53
isa_ok( $manager, 'Padre::TaskManager' );
55
# Schedule the startup timer
56
Wx::Event::EVT_TIMER( $wxapp, Padre::Wx::Main::TIMER_POSTINIT, \&startup );
57
my $timer1 = Wx::Timer->new( $wxapp, Padre::Wx::Main::TIMER_POSTINIT );
59
# Schedule the failure timeout
60
Wx::Event::EVT_TIMER( $wxapp, TIMER_LASTRESORT, \&timeout );
61
my $timer2 = Wx::Timer->new( $wxapp, TIMER_LASTRESORT );
64
$timer1->Start( 1, 1 );
65
$timer2->Start( 10000, 1 );
71
######################################################################
74
# We start with no threads
75
is( scalar( threads->list ), 0, 'No threads' );
78
# $window->Show(1) if $window;
81
# We end with no threads
82
is( scalar( threads->list ), 0, 'No threads' );
88
######################################################################
93
# Run the startup process
94
ok( $manager->start, '->start ok' );
95
Time::HiRes::sleep(1);
96
is( scalar( threads->list ), 0, 'Three threads exists' );
98
# Create the sample task
99
my $addition = Padre::Task::Addition->new(
103
isa_ok( $addition, 'Padre::Task::Addition' );
105
# Schedule the task (which should trigger it's execution)
106
ok( $manager->schedule($addition), '->schedule ok' );
107
is( $addition->{prepare}, 1, '->{prepare} is false' );
108
is( $addition->{run}, 0, '->{run} is false' );
109
is( $addition->{finish}, 0, '->{finish} is false' );
114
# Run the shutdown process
117
ok( $manager->stop, '->stop ok' );
120
# $window->Show(0) if $window;
121
$wxapp->ExitMainLoop;