~ubuntu-branches/ubuntu/quantal/padre/quantal

« back to all changes in this revision

Viewing changes to t/29_task_nothreads.t

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont, gregor herrmann, Dominique Dumont
  • Date: 2012-01-04 12:04:20 UTC
  • mfrom: (1.3.3)
  • Revision ID: package-import@ubuntu.com-20120104120420-i5oybqwf91m1d3il
Tags: 0.92.ds1-1
[ gregor herrmann ]
* Remove debian/source/local-options; abort-on-upstream-changes
  and unapply-patches are default in dpkg-source since 1.16.1.
* Swap order of alternative (build) dependencies after the perl
  5.14 transition.

[ Dominique Dumont ]
* Imported Upstream version 0.92.ds1
* removed fix-spelling patch (applied upstream)
* lintian-override: use wildcard to avoid listing a gazillion files
* updated size of some 'not-real-man-page' entries
* rules: remove dekstop cruft (replaced by a file provided in debian
  directory)
* control: removed Breaks statement. Add /me to uploaders. Updated
  dependencies
* rules: make sure that non-DFSG file (i.e. the cute butterfly, sigh)
  is not distributed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Create and test the task manager
 
4
 
 
5
use strict;
 
6
use warnings;
 
7
use Test::More;
 
8
use Storable    ();
 
9
use Time::HiRes ();
 
10
 
 
11
 
 
12
######################################################################
 
13
# This test requires a DISPLAY to run
 
14
BEGIN {
 
15
        unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) {
 
16
                plan skip_all => 'Needs DISPLAY';
 
17
                exit 0;
 
18
        }
 
19
 
 
20
        plan tests => 15;
 
21
}
 
22
 
 
23
use Padre::Logger;
 
24
use Padre::Wx                 ();
 
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 ();
 
30
 
 
31
use constant TIMER_LASTRESORT => Wx::NewId();
 
32
 
 
33
use_ok('Test::NoWarnings');
 
34
 
 
35
 
 
36
 
 
37
######################################################################
 
38
# Main Test Sequence
 
39
 
 
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' );
 
44
 
 
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' );
 
48
 
 
49
my $manager = Padre::TaskManager->new(
 
50
        threads => 0,
 
51
        conduit => $window,
 
52
);
 
53
isa_ok( $manager, 'Padre::TaskManager' );
 
54
 
 
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 );
 
58
 
 
59
# Schedule the failure timeout
 
60
Wx::Event::EVT_TIMER( $wxapp, TIMER_LASTRESORT, \&timeout );
 
61
my $timer2 = Wx::Timer->new( $wxapp, TIMER_LASTRESORT );
 
62
 
 
63
# Start the timers
 
64
$timer1->Start( 1,     1 );
 
65
$timer2->Start( 10000, 1 );
 
66
 
 
67
 
 
68
 
 
69
 
 
70
 
 
71
######################################################################
 
72
# Main Process
 
73
 
 
74
# We start with no threads
 
75
is( scalar( threads->list ), 0, 'No threads' );
 
76
 
 
77
# Enter the wx loop
 
78
# $window->Show(1) if $window;
 
79
$wxapp->MainLoop;
 
80
 
 
81
# We end with no threads
 
82
is( scalar( threads->list ), 0, 'No threads' );
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
######################################################################
 
89
# Basic Creation
 
90
 
 
91
sub startup {
 
92
 
 
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' );
 
97
 
 
98
        # Create the sample task
 
99
        my $addition = Padre::Task::Addition->new(
 
100
                x => 2,
 
101
                y => 3,
 
102
        );
 
103
        isa_ok( $addition, 'Padre::Task::Addition' );
 
104
 
 
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' );
 
110
}
 
111
 
 
112
sub timeout {
 
113
 
 
114
        # Run the shutdown process
 
115
        $timer1 = undef;
 
116
        $timer2 = undef;
 
117
        ok( $manager->stop, '->stop ok' );
 
118
        sleep(1);
 
119
 
 
120
        # $window->Show(0) if $window;
 
121
        $wxapp->ExitMainLoop;
 
122
}