sir.mts.generators
Class XMLGenerator

java.lang.Object
  extended by sir.mts.generators.XMLGenerator
All Implemented Interfaces:
TestScriptGenerator

public final class XMLGenerator
extends java.lang.Object
implements TestScriptGenerator

Generates an XML encoding of the contents of a STImpL file.

Version:
05/03/2006
Author:
Benjamin R. Liblit

Constructor Summary
XMLGenerator(Configuration config)
           
 
Method Summary
 int addComment(java.lang.String text)
          Adds a comment to the generated script.
 int addExternalFinishScript(java.lang.String filename, java.util.List params)
          Adds a script invocation to be executed after invocation of the test case.
 int addExternalSetupScript(java.lang.String filename, java.util.List params)
          Adds a script invocation to be executed prior to invocation of the test case.
 int addInlineFinishScript(java.lang.String scriptName, java.util.Map params)
          Inlines a script to executed after invocation of the test case.
 int addInlineSetupScript(java.lang.String scriptName, java.util.Map params)
          Inlines a script to executed prior to invocation of the test case.
 int addInputFile(java.lang.String filename)
          Adds a file redirection to the standard input stream of the current test case.
 int addMoveFile(java.lang.String source, java.lang.String destination)
          Adds a command to move an output file to another location after execution of the test case.
 int addOutputFile(java.lang.String filename)
          Adds a redirection to file of the standard output and error streams of the current test case.
 int addParameter(java.lang.String text)
          Adds a command line parameter to the current test case.
 int addTestDriver(java.lang.String command)
          Adds a test driver to be used to invoke the test case.
 void addVariableAssign(java.lang.String name, java.lang.String value, boolean unsetFirst)
          Inserts a statement in the script to assign a value to a named variable.
 void addVerbatim(java.lang.String text)
          Copies text verbatim to the generated script.
 int endScript()
          Indicates the end of the script.
 int endTest()
          Indicates the end of the current test implementation specification.
 java.lang.String getEscapedQuote()
          Gets the escape sequence to generate a single quote character (").
 void newTest(int testID)
          Indicates the start of a new test implementation specification.
 int setRunInBackground(boolean flagged)
          Instructs the script generator to cause the test case to be executed as a background job.
 void startScript()
          Indicates the start of a new script.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLGenerator

public XMLGenerator(Configuration config)
             throws javax.xml.parsers.ParserConfigurationException
Throws:
javax.xml.parsers.ParserConfigurationException
Method Detail

startScript

public void startScript()
                 throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the start of a new script.

This is most useful for inserting content at the start of the script.

Specified by:
startScript in interface TestScriptGenerator
Throws:
ScriptGenException - If the script generator fails to generate content associated with this event.

endScript

public int endScript()
              throws ScriptGenException
Description copied from interface: TestScriptGenerator
Indicates the end of the script.

This is most useful for inserting content at the end of the script.

Specified by:
endScript in interface TestScriptGenerator
Returns:
The number of test cases in the generated script.
Throws:
ScriptGenException - If the script generator fails to generate content associated with this event.

newTest

public void newTest(int testID)
Description copied from interface: TestScriptGenerator
Indicates the start of a new test implementation specification.

Specified by:
newTest in interface TestScriptGenerator
Parameters:
testID - The test number of this test in the script.

endTest

public int endTest()
Description copied from interface: TestScriptGenerator
Indicates the end of the current test implementation specification.

Specified by:
endTest in interface TestScriptGenerator
Returns:
The number of tests added to the script so far.

addParameter

public int addParameter(java.lang.String text)
Description copied from interface: TestScriptGenerator
Adds a command line parameter to the current test case.

Specified by:
addParameter in interface TestScriptGenerator
Parameters:
text - Command line parameter string to be added to the invocation command for the current test case.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addMoveFile

public int addMoveFile(java.lang.String source,
                       java.lang.String destination)
Description copied from interface: TestScriptGenerator
Adds a command to move an output file to another location after execution of the test case.

Specified by:
addMoveFile in interface TestScriptGenerator
Parameters:
source - Name of the output file to be moved.
destination - Path and file name to which the output file should be moved.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addComment

public int addComment(java.lang.String text)
Description copied from interface: TestScriptGenerator
Adds a comment to the generated script.

Comment text is supplied verbatim, including unmodified whitespace.

Specified by:
addComment in interface TestScriptGenerator
Parameters:
text - Comment text to be added.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addInputFile

public int addInputFile(java.lang.String filename)
Description copied from interface: TestScriptGenerator
Adds a file redirection to the standard input stream of the current test case.

Specified by:
addInputFile in interface TestScriptGenerator
Parameters:
filename - Name of the file that should be redirected to the test case on the standard input stream.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addOutputFile

public int addOutputFile(java.lang.String filename)
Description copied from interface: TestScriptGenerator
Adds a redirection to file of the standard output and error streams of the current test case.

Specified by:
addOutputFile in interface TestScriptGenerator
Parameters:
filename - Name of the file to which the standard output and error streams of the test case should be redirected.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addExternalSetupScript

public int addExternalSetupScript(java.lang.String filename,
                                  java.util.List params)
Description copied from interface: TestScriptGenerator
Adds a script invocation to be executed prior to invocation of the test case.

By historical convention, script invocations should be added in the order received (that is, the order in which they are requested by calls to this method), and should be inserted before any inlined startup scripts.

Specified by:
addExternalSetupScript in interface TestScriptGenerator
Parameters:
filename - Name of the script to be invoked prior to the test case.
params - List of parameters to be passed to the invoked script.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addExternalFinishScript

public int addExternalFinishScript(java.lang.String filename,
                                   java.util.List params)
Description copied from interface: TestScriptGenerator
Adds a script invocation to be executed after invocation of the test case.

By historical convention, script invocations should be added in the order received (that is, the order in which they are requested by calls to this method), and should be inserted after any inlined finishing scripts.

Specified by:
addExternalFinishScript in interface TestScriptGenerator
Parameters:
filename - Name of the script to be invoked after the test case.
params - List of parameters to be passed to the invoked script.
Returns:
The number of STImpL test specification commands received so far for the current test case.

setRunInBackground

public int setRunInBackground(boolean flagged)
Description copied from interface: TestScriptGenerator
Instructs the script generator to cause the test case to be executed as a background job.

Specified by:
setRunInBackground in interface TestScriptGenerator
Parameters:
flagged - true if the test case should be run in the background, false if it should be run as a normal process.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addVariableAssign

public void addVariableAssign(java.lang.String name,
                              java.lang.String value,
                              boolean unsetFirst)
Description copied from interface: TestScriptGenerator
Inserts a statement in the script to assign a value to a named variable.

Variables are considered to exist in the global scope. Thus all test cases subsequent to a variable assignment should have access to the variable value.

Specified by:
addVariableAssign in interface TestScriptGenerator
Parameters:
name - Name of the variable to be assigned.
value - Value to be assigned to the variable.
unsetFirst - boolean Flag indicating whether a statement to explicitly unset the specified variable should be inserted before the assignment statement, if such a capability exists in the target language.

addInlineSetupScript

public int addInlineSetupScript(java.lang.String scriptName,
                                java.util.Map params)
Description copied from interface: TestScriptGenerator
Inlines a script to executed prior to invocation of the test case.

By historical convention, scripts should be inlined in the order received (that is, the order in which they are requested by calls to this method), and they should always appear after the invocations of non-inlined startup scripts.

The parameters argument can be used to request that the script generator insert appropriate variable assignment statements at the head of the inlined script to simulate parameters. Note however that these variables are not cleared at the end of the inlined script, and thus they may remain in scope and available to subsequent test cases. This may be useful for maintaining state in the script.

Specified by:
addInlineSetupScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be inlined into the generated script prior to execution of the test case.
params - Map A Map<String,String> that contains pairings of variable names to values that should be assigned to those variables at the beginning of the script, simulating parameters to the script.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addInlineFinishScript

public int addInlineFinishScript(java.lang.String scriptName,
                                 java.util.Map params)
Description copied from interface: TestScriptGenerator
Inlines a script to executed after invocation of the test case.

By historical convention, scripts should be inlined in the order received (that is, the order in which they are requested by calls to this method), and they should always appear before the invocations of non-inlined finishing scripts.

The parameters argument can be used to request that the script generator insert appropriate variable assignment statements at the head of the inlined script to simulate parameters. Note however that these variables are not cleared at the end of the inlined script, and thus they may remain in scope and available to subsequent test cases. This may be useful for maintaining state in the script.

Specified by:
addInlineFinishScript in interface TestScriptGenerator
Parameters:
scriptName - Name of the script to be inlined into the generated script after execution of the test case.
params - Map A Map<String,String> that contains pairings of variable names to values that should be assigned to those variables at the beginning of the script, simulating parameters to the script.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addTestDriver

public int addTestDriver(java.lang.String command)
Description copied from interface: TestScriptGenerator
Adds a test driver to be used to invoke the test case.

Specified by:
addTestDriver in interface TestScriptGenerator
Parameters:
command - Name of the test driver program to be used to invoke the program under test.
Returns:
The number of STImpL test specification commands received so far for the current test case.

addVerbatim

public void addVerbatim(java.lang.String text)
Description copied from interface: TestScriptGenerator
Copies text verbatim to the generated script.

Note: There is currently no STImpL syntax associated with this event, and it is not called by the parser. It is reserved for future use.

Specified by:
addVerbatim in interface TestScriptGenerator
Parameters:
text - Text to be copied unchanged to the generated script.

getEscapedQuote

public java.lang.String getEscapedQuote()
Description copied from interface: TestScriptGenerator
Gets the escape sequence to generate a single quote character (").

Specified by:
getEscapedQuote in interface TestScriptGenerator
Returns:
The escape sequence required to safely produce a quote character in the target script language.