os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/async.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_AsyncCreate 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-1996 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: async.test,v 1.5 2000/04/10 17:18:56 ericm Exp $
    15 
    16 if {[lsearch [namespace children] ::tcltest] == -1} {
    17     package require tcltest
    18     namespace import -force ::tcltest::*
    19 }
    20 
    21 if {[info commands testasync] == {}} {
    22     puts "This application hasn't been compiled with the \"testasync\""
    23     puts "command, so I can't test Tcl_AsyncCreate et al."
    24     ::tcltest::cleanupTests
    25     return
    26 }
    27 
    28 proc async1 {result code} {
    29     global aresult acode
    30     set aresult $result
    31     set acode $code
    32     return "new result"
    33 }
    34 proc async2 {result code} {
    35     global aresult acode
    36     set aresult $result
    37     set acode $code
    38     return -code error "xyzzy"
    39 }
    40 proc async3 {result code} {
    41     global aresult
    42     set aresult "test pattern"
    43     return -code $code $result
    44 }
    45 
    46 set handler1 [testasync create async1]
    47 set handler2 [testasync create async2]
    48 set handler3 [testasync create async3]
    49 test async-1.1 {basic async handlers} {
    50     set aresult xxx
    51     set acode yyy
    52     list [catch {testasync mark $handler1 "original" 0} msg] $msg \
    53 	   $acode $aresult
    54 } {0 {new result} 0 original}
    55 test async-1.2 {basic async handlers} {
    56     set aresult xxx
    57     set acode yyy
    58     list [catch {testasync mark $handler1 "original" 1} msg] $msg \
    59 	   $acode $aresult
    60 } {0 {new result} 1 original}
    61 test async-1.3 {basic async handlers} {
    62     set aresult xxx
    63     set acode yyy
    64     list [catch {testasync mark $handler2 "old" 0} msg] $msg \
    65 	   $acode $aresult
    66 } {1 xyzzy 0 old}
    67 test async-1.4 {basic async handlers} {
    68     set aresult xxx
    69     set acode yyy
    70     list [catch {testasync mark $handler2 "old" 3} msg] $msg \
    71 	   $acode $aresult
    72 } {1 xyzzy 3 old}
    73 test async-1.5 {basic async handlers} {
    74     set aresult xxx
    75     list [catch {testasync mark $handler3 "foobar" 0} msg] $msg $aresult
    76 } {0 foobar {test pattern}}
    77 test async-1.6 {basic async handlers} {
    78     set aresult xxx
    79     list [catch {testasync mark $handler3 "foobar" 1} msg] $msg $aresult
    80 } {1 foobar {test pattern}}
    81 
    82 proc mult1 {result code} {
    83     global x
    84     lappend x mult1
    85     return -code 7 mult1
    86 }
    87 set hm1 [testasync create mult1]
    88 proc mult2 {result code} {
    89     global x
    90     lappend x mult2
    91     return -code 9 mult2
    92 }
    93 set hm2 [testasync create mult2]
    94 proc mult3 {result code} {
    95     global x hm1 hm2
    96     lappend x [catch {testasync mark $hm2 serial2 0}]
    97     lappend x [catch {testasync mark $hm1 serial1 0}]
    98     lappend x mult3
    99     return -code 11 mult3
   100 }
   101 set hm3 [testasync create mult3]
   102 
   103 test async-2.1 {multiple handlers} {
   104     set x {}
   105     list [catch {testasync mark $hm3 "foobar" 5} msg] $msg $x
   106 } {9 mult2 {0 0 mult3 mult1 mult2}}
   107 
   108 proc del1 {result code} {
   109     global x hm1 hm2 hm3 hm4
   110     lappend x [catch {testasync mark $hm3 serial2 0}]
   111     lappend x [catch {testasync mark $hm1 serial1 0}]
   112     lappend x [catch {testasync mark $hm4 serial1 0}]
   113     testasync delete $hm1
   114     testasync delete $hm2
   115     testasync delete $hm3
   116     lappend x del1
   117     return -code 13 del1
   118 }
   119 proc del2 {result code} {
   120     global x
   121     lappend x del2
   122     return -code 3 del2
   123 }
   124 testasync delete $handler1
   125 testasync delete $hm2
   126 testasync delete $hm3
   127 set hm2 [testasync create del1]
   128 set hm3 [testasync create mult2]
   129 set hm4 [testasync create del2]
   130 
   131 test async-3.1 {deleting handlers} {
   132     set x {}
   133     list [catch {testasync mark $hm2 "foobar" 5} msg] $msg $x
   134 } {3 del2 {0 0 0 del1 del2}}
   135 
   136 # cleanup
   137 testasync delete
   138 ::tcltest::cleanupTests
   139 return
   140 
   141 
   142 
   143 
   144 
   145 
   146 
   147 
   148 
   149 
   150 
   151