JML

org.multijava.mjc
Class FunctionalTestSuite.TestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.multijava.util.testing.TestCase
              extended byorg.multijava.mjc.FunctionalTestSuite.TestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
TestMain_CodeGen, TestMain_Runtime, TestMain_TransCompile, TestMain_Typecheck
Enclosing class:
FunctionalTestSuite

public static class FunctionalTestSuite.TestCase
extends TestCase


Nested Class Summary
protected static class FunctionalTestSuite.TestCase.CodeGenResults
          Represents the results of disassembling, including a success flag and any error messages.
protected static class FunctionalTestSuite.TestCase.CompilationResults
          A string representation of the working directory, used in matching expected error messages.
protected static class FunctionalTestSuite.TestCase.Processor
           
protected static class FunctionalTestSuite.TestCase.RuntimeResults
          Represents the results of a runtime test, including a success flag, any exception thrown and the values written to standard error and standard out.
 
Field Summary
private static FilenameFilter CLASS_FILE_FILTER
          Used by cleanWorkingDir().
private static String CLASS_PATH_PROP
           
private static Object[] EMPTY_ARRAY
           
private  ArrayList splitCache
          Used by split() to split strings into words.
private static Class[] STRING_ARRAY
           
private static FileFilter SUBDIR_FILTER
          Used by cleanWorkingDir().
private  ClassLoader tempLoader
           
private static String WORKING_DIR_PROP
           
protected  File workingDir
          The temporary working directory.
 
Fields inherited from class org.multijava.util.testing.TestCase
NEWLINE
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
FunctionalTestSuite.TestCase(String name)
           
 
Method Summary
private  OutputStream[] captureStreams()
          Establishes new output streams to capture text written to standard out and standard error.
protected  void cleanWorkingDir()
          Deletes all *.class files in workingDir and its subdirectories.
protected  FunctionalTestSuite.TestCase.CompilationResults compile(String cmdLine)
          Invokes the compiler, passing it the given command line.
protected  FunctionalTestSuite.TestCase.CodeGenResults disasm(String className, boolean details)
          Disassembles the class with the given name.
protected  void expectFailure(FunctionalTestSuite.TestCase.CompilationResults results, String expectedError)
          Called with the result of compilation when failure (i.e., compilation error) is expected, this generates the appropriate assertion and message.
protected  void expectSuccess(FunctionalTestSuite.TestCase.CompilationResults results)
          Called with the result of compilation or runtime when success is expected, this generates the appropriate assertion and message.
protected  boolean invokeCompiler(String[] args)
           
private  void releaseStreams(OutputStream[] streams)
          Reverses the action for captureStreams().
protected  void remove(String fileNames)
          Deletes files of the given names from the current directory.
private  void resetWorkingDir(String[] old)
          Resets the working directory and class path based on the argument array returned by setWorkingDir().
protected  FunctionalTestSuite.TestCase.RuntimeResults run(String className)
          Tests the class with the given name.
protected  String saveAs(String fileName, String contents)
          Creates a file in the temporary directory with the given name and contents.
 void setUp()
          This is a hack to blast all the *.class files out of the temp directory.
private  String[] setWorkingDir()
          Establishes a new working directory and class path and returns an array containing the old values.
protected  String[] split(String text)
          Splits the given text into an array of words separated by whitespace.
 void tearDown()
          This is a hack to blast all the *.class files out of the temp directory.
 
Methods inherited from class org.multijava.util.testing.TestCase
assertDiff, assertEquals
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_FILE_FILTER

private static final FilenameFilter CLASS_FILE_FILTER
Used by cleanWorkingDir().


SUBDIR_FILTER

private static final FileFilter SUBDIR_FILTER
Used by cleanWorkingDir().


WORKING_DIR_PROP

private static final String WORKING_DIR_PROP

CLASS_PATH_PROP

private static final String CLASS_PATH_PROP

splitCache

private ArrayList splitCache
Used by split() to split strings into words. Instead of creating a new list we fill and flush this one.

See Also:
split( String )

workingDir

protected final File workingDir
The temporary working directory.


EMPTY_ARRAY

private static Object[] EMPTY_ARRAY

STRING_ARRAY

private static Class[] STRING_ARRAY

tempLoader

private ClassLoader tempLoader
Constructor Detail

FunctionalTestSuite.TestCase

public FunctionalTestSuite.TestCase(String name)
Method Detail

setUp

public void setUp()
This is a hack to blast all the *.class files out of the temp directory.

Overrides:
setUp in class junit.framework.TestCase

tearDown

public void tearDown()
This is a hack to blast all the *.class files out of the temp directory.

Overrides:
tearDown in class junit.framework.TestCase

cleanWorkingDir

protected final void cleanWorkingDir()
Deletes all *.class files in workingDir and its subdirectories.


saveAs

protected String saveAs(String fileName,
                        String contents)
Creates a file in the temporary directory with the given name and contents. To keep test methods from having to catch an IOException, these are converted to (unchecked) RuntimeExceptions.

Returns:
the file name so that operations may be cascaded

remove

protected void remove(String fileNames)
Deletes files of the given names from the current directory.

Parameters:
fileNames - a space delimited list of file names

compile

protected FunctionalTestSuite.TestCase.CompilationResults compile(String cmdLine)
Invokes the compiler, passing it the given command line. Standard output and error streams are captured so they can be included in the results.


invokeCompiler

protected boolean invokeCompiler(String[] args)

setWorkingDir

private String[] setWorkingDir()
Establishes a new working directory and class path and returns an array containing the old values. The array may be passed to resetWorkingDir( String[] ) to reset to the original values.

See Also:
resetWorkingDir(String[])

resetWorkingDir

private void resetWorkingDir(String[] old)
Resets the working directory and class path based on the argument array returned by setWorkingDir().

See Also:
setWorkingDir()

captureStreams

private OutputStream[] captureStreams()
Establishes new output streams to capture text written to standard out and standard error. Returns an array such the \result[0] is the new standard error stream, \result[1] is the new standard output stream, \result[2] is the old standard error stream, and \result[3] is the old standard output stream.

See Also:
releaseStreams(OutputStream[])

releaseStreams

private void releaseStreams(OutputStream[] streams)
Reverses the action for captureStreams().

Parameters:
streams - the array returned by captureStreams()
See Also:
captureStreams()

run

protected FunctionalTestSuite.TestCase.RuntimeResults run(String className)
Tests the class with the given name. Loads the class and executes a method in it with signature public static void main( String[] ), passing an empty array. Captures the values written to standard out by the method and returns these in the result. The result also contains a record of the exception thrown if the execution failed.


disasm

protected FunctionalTestSuite.TestCase.CodeGenResults disasm(String className,
                                                             boolean details)
Disassembles the class with the given name.


split

protected String[] split(String text)
Splits the given text into an array of words separated by whitespace. Requires that splitCache be empty when this is called. Ensures the splitCache is empty.

See Also:
splitCache

expectSuccess

protected void expectSuccess(FunctionalTestSuite.TestCase.CompilationResults results)
Called with the result of compilation or runtime when success is expected, this generates the appropriate assertion and message.


expectFailure

protected void expectFailure(FunctionalTestSuite.TestCase.CompilationResults results,
                             String expectedError)
Called with the result of compilation when failure (i.e., compilation error) is expected, this generates the appropriate assertion and message.


JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.