/* * 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 static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; import java.util.List; import org.junit.Test; 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 { /** * Determine if the created disk images should be saved for later * perusal. */ private boolean saveImage = false; /** * Test writing and reading random files to a DOS 3.3 140K disk. */ @Test public void testWriteToDos33() throws IOException, DiskException { 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. */ @Test public void testWriteToDos33Nibble() throws IOException, DiskException { 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. */ @Test public void testWriteToPascal140kDisk() throws IOException, DiskException { 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. */ @Test 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. */ @Test public void testWriteToProdos140kDisk() throws IOException, DiskException { 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. */ @Test public void testWriteToProdos800kDisk() throws IOException, DiskException { 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. */ @Test public void testWriteToProdos5mbDisk() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeleteDos33() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeleteOzDos() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeleteUniDos() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeletePascal140kDisk() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeletePascal800kDisk() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeleteProdos140kDisk() throws IOException, DiskException { 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. */ @Test public void testCreateAndDeleteProdos800kDisk() throws IOException, DiskException { 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. */ @Test public void testCreateDeleteCreateDosDisk() throws IOException, DiskException { 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. */ @Test public void testCreateDeleteCreateOzdosDisk() throws IOException, DiskException { 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. */ @Test public void testCreateDeleteCreateUnidosDisk() throws IOException, DiskException { 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. */ @Test public void testCreateDeleteCreatePascalDisk() throws IOException, DiskException { 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. */ @Test public void testCreateDeleteCreateProdosDisk() throws IOException, DiskException { 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 DiskException { 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 DiskException { byte[] data = new byte[size]; for (int i=0; i files = formattedDisk.getFiles(); if (files != null) { showFiles(files, "", false); //$NON-NLS-1$ } System.out.println(formattedDisk.getFreeSpace() + " bytes free."); //$NON-NLS-1$ System.out.println(formattedDisk.getUsedSpace() + " bytes used."); //$NON-NLS-1$ System.out.println("This disk " + (formattedDisk.canHaveDirectories() ? "does" : "does not") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ " support directories."); //$NON-NLS-1$ System.out.println("This disk is formatted in the " + formattedDisk.getFormat() + " format."); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(); showDiskUsage(formattedDisk); } System.out.println(); System.out.println("************************************************"); //$NON-NLS-1$ System.out.println(); } /** * Display a list of files. */ protected void showFiles(List files, String indent, boolean showDeleted) throws DiskException { for (int i=0; i data = entry.getFileColumnData(FormattedDisk.FILE_DISPLAY_NATIVE); System.out.print(indent); for (int d=0; d 0 && i % 80 == 0) System.out.println(); usage.next(); System.out.print(usage.isFree() ? "." : "U"); //$NON-NLS-1$ //$NON-NLS-2$ i++; } System.out.println(); } else { for (int y=dimensions[0]-1; y>=0; y--) { for (int x=0; x files = disk.getFiles(); for (int i=0; i files = disk.getFiles(); for (int i=0; i