Debian Codegraph @

t/zzHList.t

raw
1 # -*- perl -*-
2 BEGIN { $^W = 1; $| = 1; }
3
4 use strict;
5 use Tk;
6
7 BEGIN {
8 if (!eval q{
9 use Test::More;
10 1;
11 }) {
12 print "1..0 # skip: no Test::More module\n";
13 exit;
14 }
15 }
16
17 plan tests => 32;
18
19 my $mw = Tk::MainWindow->new;
20 eval { $mw->geometry('+10+10'); }; # This works for mwm and interactivePlacement
21
22 my $hlist;
23 {
24 eval { require Tk::HList; };
25 is($@, "", 'Loading Tk::HList');
26 eval { $hlist = $mw->HList(); };
27 is($@, "", 'Creating HList widget');
28 ok( Tk::Exists($hlist) );
29 eval { $hlist->grid; };
30 is($@, "", '$hlist->grid');
31 eval { $hlist->update; };
32 is($@, "", '$hlist->update.');
33
34 $hlist->delete("all");
35 $hlist->add("entry with spaces");
36 my @bbox = $hlist->info('bbox', 'entry with spaces');
37 my @info = $hlist->info('item', @bbox[0, 1]);
38 is($info[0], 'entry with spaces', 'Spaces in entry path');
39 }
40 ##
41 ## With Tk800.004:
42 ## 1) headerSize returns "x y" instead of [x,y].
43 ## 2) Error headerSize err msg for non existant col contains garbage. E.g.
44 ## Column "KC@" does not exist at ...
45 ## 3) infoSelection not defined (test is just a bothering reminder to
46 ## check all other Submethods that should be defined are defined).
47 ## 4) entryconfigure -style contains garbage
48 ##
49 {
50 my $hl = $mw->HList(-header=>1)->grid;
51 $hl->headerCreate(0, -text=>'a heading');
52
53 my @dim;
54 eval { @dim = $hl->headerSize(0); };
55 is($@, '', "headerSize method");
56 is(scalar(@dim), 2, 'headerSize returned a 2 element array: |'.
57 join('|',@dim,'')
58 );
59 eval { $hlist->update; };
60 is($@, "", '$hlist->update.');
61
62 eval { $hl->header('size', 1); }; # does not exist
63 isnt($@, "", "Error for non existent header field");
64 like($@, qr/^Column "1" does not exist/,
65 "Error message matches /^Column \"1\" does not exist/"
66 );
67 eval { $hlist->update; };
68 is($@, "", '$hlist->update.');
69
70 eval { $hl->info('selection'); };
71 is($@, "", "info('selection') method.");
72 eval { $hl->infoSelection; };
73 is($@, "", "infoSelection method.");
74 eval { $hlist->update; };
75 is($@, "", '$hlist->update.');
76
77 $hl->add(1,-text=>'one');
78 my $val1 = ( $hl->entryconfigure(1, '-style') )[4];
79 # comment out the next line and at least I get always a SEGV
80 isnt(defined($val1), "entryconfigure -style is not defined");
81 my $val2 = $hl->entrycget(1, '-style');
82 isnt(defined($val2), "entrycget -style is not defined");
83 # ok($val1, $val2, "entryconfigure and entrycget do not agree");
84
85 my @bbox = $hl->infoBbox(1);
86 is(scalar(@bbox), 4, "\@bbox 4 items");
87 my $bbox = $hl->infoBbox(1);
88 is(ref($bbox), 'ARRAY', "$bbox is an ARRAY");
89 foreach my $a (@bbox)
90 {
91 is($a, shift(@$bbox), "\$bbox values OK");
92 }
93 $hl->destroy;
94 }
95
96 SKIP: {
97 skip("Aborts with Tk804", 1)
98 if $Tk::VERSION <= 804.027;
99
100 my $hl = $mw->HList;
101
102 $hl->add("top", -text => "top");
103 $hl->add("top.item1", -text => "item1");
104 $hl->add("top.item2", -text => "item2");
105
106 $hl->add("top.item3", -at => 0, -text => "item2");
107 $hl->add("top.item4", -before => "top.item1", -text => "item2");
108 $hl->add("top.item5", -after => "top.item1", -text => "item2");
109
110 pass("No abort with -at/-before/-after");
111
112 $hl->destroy;
113 }
114
115 {
116 my $hl = $mw->HList;
117
118 $hl->add("top", -text => "top");
119 $hl->add("top.item1", -text => "item1");
120 $hl->add("top.item2", -text => "item2");
121
122 ok(!$hl->info('hidden', 'top.item1'), "Item initially not hidden");
123 $hl->hide('entry','top.item1');
124 ok($hl->info('hidden', 'top.item1'), "Item now hidden");
125 $hl->show('entry','top.item1');
126 ok(!$hl->info('hidden', 'top.item1'), "Item not hidden again");
127 $hl->hideEntry('top.item1');
128 ok($hl->info('hidden', 'top.item1'), "Undocumented method hideEntry also works");
129
130 $hl->destroy;
131 }
132
133 {
134 my $hl = $mw->HList;
135 $hl->addchild("");
136 pass("addchild with empty string");
137 $hl->destroy;
138 }
139
140 TODO: {
141 todo_skip "Currently dumps core", 1;
142
143 my $hl = $mw->HList;
144 $hl->add(0);
145 eval { $hl->itemCreate(0, 0, -text => "Something", -data => "invalid") };
146 like($@, qr{Bad option `-data' at}, "-data not valid for itemCreate");
147 }
148
149 {
150 my $hl = $mw->HList(-columns => 2);
151 $hl->headerCreate(0, -text => 'h1');
152 is $hl->headerCget(0, '-text'), 'h1', 'headerCget call';
153 eval { $hl->headerCget(1, '-text') };
154 like $@, qr{Column "1" does not have a header}, 'Error message on headerCget call on column without a header';
155 $hl->destroy;
156 }
157
158 1;
159 __END__
160