File: local.test

package info (click to toggle)
itcl4 4.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,512 kB
  • sloc: ansic: 25,739; tcl: 1,705; sh: 452; makefile: 68
file content (70 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download
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
#
# Tests for "local" command for creating objects local to a proc
# ----------------------------------------------------------------------
#   AUTHOR:  Michael J. McLennan
#	    Bell Labs Innovations for Lucent Technologies
#	    mmclennan@lucent.com
#	    http://www.tcltk.com/itcl
# ----------------------------------------------------------------------
#	    Copyright (c) 1993-1998  Lucent Technologies, Inc.
# ======================================================================
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest 2.1
namespace import ::tcltest::test
::tcltest::loadTestedCommands
package require itcl

# ----------------------------------------------------------------------
#  Test "local" to create objects that only exist within a proc
# ----------------------------------------------------------------------
test local-1.1 {define a class to use for testing} {
    itcl::class test_local {
	common status ""
	constructor {} {
	    lappend status "created $this"
	}
	destructor {
	    lappend status "deleted $this"
	}
	proc clear {} {
	    set status ""
	}
	proc check {} {
	    return $status
	}
	proc test {} {
	    itcl::local test_local #auto
	    lappend status "processing"
	}
	proc test2 {} {
	    itcl::local test_local #auto
	    lappend status "call test..."
	    test
	    lappend status "...back"
	}
    }
    test_local #auto
} {test_local0}

test local-1.2 {} {
    test_local::clear
    test_local::test
    test_local::check
} {{created ::test_local::test_local1} processing {deleted ::test_local::test_local1}}

test local-1.3 {} {
    test_local::clear
    test_local::test2
    test_local::check
} {{created ::test_local::test_local2} {call test...} {created ::test_local::test_local3} processing {deleted ::test_local::test_local3} ...back {deleted ::test_local::test_local2}}

test local-1.4 {} {
    itcl::find objects -isa test_local
} {test_local0}

itcl::delete class test_local

::tcltest::cleanupTests
return