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

通讯编程

开发平台:

Visual C++

  1. # This file is a Tcl script to test out the procedures in the file 
  2. # tkUnixEmbed.c.  It is organized in the standard fashion for Tcl
  3. # tests.
  4. #
  5. # Copyright (c) 1996-1997 Sun Microsystems, Inc.
  6. # Copyright (c) 1998-1999 by Scriptics Corporation.
  7. # All rights reserved.
  8. #
  9. # RCS: @(#) $Id: unixEmbed.test,v 1.11 2002/07/13 21:52:34 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. setupbg
  17. dobg {wm withdraw .}
  18. # eatColors --
  19. # Creates a toplevel window and allocates enough colors in it to
  20. # use up all the slots in the colormap.
  21. #
  22. # Arguments:
  23. # w - Name of toplevel window to create.
  24. proc eatColors {w} {
  25.     catch {destroy $w}
  26.     toplevel $w
  27.     wm geom $w +0+0
  28.     canvas $w.c -width 400 -height 200 -bd 0
  29.     pack $w.c
  30.     for {set y 0} {$y < 8} {incr y} {
  31. for {set x 0} {$x < 40} {incr x} {
  32.     set color [format #%02x%02x%02x [expr $x*6] [expr $y*30] 0]
  33.     $w.c create rectangle [expr 10*$x] [expr 20*$y] 
  34.     [expr 10*$x + 10] [expr 20*$y + 20] -outline {} 
  35.     -fill $color
  36. }
  37.     }
  38.     update
  39. }
  40. # colorsFree --
  41. #
  42. # Returns 1 if there appear to be free colormap entries in a window,
  43. # 0 otherwise.
  44. #
  45. # Arguments:
  46. # w - Name of window in which to check.
  47. # red, green, blue - Intensities to use in a trial color allocation
  48. # to see if there are colormap entries free.
  49. proc colorsFree {w {red 31} {green 245} {blue 192}} {
  50.     set vals [winfo rgb $w [format #%02x%02x%02x $red $green $blue]]
  51.     expr ([lindex $vals 0]/256 == $red) && ([lindex $vals 1]/256 == $green) 
  52.     && ([lindex $vals 2]/256 == $blue)
  53. }
  54. test unixEmbed-1.1 {TkpUseWindow procedure, bad window identifier} unix {
  55.     catch {destroy .t}
  56.     list [catch {toplevel .t -use xyz} msg] $msg
  57. } {1 {expected integer but got "xyz"}}
  58. test unixEmbed-1.2 {TkpUseWindow procedure, bad window identifier} unix {
  59.     catch {destroy .t}
  60.     list [catch {toplevel .t -use 47} msg] $msg
  61. } {1 {couldn't create child of window "47"}}
  62. test unixEmbed-1.3 {TkpUseWindow procedure, inheriting colormap} {unix nonPortable} {
  63.     catch {destroy .t}
  64.     catch {destroy .x}
  65.     toplevel .t -colormap new
  66.     wm geometry .t +0+0
  67.     eatColors .t.t
  68.     frame .t.f -container 1
  69.     toplevel .x -use [winfo id .t.f]
  70.     set result [colorsFree .x]
  71.     destroy .t
  72.     set result
  73. } {0}
  74. test unixEmbed-1.4 {TkpUseWindow procedure, inheriting colormap} {unix nonPortable} {
  75.     catch {destroy .t}
  76.     catch {destroy .t2}
  77.     catch {destroy .x}
  78.     toplevel .t -container 1 -colormap new
  79.     wm geometry .t +0+0
  80.     eatColors .t2
  81.     toplevel .x -use [winfo id .t]
  82.     set result [colorsFree .x]
  83.     destroy .t
  84.     set result
  85. } {1}
  86. test unixEmbed-1.5 {TkpUseWindow procedure, creating Container records} {unix testembed} {
  87.     deleteWindows
  88.     frame .f1 -container 1 -width 200 -height 50
  89.     frame .f2 -container 1 -width 200 -height 50
  90.     pack .f1 .f2
  91.     dobg "set w [winfo id .f1]"
  92.     dobg {
  93. eval destroy [winfo child .]
  94. toplevel .t -use $w
  95. list [testembed] [expr [lindex [lindex [testembed all] 0] 0] - $w]
  96.     }
  97. } {{{XXX {} {} .t}} 0}
  98. test unixEmbed-1.6 {TkpUseWindow procedure, creating Container records} {unix testembed} {
  99.     deleteWindows
  100.     frame .f1 -container 1 -width 200 -height 50
  101.     frame .f2 -container 1 -width 200 -height 50
  102.     pack .f1 .f2
  103.     dobg "set w1 [winfo id .f1]"
  104.     dobg "set w2 [winfo id .f2]"
  105.     dobg {
  106. eval destroy [winfo child .]
  107. toplevel .t1 -use $w1
  108. toplevel .t2 -use $w2
  109. testembed
  110.     }
  111. } {{XXX {} {} .t2} {XXX {} {} .t1}}
  112. test unixEmbed-1.7 {TkpUseWindow procedure, container and embedded in same app} {unix testembed} {
  113.     deleteWindows
  114.     frame .f1 -container 1 -width 200 -height 50
  115.     frame .f2 -container 1 -width 200 -height 50
  116.     pack .f1 .f2
  117.     toplevel .t1 -use [winfo id .f1]
  118.     toplevel .t2 -use [winfo id .f2]
  119.     testembed
  120. } {{XXX .f2 {} .t2} {XXX .f1 {} .t1}}
  121. # Can't think of any way to test the procedures TkpMakeWindow,
  122. # TkpMakeContainer, or EmbedErrorProc.
  123. test unixEmbed-2.1 {EmbeddedEventProc procedure} {unix testembed} {
  124.     deleteWindows
  125.     frame .f1 -container 1 -width 200 -height 50
  126.     pack .f1
  127.     dobg "set w1 [winfo id .f1]"
  128.     dobg {
  129. eval destroy [winfo child .]
  130. toplevel .t1 -use $w1
  131. testembed
  132.     }
  133.     destroy .f1
  134.     update
  135.     dobg {
  136. testembed
  137.     }
  138. } {}
  139. test unixEmbed-2.2 {EmbeddedEventProc procedure} {unix testembed} {
  140.     deleteWindows
  141.     frame .f1 -container 1 -width 200 -height 50
  142.     pack .f1
  143.     dobg "set w1 [winfo id .f1]"
  144.     dobg {
  145. eval destroy [winfo child .]
  146. toplevel .t1 -use $w1
  147. testembed
  148. destroy .t1
  149. testembed
  150.     }
  151. } {}
  152. test unixEmbed-2.3 {EmbeddedEventProc procedure} {unix testembed} {
  153.     deleteWindows
  154.     frame .f1 -container 1 -width 200 -height 50
  155.     pack .f1
  156.     toplevel .t1 -use [winfo id .f1]
  157.     update
  158.     destroy .f1
  159.     testembed
  160. } {}
  161. test unixEmbed-2.4 {EmbeddedEventProc procedure} {unix testembed} {
  162.     deleteWindows
  163.     frame .f1 -container 1 -width 200 -height 50
  164.     pack .f1
  165.     toplevel .t1 -use [winfo id .f1]
  166.     update
  167.     destroy .t1
  168.     set x [testembed]
  169.     update
  170.     list $x [testembed]
  171. } {{{XXX .f1 {} {}}} {}}
  172. test unixEmbed-3.1 {ContainerEventProc procedure, detect creation} 
  173. {unix testembed nonPortable} {
  174.     deleteWindows
  175.     frame .f1 -container 1 -width 200 -height 50
  176.     pack .f1
  177.     dobg "set w1 [winfo id .f1]"
  178.     set x [testembed]
  179.     dobg {
  180. eval destroy [winfo child .]
  181. toplevel .t1 -use $w1
  182. wm withdraw .t1
  183.     }
  184.     list $x [testembed]
  185. } {{{XXX .f1 {} {}}} {{XXX .f1 XXX {}}}}
  186. test unixEmbed-3.2 {ContainerEventProc procedure, set size on creation} unix {
  187.     deleteWindows
  188.     toplevel .t1 -container 1
  189.     wm geometry .t1 +0+0
  190.     toplevel .t2 -use [winfo id .t1] -bg red
  191.     update
  192.     wm geometry .t2
  193. } {200x200+0+0}
  194. test unixEmbed-3.2 {ContainerEventProc procedure, disallow position changes} unix {
  195.     deleteWindows
  196.     frame .f1 -container 1 -width 200 -height 50
  197.     pack .f1
  198.     dobg "set w1 [winfo id .f1]"
  199.     dobg {
  200. eval destroy [winfo child .]
  201. toplevel .t1 -use $w1 -bd 2 -relief raised
  202. update
  203. wm geometry .t1 +30+40
  204.     }
  205.     update
  206.     dobg {
  207. wm geometry .t1
  208.     }
  209. } {200x200+0+0}
  210. test unixEmbed-3.3 {ContainerEventProc procedure, disallow position changes} unix {
  211.     deleteWindows
  212.     frame .f1 -container 1 -width 200 -height 50
  213.     pack .f1
  214.     dobg "set w1 [winfo id .f1]"
  215.     dobg {
  216. eval destroy [winfo child .]
  217. toplevel .t1 -use $w1
  218. update
  219. wm geometry .t1 300x100+30+40
  220.     }
  221.     update
  222.     dobg {
  223. wm geometry .t1
  224.     }
  225. } {300x100+0+0}
  226. test unixEmbed-3.4 {ContainerEventProc procedure, geometry requests} unix {
  227.     deleteWindows
  228.     frame .f1 -container 1 -width 200 -height 50
  229.     pack .f1
  230.     dobg "set w1 [winfo id .f1]"
  231.     dobg {
  232. eval destroy [winfo child .]
  233. toplevel .t1 -use $w1
  234.     }
  235.     update
  236.     dobg {
  237. .t1 configure -width 300 -height 80
  238.     }
  239.     update
  240.     list [winfo width .f1] [winfo height .f1] [dobg {wm geometry .t1}]
  241. } {300 80 300x80+0+0}
  242. test unixEmbed-3.5 {ContainerEventProc procedure, map requests} unix {
  243.     deleteWindows
  244.     frame .f1 -container 1 -width 200 -height 50
  245.     pack .f1
  246.     dobg "set w1 [winfo id .f1]"
  247.     dobg {
  248. eval destroy [winfo child .]
  249. toplevel .t1 -use $w1
  250. set x unmapped
  251. bind .t1 <Map> {set x mapped}
  252.     }
  253.     update
  254.     dobg {
  255. after 100
  256. update
  257. set x
  258.     }
  259. } {mapped}
  260. test unixEmbed-3.6 {ContainerEventProc procedure, destroy events} unix {
  261.     deleteWindows
  262.     frame .f1 -container 1 -width 200 -height 50
  263.     pack .f1
  264.     dobg "set w1 [winfo id .f1]"
  265.     bind .f1 <Destroy> {set x dead}
  266.     set x alive
  267.     dobg {
  268. eval destroy [winfo child .]
  269. toplevel .t1 -use $w1
  270.     }
  271.     update
  272.     dobg {
  273. destroy .t1
  274.     }
  275.     update
  276.     list $x [winfo exists .f1]
  277. } {dead 0}
  278. test unixEmbed-4.1 {EmbedStructureProc procedure, configure events} unix {
  279.     deleteWindows
  280.     frame .f1 -container 1 -width 200 -height 50
  281.     pack .f1
  282.     dobg "set w1 [winfo id .f1]"
  283.     dobg {
  284. eval destroy [winfo child .]
  285. toplevel .t1 -use $w1
  286.     }
  287.     update
  288.     dobg {
  289. .t1 configure -width 180 -height 100
  290.     }
  291.     update
  292.     dobg {
  293. winfo geometry .t1
  294.     }
  295. } {180x100+0+0}
  296. test unixEmbed-4.2 {EmbedStructureProc procedure, destroy events} {unix testembed} {
  297.     deleteWindows
  298.     frame .f1 -container 1 -width 200 -height 50
  299.     pack .f1
  300.     dobg "set w1 [winfo id .f1]"
  301.     dobg {
  302. eval destroy [winfo child .]
  303. toplevel .t1 -use $w1
  304.     }
  305.     update
  306.     set x [testembed]
  307.     destroy .f1
  308.     list $x [testembed]
  309. } {{{XXX .f1 XXX {}}} {}}
  310. test unixEmbed-5.1 {EmbedFocusProc procedure, FocusIn events} unix {
  311.     deleteWindows
  312.     frame .f1 -container 1 -width 200 -height 50
  313.     pack .f1
  314.     dobg "set w1 [winfo id .f1]"
  315.     dobg {
  316. eval destroy [winfo child .]
  317. toplevel .t1 -use $w1
  318. bind .t1 <FocusIn> {lappend x "focus in %W"}
  319. bind .t1 <FocusOut> {lappend x "focus out %W"}
  320. set x {}
  321.     }
  322.     focus -force .f1
  323.     update
  324.     dobg {set x}
  325. } {{focus in .t1}}
  326. test unixEmbed-5.2 {EmbedFocusProc procedure, focusing on dead window} unix {
  327.     deleteWindows
  328.     frame .f1 -container 1 -width 200 -height 50
  329.     pack .f1
  330.     dobg "set w1 [winfo id .f1]"
  331.     dobg {
  332. eval destroy [winfo child .]
  333. toplevel .t1 -use $w1
  334.     }
  335.     update
  336.     dobg {
  337. after 200 {destroy .t1}
  338.     }
  339.     after 400
  340.     focus -force .f1
  341.     update
  342. } {}
  343. test unixEmbed-5.3 {EmbedFocusProc procedure, FocusOut events} unix {
  344.     deleteWindows
  345.     frame .f1 -container 1 -width 200 -height 50
  346.     pack .f1
  347.     dobg "set w1 [winfo id .f1]"
  348.     dobg {
  349. eval destroy [winfo child .]
  350. toplevel .t1 -use $w1
  351. bind .t1 <FocusIn> {lappend x "focus in %W"}
  352. bind .t1 <FocusOut> {lappend x "focus out %W"}
  353. set x {}
  354.     }
  355.     focus -force .f1
  356.     update
  357.     set x [dobg {update; set x}]
  358.     focus .
  359.     update
  360.     list $x [dobg {update; set x}]
  361. } {{{focus in .t1}} {{focus in .t1} {focus out .t1}}}
  362. test unixEmbed-6.1 {EmbedGeometryRequest procedure, window changes size} unix {
  363.     deleteWindows
  364.     frame .f1 -container 1 -width 200 -height 50
  365.     pack .f1
  366.     dobg "set w1 [winfo id .f1]"
  367.     dobg {
  368. eval destroy [winfo child .]
  369. toplevel .t1 -use $w1
  370.     }
  371.     update
  372.     dobg {
  373. bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
  374. set x {}
  375. .t1 configure -width 300 -height 120
  376. update
  377. list $x [winfo geom .t1]
  378.     }
  379. } {{{configure .t1 300 120}} 300x120+0+0}
  380. test unixEmbed-6.2 {EmbedGeometryRequest procedure, window changes size} unix {
  381.     deleteWindows
  382.     frame .f1 -container 1 -width 200 -height 50
  383.     place .f1 -width 200 -height 200
  384.     dobg "set w1 [winfo id .f1]"
  385.     dobg {
  386. eval destroy [winfo child .]
  387. toplevel .t1 -use $w1
  388.     }
  389.     after 300 {set x done}
  390.     vwait x
  391.     dobg {
  392. bind .t1 <Configure> {lappend x {configure .t1 %w %h}}
  393. set x {}
  394. .t1 configure -width 300 -height 120
  395. update
  396. list $x [winfo geom .t1]
  397.     }
  398. } {{{configure .t1 200 200}} 200x200+0+0}
  399. # Can't think up any tests for TkpGetOtherWindow procedure.
  400. test unixEmbed-7.1 {TkpRedirectKeyEvent procedure, forward keystroke} unix {
  401.     deleteWindows
  402.     frame .f1 -container 1 -width 200 -height 50
  403.     pack .f1
  404.     dobg "set w1 [winfo id .f1]"
  405.     dobg {
  406. eval destroy [winfo child .]
  407. toplevel .t1 -use $w1
  408.     }
  409.     focus -force .
  410.     bind . <KeyPress> {lappend x {key %A %E}}
  411.     set x {}
  412.     set y [dobg {
  413. update
  414. bind .t1 <KeyPress> {lappend y {key %A}}
  415. set y {}
  416. event generate .t1 <KeyPress> -keysym a
  417. set y
  418.     }]
  419.     update
  420.     bind . <KeyPress> {}
  421.     list $x $y
  422. } {{{key a 1}} {}}
  423. test unixEmbed-7.2 {TkpRedirectKeyEvent procedure, don't forward keystroke width} unix {
  424.     deleteWindows
  425.     frame .f1 -container 1 -width 200 -height 50
  426.     pack .f1
  427.     dobg "set w1 [winfo id .f1]"
  428.     dobg {
  429. eval destroy [winfo child .]
  430. toplevel .t1 -use $w1
  431.     }
  432.     update
  433.     focus -force .f1
  434.     update
  435.     bind . <KeyPress> {lappend x {key %A}}
  436.     set x {}
  437.     set y [dobg {
  438. update
  439. bind .t1 <KeyPress> {lappend y {key %A}}
  440. set y {}
  441. event generate .t1 <KeyPress> -keysym b
  442. set y
  443.     }]
  444.     update
  445.     bind . <KeyPress> {}
  446.     list $x $y
  447. } {{} {{key b}}}
  448. test unixEmbed-8.1 {TkpClaimFocus procedure} unix {
  449.     deleteWindows
  450.     frame .f1 -container 1 -width 200 -height 50
  451.     frame .f2 -width 200 -height 50
  452.     pack .f1 .f2
  453.     dobg "set w1 [winfo id .f1]"
  454.     dobg {
  455. eval destroy [winfo child .]
  456. toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
  457.     }
  458.     focus -force .f2
  459.     update
  460.     list [dobg {
  461. focus .t1
  462. set x [list [focus]]
  463. update
  464. after 500
  465. update
  466. lappend x [focus]
  467.     }] [focus]
  468. } {{{} .t1} .f1}
  469. test unixEmbed-8.2 {TkpClaimFocus procedure} unix {
  470.     catch {interp delete child}
  471.     deleteWindows
  472.     frame .f1 -container 1 -width 200 -height 50
  473.     frame .f2 -width 200 -height 50
  474.     pack .f1 .f2
  475.     interp create child
  476.     child eval "set argv {-use [winfo id .f1]}"
  477.     load {} Tk child
  478.     child eval {
  479. . configure -bd 2 -highlightthickness 2 -relief sunken
  480.     }
  481.     focus -force .f2
  482.     update
  483.     list [child eval {
  484. focus .
  485. set x [list [focus]]
  486. update
  487. lappend x [focus]
  488.     }] [focus]
  489. } {{{} .} .f1}
  490. catch {interp delete child}
  491. test unixEmbed-9.1 {EmbedWindowDeleted procedure, check parentPtr} {unix testembed} {
  492.     deleteWindows
  493.     frame .f1 -container 1 -width 200 -height 50
  494.     frame .f2 -container 1 -width 200 -height 50
  495.     frame .f3 -container 1 -width 200 -height 50
  496.     frame .f4 -container 1 -width 200 -height 50
  497.     pack .f1 .f2 .f3 .f4
  498.     set x {}
  499.     lappend x [testembed]
  500.     foreach w {.f3 .f4 .f1 .f2} {
  501. destroy $w
  502. lappend x [testembed]
  503.     }
  504.     set x
  505. } {{{XXX .f4 {} {}} {XXX .f3 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f4 {} {}} {XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}} {XXX .f1 {} {}}} {{XXX .f2 {} {}}} {}}
  506. test unixEmbed-9.2 {EmbedWindowDeleted procedure, check embeddedPtr} {unix testembed} {
  507.     deleteWindows
  508.     frame .f1 -container 1 -width 200 -height 50
  509.     pack .f1
  510.     dobg "set w1 [winfo id .f1]"
  511.     dobg {
  512. eval destroy [winfo child .]
  513. toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
  514. set x {}
  515. lappend x [testembed]
  516. destroy .t1
  517. lappend x [testembed]
  518.     }
  519. } {{{XXX {} {} .t1}} {}}
  520. test unixEmbed-10.1 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} unix {
  521.     deleteWindows
  522.     frame .f1 -container 1 -width 200 -height 50
  523.     pack .f1
  524.     toplevel .t1 -use [winfo id .f1] -width 150 -height 80
  525.     update
  526.     wm geometry .t1 +40+50
  527.     update
  528.     wm geometry .t1
  529. } {150x80+0+0}
  530. test unixEmbed-10.2 {geometry propagation in tkUnixWm.c/UpdateGeometryInfo} unix {
  531.     deleteWindows
  532.     frame .f1 -container 1 -width 200 -height 50
  533.     pack .f1
  534.     toplevel .t1 -use [winfo id .f1] -width 150 -height 80
  535.     update
  536.     wm geometry .t1 70x300+10+20
  537.     update
  538.     wm geometry .t1
  539. } {70x300+0+0}
  540. # cleanup
  541. deleteWindows
  542. cleanupbg
  543. ::tcltest::cleanupTests
  544. return