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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tix/] [tests/] [general/] [api.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
# api.tcl --
2
#
3
#       Performs a comprehensive test on all the Tix widgets and
4
#       commands. This test knows the types and arguments of many
5
#       common Tix widget methods. It calls each widget method and
6
#       ensure that it work as expected.
7
#
8
#
9
# Copyright (c) 1996, Expert Interface Technologies
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
 
15
set depd(init)         ""
16
set info(init)         "Initialization, find out all the widget classes"
17
set depd(wcreate)      "init"
18
set info(wcreate)      "Try to create each widget"
19
set depd(method)       "init wcreate"
20
set info(method)       "Try to call each public method of all widgets"
21
set depd(config-state) "init wcreate method"
22
set info(config-state) "Configuring -state of widgets"
23
 
24
proc APITest:init {} {
25
    global widCmd cmdNames auto_index testConfig
26
 
27
    TestBlock api-1.1 {Find out all the widget classes} {
28
        # (1) Stores all the Tix commands in the associative array 
29
        #     cmdNames
30
        #
31
        foreach cmd [info commands tix*] {
32
            if [regexp : $cmd] {
33
                continue
34
            }
35
            set cmdNames($cmd) ""
36
        }
37
 
38
        foreach name [array names auto_index "tix*:AutoLoad"] {
39
            if [regsub {:AutoLoad} $name "" cmd] {
40
                set cmdNames($cmd) ""
41
            }
42
        }
43
 
44
        # (3). Don't want to mess with the console routines
45
        #
46
        foreach name [array names cmdNames] {
47
            if [string match tixCon* $name] {
48
                catch {
49
                    unset cmdNames($name)
50
                }
51
            }
52
        }
53
 
54
        # (2) Find out the names of the widget creation commands
55
        #
56
        foreach cmd [lsort [array names cmdNames]] {
57
            if [info exists $cmd\(superClass\)] {
58
                if {[set $cmd\(superClass\)] == ""} {
59
                    continue
60
                }
61
            }
62
            switch -regexp -- $cmd {
63
                {(DoWhenIdle)|(:)} {
64
                    continue
65
                }
66
            }
67
 
68
            if [info exists err] {
69
                unset err
70
            }
71
 
72
            catch {
73
                auto_load $cmd
74
            }
75
            catch {
76
                if {[uplevel #0 set $cmd\(isWidget\)] == 1} {
77
                    if {$testConfig(VERBOSE) > 20} {
78
                        puts "Found widget class: $cmd"
79
                    }
80
                    set widCmd($cmd) ""
81
                }
82
            }
83
        }
84
    }
85
}
86
 
87
proc APITest:wcreate {} {
88
    global widCmd testConfig
89
 
90
    TestBlock api-2 {Find out all the widget classes} {
91
        foreach cls [lsort [array names widCmd]] {
92
            if {[uplevel #0 set $cls\(virtual\)] == 1} {
93
                # This is a virtual base class. Skip it.
94
                #
95
                continue
96
            }
97
 
98
            TestBlock api-2.1-$cls "Create widget of class: $cls" {
99
                $cls .c
100
                if ![tixStrEq [winfo toplevel .c] .c] {
101
                    pack .c -expand yes -fill both
102
                }
103
                update
104
            }
105
 
106
            TestBlock api-2.2-$cls "Widget Deletion" {
107
                catch {
108
                    destroy .c
109
                }
110
 
111
                frame .c
112
                update idletasks
113
                global .c
114
                if {[info exists .c] && [array names .c] != "context"} {
115
                    catch {
116
                        parray .c
117
                    }
118
                    catch {
119
                        puts [set .c]
120
                    }
121
                    error "widget record has not been deleted properly"
122
                }
123
            }
124
            catch {
125
                destroy .c
126
            }
127
        }
128
    }
129
}
130
 
131
proc APITest:method {} {
132
    global widCmd testConfig
133
 
134
    TestBlock api-3 {Call all the methods of a widget class} {
135
 
136
        foreach cls [lsort [array names widCmd]] {
137
            if {[uplevel #0 set $cls\(virtual\)] == 1} {
138
                continue
139
            }
140
 
141
            TestBlock api-3.1-$cls "Widget class: $cls" {
142
                $cls .c
143
 
144
                upvar #0 $cls classRec
145
                foreach method [lsort $classRec(methods)] {
146
                    TestBlock api-3.1.1 "method: $method" {
147
                        catch {
148
                            .c $method
149
                        }
150
                    }
151
                }
152
            }
153
            catch {
154
                destroy .c
155
            }
156
        }
157
    }
158
}
159
 
160
proc APITest:config-state {} {
161
    global widCmd testConfig
162
 
163
    TestBlock api-4 {Call the config-state method} {
164
 
165
        foreach cls [lsort [array names widCmd]] {
166
            if {[uplevel #0 set $cls\(virtual\)] == 1} {
167
                continue
168
            }
169
 
170
            $cls .c
171
            catch {
172
                pack .c
173
            }
174
            if [catch {.c cget -state}] {
175
                destroy .c
176
                continue
177
            }
178
 
179
            if [tixStrEq $cls tixBalloon] {
180
                destroy .c
181
                continue
182
            }
183
 
184
            TestBlock api-4.1-$cls "Class: $cls" {
185
                .c config -state disabled
186
                Assert {[tixStrEq [.c cget -state] "disabled"]}
187
                update
188
                Assert {[tixStrEq [.c cget -state] "disabled"]}
189
 
190
                .c config -state normal
191
                Assert {[tixStrEq [.c cget -state] "normal"]}
192
                update
193
                Assert {[tixStrEq [.c cget -state] "normal"]}
194
 
195
 
196
                .c config -state disabled
197
                Assert {[tixStrEq [.c cget -state] "disabled"]}
198
                .c config -state normal
199
                Assert {[tixStrEq [.c cget -state] "normal"]}
200
 
201
            }
202
            catch {
203
                destroy .c; update
204
            }
205
        }
206
    }
207
}
208
 
209
proc APITest {t {level 0}} {
210
    global depd tested info
211
 
212
    if {$level > 300} {
213
        error "possibly circular dependency"
214
    }
215
 
216
    set tested(none)  1
217
 
218
    if [info exist tested($t)] {
219
        return
220
    }
221
    foreach dep $depd($t) {
222
        if {![info exists tested($dep)]} {
223
            APITest $dep [expr $level + 1]
224
        }
225
    }
226
 
227
    if {$t == "all"} {
228
        set tested($t) 1
229
        return
230
    } else {
231
        update
232
        eval APITest:$t
233
        set tested($t) 1
234
    }
235
}
236
 
237
proc About {} {
238
    return "Tix API Testing Suite"
239
}
240
 
241
proc Test {} {
242
    global depd env
243
 
244
    if [info exists env(APT_SUBSET)] {
245
        set tests $env(APT_SUBSET)
246
    } else {
247
        set tests [array names depd]
248
    }
249
 
250
    foreach test $tests {
251
        APITest $test
252
    }
253
}
254
 

powered by: WebSVN 2.1.0

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