summaryrefslogtreecommitdiffstats
path: root/tests/element.test
blob: f803fcc11322398a20c0df2ff8a340cd0e54799f (plain)
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
# Commands covered:  [element]
#
# This file contains a collection of tests for the style widget command of
# the tktreectrl extension.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2000 by Scriptics Corporation.
# Copyright (c) 2002 by Christian Krone.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# CVS: @(#) $Id: element.test,v 1.2 2006/11/11 21:42:18 treectrl Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import ::tcltest::*
}

package require Tk
package require treectrl

test element-0.1 {some needed preparations} -body {
    pack [treectrl .t]
} -result {}

test element-1.1 {element: missing command} -body {
    .t element
} -returnCodes error -result {wrong # args: should be ".t element command ?arg arg ...?"}

test element-1.2 {element: invalid command} -body {
    .t element foo
} -returnCodes error -result {bad command "foo": must be *} -match glob

###

test element-2.1 {element cget: missing arg} -body {
    .t element cget
} -returnCodes error -result {wrong # args: should be ".t element cget name option"}

test element-2.2 {element cget: too many args} -body {
    .t element cget a b c d
} -returnCodes error -result {wrong # args: should be ".t element cget name option"}

test element-2.3 {element cget: unknown elem} -body {
    .t element cget foo a
} -returnCodes error -result {element "foo" doesn't exist}

###

test element-3.1 {element configure: missing arg} -body {
    .t element configure
} -returnCodes error -result {wrong # args: should be ".t element configure name ?option? ?value option value ...?"}

test element-3.2 {element configure: unknown elem} -body {
    .t element configure foo
} -returnCodes error -result {element "foo" doesn't exist}

###

test element-4.1 {element create: missing arg} -body {
    .t element create
} -returnCodes error -result {wrong # args: should be ".t element create name type ?option value ...?"}

test element-4.2 {element create: empty type} -body {
    .t element create foo ""
} -returnCodes error -result {invalid element type ""}

test element-4.3 {element create: ambiguous type} -body {
    .t element create foo b ; # bitmap or border
} -returnCodes error -result {ambiguous element type "b"}

test element-4.4 {element create: unknown type} -body {
    .t element create foo bar
} -returnCodes error -result {unknown element type "bar"}

###

test element-5.1 {element delete: no args} -body {
    .t element delete
} -result {}

test element-5.2 {element delete: unknown elem} -body {
    .t element delete foo
} -returnCodes error -result {element "foo" doesn't exist}

test element-5.3 {element delete: single elem} -setup {
    .t element create e1 bitmap
} -body {
    .t element delete e1
    .t element names
} -result {}

test element-5.4 {element delete: multiple elems} -setup {
    foreach type [list bitmap border image rect text window] {
	.t element create e$type $type
    }
} -body {
    eval .t element delete [.t element names]
    .t element names
} -result {}

###

test element-6.1 {element names: too many args} -body {
    .t element names a
} -returnCodes error -result {wrong # args: should be ".t element names"}

###

test element-7.1 {element perstate: missing arg} -body {
    .t element perstate
} -returnCodes error -result {wrong # args: should be ".t element perstate element option stateList"}

test element-7.2 {element perstate: too many args} -body {
    .t element perstate a b c d
} -returnCodes error -result {wrong # args: should be ".t element perstate element option stateList"}

test element-7.3 {element perstate: empty stateList} -setup {
    .t element create eText text -fill {red !selected blue {}}
} -body {
    .t element perstate eText -fill {}
} -result {red}

test element-7.4 {element perstate: non-empty statelist} -body {
    .t element perstate eText -fill {selected}
} -result {blue}

###

test element-8.1 {element type: missing arg} -body {
    .t element type
} -returnCodes error -result {wrong # args: should be ".t element type name"}

test element-8.2 {element type: too many args} -body {
    .t element type a b
} -returnCodes error -result {wrong # args: should be ".t element type name"}

test element-8.3 {element type: unknown elem} -body {
    .t element type foo
} -returnCodes error -result {element "foo" doesn't exist}

test element-8.4 {element type: success} -body {
    .t element type eText
} -result {text}

test element-99.1 {some needed cleanup} -body {
    destroy .t
} -result {}

# cleanup
::tcltest::cleanupTests
return