001: /*
002: * TestEpoch.java --
003: *
004: * Copyright (c) 2005 Mo DeJong
005: *
006: * See the file "license.terms" for information on usage and
007: * redistribution of this file, and for a DISCLAIMER OF ALL
008: * WARRANTIES.
009: *
010: * RCS: @(#) $Id: TestEpoch.java,v 1.1 2005/11/21 02:02:41 mdejong Exp $
011: *
012: */
013:
014: package tcl.lang;
015:
016: class TestEpoch {
017: // Increment a command's WrappedCommand.cmdEpoch when deleting
018: // a command because the command is redefined.
019:
020: public static String testCmdEpoch1(Interp interp)
021: throws TclException {
022: String cmdName = "testCmdEpoch1";
023:
024: // Create proc
025: interp.eval("proc " + cmdName + " {} {return " + cmdName + "}",
026: TCL.EVAL_GLOBAL);
027:
028: // Get WrappedCommand for proc
029: WrappedCommand wcmd = Namespace.findCommand(interp, cmdName,
030: null, TCL.GLOBAL_ONLY);
031:
032: // Save cmdEpoch
033: int cmdEpoch = wcmd.cmdEpoch;
034:
035: // Redefine proc
036: interp.eval("proc " + cmdName + " {} {return dummy}",
037: TCL.EVAL_GLOBAL);
038:
039: // Double check that command was actually redefined
040: WrappedCommand new_wcmd = Namespace.findCommand(interp,
041: cmdName, null, TCL.GLOBAL_ONLY);
042: if (wcmd == new_wcmd) {
043: return "ERROR: command not redefined";
044: }
045:
046: // Check that cmdEpoch was incremented on original cmd ref
047:
048: String result;
049: if (wcmd.cmdEpoch == (cmdEpoch + 1)) {
050: result = "OK";
051: } else {
052: result = "expected cmdEpoch " + (cmdEpoch + 1)
053: + " but got " + wcmd.cmdEpoch;
054: }
055:
056: return result;
057: }
058:
059: // Increment a command's WrappedCommand.cmdEpoch when deleting
060: // a command.
061:
062: public static String testCmdEpoch2(Interp interp)
063: throws TclException {
064: String cmdName = "testCmdEpoch2";
065:
066: // Create proc
067: interp.eval("proc " + cmdName + " {} {return " + cmdName + "}",
068: TCL.EVAL_GLOBAL);
069:
070: // Get WrappedCommand for proc
071: WrappedCommand wcmd = Namespace.findCommand(interp, cmdName,
072: null, TCL.GLOBAL_ONLY);
073:
074: // Save cmdEpoch
075: int cmdEpoch = wcmd.cmdEpoch;
076:
077: // Delete proc
078: interp.eval("rename " + cmdName + " {}", TCL.EVAL_GLOBAL);
079:
080: // Check that cmdEpoch was incremented on original cmd ref
081:
082: String result;
083: if (wcmd.cmdEpoch == (cmdEpoch + 1)) {
084: result = "OK";
085: } else {
086: result = "expected cmdEpoch " + (cmdEpoch + 1)
087: + " but got " + wcmd.cmdEpoch;
088: }
089:
090: return result;
091: }
092:
093: // Increment a command's WrappedCommand.cmdEpoch when the
094: // command is renamed.
095:
096: public static String testCmdEpoch3(Interp interp)
097: throws TclException {
098: String cmdName = "testCmdEpoch3";
099:
100: // Create proc
101: interp.eval("proc " + cmdName + " {} {return " + cmdName + "}",
102: TCL.EVAL_GLOBAL);
103:
104: // Get WrappedCommand for proc
105: WrappedCommand wcmd = Namespace.findCommand(interp, cmdName,
106: null, TCL.GLOBAL_ONLY);
107:
108: // Save cmdEpoch
109: int cmdEpoch = wcmd.cmdEpoch;
110:
111: // Rename proc
112: interp.eval("catch {rename dummy" + cmdName + " {}}",
113: TCL.EVAL_GLOBAL);
114: interp.eval("rename " + cmdName + " dummy" + cmdName,
115: TCL.EVAL_GLOBAL);
116:
117: // Double check that command was actually renamed
118: WrappedCommand new_wcmd = Namespace.findCommand(interp,
119: cmdName, null, TCL.GLOBAL_ONLY);
120: if (new_wcmd != null) {
121: return "ERROR: command not renamed";
122: }
123:
124: // Check that cmdEpoch was incremented on original cmd ref
125:
126: String result;
127: if (wcmd.cmdEpoch == (cmdEpoch + 1)) {
128: result = "OK";
129: } else {
130: result = "expected cmdEpoch " + (cmdEpoch + 1)
131: + " but got " + wcmd.cmdEpoch;
132: }
133:
134: return result;
135: }
136: }
|