From 21abbe3433ff9719a15c7439ee5ebc22afde6365 Mon Sep 17 00:00:00 2001 From: "John B. Matthews" Date: Sat, 24 May 2008 16:32:43 +0000 Subject: [PATCH] Fix bug in PascalFormatDisk 800K; add Pascal unit tests. --- .../storage/os/pascal/PascalFormatDisk.java | 11 ++- .../applecommander/ui/AppleCommander.java | 2 +- .../storage/DiskWriterTest.java | 71 ++++++++++++++++++- 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java b/src/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java index 1ca6428..39b3b12 100644 --- a/src/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java +++ b/src/com/webcodepro/applecommander/storage/os/pascal/PascalFormatDisk.java @@ -49,10 +49,6 @@ public class PascalFormatDisk extends FormattedDisk { * The size of the Pascal file entry. */ public static final int ENTRY_SIZE = 26; - /** - * The number of Pascal blocks on a 140K disk. - */ - public static final int PASCAL_BLOCKS_ON_140K_DISK = 280; // filetypes used elsewhere in the code: private static final String TEXTFILE = "TEXT"; //$NON-NLS-1$ @@ -66,9 +62,9 @@ public class PascalFormatDisk extends FormattedDisk { "xdskfile", //$NON-NLS-1$ CODEFILE, TEXTFILE, - "INFO", //$NON-NLS-1$ + "INFO", //$NON-NLS-1$ DATAFILE, - "GRAF", //$NON-NLS-1$ + "GRAF", //$NON-NLS-1$ "FOTO", //$NON-NLS-1$ "securedir" }; //$NON-NLS-1$ @@ -563,7 +559,8 @@ public class PascalFormatDisk extends FormattedDisk { AppleUtil.setWordValue(directory, 2, 6); // last directory block AppleUtil.setWordValue(directory, 4, 0); // entry type (0=vol header) // volume name should have been set in constructor! - AppleUtil.setWordValue(directory, 14, PASCAL_BLOCKS_ON_140K_DISK); + int blocks = getImageOrder().getBlocksOnDevice(); + AppleUtil.setWordValue(directory, 14, blocks); AppleUtil.setWordValue(directory, 16, 0); // no files AppleUtil.setWordValue(directory, 18, 0); // first block AppleUtil.setPascalDate(directory, 20, new Date()); // most recent date setting diff --git a/src/com/webcodepro/applecommander/ui/AppleCommander.java b/src/com/webcodepro/applecommander/ui/AppleCommander.java index cd22c69..79a8225 100644 --- a/src/com/webcodepro/applecommander/ui/AppleCommander.java +++ b/src/com/webcodepro/applecommander/ui/AppleCommander.java @@ -40,7 +40,7 @@ import com.webcodepro.applecommander.util.TextBundle; * @author Rob Greene */ public class AppleCommander { - public static final String VERSION = "1.3.4.2"; //$NON-NLS-1$ + public static final String VERSION = "1.3.4.3"; //$NON-NLS-1$ private static TextBundle textBundle = UiBundle.getInstance(); /** * Launch AppleCommander. diff --git a/test/com/webcodepro/applecommander/storage/DiskWriterTest.java b/test/com/webcodepro/applecommander/storage/DiskWriterTest.java index fb088e2..cc43016 100644 --- a/test/com/webcodepro/applecommander/storage/DiskWriterTest.java +++ b/test/com/webcodepro/applecommander/storage/DiskWriterTest.java @@ -28,6 +28,7 @@ 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; @@ -81,7 +82,30 @@ public class DiskWriterTest extends TestCase { 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$ - saveImage = true; + 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); saveImage = false; } @@ -158,6 +182,32 @@ public class DiskWriterTest extends TestCase { 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. */ @@ -176,9 +226,9 @@ public class DiskWriterTest extends TestCase { */ public void testCreateAndDeleteProdos800kDisk() throws IOException { ByteArrayImageLayout imageLayout = new ByteArrayImageLayout(Disk.APPLE_800KB_DISK); - ImageOrder imageOrder = new DosOrder(imageLayout); + ImageOrder imageOrder = new ProdosOrder(imageLayout); FormattedDisk[] disks = ProdosFormatDisk.create( - "createanddelete-test-prodos-800k.dsk", "TEST", //$NON-NLS-1$ //$NON-NLS-2$ + "createanddelete-test-prodos-800k.po", "TEST", //$NON-NLS-1$ //$NON-NLS-2$ imageOrder); createAndDeleteFiles(disks, "BIN"); //$NON-NLS-1$ saveDisks(disks); @@ -226,6 +276,21 @@ public class DiskWriterTest extends TestCase { 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.