config.test
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:36k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # This file is a Tcl script to test the procedures in tkConfig.c,
  2. # which comprise the new new option configuration system.  It is
  3. # organized in the standard "white-box" fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1997 Sun Microsystems, Inc.
  6. # Copyright (c) 1998-1999 by Scriptics Corporation.
  7. # All rights reserved.
  8. #
  9. # RCS: @(#) $Id: config.test,v 1.6 2002/07/14 05:48:46 dgp Exp $
  10. package require tcltest 2.1
  11. namespace import -force tcltest::configure
  12. namespace import -force tcltest::testsDirectory
  13. configure -testdir [file join [pwd] [file dirname [info script]]]
  14. configure -loadfile [file join [testsDirectory] constraints.tcl]
  15. tcltest::loadTestedCommands
  16. testConstraint testobjconfig [llength [info commands testobjconfig]]
  17. proc killTables {} {
  18.     # Note: it's important to delete chain2 before chain1, because
  19.     # chain2 depends on chain1.  If chain1 is deleted first, the
  20.     # delete of chain2 will crash.
  21.     foreach t {alltypes chain2 chain1 configerror internal new notenoughparams
  22.     twowindows} {
  23. while {[testobjconfig info $t] != ""} {
  24.     testobjconfig delete $t
  25. }
  26.     }
  27. }
  28. if {[testConstraint testobjconfig]} {
  29.     killTables
  30. }
  31. test config-1.1 {Tk_CreateOptionTable - reference counts} testobjconfig {
  32.     deleteWindows
  33.     killTables
  34.     set x {}
  35.     testobjconfig alltypes .a
  36.     lappend x [testobjconfig info alltypes]
  37.     testobjconfig alltypes .b
  38.     lappend x [testobjconfig info alltypes]
  39.     deleteWindows
  40.     set x
  41. } {{1 16 -boolean} {2 16 -boolean}}
  42. test config-1.2 {Tk_CreateOptionTable - synonym initialization} testobjconfig {
  43.     deleteWindows
  44.     testobjconfig alltypes .a -synonym green
  45.     .a cget -color
  46. } {green}
  47. test config-1.3 {Tk_CreateOptionTable - option database initialization} testobjconfig {
  48.     deleteWindows
  49.     option clear
  50.     testobjconfig alltypes .a
  51.     option add *b.string different
  52.     testobjconfig alltypes .b
  53.     list [.a cget -string] [.b cget -string]
  54. } {foo different}
  55. test config-1.4 {Tk_CreateOptionTable - option database initialization} testobjconfig {
  56.     deleteWindows
  57.     option clear
  58.     testobjconfig alltypes .a
  59.     option add *b.String bar
  60.     testobjconfig alltypes .b
  61.     list [.a cget -string] [.b cget -string]
  62. } {foo bar}
  63. test config-1.5 {Tk_CreateOptionTable - default initialization} testobjconfig {
  64.     deleteWindows
  65.     testobjconfig alltypes .a
  66.     .a cget -relief
  67. } {raised}
  68. test config-1.6 {Tk_CreateOptionTable - chained tables} testobjconfig {
  69.     deleteWindows
  70.     killTables
  71.     testobjconfig chain1 .a
  72.     testobjconfig chain2 .b
  73.     testobjconfig info chain2
  74. } {1 4 -three 2 2 -one}
  75. test config-1.7 {Tk_CreateOptionTable - chained tables} testobjconfig {
  76.     deleteWindows
  77.     killTables
  78.     testobjconfig chain2 .b
  79.     testobjconfig chain1 .a
  80.     testobjconfig info chain2
  81. } {1 4 -three 2 2 -one}
  82. test config-1.8 {Tk_CreateOptionTable - chained tables} testobjconfig {
  83.     deleteWindows
  84.     testobjconfig chain1 .a
  85.     testobjconfig chain2 .b
  86.     list [catch {.a cget -four} msg] $msg [.a cget -one] 
  87.     [.b cget -four] [.b cget -one]
  88. } {1 {unknown option "-four"} one four one}
  89. test config-2.1 {Tk_DeleteOptionTable - reference counts} testobjconfig {
  90.     deleteWindows
  91.     killTables
  92.     testobjconfig chain1 .a
  93.     testobjconfig chain2 .b
  94.     testobjconfig chain2 .c
  95.     deleteWindows
  96.     set x {}
  97.     testobjconfig delete chain2
  98.     lappend x [testobjconfig info chain2] [testobjconfig info chain1]
  99.     testobjconfig delete chain2
  100.     lappend x [testobjconfig info chain2] [testobjconfig info chain1]
  101. } {{1 4 -three 2 2 -one} {2 2 -one} {} {1 2 -one}}
  102. # No tests for DestroyOptionHashTable; couldn't figure out how to test.
  103. test config-3.1 {Tk_InitOptions - priority of chained tables} testobjconfig {
  104.     deleteWindows
  105.     testobjconfig chain1 .a
  106.     testobjconfig chain2 .b
  107.     list [.a cget -two] [.b cget -two]
  108. } {two {two and a half}}
  109. test config-3.2 {Tk_InitOptions - initialize from database} testobjconfig {
  110.     deleteWindows
  111.     option clear
  112.     option add *a.color blue
  113.     testobjconfig alltypes .a
  114.     list [.a cget -color]
  115. } {blue}
  116. test config-3.3 {Tk_InitOptions - initialize from database} testobjconfig {
  117.     deleteWindows
  118.     option clear
  119.     option add *a.justify bogus
  120.     testobjconfig alltypes .a
  121.     list [.a cget -justify]
  122. } {left}
  123. test config-3.4 {Tk_InitOptions - initialize from widget class} testobjconfig {
  124.     deleteWindows
  125.     testobjconfig alltypes .a
  126.     list [.a cget -color]
  127. } {red}
  128. test config-3.5 {Tk_InitOptions - no initial value} testobjconfig {
  129.     deleteWindows
  130.     testobjconfig alltypes .a
  131.     .a cget -anchor
  132. } {}
  133. test config-3.6 {Tk_InitOptions - bad initial value} testobjconfig {
  134.     deleteWindows
  135.     option clear
  136.     option add *a.color non-existent
  137.     list [catch {testobjconfig alltypes .a} msg] $msg $errorInfo
  138. } {1 {unknown color name "non-existent"} {unknown color name "non-existent"
  139.     (database entry for "-color" in widget ".a")
  140.     invoked from within
  141. "testobjconfig alltypes .a"}}
  142. option clear
  143. test config-3.7 {Tk_InitOptions - bad initial value} testobjconfig {
  144.     deleteWindows
  145.     list [catch {testobjconfig configerror} msg] $msg $errorInfo
  146. } {1 {expected integer but got "bogus"} {expected integer but got "bogus"
  147.     (default value for "-int")
  148.     invoked from within
  149. "testobjconfig configerror"}}
  150. option clear
  151. test config-4.1 {DoObjConfig - boolean} testobjconfig {
  152.     catch {rename .foo {}}
  153.     list [catch {testobjconfig alltypes .foo -boolean 0} msg] $msg [catch {.foo cget -boolean} result] $result [catch {rename .foo {}}]
  154. } {0 .foo 0 0 0}
  155. test config-4.2 {DoObjConfig - boolean} testobjconfig {
  156.     catch {rename .foo {}}
  157.     list [catch {testobjconfig alltypes .foo -boolean 1} msg] $msg [catch {.foo cget -boolean} result] $result [catch {rename .foo {}}]
  158. } {0 .foo 0 1 0}
  159. test config-4.3 {DoObjConfig - invalid boolean} testobjconfig {
  160.     catch {rename .foo {}}
  161.     list [catch {testobjconfig alltypes .foo -boolean {}} msg] $msg
  162. } {1 {expected boolean value but got ""}}
  163. test config-4.4 {DoObjConfig - boolean internal value} testobjconfig {
  164.     catch {rename .foo {}}
  165.     testobjconfig internal .foo -boolean 0
  166.     .foo cget -boolean
  167. } {0}
  168. test config-4.5 {DoObjConfig - integer} testobjconfig {
  169.     catch {rename .foo {}}
  170.     list [catch {testobjconfig alltypes .foo -integer 3} msg] $msg [catch {.foo cget -integer} result] $result [catch {rename .foo {}}]
  171. } {0 .foo 0 3 0}
  172. test config-4.6 {DoObjConfig - invalid integer} testobjconfig {
  173.     catch {rename .foo {}}
  174.     list [catch {testobjconfig alltypes .foo -integer bar} msg] $msg
  175. } {1 {expected integer but got "bar"}}
  176. test config-4.7 {DoObjConfig - integer internal value} testobjconfig {
  177.     catch {rename .foo {}}
  178.     testobjconfig internal .foo -integer 421
  179.     .foo cget -integer
  180. } {421}
  181. test config-4.8 {DoObjConfig - double} testobjconfig {
  182.     catch {rename .foo {}}
  183.     list [catch {testobjconfig alltypes .foo -double 3.14} msg] $msg [catch {.foo cget -double} result] $result [catch {rename .foo {}}]
  184. } {0 .foo 0 3.14 0}
  185. test config-4.9 {DoObjConfig - invalid double} testobjconfig {
  186.     catch {rename .foo {}}
  187.     list [catch {testobjconfig alltypes .foo -double bar} msg] $msg
  188. } {1 {expected floating-point number but got "bar"}}
  189. test config-4.10 {DoObjConfig - double internal value} testobjconfig {
  190.     catch {rename .foo {}}
  191.     testobjconfig internal .foo -double 62.75
  192.     .foo cget -double
  193. } {62.75}
  194. test config-4.11 {DoObjConfig - string} testobjconfig {
  195.     catch {destroy .foo}
  196.     list [catch {testobjconfig alltypes .foo -string test} msg] $msg [catch {.foo cget -string} result] $result [destroy .foo]
  197. } {0 .foo 0 test {}}
  198. test config-4.12 {DoObjConfig - null string} testobjconfig {
  199.     catch {destroy .foo}
  200.     list [catch {testobjconfig alltypes .foo -string {}} msg] $msg [catch {.foo cget -string} result] $result [destroy .foo]
  201. } {0 .foo 0 {} {}}
  202. test config-4.13 {DoObjConfig - string internal value} testobjconfig {
  203.     catch {rename .foo {}}
  204.     testobjconfig internal .foo -string "this is a test"
  205.     .foo cget -string
  206. } {this is a test}
  207. test config-4.14 {DoObjConfig - string table} testobjconfig {
  208.     catch {destroy .foo}
  209.     list [catch {testobjconfig alltypes .foo -stringtable two} msg] $msg [catch {.foo cget -stringtable} result] $result [destroy .foo]
  210. } {0 .foo 0 two {}}
  211. test config-4.15 {DoObjConfig - invalid string table} testobjconfig {
  212.     catch {destroy .foo}
  213.     list [catch {testobjconfig alltypes .foo -stringtable foo} msg] $msg
  214. } {1 {bad stringtable "foo": must be one, two, three, or four}}
  215. test config-4.16 {DoObjConfig - new string table} testobjconfig {
  216.     catch {destroy .foo}
  217.     testobjconfig alltypes .foo -stringtable two
  218.     list [catch {.foo configure -stringtable three} msg] $msg [catch {.foo cget -stringtable} result] $result [destroy .foo]
  219. } {0 16 0 three {}}
  220. test config-4.17 {DoObjConfig - stringtable internal value} testobjconfig {
  221.     catch {rename .foo {}}
  222.     testobjconfig internal .foo -stringtable "four"
  223.     .foo cget -stringtable
  224. } {four}
  225. test config-4.18 {DoObjConfig - color} testobjconfig {
  226.     catch {rename .foo {}}
  227.     list [catch {testobjconfig alltypes .foo -color blue} msg] $msg [catch {.foo cget -color} result] $result [destroy .foo]
  228. } {0 .foo 0 blue {}}
  229. test config-4.19 {DoObjConfig - invalid color} testobjconfig {
  230.     catch {destroy .foo}
  231.     list [catch {testobjconfig alltypes .foo -color xxx} msg] $msg
  232. } {1 {unknown color name "xxx"}}
  233. test config-4.20 {DoObjConfig - color internal value} testobjconfig {
  234.     catch {rename .foo {}}
  235.     testobjconfig internal .foo -color purple
  236.     .foo cget -color
  237. } {purple}
  238. test config-4.21 {DoObjConfig - null color} testobjconfig {
  239.     catch {rename .foo {}}
  240.     list [catch {testobjconfig alltypes .foo -color {}} msg] $msg [catch {.foo cget -color} result] $result [destroy .foo]
  241. } {0 .foo 0 {} {}}
  242. test config-4.22 {DoObjConfig - getting rid of old color} testobjconfig {
  243.     catch {destroy .foo}
  244.     testobjconfig alltypes .foo -color #333333
  245.     list [catch {.foo configure -color #444444} msg] $msg [catch {.foo cget -color} result] $result [destroy .foo]
  246. } {0 32 0 #444444 {}}
  247. test config-4.23 {DoObjConfig - font} testobjconfig {
  248.     catch {rename .foo {}}
  249.     list [catch {testobjconfig alltypes .foo -font {Helvetica 72}} msg] $msg [catch {.foo cget -font} result] $result [destroy .foo]
  250. } {0 .foo 0 {Helvetica 72} {}}
  251. test config-4.24 {DoObjConfig - new font} testobjconfig {
  252.     catch {rename .foo {}}
  253.     testobjconfig alltypes .foo -font {Courier 12}
  254.     list [catch {.foo configure -font {Helvetica 72}} msg] $msg [catch {.foo cget -font} result] $result [destroy .foo]
  255. } {0 64 0 {Helvetica 72} {}}
  256. test config-4.25 {DoObjConfig - invalid font} testobjconfig {
  257.     catch {rename .foo {}}
  258.     list [catch {testobjconfig alltypes .foo -font {Helvetica 12 foo}} msg] $msg
  259. } {1 {unknown font style "foo"}}
  260. test config-4.26 {DoObjConfig - null font} testobjconfig {
  261.     catch {rename .foo {}}
  262.     list [catch {testobjconfig alltypes .foo -font {}} msg] $msg [catch {.foo cget -font} result] $result [destroy .foo]
  263. } {0 .foo 0 {} {}}
  264. test config-4.27 {DoObjConfig - font internal value} testobjconfig {
  265.     catch {rename .foo {}}
  266.     testobjconfig internal .foo -font {Times 16}
  267.     .foo cget -font
  268. } {Times 16}
  269. test config-4.28 {DoObjConfig - bitmap} testobjconfig {
  270.     catch {destroy .foo}
  271.     list [catch {testobjconfig alltypes .foo -bitmap gray75} msg] $msg [catch {.foo cget -bitmap} result] $result [destroy .foo]
  272. } {0 .foo 0 gray75 {}}
  273. test config-4.29 {DoObjConfig - new bitmap} testobjconfig {
  274.     catch {destroy .foo}
  275.     testobjconfig alltypes .foo -bitmap gray75
  276.     list [catch {.foo configure -bitmap gray50} msg] $msg [catch {.foo cget -bitmap} result] $result [destroy .foo]
  277. } {0 128 0 gray50 {}}
  278. test config-4.30 {DoObjConfig - invalid bitmap} testobjconfig {
  279.     catch {destroy .foo}
  280.     list [catch {testobjconfig alltypes .foo -bitmap foo} msg] $msg
  281. } {1 {bitmap "foo" not defined}}
  282. test config-4.31 {DoObjConfig - null bitmap} testobjconfig {
  283.     catch {destroy .foo}
  284.     list [catch {testobjconfig alltypes .foo -bitmap {}} msg] $msg [catch {.foo cget -bitmap} result] $result [destroy .foo]
  285. } {0 .foo 0 {} {}}
  286. test config-4.32 {DoObjConfig - bitmap internal value} testobjconfig {
  287.     catch {rename .foo {}}
  288.     testobjconfig internal .foo -bitmap gray25
  289.     .foo cget -bitmap
  290. } {gray25}
  291. test config-4.33 {DoObjConfig - border} testobjconfig {
  292.     catch {rename .foo {}}
  293.     list [catch {testobjconfig alltypes .foo -border green} msg] $msg [catch {.foo cget -border} result] $result [destroy .foo]
  294. } {0 .foo 0 green {}}
  295. test config-4.34 {DoObjConfig - invalid border} testobjconfig {
  296.     catch {destroy .foo}
  297.     list [catch {testobjconfig alltypes .foo -border xxx} msg] $msg
  298. } {1 {unknown color name "xxx"}}
  299. test config-4.35 {DoObjConfig - null border} testobjconfig {
  300.     catch {rename .foo {}}
  301.     list [catch {testobjconfig alltypes .foo -border {}} msg] $msg [catch {.foo cget -border} result] $result [destroy .foo]
  302. } {0 .foo 0 {} {}}
  303. test config-4.36 {DoObjConfig - border internal value} testobjconfig {
  304.     catch {rename .foo {}}
  305.     testobjconfig internal .foo -border #123456
  306.     .foo cget -border
  307. } {#123456}
  308. test config-4.37 {DoObjConfig - getting rid of old border} testobjconfig {
  309.     catch {destroy .foo}
  310.     testobjconfig alltypes .foo -border #333333
  311.     list [catch {.foo configure -border #444444} msg] $msg [catch {.foo cget -border} result] $result [destroy .foo]
  312. } {0 256 0 #444444 {}}
  313. test config-4.38 {DoObjConfig - relief} testobjconfig {
  314.     catch {destroy .foo}
  315.     list [catch {testobjconfig alltypes .foo -relief flat} msg] $msg [catch {.foo cget -relief} result] $result [destroy .foo]
  316. } {0 .foo 0 flat {}}
  317. test config-4.39 {DoObjConfig - invalid relief} testobjconfig {
  318.     catch {destroy .foo}
  319.     list [catch {testobjconfig alltypes .foo -relief foo} msg] $msg
  320. } {1 {bad relief "foo": must be flat, groove, raised, ridge, solid, or sunken}}
  321. test config-4.40 {DoObjConfig - new relief} testobjconfig {
  322.     catch {destroy .foo}
  323.     testobjconfig alltypes .foo -relief raised
  324.     list [catch {.foo configure -relief flat} msg] $msg [catch {.foo cget -relief} result] $result [destroy .foo]
  325. } {0 512 0 flat {}}
  326. test config-4.41 {DoObjConfig - relief internal value} testobjconfig {
  327.     catch {rename .foo {}}
  328.     testobjconfig internal .foo -relief ridge
  329.     .foo cget -relief
  330. } {ridge}
  331. test config-4.42 {DoObjConfig - cursor} testobjconfig {
  332.     catch {destroy .foo}
  333.     list [catch {testobjconfig alltypes .foo -cursor arrow} msg] $msg [catch {.foo cget -cursor} result] $result [destroy .foo]
  334. } {0 .foo 0 arrow {}}
  335. test config-4.43 {DoObjConfig - invalid cursor} testobjconfig {
  336.     catch {destroy .foo}
  337.     list [catch {testobjconfig alltypes .foo -cursor foo} msg] $msg
  338. } {1 {bad cursor spec "foo"}}
  339. test config-4.44 {DoObjConfig - null cursor} testobjconfig {
  340.     catch {destroy .foo}
  341.     list [catch {testobjconfig alltypes .foo -cursor {}} msg] $msg [catch {.foo cget -cursor} result] $result [destroy .foo]
  342. } {0 .foo 0 {} {}}
  343. test config-4.45 {DoObjConfig - new cursor} testobjconfig {
  344.     catch {destroy .foo}
  345.     testobjconfig alltypes .foo -cursor xterm
  346.     list [catch {.foo configure -cursor arrow} msg] $msg [catch {.foo cget -cursor} result] $result [destroy .foo]
  347. } {0 1024 0 arrow {}}
  348. test config-4.46 {DoObjConfig - cursor internal value} testobjconfig {
  349.     catch {rename .foo {}}
  350.     testobjconfig internal .foo -cursor watch
  351.     .foo cget -cursor
  352. } {watch}
  353. test config-4.47 {DoObjConfig - justify} testobjconfig {
  354.     catch {destroy .foo}
  355.     list [catch {testobjconfig alltypes .foo -justify center} msg] $msg [catch {.foo cget -justify} result] $result [destroy .foo]
  356. } {0 .foo 0 center {}}
  357. test config-4.48 {DoObjConfig - invalid justify} testobjconfig {
  358.     catch {destroy .foo}
  359.     list [catch {testobjconfig alltypes .foo -justify foo} msg] $msg
  360. } {1 {bad justification "foo": must be left, right, or center}}
  361. test config-4.49 {DoObjConfig - new justify} testobjconfig {
  362.     catch {destroy .foo}
  363.     testobjconfig alltypes .foo -justify left
  364.     list [catch {.foo configure -justify right} msg] $msg [catch {.foo cget -justify} result] $result [destroy .foo]
  365. } {0 2048 0 right {}}
  366. test config-4.50 {DoObjConfig - justify internal value} testobjconfig {
  367.     catch {rename .foo {}}
  368.     testobjconfig internal .foo -justify center
  369.     .foo cget -justify
  370. } {center}
  371. test config-4.51 {DoObjConfig - anchor} testobjconfig {
  372.     catch {destroy .foo}
  373.     list [catch {testobjconfig alltypes .foo -anchor center} msg] $msg [catch {.foo cget -anchor} result] $result [destroy .foo]
  374. } {0 .foo 0 center {}}
  375. test config-4.52 {DoObjConfig - invalid anchor} testobjconfig {
  376.     catch {destroy .foo}
  377.     list [catch {testobjconfig alltypes .foo -anchor foo} msg] $msg
  378. } {1 {bad anchor "foo": must be n, ne, e, se, s, sw, w, nw, or center}}
  379. test config-4.53 {DoObjConfig - new anchor} testobjconfig {
  380.     catch {destroy .foo}
  381.     testobjconfig alltypes .foo -anchor e
  382.     list [catch {.foo configure -anchor n} msg] $msg [catch {.foo cget -anchor} result] $result [destroy .foo]
  383. } {0 4096 0 n {}}
  384. test config-4.54 {DoObjConfig - anchor internal value} testobjconfig {
  385.     catch {rename .foo {}}
  386.     testobjconfig internal .foo -anchor sw
  387.     .foo cget -anchor
  388. } {sw}
  389. test config-4.55 {DoObjConfig - pixel} testobjconfig {
  390.     catch {destroy .foo}
  391.     list [catch {testobjconfig alltypes .foo -pixel 42} msg] $msg [catch {.foo cget -pixel} result] $result [destroy .foo]
  392. } {0 .foo 0 42 {}}
  393. test config-4.56 {DoObjConfig - invalid pixel} testobjconfig {
  394.     catch {destroy .foo}
  395.     list [catch {testobjconfig alltypes .foo -pixel foo} msg] $msg
  396. } {1 {bad screen distance "foo"}}
  397. test config-4.57 {DoObjConfig - new pixel} testobjconfig {
  398.     catch {destroy .foo}
  399.     testobjconfig alltypes .foo -pixel 42m
  400.     list [catch {.foo configure -pixel 3c} msg] $msg [catch {.foo cget -pixel} result] $result [destroy .foo]
  401. } {0 8192 0 3c {}}
  402. test config-4.58 {DoObjConfig - pixel internal value} testobjconfig {
  403.     catch {rename .foo {}}
  404.     testobjconfig internal .foo -pixel [winfo screenmmwidth .]m
  405.     .foo cget -pixel
  406. } [winfo screenwidth .]
  407. test config-4.59 {DoObjConfig - window} testobjconfig {
  408.     catch {destroy .foo}
  409.     catch {destroy .bar}
  410.     toplevel .bar
  411.     list [catch {testobjconfig twowindows .foo -window .bar} msg] $msg [catch {.foo cget -window} result] $result [destroy .foo] [destroy .bar]
  412. } {0 .foo 0 .bar {} {}}
  413. test config-4.60 {DoObjConfig - invalid window} testobjconfig {
  414.     catch {destroy .foo}
  415.     toplevel .bar
  416.     list [catch {testobjconfig twowindows .foo -window foo} msg] $msg [destroy .bar]
  417. } {1 {bad window path name "foo"} {}}
  418. test config-4.61 {DoObjConfig - null window} testobjconfig {
  419.     catch {destroy .foo}
  420.     catch {destroy .bar}
  421.     toplevel .bar
  422.     list [catch {testobjconfig twowindows .foo -window {}} msg] $msg [catch {.foo cget -window} result] $result [destroy .foo]
  423. } {0 .foo 0 {} {}}
  424. test config-4.62 {DoObjConfig - new window} testobjconfig {
  425.     catch {destroy .foo}
  426.     catch {destroy .bar}
  427.     catch {destroy .blamph}
  428.     toplevel .bar
  429.     toplevel .blamph
  430.     testobjconfig twowindows .foo -window .bar
  431.     list [catch {.foo configure -window .blamph} msg] $msg [catch {.foo cget -window} result] $result [destroy .foo] [destroy .bar] [destroy .blamph]
  432. } {0 0 0 .blamph {} {} {}}
  433. test config-4.63 {DoObjConfig - window internal value} testobjconfig {
  434.     catch {rename .foo {}}
  435.     testobjconfig internal .foo -window .
  436.     .foo cget -window
  437. } {.}
  438. test config-4.64 {DoObjConfig - releasing old values} testobjconfig {
  439.     # This test doesn't generate a useful value to check; if an
  440.     # error occurs, it will be detected only by memory checking software
  441.     # such as Purify or Tcl's built-in checker.
  442.     catch {rename .foo {}}
  443.     testobjconfig alltypes .foo -string {Test string} -color yellow 
  444.     -font {Courier 18} -bitmap questhead -border green -cursor cross 
  445.     -custom foobar
  446.     .foo configure -string {new string} -color brown 
  447.     -font {Times 8} -bitmap gray75 -border pink -cursor watch 
  448.     -custom barbaz
  449.     concat {}
  450. } {}
  451. test config-4.65 {DoObjConfig - releasing old values} testobjconfig {
  452.     # This test doesn't generate a useful value to check; if an
  453.     # error occurs, it will be detected only by memory checking software
  454.     # such as Purify or Tcl's built-in checker.
  455.     catch {rename .foo {}}
  456.     testobjconfig internal .foo -string {Test string} -color yellow 
  457.     -font {Courier 18} -bitmap questhead -border green -cursor cross 
  458.     -custom foobar
  459.     .foo configure -string {new string} -color brown 
  460.     -font {Times 8} -bitmap gray75 -border pink -cursor watch 
  461.     -custom barbaz
  462.     concat {}
  463. } {}
  464. test config-4.66 {DoObjConfig - custom} testobjconfig {
  465.     catch {destroy .foo}
  466.     list [catch {testobjconfig alltypes .foo -custom test} msg] $msg [catch {.foo cget -custom} result] $result [destroy .foo]
  467. } {0 .foo 0 TEST {}}
  468. test config-4.67 {DoObjConfig - null custom} testobjconfig {
  469.     catch {destroy .foo}
  470.     list [catch {testobjconfig alltypes .foo -custom {}} msg] $msg [catch {.foo cget -custom} result] $result [destroy .foo]
  471. } {0 .foo 0 {} {}}
  472. test config-4.68 {DoObjConfig - custom internal value} testobjconfig {
  473.     catch {rename .foo {}}
  474.     testobjconfig internal .foo -custom "this is a test"
  475.     .foo cget -custom
  476. } {THIS IS A TEST}
  477. test config-5.1 {ObjectIsEmpty - object is already string} testobjconfig {
  478.     catch {destroy .foo}
  479.     testobjconfig alltypes .foo -color [format ""]
  480.     .foo cget -color
  481. } {}
  482. test config-5.2 {ObjectIsEmpty - object is already string} testobjconfig {
  483.     catch {destroy .foo}
  484.     list [catch {testobjconfig alltypes .foo -color [format " "]} msg] $msg
  485. } {1 {unknown color name " "}}
  486. test config-5.3 {ObjectIsEmpty - must convert back to string} testobjconfig {
  487.     catch {destroy .foo}
  488.     testobjconfig alltypes .foo -color [list]
  489.     .foo cget -color
  490. } {}
  491. deleteWindows
  492. if {[testConstraint testobjconfig]} {
  493.     testobjconfig chain2 .a
  494.     testobjconfig alltypes .b
  495. }
  496. test config-6.1 {GetOptionFromObj - cached answer} testobjconfig {
  497.     list [.a cget -three] [.a cget -three]
  498. } {three three}
  499. test config-6.2 {GetOptionFromObj - exact match} testobjconfig {
  500.     .a cget -one
  501. } {one}
  502. test config-6.3 {GetOptionFromObj - abbreviation} testobjconfig {
  503.     .a cget -fo
  504. } {four}
  505. test config-6.4 {GetOptionFromObj - ambiguous abbreviation} testobjconfig {
  506.     list [catch {.a cget -on} msg] $msg
  507. } {1 {unknown option "-on"}}
  508. test config-6.5 {GetOptionFromObj - duplicate options in different tables} testobjconfig {
  509.     .a cget -tw
  510. } {two and a half}
  511. test config-6.6 {GetOptionFromObj - synonym} testobjconfig {
  512.     .b cget -synonym
  513. } {red}
  514. deleteWindows
  515. if {[testConstraint testobjconfig]} {
  516.     testobjconfig alltypes .a
  517. }
  518. test config-7.1 {Tk_SetOptions - basics} testobjconfig {
  519.     .a configure -color green -rel sunken
  520.      list [.a cget -color] [.a cget -relief]
  521. } {green sunken}
  522. test config-7.2 {Tk_SetOptions - bogus option name} testobjconfig {
  523.     list [catch {.a configure -bogus} msg] $msg
  524. } {1 {unknown option "-bogus"}}
  525. test config-7.3 {Tk_SetOptions - synonym} testobjconfig {
  526.     .a configure -synonym blue
  527.     .a cget -color
  528. } {blue}
  529. test config-7.4 {Tk_SetOptions - missing value} testobjconfig {
  530.     list [catch {.a configure -color green -relief} msg] $msg [.a cget -color]
  531. } {1 {value for "-relief" missing} green}
  532. test config-7.5 {Tk_SetOptions - saving old values} testobjconfig {
  533.     .a configure -color red -int 7 -relief raised -double 3.14159
  534.     list [catch {.a csave -color green -int 432 -relief sunken 
  535.     -double 2.0 -color bogus} msg] $msg [.a cget -color] 
  536.     [.a cget -int] [.a cget -relief] [.a cget -double]
  537. } {1 {unknown color name "bogus"} red 7 raised 3.14159}
  538. test config-7.6 {Tk_SetOptions - error in DoObjConfig call} testobjconfig {
  539.     list [catch {.a configure -color bogus} msg] $msg $errorInfo
  540. } {1 {unknown color name "bogus"} {unknown color name "bogus"
  541.     (processing "-color" option)
  542.     invoked from within
  543. ".a configure -color bogus"}}
  544. test config-7.7 {Tk_SetOptions - synonym name in error message} testobjconfig {
  545.     list [catch {.a configure -synonym bogus} msg] $msg $errorInfo
  546. } {1 {unknown color name "bogus"} {unknown color name "bogus"
  547.     (processing "-synonym" option)
  548.     invoked from within
  549. ".a configure -synonym bogus"}}
  550. test config-7.8 {Tk_SetOptions - returning mask} testobjconfig {
  551.     format %x [.a configure -color red -int 7 -relief raised -double 3.14159]
  552. } {226}
  553. test config-7.9 {Tk_SetOptions - error in DoObjConfig with custom option} testobjconfig {
  554.     list [catch {.a configure -custom bad} msg] $msg $errorInfo
  555. } {1 {expected good value, got "BAD"} {expected good value, got "BAD"
  556.     (processing "-custom" option)
  557.     invoked from within
  558. ".a configure -custom bad"}}
  559. test config-8.1 {Tk_RestoreSavedOptions - restore in proper order} testobjconfig {
  560.     deleteWindows
  561.     testobjconfig alltypes .a
  562.     list [catch {.a csave -color green -color black -color blue 
  563.     -color #ffff00 -color #ff00ff -color bogus} msg] $msg 
  564.     [.a cget -color]
  565. } {1 {unknown color name "bogus"} red}
  566. test config-8.2 {Tk_RestoreSavedOptions - freeing object memory} testobjconfig {
  567.     deleteWindows
  568.     testobjconfig alltypes .a
  569.     .a csave -color green -color black -color blue -color #ffff00 
  570.     -color #ff00ff
  571. } {32}
  572. test config-8.3 {Tk_RestoreSavedOptions - boolean internal form} testobjconfig {
  573.     deleteWindows
  574.     testobjconfig internal .a
  575.     list [catch {.a csave -boolean 0 -color bogus}] [.a cget -boolean]
  576. } {1 1}
  577. test config-8.4 {Tk_RestoreSavedOptions - integer internal form} testobjconfig {
  578.     deleteWindows
  579.     testobjconfig internal .a
  580.     list [catch {.a csave -integer 24 -color bogus}] [.a cget -integer]
  581. } {1 148962237}
  582. test config-8.5 {Tk_RestoreSavedOptions - double internal form} testobjconfig {
  583.     deleteWindows
  584.     testobjconfig internal .a
  585.     list [catch {.a csave -double 62.4 -color bogus}] [.a cget -double]
  586. } {1 3.14159}
  587. test config-8.6 {Tk_RestoreSavedOptions - string internal form} testobjconfig {
  588.     deleteWindows
  589.     testobjconfig internal .a
  590.     list [catch {.a csave -string "A long string" -color bogus}] 
  591.     [.a cget -string]
  592. } {1 foo}
  593. test config-8.7 {Tk_RestoreSavedOptions - string table internal form} testobjconfig {
  594.     deleteWindows
  595.     testobjconfig internal .a
  596.     list [catch {.a csave -stringtable three -color bogus}] 
  597.     [.a cget -stringtable]
  598. } {1 one}
  599. test config-8.8 {Tk_RestoreSavedOptions - color internal form} testobjconfig {
  600.     deleteWindows
  601.     testobjconfig internal .a
  602.     list [catch {.a csave -color green -color bogus}] [.a cget -color]
  603. } {1 red}
  604. test config-8.9 {Tk_RestoreSavedOptions - font internal form} {testobjconfig nonPortable} {
  605.     deleteWindows
  606.     testobjconfig internal .a
  607.     list [catch {.a csave -font {Times 12} -color bogus}] [.a cget -font]
  608. } {1 {Helvetica 12}}
  609. test config-8.10 {Tk_RestoreSavedOptions - bitmap internal form} testobjconfig {
  610.     deleteWindows
  611.     testobjconfig internal .a
  612.     list [catch {.a csave -bitmap questhead -color bogus}] [.a cget -bitmap]
  613. } {1 gray50}
  614. test config-8.11 {Tk_RestoreSavedOptions - border internal form} testobjconfig {
  615.     deleteWindows
  616.     testobjconfig internal .a
  617.     list [catch {.a csave -border brown -color bogus}] [.a cget -border]
  618. } {1 blue}
  619. test config-8.12 {Tk_RestoreSavedOptions - relief internal form} testobjconfig {
  620.     deleteWindows
  621.     testobjconfig internal .a
  622.     list [catch {.a csave -relief sunken -color bogus}] [.a cget -relief]
  623. } {1 raised}
  624. test config-8.13 {Tk_RestoreSavedOptions - cursor internal form} testobjconfig {
  625.     deleteWindows
  626.     testobjconfig internal .a
  627.     list [catch {.a csave -cursor watch -color bogus}] [.a cget -cursor]
  628. } {1 xterm}
  629. test config-8.14 {Tk_RestoreSavedOptions - justify internal form} testobjconfig {
  630.     deleteWindows
  631.     testobjconfig internal .a
  632.     list [catch {.a csave -justify right -color bogus}] [.a cget -justify]
  633. } {1 left}
  634. test config-8.15 {Tk_RestoreSavedOptions - anchor internal form} testobjconfig {
  635.     deleteWindows
  636.     testobjconfig internal .a
  637.     list [catch {.a csave -anchor center -color bogus}] [.a cget -anchor]
  638. } {1 n}
  639. test config-8.16 {Tk_RestoreSavedOptions - window internal form} testobjconfig {
  640.     deleteWindows
  641.     testobjconfig internal .a -window .a
  642.     list [catch {.a csave -window .a -color bogus}] [.a cget -window]
  643. } {1 .a}
  644. test config-8.17 {Tk_RestoreSavedOptions - custom internal form} testobjconfig {
  645.     deleteWindows
  646.     testobjconfig internal .a -custom "foobar"
  647.     list [catch {.a csave -custom "barbaz" -color bogus}] [.a cget -custom]
  648. } {1 FOOBAR}
  649. # Most of the tests below will cause memory leakage if there is a
  650. # problem.  This may not be evident unless the tests are run in
  651. # conjunction with a memory usage analyzer such as Purify.
  652. test config-9.1 {Tk_FreeConfigOptions/FreeResources - string internal form} testobjconfig {
  653.     catch {destroy .foo}
  654.     testobjconfig internal .foo
  655.     .foo configure -string "two words"
  656.     destroy .foo
  657. } {}
  658. test config-9.2 {Tk_FreeConfigOptions/FreeResources - color internal form} testobjconfig {
  659.     catch {destroy .foo}
  660.     testobjconfig internal .foo
  661.     .foo configure -color yellow
  662.     destroy .foo
  663. } {}
  664. test config-9.3 {Tk_FreeConfigOptions/FreeResources - color} testobjconfig {
  665.     catch {destroy .foo}
  666.     testobjconfig alltypes .foo
  667.     .foo configure -color [format blue]
  668.     destroy .foo
  669. } {}
  670. test config-9.4 {Tk_FreeConfigOptions/FreeResources - font internal form} testobjconfig {
  671.     catch {destroy .foo}
  672.     testobjconfig internal .foo
  673.     .foo configure -font {Courier 20}
  674.     destroy .foo
  675. } {}
  676. test config-9.5 {Tk_FreeConfigOptions/FreeResources - font} testobjconfig {
  677.     catch {destroy .foo}
  678.     testobjconfig alltypes .foo
  679.     .foo configure -font [format {Courier 24}]
  680.     destroy .foo
  681. } {}
  682. test config-9.6 {Tk_FreeConfigOptions/FreeResources - bitmap internal form} testobjconfig {
  683.     catch {destroy .foo}
  684.     testobjconfig internal .foo
  685.     .foo configure -bitmap gray75
  686.     destroy .foo
  687. } {}
  688. test config-9.7 {Tk_FreeConfigOptions/FreeResources - bitmap} testobjconfig {
  689.     catch {destroy .foo}
  690.     testobjconfig alltypes .foo
  691.     .foo configure -bitmap [format gray75]
  692.     destroy .foo
  693. } {}
  694. test config-9.8 {Tk_FreeConfigOptions/FreeResources - border internal form} testobjconfig {
  695.     catch {destroy .foo}
  696.     testobjconfig internal .foo
  697.     .foo configure -border orange
  698.     destroy .foo
  699. } {}
  700. test config-9.9 {Tk_FreeConfigOptions/FreeResources - border} testobjconfig {
  701.     catch {destroy .foo}
  702.     testobjconfig alltypes .foo
  703.     .foo configure -border [format blue]
  704.     destroy .foo
  705. } {}
  706. test config-9.10 {Tk_FreeConfigOptions/FreeResources - cursor internal form} testobjconfig {
  707.     catch {destroy .foo}
  708.     testobjconfig internal .foo
  709.     .foo configure -cursor cross
  710.     destroy .foo
  711. } {}
  712. test config-9.11 {Tk_FreeConfigOptions/FreeResources - cursor} testobjconfig {
  713.     catch {destroy .foo}
  714.     testobjconfig alltypes .foo
  715.     .foo configure -cursor [format watch]
  716.     destroy .foo
  717. } {}
  718. test config-9.12 {Tk_FreeConfigOptions/FreeResources - not special} testobjconfig {
  719.     catch {destroy .foo}
  720.     testobjconfig alltypes .foo
  721.     .foo configure -integer [format 27]
  722.     destroy .foo
  723. } {}
  724. test config-9.13 {Tk_FreeConfigOptions/FreeResources - custom internal form} testobjconfig {
  725.     catch {destroy .fpp}
  726.     testobjconfig internal .foo
  727.     .foo configure -custom "foobar"
  728.     destroy .foo
  729. } {}
  730. test config-10.1 {Tk_GetOptionInfo - one item} testobjconfig {
  731.     catch {destroy .foo}
  732.     testobjconfig alltypes .foo
  733.     .foo configure -relief groove
  734.     .foo configure -relief
  735. } {-relief relief Relief raised groove}
  736. test config-10.2 {Tk_GetOptionInfo - one item, synonym} testobjconfig {
  737.     catch {destroy .foo}
  738.     testobjconfig alltypes .foo
  739.     .foo configure -color black
  740.     .foo configure -synonym
  741. } {-color color Color red black}
  742. test config-10.3 {Tk_GetOptionInfo - all items} testobjconfig {
  743.     catch {destroy .foo}
  744.     testobjconfig alltypes .foo -font {Helvetica 18} -integer 13563
  745.     .foo configure
  746. } {{-boolean boolean Boolean 1 1} {-integer integer Integer 7 13563} {-double double Double 3.14159 3.14159} {-string string String foo foo} {-stringtable StringTable stringTable one one} {-color color Color red red} {-font font Font {Helvetica 12} {Helvetica 18}} {-bitmap bitmap Bitmap gray50 gray50} {-border border Border blue blue} {-relief relief Relief raised raised} {-cursor cursor Cursor xterm xterm} {-justify {} {} left left} {-anchor anchor Anchor {} {}} {-pixel pixel Pixel 1 1} {-custom {} {} {} {}} {-synonym -color}}
  747. test config-10.4 {Tk_GetOptionInfo - chaining through tables} testobjconfig {
  748.     catch {destroy .foo}
  749.     testobjconfig chain2 .foo -one asdf -three xyzzy
  750.     .foo configure
  751. } {{-three three Three three xyzzy} {-four four Four four four} {-two two Two {two and a half} {two and a half}} {-oneAgain oneAgain OneAgain {one again} {one again}} {-one one One one asdf} {-two two Two two {two and a half}}}
  752. deleteWindows
  753. if {[testConstraint testobjconfig]} {
  754.     testobjconfig alltypes .a
  755. }
  756. test config-11.1 {GetConfigList - synonym} testobjconfig {
  757.     lindex [.a configure] end
  758. } {-synonym -color}
  759. test config-11.2 {GetConfigList - null database names} testobjconfig {
  760.     .a configure -justify
  761. } {-justify {} {} left left}
  762. test config-11.3 {GetConfigList - null default and current value} testobjconfig {
  763.     .a configure -anchor
  764. } {-anchor anchor Anchor {} {}}
  765. deleteWindows
  766. if {[testConstraint testobjconfig]} {
  767.     testobjconfig internal .a
  768. }
  769. test config-12.1 {GetObjectForOption - boolean} testobjconfig {
  770.     .a configure -boolean 0
  771.     .a cget -boolean
  772. } {0}
  773. test config-12.2 {GetObjectForOption - integer} testobjconfig {
  774.     .a configure -integer 1247
  775.     .a cget -integer
  776. } {1247}
  777. test config-12.3 {GetObjectForOption - double} testobjconfig {
  778.     .a configure -double -88.82
  779.     .a cget -double
  780. } {-88.82}
  781. test config-12.4 {GetObjectForOption - string} testobjconfig {
  782.     .a configure -string "test value"
  783.     .a cget -string
  784. } {test value}
  785. test config-12.5 {GetObjectForOption - stringTable} testobjconfig {
  786.     .a configure -stringtable "two"
  787.     .a cget -stringtable
  788. } {two}
  789. test config-12.6 {GetObjectForOption - color} testobjconfig {
  790.     .a configure -color "green"
  791.     .a cget -color
  792. } {green}
  793. test config-12.7 {GetObjectForOption - font} testobjconfig {
  794.     .a configure -font {Times 36}
  795.     .a cget -font
  796. } {Times 36}
  797. test config-12.8 {GetObjectForOption - bitmap} testobjconfig {
  798.     .a configure -bitmap "questhead"
  799.     .a cget -bitmap
  800. } {questhead}
  801. test config-12.9 {GetObjectForOption - border} testobjconfig {
  802.     .a configure -border #33217c
  803.     .a cget -border
  804. } {#33217c}
  805. test config-12.10 {GetObjectForOption - relief} testobjconfig {
  806.     .a configure -relief groove
  807.     .a cget -relief
  808. } {groove}
  809. test config-12.11 {GetObjectForOption - cursor} testobjconfig {
  810.     .a configure -cursor watch
  811.     .a cget -cursor
  812. } {watch}
  813. test config-12.12 {GetObjectForOption - justify} testobjconfig {
  814.     .a configure -justify right
  815.     .a cget -justify
  816. } {right}
  817. test config-12.13 {GetObjectForOption - anchor} testobjconfig {
  818.     .a configure -anchor e
  819.     .a cget -anchor
  820. } {e}
  821. test config-12.14 {GetObjectForOption - pixels} testobjconfig {
  822.     .a configure -pixel 193.2
  823.     .a cget -pixel
  824. } {193}
  825. test config-12.15 {GetObjectForOption - window} testobjconfig {
  826.     .a configure -window .a
  827.     .a cget -window
  828. } {.a}
  829. test config-12.16 {GetObjectForOption -custom} testobjconfig {
  830.     .a configure -custom foobar
  831.     .a cget -custom
  832. } {FOOBAR}
  833. test config-12.17 {GetObjectForOption - null values} testobjconfig {
  834.     .a configure -string {} -color {} -font {} -bitmap {} -border {} 
  835.     -cursor {} -window {} -custom {}
  836.     list [.a cget -string] [.a cget -color] [.a cget -font] 
  837.     [.a cget -bitmap] [.a cget -border] [.a cget -cursor] 
  838.     [.a cget -window] [.a cget -custom]
  839. } {{} {} {} {} {} {} {} {}}
  840. test config-13.1 {proper cleanup of options with widget destroy} {
  841.     foreach type {
  842. button canvas entry frame listbox menu menubutton message
  843. scale scrollbar text radiobutton checkbutton
  844.     } {
  845. destroy .w
  846. $type .w -cursor crosshair
  847. destroy .w
  848.     }
  849. } {}
  850. deleteWindows
  851. test config-14.1 {Tk_CreateOptionTable - use with namespace import} {
  852.     namespace export -clear *
  853.     foreach type {
  854. button canvas entry frame listbox menu menubutton message
  855. scale scrollbar spinbox text radiobutton checkbutton
  856.     } {
  857. namespace eval ::foo [subst {
  858.     namespace import -force ::$type
  859.     ::foo::$type .a
  860.     ::foo::$type .b
  861. }
  862. ]
  863. destroy .a .b
  864.     }
  865. } {}
  866. # cleanup
  867. deleteWindows
  868. if {[testConstraint testobjconfig]} {
  869.     killTables
  870. }
  871. ::tcltest::cleanupTests
  872. return