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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
# -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# namesp.test --
#
# This file is a Tcl script to test out Tix's behavior under
# namespaces. It is organized in the standard fashion for Tcl
# tests.
#
# Copyright (c) 2000-2001 Tix Project Group.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: namesp.test,v 1.3 2002/11/13 21:12:17 idiscovery Exp $
# TODO:
# Invoke tix methods inside namespace
# Invoke tix var traces inside namesp
# Invoke tix -commands inside namesp
# Invoke delayed actions (e.g., browsecmd) inside namesp
# more more more tests
package require Tix
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
}
tixClass tixTestClass {
-superclass {}
-classname TixTestClass
-method {
cget configure foo bar
}
-flag {
-x -y
}
-configspec {
{-x 0}
{-y 0}
}
}
proc tixTestClass:Constructor {args} {}
proc tixTestClass:foo {w args} {
upvar #0 $w data
return [list $data(-x) and me too]
}
test namesp-1.1.1 {create widget in namespace} {
#
# widget command should be created in global name space
#
namespace eval ::myNameSpace {
tixScrolledHList .sl
}
set a [info command ::.sl]
destroy .sl
set a
} {::.sl}
test namesp-1.1.2 {create class instance in namespace} {
#
# instance command should be created in global name space
#
namespace eval ::myNameSpace {
tixTestClass xx
}
set a [info command ::xx]
rename xx ""
set a
} {::xx}
test namesp-1.2.1 {create widget in namespace} {
#
# widget variable should be created in global name space
#
namespace eval ::myNameSpace {
tixScrolledHList .sl
}
set a [list [catch {set ::.sl} msg] $msg]
destroy .sl
set a
} {1 {can't read "::.sl": variable is array}}
test namesp-1.2.2 {create class instance in namespace} {
#
# instance variable should be created in global name space
#
namespace eval ::myNameSpace {
tixTestClass xx
}
set a [list [catch {set ::xx} msg] $msg]
rename xx {}
set a
} {1 {can't read "::xx": variable is array}}
test namesp-1.3.2 {class instance variable} {
#
# instance variable should be created in global name space
#
namespace eval ::myNameSpace {
tixTestClass xx -x 10 -y 10
}
set a [list [catch {set ::xx(-x)} msg] $msg]
rename xx {}
set a
} {0 10}
test namesp-1.4.2 {class instance method} {
tixTestClass xx -x 10 -y 10
namespace eval ::myNameSpace {
set ::a [list [catch {xx foo} msg] $msg]
}
rename xx {}
set a
} {0 {10 and me too}}
test namesp-1.5.2 {class instance cget} {
tixTestClass xx -x 1234
namespace eval ::myNameSpace {
set ::a [list [catch {xx cget -x} msg] $msg]
}
rename xx {}
set a
} {0 1234}
test namesp-1.6.2 {class instance configure} {
tixTestClass xx -x 1234
namespace eval ::myNameSpace {
xx config -x 2345
}
set ::a [list [catch {xx cget -x} msg] $msg]
rename xx {}
set a
} {0 2345}
test namesp-2.1.1 {invalid widget name} {
list [catch {tixScrolledHList ::.sl} msg] $msg
} {1 {invalid widget name "::.sl": may not contain substring "::"}}
test namesp-2.1.2 {invalid instance name} {
list [catch {tixTestClass ::.sl} msg] $msg
} {1 {invalid instance name "::.sl": may not contain substring "::"}}
test namesp-2.2 {invalid widget name} {
list [catch {tixScrolledHList .sl::xx} msg] $msg
} {1 {invalid widget name ".sl::xx": may not contain substring "::"}}
test namesp-3.1.1 {declare class inside namespace} {
namespace eval ::myNameSpace {
tixClass tixTestClass2 {
-superclass {}
-classname TixTestClass
-method {
foo bar
}
-flag {
-x -y
}
-configspec {
{-x 0}
{-y 0}
}
}
}
set a [list [catch {info commands ::tixTestClass2} msg] $msg]
set b [list [catch {set ::tixTestClass2} msg] $msg]
set c [list [catch {set ::tixTestClass2(className)} msg] $msg]
list $a $b $c
} {{0 ::tixTestClass2} {1 {can't read "::tixTestClass2": variable is array}} {0 tixTestClass2}}
# cleanup
::tcltest::cleanupTests
return
|