Methods Summary |
---|
protected void | cleanupBed()Cleans up the testbed by calling a target in the
src/etc/testcases/types/selectors.xml file.
if (tbed != null) {
tbed.tearDown();
tbed = null;
}
|
protected void | cleanupMirror()Cleans up the mirror testbed by calling a target in the
src/etc/testcases/types/selectors.xml file.
if (tbed != null) {
tbed.deleteMirror();
tbed = null;
}
|
public java.lang.String | diff(java.lang.String expected, java.lang.String result)Checks which files are selected and shouldn't be or which
are not selected but should.
int length1 = expected.length();
int length2 = result.length();
int min = (length1 > length2) ? length2 : length1;
StringBuffer sb = new StringBuffer();
for (int i=0; i<min; i++) {
sb.append(
(expected.charAt(i) == result.charAt(i))
? "-"
: "X"
);
}
return sb.toString();
|
public abstract BaseSelector | getInstance()Override this in child classes to return a specific Selector
|
public org.apache.tools.ant.Project | getProject()
return project;
|
public BaseSelector | getSelector()Return a preconfigured selector (with a set reference to
project instance).
BaseSelector selector = getInstance();
selector.setProject( getProject() );
return selector;
|
protected void | makeBed()Creates a testbed. We avoid the dreaded "test" word so that we
don't falsely identify this as a test to be run. The actual
setting up of the testbed is done in the
src/etc/testcases/types/selectors.xml build file.
Note that the right way to call this is within a try block,
with a finally clause that calls cleanupBed(). You place tests of
the isSelected() method within the try block.
tbed = new TaskdefForMakingBed("setupfiles");
tbed.setUp();
tbed.makeTestbed();
|
protected void | makeMirror()Creates a mirror of the testbed for use in dependency checks.
Note that the right way to call this is within a try block,
with a finally clause that calls cleanupMirror(). You place tests of
the isSelected() method within the try block.
tbed = new TaskdefForMakingBed("mirrorfiles");
tbed.setUp();
tbed.makeMirror();
|
public java.lang.String | mirrorSelectionString(FileSelector selector)This is a helper method that takes a selector and calls its
isSelected() method on each file in the mirror testbed. This
variation is used for dependency checks and to get around the
limitations in the touch task when running JDK 1.1. It returns
a string of "T"s amd "F"s.
return selectionString(mirrordir,mirrorfiles,selector);
|
public void | performTests(FileSelector selector, java.lang.String expected)Does the selection test for a given selector and prints the
filenames of the differing files (selected but shouldn't,
not selected but should).
String result = selectionString(selector);
String diff = diff(expected, result);
String resolved = resolve(diff);
assertEquals("Differing files: " + resolved, result, expected);
|
public java.lang.String | resolve(java.lang.String filelist)Resolves a diff-String (@see diff()) against the (inherited) filenames-
and files arrays.
StringBuffer sb = new StringBuffer();
int min = (filenames.length > filelist.length())
? filelist.length()
: filenames.length;
for (int i=0; i<min; i++) {
if ('X"==filelist.charAt(i)) {
sb.append(filenames[i]);
sb.append(";");
}
}
return sb.toString();
|
public java.lang.String | selectionString(FileSelector selector)This is a helper method that takes a selector and calls its
isSelected() method on each file in the testbed. It returns
a string of "T"s amd "F"s
return selectionString(beddir,files,selector);
|
public java.lang.String | selectionString(java.io.File basedir, java.io.File[] files, FileSelector selector)Worker method for the two convenience methods above. Applies a
selector on a set of files passed in and returns a string of
"T"s amd "F"s from applying the selector to each file.
StringBuffer buf = new StringBuffer();
for (int x = 0; x < files.length; x++) {
if (selector.isSelected(basedir,filenames[x],files[x])) {
buf.append('T");
}
else {
buf.append('F");
}
}
return buf.toString();
|
public void | setUp()
project = new Project();
project.init();
project.setBaseDir(basedir);
for (int x = 0; x < files.length; x++) {
files[x] = new File(beddir,filenames[x]);
mirrorfiles[x] = new File(mirrordir,filenames[x]);
}
|
public void | testRespondsToError()This is a test that all Selectors derived from BaseSelector can
use. It calls the setError() method and checks to ensure that a
BuildException is thrown as a result.
BaseSelector s = getInstance();
if (s == null) {
return;
}
s.setError("test error");
try {
s.isSelected(beddir,filenames[0],files[0]);
fail("Cannot cause BuildException when setError() is called");
} catch (BuildException be) {
assertEquals("test error",
be.getMessage());
}
|