Debian Codegraph @

t/create.t

raw
1 # -*- perl -*-
2 BEGIN { $|=1; $^W=1; }
3 use strict;
4 use Test::More;
5 BEGIN {
6 # Test::More::note not available in older Test::More
7 if (!defined &note) {
8 *note = sub { diag @_ };
9 }
10 }
11 ##
12 ## Almost all widget classes: load module, create, pack, and
13 ## destory an instance.
14 ##
15 ## Menu stuff not tested up to now
16 ##
17
18 use vars '@class';
19
20 BEGIN
21 {
22 @class = (
23 # Tk core widgets
24 qw(
25 Frame
26 Toplevel
27
28 Label
29 Button
30 Checkbutton
31 Radiobutton
32
33 Entry
34 Spinbox
35
36 Listbox
37
38 Scale
39 Scrollbar
40
41 Labelframe
42 Panedwindow
43
44 Canvas
45 Text
46 ),
47 # Tix core widgets
48 qw(
49 HList
50 InputO
51 NoteBook
52 TList
53 TixGrid
54 Optionmenu
55 ),
56 # Tixish composites
57 qw(
58 BrowseEntry
59 Tree
60 DirTree
61 ),
62 # perl/Tk composites
63 ($^O eq 'MSWin32') ? () : qw(ColorEditor),
64 qw(
65 LabEntry
66 LabFrame
67 Optionmenu
68 ROText
69 Table
70 Tiler
71 TextUndo
72 TextEdit
73 Dialog
74 DialogBox
75 FileSelect
76 ),
77 # Tclish composites
78 qw(
79 FBox
80 IconList
81 ),
82 );
83
84 require Tk if ($^O eq 'cygwin');
85 @class = grep(!/InputO/,@class) if ($^O eq 'MSWin32' or
86 ($^O eq 'cygwin' and defined($Tk::platform)
87 and $Tk::platform eq 'MSWin32'));
88
89 plan tests => (15*@class+4);
90
91 };
92
93 if (!defined &diag)
94 {
95 *diag = sub { print "# $_[0]\n" };
96 }
97
98 eval { require Tk; };
99 is($@, "", "loading Tk module");
100
101 my $mw;
102 eval {$mw = Tk::MainWindow->new();};
103 is($@, "", "No error while creating MainWindow");
104 ok(Tk::Exists($mw), "MainWindow creation OK");
105 eval { $mw->geometry('+10+10'); }; # This works for mwm and interactivePlacement
106
107 eval { Tk::MainWindow::Create() };
108 isnt($@, '', "no segfault for Tk::MainWindow::Create without args, but an error message");
109
110 my $w;
111 foreach my $class (@class)
112 {
113 note "Testing $class";
114 undef($w);
115
116 eval "require Tk::$class;";
117 is($@, "", "No error loading Tk::$class");
118 SKIP: {
119 skip "Test::More too old for isa_ok class check", 1
120 if $Test::More::VERSION < 0.88;
121 isa_ok("Tk::$class", 'Tk::Widget');
122 }
123
124 eval { $w = $mw->$class(); };
125 is($@, "", "Can create $class widget");
126 ok(Tk::Exists($w), "$class instance exists");
127
128 SKIP: {
129 skip "Window cannot be created", 6
130 if !Tk::Exists($w);
131
132 is($w->class,$class,"Window class matches");
133
134 if ($w->isa('Tk::Wm'))
135 {
136 # KDE-beta4 wm with policies:
137 # 'interactive placement'
138 # okay with geometry and positionfrom
139 # 'manual placement'
140 # geometry and positionfrom do not help
141 eval { $w->positionfrom('user'); };
142 #eval { $w->geometry('+10+10'); };
143 is ($@, "", 'No problem set postitionform to user');
144
145 eval { $w->Popup; };
146 is ($@, "", "Can Popup a $class widget")
147 }
148 else
149 {
150 pass("dummy for positionfrom test for non-Wm widgets");
151 eval { $w->pack; };
152 is ($@, "", "Can pack a $class widget")
153 }
154 note "$class update";
155 eval { $mw->update; };
156 is ($@, "", "No error during 'update' for $class widget");
157
158 my @dummy;
159 note "$class configure list";
160 eval { @dummy = $w->configure; };
161 is ($@, "", "No error while getting configure as list for $class");
162 my $dummy;
163 note "$class configure scalar";
164 eval { $dummy = $w->configure; };
165 is ($@, "", "No error while getting configure as scalar for $class");
166 is (scalar(@dummy),scalar(@$dummy), "Error: scalar config != list config");
167
168 $@ = "";
169 my %skip = (-class => 1);
170 foreach my $opt ($w->CreateOptions)
171 {
172 $skip{$opt} = 1;
173 }
174 foreach my $opt (@dummy)
175 {
176 my @val = @$opt;
177 if (@val != 2 && !exists($skip{$val[0]}) )
178 {
179 eval { $w->configure($val[0],$val[-1]) };
180 if ($@)
181 {
182 diag "$class @val:$@";
183 last;
184 }
185 }
186 }
187 is($@,"","Re-configure $class");
188
189 note "$class update post-configure";
190 eval { $mw->update; };
191 is ($@, "", "'update' after configure for $class widget");
192
193 note "$class destroy";
194 eval { $w->destroy; };
195 is($@, "", "can destroy $class widget");
196 ok(!Tk::Exists($w), "$class: widget is really destroyed");
197
198 # XXX: destroy-destroy test disabled because nobody vote for this feature
199 # Nick Ing-Simmmons wrote:
200 # The only way to make test pass, is when Tk800 would fail, to specifcally look
201 # and see if method is 'destroy', and ignore it. Can be done but is it worth it?
202 # Note I cannot call tk's internal destroy as I have no way of relating
203 # (now destroy has happened) the object back to interp/MainWindow that it used
204 # to be associated with, and hence cannot create the args I need to pass
205 # to the core.
206
207 # since Tk8.0 a destroy on an already destroyed widget should
208 # not complain
209 #eval { $w->destroy; };
210 #ok($@, "", "Ooops, destroying a destroyed widget should not complain");
211
212 }
213 }
214
215 1;
216 __END__