| 1 |
# -*- perl -*- |
| 2 |
BEGIN { $|=1; $^W=1; } |
| 3 |
use strict; |
| 4 |
|
| 5 |
BEGIN { |
| 6 |
if (!eval q{ |
| 7 |
use Test::More; |
| 8 |
1; |
| 9 |
}) { |
| 10 |
print "1..0 # skip: no Test::More module\n"; |
| 11 |
exit; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
my $interactive_tests = 4; |
| 16 |
plan tests => 8 + $interactive_tests; |
| 17 |
|
| 18 |
if (!defined $ENV{BATCH}) { $ENV{BATCH} = 1 } |
| 19 |
|
| 20 |
use_ok("Tk"); |
| 21 |
use_ok("Tk::DialogBox"); |
| 22 |
|
| 23 |
my $top = new MainWindow; |
| 24 |
$top->Message(-font => "Helvetica 24", |
| 25 |
-text => "This is the Main Window")->pack; |
| 26 |
$top->withdraw unless $^O eq 'MSWin32'; |
| 27 |
eval { $top->geometry('+10+10'); }; # This works for mwm and interactivePlacement |
| 28 |
|
| 29 |
{ |
| 30 |
my $d = $top->DialogBox; |
| 31 |
$d->add("Label", |
| 32 |
-text => "A dialog box with some widgets." . |
| 33 |
(!$ENV{BATCH} ? "\nClick OK to continue." : ""), |
| 34 |
)->pack; |
| 35 |
my $e = $d->add("Entry")->pack; |
| 36 |
$d->configure(-focus => $e, |
| 37 |
-showcommand => sub { |
| 38 |
my $w = shift; |
| 39 |
is($w, $d, "Callback parameter check"); |
| 40 |
$d->update; |
| 41 |
my $fc = $d->focusCurrent || ""; |
| 42 |
ok($fc eq "" || $fc eq $e, |
| 43 |
"Check -focus option (current focus is on `$fc')"); |
| 44 |
my $ok_b = $d->Subwidget("B_OK"); |
| 45 |
ok(Tk::Exists($ok_b), "Check default button"); |
| 46 |
isa_ok($ok_b, "Tk::Button"); |
| 47 |
$ok_b->after(300, sub { $ok_b->invoke }) if $ENV{BATCH}; |
| 48 |
}); |
| 49 |
is($d->Show, "OK", "Expected result"); |
| 50 |
} |
| 51 |
|
| 52 |
{ |
| 53 |
my $d = $top->DialogBox(-buttons => [qw(OK Cancel), "I don't know"], |
| 54 |
-default_button => "Cancel"); |
| 55 |
my $e = $d->add("Label", -text => "Hello, world!\nPlease click the default button (Cancel)")->pack; |
| 56 |
$d->configure(-showcommand => sub { |
| 57 |
$d->update; |
| 58 |
my $d_b = $d->{default_button}; |
| 59 |
$d->after(300, sub { $d_b->invoke }) if $ENV{BATCH}; |
| 60 |
}); |
| 61 |
is($d->Show, "Cancel", "Expected default button result"); |
| 62 |
} |
| 63 |
|
| 64 |
SKIP: { |
| 65 |
skip("Needs non-BATCH mode (env BATCH=0 $^X -Mblib t/dialogbox.t)", $interactive_tests) |
| 66 |
if $ENV{BATCH}; |
| 67 |
|
| 68 |
my $close_text = "Please close the dialog by using the window manager's close button"; |
| 69 |
|
| 70 |
{ |
| 71 |
my $d = $top->DialogBox(-buttons => [qw(OK)]); |
| 72 |
my $e = $d->add("Label", -text => $close_text)->pack; |
| 73 |
is($d->Show, "OK", "One button dialog - only button is cancel_button"); |
| 74 |
} |
| 75 |
|
| 76 |
{ |
| 77 |
my $d = $top->DialogBox(-buttons => [qw(OK Cancel)], -cancel_button => 'Cancel'); |
| 78 |
my $e = $d->add("Label", -text => $close_text)->pack; |
| 79 |
is($d->Show, "Cancel", "Explicite cancel button"); |
| 80 |
} |
| 81 |
|
| 82 |
{ |
| 83 |
my $d = $top->DialogBox(-buttons => [qw(OK Cancel)]); |
| 84 |
my $e = $d->add("Label", -text => $close_text)->pack; |
| 85 |
is($d->Show, undef, "No implicite cancel button with more than one buttons"); |
| 86 |
} |
| 87 |
|
| 88 |
# This should be the last test |
| 89 |
{ |
| 90 |
$top->raise; |
| 91 |
$top->deiconify; |
| 92 |
my $d = $top->DialogBox(-buttons => [qw(Ok Cancel)]); |
| 93 |
my $e = $d->add("Message", -text => "Please close the ***Main window*** using the window manager's close button. The test program must not hang.")->pack; |
| 94 |
ok(!$d->Show, "No hanging program after destroying main window"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
1; |
| 99 |
__END__ |