Debian Codegraph @

t/wm-time.t

raw
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3
4
5 use strict;
6 use FindBin;
7 use lib "$FindBin::RealBin";
8
9 use Tk;
10 use Test::More;
11
12 use TkTest qw(wm_info);
13
14 # Win32 gets one <visibility> event on toplevel and one on content (as expected)
15 # UNIX/X is more complex, as windows overlap (deliberately)
16 our $tests = 6;
17 our $expect = 0;
18 plan 'no_plan'; # $tests for fast connections, $tests-1 for slow connections
19
20 my $mw = new MainWindow;
21
22 my %wm_info = wm_info($mw);
23 my $wm_name = $wm_info{name};
24 $wm_name = '' unless defined $wm_name;
25
26 my $initial_ok_delay = 0.4;
27 # GNOME Shell is sometimes slow
28 my $ok_delay = $wm_name eq 'GNOME Shell' ? 1.0 : 0.5;
29
30 my $event = '<Map>';
31 my $why;
32 my $start;
33 my $skip_slow_connection;
34
35 sub begin
36 {
37 $start = Tk::timeofday();
38 $why = shift;
39 $expect = shift;
40 diag "Start $why $expect";
41 }
42
43 # First setup timers to kill the script in case of timeouts
44 $mw->after(5*1000, sub { diag "This test script takes longer than usual... it will maybe be killed in some seconds." });
45 $mw->after(30*1000, sub { diag "Killing main window."; $mw->destroy });
46
47 my $l = $mw->Label(-text => 'Content')->pack;
48 #$l->bind($event,[\&mapped,"update"]);
49 $mw->bind($event,[\&mapped,"initial"]);
50 $mw->geometry("+0+0");
51 begin('update',2);
52 $mw->update;
53
54 local $TODO = "Ignore test results because of slow connection" if $skip_slow_connection;
55
56 my $t = $mw->Toplevel(-width => 100, -height => 100);
57 $t->geometry("-0+0");
58 my $l2 = $t->Label(-text => 'Content')->pack;
59 $t->bind($event,[\&mapped,"Popup"]);
60 #$l2->bind($event,[\&mapped,"Popup"]);
61 begin('Popup',2);
62 $t->Popup(-popover => $mw);
63 $t->update;
64 begin('withdraw',0);
65 $t->withdraw;
66 begin('Popup Again',2);
67 $t->Popup(-popover => $mw);
68
69 $mw->after(500, sub { begin('destroy',0); $mw->destroy });
70
71 MainLoop;
72
73
74 sub mapped
75 {
76 my ($w, $state) = @_;
77 my $now = Tk::timeofday();
78 my $delay = $now - $start;
79 diag sprintf "%s $why %.3g $expect\n",$w->PathName,$delay;
80 if ($state eq 'initial' && $delay > $initial_ok_delay)
81 {
82 $skip_slow_connection = 1;
83 return;
84 }
85 if ($expect-- > 0)
86 {
87 cmp_ok($delay, "<", $ok_delay, $why);
88 }
89 }
90
91
92
93
94