nz.ac.waikato.modeljunit
Class GraphListener

java.lang.Object
  extended by nz.ac.waikato.modeljunit.AbstractListener
      extended by nz.ac.waikato.modeljunit.GraphListener
All Implemented Interfaces:
ModelListener

public class GraphListener
extends AbstractListener

This ModelListener builds a graph of the observed parts of the model. Note that it is some other class (typically a Tester subclass) that determines which parts of the model are explored. As well as building the graph, this listener also keeps track of which paths have not yet been explored. Internally, it keeps track of two bitsets for each node/state. The 'done_' set records the outgoing transitions that have been taken/explored since the last call to clearDoneTodo(). The 'wasEnabled_' set records the actions that have been observed to have true guards at some point since the last call to clearDoneTodo() (this includes implicitly true guards, where the action has no explicit guard).


Field Summary
 
Fields inherited from class nz.ac.waikato.modeljunit.AbstractListener
model_
 
Constructor Summary
GraphListener()
           
 
Method Summary
 void clearDoneTodo()
          Resets all the done and todo information.
 void doneTransition(int action, Transition tr)
          Records a transition in the graph, if it is not already there.
 java.util.BitSet getDone(java.lang.Object state)
          Returns a bitset of all the DONE bits for this state.
 InspectableGraph getGraph()
          Returns the graph of the FSM model.
 java.lang.String getName()
          Get the short name that this listener is known by.
 java.util.BitSet getTodo(java.lang.Object state)
          Returns a bitset of all the TODO bits for this state.
 Vertex getVertex(java.lang.Object state)
          Maps a state to a vertex object of the FSM graph.
 java.util.Map<java.lang.Object,Vertex> getVertexMap()
          Returns a map that maps each state of the model to the corresponding vertex of the graph.
 boolean isComplete()
          Returns true after the graph seems to be completely explored.
 boolean isDone(java.lang.Object state, int action)
          True if the given action has been executed from the given state.
 boolean isTodo(java.lang.Object state, int action)
          True if the guard of the given action was once true in the given state, but that action has not yet been executed from that state.
 int numTodo()
          Returns the number of unexplored paths/branches in the graph.
 void printGraphDot(java.lang.String filename)
          Saves the FSM graph into the given file, in DOT format.
 void printProgress(int importance, java.lang.String msg)
           
 void setModel(Model model)
          Starts to build the FSM graph by exploring the fsm object.
static java.lang.String stateName(java.lang.Object state)
          Converts a state into a name.
 
Methods inherited from class nz.ac.waikato.modeljunit.AbstractListener
doneGuard, doneReset, failure, getModel, startAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphListener

public GraphListener()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: ModelListener
Get the short name that this listener is known by. This name is used to add a listener to a model or a Tester object and to lookup a listener. The name should be a short descriptive noun phrase, all in lowercase, should usually be less than 30 characters, and may contain spaces.


isComplete

public boolean isComplete()
Returns true after the graph seems to be completely explored. That is, when numTodo()==0 at some point in the past. However, this is only a heuristic, and it is quite possible that a few more non-deterministic or rarely-enabled transitions will be found by further test generation.

Returns:
true if numTodo() was or is 0.

numTodo

public int numTodo()
Returns the number of unexplored paths/branches in the graph. TODO: make this efficient by maintaining the sum of the number of done_ and wasEnabled_ bits and returning the difference.


isTodo

public boolean isTodo(java.lang.Object state,
                      int action)
True if the guard of the given action was once true in the given state, but that action has not yet been executed from that state.

Parameters:
state - A non-null state of the model.
action - The number of one of the actions of the model.
Returns:
true if no transition (state, action, _) has been taken yet.

getTodo

public java.util.BitSet getTodo(java.lang.Object state)
Returns a bitset of all the TODO bits for this state. Callers can mutate the returned BitSet.

Parameters:
state -
Returns:
A copy of a non-null BitSet.

isDone

public boolean isDone(java.lang.Object state,
                      int action)
True if the given action has been executed from the given state.

Parameters:
state - A non-null state of the model.
action - The number of one of the actions of the model.
Returns:
true if any transition (state, action, _) has been taken.

getDone

public java.util.BitSet getDone(java.lang.Object state)
Returns a bitset of all the DONE bits for this state. Callers can mutate the returned BitSet.

Parameters:
state -
Returns:
A non-null BitSet.

clearDoneTodo

public void clearDoneTodo()
Resets all the done and todo information. Immediately after calling this, isDone and isTodo will return false for every state and action.


getGraph

public InspectableGraph getGraph()
Returns the graph of the FSM model. Note that the graph may be incomplete (call buildGraph to explore the graph thoroughly).


getVertexMap

public java.util.Map<java.lang.Object,Vertex> getVertexMap()
Returns a map that maps each state of the model to the corresponding vertex of the graph.

Returns:
a map

getVertex

public Vertex getVertex(java.lang.Object state)
Maps a state to a vertex object of the FSM graph.


printProgress

public void printProgress(int importance,
                          java.lang.String msg)

setModel

public void setModel(Model model)
Starts to build the FSM graph by exploring the fsm object. This does a reset if the model is not already in the initial state.

Specified by:
setModel in interface ModelListener
Overrides:
setModel in class AbstractListener

printGraphDot

public void printGraphDot(java.lang.String filename)
                   throws java.io.FileNotFoundException
Saves the FSM graph into the given file, in DOT format. The DOT format can be converted into many other graphical formats, including xfig, postscript, jpeg etc. by using the 'dot' or 'neato' tools, which are freely available from http://www.graphviz.org. This method should only be called after buildGraph has built the graph.

Parameters:
filename - The filename should end with ".dot".
Throws:
java.io.FileNotFoundException

stateName

public static java.lang.String stateName(java.lang.Object state)
Converts a state into a name. It calls toString on the state, and then adds quotes around the string if it is not a Java identifier.

Parameters:
state -
Returns:
A name that is suitable for printing in a .dot file.

doneTransition

public void doneTransition(int action,
                           Transition tr)
Records a transition in the graph, if it is not already there.

Specified by:
doneTransition in interface ModelListener
Overrides:
doneTransition in class AbstractListener
Parameters:
action - The number of the action just taken
tr - A possibly new transition (and state).


Copyright © 2009 ModelJUnit Project. All Rights Reserved.