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