os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/cmdInfo.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 # Commands covered:  none
     2 #
     3 # This file contains a collection of tests for Tcl_GetCommandInfo,
     4 # Tcl_SetCommandInfo, Tcl_CreateCommand, Tcl_DeleteCommand, and
     5 # Tcl_NameOfCommand.  Sourcing this file into Tcl runs the tests
     6 # and generates output for errors.  No output means no errors were
     7 # found.
     8 #
     9 # Copyright (c) 1993 The Regents of the University of California.
    10 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
    11 # Copyright (c) 1998-1999 by Scriptics Corporation.
    12 #
    13 # See the file "license.terms" for information on usage and redistribution
    14 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    15 #
    16 # RCS: @(#) $Id: cmdInfo.test,v 1.7 2002/06/22 04:19:47 dgp Exp $
    17 
    18 if {[lsearch [namespace children] ::tcltest] == -1} {
    19     package require tcltest 2
    20     namespace import -force ::tcltest::*
    21 }
    22 
    23 ::tcltest::testConstraint testcmdinfo \
    24 	[llength [info commands testcmdinfo]]
    25 ::tcltest::testConstraint testcmdtoken \
    26 	[llength [info commands testcmdtoken]]
    27 
    28 test cmdinfo-1.1 {command procedure and clientData} {testcmdinfo} {
    29     testcmdinfo create x1
    30     testcmdinfo get x1
    31 } {CmdProc1 original CmdDelProc1 original :: stringProc}
    32 test cmdinfo-1.2 {command procedure and clientData} {testcmdinfo} {
    33     testcmdinfo create x1
    34     x1
    35 } {CmdProc1 original}
    36 test cmdinfo-1.3 {command procedure and clientData} {testcmdinfo} {
    37     testcmdinfo create x1
    38     testcmdinfo modify x1
    39     testcmdinfo get x1
    40 } {CmdProc2 new_command_data CmdDelProc2 new_delete_data :: stringProc}
    41 test cmdinfo-1.4 {command procedure and clientData} {testcmdinfo} {
    42     testcmdinfo create x1
    43     testcmdinfo modify x1
    44     x1
    45 } {CmdProc2 new_command_data}
    46 
    47 test cmdinfo-2.1 {command deletion callbacks} {testcmdinfo} {
    48     testcmdinfo create x1
    49     testcmdinfo delete x1
    50 } {CmdDelProc1 original}
    51 test cmdinfo-2.2 {command deletion callbacks} {testcmdinfo} {
    52     testcmdinfo create x1
    53     testcmdinfo modify x1
    54     testcmdinfo delete x1
    55 } {CmdDelProc2 new_delete_data}
    56 
    57 test cmdinfo-3.1 {Tcl_Get/SetCommandInfo return values} {testcmdinfo} {
    58     testcmdinfo get non_existent
    59 } {??}
    60 test cmdinfo-3.2 {Tcl_Get/SetCommandInfo return values} {testcmdinfo} {
    61     testcmdinfo create x1
    62     testcmdinfo modify x1
    63 } 1
    64 test cmdinfo-3.3 {Tcl_Get/SetCommandInfo return values} {testcmdinfo} {
    65     testcmdinfo modify non_existent
    66 } 0
    67 
    68 test cmdinfo-4.1 {Tcl_GetCommandName/Tcl_GetCommandFullName procedures} \
    69 	{testcmdtoken} {
    70     set x [testcmdtoken create x1]
    71     rename x1 newName
    72     set y [testcmdtoken name $x]
    73     rename newName x1
    74     eval lappend y [testcmdtoken name $x]
    75 } {newName ::newName x1 ::x1}
    76 
    77 catch {rename newTestCmd {}}
    78 catch {rename newTestCmd2 {}}
    79 
    80 test cmdinfo-5.1 {Names for commands created when inside namespaces} \
    81 	{testcmdtoken} {
    82     # create namespace cmdInfoNs1
    83     namespace eval cmdInfoNs1 {}   ;# creates namespace cmdInfoNs1
    84     # create namespace cmdInfoNs1::cmdInfoNs2 and execute a script in it
    85     set x [namespace eval cmdInfoNs1::cmdInfoNs2 {
    86         # the following creates a cmd in the global namespace
    87         testcmdtoken create testCmd
    88     }]
    89     set y [testcmdtoken name $x]
    90     rename ::testCmd newTestCmd
    91     eval lappend y [testcmdtoken name $x]
    92 } {testCmd ::testCmd newTestCmd ::newTestCmd}
    93 
    94 test cmdinfo-6.1 {Names for commands created when outside namespaces} \
    95 	{testcmdtoken} {
    96     set x [testcmdtoken create cmdInfoNs1::cmdInfoNs2::testCmd]
    97     set y [testcmdtoken name $x]
    98     rename cmdInfoNs1::cmdInfoNs2::testCmd newTestCmd2
    99     eval lappend y [testcmdtoken name $x]
   100 } {testCmd ::cmdInfoNs1::cmdInfoNs2::testCmd newTestCmd2 ::newTestCmd2}
   101 
   102 # cleanup
   103 catch {namespace delete cmdInfoNs1::cmdInfoNs2 cmdInfoNs1}
   104 catch {rename x1 ""}
   105 ::tcltest::cleanupTests
   106 return