From: Nick Burch Date: Thu, 7 Jan 2010 16:47:09 +0000 (+0000) Subject: Shuffle where some of the HSMF tests live to better match package names, and stub... X-Git-Tag: REL_3_7_BETA1~163 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8b89688ddb2c098177e578ef653dd906964e1e11;p=poi.git Shuffle where some of the HSMF tests live to better match package names, and stub out a few more tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@896923 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 7bb482d7c4..6e6cee08cd 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -22,10 +22,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Map; import org.apache.poi.hsmf.datatypes.AttachmentChunks; -import org.apache.poi.hsmf.datatypes.Chunk; import org.apache.poi.hsmf.datatypes.ChunkGroup; import org.apache.poi.hsmf.datatypes.Chunks; import org.apache.poi.hsmf.datatypes.NameIdChunks; diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index c169e5f22f..c7ad005e74 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -37,10 +37,20 @@ public class AttachmentChunks implements ChunkGroup { public StringChunk attachFileName; public StringChunk attachLongFileName; public StringChunk attachMimeTag; + + /** + * What the POIFS name of this attachment is. + */ + private String poifsName; /** Holds all the chunks that were found. */ private List allChunks = new ArrayList(); + + public AttachmentChunks(String poifsName) { + this.poifsName = poifsName; + } + public Chunk[] getAll() { return allChunks.toArray(new Chunk[allChunks.size()]); } @@ -48,6 +58,10 @@ public class AttachmentChunks implements ChunkGroup { return getAll(); } + public String getPOIFSName() { + return poifsName; + } + /** * Called by the parser whenever a chunk is found. */ diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index 48bd7550a9..adbe1a7ac9 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -60,7 +60,7 @@ public final class POIFSChunkParser { // Do we know what to do with it? if(dir.getName().startsWith(AttachmentChunks.PREFIX)) { - group = new AttachmentChunks(); + group = new AttachmentChunks(dir.getName()); } if(dir.getName().startsWith(NameIdChunks.PREFIX)) { group = new NameIdChunks(); diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java b/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java index 81daab2f23..260b658fce 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/AllHSMFTests.java @@ -20,7 +20,8 @@ package org.apache.poi.hsmf; import junit.framework.Test; import junit.framework.TestSuite; -import org.apache.poi.hsmf.model.*; +import org.apache.poi.hsmf.datatypes.*; +import org.apache.poi.hsmf.parsers.*; public final class AllHSMFTests { @@ -29,9 +30,13 @@ public final class AllHSMFTests { suite.addTestSuite(TestBlankFileRead.class); suite.addTestSuite(TestSimpleFileRead.class); suite.addTestSuite(TestOutlook30FileRead.class); - suite.addTestSuite(TestChunkData.class); suite.addTestSuite(TestFileWithAttachmentsRead.class); + + suite.addTestSuite(TestChunkData.class); + suite.addTestSuite(TestTypes.class); + suite.addTestSuite(TestPOIFSChunkParser.class); + return suite; } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java new file mode 100644 index 0000000000..430c1b8e7a --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java @@ -0,0 +1,126 @@ +/* ==================================================================== + 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; + +import java.io.IOException; + +import org.apache.poi.hsmf.MAPIMessage; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.apache.poi.POIDataSamples; + +import junit.framework.TestCase; + + +/** + * Tests to verify that the library can read blank msg files. + * + * @author Travis Ferguson + * + */ +public final class TestBlankFileRead extends TestCase { + private MAPIMessage mapiMessage; + + /** + * Initialize this test, load up the blank.msg mapi message. + */ + public TestBlankFileRead() throws IOException { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); + } + + /** + * Check if we can read the body of the blank message, we expect "". + */ + public void testReadBody() { + try { + mapiMessage.getTextBody(); + } catch(ChunkNotFoundException exp) { + return; + } + + TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + } + + + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayCC(); + String expected = ""; + + TestCase.assertEquals(expected, obtained); + } + + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayTo() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayTo(); + String expected = ""; + + TestCase.assertEquals(expected, obtained); + } + + /** + * Test to see if we can read the FROM Chunk. + */ + public void testReadDisplayFrom() { + try { + mapiMessage.getDisplayFrom(); + } catch(ChunkNotFoundException exp) { + return; + } + + TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + } + + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayBCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayBCC(); + String expected = ""; + + TestCase.assertEquals(expected, obtained); + } + + + /** + * Check if we can read the subject line of the blank message, we expect "" + */ + public void testReadSubject() throws Exception { + String obtained = mapiMessage.getSubject(); + TestCase.assertEquals("", obtained); + } + + + /** + * Check if we can read the subject line of the blank message, we expect "" + */ + public void testReadConversationTopic() { + try { + mapiMessage.getConversationTopic(); + } catch(ChunkNotFoundException exp) { + return; + } + TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file."); + } + + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java new file mode 100644 index 0000000000..c3fcda741f --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestFileWithAttachmentsRead.java @@ -0,0 +1,85 @@ +/* ==================================================================== + 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; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Iterator; +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; + +/** + * Tests to verify that we can read attachments from msg file + * + * @author Nicolas Bureau + */ +public class TestFileWithAttachmentsRead extends TestCase { + private MAPIMessage mapiMessage; + + /** + * Initialize this test, load up the attachment_test_msg.msg mapi message. + * + * @throws Exception + */ + public TestFileWithAttachmentsRead() throws IOException { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg")); + } + + /** + * Test to see if we can retrieve attachments. + * + * @throws ChunkNotFoundException + * + */ + // public void testReadDisplayCC() throws ChunkNotFoundException { + public void testRetrieveAttachments() { + AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles(); + int obtained = attachments.length; + int expected = 2; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if attachments are not empty. + * + * @throws ChunkNotFoundException + * + */ + public void testReadAttachments() throws IOException { + AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles(); + + 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/TestOutlook30FileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java new file mode 100644 index 0000000000..113a214eb0 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java @@ -0,0 +1,136 @@ +/* ==================================================================== + 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; + +import java.io.IOException; + +import org.apache.poi.hsmf.MAPIMessage; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.apache.poi.POIDataSamples; + +import junit.framework.TestCase; + +/** + * Tests to verify that we can still work on the newer Outlook 3.0 files. + */ +public final class TestOutlook30FileRead extends TestCase { +private MAPIMessage mapiMessage; + + /** + * Initialize this test, load up the blank.msg mapi message. + * @throws Exception + */ + public TestOutlook30FileRead() throws IOException { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayCC(); + String expected = ""; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayTo() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayTo(); + + assertTrue(obtained.startsWith("Bohn, Shawn")); + } + + /** + * Test to see if we can read the From Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayFrom() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayFrom(); + String expected = "Cramer, Nick"; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayBCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayBCC(); + String expected = ""; + + TestCase.assertEquals(obtained, expected); + } + + + /** + * Check if we can read the body of the blank message, we expect "". + * + * @throws Exception + */ + public void testReadBody() throws Exception { + String obtained = mapiMessage.getTextBody(); + assertTrue(obtained.startsWith("I am shutting down")); + } + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadSubject() throws Exception { + String obtained = mapiMessage.getSubject(); + String expected = "IN-SPIRE servers going down for a bit, back up around 8am"; + + TestCase.assertEquals(expected, obtained); + } + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadConversationTopic() throws Exception { + String obtained = mapiMessage.getConversationTopic(); + TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); + } + + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadMessageClass() throws Exception { + String obtained = mapiMessage.getMessageClass(); + TestCase.assertEquals("IPM.Note", obtained); + } + + + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java new file mode 100644 index 0000000000..3f261f4d8f --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestSimpleFileRead.java @@ -0,0 +1,142 @@ +/* ==================================================================== + 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; + +import java.io.IOException; + +import org.apache.poi.hsmf.MAPIMessage; +import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; +import org.apache.poi.POIDataSamples; + +import junit.framework.TestCase; + +/** + * Tests to verify that we can read a simple msg file, that is in plain/text format with no attachments + * or extra recipents. + * + * @author Travis Ferguson + */ +public final class TestSimpleFileRead extends TestCase { +private MAPIMessage mapiMessage; + + /** + * Initialize this test, load up the blank.msg mapi message. + * @throws Exception + */ + public TestSimpleFileRead() throws IOException { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg")); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayCC(); + String expected = ""; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayTo() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayTo(); + String expected = "travis@overwrittenstack.com"; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if we can read the From Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayFrom() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayFrom(); + String expected = "Travis Ferguson"; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayBCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayBCC(); + String expected = ""; + + TestCase.assertEquals(obtained, expected); + } + + + /** + * Check if we can read the body of the blank message, we expect "". + * + * @throws Exception + */ + public void testReadBody() throws Exception { + String obtained = mapiMessage.getTextBody(); + String expected = "This is a test message."; + + TestCase.assertEquals(obtained, expected); + } + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadSubject() throws Exception { + String obtained = mapiMessage.getSubject(); + String expected = "test message"; + + TestCase.assertEquals(expected, obtained); + } + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadConversationTopic() throws Exception { + String obtained = mapiMessage.getConversationTopic(); + TestCase.assertEquals("test message", obtained); + } + + + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadMessageClass() throws Exception { + String obtained = mapiMessage.getMessageClass(); + TestCase.assertEquals("IPM.Note", obtained); + } + + + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java new file mode 100644 index 0000000000..39440d13b6 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestChunkData.java @@ -0,0 +1,85 @@ +/* ==================================================================== + 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.datatypes; + +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; + +/** + * Verifies that the Chunks class is actually setup properly and hasn't been changed in ways + * that will break the library. + * + * @author Travis Ferguson + * + */ +public final class TestChunkData extends TestCase { + public void testChunkCreate() { + 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, 0x001E); + assertEquals("__substg1.0_0000001E", chunk.getEntryName()); + + chunk = new StringChunk(0xFFFF, 0x001E); + assertEquals("__substg1.0_FFFF001E", chunk.getEntryName()); + + chunk = new StringChunk(0xFFFF, 0x001F); + assertEquals("__substg1.0_FFFF001F", chunk.getEntryName()); + } + + public void testTextBodyChunk() { + StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING); + assertEquals(chunk.getChunkId(), Chunks.TEXT_BODY); + } + + public void testDisplayToChunk() { + StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING); + assertEquals(chunk.getChunkId(), Chunks.DISPLAY_TO); + } + + + public void testDisplayCCChunk() { + StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING); + assertEquals(chunk.getChunkId(), Chunks.DISPLAY_CC); + } + + public void testDisplayBCCChunk() { + StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING); + assertEquals(chunk.getChunkId(), Chunks.DISPLAY_BCC); + } + + public void testSubjectChunk() { + Chunk chunk = new StringChunk(0x0037, Types.UNICODE_STRING); + assertEquals(chunk.getChunkId(), Chunks.SUBJECT); + } + +} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/TestTypes.java new file mode 100644 index 0000000000..0a2de38ac3 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/datatypes/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.datatypes; + +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)); + } +} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java deleted file mode 100644 index fb21c5e86e..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestBlankFileRead.java +++ /dev/null @@ -1,126 +0,0 @@ -/* ==================================================================== - 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 java.io.IOException; - -import org.apache.poi.hsmf.MAPIMessage; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; -import org.apache.poi.POIDataSamples; - -import junit.framework.TestCase; - - -/** - * Tests to verify that the library can read blank msg files. - * - * @author Travis Ferguson - * - */ -public final class TestBlankFileRead extends TestCase { - private MAPIMessage mapiMessage; - - /** - * Initialize this test, load up the blank.msg mapi message. - */ - public TestBlankFileRead() throws IOException { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); - } - - /** - * Check if we can read the body of the blank message, we expect "". - */ - public void testReadBody() { - try { - mapiMessage.getTextBody(); - } catch(ChunkNotFoundException exp) { - return; - } - - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); - } - - - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayCC(); - String expected = ""; - - TestCase.assertEquals(expected, obtained); - } - - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayTo() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayTo(); - String expected = ""; - - TestCase.assertEquals(expected, obtained); - } - - /** - * Test to see if we can read the FROM Chunk. - */ - public void testReadDisplayFrom() { - try { - mapiMessage.getDisplayFrom(); - } catch(ChunkNotFoundException exp) { - return; - } - - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); - } - - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayBCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayBCC(); - String expected = ""; - - TestCase.assertEquals(expected, obtained); - } - - - /** - * Check if we can read the subject line of the blank message, we expect "" - */ - public void testReadSubject() throws Exception { - String obtained = mapiMessage.getSubject(); - TestCase.assertEquals("", obtained); - } - - - /** - * Check if we can read the subject line of the blank message, we expect "" - */ - public void testReadConversationTopic() { - try { - mapiMessage.getConversationTopic(); - } catch(ChunkNotFoundException exp) { - return; - } - TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file."); - } - - -} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java deleted file mode 100644 index 6a9fae44e2..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestChunkData.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ==================================================================== - 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.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; - -/** - * Verifies that the Chunks class is actually setup properly and hasn't been changed in ways - * that will break the library. - * - * @author Travis Ferguson - * - */ -public final class TestChunkData extends TestCase { - public void testChunkCreate() { - 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, 0x001E); - assertEquals("__substg1.0_0000001E", chunk.getEntryName()); - - chunk = new StringChunk(0xFFFF, 0x001E); - assertEquals("__substg1.0_FFFF001E", chunk.getEntryName()); - - chunk = new StringChunk(0xFFFF, 0x001F); - assertEquals("__substg1.0_FFFF001F", chunk.getEntryName()); - } - - public void testTextBodyChunk() { - StringChunk chunk = new StringChunk(0x1000, Types.UNICODE_STRING); - assertEquals(chunk.getChunkId(), Chunks.TEXT_BODY); - } - - public void testDisplayToChunk() { - StringChunk chunk = new StringChunk(0x0E04, Types.UNICODE_STRING); - assertEquals(chunk.getChunkId(), Chunks.DISPLAY_TO); - } - - - public void testDisplayCCChunk() { - StringChunk chunk = new StringChunk(0x0E03, Types.UNICODE_STRING); - assertEquals(chunk.getChunkId(), Chunks.DISPLAY_CC); - } - - public void testDisplayBCCChunk() { - StringChunk chunk = new StringChunk(0x0E02, Types.UNICODE_STRING); - assertEquals(chunk.getChunkId(), Chunks.DISPLAY_BCC); - } - - public void testSubjectChunk() { - 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 deleted file mode 100644 index 8762ef415c..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestFileWithAttachmentsRead.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ==================================================================== - 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 java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Iterator; -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; - -/** - * Tests to verify that we can read attachments from msg file - * - * @author Nicolas Bureau - */ -public class TestFileWithAttachmentsRead extends TestCase { - private MAPIMessage mapiMessage; - - /** - * Initialize this test, load up the attachment_test_msg.msg mapi message. - * - * @throws Exception - */ - public TestFileWithAttachmentsRead() throws IOException { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg")); - } - - /** - * Test to see if we can retrieve attachments. - * - * @throws ChunkNotFoundException - * - */ - // public void testReadDisplayCC() throws ChunkNotFoundException { - public void testRetrieveAttachments() { - AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles(); - int obtained = attachments.length; - int expected = 2; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if attachments are not empty. - * - * @throws ChunkNotFoundException - * - */ - public void testReadAttachments() throws IOException { - AttachmentChunks[] attachments = mapiMessage.getAttachmentFiles(); - - 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/TestOutlook30FileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestOutlook30FileRead.java deleted file mode 100644 index 12cc44c42b..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestOutlook30FileRead.java +++ /dev/null @@ -1,136 +0,0 @@ -/* ==================================================================== - 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 java.io.IOException; - -import org.apache.poi.hsmf.MAPIMessage; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; -import org.apache.poi.POIDataSamples; - -import junit.framework.TestCase; - -/** - * Tests to verify that we can still work on the newer Outlook 3.0 files. - */ -public final class TestOutlook30FileRead extends TestCase { -private MAPIMessage mapiMessage; - - /** - * Initialize this test, load up the blank.msg mapi message. - * @throws Exception - */ - public TestOutlook30FileRead() throws IOException { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayCC(); - String expected = ""; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayTo() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayTo(); - - assertTrue(obtained.startsWith("Bohn, Shawn")); - } - - /** - * Test to see if we can read the From Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayFrom() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayFrom(); - String expected = "Cramer, Nick"; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayBCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayBCC(); - String expected = ""; - - TestCase.assertEquals(obtained, expected); - } - - - /** - * Check if we can read the body of the blank message, we expect "". - * - * @throws Exception - */ - public void testReadBody() throws Exception { - String obtained = mapiMessage.getTextBody(); - assertTrue(obtained.startsWith("I am shutting down")); - } - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadSubject() throws Exception { - String obtained = mapiMessage.getSubject(); - String expected = "IN-SPIRE servers going down for a bit, back up around 8am"; - - TestCase.assertEquals(expected, obtained); - } - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadConversationTopic() throws Exception { - String obtained = mapiMessage.getConversationTopic(); - TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); - } - - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadMessageClass() throws Exception { - String obtained = mapiMessage.getMessageClass(); - TestCase.assertEquals("IPM.Note", obtained); - } - - - -} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java deleted file mode 100644 index 672d94e8ff..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestSimpleFileRead.java +++ /dev/null @@ -1,142 +0,0 @@ -/* ==================================================================== - 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 java.io.IOException; - -import org.apache.poi.hsmf.MAPIMessage; -import org.apache.poi.hsmf.exceptions.ChunkNotFoundException; -import org.apache.poi.POIDataSamples; - -import junit.framework.TestCase; - -/** - * Tests to verify that we can read a simple msg file, that is in plain/text format with no attachments - * or extra recipents. - * - * @author Travis Ferguson - */ -public final class TestSimpleFileRead extends TestCase { -private MAPIMessage mapiMessage; - - /** - * Initialize this test, load up the blank.msg mapi message. - * @throws Exception - */ - public TestSimpleFileRead() throws IOException { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg")); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayCC(); - String expected = ""; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayTo() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayTo(); - String expected = "travis@overwrittenstack.com"; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if we can read the From Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayFrom() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayFrom(); - String expected = "Travis Ferguson"; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayBCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayBCC(); - String expected = ""; - - TestCase.assertEquals(obtained, expected); - } - - - /** - * Check if we can read the body of the blank message, we expect "". - * - * @throws Exception - */ - public void testReadBody() throws Exception { - String obtained = mapiMessage.getTextBody(); - String expected = "This is a test message."; - - TestCase.assertEquals(obtained, expected); - } - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadSubject() throws Exception { - String obtained = mapiMessage.getSubject(); - String expected = "test message"; - - TestCase.assertEquals(expected, obtained); - } - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadConversationTopic() throws Exception { - String obtained = mapiMessage.getConversationTopic(); - TestCase.assertEquals("test message", obtained); - } - - - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadMessageClass() throws Exception { - String obtained = mapiMessage.getMessageClass(); - TestCase.assertEquals("IPM.Note", obtained); - } - - - -} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java b/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java deleted file mode 100644 index 2b99af5309..0000000000 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/model/TestTypes.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ==================================================================== - 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)); - } -} diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java new file mode 100644 index 0000000000..06bc5f9e30 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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.parsers; + +import java.io.FileInputStream; +import java.io.IOException; + +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.POIDataSamples; + +import junit.framework.TestCase; + +/** + * Tests to verify that the chunk parser works properly + */ +public final class TestPOIFSChunkParser extends TestCase { + private POIDataSamples samples; + + public TestPOIFSChunkParser() throws IOException { + samples = POIDataSamples.getHSMFInstance(); + } + + public void testFindsRecips() throws IOException { + + } + + public void testFindsAttachments() throws IOException { + POIFSFileSystem with = new POIFSFileSystem( + new FileInputStream(samples.getFile("attachment_test_msg.msg")) + ); + POIFSFileSystem without = new POIFSFileSystem( + new FileInputStream(samples.getFile("simple_test_msg.msg")) + ); + + // Check details on the one with + + // One with, from the top + + // One without, from the top + } +}