# # ttk::combobox widget tests # package require tk package require tcltest 2.2 namespace import -force tcltest::* loadTestedCommands test combobox-1.0 "Combobox tests -- setup" -body { ttk::combobox .cb } -result .cb test combobox-1.1 "Bad -values list" -body { .cb configure -values "bad \{list" } -result "unmatched open brace in list" -returnCodes error test combobox-1.end "Combobox tests -- cleanup" -body { destroy .cb } test combobox-2.0 "current command" -body { ttk::combobox .cb -values [list a b c d e a] expr {[.cb current]<0} } -result 1 test combobox-2.1 "current -- set index" -body { .cb current 5 .cb get } -result a test combobox-2.2 "current -- change -values" -body { .cb configure -values [list c b a d e] .cb current } -result 2 test combobox-2.3 "current -- change value" -body { .cb set "b" .cb current } -result 1 test combobox-2.4 "current -- value not in list" -body { .cb set "z" expr {[.cb current]<0} } -result 1 test combobox-2.5 "current -- set to end index" -body { .cb configure -values [list a b c d e thelastone] .cb current end .cb get } -result thelastone test combobox-2.6 "current -- set to unknown index" -body { .cb configure -values [list a b c d e] .cb current notanindex } -returnCodes error -result {bad index "notanindex"} test combobox-2.7 {current -- set to 0 index when empty [bug 924835c36d]} -body { .cb configure -values {} .cb current 0 } -returnCodes error -result {index "0" out of range} test combobox-2.8 "current -- set to end index in an empty combobox" -body { .cb configure -values {} .cb current end } -returnCodes error -result {index "end" out of range} test combobox-2.end "Cleanup" -body { destroy .cb } test combobox-3 "Read postoffset value dynamically from current style" -body { ttk::combobox .cb -values [list a b c] -style "DerivedStyle.TCombobox" pack .cb -expand true -fill both update idletasks ttk::style configure DerivedStyle.TCombobox -postoffset [list 25 0 0 0] if {[tk windowingsystem] == "aqua"} { after 500 { pressbutton [expr {[winfo rootx .cb] + 25}] [expr {[winfo rooty .cb] + 25}] } } ttk::combobox::Post .cb expr {[winfo rootx .cb.popdown] - [winfo rootx .cb]} } -result 25 -cleanup { destroy .cb } test combobox-1890211 "ComboboxSelected event after listbox unposted" \ -constraints {notAqua} -body { # whitebox test... pack [ttk::combobox .cb -values [list a b c]] update idletasks set result [list] bind .cb <> { lappend result Event [winfo ismapped .cb.popdown] [.cb get] } lappend result Start 0 [.cb get] ttk::combobox::Post .cb lappend result Post [winfo ismapped .cb.popdown] [.cb get] .cb.popdown.f.l selection clear 0 end; .cb.popdown.f.l selection set 1 ttk::combobox::LBSelected .cb.popdown.f.l lappend result Select [winfo ismapped .cb.popdown] [.cb get] update set result } -result [list Start 0 {} Post 1 {} Select 0 b Event 0 b] -cleanup { destroy .cb } test combobox-4.1 "style command" -body { ttk::combobox .w list [.w cget -style] [.w style] [winfo class .w] } -cleanup { destroy .w } -result {{} TCombobox TCombobox} test combobox-4.2 "style command" -body { ttk::style configure customStyle.TCombobox ttk::combobox .w -style customStyle.TCombobox list [.w cget -style] [.w style] [winfo class .w] } -cleanup { destroy .w } -result {customStyle.TCombobox customStyle.TCombobox TCombobox} tcltest::cleanupTests