TIPTestImpl.mesa
Copyright Ó 1988, 1991, 1992 by Xerox Corporation. All rights reserved.
Bier, November 18, 1988 5:07:14 pm PST
Michael Plass, November 26, 1991 1:38 pm PST
Christian Jacobi, February 24, 1992 4:05 pm PST
Contents: Testing TIP.
DIRECTORY
Atom, CodeTimer, Commander, IO, KeySyms1, KeySymsKB, KeyMapping, KeyTypes, Rope, TIPKeyboards, TIPPrivate, TIPTables, TIPTest, TIPUser, Process, UserInput, UserInputGetActions, UserInputInsertActions, UserInputOps;
TIPTestImpl: CEDAR PROGRAM
IMPORTS Atom, CodeTimer, Commander, IO, KeyMapping, TIPKeyboards, TIPPrivate, TIPUser, Process, UserInputInsertActions, UserInputOps
EXPORTS TIPTest
SHARES TIPPrivate
=
BEGIN
KeyTable: TYPE = KeyMapping.KeyTable;
KeyTableRep: TYPE = KeyMapping.KeyTableRep;
KeySyms: TYPE = KeyMapping.KeySyms;
KeySymsRep: TYPE = KeyMapping.KeySymsRep;
KeyCode: TYPE = KeyTypes.KeyCode;
ROPE: TYPE = Rope.ROPE;
TIPClient: TYPE = TIPPrivate.TIPClient;
TIPClientRec: TYPE = TIPPrivate.TIPClientRec;
secondsToPause: INTEGER ¬ 45;
Reset: PROC [cmd: Commander.Handle] RETURNS [result: REF ¬ NIL, msg: ROPE ¬ NIL] = {
CodeTimer.ResetTable[CodeTimer.GetTable[$PTIP]];
};
Print: PROC [cmd: Commander.Handle] RETURNS [result: REF ¬ NIL, msg: ROPE ¬ NIL] = {
CodeTimer.PrintTable[cmd.out, CodeTimer.GetTable[$PTIP]];
};
ParseTIP: PUBLIC PROC [name: Rope.ROPE] RETURNS [table: REF ANY] = {
table ¬ TIPUser.InstantiateNewTIPTable[name];
};
TryTIP: PROC [cmd: Commander.Handle] RETURNS [result: REF ¬ NIL, msg: ROPE ¬ NIL] = {
OPEN KeySyms1, KeySymsKB;
table: TIPUser.TIPTable;
parseInfo: TIPPrivate.TIPParseInfo;
downAction: UserInputGetActions.InputActionBody;
upAction: UserInputGetActions.InputActionBody;
event: LIST OF REF ANY;
out: IO.STREAM;
nameStream: IO.STREAM ¬ IO.RIS[cmd.commandLine];
name: Rope.ROPE;
handle: UserInput.Handle;
downAction.kind ¬ $Key;
downAction.down ¬ TRUE;
upAction.kind ¬ $Key;
upAction.down ¬ FALSE;
[] ¬ IO.SkipWhitespace[nameStream];
name ¬ IO.GetLineRope[nameStream];
out ¬ cmd.out;
table ¬ TIPUser.InstantiateNewTIPTable[name];
parseInfo ¬ TIPPrivate.CreateParseInfo[table];
handle ¬ parseInfo.inCreek;
SetUpPrincOpsKeyboard[handle];
Try keys going down and up
FOR keyCode: KeyCode IN [keycode0..VAL[111]] DO
downAction.keyCode ¬ keyCode;
upAction.keyCode ¬ keyCode;
event ¬ TIPPrivate.WideMatchEvent[parseInfo, downAction];
PrintResult[out, event];
event ¬ TIPPrivate.WideMatchEvent[parseInfo, upAction];
PrintResult[out, event];
ENDLOOP;
};
TestNotify: TIPPrivate.TIPNotifyProc = {
PrintResult[out, results];
};
out: IO.STREAM;
SetUpPrincOpsKeyboard: PROC [handle: UserInput.Handle] = {
keyTable: KeyMapping.KeyTable;
success: BOOL ¬ FALSE;
keySym1, keySym2: KeyTypes.KeySym;
keyTable ¬ NEW[KeyMapping.KeyTableRep];
FOR keyCode: KeyMapping.KeyCode IN KeyMapping.KeyCode DO
[keySym1, keySym2, success] ¬ TIPKeyboards.KeySymsFromKeyCode[keyCode];
IF success THEN {
keyTable[keyCode] ¬ NEW[KeyMapping.KeySymsRep[2]];
keyTable[keyCode][0] ¬ keySym1;
keyTable[keyCode][1] ¬ keySym2;
}
ELSE {
keyTable[keyCode] ¬ NEW[KeyMapping.KeySymsRep[0]];
};
ENDLOOP;
UserInputOps.SetMapping[handle, KeyMapping.NewMapping[keyTable]];
};
Queue: PROC [cmd: Commander.Handle] RETURNS [result: REF ¬ NIL, msg: ROPE ¬ NIL] = {
OPEN KeySyms1, KeySymsKB;
table: TIPUser.TIPTable;
tipClient: TIPClient;
handle: UserInput.Handle;
downAction: UserInputGetActions.InputActionBody;
upAction: UserInputGetActions.InputActionBody;
success: BOOL ¬ FALSE;
controlCodes, shiftCodes: KeyMapping.KeyCodes;
nameStream: IO.STREAM ¬ IO.RIS[cmd.commandLine];
name: Rope.ROPE;
[] ¬ IO.SkipWhitespace[nameStream];
name ¬ IO.GetLineRope[nameStream];
out ¬ cmd.out;
tipClient ¬ TIPPrivate.CreateTIPClient[TestNotify, NIL, NIL];
handle ¬ tipClient.parseInfo.inCreek;
SetUpPrincOpsKeyboard[handle];
table ¬ TIPUser.InstantiateNewTIPTable[name];
TIPPrivate.PushTIPTable[tipClient, table, FALSE];
TIPPrivate.StartTIPClient[tipClient]; -- fork a matcher process
Try keys going down and up
FOR keyCode: KeyCode IN [keycode0..VAL[111]] DO
downAction.keyCode ¬ keyCode;
UserInputInsertActions.InsertKey[handle, 0, TRUE, keyCode];
UserInputInsertActions.InsertKey[handle, 0, FALSE, keyCode];
ENDLOOP;
controlCodes ¬ KeyMapping.KeyCodesFromKeySym[UserInputOps.GetMapping[handle], KeySymsKB.LeftControl];
IF controlCodes.n<1 THEN ERROR;
Do it again with the Control key down.
UserInputInsertActions.InsertKey[handle, 0, TRUE, controlCodes[0].keyCode];
FOR keyCode: KeyCode IN [keycode0..VAL[111]] DO
IF keyCode = controlCodes[0].keyCode THEN LOOP;
UserInputInsertActions.InsertKey[handle, 0, TRUE, keyCode];
UserInputInsertActions.InsertKey[handle, 0, FALSE, keyCode];
ENDLOOP;
upAction.keyCode ¬ controlCodes[0].keyCode;
UserInputInsertActions.InsertKey[handle, 0, FALSE, controlCodes[0].keyCode];
shiftCodes ¬ KeyMapping.KeyCodesFromKeySym[UserInputOps.GetMapping[handle], KeySymsKB.LeftShift];
IF shiftCodes.n<1 THEN ERROR;
Do it again with the Shift key down.
UserInputInsertActions.InsertKey[handle, 0, TRUE, shiftCodes[0].keyCode];
FOR keyCode: KeyCode IN [keycode0..VAL[111]] DO
IF keyCode = shiftCodes[0].keyCode THEN LOOP;
UserInputInsertActions.InsertKey[handle, 0, TRUE, keyCode];
UserInputInsertActions.InsertKey[handle, 0, FALSE, keyCode];
ENDLOOP;
Do it again with Control and Shift Down
UserInputInsertActions.InsertKey[handle, 0, TRUE, controlCodes[0].keyCode];
FOR keyCode: KeyCode IN [keycode0..VAL[111]] DO
IF keyCode = controlCodes[0].keyCode OR keyCode = shiftCodes[0].keyCode THEN LOOP;
UserInputInsertActions.InsertKey[handle, 0, TRUE, keyCode];
UserInputInsertActions.InsertKey[handle, 0, FALSE, keyCode];
ENDLOOP;
Process.Pause[ticks: Process.SecondsToTicks[secondsToPause]];
};
PrintResult: PROC [s: IO.STREAM, result: LIST OF REF ANY] = {
PrintElement: PROC [s: IO.STREAM, element: REF ANY] = {
WITH element SELECT FROM
atom: ATOM => s.PutRope[Atom.GetPName[atom]];
coords: TIPUser.TIPScreenCoords => s.PutRope["Coords"];
char: REF CHAR => {s.PutChar['']; s.PutChar[char­];};
time: TIPUser.TIPTime => s.PutRope["Time"];
int: REF INT => s.PutF1["%g", [integer[int­]]];
text: REF TEXT => s.PutBlock[text];
ENDCASE => ERROR;
s.PutChar[IO.SP];
};
IF result = NIL THEN s.PutRope["----"]
ELSE {
FOR list: LIST OF REF ANY ¬ result, list.rest UNTIL list = NIL DO
PrintElement[s, list.first];
ENDLOOP;
};
s.PutChar[IO.CR];
};
Commander.Register["queue", Queue, "queue <filename.tip>, parses a tip table, queues a sequence of keyboard and mouse actions, filters them with the tip table, and prints out the results"];
Commander.Register["trytip", TryTIP, "match <filename.tip>, parses a tip table, and filters a set of keyboard actions through the tip table, and prints out the results"];
Commander.Register["resetTIP", Reset, "Clears the CodeTimer table that measures TIP performance"];
Commander.Register["printTIP", Print, "Prints out the CodeTimer table for TIP performance"];
END.