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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [tests/] [chain.test] - Blame information for rev 1773

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

Line No. Rev Author Line
1 578 markom
#
2
# Tests for chaining methods and procs
3
# ----------------------------------------------------------------------
4
#   AUTHOR:  Michael J. McLennan
5
#            Bell Labs Innovations for Lucent Technologies
6
#            mmclennan@lucent.com
7
#            http://www.tcltk.com/itcl
8
#
9
#      RCS:  $Id: chain.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
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.
15
 
16
if {[string compare test [info procs test]] == 1} then {source defs}
17
 
18
# ----------------------------------------------------------------------
19
#  Chaining methods and procs
20
# ----------------------------------------------------------------------
21
test chain-1.1 {define simple classes with inheritance} {
22
    itcl::class test_chain_a {
23
        constructor {args} {
24
            eval chain $args
25
        } {
26
            global ::test_chain_status
27
            lappend test_chain_status "a::constructor $args"
28
        }
29
        method show {mesg} {
30
            chain $mesg
31
            global ::test_chain_status
32
            lappend test_chain_status "a::show $mesg"
33
        }
34
        proc tell {mesg} {
35
            global ::test_chain_status
36
            lappend test_chain_status "a::tell $mesg"
37
            chain $mesg
38
        }
39
    }
40
    itcl::class test_chain_b {
41
        constructor {args} {
42
            eval chain $args
43
        } {
44
            global ::test_chain_status
45
            lappend test_chain_status "b::constructor $args"
46
        }
47
        method show {mesg} {
48
            chain $mesg
49
            global ::test_chain_status
50
            lappend test_chain_status "b::show $mesg"
51
        }
52
        proc tell {mesg} {
53
            global ::test_chain_status
54
            lappend test_chain_status "b::tell $mesg"
55
            chain $mesg
56
        }
57
    }
58
    itcl::class test_chain_c {
59
        inherit test_chain_a test_chain_b
60
        constructor {args} {
61
            eval chain $args
62
        } {
63
            global ::test_chain_status
64
            lappend test_chain_status "c::constructor $args"
65
        }
66
        proc tell {mesg} {
67
            global ::test_chain_status
68
            lappend test_chain_status "c::tell $mesg"
69
            chain $mesg
70
        }
71
    }
72
    itcl::class test_chain_d {
73
        inherit test_chain_c
74
        constructor {args} {
75
            eval chain $args
76
        } {
77
            global ::test_chain_status
78
            lappend test_chain_status "d::constructor $args"
79
        }
80
        method show {mesg} {
81
            chain $mesg
82
            global ::test_chain_status
83
            lappend test_chain_status "d::show $mesg"
84
        }
85
        proc tell {mesg} {
86
            global ::test_chain_status
87
            lappend test_chain_status "d::tell $mesg"
88
            chain $mesg
89
        }
90
    }
91
} ""
92
 
93
test chain-1.2 {create a test object} {
94
    set test_chain_status ""
95
    set testobj [test_chain_d #auto 1 2 3]
96
    set test_chain_status
97
} {{b::constructor 1 2 3} {a::constructor 1 2 3} {c::constructor 1 2 3} {d::constructor 1 2 3}}
98
 
99
test chain-1.3 {invoke a chained method} {
100
    set test_chain_status ""
101
    $testobj show "hello there"
102
    set test_chain_status
103
} {{b::show hello there} {a::show hello there} {d::show hello there}}
104
 
105
test chain-1.4 {invoke a chained method with a specific name} {
106
    set test_chain_status ""
107
    $testobj test_chain_d::show "hello there"
108
    set test_chain_status
109
} {{b::show hello there} {a::show hello there} {d::show hello there}}
110
 
111
test chain-1.5 {chained methods can cross multiple-inheritance branches} {
112
    set test_chain_status ""
113
    $testobj test_chain_a::show "hello there"
114
    set test_chain_status
115
} {{b::show hello there} {a::show hello there}}
116
 
117
test chain-1.6 {invoke a chained proc} {
118
    set test_chain_status ""
119
    test_chain_d::tell "testing 1 2 3"
120
    set test_chain_status
121
} {{d::tell testing 1 2 3} {c::tell testing 1 2 3} {a::tell testing 1 2 3}}
122
 
123
test chain-1.7 {invoke a chained proc} {
124
    set test_chain_status ""
125
    test_chain_c::tell "testing 1 2 3"
126
    set test_chain_status
127
} {{c::tell testing 1 2 3} {a::tell testing 1 2 3}}
128
 
129
test chain-2.1 {create a test object in a base class} {
130
    set test_chain_status ""
131
    set testobj [test_chain_c #auto 4 5 6]
132
    set test_chain_status
133
} {{b::constructor 4 5 6} {a::constructor 4 5 6} {c::constructor 4 5 6}}
134
 
135
test chain-2.2 {invoke a chained method} {
136
    set test_chain_status ""
137
    $testobj show "hello there"
138
    set test_chain_status
139
} {{b::show hello there} {a::show hello there}}
140
 
141
test chain-3.0 {invoke "chain" outside of a class} {
142
    list [catch {itcl::builtin::chain 1 2 3} err] $err
143
} {1 {cannot chain functions outside of a class context}}
144
 
145
# ----------------------------------------------------------------------
146
#  Clean up
147
# ----------------------------------------------------------------------
148
delete class test_chain_d test_chain_c test_chain_b test_chain_a

powered by: WebSVN 2.1.0

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