From 7ba84fbf97228d9e4769fe61a157dd9dfbadd53b Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Thu, 3 Jun 2004 03:28:26 +0000 Subject: [PATCH] Moved tests to a separate source folder. --- .../applecommander/test/AppleUtilTest.java | 79 ------------ .../compiler}/ApplesoftCompilerTest.java | 2 +- .../storage}/DiskHelperTest.java | 2 +- .../storage}/DiskWriterTest.java | 2 +- .../filters/imagehandlers}/SwtImageTest.java | 2 +- .../applecommander/util/AppleUtilTest.java | 118 ++++++++++++++++++ 6 files changed, 122 insertions(+), 83 deletions(-) delete mode 100644 src/com/webcodepro/applecommander/test/AppleUtilTest.java rename {src/com/webcodepro/applecommander/test => test/com/webcodepro/applecommander/compiler}/ApplesoftCompilerTest.java (97%) rename {src/com/webcodepro/applecommander/test => test/com/webcodepro/applecommander/storage}/DiskHelperTest.java (99%) rename {src/com/webcodepro/applecommander/test => test/com/webcodepro/applecommander/storage}/DiskWriterTest.java (99%) rename {src/com/webcodepro/applecommander/test => test/com/webcodepro/applecommander/storage/filters/imagehandlers}/SwtImageTest.java (96%) create mode 100644 test/com/webcodepro/applecommander/util/AppleUtilTest.java diff --git a/src/com/webcodepro/applecommander/test/AppleUtilTest.java b/src/com/webcodepro/applecommander/test/AppleUtilTest.java deleted file mode 100644 index 6b22c00..0000000 --- a/src/com/webcodepro/applecommander/test/AppleUtilTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * AppleCommander - An Apple ][ image utility. - * Copyright (C) 2003 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.util.AppleUtil; - -import junit.framework.TestCase; - -/** - * Test AppleUtil. - */ -public class AppleUtilTest extends TestCase { - public AppleUtilTest(String name) { - super(name); - } - - public static void main(String[] args) { - junit.textui.TestRunner.run(AppleUtilTest.class); - } - - /** - * These constants were pulled from Applesoft itself. - */ - public void testApplesoftFloat() { - testApplesoftFloat(1.0, 0x8100000000L); - testApplesoftFloat(10.0, 0x8420000000L); - testApplesoftFloat(0.5, 0x8000000000L); - testApplesoftFloat(-0.5, 0x8080000000L); - testApplesoftFloat(0.25, 0x7F00000000L); - testApplesoftFloat(-32768.0, 0x9080000000L); - testApplesoftFloat(99999999.9, 0x9B3EBC1FFDL); - testApplesoftFloat(999999999.0, 0x9E6E6B27FDL); - testApplesoftFloat(1000000000.0, 0x9E6E6B2800L); - testApplesoftFloat(Math.sqrt(0.5), 0x803504F334L); - testApplesoftFloat(Math.sqrt(2.0), 0x813504F334L); - testApplesoftFloat(Math.log(2.0), 0x80317217F8L); - testApplesoftFloat(Math.PI / 2, 0x81490FDAA2L); - testApplesoftFloat(Math.PI * 2, 0x83490FDAA2L); - } - - protected void testApplesoftFloat(double question, long correctAnswer) { - log("Testing " + question); - byte[] testAnswer = AppleUtil.getApplesoftFloat(question); - long answer = testAnswer[0] & 0xff; - answer <<= 8; - answer |= testAnswer[1] & 0xff; - answer <<= 8; - answer |= testAnswer[2] & 0xff; - answer <<= 8; - answer |= testAnswer[3] & 0xff; - answer <<= 8; - answer |= testAnswer[4] & 0xff; - // Allow some variance = +/- 1 (that would be the least-significant bit) - if (Math.abs(answer - correctAnswer) > 1) { - fail("Numbers should match - " + question); - } - } - - protected void log(String message) { - System.out.println(message); - } -} diff --git a/src/com/webcodepro/applecommander/test/ApplesoftCompilerTest.java b/test/com/webcodepro/applecommander/compiler/ApplesoftCompilerTest.java similarity index 97% rename from src/com/webcodepro/applecommander/test/ApplesoftCompilerTest.java rename to test/com/webcodepro/applecommander/compiler/ApplesoftCompilerTest.java index d05727e..3a8cd03 100644 --- a/src/com/webcodepro/applecommander/test/ApplesoftCompilerTest.java +++ b/test/com/webcodepro/applecommander/compiler/ApplesoftCompilerTest.java @@ -17,7 +17,7 @@ * 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; +package com.webcodepro.applecommander.compiler; import com.webcodepro.applecommander.compiler.ApplesoftCompiler; import com.webcodepro.applecommander.storage.Disk; diff --git a/src/com/webcodepro/applecommander/test/DiskHelperTest.java b/test/com/webcodepro/applecommander/storage/DiskHelperTest.java similarity index 99% rename from src/com/webcodepro/applecommander/test/DiskHelperTest.java rename to test/com/webcodepro/applecommander/storage/DiskHelperTest.java index f9846b8..c517bfa 100644 --- a/src/com/webcodepro/applecommander/test/DiskHelperTest.java +++ b/test/com/webcodepro/applecommander/storage/DiskHelperTest.java @@ -17,7 +17,7 @@ * 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; +package com.webcodepro.applecommander.storage; import com.webcodepro.applecommander.storage.ApplesoftFileFilter; import com.webcodepro.applecommander.storage.BinaryFileFilter; diff --git a/src/com/webcodepro/applecommander/test/DiskWriterTest.java b/test/com/webcodepro/applecommander/storage/DiskWriterTest.java similarity index 99% rename from src/com/webcodepro/applecommander/test/DiskWriterTest.java rename to test/com/webcodepro/applecommander/storage/DiskWriterTest.java index 83d486e..92af28b 100644 --- a/src/com/webcodepro/applecommander/test/DiskWriterTest.java +++ b/test/com/webcodepro/applecommander/storage/DiskWriterTest.java @@ -17,7 +17,7 @@ * 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; +package com.webcodepro.applecommander.storage; import com.webcodepro.applecommander.storage.DirectoryEntry; import com.webcodepro.applecommander.storage.Disk; diff --git a/src/com/webcodepro/applecommander/test/SwtImageTest.java b/test/com/webcodepro/applecommander/storage/filters/imagehandlers/SwtImageTest.java similarity index 96% rename from src/com/webcodepro/applecommander/test/SwtImageTest.java rename to test/com/webcodepro/applecommander/storage/filters/imagehandlers/SwtImageTest.java index 345208f..e0843a6 100644 --- a/src/com/webcodepro/applecommander/test/SwtImageTest.java +++ b/test/com/webcodepro/applecommander/storage/filters/imagehandlers/SwtImageTest.java @@ -1,4 +1,4 @@ -package com.webcodepro.applecommander.test; +package com.webcodepro.applecommander.storage.filters.imagehandlers; import com.webcodepro.applecommander.storage.filters.imagehandlers.SwtImage; diff --git a/test/com/webcodepro/applecommander/util/AppleUtilTest.java b/test/com/webcodepro/applecommander/util/AppleUtilTest.java new file mode 100644 index 0000000..3a8da18 --- /dev/null +++ b/test/com/webcodepro/applecommander/util/AppleUtilTest.java @@ -0,0 +1,118 @@ +/* + * AppleCommander - An Apple ][ image utility. + * Copyright (C) 2003 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.util; + +import junit.framework.TestCase; + +import com.webcodepro.applecommander.storage.Disk; +import com.webcodepro.applecommander.storage.DiskFullException; +import com.webcodepro.applecommander.storage.DosFormatDisk; +import com.webcodepro.applecommander.storage.FileEntry; +import com.webcodepro.applecommander.storage.ProdosFormatDisk; +import com.webcodepro.applecommander.storage.physical.ByteArrayImageLayout; +import com.webcodepro.applecommander.storage.physical.DosOrder; +import com.webcodepro.applecommander.storage.physical.NibbleOrder; +import com.webcodepro.applecommander.storage.physical.ProdosOrder; + +/** + * Test AppleUtil. + */ +public class AppleUtilTest extends TestCase { + public AppleUtilTest(String name) { + super(name); + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(AppleUtilTest.class); + } + + /** + * These constants were pulled from Applesoft itself. + */ + public void testApplesoftFloat() { + testApplesoftFloat(1.0, 0x8100000000L); + testApplesoftFloat(10.0, 0x8420000000L); + testApplesoftFloat(0.5, 0x8000000000L); + testApplesoftFloat(-0.5, 0x8080000000L); + testApplesoftFloat(0.25, 0x7F00000000L); + testApplesoftFloat(-32768.0, 0x9080000000L); + testApplesoftFloat(99999999.9, 0x9B3EBC1FFDL); + testApplesoftFloat(999999999.0, 0x9E6E6B27FDL); + testApplesoftFloat(1000000000.0, 0x9E6E6B2800L); + testApplesoftFloat(Math.sqrt(0.5), 0x803504F334L); + testApplesoftFloat(Math.sqrt(2.0), 0x813504F334L); + testApplesoftFloat(Math.log(2.0), 0x80317217F8L); + testApplesoftFloat(Math.PI / 2, 0x81490FDAA2L); + testApplesoftFloat(Math.PI * 2, 0x83490FDAA2L); + } + + protected void testApplesoftFloat(double question, long correctAnswer) { + byte[] testAnswer = AppleUtil.getApplesoftFloat(question); + long answer = testAnswer[0] & 0xff; + answer <<= 8; + answer |= testAnswer[1] & 0xff; + answer <<= 8; + answer |= testAnswer[2] & 0xff; + answer <<= 8; + answer |= testAnswer[3] & 0xff; + answer <<= 8; + answer |= testAnswer[4] & 0xff; + // Allow some variance = +/- 1 (that would be the least-significant bit) + if (Math.abs(answer - correctAnswer) > 1) { + fail("Numbers should match - " + question); + } + } + + public void testChangeDosImageOrder() throws DiskFullException { + // Straight DOS disk in standard DOS order + DosFormatDisk dosDiskDosOrder = DosFormatDisk.create("dostemp.dsk", + new DosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0]; + FileEntry fileEntry = dosDiskDosOrder.createFile(); + fileEntry.setFilename("TESTFILE"); + fileEntry.setFiletype("T"); + fileEntry.setFileData("This is a test file.".getBytes()); + // A duplicate - then we change it to a NIB disk image... + DosFormatDisk dosDiskNibbleOrder = DosFormatDisk.create("dostemp2.nib", + new NibbleOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0]; + AppleUtil.changeImageOrderByTrackAndSector(dosDiskDosOrder.getImageOrder(), + dosDiskNibbleOrder.getImageOrder()); + // Confirm that these disks are identical: + assertTrue(AppleUtil.disksEqualByTrackAndSector(dosDiskDosOrder, dosDiskNibbleOrder)); + } + + public void testChangeProdosImageOrder() throws DiskFullException { + // Straight ProDOS disk in standard ProDOS block order + ProdosFormatDisk prodosDiskDosOrder = ProdosFormatDisk.create("prodostemp.po", + "prodostemp", + new ProdosOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0]; + FileEntry fileEntry = prodosDiskDosOrder.createFile(); + fileEntry.setFilename("TESTFILE"); + fileEntry.setFiletype("TXT"); + fileEntry.setFileData("This is a test file.".getBytes()); + // A duplicate - then we change it to a NIB disk image... + ProdosFormatDisk prodosDiskNibbleOrder = ProdosFormatDisk.create("prodostemp2.nib", + "prodostemp2", + new NibbleOrder(new ByteArrayImageLayout(Disk.APPLE_140KB_DISK)))[0]; + AppleUtil.changeImageOrderByBlock(prodosDiskDosOrder.getImageOrder(), + prodosDiskNibbleOrder.getImageOrder()); + // Confirm that these disks are identical: + assertTrue(AppleUtil.disksEqualByBlock(prodosDiskDosOrder, prodosDiskNibbleOrder)); + } +}