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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [itcl/] [itcl/] [tests/] [namespace.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 classes within namespaces
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: namespace.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
#  Classes within namespaces
20
# ----------------------------------------------------------------------
21
test namespace-1.1 {same class name can be used in different namespaces} {
22
    namespace eval test_ns_1 {
23
        class Counter {
24
            variable num 0
25
            method ++ {{by 1}} {
26
                incr num $by
27
            }
28
            method do {args} {
29
                return [eval $args]
30
            }
31
            common tag 1
32
        }
33
    }
34
    namespace eval test_ns_2 {
35
        class Counter {
36
            variable num 0
37
            method ++ {{by 2}} {
38
                if {$num == 0} {
39
                    set num 1
40
                } else {
41
                    set num [expr $num*$by]
42
                }
43
            }
44
            method do {args} {
45
                return [eval $args]
46
            }
47
            common tag 2
48
        }
49
    }
50
} ""
51
 
52
test namespace-1.2 {classes in different namespaces are different} {
53
    list [namespace eval test_ns_1::Counter {info variable tag}] \
54
         [namespace eval test_ns_2::Counter {info variable tag}] \
55
} {{protected common ::test_ns_1::Counter::tag 1 1} {protected common ::test_ns_2::Counter::tag 2 2}}
56
 
57
test namespace-1.3 {create an object in one namespace} {
58
    namespace eval test_ns_1 {
59
        list [Counter c] [c ++] [c ++] [c ++] [c ++]
60
    }
61
} {c 1 2 3 4}
62
 
63
test namespace-1.4 {create an object in another namespace} {
64
    namespace eval test_ns_2 {
65
        list [Counter c] [c ++] [c ++] [c ++] [c ++]
66
    }
67
} {c 1 2 4 8}
68
 
69
test namespace-1.5 {can find classes wrapped in a namespace} {
70
    list [catch {test_ns_1::c do find objects -isa Counter} msg] $msg \
71
         [catch {test_ns_1::c do find objects -class Counter} msg] $msg
72
} {0 {} 0 {}}
73
 
74
namespace delete test_ns_1 test_ns_2

powered by: WebSVN 2.1.0

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