|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jfig.utils.Gremlins
class for (pseudo-) random stress testing of the jfig editor. This class first creates a jfig2 editor window and then uses the java.awt.Robot class to create and execute random GUI events for fast testing of the editor and all editing functions, including modal and non-modal dialog windows. As the random generator seed can be specified on the command line, it is possible to repeat sequences of events. Note that it may be necessary to run the test as a privileged user or with GUI-specific extensions. Also note that the Robot class may potentially generate events that control the window manager or other applications. Due to the random nature of the generated events, there is the additional danger of writing to random files, which is DANGEROUS. You should have a backup of all files in the local directory and your '.jfigrc' configuration file in your home directory.
After initialization of the editor and the Robot, the basic testing algorithm checks whether the user-specified limit values for the number-of-events or the run-time have been reached. If not, it randomly selects a GUI leaf component as the target of the next event. When dialog windows are open, only leaf components in the dialog are considered. To avoid a 'deadlock' in case the dialog GUI provides no separate 'OK' or 'Cancel' controls, WindowClose events will be generated with a low probabibility, too. After selection of the GUI component, the class checks for the type of the component (Button, TextField, etc) and uses (hard-coded) probabilities to decide whether to generate a mouse click, and key click, etc. This event is then delivered to the GUI via the Robot class and executed by the editor.
To avoid race-conditions, the Robot is instructed to wait after each event.
NOTE: a much better strategy than fully random testing would obviously to (1) select a random command, (2) set several of the attributes available for that command, and (3) generate a few dozen mouse clicks and mouse moves, (4) specify new attributes and then a few more mouse clicks. Also, mouse clicks should sometimes occur at the position of existing objects and not purely random. From time to time, we would also select a menu command. Dialog windows, if visible, should be closed with a fixed probability but except for that, the GUI components of that window should be modified randomly.
Field Summary | |
static int |
BUTTON1
|
static int |
BUTTON2
|
static int |
BUTTON3
|
(package private) JModularEditor |
editor
|
(package private) java.util.Vector |
editorComponents
|
(package private) java.util.Random |
generator
|
static int |
KEY_ASCII
|
static int |
KEY_CURSOR
|
static int |
KEY_NUMBER
|
(package private) int[] |
keycodes
|
static int[] |
keycodesASCII
|
static int[] |
keycodesCURSOR
|
static int[] |
keycodesNUMERIC
|
(package private) java.awt.Component |
lastActiveComponent
|
(package private) int |
max_events
|
(package private) int |
max_seconds
|
static int |
MOUSE_DRAG
|
static int |
MOUSE_LEFT_CLICK
|
static int |
MOUSE_MIDDLE_CLICK
|
static int |
MOUSE_MOVE
|
static int |
MOUSE_RIGHT_CLICK
|
(package private) int |
mouse_x
|
(package private) int |
mouse_y
|
(package private) int |
n_events
|
(package private) int |
n_seconds
|
static java.lang.String[] |
names
|
static double[] |
pFigSwingCanvas
|
static double[] |
pJButton
|
static double[] |
pJComboBox
|
static double[] |
pJComponent
|
static double[] |
pJImageButton
|
static double[] |
pJStateButton
|
static double[] |
pJTextField
|
(package private) java.awt.Robot |
robot
|
(package private) java.awt.Dimension |
screenSize
|
(package private) long |
seed
|
(package private) long |
t_start
|
Constructor Summary | |
Gremlins()
|
Method Summary | |
void |
clearObjects()
|
int |
clip(int value,
int min,
int max)
|
void |
createKeyCodeTable()
|
void |
createKeyTypeAscii(java.awt.Component target)
|
void |
createKeyTypeCursor(java.awt.Component target)
|
void |
createKeyTypeNumber(java.awt.Component target)
|
void |
createMouseClick(java.awt.Component target,
int MASK)
|
void |
createMouseDrag(java.awt.Component target)
|
void |
createMouseMove()
simulate a "human mouse" event. |
void |
createMouseMove(java.awt.Component target)
|
void |
createOneRandomEvent()
|
void |
createRandomComponentEvent(java.awt.Component target)
|
void |
createRandomWeightedEvent(java.awt.Component target,
double[] weights)
|
void |
enumerateLeafComponents(java.awt.Container container,
java.util.Vector v)
enumerate all leaf GUI components for the given container and put the into the given Vector. |
java.awt.Window |
findActiveWindow(java.awt.Window parent)
check whether one or more dialog windows are currently showing, and find the (topmost) active window. |
JImageButton |
findImageButton(java.lang.String label)
|
java.awt.Rectangle |
getLocation(java.awt.Component target)
|
double |
getRandom(double min,
double max)
|
int |
getRunTimeSeconds(long start_millis)
|
static void |
main(java.lang.String[] argv)
|
void |
modifyJStateButton(java.lang.Object tmp)
set a new random value for the given JStateButton. |
static void |
msg(java.lang.String s)
|
void |
resetAttributes()
|
void |
runCreateArcTest(int n_iterations)
|
void |
runCreateBezierTest(int n_iterations)
|
void |
runCreateCircleTest(int n_iterations)
|
void |
runCreateClosedBezierTest(int n_iterations)
|
void |
runCreateClosedSplineTest(int n_iterations)
|
void |
runCreateEllipseTest(int n_iterations)
|
void |
runCreateImageObjectTest()
|
void |
runCreateLibraryObjectTest()
|
void |
runCreateObjectsTest()
|
void |
runCreatePolygonTest(int n_iterations)
|
void |
runCreatePolylineTest(int n_iterations)
|
void |
runCreateRectangleTest(int n_iterations)
|
void |
runCreateRoundRectangleTest(int n_iterations)
|
void |
runCreateSplineTest(int n_iterations)
|
void |
runCreateTextTest(int n_iterations)
|
void |
runModifyObjectsTest()
|
void |
runRandomTest()
|
java.awt.Frame |
selectActiveFrame()
query the editor for a list of all currently active Frames, and randomly select one of them. |
java.awt.Component |
selectRandomLeafComponent(java.awt.Window window)
enumerate all leaf (non container) GUI components in the given window and randomly select one of them. |
void |
setMaxEventCount(int n)
|
void |
setMaxSeconds(int n)
|
void |
setRandomAttributes()
set random values for all currently enabled attribute controls. |
void |
setSeed(long _seed)
|
void |
testJStateButtonSelectDialog(JStateButton button)
test the selection dialog of a JStateButton. |
static void |
usage()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
long seed
int n_seconds
int n_events
int max_seconds
int max_events
int mouse_x
int mouse_y
long t_start
int[] keycodes
java.util.Random generator
java.awt.Dimension screenSize
java.awt.Robot robot
JModularEditor editor
java.awt.Component lastActiveComponent
java.util.Vector editorComponents
public static final int BUTTON1
public static final int BUTTON2
public static final int BUTTON3
public static final int MOUSE_MOVE
public static final int MOUSE_DRAG
public static final int MOUSE_LEFT_CLICK
public static final int MOUSE_MIDDLE_CLICK
public static final int MOUSE_RIGHT_CLICK
public static final int KEY_ASCII
public static final int KEY_NUMBER
public static final int KEY_CURSOR
public static final java.lang.String[] names
public static final double[] pFigSwingCanvas
public static final double[] pJImageButton
public static final double[] pJStateButton
public static final double[] pJTextField
public static final double[] pJButton
public static final double[] pJComboBox
public static final double[] pJComponent
public static final int[] keycodesNUMERIC
public static final int[] keycodesASCII
public static final int[] keycodesCURSOR
Constructor Detail |
public Gremlins()
Method Detail |
public void setSeed(long _seed)
public void setMaxSeconds(int n)
public void setMaxEventCount(int n)
public int getRunTimeSeconds(long start_millis)
public void createKeyCodeTable()
public void runRandomTest()
public void runCreateObjectsTest()
public void clearObjects()
public void runModifyObjectsTest()
public void runCreateRectangleTest(int n_iterations)
public void runCreateRoundRectangleTest(int n_iterations)
public void runCreateCircleTest(int n_iterations)
public void runCreateEllipseTest(int n_iterations)
public void runCreatePolylineTest(int n_iterations)
public void runCreatePolygonTest(int n_iterations)
public void runCreateSplineTest(int n_iterations)
public void runCreateClosedSplineTest(int n_iterations)
public void runCreateBezierTest(int n_iterations)
public void runCreateClosedBezierTest(int n_iterations)
public void runCreateArcTest(int n_iterations)
public void runCreateTextTest(int n_iterations)
public void runCreateImageObjectTest()
public void runCreateLibraryObjectTest()
public JImageButton findImageButton(java.lang.String label)
public void setRandomAttributes()
public void resetAttributes()
public void modifyJStateButton(java.lang.Object tmp)
public void testJStateButtonSelectDialog(JStateButton button)
Special support is included to handle nested-nested dialogs like the JColorChooser in JColorButton-Select-Add new color-JColorChooser.
public void createOneRandomEvent()
public java.awt.Frame selectActiveFrame()
public java.awt.Window findActiveWindow(java.awt.Window parent)
public java.awt.Component selectRandomLeafComponent(java.awt.Window window)
For performance reasons, we cache the leaf components per window.
public void enumerateLeafComponents(java.awt.Container container, java.util.Vector v)
public void createRandomComponentEvent(java.awt.Component target)
public void createRandomWeightedEvent(java.awt.Component target, double[] weights)
public void createMouseMove(java.awt.Component target)
public void createMouseDrag(java.awt.Component target)
public void createMouseClick(java.awt.Component target, int MASK)
public void createKeyTypeAscii(java.awt.Component target)
public void createKeyTypeNumber(java.awt.Component target)
public void createKeyTypeCursor(java.awt.Component target)
public java.awt.Rectangle getLocation(java.awt.Component target)
public void createMouseMove()
public int clip(int value, int min, int max)
public double getRandom(double min, double max)
public static void msg(java.lang.String s)
public static void usage()
public static void main(java.lang.String[] argv)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |