1# This file is a Tcl script to test the tk command. 2# It is organized in the standard fashion for Tcl tests. 3# 4# Copyright (c) 1997 Sun Microsystems, Inc. 5# Copyright (c) 1998-1999 by Scriptics Corporation. 6# Copyright (c) 2002 ActiveState Corporation. 7# 8# RCS: @(#) $Id: tk.test,v 1.9 2002/09/02 19:15:38 hobbs Exp $ 9 10package require tcltest 2.1 11namespace import -force tcltest::configure 12namespace import -force tcltest::testsDirectory 13configure -testdir [file join [pwd] [file dirname [info script]]] 14configure -loadfile [file join [testsDirectory] constraints.tcl] 15tcltest::loadTestedCommands 16 17test tk-1.1 {tk command: general} { 18 list [catch {tk} msg] $msg 19} {1 {wrong # args: should be "tk option ?arg?"}} 20test tk-1.2 {tk command: general} { 21 list [catch {tk xyz} msg] $msg 22} {1 {bad option "xyz": must be appname, caret, scaling, useinputmethods, or windowingsystem}} 23 24set appname [tk appname] 25test tk-2.1 {tk command: appname} { 26 list [catch {tk appname xyz abc} msg] $msg 27} {1 {wrong # args: should be "tk appname ?newName?"}} 28test tk-2.2 {tk command: appname} { 29 tk appname foobazgarply 30} {foobazgarply} 31test tk-2.3 {tk command: appname} {unixOnly} { 32 tk appname bazfoogarply 33 expr {[lsearch -exact [winfo interps] [tk appname]] >= 0} 34} {1} 35test tk-2.4 {tk command: appname} { 36 tk appname $appname 37} $appname 38tk appname $appname 39 40set scaling [tk scaling] 41test tk-3.1 {tk command: scaling} { 42 list [catch {tk scaling -displayof} msg] $msg 43} {1 {value for "-displayof" missing}} 44test tk-3.2 {tk command: scaling: get current} { 45 tk scaling 1 46 format %.2g [tk scaling] 47} 1 48test tk-3.3 {tk command: scaling: get current} { 49 tk scaling -displayof . 1.25 50 format %.3g [tk scaling] 51} 1.25 52test tk-3.4 {tk command: scaling: set new} { 53 list [catch {tk scaling xyz} msg] $msg 54} {1 {expected floating-point number but got "xyz"}} 55test tk-3.5 {tk command: scaling: set new} { 56 list [catch {tk scaling -displayof . xyz} msg] $msg 57} {1 {expected floating-point number but got "xyz"}} 58test tk-3.6 {tk command: scaling: set new} { 59 tk scaling 1 60 format %.2g [tk scaling] 61} 1 62test tk-3.7 {tk command: scaling: set new} { 63 tk scaling -displayof . 1.25 64 format %.3g [tk scaling] 65} 1.25 66test tk-3.8 {tk command: scaling: negative} { 67 tk scaling -1 68 expr {[tk scaling] > 0} 69} {1} 70test tk-3.9 {tk command: scaling: too big} { 71 tk scaling 1000000 72 expr {[tk scaling] < 10000} 73} {1} 74test tk-3.10 {tk command: scaling: widthmm} { 75 tk scaling 1.25 76 expr {int((25.4*[winfo screenwidth .])/(72*1.25)+0.5)-[winfo screenmmwidth .]} 77} {0} 78test tk-3.11 {tk command: scaling: heightmm} { 79 tk scaling 1.25 80 expr {int((25.4*[winfo screenheight .])/(72*1.25)+0.5)-[winfo screenmmheight .]} 81} {0} 82tk scaling $scaling 83 84set useim [tk useinputmethods] 85test tk-4.1 {tk command: useinputmethods} { 86 list [catch {tk useinputmethods -displayof} msg] $msg 87} {1 {value for "-displayof" missing}} 88test tk-4.2 {tk command: useinputmethods: get current} { 89 tk useinputmethods no 90} 0 91test tk-4.3 {tk command: useinputmethods: get current} { 92 tk useinputmethods -displayof . 93} 0 94test tk-4.4 {tk command: useinputmethods: set new} { 95 list [catch {tk useinputmethods xyz} msg] $msg 96} {1 {expected boolean value but got "xyz"}} 97test tk-4.5 {tk command: useinputmethods: set new} { 98 list [catch {tk useinputmethods -displayof . xyz} msg] $msg 99} {1 {expected boolean value but got "xyz"}} 100test tk-4.6 {tk command: useinputmethods: set new} {unixOnly} { 101 # This isn't really a test, but more of a check... 102 # The answer is what was given, because we may be on a Unix 103 # system that doesn't have the XIM stuff 104 if {[tk useinputmethods 1] == 0} { 105 puts "this wish doesn't have XIM (X Input Methods) support" 106 } 107 set useim 108} $useim 109test tk-4.7 {tk command: useinputmethods: set new} {macOrPc} { 110 # Mac and Windows don't have X Input Methods, so this should 111 # always return 0 112 tk useinputmethods 1 113} 0 114tk useinputmethods $useim 115 116test tk-5.1 {tk caret} { 117 list [catch {tk caret} msg] $msg 118} {1 {wrong # args: should be "tk caret window ?-x x? ?-y y? ?-height height?"}} 119test tk-5.2 {tk caret} { 120 list [catch {tk caret bogus} msg] $msg 121} {1 {bad window path name "bogus"}} 122test tk-5.3 {tk caret} { 123 list [catch {tk caret . -foo} msg] $msg 124} {1 {bad caret option "-foo": must be -x, -y, or -height}} 125test tk-5.4 {tk caret} { 126 list [catch {tk caret . -x 0 -y} msg] $msg 127} {1 {wrong # args: should be "tk caret window ?-x x? ?-y y? ?-height height?"}} 128test tk-5.5 {tk caret} { 129 list [catch {tk caret . -x 10 -y 11 -h 12; tk caret .} msg] $msg 130} {0 {-height 12 -x 10 -y 11}} 131test tk-5.6 {tk caret} { 132 list [catch {tk caret . -x 20 -y 25 -h 30; tk caret . -hei} msg] $msg 133} {0 30} 134 135# cleanup 136::tcltest::cleanupTests 137return 138