1 |
578 |
markom |
#
|
2 |
|
|
# Privacy options for components
|
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: privacy.test,v 1.1.1.1 2002-01-16 10:24:48 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 |
|
|
# Define a base class with public variables and a simple mega-widget
|
20 |
|
|
# ----------------------------------------------------------------------
|
21 |
|
|
test privacy-1.1 {define simple mega-widget class} {
|
22 |
|
|
itcl::class TestPrivacy {
|
23 |
|
|
inherit itk::Widget
|
24 |
|
|
constructor {args} {
|
25 |
|
|
eval itk_initialize $args
|
26 |
|
|
}
|
27 |
|
|
method do {args} {
|
28 |
|
|
return [eval $args]
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
set testobj [TestPrivacy .#auto]
|
32 |
|
|
pack $testobj
|
33 |
|
|
} {}
|
34 |
|
|
|
35 |
|
|
test privacy-1.2 {"itk_component add" requires certain arguments} {
|
36 |
|
|
list [catch {$testobj do itk_component add foo} msg] $msg \
|
37 |
|
|
[catch {$testobj do itk_component add foo bar baz qux} msg] $msg
|
38 |
|
|
} {1 {wrong # args: should be "itk_component add ?-protected? ?-private? ?--? name createCmds ?optionCmds?"} 1 {wrong # args: should be "add ?-protected? ?-private? ?--? name createCmds ?optionCmds?}}
|
39 |
|
|
|
40 |
|
|
test privacy-1.3 {"itk_component add" rejects invalid options} {
|
41 |
|
|
list [catch {
|
42 |
|
|
$testobj do itk_component add -foo bar baz qux
|
43 |
|
|
} msg] $msg \
|
44 |
|
|
[catch {
|
45 |
|
|
$testobj do itk_component add -- -foo {label $itk_interior.l}
|
46 |
|
|
} msg] $msg
|
47 |
|
|
} {1 {bad option "-foo": should be -private, -protected or --} 0 -foo}
|
48 |
|
|
|
49 |
|
|
test privacy-1.4 {"itk_component add" recognizes privacy options} {
|
50 |
|
|
list [catch {
|
51 |
|
|
$testobj do itk_component add -protected x {label $itk_interior.x}
|
52 |
|
|
} msg] $msg \
|
53 |
|
|
[catch {
|
54 |
|
|
$testobj do itk_component add -private y {label $itk_interior.y}
|
55 |
|
|
} msg] $msg
|
56 |
|
|
} {0 x 0 y}
|
57 |
|
|
|
58 |
|
|
test privacy-1.5 {protected/private components are hidden} {
|
59 |
|
|
list [lsort [$testobj component]] \
|
60 |
|
|
[lsort [$testobj do component]]
|
61 |
|
|
} {{-foo hull} {-foo hull x y}}
|
62 |
|
|
|
63 |
|
|
test privacy-1.6 {define a derived class and add protected/private comps} {
|
64 |
|
|
itcl::class TestMorePrivacy {
|
65 |
|
|
inherit TestPrivacy
|
66 |
|
|
constructor {args} {
|
67 |
|
|
eval itk_initialize $args
|
68 |
|
|
}
|
69 |
|
|
method do {args} {
|
70 |
|
|
return [eval $args]
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
set testobj2 [TestMorePrivacy .#auto]
|
74 |
|
|
$testobj2 TestPrivacy::do itk_component add -private x {
|
75 |
|
|
label $itk_interior.x
|
76 |
|
|
}
|
77 |
|
|
$testobj2 TestPrivacy::do itk_component add -protected y {
|
78 |
|
|
label $itk_interior.y
|
79 |
|
|
}
|
80 |
|
|
$testobj2 TestPrivacy::do itk_component add z {
|
81 |
|
|
label $itk_interior.z
|
82 |
|
|
}
|
83 |
|
|
} {z}
|
84 |
|
|
|
85 |
|
|
test privacy-1.7 {components are visible depending on namespace context} {
|
86 |
|
|
list [lsort [$testobj2 component]] \
|
87 |
|
|
[lsort [$testobj2 do component]] \
|
88 |
|
|
[lsort [$testobj2 TestPrivacy::do component]]
|
89 |
|
|
} {{hull z} {hull y z} {hull x y z}}
|
90 |
|
|
|
91 |
|
|
# ----------------------------------------------------------------------
|
92 |
|
|
# Clean up
|
93 |
|
|
# ----------------------------------------------------------------------
|
94 |
|
|
itcl::delete class TestPrivacy TestMorePrivacy
|