# Test the "tk::fontchooser" command # # Copyright © 2008 Pat Thoyts # # TESTFILE INITIALIZATION # package require tcltest 2.2; # needed in mode -singleproc 0 # Load the main script main.tcl, which takes care of: # - setup for the application and the root window # - importing commands from the tcltest namespace # - loading of the testutils mechanism along with its utility procs # - loading of Tk specific test constraints (additionally to constraints # provided by the package tcltest) source [file join [tcltest::configure -testdir] main.tcl] # Ensure a pristine initial window state resetWindows # Import utility procs for specific functional areas testutils import dialog set applyFontCmd [list set testDialogFont] # # LOCAL TEST CONSTRAINTS # # The tk fontchooser call below autoloads fontchooser.tcl on platforms # that don't provide a native implementation of the font selection dialog. # This will make ::tk::fontchooser::Configure exist, and scriptImpl become true, # indicating use of the scripted implementation of the dialog. Platforms using # the native dialog do not define a ::tk::fontchooser::Configure proc. catch {tk fontchooser} testConstraint scriptImpl [llength [info proc ::tk::fontchooser::Configure]] # # TESTS # test fontchooser-1.1 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser -z } -result {unknown or ambiguous subcommand "-z": must be configure, hide, or show} test fontchooser-1.2 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -z } -match glob -result {bad option "-z":*} test fontchooser-1.3 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -parent . -font } -result {value for "-font" missing} test fontchooser-1.4 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -parent . -title } -result {value for "-title" missing} test fontchooser-1.5 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -parent . -command } -result {value for "-command" missing} test fontchooser-1.6 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -title . -parent } -result {value for "-parent" missing} test fontchooser-1.7 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -parent abc } -result {bad window path name "abc"} test fontchooser-1.8 {tk fontchooser: usage} -returnCodes ok -body { tk fontchooser configure -visible } -result 0 test fontchooser-1.9 {tk fontchooser: usage} -returnCodes error -body { tk fontchooser configure -visible 1 } -match glob -result {*} # # The remaining tests in this file are only relevant for the script # implementation. They can be tested by sourcing the script file but # the Tk tests are run with -singleproc 1 and doing this affects the # result of later attempts to test the native implementations. # test fontchooser-2.0 {fontchooser -title} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -title "Hello" tk::fontchooser::Show } testDialog onDisplay { set x [wm title $testDialog] Click cancel } set x } -result {Hello} test fontchooser-2.1 {fontchooser -title (cyrillic)} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure \ -title "Привет" tk::fontchooser::Show } testDialog onDisplay { set x [wm title $testDialog] Click cancel } set x } -result "Привет" test fontchooser-3.0 {fontchooser -parent} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -parent . tk::fontchooser::Show } testDialog onDisplay { set x [winfo parent $testDialog] Click cancel } set x } -result {.} test fontchooser-3.1 {fontchooser -parent (invalid)} -constraints scriptImpl -body { tk::fontchooser::Configure -parent junk } -returnCodes error -match glob -result {bad window path *} test fontchooser-4.0 {fontchooser -font} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -command $applyFontCmd -font courier tk::fontchooser::Show } testDialog onDisplay { Click cancel } set testDialogFont } -result {} test fontchooser-4.1 {fontchooser -font} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -command $applyFontCmd -font courier tk::fontchooser::Show } testDialog onDisplay { Click ok } expr {$testDialogFont ne {}} } -result 1 test fontchooser-4.2 {fontchooser -font} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -command $applyFontCmd -font TkDefaultFont tk::fontchooser::Show } testDialog onDisplay { Click ok } expr {$testDialogFont ne {}} } -result 1 test fontchooser-4.3 {fontchooser -font} -constraints scriptImpl -body { testDialog launch { tk::fontchooser::Configure -command $applyFontCmd -font {times 14 bold} tk::fontchooser::Show } testDialog onDisplay { Click ok } expr {$testDialogFont ne {}} } -result 1 test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl havePointsize14BoldFont} -body { testDialog launch { tk::fontchooser::Configure -command $applyFontCmd -font {times 14 bold} tk::fontchooser::Show } testDialog onDisplay { Click ok } lrange $testDialogFont 1 end } -result {14 bold} test fontchooser-5.1 {fontchooser multiple configure} -constraints {scriptImpl} -body { tk fontchooser configure -title TestTitle -command foo tk fontchooser configure -command bar tk fontchooser configure -title } -result {TestTitle} # # TESTFILE CLEANUP # unset applyFontCmd testutils forget dialog cleanupTests # Local Variables: # mode: tcl # indent-tabs-mode: nil # End: