From 66d1f0d1e2a12f8968e2d5f628a35d07013ec981 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 12 Apr 2006 16:31:34 +0000 Subject: [PATCH] Add a check that just opening a usermodel slidesheet on it doesn't break things git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@393497 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/TestReWrite.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java index c671220ca7..01410a9bfa 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWrite.java @@ -22,6 +22,8 @@ package org.apache.poi.hslf; import junit.framework.TestCase; import java.io.*; + +import org.apache.poi.hslf.usermodel.SlideShow; import org.apache.poi.poifs.filesystem.*; /** @@ -32,22 +34,56 @@ import org.apache.poi.poifs.filesystem.*; */ public class TestReWrite extends TestCase { // HSLFSlideShow primed on the test data - private HSLFSlideShow ss; + private HSLFSlideShow hss; // POIFS primed on the test data private POIFSFileSystem pfs; - public TestReWrite() throws Exception { + public void setUp() 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); + hss = new HSLFSlideShow(pfs); } public void testWritesOutTheSame() throws Exception { // Write out to a byte array ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ss.write(baos); + hss.write(baos); + + // Build an input stream of it + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + + // Use POIFS to query that lot + POIFSFileSystem npfs = new POIFSFileSystem(bais); + + // Check that the "PowerPoint Document" sections have the same size + DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document"); + DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document"); + assertEquals(oProps.getSize(),nProps.getSize()); + + // Check that they contain the same data + byte[] _oData = new byte[oProps.getSize()]; + byte[] _nData = new byte[nProps.getSize()]; + pfs.createDocumentInputStream("PowerPoint Document").read(_oData); + npfs.createDocumentInputStream("PowerPoint Document").read(_nData); + for(int i=0; i<_oData.length; i++) { + System.out.println(i + "\t" + Integer.toHexString(i)); + assertEquals(_oData[i], _nData[i]); + } + } + + /** + * Ensure that simply opening a slideshow (usermodel) view of it + * doesn't change things + */ + public void testSlideShowWritesOutTheSame() throws Exception { + // Create a slideshow covering it + SlideShow ss = new SlideShow(hss); + + // Now write out to a byte array + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + hss.write(baos); // Build an input stream of it ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); -- 2.39.5