1# This file is a Tcl script to test out [incr Widgets] Tabset class.
2# It is organized in the standard fashion for Tcl tests with the following
3# notation for test case labels:
4#
5#   1.x - Construction/Destruction tests
6#   2.x - Configuration option tests
7#   3.x - Method tests
8#
9# Copyright (c) 1995 DSC Technologies Corporation
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13#
14# @(#) $Id: tabset.test,v 1.4 2001/08/07 19:56:48 smithc Exp $
15
16package require tcltest
17namespace import -force ::tcltest::*
18
19if [catch {package require Iwidgets 4.0}] {
20  # Let's try modifying the auto_path.  Note that the IWIDGETS_LIBRARY
21  # env var is initialized in the Makefile when doing a 'make test'.
22  # If sourcing this file independently, this variable must be set manually.
23  if ![info exists env(IWIDGETS_LIBRARY)] {
24    error "Unable to locate Iwidgets package.  Set your IWIDGETS_LIBRARY\
25      environment\nvariable to the directory that contains iwidgets.tcl"
26  }
27  lappend auto_path $env(IWIDGETS_LIBRARY)
28  package require Iwidgets 4.0
29}
30
31if {[string compare test [info procs test]] == 1} {
32    source defs
33}
34
35wm geometry . {}
36raise .
37
38set c 1
39set o 1
40set m 1
41
42#
43# Initial construction test
44#
45test Tabset-1.$c {Tabset construction} {
46    iwidgets::Tabset .ts
47    pack .ts 
48    update 
49    .ts add -label one
50    update 
51    .ts add -label two
52    update 
53    .ts add -label three
54    update 
55} {}
56
57incr c
58
59#
60# Option tests which are successful.
61#
62test Tabset-2.$o {configuration option} {
63    llength [.ts configure]
64} {24}
65
66incr o
67
68foreach test {
69	{-disabledforeground #a3a3a3 #a3a3a3 }
70	{-backdrop white white }
71	{-start 4 4 }
72	{-command   }
73	{-font fixed fixed }
74	{-selectbackground #ececec #ececec }
75	{-gap overlap overlap }
76	{-background #CDCDB7B7B5B5 #CDCDB7B7B5B5 }
77	{-state normal normal }
78	{-equaltabs true true }
79	{-bevelamount 0 0 }
80	{-selectforeground black black }
81	{-foreground #000000000000 #000000000000 }
82	{-raiseselect false false }
83	{-padx 4 4 }
84	{-pady 4 4 }
85	{-cursor   }
86	{-margin 5 5 }
87	{-angle 20 20 }
88	{-width 0 0 }
89	{-tabborders true true }
90	{-height 0 0 }
91	{-tabpos s s }
92	} {
93	set option [lindex $test 0]
94	test Tabset-2.$o "configuration options, $option" {
95	    .ts configure $option [lindex $test 1] 
96		lindex [.ts configure $option] 4
97	} [lindex $test 2]
98	update 
99	incr o
100}
101
102#
103# Tabconfigure Option tests which are successful.
104#
105test Tabset-2.$o {tab configuration option} {
106    llength [.ts tabconfigure 0]
107} {22}
108
109# do tabconfigure tests also...
110foreach test {
111	{0 -bevelamount 0 0}
112	{0 -state normal normal}
113	{0 -anchor c c}
114	{0 -image {} {}}
115	{0 -bitmap {} {}}
116	{0 -label Hello Hello}
117	{0 -label "Hello World" "Hello World"}
118	{0 -padx 4 4}
119	{0 -pady 4 4}
120	{0 -selectbackground gray70 gray70}
121	{0 -selectforeground black black}
122	{0 -disabledforeground gray gray}
123	{0 -background white white}
124	{0 -foreground black black}
125	{0 -orient vertical vertical}
126	{0 -invert false false}
127	{0 -angle 20 20}
128	{0 -font "-adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1" "-adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1"}
129	{0 -tabborders true true}
130	} {
131		set index  [lindex $test 0]
132		set option [lindex $test 1]
133		test Tabset-2.$o "tab configuration options, $option" {
134			.ts tabconfigure $index $option [lindex $test 2] 
135			.ts tabcget $index $option
136		} [lindex $test 3]
137	update 
138	incr o
139}
140
141#
142# Option tests which fail and produce errors.
143#
144#foreach test {
145#	{ -OPTION BADVALUE {ERROR_MESSAGE} }
146#	} {
147#	set option [lindex $test 0]
148#        test Tabset-2.$o "configuration options, $option" {
149#	    list [catch {.bb configure $option [lindex $test 1]} msg] $msg
150#	} [list 1 [lindex $test 2]]
151#	incr o
152#}
153
154#
155# Method tests which are successful.
156#
157foreach test {
158    {{.ts add} 
159		{::.ts-tab[0-9]+}}
160    {{.ts add} 
161		{::.ts-tab[0-9]+}}
162    {{.ts add} 
163		{::.ts-tab[0-9]+}}
164    {{.ts add -label Never} 
165		{::.ts-tab[0-9]+}}
166    {{.ts add} 
167		{::.ts-tab[0-9]+}}
168	{{.ts add -label "Hello World" -disabledforeground gray} 
169		{::.ts-tab[0-9]+}}
170    {{.ts index end} 
171		{[0-9]+}}
172    {{.ts index Never} 
173		{[0-9]+}}
174    {{.ts index 0} 
175		{0}}
176    {{.ts select 0} 
177		{0}}
178    {{.ts select select} 
179		{0}}
180    {{.ts select end} 
181		{[0-9]+}}
182    {{.ts select "Hello World"} 
183		{[0-9]+}}
184    {{.ts insert 0} 
185		{::.ts-tab[0-9]+}}
186    {{.ts insert select -label "An Insert"} 
187		{::.ts-tab[0-9]+}}
188    {{.ts insert end -label "Next To Last"} 
189		{::.ts-tab[0-9]+}}
190    {{.ts select 0} 
191		{0}}
192    {{.ts next} 
193		{1}}
194    {{.ts next} 
195		{2}}
196    {{.ts prev} 
197		{1}}
198    {{.ts prev} 
199		{0}}
200    {{.ts delete Never} 
201		{}}
202    {{.ts delete 1 2} 
203		{}}
204    {{.ts delete 0 "Hello World"} 
205		{}}
206    {{.ts add} 
207		{::.ts-tab[0-9]+}}
208    {{.ts add} 
209		{::.ts-tab[0-9]+}}
210    {{.ts add} 
211		{::.ts-tab[0-9]+}}
212    {{.ts add} 
213		{::.ts-tab[0-9]+}}
214    {{.ts delete 0 end} 
215		{}}
216    {{.ts add} 
217		{::.ts-tab[0-9]+}}
218    {{.ts add} 
219		{::.ts-tab[0-9]+}}
220    {{.ts add} 
221		{::.ts-tab[0-9]+}}
222    {{.ts add} 
223		{::.ts-tab[0-9]+}}
224    {{.ts select 2} 
225		{[-]*[0-9]+}}
226    {{.ts delete select end} 
227		{}}
228    {{.ts delete 0 end} 
229		{}}
230    {{.ts add -label "First Page"} 
231		{::.ts-tab[0-9]+}}
232    {{.ts add -label "Second Page"} 
233		{::.ts-tab[0-9]+}}
234    {{.ts add -label "Third Page"} 
235		{::.ts-tab[0-9]+}}
236    {{.ts add -label "Fourth Page"} 
237		{::.ts-tab[0-9]+}}
238    {{.ts add -label "Fifth Page"} 
239		{::.ts-tab[0-9]+}}
240    {{.ts add -label "Sixth Page"} 
241		{::.ts-tab[0-9]+}}
242    {{.ts select "First Page"} 
243		{[-]*[0-9]+}}
244    {{.ts delete select "Second Page"} 
245		{}}
246    {{.ts delete "Third Page" 1} 
247		{}}
248    {{.ts delete "Fifth Page" "Sixth Page"} 
249		{}}
250	} {
251	set method [lindex [lindex $test 0] 1]
252	set method_invoke [lindex $test 0]
253
254	set testContents "set msg {}\n"
255	append testContents \
256	    "set result \[catch \{[lindex $test 0]\} msg\]\n"
257	append testContents \
258	    "lappend result \[regexp -- \{[lindex $test 1]\} \$msg\] \n"
259	append testContents "set result\n"
260	test Tabset-3.$m "\[$method_invoke\]" $testContents \
261		[list 0 1]
262	update 
263	incr m
264}
265
266#
267# Method tests which fail and produce errors
268#
269set m 1
270foreach test {
271		{1 {.ts delete 0 end} {can't delete tab}}
272		{0 {.ts add} {}}
273		{0 {.ts delete 0} {}}
274		{1 {.ts delete 0} {can't delete tabs, no tabs}}
275		{0 {.ts add} {}}
276		{1 {.ts delete 1} {bad value for index1}}
277		{1 {.ts delete select} {bad value for index1}}
278		{0 {.ts delete 0} {}}
279		{0 {.ts add} {}}
280		{1 {.ts delete 0 1} {bad value for index2}}
281		{1 {.ts delete 1 4} {bad value for index1}}
282		{0 {.ts add} {}}
283		{0 {.ts delete 0 1} {}}
284		{0 {.ts add} {}}
285		{1 {.ts delete 0 1 4 5 6} {wrong # args}}
286		{1 {.ts delete} {wrong # args}}
287		{0 {.ts delete 0} {}}
288		{1 {.ts delete 0} {can't delete tabs}}
289		{1 {.ts delete select} {can't delete tabs}}
290		{1 {.ts insert 0} {no tab to insert before, tabset}}
291		{0 {.ts add} {}}
292		{0 {.ts add} {}}
293		{1 {.ts insert 2} {bad value}}
294		{1 {.ts insert -1} {bad option}}
295		{0 {.ts delete 0 end} {}}
296		{1 {.ts next} {can't goto next tab, no tabs in the tabset}}
297		{1 {.ts prev} {can't goto previous tab, no tabs in the tabset}}
298		{1 {.ts select 0} {can't activate a tab, no tabs in the tabset}}
299		{0 {.ts add} {}}
300		{1 {.ts select 1} {bad value}}
301		{0 {.ts delete 0} {}}
302	} {
303		set method_status [lindex $test 0]
304		set method_invoke [lindex $test 1]
305		set method [lindex $method_invoke 1]
306
307		set testContents "set msg {}\n"
308		append testContents \
309		    "set result \[catch \{$method_invoke\} msg\]\n"
310		append testContents \
311		    "lappend result \[regexp -- \{[lindex $test 2]\} \$msg\] \n"
312		append testContents "set result\n"
313		test Tabset-4.$m "\[$method_invoke\]" $testContents \
314			[list $method_status 1]
315	incr m
316	}
317
318# Conclusion of constrcution/destruction tests
319#
320test Tabset-1.$c {Tabset destruction} {
321    destroy .ts
322    update 
323} {}
324
325incr c
326
327test Tabset-1.$c {Tabset construction} {
328    iwidgets::Tabset .ts -width 100 -height 100
329    pack .ts 
330    update 
331    .ts add -label one
332    update 
333    .ts add -label two
334    update 
335    .ts add -label three
336    update 
337} {}
338
339incr c
340
341test Tabset-1.$c {Tabset destruction} {
342	destroy .ts
343    update 
344} {}
345
346::tcltest::cleanupTests
347exit
348