Using tcl to Replay Xt Applications
Presented talk at AUUG94 by Jan Newmarch.
Why ``play'' Xt Applications?
-
Automated testing of GUI applications.
-
Automated demonstration of GUI applications.
-
Scripting language to control Xt Applications
cf AppleScript
X support for record/replay
-
Preparation of X events.
-
Extensions like XTrap allow X event capture.
-
Insertion into the X event queue by
XSendEvent().
-
Capture of X windows as screendumps.
-
Comparison of screendumps.
Drawbacks of X approaches
-
X events require x, y co-ordinates.
-
Moving or resizing windows may invalidate this.
-
Screendump comparisons rely on:
-
sizes.
-
co-ordinates.
-
colormaps.
-
structure.
Xt objects
-
Xt defines objects called widgets.
-
Widgets have ``methods'' called ``actions''.
e.g. Motif PushButton has actions
Arm() Disarm() Activate()
-
User level events are mapped into actions.
-
Actions call application-level callback functions.
Xt replay system
-
Actions define widget methods.
-
The Xt function
XtCallActionProc()
invokes a method.
-
A sequence of
XtCallActionsProc's
allows replay of an Xt application.
XtCallActionProc(btn,
"Arm()", event);
XtCallActionProc(btn,
"Disarm()", event);
XtCallActionProc(text,
"insert()", event);
Major Xt problems
-
Events enter the Xt event queue and are processed by
XtAppMainLoop().
-
Simulation method must allow queuing, and must allow processing.
-
Some actions require event information.
e.g. The Disarm() action for a Motif
PushButton.
-
Gadgets don't have actions.
Major simulation language problems
-
Use may exceed design: need a full programming language.
-
Language must integrate into Xt requirements (rules out C).
-
Preference for non-proprietary language.
-
Require extensible language.
Tcl - Tool Command Language
-
An application-independant command language.
-
An extensible language.
-
An embeddable language.
-
Free.
-
Source code availability
Structure of a tcl-enabled application
New tcl command - callActionProc
-
Define a new command to the tcl interpreter.
callActionProc widget action
-
Link this to C code that
-
Uses
XtNameToWidget()
to locate widget.
-
Prepares suitable X event and other parameters.
-
Calls
XtCallActionProc()
Event loops
-
Failed method:
source the file of commands.
This puts all actions into the queue, and does no processing
of events till the end.
-
Failed method: parse the file into commands, and run each as a
``work procedure''.
Won't allow for the delays required for demonstrations.
-
Failed method: parse the file into commands, and run each using
an Xt timer.
Can't easily penetrate toplevel of the parse tree, e.g.
into loops and procedures.
-
Successful method: use the tcl ``trace'' mechanism to call
XtProcessEvent().
Atomic at the tcl level; processes all pending Xt events.
Sample script
This performs 12 + 34 = for xcalc
callActionProc *screen.LCD digit(1)
sleep 1000
callActionProc *screen.LCD digit(2)
sleep 1000
callActionProc *screen.LCD add()
sleep 1000
callActionProc *screen.LCD digit(3)
sleep 1000
callActionProc *screen.LCD digit(4)
sleep 1000
callActionProc *screen.LCD equal()
Goodies and baddies
-
tcl allows for procedural abstraction e.g.
proc click {w} {
callActionProc $w Arm()
sleep 500
callActionProc $w Activate()
}
-
tcl allows for stress testing e.g.
for {set n 0} {$n < 100} {incr n} {
testit
}
-
An interface to
XtGetValues allows query of
widget state e.g.
getValues $w \
-width width \
-height height \
set mid_x [expr $width/2]
set mid_y [expr $height/2]
warpPointer $w $mid_x $mid_y
-
The function
XtAppAddActionHook() allows recording of
actions, but in a less than ideal form.
-
Gadgets are hacks to place load on the application side instead
of on the server. Proper handling of them requires regularities
not specified by Xt.
-
The Motif List widget has non-widget, non-gadget internal structure.
Send
-
A communication method between X applications.
send application tcl-command
-
Designed by John Ousterhout for Tk.
-
Ported to Xt.
-
Builtin to replay library.
-
Allows tcl to be used as a scripting language like Apple's AppleScript
Status
-
Current version: 1.2
-
Available as a library with a single entry point.
-
Publically available from ftp.canberra.edu.au
Results