aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-06-11 00:43:45 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-06-11 00:43:45 +0000
commitd559feb7deff492fd196bfbaf05888db1305cc45 (patch)
tree87aa211c95598a860ece3fc500d4197593361be8 /src/testcases
parent0181d2abd90142edc4572ca3acdc88cefeb6a3a4 (diff)
downloadpoi-d559feb7deff492fd196bfbaf05888db1305cc45.tar.gz
poi-d559feb7deff492fd196bfbaf05888db1305cc45.zip
64512 - Ole10Native aka embedded / object packager - handle UTF16 variants
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1878730 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java b/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
index ad686358d0..4de08c4c5c 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
@@ -17,11 +17,9 @@
package org.apache.poi.poifs.filesystem;
-import static org.apache.poi.POITestCase.assertContains;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -33,11 +31,17 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.RecordFormatException;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class TestOle10Native {
private static final POIDataSamples dataSamples = POIDataSamples.getPOIFSInstance();
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void testOleNative() throws IOException, Ole10NativeException {
POIFSFileSystem fs = new POIFSFileSystem(dataSamples.openResourceAsStream("oleObject1.bin"));
@@ -59,26 +63,26 @@ public class TestOle10Native {
POIDataSamples.getDocumentInstance().getFile("Bug53380_3.doc"),
POIDataSamples.getDocumentInstance().getFile("Bug47731.doc")
};
-
+
for (File f : files) {
POIFSFileSystem fs = new POIFSFileSystem(f, true);
List<Entry> entries = new ArrayList<>();
findOle10(entries, fs.getRoot(), "/");
-
+
for (Entry e : entries) {
ByteArrayOutputStream bosExp = new ByteArrayOutputStream();
InputStream is = ((DirectoryNode)e.getParent()).createDocumentInputStream(e);
IOUtils.copy(is,bosExp);
is.close();
-
+
Ole10Native ole = Ole10Native.createFromEmbeddedOleObject((DirectoryNode)e.getParent());
-
+
ByteArrayOutputStream bosAct = new ByteArrayOutputStream();
ole.writeOut(bosAct);
-
+
assertThat(bosExp.toByteArray(), equalTo(bosAct.toByteArray()));
}
-
+
fs.close();
}
}
@@ -97,14 +101,11 @@ public class TestOle10Native {
}
@Test
- public void testOleNativeOOM() throws IOException {
+ public void testOleNativeOOM() throws IOException, Ole10NativeException {
POIFSFileSystem fs = new POIFSFileSystem(dataSamples.openResourceAsStream("60256.bin"));
- try {
- Ole10Native.createFromEmbeddedOleObject(fs);
- fail("Should have thrown exception because OLENative lacks a length parameter");
- } catch (Ole10NativeException e) {
- assertContains(e.getMessage(), "declared data length");
- }
+ thrown.expect(RecordFormatException.class);
+ thrown.expectMessage("Tried to allocate");
+ Ole10Native.createFromEmbeddedOleObject(fs);
}
}