/* * 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.test; import com.webcodepro.applecommander.storage.DiskFullException; import com.webcodepro.applecommander.storage.DosFormatDisk; import com.webcodepro.applecommander.storage.FileEntry; import com.webcodepro.applecommander.storage.FormattedDisk; import com.webcodepro.applecommander.storage.OzDosFormatDisk; import com.webcodepro.applecommander.storage.ProdosFormatDisk; import com.webcodepro.applecommander.storage.UniDosFormatDisk; import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage; import java.io.IOException; import java.util.List; import junit.framework.TestCase; /** * 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 static final 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 { FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.dsk"); writeFiles(disks, "B", "T", false); saveDisks(disks); } /** * Test writing and reading random files to a ProDOS 140K disk. */ public void testWriteToProdos140kDisk() throws DiskFullException, IOException { FormattedDisk[] disks = ProdosFormatDisk.create( "write-test-prodos-140k.dsk", "TEST", ProdosFormatDisk.APPLE_140KB_DISK); writeFiles(disks, "BIN", "TXT", true); saveDisks(disks); } /** * Test writing and reading random files to a ProDOS 800K disk. */ public void testWriteToProdos800kDisk() throws DiskFullException, IOException { FormattedDisk[] disks = ProdosFormatDisk.create( "write-test-prodos-800k.po", "TEST", ProdosFormatDisk.APPLE_800KB_DISK); writeFiles(disks, "BIN", "TXT", true); saveDisks(disks); } /** * Test writing and reading random files to a ProDOS 5MB disk. */ public void testWriteToProdos5mbDisk() throws DiskFullException, IOException { FormattedDisk[] disks = ProdosFormatDisk.create( "write-test-prodos-5mb.hdv", "TEST", ProdosFormatDisk.APPLE_5MB_HARDDISK); writeFiles(disks, "BIN", "TXT", true); saveDisks(disks); } /** * Test creating and deleting many files on a DOS 3.3 140K disk. */ public void testCreateAndDeleteDos33() throws IOException { FormattedDisk[] disks = DosFormatDisk.create( "createanddelete-test-dos33.dsk"); createAndDeleteFiles(disks, "B"); saveDisks(disks); } /** * Test creating and deleting many files on an OzDOS 800K disk. */ public void testCreateAndDeleteOzDos() throws IOException { FormattedDisk[] disks = OzDosFormatDisk.create( "createanddelete-test-ozdos.po"); createAndDeleteFiles(disks, "B"); saveDisks(disks); } /** * Test creating and deleting many files on a UniDOS 800K disk. */ public void testCreateAndDeleteUniDos() throws IOException { FormattedDisk[] disks = UniDosFormatDisk.create( "createanddelete-test-unidos.dsk"); createAndDeleteFiles(disks, "B"); saveDisks(disks); } /** * Test creating and deleting many files on a ProDOS 140K disk. */ public void testCreateAndDeleteProdos140kDisk() throws IOException { FormattedDisk[] disks = ProdosFormatDisk.create( "createanddelete-test-prodos-140k.dsk", "TEST", ProdosFormatDisk.APPLE_140KB_DISK); createAndDeleteFiles(disks, "BIN"); saveDisks(disks); } /** * Test creating and deleting many files on a ProDOS 800K disk. */ public void testCreateAndDeleteProdos800kDisk() throws IOException { FormattedDisk[] disks = ProdosFormatDisk.create( "createanddelete-test-prodos-800k.dsk", "TEST", ProdosFormatDisk.APPLE_800KB_2IMG_DISK); createAndDeleteFiles(disks, "BIN"); 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 { FormattedDisk[] disks = DosFormatDisk.create( "createdeletecreate-test-dos-140k.dsk"); createDeleteCreate(disks, "B"); 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 { FormattedDisk[] disks = OzDosFormatDisk.create( "createdeletecreate-test-ozdos-800k.po"); createDeleteCreate(disks, "B"); 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 { FormattedDisk[] disks = UniDosFormatDisk.create( "createdeletecreate-test-unidos-800k.dsk"); createDeleteCreate(disks, "B"); 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 { FormattedDisk[] disks = ProdosFormatDisk.create( "createdeletecreate-test-prodos-140k.dsk", "TEST", ProdosFormatDisk.APPLE_140KB_DISK); createDeleteCreate(disks, "BIN"); 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"); 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(), textType, testText); if (disk.getPhysicalSize() > disk.APPLE_140KB_DISK) { // create a few big files writeFile(disk, 150000, binaryType, true); writeFile(disk, 300000, binaryType, true); } showDirectory(disks, "AFTER FILE CREATION"); } /** * 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 0 && i % 80 == 0) System.out.println(); usage.next(); System.out.print(usage.isFree() ? "." : "U"); i++; } System.out.println(); } else { for (int y=dimensions[0]-1; y>=0; y--) { for (int x=0; x