OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [tests/] [general/] [dirbox.tcl] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# dirbox.tcl --
2
#
3
#       Tests the DirSelectBox and DirSelectDialog widgets.
4
#
5
# Copyright (c) 1996, Expert Interface Technologies
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
 
11
proc About {} {
12
    return "Testing the DirSelectBox and DirSelectDialog widgets."
13
}
14
 
15
# Try to configure the directory of a widget and see if it satisfy all
16
# the requirements:
17
#
18
#       1: Should return error for non-existant directory, preserving
19
#          the old directory
20
#
21
#       2: When given a non-normalized path, it should normalize it.
22
#
23
proc TestConfigDirectory {class spec pack} {
24
    global errorInfo
25
 
26
    set w .w
27
 
28
    if [winfo exists $w] {
29
        destroy $w
30
    }
31
 
32
    TestBlock config-dir-1.1 "Simple creating of $class" {
33
        # Creation without the spec. The default value should be normalized
34
        #
35
 
36
        # The default value should always be an absolute path
37
        #
38
        $class .w
39
        set value [$w cget $spec]
40
        Assert {[tixFSIsNorm_os $value]} 0 cont
41
    }
42
    catch {
43
        destroy .w
44
    }
45
 
46
    TestBlock config-dir-1.2 "Creation with arbitrary (perhaps invalid) path" {
47
        foreach item [GetCases_FsNormDir] {
48
            if [info exists errorInfo] {
49
                set errorInfo ""
50
            }
51
 
52
            set text    [lindex $item 0]
53
            set want    [lindex $item 1]
54
            set wanterr [lindex $item 2]
55
 
56
            set err [catch {
57
                set w [$class .w $spec $text]
58
                set got [$w cget -value]
59
            }]
60
            Assert {$err == $wanterr}
61
            if {!$err} {
62
                set want [tixFSDisplayName $want]
63
                Assert {[tixStrEq $want $got]}
64
            }
65
 
66
            catch {
67
                destroy .w
68
            }
69
        }
70
    }
71
 
72
    catch {
73
        destroy .w
74
    }
75
 
76
    TestBlock config-dir-1.2 "Config with arbitrary (perhaps invalid) path" {
77
        set w [$class .w]
78
 
79
        foreach item [GetCases_FsNormDir] {
80
            if [info exists errorInfo] {
81
                set errorInfo ""
82
            }
83
 
84
            set text    [lindex $item 0]
85
            set want    [lindex $item 1]
86
            set wanterr [lindex $item 2]
87
 
88
            set err [catch {
89
                $w config $spec $text
90
                set got [$w cget -value]
91
            }]
92
            Assert {$err == $wanterr}
93
 
94
            if $err {
95
                # Should hold the previous -value
96
                #
97
                set value [$w cget $spec]
98
                Assert {[tixFSIsNorm_os $value]} 0 cont
99
            } else {
100
                set value [$w cget $spec]
101
                Assert {[tixFSIsNorm_os $value]} 0 cont
102
 
103
                set want [tixFSDisplayName $want]
104
                Assert {[tixStrEq $want $got]}
105
            }
106
 
107
            if $pack {
108
                pack $w -expand yes -fill both -padx 10 -pady 10
109
                update idletasks
110
            }
111
        }
112
    }
113
 
114
    catch {
115
        destroy $w
116
    }
117
}
118
 
119
proc TestRand {max} {
120
    global testRandSeed
121
 
122
    if ![info exists testRandSeed] {
123
        set testRandSeed [expr [lindex [time {cd [pwd]}] 0] * 47 + 147]
124
    }
125
 
126
    set x [expr ($testRandSeed + 47) * [lindex [time {cd [pwd]}] 0]]
127
    set x [expr $x + 7 * $max]
128
    set testRandSeed [expr ($x % $max) + $max]
129
 
130
    return [expr $testRandSeed % $max]
131
}
132
 
133
# TestHListWildClick --
134
#
135
#       Randomly click around an hlist widget
136
#
137
# Args:
138
#       hlist:widget    The HList widget.
139
#       mode:           Either "single" or "double", indicating which type
140
#                       of mouse click is desired.
141
#       cmd:            Command to call after each click.
142
#
143
proc TestHListWildClick {hlist mode cmd} {
144
    # The percentage chance that we sould traverse to a child node
145
    #
146
    set chance 40
147
 
148
    for {set x 0} {$x < 10} {incr x} {
149
        set node [$hlist info children ""]
150
        if [tixStrEq $node ""] {
151
            return
152
        }
153
 
154
        while 1 {
155
            set ran [TestRand 100]
156
            if {$ran >= $chance} {
157
                break
158
            }
159
            set children [$hlist info children $node]
160
            if [tixStrEq $children ""] {
161
                break
162
            }
163
            set node [lindex $children [expr $ran % [llength $children]]]
164
        }
165
 
166
        TestBlock wild-click-1.1 "clicking \"$node\" of HList" {
167
            if {![regexp -nocase alex [$hlist info data $node]]} {
168
                #
169
                # dirty fix: "alex" may be an AFS mounted file. Reading this
170
                # directory may start an FTP session, which may be slow like
171
                # hell
172
                #
173
                ClickHListEntry $hlist $node $mode
174
                eval $cmd [list $node]
175
            }
176
        }
177
    }
178
}
179
 
180
 
181
proc DirboxTest_Cmd {args} {
182
    global dirboxTest_selected
183
 
184
    set dirboxTest_selected [tixEvent value]
185
}
186
 
187
proc DirboxTest_Compare {isDirBox w h node} {
188
    global dirboxTest_selected
189
 
190
    set selFile [$h info data $node]
191
 
192
    Assert {[tixStrEq "$dirboxTest_selected" "$selFile"]}
193
    set dirboxTest_selected ""
194
 
195
    if {$isDirBox} {
196
        set entry [$w subwidget dircbx subwidget combo subwidget entry]
197
        set entText [$entry get]
198
        Assert {[tixStrEq "$entText" "$selFile"]}
199
    }
200
}
201
 
202
proc Test {} {
203
    global dirboxTest_selected
204
 
205
    #------------------------------------------------------------
206
    # (1) DirList
207
    #------------------------------------------------------------
208
 
209
    TestBlock dirbox-1.1 {Generic testing of tixDirList} {
210
        TestConfigDirectory tixDirList -value 1
211
    }
212
 
213
    TestBlock dirbox-1.2 {Wild click on the hlist subwidget} {
214
        set dirboxTest_selected ""
215
        set w [tixDirList .c -command DirboxTest_Cmd]
216
        set h [$w subwidget hlist]
217
        pack $w -expand yes -fill both
218
        TestHListWildClick $h double "DirboxTest_Compare 0 $w $h"
219
    }
220
    catch {
221
        destroy $w
222
    }
223
 
224
    #------------------------------------------------------------
225
    # (2) DirTree
226
    #------------------------------------------------------------
227
 
228
    TestBlock dirbox-2.1 {Generic testing of tixDirTree} {
229
#       TestConfigDirectory tixDirTree -value 1
230
    }
231
 
232
    TestBlock dirbox-2.2 {Wild click on the hlist subwidget} {
233
        set dirboxTest_selected ""
234
        set w [tixDirTree .c -command DirboxTest_Cmd]
235
        set h [$w subwidget hlist]
236
        pack $w -expand yes -fill both
237
#       TestHListWildClick $h double "DirboxTest_Compare 0 $w $h"
238
    }
239
    catch {
240
        destroy $w
241
    }
242
 
243
    #------------------------------------------------------------
244
    # (3) DirBox
245
    #------------------------------------------------------------
246
 
247
    TestBlock dirbox-3.1 {Generic testing of tixDirSelectBox} {
248
#       TestConfigDirectory tixDirSelectBox -value 1
249
    }
250
 
251
    TestBlock dirbox-3.2 {Wild click on the hlist subwidget} {
252
        set dirboxTest_selected ""
253
        set w [tixDirSelectBox .c -command DirboxTest_Cmd]
254
        set h [$w subwidget dirlist subwidget hlist]
255
        pack $w -expand yes -fill both
256
#       TestHListWildClick $h double "DirboxTest_Compare 0 $w $h"
257
    }
258
    catch {
259
        destroy $w
260
    }
261
 
262
    TestBlock dirbox-4.1 {-disablecallback option} {
263
        global dirbox_called
264
        tixDirList .c -command dirbox_callback
265
        pack .c
266
        set dirbox_called 0
267
        .c config -disablecallback 1
268
        .c config -value [pwd]
269
        .c config -disablecallback 0
270
        Assert {$dirbox_called == 0}
271
    }
272
    catch {
273
        destroy .c
274
    }
275
}
276
 
277
proc dirbox_callback {args} {
278
    global dirbox_called
279
    set dirbox_called 1
280
}
281
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.