From 7fc50ed9003e858c751731dbe715c09cae9c1e9f Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 23 Apr 2015 18:16:37 +0000 Subject: [PATCH] Pull out a common NPOIFS/POIFS test to a decidated bugs test class git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675696 13f79535-47bb-0310-9956-ffa450edef68 --- .../poifs/filesystem/TestFileSystemBugs.java | 66 +++++++++++++++++++ .../poifs/filesystem/TestPOIFSFileSystem.java | 41 ------------ 2 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java new file mode 100644 index 0000000000..cdd70c33ad --- /dev/null +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -0,0 +1,66 @@ +/* ==================================================================== + 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.poifs.filesystem; + +import java.util.Iterator; + +import junit.framework.TestCase; + +import org.apache.poi.POIDataSamples; + +/** + * Tests bugs across both POIFSFileSystem and NPOIFSFileSystem + */ +public final class TestFileSystemBugs extends TestCase { + /** + * Test that we can open files that come via Lotus notes. + * These have a top level directory without a name.... + */ + public void testNotesOLE2Files() throws Exception { + POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); + + // Open the file up + POIFSFileSystem fs = new POIFSFileSystem( + _samples.openResourceAsStream("Notes.ole2") + ); + + // Check the contents + assertEquals(1, fs.getRoot().getEntryCount()); + + Entry entry = fs.getRoot().getEntries().next(); + assertTrue(entry.isDirectoryEntry()); + assertTrue(entry instanceof DirectoryEntry); + + // The directory lacks a name! + DirectoryEntry dir = (DirectoryEntry)entry; + assertEquals("", dir.getName()); + + // Has two children + assertEquals(2, dir.getEntryCount()); + + // Check them + Iterator it = dir.getEntries(); + entry = it.next(); + assertEquals(true, entry.isDocumentEntry()); + assertEquals("\u0001Ole10Native", entry.getName()); + + entry = it.next(); + assertEquals(true, entry.isDocumentEntry()); + assertEquals("\u0001CompObj", entry.getName()); + } +} diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java index de5824efe2..bbb9b9db12 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java @@ -22,7 +22,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; -import java.util.Iterator; import junit.framework.TestCase; @@ -37,12 +36,9 @@ import org.apache.poi.poifs.storage.RawDataBlockList; /** * Tests for POIFSFileSystem - * - * @author Josh Micich */ public final class TestPOIFSFileSystem extends TestCase { private POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); - /** * Mock exception used to ensure correct error handling @@ -297,43 +293,6 @@ public final class TestPOIFSFileSystem extends TestCase { } } } - - /** - * Test that we can open files that come via Lotus notes. - * These have a top level directory without a name.... - */ - public void testNotesOLE2Files() throws Exception { - POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); - - // Open the file up - POIFSFileSystem fs = new POIFSFileSystem( - _samples.openResourceAsStream("Notes.ole2") - ); - - // Check the contents - assertEquals(1, fs.getRoot().getEntryCount()); - - Entry entry = fs.getRoot().getEntries().next(); - assertTrue(entry.isDirectoryEntry()); - assertTrue(entry instanceof DirectoryEntry); - - // The directory lacks a name! - DirectoryEntry dir = (DirectoryEntry)entry; - assertEquals("", dir.getName()); - - // Has two children - assertEquals(2, dir.getEntryCount()); - - // Check them - Iterator it = dir.getEntries(); - entry = it.next(); - assertEquals(true, entry.isDocumentEntry()); - assertEquals("\u0001Ole10Native", entry.getName()); - - entry = it.next(); - assertEquals(true, entry.isDocumentEntry()); - assertEquals("\u0001CompObj", entry.getName()); - } private static InputStream openSampleStream(String sampleFileName) { return HSSFTestDataSamples.openSampleFileStream(sampleFileName); -- 2.39.5