# 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.

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
