Debian Codegraph @

t/zzScrolled.t

raw
1 # -*- perl -*-
2 BEGIN { $|=1; $^W=1; }
3 use strict;
4 use Tk;
5
6 BEGIN {
7 if (!eval q{
8 use Test::More;
9 1;
10 }) {
11 print "# tests only work with installed Test::More module\n";
12 print "1..1\n";
13 print "ok 1\n";
14 exit;
15 }
16 }
17
18 BEGIN { plan tests => 94};
19
20 my $mw = Tk::MainWindow->new;
21 eval { $mw->geometry('+10+10'); }; # This works for mwm and interactivePlacement
22
23 my $scrl;
24 my $text;
25 {
26 eval { require Tk::Text; };
27 is($@, "", "loading Tk::Text");
28 eval { $scrl = $mw->Scrolled('Text', -scrollbars=>'sw', -setgrid=>1); };
29 is($@, "", "creating Scrolled('Text')");
30 ok( Tk::Exists($scrl) );
31 eval { $scrl->grid(-sticky => 'nw'); };
32 is($@, "", 'managing Scrolled Text with grid');
33 eval { $scrl->update; };
34 is($@, "", 'update');
35 eval { $text = $scrl->Subwidget('text'); };
36 is($@, "", 'get subwidget text');
37 }
38 ##
39 ## -fg/-foreground was not propagated to Text widget until
40 ## and including Tk800.003
41 ##
42 {
43 my ($oldcol, $txtcol);
44 my $newcol = 'yellow';
45
46 for my $opt ( qw(-fg -foreground -bg -background) )
47 {
48 eval { $oldcol = $scrl->cget($opt); };
49 is($@, "", "cget $opt");
50
51 isnt($oldcol, $newcol, "colors aren't already the same $oldcol=$newcol");
52
53 ## Set
54 eval { $scrl->configure($opt=>$newcol); };
55 is($@, "", "configure $opt => $newcol");
56 eval { $txtcol = $text->cget($opt); };
57 is($@, "", "text cget $opt");
58 is($txtcol, $newcol, "$opt propagated to Text subwidget");
59 $mw->update;
60
61 ## ReSet
62 eval { $scrl->configure($opt=>$oldcol); };
63 is($@, "", "Reset: configure $opt => $oldcol");
64 eval { $txtcol = $scrl->cget($opt); };
65 is($@, "", "Reset: text cget $opt");
66 is($txtcol, $oldcol, "Reset scrolled $opt color");
67 $mw->update;
68 }
69 }
70 ##
71 ## Scrolled suppress size changes up to and including at least Tk800.003
72 ## and including Tk800.004. config/cget are okay but geometry uncovers it.
73 ##
74 {
75 my ($oldsize, $newsize, $oldgeo, $newgeo);
76
77 for my $opt (qw(-height -width))
78 {
79 for my $chg (qw(-5 5))
80 {
81 eval { $oldsize = $scrl->cget($opt); };
82 is($@, "", "Sizechk: cget $opt");
83 eval { $oldgeo = $scrl->geometry; };
84 is($@, "", "Sizechk: geometry $opt");
85
86 ## Set
87 eval { $scrl->configure($opt=>($oldsize+$chg)); };
88 is($@, "", "configure $opt => $oldsize + $chg");
89 eval { $mw->update; };
90 is($@, "", "Sizechg: Error update configure $opt");
91 eval { $newsize = $text->cget($opt); };
92 is($@, "", "Sizechg: cget $opt");
93 is($newsize, $oldsize+$chg, "No size change.");
94
95 # check if geometry has changed
96 eval { $newgeo = $scrl->geometry; };
97 is($@, "", "Sizechk: new geometry $opt");
98 is($newgeo, $oldgeo, "Sizechk: geometry is the same " .
99 "($newgeo) for $opt => $oldsize+($chg)"
100 );
101
102 ## ReSet
103 eval { $scrl->configure($opt=>$oldsize); };
104 is($@, "", "Reset size: configure $opt => $oldsize");
105 eval { $mw->update; };
106 eval { $newsize = $text->cget($opt); };
107 is($@, "", "Reset size: text cget $opt");
108 is($newsize, $oldsize, "Reset size: scrolled $opt ");
109 is($@, "", "Sizechg: no error reset update configure $opt");
110 eval { $newgeo = $scrl->geometry; };
111 is($@, "", "Sizechk: reset geometry $opt");
112
113 local $TODO = "Next one often fails - window stays same size but moves";
114 # e.g. expect 589x341+0+32 get 589x341+17+32
115 # tried changing -sticky above as a fix?
116 # Only seen on metacity, but not fvwm2 or twm
117 is($newgeo, $oldgeo, "Sizechk: geometry has changed not reset" .
118 " for $opt => $oldsize+($chg)"
119 );
120 }
121 }
122 }
123
124 1;
125 __END__