mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-03-20 00:00:03 -04:00
#438 CompoundDocument file descriptor fix
(cherry picked from commit 04f27a1)
This commit is contained in:
@@ -72,64 +72,64 @@ public class CompoundDocumentTest {
|
||||
|
||||
@Test
|
||||
public void testRoot() throws IOException {
|
||||
CompoundDocument document = createTestDocument();
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
|
||||
Entry root = document.getRootEntry();
|
||||
|
||||
assertNotNull(root);
|
||||
assertEquals("Root Entry", root.getName());
|
||||
assertTrue(root.isRoot());
|
||||
assertFalse(root.isFile());
|
||||
assertFalse(root.isDirectory());
|
||||
assertEquals(0, root.length());
|
||||
assertNull(root.getInputStream());
|
||||
assertNotNull(root);
|
||||
assertEquals("Root Entry", root.getName());
|
||||
assertTrue(root.isRoot());
|
||||
assertFalse(root.isFile());
|
||||
assertFalse(root.isDirectory());
|
||||
assertEquals(0, root.length());
|
||||
assertNull(root.getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContents() throws IOException {
|
||||
CompoundDocument document = createTestDocument();
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
|
||||
Entry root = document.getRootEntry();
|
||||
assertNotNull(root);
|
||||
|
||||
assertNotNull(root);
|
||||
SortedSet<Entry> children = new TreeSet<Entry>(root.getChildEntries());
|
||||
assertEquals(25, children.size());
|
||||
|
||||
SortedSet<Entry> children = new TreeSet<Entry>(root.getChildEntries());
|
||||
assertEquals(25, children.size());
|
||||
|
||||
// Weirdness in the file format, name is *written backwards* 1-24 + Catalog
|
||||
for (String name : "1,2,3,4,5,6,7,8,9,01,02,11,12,21,22,31,32,41,42,51,61,71,81,91,Catalog".split(",")) {
|
||||
assertEquals(name, children.first().getName());
|
||||
children.remove(children.first());
|
||||
// Weirdness in the file format, name is *written backwards* 1-24 + Catalog
|
||||
for (String name : "1,2,3,4,5,6,7,8,9,01,02,11,12,21,22,31,32,41,42,51,61,71,81,91,Catalog".split(",")) {
|
||||
assertEquals(name, children.first().getName());
|
||||
children.remove(children.first());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testChildEntriesUnmodifiable() throws IOException {
|
||||
CompoundDocument document = createTestDocument();
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
|
||||
Entry root = document.getRootEntry();
|
||||
assertNotNull(root);
|
||||
|
||||
assertNotNull(root);
|
||||
SortedSet<Entry> children = root.getChildEntries();
|
||||
|
||||
SortedSet<Entry> children = root.getChildEntries();
|
||||
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
// Should not be allowed, as it modifies the internal structure
|
||||
children.remove(children.first());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadThumbsCatalogFile() throws IOException {
|
||||
CompoundDocument document = createTestDocument();
|
||||
try (CompoundDocument document = createTestDocument()) {
|
||||
Entry root = document.getRootEntry();
|
||||
|
||||
Entry root = document.getRootEntry();
|
||||
assertNotNull(root);
|
||||
assertEquals(25, root.getChildEntries().size());
|
||||
|
||||
assertNotNull(root);
|
||||
assertEquals(25, root.getChildEntries().size());
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
Entry catalog = root.getChildEntry("Catalog");
|
||||
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
assertNotNull(catalog);
|
||||
assertNotNull("Input stream may not be null", catalog.getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,12 +33,12 @@ package com.twelvemonkeys.io.ole2;
|
||||
import com.twelvemonkeys.io.InputStreamAbstractTest;
|
||||
import com.twelvemonkeys.io.LittleEndianDataOutputStream;
|
||||
import com.twelvemonkeys.io.MemoryCacheSeekableStream;
|
||||
import com.twelvemonkeys.io.SeekableInputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -51,35 +51,7 @@ import static org.junit.Assert.*;
|
||||
* @author last modified by $Author: haraldk$
|
||||
* @version $Id: CompoundDocument_StreamTestCase.java,v 1.0 13.10.11 12:01 haraldk Exp$
|
||||
*/
|
||||
//@Ignore("Need proper in-memory creation of CompoundDocuments")
|
||||
public class CompoundDocument_StreamTest extends InputStreamAbstractTest {
|
||||
private static final String SAMPLE_DATA = "/Thumbs-camera.db";
|
||||
|
||||
protected final CompoundDocument createTestDocument() throws IOException {
|
||||
URL input = getClass().getResource(SAMPLE_DATA);
|
||||
|
||||
assertNotNull("Missing test resource!", input);
|
||||
assertEquals("Test resource not a file:// resource", "file", input.getProtocol());
|
||||
|
||||
try {
|
||||
return new CompoundDocument(new File(input.toURI()));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private SeekableInputStream createRealInputStream() {
|
||||
try {
|
||||
Entry first = createTestDocument().getRootEntry().getChildEntries().first();
|
||||
assertNotNull(first);
|
||||
return first.getInputStream();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream makeInputStream(byte[] data) {
|
||||
try {
|
||||
@@ -182,15 +154,13 @@ public class CompoundDocument_StreamTest extends InputStreamAbstractTest {
|
||||
return pad;
|
||||
}
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
public void testDev() throws IOException {
|
||||
public void testStreamRead() throws IOException {
|
||||
InputStream stream = makeInputStream(makeOrderedArray(32));
|
||||
|
||||
int read;
|
||||
int count = 0;
|
||||
while ((read = stream.read()) >= 0) {
|
||||
// System.out.printf("read %02d: 0x%02x%n", count, read & 0xFF);
|
||||
assertEquals(count, read);
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user