From c2575f692cface73503092792a7dc693d990abff Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Mon, 23 Dec 2002 21:11:58 +0000 Subject: [PATCH] Added test for disk image writing. --- .../applecommander/test/DiskWriterTest.java | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 src/com/webcodepro/applecommander/test/DiskWriterTest.java diff --git a/src/com/webcodepro/applecommander/test/DiskWriterTest.java b/src/com/webcodepro/applecommander/test/DiskWriterTest.java new file mode 100644 index 0000000..6a39b20 --- /dev/null +++ b/src/com/webcodepro/applecommander/test/DiskWriterTest.java @@ -0,0 +1,143 @@ +/* + * 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.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 { + + public DiskWriterTest(String name) { + super(name); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(DiskWriterTest.class); + } + + public void testWriteToDos33() throws DiskFullException, IOException { + FormattedDisk[] disks = DosFormatDisk.create("write-test.dsk"); + showDirectory(disks, "BEFORE FILE CREATION"); + FormattedDisk disk = disks[0]; + FileEntry entry = disk.createFile(); + entry.setFilename("big binary file"); + entry.setFiletype("B"); + entry.setFileData(new byte[50000]); + showDirectory(disks, "AFTER FILE CREATION"); + entry.setFilename("test"); + entry.setFiletype("T"); + entry.setFileData( + "This is a test text file created from the DiskWriterTest".getBytes()); + showDirectory(disks, "AFTER FILE MODIFICATION"); + FileEntry entry2 = disk.createFile(); + entry2.setFilename("another test text file"); + entry2.setFiletype("T"); + entry2.setFileData( + "Yo ho ho and a bottle of rum".getBytes()); + showDirectory(disks, "AFTER SECONDARY FILE CREATION"); + disk.save(); + } + + protected void showDirectory(FormattedDisk[] formattedDisks, String title) { + System.out.println(); + System.out.println("************************************************"); + System.out.println(title); + 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