FileDocCategorySizeDatePackage
BZip2Test.javaAPI DocApache Ant 1.703656Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

BZip2Test

public class BZip2Test extends org.apache.tools.ant.BuildFileTest

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Utilities used for file operations
Constructors Summary
public BZip2Test(String name)


       
        super(name);
    
Methods Summary
public voidsetUp()

        configureProject("src/etc/testcases/taskdefs/bzip2.xml");
        executeTarget("prepare");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtestDateCheck()

        executeTarget("testDateCheck");
        String log = getLog();
        assertTrue(
            "Expecting message ending with 'asf-logo.gif.bz2 is up to date.' but got '" + log + "'",
            log.endsWith("asf-logo.gif.bz2 is up to date."));
    
public voidtestRealTest()

        executeTarget("realTest");

        // doesn't work: Depending on the compression engine used,
        // compressed bytes may differ. False errors would be
        // reported.
        // assertTrue("File content mismatch",
        // FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"),
        // project.resolveFile("asf-logo-huge.tar.bz2")));

        // We have to compare the decompressed content instead:

        File originalFile =
            project.resolveFile("expected/asf-logo-huge.tar.bz2");
        File actualFile   = project.resolveFile("asf-logo-huge.tar.bz2");

        InputStream originalIn =
            new BufferedInputStream(new FileInputStream(originalFile));
        assertEquals((byte) 'B", originalIn.read());
        assertEquals((byte) 'Z", originalIn.read());

        InputStream actualIn =
            new BufferedInputStream(new FileInputStream(actualFile));
        assertEquals((byte) 'B", actualIn.read());
        assertEquals((byte) 'Z", actualIn.read());

        originalIn = new CBZip2InputStream(originalIn);
        actualIn   = new CBZip2InputStream(actualIn);

        while (true) {
            int expected = originalIn.read();
            int actual   = actualIn.read();
            if (expected >= 0) {
                if (expected != actual) {
                    fail("File content mismatch");
                }
            } else {
                if (actual >= 0) {
                    fail("File content mismatch");
                }
                break;
            }
        }

        originalIn.close();
        actualIn.close();
    
public voidtestResource()

        executeTarget("realTestWithResource");