|
JML | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jmlspecs.jmlunit.TestClassGenerator
A class for generating JML/JUnit test driver classes.
An object of this class can generate a JML/JUnit test oracle class
from an object of JCompilationUnit
.
Class Specifications |
invariant this.typeDecl != null ==> this.testClassName.equals(this.typeDecl.ident()+"_JML_Test"); invariant this.fixtureTypes != null&&( \forall java.lang.Object o; this.fixtureTypes.contains(o); o != null&&o instanceof org.multijava.mjc.CType); private invariant this.requestedVisibility == 1||this.requestedVisibility == 4||this.requestedVisibility == org.jmlspecs.jmlunit.TestClassGenerator.ACC_ALL; |
Specifications inherited from class Object |
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT; public represents _getClass <- \typeof(this); |
Specifications inherited from interface Constants |
invariant "junit.framework.".length() > 0 ==> "junit.framework.".charAt("junit.framework.".length()) == 46; invariant "org.jmlspecs.jmlrac.runtime.".length() > 0 ==> "org.jmlspecs.jmlrac.runtime.".charAt("org.jmlspecs.jmlrac.runtime.".length()) == 46; invariant "org.jmlspecs.jmlunit.".length() > 0 ==> "org.jmlspecs.jmlunit.".charAt("org.jmlspecs.jmlunit.".length()) == 46; invariant "org.jmlspecs.jmlunit.strategies.".length() > 0 ==> "org.jmlspecs.jmlunit.strategies.".charAt("org.jmlspecs.jmlunit.".length()) == 46; |
Specifications inherited from interface Constants |
public invariant true; |
Nested Class Summary | |
protected class |
TestClassGenerator.MethodInfo
Common information needed from JMethodDeclarationType and CMethod in this class. |
protected class |
TestClassGenerator.MethodsIterator
A composite control abstraction useful in this class. |
private static class |
TestClassGenerator.NameGenerator
A class for generating unique names for test methods. |
private static class |
TestClassGenerator.Parameter
A simple data structure class for storing information about a formal parameter. |
Model Field Summary |
Model fields inherited from class java.lang.Object |
_getClass, objectState, theString |
Ghost Field Summary |
Ghost fields inherited from class java.lang.Object |
objectTimesFinalized, owner |
Field Summary | |
private static long |
ACC_ALL
|
protected Set |
fixtureTypes
|
protected String |
generatorClassName
|
protected String |
generatorPackageName
|
protected boolean |
includeInherited
Indicates whether tests are generated for all the inherited methods too. |
private TestClassGenerator.NameGenerator |
nameGen
A name generator to generate unique names for test methods. |
protected String |
packageString
The name of the package the generated class is in. |
private boolean |
requestedDeprecation
Tell whether tests should be generated for deprecated methods. |
private long |
requestedVisibility
|
protected String |
testClassName
|
protected String |
testedPackageString
The name of the package the type being tested is in. |
protected JTypeDeclarationType |
typeDecl
The type declaration currently being translated. |
protected boolean |
useGenerator
|
private FancyTabbedPrintWriter |
writer
The writer where the generated test oracle classes are to be printed to. |
Fields inherited from interface org.jmlspecs.jmlunit.Constants |
DOT_JAVA, PKG_JMLRAC, PKG_JMLUNIT, PKG_JUNIT, PKG_STRATEGIES, TEST_CLASS_FILE_NAME_POSTFIX, TEST_CLASS_NAME_POSTFIX, TEST_DATA_FILE_NAME_POSTFIX, TEST_DATA_NAME_POSTFIX, TEST_METHOD_NAME_PREFIX |
Constructor Summary | |
TestClassGenerator(non_null JntOptions options)
Constructs a new test oracle generator. |
Model Method Summary |
Model methods inherited from class java.lang.Object |
hashValue |
Method Summary | |
protected String |
capitalize(non_null String s)
Return a capitalized version of the argument |
protected void |
composeFailMessage(TestClassGenerator.MethodInfo mdecl,
String mname,
TestClassGenerator.Parameter[] params,
TestClassGenerator.Parameter receiver,
boolean isInstance,
boolean isConstructor)
Generates code that composes a message about the method and parameters. |
private TestClassGenerator.Parameter[] |
filterParameters(JFormalParameter[] p)
Returns an array of original formal parameters, i.e., those not generated by the type checker. |
protected static String |
fixtureVariableName(CType type)
Returns a fixture variable name for the type named, type . |
private void |
generateNestedTestClassFor(TestClassGenerator.MethodInfo mdecl,
String mname,
String className,
TestClassGenerator.Parameter[] params,
TestClassGenerator.Parameter receiver,
boolean isInstance,
boolean isConstructor)
Generates and prints a test class for the given method declaration, mdecl . |
private TestClassGenerator.Parameter[] |
generateParameters(CSpecializedType[] p)
Returns an array of formal parameters for given parameter types, p . |
protected void |
generateTestClass(non_null JCompilationUnit cunit,
non_null JTypeDeclarationType cdecl)
Generates a test oracle class for the given class declaration, cdecl . |
protected String |
getPackageString()
return the package string, if present. |
protected String |
getTestedPackageString()
return the package string, if present. |
private boolean |
hasRequestedVisibility(long modifiers)
Returns true if the given modifiers include an access modifier that has the same or widely visible than requested by the user. |
protected void |
indent()
Indents one TAB_SIZE. |
protected void |
initializeFixture()
Initialize the fixture to contain all of the types used as paramaeters in all the methods. |
private static boolean |
isAbstract(long modifiers)
Returns true if the argument has a public modifier. |
private static boolean |
isPrivate(long modifiers)
Returns true if the argument has a private modifier. |
private static boolean |
isProtected(long modifiers)
Returns true if the argument has a protected modifier. |
private static boolean |
isPublic(long modifiers)
Returns true if the argument has a public modifier. |
protected static boolean |
isStatic(long modifiers)
Returns true if the argument has a static modifier. |
private boolean |
isTestable(CMethod mdecl)
Return true if the given inherited method can be tested. |
private boolean |
isTestable(JMethodDeclarationType mdecl)
Return true if the given method declaration can be tested. |
private boolean |
isTestable(JTypeDeclarationType cdecl,
String fileNameId)
Returns true if the given type declaration is
testable using the JML/JUnit approach. |
private String |
methodKind(TestClassGenerator.MethodInfo mdecl)
Return the kind of method this is: either "method" or "constructor". |
protected TestClassGenerator.MethodsIterator |
methodsIter()
Return a new methods iterator for the methods that should be checked. |
protected void |
newLine()
Prints a line separator. |
void |
perform(non_null Writer writer,
non_null JCompilationUnit cunit,
non_null JntOptions options)
Generates a JML/JUnit test oracle class for the given compilation unit. |
protected void |
print(Object s)
Prints the given object. |
protected void |
print(String s)
Prints the given string. |
private void |
printAddCallFor(String name)
Prints a call to the appropriateaddTestSuiteFor$X method. |
private void |
printAddMethodFor(TestClassGenerator.MethodInfo mdecl,
String mname,
String className,
TestClassGenerator.Parameter[] params,
TestClassGenerator.Parameter receiver,
boolean isInstance,
boolean isConstructor)
Prints a method to add the test cases for the given method to a test suite. |
private void |
printAddTestSuiteForEachMethod()
Prints the addTestSuiteForEachMethod method, and the methods directly called by it and supporting nested classes. |
private void |
printAdvance(String iterVarStart)
Print the advance of the given named iterator and closing bracket |
private void |
printBodyLoopControl(String mname,
TestClassGenerator.Parameter param,
int paramNum,
int loopsThisSurrounds)
Print the loop control statements for the body of adding tests for a method. |
private void |
printCharToString()
|
private void |
printCheckHasData()
Emit the a private method to check that the result of a call to get_receivers returned a non-null value (and note a test failure otherwise). |
protected void |
printClassHeader()
Prints the class header of test oracle class. |
protected void |
printClassJavadoc()
Prints a javadoc comment for the current class. |
protected void |
printConstructor()
Prints a boilerplate constructor. |
protected void |
printFileHeader()
Prints a file header message. |
protected void |
printImportStatements(JCompilationUnit cunit)
Prints import statements. |
private void |
printInnerVarDecl(String mname,
TestClassGenerator.Parameter param,
int paramNum)
Print the declaration of a final variable for this parameter. |
protected void |
println(Object s)
Prints the given object with a trailing line separator. |
protected void |
printlnIn(Object s)
Prints the given object with one TAB_SIZE indentation and a trailing line separator. |
protected void |
printMain()
Prints a boilerplate main method. |
private void |
printOneTest()
Prints the nested OneTest class. |
private void |
printPackageStatement()
Prints a package statement. |
private void |
printPrivateHelperMethods()
Emit methods private to the generated class. |
protected void |
printSuite()
Prints the suite() method. |
private void |
printTestClassArgumentDecl(TestClassGenerator.Parameter param)
Print declaration of an argument. |
private void |
printTestClassConstrAssign(TestClassGenerator.Parameter param)
Print the assignment of a parameter to a field. |
private void |
printTestClassDoCall(String mname,
TestClassGenerator.Parameter[] params,
TestClassGenerator.Parameter receiver,
boolean isInstance,
boolean isConstructor)
Print the doCall method. |
private void |
printTestClassFailMessage(TestClassGenerator.MethodInfo mdecl,
String mname,
TestClassGenerator.Parameter[] params,
TestClassGenerator.Parameter receiver,
boolean isInstance,
boolean isConstructor)
Print the doCall method. |
private void |
printTestClassFieldDecl(TestClassGenerator.Parameter param,
int paramNum)
Print the declaration of a field for this parameter. |
private void |
printTestIsRACCompiled(JTypeDeclarationType cdecl)
Prints test$IfRACCompiled method. |
private String |
testMethodClassName(String ident)
Returns a unique test class name for the given method name. |
private String |
testMethodName(String ident)
Returns a unique test method name for the given method name. |
protected void |
undent()
Und-ndents one TAB_SIZE. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private FancyTabbedPrintWriter writer
protected JTypeDeclarationType typeDecl
protected String testClassName
protected String packageString
protected String testedPackageString
protected Set fixtureTypes
private TestClassGenerator.NameGenerator nameGen
private final long requestedVisibility
#hasRequestedVisibility(int)
,
isTestable(JMethodDeclarationType)
,
isTestable(CMethod)
private final boolean requestedDeprecation
isTestable(JMethodDeclarationType)
,
isTestable(CMethod)
private static final long ACC_ALL
protected final boolean includeInherited
protected boolean useGenerator
protected String generatorPackageName
protected String generatorClassName
Constructor Detail |
public TestClassGenerator(non_null JntOptions options)
Method Detail |
public void perform(non_null Writer writer, non_null JCompilationUnit cunit, non_null JntOptions options)
protected void printFileHeader()
protected void printImportStatements(JCompilationUnit cunit)
protected void printClassJavadoc()
protected void printClassHeader()
protected void generateTestClass(non_null JCompilationUnit cunit, non_null JTypeDeclarationType cdecl)
cdecl
.
protected void initializeFixture()
private String methodKind(TestClassGenerator.MethodInfo mdecl)
protected void printConstructor()
protected void printMain()
protected void printSuite()
private void printOneTest()
private void printAddTestSuiteForEachMethod()
private void printAddCallFor(String name)
private void printAddMethodFor(TestClassGenerator.MethodInfo mdecl, String mname, String className, TestClassGenerator.Parameter[] params, TestClassGenerator.Parameter receiver, boolean isInstance, boolean isConstructor)
private void printBodyLoopControl(String mname, TestClassGenerator.Parameter param, int paramNum, int loopsThisSurrounds)
private void printInnerVarDecl(String mname, TestClassGenerator.Parameter param, int paramNum)
private void printAdvance(String iterVarStart)
private void generateNestedTestClassFor(TestClassGenerator.MethodInfo mdecl, String mname, String className, TestClassGenerator.Parameter[] params, TestClassGenerator.Parameter receiver, boolean isInstance, boolean isConstructor)
mdecl
.
private void printTestClassFieldDecl(TestClassGenerator.Parameter param, int paramNum)
private void printTestClassArgumentDecl(TestClassGenerator.Parameter param)
private void printTestClassConstrAssign(TestClassGenerator.Parameter param)
private void printTestClassDoCall(String mname, TestClassGenerator.Parameter[] params, TestClassGenerator.Parameter receiver, boolean isInstance, boolean isConstructor)
private void printTestClassFailMessage(TestClassGenerator.MethodInfo mdecl, String mname, TestClassGenerator.Parameter[] params, TestClassGenerator.Parameter receiver, boolean isInstance, boolean isConstructor)
protected String getPackageString()
protected String getTestedPackageString()
private void printTestIsRACCompiled(JTypeDeclarationType cdecl)
private void printPackageStatement()
protected static final String fixtureVariableName(CType type)
type
. The convention is to prefix the string
"v" to the type name.
private boolean isTestable(JTypeDeclarationType cdecl, String fileNameId)
true
if the given type declaration is
testable using the JML/JUnit approach. All non-private classes
and interfaces are are testable.
private boolean isTestable(JMethodDeclarationType mdecl)
private boolean isTestable(CMethod mdecl)
private boolean hasRequestedVisibility(long modifiers)
private void printPrivateHelperMethods()
private void printCheckHasData()
private void printCharToString()
protected void composeFailMessage(TestClassGenerator.MethodInfo mdecl, String mname, TestClassGenerator.Parameter[] params, TestClassGenerator.Parameter receiver, boolean isInstance, boolean isConstructor)
private TestClassGenerator.Parameter[] filterParameters(JFormalParameter[] p)
private TestClassGenerator.Parameter[] generateParameters(CSpecializedType[] p)
p
.
protected String capitalize(non_null String s)
private String testMethodName(String ident)
private String testMethodClassName(String ident)
protected static final boolean isStatic(long modifiers)
private static final boolean isPrivate(long modifiers)
private static final boolean isPublic(long modifiers)
private static final boolean isProtected(long modifiers)
private static final boolean isAbstract(long modifiers)
protected TestClassGenerator.MethodsIterator methodsIter()
protected final void indent()
protected final void undent()
protected void print(Object s)
protected void print(String s)
protected void println(Object s)
protected void printlnIn(Object s)
protected void newLine()
|
JML | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |