/* * AppleCommander - An Apple ][ image utility. * Copyright (C) 2002 by Robert Greene * robgreene at users.sourceforge.net * * This program is free software; you can redistribute it and/or modify it * under the terms of 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 program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.webcodepro.applecommander.storage; import java.io.IOException; import java.util.List; import junit.framework.TestCase; import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage; import com.webcodepro.applecommander.storage.os.dos33.DosFormatDisk; import com.webcodepro.applecommander.storage.os.dos33.OzDosFormatDisk; import com.webcodepro.applecommander.storage.os.dos33.UniDosFormatDisk; import com.webcodepro.applecommander.storage.os.pascal.PascalFormatDisk; import com.webcodepro.applecommander.storage.os.prodos.ProdosFormatDisk; import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout; import com.webcodepro.applecommander.storage.physical.DosOrder; import com.webcodepro.applecommander.storage.physical.ImageOrder; import com.webcodepro.applecommander.storage.physical.NibbleOrder; import com.webcodepro.applecommander.storage.physical.ProdosOrder; /** * Test Disk and FormattedDisk for write. *
* Date created: Oct 3, 2002 11:35:26 PM
* @author Rob Greene
*/
public class DiskWriterTest extends TestCase {
/**
* Determine if the created disk images should be saved for later
* perusal.
*/
private boolean saveImage = false;
/**
* Create the DiskWriterTest.
*/
public DiskWriterTest(String name) {
super(name);
}
/**
* Run the test in text mode.
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(DiskWriterTest.class);
}
/**
* Test writing and reading random files to a DOS 3.3 140K disk.
*/
public void testWriteToDos33() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.dsk", imageOrder); //$NON-NLS-1$
writeFiles(disks, "B", "T", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a DOS 3.3 140K nibbilized disk.
*/
public void testWriteToDos33Nibble() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_NIBBLE_DISK);
ImageOrder imageOrder = new NibbleOrder(imageLayout);
FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.nib", imageOrder); //$NON-NLS-1$
writeFiles(disks, "B", "T", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a ProDOS 140K disk.
*/
public void testWriteToPascal140kDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = PascalFormatDisk.create(
"write-test-pascal-140k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "code", "text", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a ProDOS 140K disk.
*/
public void testWriteToPascal800kDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = PascalFormatDisk.create(
"write-test-pascal-800k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
//writeFiles(disks, "code", "text", false); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a ProDOS 140K disk.
*/
public void testWriteToProdos140kDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-140k.dsk", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a ProDOS 800K disk.
*/
public void testWriteToProdos800kDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-800k.po", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test writing and reading random files to a ProDOS 5MB disk.
*/
public void testWriteToProdos5mbDisk() throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_5MB_HARDDISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"write-test-prodos-5mb.hdv", "TEST", imageOrder); //$NON-NLS-1$ //$NON-NLS-2$
writeFiles(disks, "BIN", "TXT", true); //$NON-NLS-1$ //$NON-NLS-2$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a DOS 3.3 140K disk.
*/
public void testCreateAndDeleteDos33() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = DosFormatDisk.create(
"createanddelete-test-dos33.dsk", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on an OzDOS 800K disk.
*/
public void testCreateAndDeleteOzDos() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = OzDosFormatDisk.create(
"createanddelete-test-ozdos.po", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a UniDOS 800K disk.
*/
public void testCreateAndDeleteUniDos() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = UniDosFormatDisk.create(
"createanddelete-test-unidos.dsk", imageOrder); //$NON-NLS-1$
createAndDeleteFiles(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a Pascal 140K disk.
*/
public void testCreateAndDeletePascal140kDisk() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = PascalFormatDisk.create(
"createanddelete-test-pascal-140k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createAndDeleteFiles(disks, "CODE"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a Pascal 800K disk.
*/
public void testCreateAndDeletePascal800kDisk() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = PascalFormatDisk.create(
"createanddelete-test-pascal-800k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createAndDeleteFiles(disks, "CODE"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a ProDOS 140K disk.
*/
public void testCreateAndDeleteProdos140kDisk() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createanddelete-test-prodos-140k.dsk", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createAndDeleteFiles(disks, "BIN"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating and deleting many files on a ProDOS 800K disk.
*/
public void testCreateAndDeleteProdos800kDisk() throws IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createanddelete-test-prodos-800k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createAndDeleteFiles(disks, "BIN"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating, deleting, and then creating another file which re-uses
* the old directory entry on a DOS 3.3 140K disk.
*/
public void testCreateDeleteCreateDosDisk()
throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = DosFormatDisk.create(
"createdeletecreate-test-dos-140k.dsk", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating, deleting, and then creating another file which re-uses
* the old directory entry on a OzDOS 800K disk.
*/
public void testCreateDeleteCreateOzdosDisk()
throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = OzDosFormatDisk.create(
"createdeletecreate-test-ozdos-800k.po", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating, deleting, and then creating another file which re-uses
* the old directory entry on a UniDOS 800K disk.
*/
public void testCreateDeleteCreateUnidosDisk()
throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK);
ImageOrder imageOrder = new DosOrder(imageLayout);
FormattedDisk[] disks = UniDosFormatDisk.create(
"createdeletecreate-test-unidos-800k.dsk", imageOrder); //$NON-NLS-1$
createDeleteCreate(disks, "B"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating, deleting, and then creating another file which re-uses
* the old directory entry on a Pascal 140K disk.
*/
public void testCreateDeleteCreatePascalDisk()
throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = PascalFormatDisk.create(
"createdeletecreate-test-pascal-140k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createDeleteCreate(disks, "CODE"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Test creating, deleting, and then creating another file which re-uses
* the old directory entry on a ProDOS 140K disk.
*/
public void testCreateDeleteCreateProdosDisk()
throws DiskFullException, IOException {
ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_140KB_DISK);
ImageOrder imageOrder = new ProdosOrder(imageLayout);
FormattedDisk[] disks = ProdosFormatDisk.create(
"createdeletecreate-test-prodos-140k.dsk", "TEST", //$NON-NLS-1$ //$NON-NLS-2$
imageOrder);
createDeleteCreate(disks, "BIN"); //$NON-NLS-1$
saveDisks(disks);
}
/**
* Write many files to disk, read from disk, and verify contents.
* The intention is to verify creating files is done correctly,
* writing of contents is done correctly (the files are a series of
* random bytes), and reading of files is done correctly.
*/
protected void writeFiles(FormattedDisk[] disks, String binaryType,
String textType, boolean testText) throws DiskFullException {
FormattedDisk disk = disks[0];
showDirectory(disks, "BEFORE FILE CREATION"); //$NON-NLS-1$
writeFile(disk, 1, binaryType, true);
writeFile(disk, 2, binaryType, true);
writeFile(disk, 4, binaryType, true);
writeFile(disk, 8, binaryType, true);
writeFile(disk, 16, binaryType, true);
writeFile(disk, 256, binaryType, true);
writeFile(disk, 512, binaryType, true);
writeFile(disk, 1234, binaryType, true);
writeFile(disk, 54321, binaryType, true);
writeFile(disk,
"This is a test text file create from the DiskWriterTest".getBytes(), //$NON-NLS-1$
textType, testText);
if (disk.getPhysicalSize() > Disk.APPLE_140KB_DISK
&& disk.getPhysicalSize() != Disk.APPLE_140KB_NIBBLE_DISK) {
// create a few big files
writeFile(disk, 150000, binaryType, true);
writeFile(disk, 300000, binaryType, true);
}
showDirectory(disks, "AFTER FILE CREATION"); //$NON-NLS-1$
}
/**
* Generate randomized data for writing to disk.
*/
protected void writeFile(FormattedDisk disk, int size, String fileType,
boolean test) throws DiskFullException {
byte[] data = new byte[size];
for (int i=0; i