#
|
#
|
# Tests for classes within namespaces
|
# Tests for classes within namespaces
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# AUTHOR: Michael J. McLennan
|
# AUTHOR: Michael J. McLennan
|
# Bell Labs Innovations for Lucent Technologies
|
# Bell Labs Innovations for Lucent Technologies
|
# mmclennan@lucent.com
|
# mmclennan@lucent.com
|
# http://www.tcltk.com/itcl
|
# http://www.tcltk.com/itcl
|
#
|
#
|
# RCS: $Id: namespace.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# RCS: $Id: namespace.test,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# ======================================================================
|
# ======================================================================
|
# See the file "license.terms" for information on usage and
|
# See the file "license.terms" for information on usage and
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
if {[string compare test [info procs test]] == 1} then {source defs}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Classes within namespaces
|
# Classes within namespaces
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
test namespace-1.1 {same class name can be used in different namespaces} {
|
test namespace-1.1 {same class name can be used in different namespaces} {
|
namespace eval test_ns_1 {
|
namespace eval test_ns_1 {
|
class Counter {
|
class Counter {
|
variable num 0
|
variable num 0
|
method ++ {{by 1}} {
|
method ++ {{by 1}} {
|
incr num $by
|
incr num $by
|
}
|
}
|
method do {args} {
|
method do {args} {
|
return [eval $args]
|
return [eval $args]
|
}
|
}
|
common tag 1
|
common tag 1
|
}
|
}
|
}
|
}
|
namespace eval test_ns_2 {
|
namespace eval test_ns_2 {
|
class Counter {
|
class Counter {
|
variable num 0
|
variable num 0
|
method ++ {{by 2}} {
|
method ++ {{by 2}} {
|
if {$num == 0} {
|
if {$num == 0} {
|
set num 1
|
set num 1
|
} else {
|
} else {
|
set num [expr $num*$by]
|
set num [expr $num*$by]
|
}
|
}
|
}
|
}
|
method do {args} {
|
method do {args} {
|
return [eval $args]
|
return [eval $args]
|
}
|
}
|
common tag 2
|
common tag 2
|
}
|
}
|
}
|
}
|
} ""
|
} ""
|
|
|
test namespace-1.2 {classes in different namespaces are different} {
|
test namespace-1.2 {classes in different namespaces are different} {
|
list [namespace eval test_ns_1::Counter {info variable tag}] \
|
list [namespace eval test_ns_1::Counter {info variable tag}] \
|
[namespace eval test_ns_2::Counter {info variable tag}] \
|
[namespace eval test_ns_2::Counter {info variable tag}] \
|
} {{protected common ::test_ns_1::Counter::tag 1 1} {protected common ::test_ns_2::Counter::tag 2 2}}
|
} {{protected common ::test_ns_1::Counter::tag 1 1} {protected common ::test_ns_2::Counter::tag 2 2}}
|
|
|
test namespace-1.3 {create an object in one namespace} {
|
test namespace-1.3 {create an object in one namespace} {
|
namespace eval test_ns_1 {
|
namespace eval test_ns_1 {
|
list [Counter c] [c ++] [c ++] [c ++] [c ++]
|
list [Counter c] [c ++] [c ++] [c ++] [c ++]
|
}
|
}
|
} {c 1 2 3 4}
|
} {c 1 2 3 4}
|
|
|
test namespace-1.4 {create an object in another namespace} {
|
test namespace-1.4 {create an object in another namespace} {
|
namespace eval test_ns_2 {
|
namespace eval test_ns_2 {
|
list [Counter c] [c ++] [c ++] [c ++] [c ++]
|
list [Counter c] [c ++] [c ++] [c ++] [c ++]
|
}
|
}
|
} {c 1 2 4 8}
|
} {c 1 2 4 8}
|
|
|
test namespace-1.5 {can find classes wrapped in a namespace} {
|
test namespace-1.5 {can find classes wrapped in a namespace} {
|
list [catch {test_ns_1::c do find objects -isa Counter} msg] $msg \
|
list [catch {test_ns_1::c do find objects -isa Counter} msg] $msg \
|
[catch {test_ns_1::c do find objects -class Counter} msg] $msg
|
[catch {test_ns_1::c do find objects -class Counter} msg] $msg
|
} {0 {} 0 {}}
|
} {0 {} 0 {}}
|
|
|
namespace delete test_ns_1 test_ns_2
|
namespace delete test_ns_1 test_ns_2
|
|
|