1##########################################################################
2# TEPAM - Tcl's Enhanced Procedure and Argument Manager
3##########################################################################
4#
5# adbox_widgets.test:
6# This file is part of the enhanced procedure and argument manager's regression
7# test. It verifies the basic functionalities (create, set, get) of all entry widgets.
8#
9# Copyright (C) 2009, 2010 Andreas Drollinger
10# 
11# RCS: @(#) $Id: adbox_widgets.test,v 1.1 2010/02/11 21:50:55 droll Exp $
12##########################################################################
13# See the file "license.terms" for information on usage and redistribution
14# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15##########################################################################
16
17source [file join \
18   [file dirname [file dirname [file join [pwd] [info script]]]] \
19   devtools testutilities.tcl]
20
21testsNeedTcl     8.3
22testsNeedTcltest 1.0
23
24catch {namespace delete ::tepam}
25testing {
26   useLocal tepam.tcl tepam
27}
28
29package require Tk
30tepam::GuiEnvironmentInit
31
32######## Entry ########
33
34   frame .f
35   array set Option {}
36
37   test tepam-adbox.widg.ent.cr "argument_dialogbox, all widgets: entry - create" \
38      -body {tepam::ad_form(entry) .f create} \
39      -result "*" \
40      -match glob
41
42   set tn 0
43   foreach Data { "This is a text entry" "This is another text" } {
44      incr tn
45
46      test tepam-adbox.widg.ent$tn.st "argument_dialogbox, all widgets: entry $tn - set" \
47         -body "tepam::ad_form(entry) .f set \"$Data\"" \
48         -result "*" \
49         -match glob
50
51      test tepam-adbox.widg.ent$tn.gt "argument_dialogbox, all widgets: entry $tn - get" \
52         -body {tepam::ad_form(entry) .f get} \
53         -result $Data \
54         -match exact
55   }
56
57   destroy .f
58   array unset Option
59
60######## Color ########
61
62   frame .f
63   array set Option {}
64
65   test tepam-adbox.widg.col.cr "argument_dialogbox, all widgets: color - create" \
66      -body {tepam::ad_form(color) .f create} \
67      -result "*" \
68      -match glob
69
70   set tn 0
71   foreach Data {red blue yellow} {
72      incr tn
73
74      test tepam-adbox.widg.col$tn.st "argument_dialogbox, all widgets: color $tn - set" \
75         -body "tepam::ad_form(color) .f set \"$Data\"" \
76         -result "*" \
77         -match glob
78
79      test tepam-adbox.widg.col$tn.gt "argument_dialogbox, all widgets: color $tn - get" \
80         -body {tepam::ad_form(color) .f get} \
81         -result $Data \
82         -match exact
83   }
84
85   destroy .f
86   array unset Option
87
88######## File and Directories ########
89
90   set fd 0
91   foreach FileDir {existingdirectory directory existingfile file} {
92      incr fd
93      frame .f
94      array set Option {}
95
96      test tepam-adbox.widg.fd$fd.cr "argument_dialogbox, all widgets: Files/Directories - create" \
97         -body "tepam::ad_form($FileDir) .f create" \
98         -result "*" \
99         -match glob
100
101      set tn 0
102      foreach Data {my_dir your_directory} {
103         incr tn
104   
105         test tepam-adbox.widg.fd$fd.st$tn "argument_dialogbox, all widgets: Files/Directories $tn - set" \
106            -body "tepam::ad_form($FileDir) .f set \"$Data\"" \
107            -result "*" \
108            -match glob
109   
110         test tepam-adbox.widg.fd$fd.gt$tn "argument_dialogbox, all widgets: Files/Directories $tn - get" \
111            -body "tepam::ad_form($FileDir) .f get" \
112            -result $Data \
113            -match exact
114      }
115
116      destroy .f
117      array unset Option
118   }
119
120######## Combobox ########
121
122   frame .f
123   array set Option {}
124
125   test tepam-adbox.widg.combo.cr "argument_dialogbox, all widgets: Combo box -  create" \
126      -body {
127         tepam::ad_form(combobox) .f create;
128         tepam::ad_form(combobox) .f set_choice {123 234 345 456 567 678 789}
129      } \
130      -result "*" \
131      -match glob
132
133   set tn 0
134   foreach Data {234 456 678} {
135      incr tn
136
137      test tepam-adbox.widg.combo$tn.st "argument_dialogbox, all widgets: Combo box $tn - set" \
138         -body "tepam::ad_form(combobox) .f set \"$Data\"" \
139         -result "*" \
140         -match glob
141
142      test tepam-adbox.widg.combo$tn.oc "argument_dialogbox, all widgets: Combo box $tn - open/close selection" \
143         -body {
144            tepam::ad_form(combobox) .f open_selection;
145            tepam::ad_form(combobox) .f close_selection
146         } \
147         -result "*" \
148         -match glob
149
150      test tepam-adbox.widg.combo$tn.gt "argument_dialogbox, all widgets: Combo box $tn - get" \
151         -body {tepam::ad_form(combobox) .f get} \
152         -result $Data \
153         -match exact
154   }
155
156   destroy .f
157   array unset Option
158
159######## Listbox ########
160
161   set tn 0
162   foreach {ListboxOptions Choices Datas} {
163      "-multiple_selection 0" {123 234 345 456 567 678 789} {234 456 678}
164      "-multiple_selection 1" {123 234 345 456 567 678 789} {234 678}
165      "-multiple_selection 1" {123 234 345 456 567 678 789} {{234 456} {345 678}}
166   } {
167      incr tn
168      frame .f
169      frame .f.f
170      array set Option $ListboxOptions
171      set Framed 0
172
173      test tepam-adbox.widg.lstb$tn.cr "argument_dialogbox, all widgets: Listbox $tn - create" \
174         -body {
175            tepam::ad_form(listbox) .f.f create
176            tepam::ad_form(listbox) .f.f set_choice $Choices
177         } \
178         -result "*" \
179         -match glob
180
181      # Check that the default selected value is the first value in the list
182      test tepam-adbox.widg.lstb$tn.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
183         -body {tepam::ad_form(listbox) .f.f get} \
184         -result 123 \
185         -match exact
186
187      # Perform several set/get operations
188      set sn 0
189      foreach Data $Datas {
190         incr sn
191
192         test tepam-adbox.widg.lstb$tn.st$sn "argument_dialogbox, all widgets: Listbox $tn - set $sn" \
193            -body "tepam::ad_form(listbox) .f.f set \"$Data\"" \
194            -result "*" \
195            -match glob
196
197         test tepam-adbox.widg.lstb$tn.gt$sn "argument_dialogbox, all widgets: Listbox $tn - get $sn" \
198            -body {tepam::ad_form(listbox) .f.f get} \
199            -result $Data \
200            -match exact
201      }
202
203      destroy .f
204      array unset Option
205   }
206
207######## Disjoint listbox ########
208
209   frame .f
210   frame .f.f
211   array set Option {}
212   set Framed 0
213
214   test tepam-adbox.widg.djlb.cr "argument_dialogbox, all widgets: Disjoint listbox -  create" \
215      -body {
216         tepam::ad_form(disjointlistbox) .f.f create;
217         tepam::ad_form(disjointlistbox) .f.f set_choice {123 234 345 456 567 678 789}
218      } \
219      -result "*" \
220      -match glob
221
222   # Check that nothing is selected by default
223   test tepam-adbox.widg.djlb.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
224      -body {tepam::ad_form(disjointlistbox) .f.f get} \
225      -result {} \
226      -match exact
227
228   set tn 0
229   foreach Data {234 {123 234 345 456 567 678 789} {234 456}} {
230      incr tn
231
232      test tepam-adbox.widg.djlb$tn.st "argument_dialogbox, all widgets: Disjoint listbox $tn - set" \
233         -body "tepam::ad_form(disjointlistbox) .f.f set \"$Data\"" \
234         -result "*" \
235         -match glob
236
237      test tepam-adbox.widg.djlb$tn.gt "argument_dialogbox, all widgets: Disjoint listbox $tn - get" \
238         -body {tepam::ad_form(disjointlistbox) .f.f get} \
239         -result $Data \
240         -match exact
241   }
242
243   destroy .f
244   array unset Option
245
246######## Checkbox ########
247
248   frame .f
249   array set Option {}
250   set Framed 0
251
252   test tepam-adbox.widg.chkbx.cr "argument_dialogbox, all widgets: Checkbox -  create" \
253      -body {
254         tepam::ad_form(checkbox) .f create;
255         tepam::ad_form(checkbox) .f set_choice {123 234 345 456 567}
256      } \
257      -result "*" \
258      -match glob
259
260   # Check that nothing is selected by default
261   test tepam-adbox.widg.chkbx.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
262      -body {tepam::ad_form(checkbox) .f get} \
263      -result {} \
264      -match exact
265
266   set tn 0
267   foreach Data {234 {123 234 345 456 567} {234 456}} {
268      incr tn
269
270      test tepam-adbox.widg.chkbx$tn.st "argument_dialogbox, all widgets: Checkbox $tn - set" \
271         -body "tepam::ad_form(checkbox) .f set \"$Data\"" \
272         -result "*" \
273         -match glob
274
275      test tepam-adbox.widg.chkbx$tn.gt "argument_dialogbox, all widgets: Checkbox $tn - get" \
276         -body {tepam::ad_form(checkbox) .f get} \
277         -result $Data \
278         -match exact
279   }
280
281   destroy .f
282   array unset Option
283
284######## Radiobox ########
285
286   frame .f
287   array set Option {}
288   set Framed 0
289
290   test tepam-adbox.widg.rdiobx.cr "argument_dialogbox, all widgets: Radiobox -  create" \
291      -body {
292         tepam::ad_form(radiobox) .f create;
293         tepam::ad_form(radiobox) .f set_choice {123 234 345 456 567}
294      } \
295      -result "*" \
296      -match glob
297
298   # Check that the first item is selected by default
299   test tepam-adbox.widg.rdiobx.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
300      -body {tepam::ad_form(radiobox) .f get} \
301      -result 123 \
302      -match exact
303
304   set tn 0
305   foreach Data {234 456 567} {
306      incr tn
307
308      test tepam-adbox.widg.rdiobx$tn.st "argument_dialogbox, all widgets: Radiobox $tn - set" \
309         -body "tepam::ad_form(radiobox) .f set \"$Data\"" \
310         -result "*" \
311         -match glob
312
313      test tepam-adbox.widg.rdiobx$tn.gt "argument_dialogbox, all widgets: Radiobox $tn - get" \
314         -body {tepam::ad_form(radiobox) .f get} \
315         -result $Data \
316         -match exact
317   }
318
319   destroy .f
320   array unset Option
321
322######## Checkbutton ########
323
324   frame .f
325   array set Option {}
326   set Framed 0
327
328   test tepam-adbox.widg.chkbtn.cr "argument_dialogbox, all widgets: Checkbutton -  create" \
329      -body {
330         tepam::ad_form(checkbutton) .f create;
331      } \
332      -result "*" \
333      -match glob
334
335   # Check that the default value is 0
336   test tepam-adbox.widg.chkbtn.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
337      -body {tepam::ad_form(checkbutton) .f get} \
338      -result 0 \
339      -match exact
340
341   set tn 0
342   foreach Data {0 1} {
343      incr tn
344
345      test tepam-adbox.widg.chkbtn$tn.st "argument_dialogbox, all widgets: Checkbutton $tn - set" \
346         -body "tepam::ad_form(checkbutton) .f set \"$Data\"" \
347         -result "*" \
348         -match glob
349
350      test tepam-adbox.widg.chkbtn$tn.gt "argument_dialogbox, all widgets: Checkbutton $tn - get" \
351         -body {tepam::ad_form(checkbutton) .f get} \
352         -result $Data \
353         -match exact
354   }
355
356   destroy .f
357   array unset Option
358
359#### Font selector ####
360
361# Evaluate the default font name. Use the 'font actual' command to evaluate the real font
362# names (Tk8.5 uses pseudo font names like 'TkDefaultFont').
363set DefaultFontOrig [[label .lfont] cget -font]
364set DefaultFont [list [font actual $DefaultFontOrig -family] \
365                      [expr [font actual $DefaultFontOrig -size]<6 ? 6 : [font actual $DefaultFontOrig -size]]]
366
367   frame .f
368   frame .f.f
369   array set Option {}
370   set Framed 0
371
372   test tepam-adbox.widg.f.font.cr "argument_dialogbox, all widgets: Font -  create" \
373      -body {
374         tepam::ad_form(font) .f.f create;
375      } \
376      -result "*" \
377      -match glob
378
379   test tepam-adbox.widg.f.font.gt "argument_dialogbox, all widgets: Listbox $tn - get" \
380      -body {tepam::ad_form(font) .f.f get} \
381      -result $DefaultFont \
382      -match exact
383
384   set tn 0
385   foreach Data { {Arial 8} {Arial 10 bold} {Courier 12 underline} {Arial 12 italic} {Arial 12 overstrike} } {
386      incr tn
387
388      test tepam-adbox.widg.f.font$tn.st "argument_dialogbox, all widgets: Font $tn - set" \
389         -body "tepam::ad_form(font) .f.f set \"$Data\"" \
390         -result "*" \
391         -match glob
392
393      test tepam-adbox.widg.f.font$tn.gt "argument_dialogbox, all widgets: Font $tn - get" \
394         -body {tepam::ad_form(font) .f.f get} \
395         -result $Data \
396         -match exact
397   }
398
399   destroy .f .lfont
400   array unset Option
401
402
403######## That's all ########
404
405::tcltest::cleanupTests
406return
407
408##########################################################################
409# $RCSfile: adbox_widgets.test,v $ - ($Name:  $)
410# $Id: adbox_widgets.test,v 1.1 2010/02/11 21:50:55 droll Exp $
411# Modifications:
412# $Log: adbox_widgets.test,v $
413# Revision 1.1  2010/02/11 21:50:55  droll
414# TEPAM module checkin
415#
416##########################################################################
417
418