Debian Codegraph @

t/fileselect.t

raw
1 # -*- perl -*-
2 BEGIN { $|=1; $^W=1; }
3 use strict;
4 use Test;
5
6 BEGIN { plan test => 6 };
7
8 eval { require Tk };
9 ok($@, "", "loading Tk module");
10
11 eval { require Tk::FileSelect };
12 ok($@, "", "loading Tk::FileSelect module");
13
14 my $top = new MainWindow;
15 eval { $top->geometry('+10+10'); }; # This works for mwm and interactivePlacement
16 my $f = $top->FileSelect;
17 ok($f->cget('-filter'), "*", "filter not equal *");
18
19 $f = $top->FileSelect(-defaultextension => 'c');
20 ok($f->cget('-filter'), "*.c", "filter/defaultextension mismatch");
21
22 $f = $top->FileSelect(-filter => '*.h');
23 ok($f->cget('-filter'), "*.h", "filter not equal *.h");
24
25 if (eval { require File::Temp; 1 }) {
26 my $tempdir = File::Temp::tempdir(TMPDIR => 1, CLEANUP => 1);
27 my $tempfile = "$tempdir/bla'foo";
28 open FH, "> $tempfile"
29 or die "Cannot create $tempfile: $!";
30 close FH; # just touch
31
32 my $fs = $top->FileSelect(-directory => $tempdir);
33 my $tries = 0;
34 my $slow_machine = 0;
35 my $fs_Accept;
36 $fs_Accept = sub {
37 if ($tries > 10) {
38 warn "Too many retries, maybe machine is too slow...";
39 $slow_machine = 1;
40 $fs->Accept;
41 } else {
42 my $file_list = $fs->Subwidget("file_list");
43 if (!Tk::Exists($file_list) || !$file_list->viewable) {
44 $tries++;
45 $fs->after(100, $fs_Accept);
46 } else {
47 $file_list->selectionSet(0);
48 $fs->Accept;
49 }
50 }
51 };
52 $fs->after(100, $fs_Accept);
53 my $res = $fs->Show;
54 if ($slow_machine) {
55 ok(1);
56 } else {
57 if ($res eq $tempfile) {
58 ok(1);
59 } else {
60 # On MacOSX /tmp is hardlinked to /private/tmp. Check
61 # stat() output to determine if it's the same file.
62 my($dev_ino_tempfile) = join(" ", ((stat($tempfile))[0,1]));
63 my($dev_ino_res) = join(" ", ((stat($res)) [0,1]));
64 ok($dev_ino_res, $dev_ino_tempfile, "device/inode of tempfile and result not the same");
65 }
66 }
67 } else {
68 ok(1); # skipping, not File::Temp
69 }
70
71 1;
72
73 __END__