mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2025-02-27 02:31:23 +00:00
Updated test to use a common test across any disk format; added
ProDOS 140K, 800K, and 5MB tests.
This commit is contained in:
parent
ae9ec0f016
commit
ee1d5fb8b5
@ -23,9 +23,11 @@ import com.webcodepro.applecommander.storage.DiskFullException;
|
|||||||
import com.webcodepro.applecommander.storage.DosFormatDisk;
|
import com.webcodepro.applecommander.storage.DosFormatDisk;
|
||||||
import com.webcodepro.applecommander.storage.FileEntry;
|
import com.webcodepro.applecommander.storage.FileEntry;
|
||||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||||
|
import com.webcodepro.applecommander.storage.ProdosFormatDisk;
|
||||||
import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage;
|
import com.webcodepro.applecommander.storage.FormattedDisk.DiskUsage;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -47,26 +49,74 @@ public class DiskWriterTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteToDos33() throws DiskFullException, IOException {
|
public void testWriteToDos33() throws DiskFullException, IOException {
|
||||||
FormattedDisk[] disks = DosFormatDisk.create("write-test.dsk");
|
FormattedDisk[] disks = DosFormatDisk.create("write-test-dos33.dsk");
|
||||||
showDirectory(disks, "BEFORE FILE CREATION");
|
writeFiles(disks, "B", "T");
|
||||||
|
disks[0].save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWriteToProdos140kDisk() throws DiskFullException, IOException {
|
||||||
|
FormattedDisk[] disks = ProdosFormatDisk.create(
|
||||||
|
"write-test-prodos-140k.dsk", "TEST", ProdosFormatDisk.APPLE_140KB_DISK);
|
||||||
|
writeFiles(disks, "BIN", "TXT");
|
||||||
|
disks[0].save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWriteToProdos800kDisk() throws DiskFullException, IOException {
|
||||||
|
FormattedDisk[] disks = ProdosFormatDisk.create(
|
||||||
|
"write-test-prodos-800k.po", "TEST", ProdosFormatDisk.APPLE_800KB_DISK);
|
||||||
|
writeFiles(disks, "BIN", "TXT");
|
||||||
|
disks[0].save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWriteToProdos5mbDisk() throws DiskFullException, IOException {
|
||||||
|
FormattedDisk[] disks = ProdosFormatDisk.create(
|
||||||
|
"write-test-prodos-5mb.hdv", "TEST", ProdosFormatDisk.APPLE_5MB_HARDDISK);
|
||||||
|
writeFiles(disks, "BIN", "TXT");
|
||||||
|
disks[0].save();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void writeFiles(FormattedDisk[] disks, String binaryType,
|
||||||
|
String textType) throws DiskFullException {
|
||||||
FormattedDisk disk = disks[0];
|
FormattedDisk disk = disks[0];
|
||||||
FileEntry entry = disk.createFile();
|
showDirectory(disks, "BEFORE FILE CREATION");
|
||||||
entry.setFilename("big binary file");
|
writeFile(disk, 1, binaryType);
|
||||||
entry.setFiletype("B");
|
writeFile(disk, 2, binaryType);
|
||||||
entry.setFileData(new byte[50000]);
|
writeFile(disk, 4, binaryType);
|
||||||
|
writeFile(disk, 8, binaryType);
|
||||||
|
writeFile(disk, 16, binaryType);
|
||||||
|
writeFile(disk, 256, binaryType);
|
||||||
|
writeFile(disk, 512, binaryType);
|
||||||
|
writeFile(disk, 1234, binaryType);
|
||||||
|
writeFile(disk, 54321, binaryType);
|
||||||
|
writeFile(disk,
|
||||||
|
"This is a test text file create from the DiskWriterTest".getBytes(),
|
||||||
|
textType);
|
||||||
|
if (disk.getPhysicalSize() > disk.APPLE_140KB_DISK) {
|
||||||
|
// create a few big files
|
||||||
|
writeFile(disk, 150000, binaryType);
|
||||||
|
writeFile(disk, 300000, binaryType);
|
||||||
|
}
|
||||||
showDirectory(disks, "AFTER FILE CREATION");
|
showDirectory(disks, "AFTER FILE CREATION");
|
||||||
entry.setFilename("test");
|
}
|
||||||
entry.setFiletype("T");
|
|
||||||
entry.setFileData(
|
protected void writeFile(FormattedDisk disk, int size, String fileType)
|
||||||
"This is a test text file created from the DiskWriterTest".getBytes());
|
throws DiskFullException {
|
||||||
showDirectory(disks, "AFTER FILE MODIFICATION");
|
byte[] data = new byte[size];
|
||||||
FileEntry entry2 = disk.createFile();
|
for (int i=0; i<data.length; i++) {
|
||||||
entry2.setFilename("another test text file");
|
data[i] = (byte)(Math.random() * 1024);
|
||||||
entry2.setFiletype("T");
|
}
|
||||||
entry2.setFileData(
|
writeFile(disk, data, fileType);
|
||||||
"Yo ho ho and a bottle of rum".getBytes());
|
}
|
||||||
showDirectory(disks, "AFTER SECONDARY FILE CREATION");
|
|
||||||
disk.save();
|
protected void writeFile(FormattedDisk disk, byte[] data, String fileType)
|
||||||
|
throws DiskFullException {
|
||||||
|
FileEntry entry = disk.createFile();
|
||||||
|
entry.setFilename("file-" + data.length);
|
||||||
|
entry.setFiletype(fileType);
|
||||||
|
entry.setFileData(data);
|
||||||
|
byte[] data2 = entry.getFileData();
|
||||||
|
assertTrue("File lengths do not match", data.length == data2.length);
|
||||||
|
assertTrue("File contents do not match", Arrays.equals(data, data2));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showDirectory(FormattedDisk[] formattedDisks, String title) {
|
protected void showDirectory(FormattedDisk[] formattedDisks, String title) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user