~ubuntu-branches/ubuntu/saucy/padre/saucy-proposed

« back to all changes in this revision

Viewing changes to t/03-wx.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
 
use strict;
4
 
use warnings;
5
 
use Test::More;
6
 
 
7
 
BEGIN {
8
 
        unless ( $ENV{DISPLAY} or $^O eq 'MSWin32' ) {
9
 
                plan skip_all => 'Needs DISPLAY';
10
 
                exit 0;
11
 
        }
12
 
        if ( $^O eq 'MSWin32' ) {
13
 
                plan skip_all => 'Windows currently has problems with Unicode files';
14
 
                exit(0);
15
 
        }
16
 
 
17
 
        # Ticket #643
18
 
        plan( skip_all => 'Sometimes fails for unknown reasons, skipping for release till fixed' );
19
 
        exit 0;
20
 
}
21
 
 
22
 
use File::Basename qw(basename);
23
 
use File::Copy qw(copy);
24
 
use File::Spec::Functions qw(catfile);
25
 
use Test::NoWarnings;
26
 
use Test::Builder;
27
 
use t::lib::Padre;
28
 
use Cwd;
29
 
use Padre;
30
 
 
31
 
plan tests => 100;
32
 
diag "PADRE_HOME: $ENV{PADRE_HOME}";
33
 
my $home = $ENV{PADRE_HOME};
34
 
copy catfile( 'eg', 'hello_world.pl' ),   catfile( $home, 'hello_world.pl' );
35
 
copy catfile( 'eg', 'cyrillic_test.pl' ), catfile( $home, 'cyrillic_test.pl' );
36
 
copy catfile( 't', 'files', 'one_char.pl' ), catfile( $home, 'one_char.pl' );
37
 
 
38
 
my $padreInstance = Padre->new;
39
 
my $ide           = Padre->ide;
40
 
my $frame         = $ide->wx->main;
41
 
 
42
 
diag "This test script is known to fail sometimes on some operating systems";
43
 
diag "If this happens to you, please report it to the Padre developers";
44
 
diag "and use the force to install Padre anyway.";
45
 
 
46
 
my @events = (
47
 
        {   delay => 1000, # TODO: if we reduce this to 100 or even 500 the test crashes (segfault?) after 2 oks
48
 
                               # this seems to be an issue with Padre or wx beneath but for now we hide it with the larger
49
 
                               # delay
50
 
                code  => sub {
51
 
                        my $main = $ide->wx->main;
52
 
                        my $T    = Test::Builder->new;
53
 
                        SCOPE: {
54
 
                                my @editors = $main->editors;
55
 
                                $T->is_num( scalar(@editors), 1, '1 editor' );
56
 
                        }
57
 
                        $main->setup_editors( catfile( $home, 'hello_world.pl' ) );
58
 
                        SCOPE: {
59
 
                                my @editors = $main->editors;
60
 
 
61
 
                                #$T->todo_skip('close the empty buffer');
62
 
                                $T->is_num( scalar(@editors), 1, '1 editor' );
63
 
                        }
64
 
                },
65
 
        },
66
 
        {   delay => 100,
67
 
                code  => sub {
68
 
                        my $main   = $ide->wx->main;
69
 
                        my $doc    = $main->current->document;
70
 
                        my $editor = $doc->editor;
71
 
                        $editor->SetSelection( 10, 15 );
72
 
                        my $T = Test::Builder->new;
73
 
                        $T->is_eq( $editor->GetSelectedText, '/perl', 'selection' );
74
 
                        $T->is_eq( $main->current->text,     '/perl', 'selected_text' );
75
 
 
76
 
                        $editor->ReplaceSelection('/java');
77
 
                        $editor->SetSelection( 0, 0 );
78
 
                        $T->is_eq( $main->current->text, '', 'no selected_text' );
79
 
 
80
 
                        # Search for 'java'
81
 
                        Padre::DB::History->create(
82
 
                                type => 'search',
83
 
                                name => 'java',
84
 
                        );
85
 
                        $main->find->search;
86
 
 
87
 
                        my ( $start, $end ) = $editor->GetSelection;
88
 
                        $T->is_num( $start, 11, 'start is 11' );
89
 
                        $T->is_num( $end,   15, 'end is 15' );
90
 
 
91
 
                        $T->is_eq( $main->current->text, 'java', 'java selected_text' );
92
 
 
93
 
                        $main->on_save;
94
 
                        my $line = '';
95
 
 
96
 
                        # TODO: better report if file could not be opended
97
 
                        if ( open my $fh, '<', catfile( $home, 'hello_world.pl' ) ) {
98
 
                                $line = <$fh>;
99
 
                                close $fh;
100
 
                        } else {
101
 
                                $T->diag("Could not open hello_world.pl '$!'");
102
 
                        }
103
 
                        $T->is_eq( $line, "#!/usr/bin/java\n", 'file really changed' );
104
 
                        }
105
 
        },
106
 
        {   delay => 200,
107
 
                code  => sub {
108
 
                        my $main = $ide->wx->main;
109
 
                        $main->setup_editors( catfile( $home, 'cyrillic_test.pl' ) );
110
 
 
111
 
                        my $T      = Test::Builder->new;
112
 
                        my $doc    = $main->current->document;
113
 
                        my $editor = $doc->editor;
114
 
 
115
 
                        Padre::DB::History->create(
116
 
                                type => 'search',
117
 
                                name => 'test',
118
 
                        );
119
 
 
120
 
                        SCOPE: {
121
 
                                my @editors = $main->editors;
122
 
                                $T->is_num( scalar(@editors), 2, '2 editors' );
123
 
                        }
124
 
                        SCOPE: {
125
 
                                $main->find->search;
126
 
                                $T->is_eq( $main->current->text, 'test', 'test selected_text' );
127
 
                                my ( $start, $end ) = $editor->GetSelection;
128
 
                                $T->is_num( $start, 56, 'start is 56' );
129
 
                                $T->is_num( $end,   60, 'end is 60' );
130
 
                        }
131
 
                        SCOPE: {
132
 
                                $main->find->search;
133
 
                                $T->is_eq( $main->current->text, 'test', 'selected_text' );
134
 
                                my ( $start, $end ) = $editor->GetSelection;
135
 
                                $T->is_num( $start, 211, 'start is 211' );
136
 
                                $T->is_num( $end,   215, 'end is 215' );
137
 
                        }
138
 
 
139
 
                        $main->close_all( $main->notebook->GetSelection );
140
 
                        SCOPE: {
141
 
                                my @editors = $main->editors;
142
 
                                $T->is_num( scalar(@editors), 1, '1 editor' );
143
 
                                my $doc = $main->current->document;
144
 
                                $T->is_eq( basename( $doc->filename ), 'cyrillic_test.pl', 'filename is cyrillic_test.pl' );
145
 
                        }
146
 
                },
147
 
        },
148
 
        {   delay => 200,
149
 
                code  => sub {
150
 
                        my $main = $ide->wx->main;
151
 
                        my $T    = Test::Builder->new;
152
 
                        $main->close_all;
153
 
                        SCOPE: {
154
 
                                my @editors = $main->editors;
155
 
                                $T->is_num( scalar(@editors), 0, '0 editor' );
156
 
                                my $doc = $main->current->document;
157
 
                                $T->ok( not( defined $doc ), 'no document' );
158
 
                        }
159
 
                },
160
 
        },
161
 
        {   delay => 400,
162
 
                code  => sub {
163
 
                        my $T = Test::Builder->new;
164
 
                        $T->diag("changing locale");
165
 
                        my $main = $ide->wx->main;
166
 
                        $main->change_locale('en');
167
 
                        $main->change_locale('');
168
 
                        $main->change_locale('en');
169
 
                },
170
 
        },
171
 
        {   delay => 200,
172
 
                code  => sub {
173
 
                        my $T = Test::Builder->new;
174
 
                        $T->diag("setting syntax check");
175
 
                        my $main = $ide->wx->main;
176
 
                        $T->diag( "syntaxcheck_panel: " . $main->syntax );
177
 
                        $main->menu->view->{syntaxcheck}->Check(1);
178
 
                        $main->show_syntaxcheck(1);
179
 
                        $T->ok( $main->syntax->isa('Wx::ListView'), 'is a Wx::ListView' );
180
 
                },
181
 
        },
182
 
        {
183
 
 
184
 
                # for now, just check if there are no warnings generated
185
 
                delay => 800,
186
 
                code  => sub {
187
 
                        my $T    = Test::Builder->new;
188
 
                        my $main = $ide->wx->main;
189
 
                        $T->diag("setup editor for one_char.pl");
190
 
                        $main->setup_editors( catfile( $home, 'one_char.pl' ) );
191
 
                        my @editors = $main->editors;
192
 
                        $T->is_num( scalar(@editors), 1, '1 editor' );
193
 
                },
194
 
        },
195
 
        {
196
 
 
197
 
                # for now, just check if there are no warnings generated
198
 
                delay => 1500,
199
 
                code  => sub {
200
 
                        my $T    = Test::Builder->new;
201
 
                        my $main = $ide->wx->main;
202
 
                        $T->diag("setup editor for cyrillic_test.pl");
203
 
                        $main->setup_editors( catfile( $home, 'cyrillic_test.pl' ) );
204
 
                        my @editors = $main->editors;
205
 
                        $T->is_num( scalar(@editors), 2, '2 editor' );
206
 
                },
207
 
        },
208
 
        {   delay => 800,
209
 
                code  => sub {
210
 
                        my $T    = Test::Builder->new;
211
 
                        my $main = $ide->wx->main;
212
 
                        $main->close_all;
213
 
                        $T->diag("create a new editor");
214
 
                        $main->on_new;
215
 
                        my @editors = $main->pages;
216
 
                        $T->is_num( scalar(@editors), 1, 'one new editor' );
217
 
                        my $doc    = $main->current->document;
218
 
                        my $editor = $doc->editor;
219
 
                        SCOPE: {
220
 
 
221
 
                                #one abs path file.
222
 
                                my $path = catfile( $home, 'cyrillic_test.pl' );
223
 
                                $doc->text_set($path);
224
 
                                $editor->SetSelection( 0, length($path) );
225
 
                                $main->on_open_selection;
226
 
                                $T->is_num( scalar( $main->pages ), 2, 'new and abs cyrillic_test open' );
227
 
 
228
 
                        }
229
 
                        $main->close;
230
 
                        $T->is_num( scalar( $main->pages ), 1, 'back to unsaved?' );
231
 
                        SCOPE: {
232
 
 
233
 
                                #put down one filename that is relative to the dir padre was started from
234
 
                                my $path = catfile( './eg/perl5/', 'cyrillic_test.pl' );
235
 
                                $doc->text_set($path);
236
 
                                $editor->SetSelection( 0, length($path) );
237
 
                                $main->on_open_selection;
238
 
                                $T->is_num( scalar( $main->pages ), 2, 'new and relative cyrillic_test open' );
239
 
                        }
240
 
                        $main->close;
241
 
                        $T->is_num( scalar( $main->pages ), 1, 'back to unsaved?' );
242
 
                        SCOPE: {
243
 
 
244
 
                                #put down one filename that is relative to the dir padre was started from
245
 
                                my $path = catfile( './eg/perl5/', 'cyrillic_test.pl' ) . "\n";
246
 
                                $doc->text_set($path);
247
 
                                $editor->SetSelection( 0, length($path) );
248
 
                                $main->on_open_selection;
249
 
                                $T->is_num( scalar( $main->pages ), 2, 'relative cyrillic_test open with additional \n' );
250
 
                        }
251
 
                        $main->close;
252
 
                        $T->is_num( scalar( $main->pages ), 1, 'back to unsaved?' );
253
 
                        SCOPE: {
254
 
 
255
 
                                #put down one filename that is relative to the dir padre was started from
256
 
                                my $path = "\n" . catfile( './eg/perl5/', 'cyrillic_test.pl' ) . "\n";
257
 
                                $doc->text_set($path);
258
 
                                $editor->SetSelection( 0, length($path) );
259
 
                                $main->on_open_selection;
260
 
                                $T->is_num( scalar( $main->pages ), 2, 'relative cyrillic_test open with additional \n' );
261
 
                        }
262
 
                        $main->close;
263
 
                        $T->is_num( scalar( $main->pages ), 1, 'back to unsaved?' );
264
 
                        SCOPE: {
265
 
 
266
 
                                #put down one filename that is relative to the dir padre was started from
267
 
                                #$T->diag(Cwd::cwd());
268
 
                                my $path = "\t   " . catfile( './eg/perl5/', 'cyrillic_test.pl' ) . " \n\t ";
269
 
                                $doc->text_set($path);
270
 
                                $editor->SetSelection( 0, length($path) );
271
 
 
272
 
                                #$T->diag("selected : ".$main->current->text);
273
 
                                $main->on_open_selection;
274
 
                                $T->is_num( scalar( $main->pages ), 2, 'relative cyrillic_test open with additional \n' );
275
 
                        }
276
 
 
277
 
                        #redo above tests from an editor which _does_ have a filename (ie, has been opened or saved, not newly created
278
 
 
279
 
                        #several files
280
 
                        #non .pm file
281
 
                        #abs path
282
 
                        #use line
283
 
                        #require line
284
 
                        #multiple use/require lines
285
 
                        #makefile
286
 
                        #no selection, fill in - not there, popup again with edit and possibly options to choose from
287
 
                        #selection isn't there, but found similar?
288
 
 
289
 
                },
290
 
        },
291
 
        {   delay => 4000,
292
 
                code  => sub {
293
 
                        my $T = Test::Builder->new;
294
 
                        $T->diag("exiting");
295
 
                        $ide->wx->ExitMainLoop;
296
 
                        $ide->wx->main->Destroy;
297
 
                },
298
 
        },
299
 
);
300
 
 
301
 
t::lib::Padre::setup_event( $frame, \@events, 0 );
302
 
 
303
 
$ide->wx->MainLoop;
304
 
 
305
 
ok( 1, 'finished' );
306
 
 
307
 
sub event {
308
 
        my (%args) = @_;
309
 
        return bless \%args, 'Wx::Event';
310
 
}
311
 
 
312
 
package Wx::Event;
313
 
 
314
 
sub IsChecked {
315
 
        $_[0]->{checked};
316
 
}