Debian Codegraph @

t/widget.t

raw
1 BEGIN { $|=1; $^W=1; }
2 use strict;
3
4 BEGIN {
5 if (!eval q{
6 use Test::More;
7 1;
8 }) {
9 print "1..0 # skip: no Test::More module\n";
10 exit;
11 }
12 }
13
14 use Tk;
15
16 BEGIN { plan tests => 19 };
17
18 my $mw = Tk::MainWindow->new;
19 $mw->geometry('+0+0');
20 my $w = $mw->Label(-text=>'a widget but not a Wm')->grid;
21
22 ##
23 ## appname (missing until Tk800 until .004)
24 ##
25 {
26 my $name;
27 eval { $name = $w->appname; };
28 is($@, "", "\$w->appname works");
29 my ($leaf) = $name =~ /^(\w+)/;
30 is( $leaf, 'widget', "Appname matches filename" );
31 is( $mw->name, $name, "\$mw->name is equal to appname");
32 }
33 ##
34 ## scaling (missing until Tk800 until .004)
35 ##
36 {
37 my $scale;
38 eval { $scale = $w->scaling; };
39 is($@, "", "\$w->scaling works");
40 like($scale, qr/^[0-9.]+$/, "Scaling factor is a number: '$scale'" );
41 }
42 ##
43 ## pathname did not work until Tk800.004
44 ##
45 {
46 my $path;
47 my $c = $w->PathName;
48 eval { $path = $mw->pathname($w->id); };
49 is($@, "", "\$mw->pathname works");
50 is( $path, $c, "Pathname and pathname agree" );
51 }
52
53 ##
54 ## Busy/Unbusy
55 ##
56 {
57 my $oldcursor = $mw->cget(-cursor);
58 $mw->update; # make main window viewable, necessary for Busy
59 $mw->Busy;
60 is($mw->cget(-cursor), "watch", "The busy cursor");
61 $mw->after(10);
62 $mw->Unbusy;
63 is($mw->cget(-cursor), $oldcursor, "Old cursor restored");
64 }
65
66 ##
67 ## Busy/Unbusy with recursion
68 ##
69 {
70 my $oldcursor = $mw->cget(-cursor);
71 my $w2 = $mw->Label(-cursor => "cross")->grid;
72 $mw->Busy(-recurse => 1, -cursor => "watch");
73 is($mw->cget(-cursor), "watch", "The busy cursor");
74 is($w2->cget(-cursor), "watch", "Subwidget has also the busy cursor");
75 $mw->after(10);
76 $mw->Unbusy;
77 is($mw->cget(-cursor), $oldcursor, "Old cursor restored");
78 is($w2->cget(-cursor), "cross", "Oldsubwidget cursor also restored");
79 $w2->destroy;
80 }
81
82 ## [rt.cpan.org #32858]
83 {
84 my $top = $mw->Toplevel;
85 $top->geometry('+0+0');
86 $mw->update;
87 $mw->Busy(-recurse => 1);
88 for my $w ($mw, $top) {
89 is(($w->bindtags)[0], 'Busy', "tag 'Busy' set for $w");
90 is($w->cget('-cursor'), 'watch', "cursor 'watch'set for $w");
91 }
92 $mw->Unbusy;
93 $top->destroy;
94 }
95
96 ##
97 ## PathName vs. Widget
98 ##
99 {
100 my $path = $w->PathName;
101 is($mw->Widget($path), $w, "PathName() and Widget()");
102 }
103
104 ## [rt.cpan.org #49515]
105 SKIP: {
106 skip 'Probably does not work on monochrome displays', 1
107 if $w->depth == 1;
108 my $w2 = $mw->Label;
109 $w2->RecolorTree({background => 'green'});
110 is($w2->cget('-background'), 'green', 'RecolorTree was effective');
111 }
112
113 1;
114 __END__