aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache/poi/hsmf
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-01-07 16:15:20 +0000
committerNick Burch <nick@apache.org>2010-01-07 16:15:20 +0000
commit41994b053f940a3ee9e8d682c49628b3a71ccf7b (patch)
treec47f32743c19fe7889cdc3479f515779d2f0caae /src/scratchpad/testcases/org/apache/poi/hsmf
parent643a43720b5c89a2dfa7d809e62d1d767fc822c7 (diff)
downloadpoi-41994b053f940a3ee9e8d682c49628b3a71ccf7b.tar.gz
poi-41994b053f940a3ee9e8d682c49628b3a71ccf7b.zip
Start on major HSMF refactoring. Should compile, but not quite all tests pass as a little bit of work is left
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@896914 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache/poi/hsmf')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java50
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java24
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java46
3 files changed, 86 insertions, 34 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java
index fe9a370ab3..6a9fae44e2 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java
@@ -20,6 +20,7 @@ package org.apache.poi.hsmf.model;
import org.apache.poi.hsmf.datatypes.Chunk;
import org.apache.poi.hsmf.datatypes.Chunks;
import org.apache.poi.hsmf.datatypes.StringChunk;
+import org.apache.poi.hsmf.datatypes.Types;
import junit.framework.TestCase;
@@ -31,47 +32,54 @@ import junit.framework.TestCase;
*
*/
public final class TestChunkData extends TestCase {
- private Chunks chunks = Chunks.getInstance(false);
-
public void testChunkCreate() {
- StringChunk chunk = new StringChunk(0x0200, false);
- TestCase.assertEquals("__substg1.0_0200001E", chunk.getEntryName());
-
+ Chunk chunk;
+
+ chunk = new StringChunk(0x0200, 0x001E);
+ assertEquals("__substg1.0_0200001E", chunk.getEntryName());
+ assertEquals(0x0200, chunk.getChunkId());
+ assertEquals(0x001E, chunk.getType());
+
+ chunk = new StringChunk("__substg1.0_0200001E");
+ assertEquals("__substg1.0_0200001E", chunk.getEntryName());
+ assertEquals(0x0200, chunk.getChunkId());
+ assertEquals(0x001E, chunk.getType());
+
/* test the lower and upper limits of the chunk ids */
- chunk = new StringChunk(0x0000, false);
- TestCase.assertEquals("__substg1.0_0000001E", chunk.getEntryName());
+ chunk = new StringChunk(0x0000, 0x001E);
+ assertEquals("__substg1.0_0000001E", chunk.getEntryName());
- chunk = new StringChunk(0xFFFF, false);
- TestCase.assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
+ chunk = new StringChunk(0xFFFF, 0x001E);
+ assertEquals("__substg1.0_FFFF001E", chunk.getEntryName());
- chunk = new StringChunk(0xFFFF, true);
- TestCase.assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
+ chunk = new StringChunk(0xFFFF, 0x001F);
+ assertEquals("__substg1.0_FFFF001F", chunk.getEntryName());
}
public void testTextBodyChunk() {
- StringChunk chunk = new StringChunk(0x1000, false);
- TestCase.assertEquals(chunk.getEntryName(), chunks.textBodyChunk.getEntryName());
+ StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.TEXT_BODY);
}
public void testDisplayToChunk() {
- StringChunk chunk = new StringChunk(0x0E04, false);
- TestCase.assertEquals(chunk.getEntryName(), chunks.displayToChunk.getEntryName());
+ StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_TO);
}
public void testDisplayCCChunk() {
- StringChunk chunk = new StringChunk(0x0E03, false);
- TestCase.assertEquals(chunk.getEntryName(), chunks.displayCCChunk.getEntryName());
+ StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_CC);
}
public void testDisplayBCCChunk() {
- StringChunk chunk = new StringChunk(0x0E02, false);
- TestCase.assertEquals(chunk.getEntryName(), chunks.displayBCCChunk.getEntryName());
+ StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.DISPLAY_BCC);
}
public void testSubjectChunk() {
- Chunk chunk = new StringChunk(0x0037, false);
- TestCase.assertEquals(chunk.getEntryName(), chunks.subjectChunk.getEntryName());
+ Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING);
+ assertEquals(chunk.getChunkId(), Chunks.SUBJECT);
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java
index 24f8eae477..8762ef415c 100644
--- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java
@@ -26,6 +26,7 @@ import java.util.Map;
import junit.framework.TestCase;
import org.apache.poi.hsmf.MAPIMessage;
+import org.apache.poi.hsmf.datatypes.AttachmentChunks;
import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.POIDataSamples;
@@ -55,8 +56,8 @@ public class TestFileWithAttachmentsRead extends TestCase {
*/
// public void testReadDisplayCC() throws ChunkNotFoundException {
public void testRetrieveAttachments() {
- Map attachmentsMap = mapiMessage.getAttachmentFiles();
- int obtained = attachmentsMap.size();
+ AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
+ int obtained = attachments.length;
int expected = 2;
TestCase.assertEquals(obtained, expected);
@@ -69,19 +70,16 @@ public class TestFileWithAttachmentsRead extends TestCase {
*
*/
public void testReadAttachments() throws IOException {
- Map attachmentsMap = mapiMessage.getAttachmentFiles();
+ AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles();
- for (Iterator iterator = attachmentsMap.keySet().iterator(); iterator.hasNext();) {
- String fileName = (String) iterator.next();
- ByteArrayInputStream fileStream = (ByteArrayInputStream) attachmentsMap.get(fileName);
- ByteArrayOutputStream fileContent = new ByteArrayOutputStream();
-
- while (fileStream.available() > 0) {
- fileContent.write(fileStream.read());
- }
- String obtained = new String(fileContent.toByteArray(), "UTF-8");
- assertTrue(obtained.trim().length() > 0);
+ for (AttachmentChunks attachment : attachments) {
+ assertTrue(attachment.attachFileName.getValue().length() > 0);
+ assertTrue(attachment.attachLongFileName.getValue().length() > 0);
+ assertTrue(attachment.attachExtension.getValue().length() > 0);
+ assertTrue(attachment.attachMimeTag.getValue().length() > 0);
}
+
+ // TODO better checking
}
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java
new file mode 100644
index 0000000000..2b99af5309
--- /dev/null
+++ b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java
@@ -0,0 +1,46 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hsmf.model;
+
+import org.apache.poi.hsmf.datatypes.Types;
+
+import junit.framework.TestCase;
+
+/**
+ * Verifies that the Types class is behaving properly.
+ * Also check that no changes have been made that will
+ * break the library.
+ */
+public final class TestTypes extends TestCase {
+ public void testTypeIds() {
+ assertEquals(0x1e, Types.ASCII_STRING);
+ assertEquals(0x1f, Types.UNICODE_STRING);
+
+ assertEquals(0x0102, Types.BINARY);
+ assertEquals(0x000B, Types.BOOLEAN);
+ assertEquals(0x0003, Types.LONG);
+ assertEquals(0x0040, Types.TIME);
+ }
+
+ public void testTypeFormatting() {
+ assertEquals("0000", Types.asFileEnding(0x0000));
+ assertEquals("0020", Types.asFileEnding(0x0020));
+ assertEquals("0102", Types.asFileEnding(0x0102));
+ assertEquals("FEDC", Types.asFileEnding(0xfedc));
+ }
+}