os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/link.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 # Copyright (c) 1994 Sun Microsystems, Inc.
     9 # Copyright (c) 1998-1999 by Scriptics Corporation.
    10 #
    11 # See the file "license.terms" for information on usage and redistribution
    12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    13 #
    14 # RCS: @(#) $Id: link.test,v 1.7 2002/06/22 04:19:47 dgp Exp $
    15 
    16 if {[lsearch [namespace children] ::tcltest] == -1} {
    17     package require tcltest 2
    18     namespace import -force ::tcltest::*
    19 }
    20 
    21 ::tcltest::testConstraint testlink \
    22         [expr {[info commands testlink] != {}}]
    23 
    24 foreach i {int real bool string} {
    25     catch {unset $i}
    26 }
    27 test link-1.1 {reading C variables from Tcl} {testlink} {
    28     testlink delete
    29     testlink set 43 1.23 4 - 12341234
    30     testlink create 1 1 1 1 1
    31     list $int $real $bool $string $wide
    32 } {43 1.23 1 NULL 12341234}
    33 test link-1.2 {reading C variables from Tcl} {testlink} {
    34     testlink delete
    35     testlink create 1 1 1 1 1
    36     testlink set -3 2 0 "A long string with spaces"  43214321
    37     list $int $real $bool $string $wide $int $real $bool $string $wide
    38 } {-3 2.0 0 {A long string with spaces} 43214321 -3 2.0 0 {A long string with spaces} 43214321}
    39 
    40 test link-2.1 {writing C variables from Tcl} {testlink} {
    41     testlink delete
    42     testlink set 43 1.21 4 - 56785678
    43     testlink create 1 1 1 1 1
    44     set int "00721"
    45     set real -10.5
    46     set bool true
    47     set string abcdef
    48     set wide 135135
    49     concat [testlink get] $int $real $bool $string $wide
    50 } {465 -10.5 1 abcdef 135135 00721 -10.5 true abcdef 135135}
    51 test link-2.2 {writing bad values into variables} {testlink} {
    52     testlink delete
    53     testlink set 43 1.23 4 - 56785678
    54     testlink create 1 1 1 1 1
    55     list [catch {set int 09a} msg] $msg $int
    56 } {1 {can't set "int": variable must have integer value} 43}
    57 test link-2.3 {writing bad values into variables} {testlink} {
    58     testlink delete
    59     testlink set 43 1.23 4 - 56785678
    60     testlink create 1 1 1 1 1
    61     list [catch {set real 1.x3} msg] $msg $real
    62 } {1 {can't set "real": variable must have real value} 1.23}
    63 test link-2.4 {writing bad values into variables} {testlink} {
    64     testlink delete
    65     testlink set 43 1.23 4 - 56785678
    66     testlink create 1 1 1 1 1
    67     list [catch {set bool gorp} msg] $msg $bool
    68 } {1 {can't set "bool": variable must have boolean value} 1}
    69 test link-2.5 {writing bad values into variables} {testlink} {
    70     testlink delete
    71     testlink set 43 1.23 4 - 56785678
    72     testlink create 1 1 1 1 1
    73     list [catch {set wide gorp} msg] $msg $bool
    74 } {1 {can't set "wide": variable must have integer value} 1}
    75 
    76 test link-3.1 {read-only variables} {testlink} {
    77     testlink delete
    78     testlink set 43 1.23 4 - 56785678
    79     testlink create 0 1 1 0 0
    80     list [catch {set int 4} msg] $msg $int \
    81 	[catch {set real 10.6} msg] $msg $real \
    82 	[catch {set bool no} msg] $msg $bool \
    83 	[catch {set string "new value"} msg] $msg $string \
    84 	[catch {set wide 12341234} msg] $msg $wide
    85 } {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 1 {can't set "wide": linked variable is read-only} 56785678}
    86 test link-3.2 {read-only variables} {testlink} {
    87     testlink delete
    88     testlink set 43 1.23 4 - 56785678
    89     testlink create 1 0 0 1 1
    90     list [catch {set int 4} msg] $msg $int \
    91 	[catch {set real 10.6} msg] $msg $real \
    92 	[catch {set bool no} msg] $msg $bool \
    93 	[catch {set string "new value"} msg] $msg $string\
    94 	[catch {set wide 12341234} msg] $msg $wide
    95 } {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} 0 12341234 12341234}
    96 
    97 test link-4.1 {unsetting linked variables} {testlink} {
    98     testlink delete
    99     testlink set -6 -2.5 0 stringValue 13579
   100     testlink create 1 1 1 1 1
   101     unset int real bool string wide
   102     list [catch {set int} msg] $msg [catch {set real} msg] $msg \
   103 	    [catch {set bool} msg] $msg [catch {set string} msg] $msg \
   104 	    [catch {set wide} msg] $msg
   105 } {0 -6 0 -2.5 0 0 0 stringValue 0 13579}
   106 test link-4.2 {unsetting linked variables} {testlink} {
   107     testlink delete
   108     testlink set -6 -2.1 0 stringValue 97531
   109     testlink create 1 1 1 1 1
   110     unset int real bool string wide
   111     set int 102
   112     set real 16
   113     set bool true
   114     set string newValue
   115     set wide 333555
   116     testlink get
   117 } {102 16.0 1 newValue 333555}
   118 
   119 test link-5.1 {unlinking variables} {testlink} {
   120     testlink delete
   121     testlink set -6 -2.25 0 stringValue 13579
   122     testlink delete
   123     set int xx1
   124     set real qrst
   125     set bool bogus
   126     set string 12345
   127     set wide 875421
   128     testlink get
   129 } {-6 -2.25 0 stringValue 13579}
   130 test link-5.2 {unlinking variables} {testlink} {
   131     testlink delete
   132     testlink set -6 -2.25 0 stringValue 97531
   133     testlink create 1 1 1 1 1
   134     testlink delete
   135     testlink set 25 14.7 7 - 999999
   136     list $int $real $bool $string $wide
   137 } {-6 -2.25 0 stringValue 97531}
   138 
   139 test link-6.1 {errors in setting up link} {testlink} {
   140     testlink delete
   141     catch {unset int}
   142     set int(44) 1
   143     list [catch {testlink create 1 1 1 1 1} msg] $msg
   144 } {1 {can't set "int": variable is array}}
   145 catch {unset int}
   146 
   147 test link-7.1 {access to linked variables via upvar} {testlink} {
   148     proc x {} {
   149 	upvar int y
   150 	unset y
   151     }
   152     testlink delete
   153     testlink create 1 0 0 0 0
   154     testlink set 14 {} {} {} {}
   155     x
   156     list [catch {set int} msg] $msg
   157 } {0 14}
   158 test link-7.2 {access to linked variables via upvar} {testlink} {
   159     proc x {} {
   160 	upvar int y
   161 	return [set y]
   162     }
   163     testlink delete
   164     testlink create 1 0 0 0 0
   165     testlink set 0 {} {} {} {}
   166     set int
   167     testlink set 23 {} {} {} {}
   168     x
   169     list [x] $int
   170 } {23 23}
   171 test link-7.3 {access to linked variables via upvar} {testlink} {
   172     proc x {} {
   173 	upvar int y
   174 	set y 44
   175     }
   176     testlink delete
   177     testlink create 0 0 0 0 0
   178     testlink set 11 {} {} {} {}
   179     list [catch x msg] $msg $int
   180 } {1 {can't set "y": linked variable is read-only} 11}
   181 test link-7.4 {access to linked variables via upvar} {testlink} {
   182     proc x {} {
   183 	upvar int y
   184 	set y abc
   185     }
   186     testlink delete
   187     testlink create 1 1 1 1 1
   188     testlink set -4 {} {} {} {}
   189     list [catch x msg] $msg $int
   190 } {1 {can't set "y": variable must have integer value} -4}
   191 test link-7.5 {access to linked variables via upvar} {testlink} {
   192     proc x {} {
   193 	upvar real y
   194 	set y abc
   195     }
   196     testlink delete
   197     testlink create 1 1 1 1 1
   198     testlink set -4 16.75 {} {} {}
   199     list [catch x msg] $msg $real
   200 } {1 {can't set "y": variable must have real value} 16.75}
   201 test link-7.6 {access to linked variables via upvar} {testlink} {
   202     proc x {} {
   203 	upvar bool y
   204 	set y abc
   205     }
   206     testlink delete
   207     testlink create 1 1 1 1 1
   208     testlink set -4 16.3 1 {} {}
   209     list [catch x msg] $msg $bool
   210 } {1 {can't set "y": variable must have boolean value} 1}
   211 test link-7.7 {access to linked variables via upvar} {testlink} {
   212     proc x {} {
   213 	upvar wide y
   214 	set y abc
   215     }
   216     testlink delete
   217     testlink create 1 1 1 1 1
   218     testlink set -4 16.3 1 {} 778899
   219     list [catch x msg] $msg $wide
   220 } {1 {can't set "y": variable must have integer value} 778899}
   221 
   222 test link-8.1 {Tcl_UpdateLinkedVar procedure} {testlink} {
   223     proc x args {
   224 	global x int real bool string wide
   225 	lappend x $args $int $real $bool $string $wide
   226     }
   227     set x {}
   228     testlink create 1 1 1 1 1
   229     testlink set 14 -2.0 0 xyzzy 995511
   230     trace var int w x
   231     testlink update 32 4.0 3 abcd 113355
   232     trace vdelete int w x
   233     set x
   234 } {{int {} w} 32 -2.0 0 xyzzy 995511}
   235 test link-8.2 {Tcl_UpdateLinkedVar procedure} {testlink} {
   236     proc x args {
   237 	global x int real bool string wide
   238 	lappend x $args $int $real $bool $string $wide
   239     }
   240     set x {}
   241     testlink create 1 1 1 1 1
   242     testlink set 14 -2.0 0 xyzzy 995511
   243     testlink delete
   244     trace var int w x
   245     testlink update 32 4.0 6 abcd 113355
   246     trace vdelete int w x
   247     set x
   248 } {}
   249 test link-8.3 {Tcl_UpdateLinkedVar procedure, read-only variable} {testlink} {
   250     testlink create 0 0 0 0 0
   251     list [catch {testlink update 47 {} {} {} {}} msg] $msg $int
   252 } {0 {} 47}
   253 
   254 catch {testlink set 0 0 0 - 0}
   255 catch {testlink delete}
   256 foreach i {int real bool string wide} {
   257     catch {unset $i}
   258 }
   259 
   260 # cleanup
   261 ::tcltest::cleanupTests
   262 return