jfig.utils
Class Gremlins

java.lang.Object
  extended byjfig.utils.Gremlins

public class Gremlins
extends java.lang.Object

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

seed

long seed

n_seconds

int n_seconds

n_events

int n_events

max_seconds

int max_seconds

max_events

int max_events

mouse_x

int mouse_x

mouse_y

int mouse_y

t_start

long t_start

keycodes

int[] keycodes

generator

java.util.Random generator

screenSize

java.awt.Dimension screenSize

robot

java.awt.Robot robot

editor

JModularEditor editor

lastActiveComponent

java.awt.Component lastActiveComponent

editorComponents

java.util.Vector editorComponents

BUTTON1

public static final int BUTTON1
See Also:
Constant Field Values

BUTTON2

public static final int BUTTON2
See Also:
Constant Field Values

BUTTON3

public static final int BUTTON3
See Also:
Constant Field Values

MOUSE_MOVE

public static final int MOUSE_MOVE
See Also:
Constant Field Values

MOUSE_DRAG

public static final int MOUSE_DRAG
See Also:
Constant Field Values

MOUSE_LEFT_CLICK

public static final int MOUSE_LEFT_CLICK
See Also:
Constant Field Values

MOUSE_MIDDLE_CLICK

public static final int MOUSE_MIDDLE_CLICK
See Also:
Constant Field Values

MOUSE_RIGHT_CLICK

public static final int MOUSE_RIGHT_CLICK
See Also:
Constant Field Values

KEY_ASCII

public static final int KEY_ASCII
See Also:
Constant Field Values

KEY_NUMBER

public static final int KEY_NUMBER
See Also:
Constant Field Values

KEY_CURSOR

public static final int KEY_CURSOR
See Also:
Constant Field Values

names

public static final java.lang.String[] names

pFigSwingCanvas

public static final double[] pFigSwingCanvas

pJImageButton

public static final double[] pJImageButton

pJStateButton

public static final double[] pJStateButton

pJTextField

public static final double[] pJTextField

pJButton

public static final double[] pJButton

pJComboBox

public static final double[] pJComboBox

pJComponent

public static final double[] pJComponent

keycodesNUMERIC

public static final int[] keycodesNUMERIC

keycodesASCII

public static final int[] keycodesASCII

keycodesCURSOR

public static final int[] keycodesCURSOR
Constructor Detail

Gremlins

public Gremlins()
Method Detail

setSeed

public void setSeed(long _seed)

setMaxSeconds

public void setMaxSeconds(int n)

setMaxEventCount

public void setMaxEventCount(int n)

getRunTimeSeconds

public int getRunTimeSeconds(long start_millis)

createKeyCodeTable

public void createKeyCodeTable()

runRandomTest

public void runRandomTest()

runCreateObjectsTest

public void runCreateObjectsTest()

clearObjects

public void clearObjects()

runModifyObjectsTest

public void runModifyObjectsTest()

runCreateRectangleTest

public void runCreateRectangleTest(int n_iterations)

runCreateRoundRectangleTest

public void runCreateRoundRectangleTest(int n_iterations)

runCreateCircleTest

public void runCreateCircleTest(int n_iterations)

runCreateEllipseTest

public void runCreateEllipseTest(int n_iterations)

runCreatePolylineTest

public void runCreatePolylineTest(int n_iterations)

runCreatePolygonTest

public void runCreatePolygonTest(int n_iterations)

runCreateSplineTest

public void runCreateSplineTest(int n_iterations)

runCreateClosedSplineTest

public void runCreateClosedSplineTest(int n_iterations)

runCreateBezierTest

public void runCreateBezierTest(int n_iterations)

runCreateClosedBezierTest

public void runCreateClosedBezierTest(int n_iterations)

runCreateArcTest

public void runCreateArcTest(int n_iterations)

runCreateTextTest

public void runCreateTextTest(int n_iterations)

runCreateImageObjectTest

public void runCreateImageObjectTest()

runCreateLibraryObjectTest

public void runCreateLibraryObjectTest()

findImageButton

public JImageButton findImageButton(java.lang.String label)

setRandomAttributes

public void setRandomAttributes()
set random values for all currently enabled attribute controls. This method steps through the set of all attribute controls enabled for the current command, and sets random values via generating corresponding events for the GUI controls instead of directly modifying an FigAttribs object.


resetAttributes

public void resetAttributes()

modifyJStateButton

public void modifyJStateButton(java.lang.Object tmp)
set a new random value for the given JStateButton. We use the probabilites 30% to increase, 70% to decrease, and 0% (zero) to select (and handle the SelectDialog). The reasons for the larger percentage of decrease operations is that this means the object's layer will become smaller over time, so that more recent objects are actually visible...


testJStateButtonSelectDialog

public void testJStateButtonSelectDialog(JStateButton button)
test the selection dialog of a JStateButton. This method tries to create and display the nested attribute selection dialog window of the given JStateButton, waits for the window to appear (with timeout of 4 seconds), selects a random component on the dialog, and waits for the dialog to close.

Special support is included to handle nested-nested dialogs like the JColorChooser in JColorButton-Select-Add new color-JColorChooser.


createOneRandomEvent

public void createOneRandomEvent()

selectActiveFrame

public java.awt.Frame selectActiveFrame()
query the editor for a list of all currently active Frames, and randomly select one of them.


findActiveWindow

public java.awt.Window findActiveWindow(java.awt.Window parent)
check whether one or more dialog windows are currently showing, and find the (topmost) active window.


selectRandomLeafComponent

public 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. We use hardcoded weights to select GUI components based on their type, to avoid generating only menu or button events. Buttons/MenuItems etc. have weight 1, TextFields have weight 10, TextAreas have weight 20, a FigCanvas has weight 200.

For performance reasons, we cache the leaf components per window.


enumerateLeafComponents

public 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. Unfortunately, JComponent itself is a container, which makes the decision between container and leaf components a little bit tricky. To avoid lots of instanceof checks, we include all found JComponents in the Vector.


createRandomComponentEvent

public void createRandomComponentEvent(java.awt.Component target)

createRandomWeightedEvent

public void createRandomWeightedEvent(java.awt.Component target,
                                      double[] weights)

createMouseMove

public void createMouseMove(java.awt.Component target)

createMouseDrag

public void createMouseDrag(java.awt.Component target)

createMouseClick

public void createMouseClick(java.awt.Component target,
                             int MASK)

createKeyTypeAscii

public void createKeyTypeAscii(java.awt.Component target)

createKeyTypeNumber

public void createKeyTypeNumber(java.awt.Component target)

createKeyTypeCursor

public void createKeyTypeCursor(java.awt.Component target)

getLocation

public java.awt.Rectangle getLocation(java.awt.Component target)

createMouseMove

public void createMouseMove()
simulate a "human mouse" event.


clip

public int clip(int value,
                int min,
                int max)

getRandom

public double getRandom(double min,
                        double max)

msg

public static void msg(java.lang.String s)

usage

public static void usage()

main

public static void main(java.lang.String[] argv)