home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / tests / link.test < prev    next >
Text File  |  1993-07-28  |  5KB  |  149 lines

  1. # Commands covered:  none
  2. #
  3. # This file contains a collection of tests for Tcl_LinkVar and related
  4. # library procedures.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/link.test,v 1.5 93/07/28 15:05:32 ouster Exp $ (Berkeley)
  28.  
  29. if {[info commands testlink] == {}} {
  30.     puts "This application hasn't been compiled with the \"testlink\""
  31.     puts "command, so I can't test Tcl_LinkVar et al."
  32.     return
  33. }
  34.  
  35. if {[string compare test [info procs test]] == 1} then {source defs}
  36.  
  37. foreach i {int real bool string} {
  38.     catch {unset $i}
  39. }
  40. test link-1.1 {reading C variables from Tcl} {
  41.     testlink delete
  42.     testlink set 43 1.23 4 -
  43.     testlink create 1 1 1 1
  44.     list $int $real $bool $string
  45. } {43 1.23 1 NULL}
  46. test link-1.2 {reading C variables from Tcl} {
  47.     testlink delete
  48.     testlink create 1 1 1 1
  49.     testlink set -3 2 0 "A long string with spaces"
  50.     list $int $real $bool $string $int $real $bool $string
  51. } {-3 2.0 0 {A long string with spaces} -3 2.0 0 {A long string with spaces}}
  52.  
  53. test link-2.1 {writing C variables from Tcl} {
  54.     testlink delete
  55.     testlink set 43 1.23 4 -
  56.     testlink create 1 1 1 1
  57.     set int "00721"
  58.     set real -8e13
  59.     set bool true
  60.     set string abcdef
  61.     concat [testlink get] $int $real $bool $string
  62. } {465 -8e+13 1 abcdef 00721 -8e13 true abcdef}
  63. test link-2.2 {writing bad values into variables} {
  64.     testlink delete
  65.     testlink set 43 1.23 4 -
  66.     testlink create 1 1 1 1
  67.     list [catch {set int 09a} msg] $msg $int
  68. } {1 {can't set "int": variable must have integer value} 43}
  69. test link-2.3 {writing bad values into variables} {
  70.     testlink delete
  71.     testlink set 43 1.23 4 -
  72.     testlink create 1 1 1 1
  73.     list [catch {set real 1.x3} msg] $msg $real
  74. } {1 {can't set "real": variable must have real value} 1.23}
  75. test link-2.4 {writing bad values into variables} {
  76.     testlink delete
  77.     testlink set 43 1.23 4 -
  78.     testlink create 1 1 1 1
  79.     list [catch {set bool gorp} msg] $msg $bool
  80. } {1 {can't set "bool": variable must have boolean value} 1}
  81.  
  82. test link-3.1 {read-only variables} {
  83.     testlink delete
  84.     testlink set 43 1.23 4 -
  85.     testlink create 0 1 1 0
  86.     list [catch {set int 4} msg] $msg $int \
  87.     [catch {set real 10.6} msg] $msg $real \
  88.     [catch {set bool no} msg] $msg $bool \
  89.     [catch {set string "new value"} msg] $msg $string
  90. } {1 {can't set "int": linked variable is read-only} 43 0 10.6 10.6 0 no no 1 {can't set "string": linked variable is read-only} NULL}
  91. test link-3.2 {read-only variables} {
  92.     testlink delete
  93.     testlink set 43 1.23 4 -
  94.     testlink create 1 0 0 1
  95.     list [catch {set int 4} msg] $msg $int \
  96.     [catch {set real 10.6} msg] $msg $real \
  97.     [catch {set bool no} msg] $msg $bool \
  98.     [catch {set string "new value"} msg] $msg $string
  99. } {0 4 4 1 {can't set "real": linked variable is read-only} 1.23 1 {can't set "bool": linked variable is read-only} 1 0 {new value} {new value}}
  100.  
  101. test link-4.1 {unsetting linked variables} {
  102.     testlink delete
  103.     testlink set -6 -2.1 0 stringValue
  104.     testlink create 1 1 1 1
  105.     unset int real bool string
  106.     list [catch {set int} msg] $msg [catch {set real} msg] $msg \
  107.         [catch {set bool} msg] $msg [catch {set string} msg] $msg
  108. } {0 -6 0 -2.1 0 0 0 stringValue}
  109. test link-4.2 {unsetting linked variables} {
  110.     testlink delete
  111.     testlink set -6 -2.1 0 stringValue
  112.     testlink create 1 1 1 1
  113.     unset int real bool string
  114.     set int 102
  115.     set real 16
  116.     set bool true
  117.     set string newValue
  118.     testlink get
  119. } {102 16.0 1 newValue}
  120.  
  121. test link-5.1 {unlinking variables} {
  122.     testlink delete
  123.     testlink set -6 -2.1 0 stringValue
  124.     testlink delete
  125.     set int xx1
  126.     set real qrst
  127.     set bool bogus
  128.     set string 12345
  129.     testlink get
  130. } {-6 -2.1 0 stringValue}
  131. test link-5.2 {unlinking variables} {
  132.     testlink delete
  133.     testlink set -6 -2.1 0 stringValue
  134.     testlink create 1 1 1 1
  135.     testlink delete
  136.     testlink set 25 14.7 7 -
  137.     list $int $real $bool $string
  138. } {-6 -2.1 0 stringValue}
  139.  
  140. test link-6.1 {errors in setting up link} {
  141.     testlink delete
  142.     catch {unset int}
  143.     set int(44) 1
  144.     list [catch {testlink create 1 1 1 1} msg] $msg
  145. } {1 {can't set "int": variable is array}}
  146.  
  147. testlink delete
  148. unset int real bool string
  149.