File: proc_interactive.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (402 lines) | stat: -rw-r--r-- 16,260 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# -*- tcl -*-
##########################################################################
# TEPAM - Tcl's Enhanced Procedure and Argument Manager
##########################################################################
#
# proc_interactive.test: 
# This file is part of the enhanced procedure and argument manager's regression
# test. It validates the interactive procedure calls for the different data and
# widget types.
#
# Copyright (C) 2009, 2010 Andreas Drollinger
# 
# Id: proc_interactive.test
##########################################################################
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
##########################################################################

source [file join \
   [file dirname [file dirname [file join [pwd] [info script]]]] \
   devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 1.0
testsNeed     Tk 8.5

catch {namespace delete ::tepam}
testing {
   useLocal tepam.tcl tepam
}

namespace import tepam::*

######## Check the default values ########

# Evaluate the default font name. Use the 'font actual' command to evaluate the real font
# names (Tk8.5 uses pseudo font names like 'TkDefaultFont').
set DefaultFontOrig [[label .lfont] cget -font]
set DefaultFont [list [font actual $DefaultFontOrig -family] \
                      [expr [font actual $DefaultFontOrig -size]<6 ? 6 : [font actual $DefaultFontOrig -size]]]

   # Procedure declaration
   
      set tepam::interactive_display_format short
      
      procedure AllTypeProcedure1Default {
         -args {
            {-untyped -default UNTYPED}
            {-untyped2 -type "" -default UNTYPED2}
            {-string -type string -default STRING}
            {-integer -type integer -default 1234}
            {-alnum -type alnum -default ALNUM}
            {-alpha -type alpha -default ALPHA}
            {-ascii -type ascii -default ASCII}
            {-control -type control -default "\t"}
            {-boolean -type boolean -default 0}
            {-digit -type digit -default 9876}
            {-double -type double -default 1.234}
            {-graph -type graph -default GRAPH}
            {-lower -type lower -default lower}
            {-print -type print -default PRINT}
            {-punct -type punct -default ..,.}
            {-space -type space -default "   "}
            {-upper -type upper -default UPPER}
            {-wordchar -type wordchar -default WORDCHAR}
            {-xdigit -type xdigit -default 1234ABCD}
            {-color -type color -default blue}
            {-font -type font -default {Arial 13}}
            {-file -type file -default test_file.log}
            {-directory -type directory -default my_dir}

            {-integer2 -type integer -choices {1 2 3} -default 2}
            {-integer3 -type integer -multiple -choices {1 2 3 4 5 6 7 8 9} -default 4}
            {-none1 -type none -default 0}
            {-none2 -type none -default 1}
         }
      } {
         set res "Arguments - "
         append res "untyped:'$untyped' "
         append res "untyped2:'$untyped2' "
         append res "string:'$string' "
         append res "integer:'$integer' "
         append res "alnum:'$alnum' "
         append res "alpha:'$alpha' "
         append res "ascii:'$ascii' "
         append res "control:'$control' "
         append res "boolean:'$boolean' "
         append res "digit:'$digit' "
         append res "double:'$double' "
         append res "graph:'$graph' "
         append res "lower:'$lower' "
         append res "print:'$print' "
         append res "punct:'$punct' "
         append res "space:'$space' "
         append res "upper:'$upper' "
         append res "wordchar:'$wordchar' "
         append res "xdigit:'$xdigit' "
         append res "color:'$color' "
         append res "font:'$font' "
         append res "file:'$file' "
         append res "directory:'$directory' "

         append res "integer2:'$integer2' "
         append res "integer3:'$integer3' "
         append res "none1:'$none1' "
         append res "none2:'$none2' "

         return $res
      }

   # Call the procedure without providing any argument. This creates the reference result:
      set ReferenceDefaultString [AllTypeProcedure1Default]

   # Call the procedure interactively, emulate the activation of the "Cancel" button:
      set tepam::argument_dialogbox(test,status) cancel

      test tepam-proc.int-call-default.cancel "tepam, interactive procedure call - cancel" \
               -body {set InteractiveCancelString [AllTypeProcedure1Default -interactive]} \
               -result "" -output "" -match exact

   # Call the procedure interactively, emulate the activation of the "OK" button:
      set tepam::argument_dialogbox(test,status) ok

      # Call the procedure interactively and check that a result is returned
      test tepam-proc.int-call-default.ok "tepam, interactive procedure call - ok  " \
               -body {set InteractiveDefaultString [AllTypeProcedure1Default -interactive]} \
               -result "Arguments - *" -output "" -match glob

      # Check now all parts of the previous result string

      foreach {Type Default} {
            untyped UNTYPED
            untyped2 UNTYPED2
            string STRING
            integer 1234
            alnum ALNUM
            alpha ALPHA
            ascii ASCII
            control "\t"
            boolean 0
            digit 9876
            double 1.234
            graph GRAPH
            lower lower
            print PRINT
            punct ..,.
            space "   "
            upper UPPER
            wordchar WORDCHAR
            xdigit 1234ABCD
            color blue
            font {Arial 13}
            file test_file.log
            directory my_dir

            integer2 2
            integer3 4
            none1 0
            none2 1
      } {
         test tepam-proc.int-call.default.$Type "tepam, interactive procedure call - $Type" \
                  -body {set InteractiveDefaultString} \
                  -result "* $Type:'$Default' *" -match glob
      }

######## Check each data type individually ########

   # Procedure declaration
   
      set tepam::interactive_display_format short
      
      procedure AllTypeProcedure2 {
         -args {
            {-untyped -optional}
            {-untyped2 -type "" -optional}
            {-string -type string -optional}
            {-integer -type integer -optional}
            {-alnum -type alnum -optional}
            {-alpha -type alpha -optional}
            {-ascii -type ascii -optional}
            {-control -type control -optional}
            {-boolean -type boolean -optional}
            {-digit -type digit -optional}
            {-double -type double -optional}
            {-graph -type graph -optional}
            {-lower -type lower -optional}
            {-print -type print -optional}
            {-punct -type punct -optional}
            {-space -type space -optional}
            {-upper -type upper -optional}
            {-wordchar -type wordchar -optional}
            {-xdigit -type xdigit -optional}
            {-color -type color -optional}
            {-font -type font -optional}
            {-file -type file -optional}
            {-directory -type directory -optional}

            {-integer2 -type integer -choices {1 2 3} -optional}
            {-integer3 -type integer -multiple -choices {1 2 3 4 5 6 7 8 9} -optional}
            {-none -type none -optional}
         }
      } {
         set res ""
         catch {append res " untyped:'$untyped'"}
         catch {append res " untyped2:'$untyped2'"}
         catch {append res " string:'$string'"}
         catch {append res " integer:'$integer'"}
         catch {append res " alnum:'$alnum'"}
         catch {append res " alpha:'$alpha'"}
         catch {append res " ascii:'$ascii'"}
         catch {append res " control:'$control'"}
         catch {append res " boolean:'$boolean'"}
         catch {append res " digit:'$digit'"}
         catch {append res " double:'$double'"}
         catch {append res " graph:'$graph'"}
         catch {append res " lower:'$lower'"}
         catch {append res " print:'$print'"}
         catch {append res " punct:'$punct'"}
         catch {append res " space:'$space'"}
         catch {append res " upper:'$upper'"}
         catch {append res " wordchar:'$wordchar'"}
         catch {append res " xdigit:'$xdigit'"}
         catch {append res " color:'$color'"}
         catch {append res " file:'$file'"}
         catch {append res " directory:'$directory'"}

         catch {append res " integer3:'$integer3'"}

         catch {append res " font:'$font'"}
         catch {append res " integer2:'$integer2'"}
         catch {append res " none:'$none'"}

         return [string range $res 1 end]
      }

   # Call the procedure interactively, emulate the activation of the "Cancel" button:
      set tepam::argument_dialogbox(test,status) cancel

      test tepam-proc.int-call.cancel "tepam, interactive procedure call - cancel" \
               -body {set InteractiveCancelString [AllTypeProcedure2 -interactive]} \
               -result "" -output "" -match exact

   # Call the procedure interactively, emulate the activation of the "OK" button:
      set tepam::argument_dialogbox(test,status) ok

      # Call the procedure interactively and check that an empty result is returned
      test tepam-proc.int-call.ok "tepam, interactive procedure call - ok" \
               -body {AllTypeProcedure2 -interactive} \
               -result "font:'$DefaultFont' integer2:'1' none:'0'" -output "" -match exact

      # Check now all parts of the previous result string

      set ArgPos 2
      foreach {Type Value} {
            untyped UNTYPED
            untyped2 UNTYPED2
            string STRING
            integer 1234
            alnum ALNUM
            alpha ALPHA
            ascii ASCII
            control "\t"
            boolean 0
            digit 9876
            double 1.234
            graph GRAPH
            lower lower
            print PRINT
            punct ..,.
            space "   "
            upper UPPER
            wordchar WORDCHAR
            xdigit 1234ABCD
            color blue
            font {Arial 13}
            file test_file.log
            directory my_dir

            integer2 2
            integer3 4
            none 1
      } {
         if {$Type=="integer2"} {
            set EntryWidget "radiobox"
         } elseif {$Type=="integer3"} {
            set EntryWidget "disjointlistbox"
         } elseif {$Type=="none"} {
            set EntryWidget "checkbutton"
         } elseif {[info procs ::tepam::ad_form($Type)]!=""} {
            set EntryWidget $Type
         } else {
            set EntryWidget "entry"
         }

         switch $Type {
            "font" {set Result "$Type:'$Value' integer2:'1' none:'0'"}
            "integer2" {set Result "font:'$DefaultFont' $Type:'$Value' none:'0'"}
            "none" {set Result "font:'$DefaultFont' integer2:'1' $Type:'$Value'"}
            default {set Result "$Type:'$Value' font:'$DefaultFont' integer2:'1' none:'0'"}
         }
         
         # Change the value and check that this value is returned:
         set tepam::argument_dialogbox(test,script) "ad_form($EntryWidget) \$WChild($ArgPos).f set \"$Value\""
         set tepam::argument_dialogbox(test,status) ok
         catch {array unset ::tepam::last_parameters}

         test tepam-proc.int-call.$Type "tepam, interactive procedure call - $Type" \
                  -body {AllTypeProcedure2 -interactive} \
                  -result $Result -output "" -match exact

#         # Call the procedure again interactively, but keep the previous values:
#         set tepam::argument_dialogbox(test,script) ""
#         set tepam::argument_dialogbox(test,status) ok

#         test tepam-proc.int-recall.$Type "tepam, interactive procedure recall - $Type" \
#                  -body {AllTypeProcedure2 -interactive} \
#                  -result $Result -output "" -match exact

         incr ArgPos
      }

######## Check each entry widget individually with and without default value ########

   foreach {name       wtype       default      setvalue    getvalue    procargs} {
            entry0     entry       {}           {"abcd"}    {abcd}      {}
            entry1     entry       {123}        {"abcd"}    {abcd}      {-default 123}

            checkbx0   checkbox    {}           {uline}     {uline}     {-multiple -choices {bold ital uline}}
            checkbx1   checkbox    {ital}       {uline}     {uline}     {-multiple -choices {bold ital uline} -default ital}
            checkbx2   checkbox    {ital uline} {uline}     {uline}     {-multiple -choices {bold ital uline} -default {ital uline}}

            radiobx0   radiobox    {bold}       {uline}     {uline}     {-choices {bold ital uline}}
            radiobx1   radiobox    {ital}       {uline}     {uline}     {-choices {bold ital uline} -default ital}

            chkbttn0   checkbutton {0}          {1}         {1}         {-type none}
            chkbttn1   checkbutton {1}          {0}         {0}         {-type none -default 1}

            listbx0    listbox     {1}          {4}         {4}         {-choices {1 2 3 4 5 6 7 8}}
            listbx1    listbox     {5}          {4}         {4}         {-choices {1 2 3 4 5 6 7 8} -default 5}

            djlistbx0  disjointlistbox {}       "{4 6 8}"   {4 6 8}     {-multiple -choices {1 2 3 4 5 6 7 8}}
            djlistbx0  disjointlistbox {2 3}    "{4 6 8}"   {4 6 8}     {-multiple -choices {1 2 3 4 5 6 7 8} -default {2 3}}

            file1      file        {b.log}      {a.log}     {a.log}     {-type file -default b.log}
            dir1       directory   {mydir}      {yourdir}   {yourdir}   {-type directory -default mydir}
            color1     color       {red}        {blue}      {blue}      {-type color -default red}
            font1      font        {Courier 10} "{Arial 12}" {Arial 12} {-type font -default {Courier 10}}
   } {

      # Procedure declaration
         set tepam::interactive_display_format short

         procedure test_proc__$name "-args \{ \{par $procargs\} \}" {
            return "$par"
         }

      # Accept just the default values
         set tepam::argument_dialogbox(test,script) ""
         set tepam::argument_dialogbox(test,status) ok
         catch {array unset ::tepam::last_parameters}

         test tepam-proc.int-call.$name.default "tepam, interactive procedure call - $name default" \
                  -body {test_proc__$name -interactive} \
                  -result "$default" -output "" -match exact

      # Change the values and check that this value is returned:
         set tepam::argument_dialogbox(test,script)    "ad_form($wtype) \$WChild(2).f set $setvalue; "
         set tepam::argument_dialogbox(test,status) ok

         test tepam-proc.int-call.$name.change "tepam, interactive procedure call - $name change" \
                  -body {test_proc__$name -interactive} \
                  -result "$getvalue" -output "" -match exact

      # Call the procedure again interactively, but keep the previous values:
         set tepam::argument_dialogbox(test,script) ""
         set tepam::argument_dialogbox(test,status) ok

         test tepam-proc.int-call.$name.ok "tepam, interactive procedure call - $name OK" \
                  -body {test_proc__$name -interactive} \
                  -result "$getvalue" -output "" -match exact
   }

######## That's all ########

destroy .lfont; # Remove again the label widget to evaluate the default font
::tcltest::cleanupTests
return

##########################################################################
# Id: proc_interactive.test
# Modifications:
#
# Revision 1.2  2011/11/09 05:43:30  andreas_kupries
#
#  * adbox_all.test: [Bug 3422990]: Fixed these test files to
#  * adbox_widgets.test: properly register their need for Tk
#  * proc_interactive.test: and not execute without it.
#
# Revision 1.1  2010/02/11 21:50:55  droll
# * TEPAM module checkin
##########################################################################