From b7827f268789f89cc8f729d7923580071589c07e Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 19 Mar 2006 15:59:43 +0000 Subject: [PATCH] Test for new Document record class git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@386982 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hslf/record/TestDocument.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java new file mode 100644 index 000000000..010e3ddc7 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestDocument.java @@ -0,0 +1,82 @@ + +/* ==================================================================== + Copyright 2002-2004 Apache Software Foundation + + Licensed 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.hslf.record; + + +import junit.framework.TestCase; +import java.io.*; + +import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.poifs.filesystem.*; + +/** + * Tests that Document works properly + * + * @author Nick Burch (nick at torchbox dot com) + */ +public class TestDocument extends TestCase { + // HSLFSlideShow primed on the test data + private HSLFSlideShow ss; + // POIFS primed on the test data + private POIFSFileSystem pfs; + + public TestDocument() throws Exception { + String dirname = System.getProperty("HSLF.testdata.path"); + String filename = dirname + "/basic_test_ppt_file.ppt"; + FileInputStream fis = new FileInputStream(filename); + pfs = new POIFSFileSystem(fis); + ss = new HSLFSlideShow(pfs); + } + + private Document getDocRecord() { + Record[] r = ss.getRecords(); + for(int i=(r.length-1); i>=0; i--) { + if(r[i] instanceof Document) { + return (Document)r[i]; + } + } + throw new IllegalStateException("No Document record found"); + } + + public void testRecordType() throws Exception { + Document dr = getDocRecord(); + assertEquals(1000, dr.getRecordType()); + } + + public void testChildRecords() throws Exception { + Document dr = getDocRecord(); + assertNotNull(dr.getDocumentAtom()); + assertTrue(dr.getDocumentAtom() instanceof DocumentAtom); + + assertNotNull(dr.getEnvironment()); + assertEquals(RecordTypes.Environment.typeID, dr.getEnvironment().getRecordType()); + + assertNotNull(dr.getSlideListWithTexts()); + assertEquals(3, dr.getSlideListWithTexts().length); + assertNotNull(dr.getSlideListWithTexts()[0]); + assertTrue(dr.getSlideListWithTexts()[0] instanceof SlideListWithText); + assertNotNull(dr.getSlideListWithTexts()[1]); + assertTrue(dr.getSlideListWithTexts()[1] instanceof SlideListWithText); + assertNotNull(dr.getSlideListWithTexts()[2]); + assertTrue(dr.getSlideListWithTexts()[2] instanceof SlideListWithText); + } + + // No need to check re-writing - hslf.TestReWrite does all that for us +}