2 # Basic tests for class definition and method/proc access
3 # ----------------------------------------------------------------------
4 # AUTHOR: Michael J. McLennan
5 # Bell Labs Innovations for Lucent Technologies
7 # http://www.tcltk.com/itcl
10 # ----------------------------------------------------------------------
11 # Copyright (c) 1993-1998 Lucent Technologies, Inc.
12 # ======================================================================
13 # See the file "license.terms" for information on usage and
14 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16 # ----------------------------------------------------------------------
18 # ----------------------------------------------------------------------
19 foreach obj [itcl_info objects -class Foo] {
23 # ----------------------------------------------------------------------
25 # ----------------------------------------------------------------------
26 test {Create a simple object} {
32 test {Make sure that object names cannot be duplicated} {
38 test {Create another object} {
44 test {Create an object with an automatic name} {
47 [string match foo* $result]
50 test {Get list of objects in a class} {
51 itcl_info objects -class Foo
53 [llength $result] == 3
56 # ----------------------------------------------------------------------
58 # ----------------------------------------------------------------------
59 test {Info: all public variables} {
62 [test_cmp_lists $result {Foo::blit Foo::blat Foo::blot}]
65 test {Info: public variable initial value} {
66 x info public blit -init
71 test {Info: public variable initial value (undefined)} {
72 x info public blit -value
74 $result == "<undefined>"
77 test {Info: public variable initial value} {
78 x info public blat -init
83 test {Info: public variable current value} {
84 x info public blot -value
89 test {Info: public variable config statement} {
90 x info public blit -config
95 test {Info: public variable config statement} {
96 x info public blot -config
98 $result == {global WATCH; set WATCH "blot=$blot"}
101 # ----------------------------------------------------------------------
102 # CONFIG-ING PUBLIC VARIABLES
103 # ----------------------------------------------------------------------
104 test {Setting public variables via "config"} {
105 x config -blit 27 -blat xyz
107 $result == "Foo::blit Foo::blat"
110 test {Info: public variable init/current value} {
111 x info public blit -init -value
116 test {Info: public variable init/current value} {
117 x info public blat -init -value
122 test {"config" is ordinary arg if it is not last arg} {
125 $result == {-blit|pdq}
128 test {Public variables with "config" code} {
130 concat [x config -blot abc] / $WATCH
132 $result == "Foo::blot / blot=abc"
135 test {Make sure object data is local to objects} {
138 concat [x info public blit -value] / [xx info public blit -value]
140 $result == "abc / xyz"
143 # ----------------------------------------------------------------------
144 # PROTECTED VARIABLES
145 # ----------------------------------------------------------------------
146 test {Info: all protected variables} {
149 [test_cmp_lists $result {Foo::_blit Foo::_blat Foo::this}]
152 test {Info: protected "this" variable} {
153 x info protected this -value
158 test {Info: protected "this" variable} {
159 xx info protected this -value
164 test {Info: protected variable initial value} {
165 x info protected _blit -init
170 test {Info: protected variable access/value} {
173 $result == "Foo says 'rst'" &&
174 [x info protected _blit -value] == "rst"
177 # ----------------------------------------------------------------------
179 # ----------------------------------------------------------------------
180 test {Info: all protected variables} {
183 [test_cmp_lists $result {Foo::foos Foo::nfoo}]
186 test {Info: common variable initial value} {
187 x info common foos -init
192 test {Info: common variable initial value} {
193 x info common nfoo -init
198 test {Info: common variable access/value} {
200 x info common nfoo -value
205 test {Make sure common data is really common} {
207 x info common nfoo -value
209 $result == [xx info common nfoo -value]
212 test {Access common data in proc} {
219 test {Common variables can be initialized within class definition} {
220 x do {if {[info exists foos(_ignore_)]} {set foos(_ignore_)}}
222 $result == "Foo says 'foos-is-now-an-array'"
225 test {Arrays as common data} {
228 [test_cmp_lists $result [itcl_info objects -class Foo]]
231 # ----------------------------------------------------------------------
233 # ----------------------------------------------------------------------
234 test {Info: all methods} {
237 [test_cmp_lists $result {
238 Foo::constructor Foo::destructor
239 Foo::nothing Foo::do Foo::xecho
240 Foo::config Foo::xconfig Foo::configx
242 Foo::configure Foo::delete Foo::cget Foo::isa
246 test {Info: method args} {
247 x info method nothing -args
252 test {Info: method args} {
253 x info method xconfig -args
255 $result == "x config"
258 test {Info: method body} {
259 x info method nothing -body
264 test {Info: method body} {
265 x info method xconfig -body
272 # ----------------------------------------------------------------------
274 # ----------------------------------------------------------------------
275 test {Info: all procs} {
278 [test_cmp_lists $result {
279 Foo::echo Foo::foos Foo::nfoos Foo::testProcArgs
283 test {Info: proc args} {
284 x info proc nfoos -args
289 test {Info: proc args} {
290 x info proc foos -args
292 $result == "{pattern *}"
295 test {Info: proc body} {
296 x info proc nfoos -body
303 test {Info: proc body} {
311 # ----------------------------------------------------------------------
313 # ----------------------------------------------------------------------
314 test {Default arguments can get assigned a proper value} {
317 [test_cmp_lists $result {x xx}]
320 test {Default value for "config" argument} {
323 $result == "Foo::blit Foo::blat" &&
324 [x info public blit -value] == "auto" &&
325 [x info public blat -value] == "matic"
328 test {"args" formal argument absorbs extra arguments} {
329 Foo :: echo abc 1 2 3
331 $result == "abc | 3: 1 2 3"
334 test {"args" formal argument absorbs extra arguments} {
337 $result == "def | 0: "
340 test {"args" formal argument absorbs extra arguments} {
343 $result == "abc | 3: 1 2 3"
346 test {"args" formal argument absorbs extra arguments} {
349 $result == "def | 0: "
352 test {Extra args cause an error} {
353 catch "x configx arg arg error"
358 test {Extra args cause an error} {
359 catch "x nothing error"
364 test {Formal arguments don't clobber public/protected variables} {
369 x testMethodArgs yuck puke etc.
371 $result == "yuck, puke, and 1 other args" &&
372 [x info public blit -value] == "okay" &&
373 [x info protected _blit -value] == "no-problem"
376 test {Formal arguments don't clobber common variables} {
377 Foo :: testProcArgs yuck etc.
379 $result == "yuck, and 1 other args" &&
380 [x info common nfoo -value] != "yuck"
383 # ----------------------------------------------------------------------
385 # ----------------------------------------------------------------------
386 test {Delete an object} {
392 test {Delete an object} {
398 test {Destructor is properly invoked} {
401 [test_cmp_lists $result [itcl_info objects -class Foo]]
404 test {Object names are removed as commands} {
405 expr {[info commands x] == "" && [info commands xx] == ""}