whitespace
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1739661 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ba64b65412
commit
1e07b01af3
@ -41,87 +41,87 @@ import org.junit.Test;
|
|||||||
* @author Nick Burch (nick at torchbox dot com)
|
* @author Nick Burch (nick at torchbox dot com)
|
||||||
*/
|
*/
|
||||||
public final class TestReWrite {
|
public final class TestReWrite {
|
||||||
// HSLFSlideShow primed on the test data
|
// HSLFSlideShow primed on the test data
|
||||||
private HSLFSlideShowImpl hssA;
|
private HSLFSlideShowImpl hssA;
|
||||||
private HSLFSlideShowImpl hssB;
|
private HSLFSlideShowImpl hssB;
|
||||||
private HSLFSlideShowImpl hssC;
|
private HSLFSlideShowImpl hssC;
|
||||||
// POIFS primed on the test data
|
// POIFS primed on the test data
|
||||||
private POIFSFileSystem pfsA;
|
private POIFSFileSystem pfsA;
|
||||||
private POIFSFileSystem pfsB;
|
private POIFSFileSystem pfsB;
|
||||||
private POIFSFileSystem pfsC;
|
private POIFSFileSystem pfsC;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
|
||||||
pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
pfsA = new POIFSFileSystem(slTests.openResourceAsStream("basic_test_ppt_file.ppt"));
|
||||||
hssA = new HSLFSlideShowImpl(pfsA);
|
hssA = new HSLFSlideShowImpl(pfsA);
|
||||||
|
|
||||||
pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
|
pfsB = new POIFSFileSystem(slTests.openResourceAsStream("ParagraphStylesShorterThanCharStyles.ppt"));
|
||||||
hssB = new HSLFSlideShowImpl(pfsB);
|
hssB = new HSLFSlideShowImpl(pfsB);
|
||||||
|
|
||||||
pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
|
pfsC = new POIFSFileSystem(slTests.openResourceAsStream("WithMacros.ppt"));
|
||||||
hssC = new HSLFSlideShowImpl(pfsC);
|
hssC = new HSLFSlideShowImpl(pfsC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWritesOutTheSame() throws Exception {
|
public void testWritesOutTheSame() throws Exception {
|
||||||
assertWritesOutTheSame(hssA, pfsA);
|
assertWritesOutTheSame(hssA, pfsA);
|
||||||
assertWritesOutTheSame(hssB, pfsB);
|
assertWritesOutTheSame(hssB, pfsB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
|
public void assertWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws Exception {
|
||||||
// Write out to a byte array
|
// Write out to a byte array
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
hss.write(baos);
|
hss.write(baos);
|
||||||
|
|
||||||
// Build an input stream of it
|
// Build an input stream of it
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
|
|
||||||
// Use POIFS to query that lot
|
// Use POIFS to query that lot
|
||||||
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
||||||
|
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
||||||
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
//System.out.println(i + "\t" + Integer.toHexString(i));
|
//System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
assertEquals(_oData[i], _nData[i]);
|
assertEquals(_oData[i], _nData[i]);
|
||||||
}
|
}
|
||||||
npfs.close();
|
npfs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithMacroStreams() throws IOException {
|
public void testWithMacroStreams() throws IOException {
|
||||||
// Check that they're apparently the same
|
// Check that they're apparently the same
|
||||||
assertSlideShowWritesOutTheSame(hssC, pfsC);
|
assertSlideShowWritesOutTheSame(hssC, pfsC);
|
||||||
|
|
||||||
// Currently has a Macros stream
|
// Currently has a Macros stream
|
||||||
assertNotNull( pfsC.getRoot().getEntry("Macros") );
|
assertNotNull( pfsC.getRoot().getEntry("Macros") );
|
||||||
|
|
||||||
// Write out normally, will loose the macro stream
|
// Write out normally, will loose the macro stream
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
hssC.write(baos);
|
hssC.write(baos);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
POIFSFileSystem pfsNew = new POIFSFileSystem(bais);
|
POIFSFileSystem pfsNew = new POIFSFileSystem(bais);
|
||||||
assertFalse(pfsNew.getRoot().hasEntry("Macros"));
|
assertFalse(pfsNew.getRoot().hasEntry("Macros"));
|
||||||
pfsNew.close();
|
pfsNew.close();
|
||||||
|
|
||||||
// But if we write out with nodes preserved, will be there
|
// But if we write out with nodes preserved, will be there
|
||||||
baos.reset();
|
baos.reset();
|
||||||
hssC.write(baos, true);
|
hssC.write(baos, true);
|
||||||
bais = new ByteArrayInputStream(baos.toByteArray());
|
bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
pfsNew = new POIFSFileSystem(bais);
|
pfsNew = new POIFSFileSystem(bais);
|
||||||
assertTrue( pfsNew.getRoot().hasEntry("Macros") );
|
assertTrue( pfsNew.getRoot().hasEntry("Macros") );
|
||||||
pfsNew.close();
|
pfsNew.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,62 +130,62 @@ public final class TestReWrite {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSlideShowWritesOutTheSame() throws Exception {
|
public void testSlideShowWritesOutTheSame() throws Exception {
|
||||||
assertSlideShowWritesOutTheSame(hssA, pfsA);
|
assertSlideShowWritesOutTheSame(hssA, pfsA);
|
||||||
|
|
||||||
// Some bug in StyleTextPropAtom rewriting means this will fail
|
// Some bug in StyleTextPropAtom rewriting means this will fail
|
||||||
// We need to identify and fix that first
|
// We need to identify and fix that first
|
||||||
//assertSlideShowWritesOutTheSame(hssB, pfsB);
|
//assertSlideShowWritesOutTheSame(hssB, pfsB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws IOException {
|
public void assertSlideShowWritesOutTheSame(HSLFSlideShowImpl hss, POIFSFileSystem pfs) throws IOException {
|
||||||
// Create a slideshow covering it
|
// Create a slideshow covering it
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
||||||
ss.getSlides();
|
ss.getSlides();
|
||||||
ss.getNotes();
|
ss.getNotes();
|
||||||
|
|
||||||
// Now write out to a byte array
|
// Now write out to a byte array
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
hss.write(baos);
|
hss.write(baos);
|
||||||
|
|
||||||
// Build an input stream of it
|
// Build an input stream of it
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
|
|
||||||
// Use POIFS to query that lot
|
// Use POIFS to query that lot
|
||||||
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
POIFSFileSystem npfs = new POIFSFileSystem(bais);
|
||||||
|
|
||||||
// Check that the "PowerPoint Document" sections have the same size
|
// Check that the "PowerPoint Document" sections have the same size
|
||||||
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry oProps = (DocumentEntry)pfs.getRoot().getEntry("PowerPoint Document");
|
||||||
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
DocumentEntry nProps = (DocumentEntry)npfs.getRoot().getEntry("PowerPoint Document");
|
||||||
assertEquals(oProps.getSize(),nProps.getSize());
|
assertEquals(oProps.getSize(),nProps.getSize());
|
||||||
|
|
||||||
// Check that they contain the same data
|
// Check that they contain the same data
|
||||||
byte[] _oData = new byte[oProps.getSize()];
|
byte[] _oData = new byte[oProps.getSize()];
|
||||||
byte[] _nData = new byte[nProps.getSize()];
|
byte[] _nData = new byte[nProps.getSize()];
|
||||||
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
pfs.createDocumentInputStream("PowerPoint Document").read(_oData);
|
||||||
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
npfs.createDocumentInputStream("PowerPoint Document").read(_nData);
|
||||||
for(int i=0; i<_oData.length; i++) {
|
for(int i=0; i<_oData.length; i++) {
|
||||||
if(_oData[i] != _nData[i])
|
if(_oData[i] != _nData[i])
|
||||||
System.out.println(i + "\t" + Integer.toHexString(i));
|
System.out.println(i + "\t" + Integer.toHexString(i));
|
||||||
assertEquals(_oData[i], _nData[i]);
|
assertEquals(_oData[i], _nData[i]);
|
||||||
}
|
}
|
||||||
npfs.close();
|
npfs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test48593() throws IOException {
|
public void test48593() throws IOException {
|
||||||
HSLFSlideShow ppt1 = new HSLFSlideShow();
|
HSLFSlideShow ppt1 = new HSLFSlideShow();
|
||||||
ppt1.createSlide();
|
ppt1.createSlide();
|
||||||
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
|
||||||
ppt2.createSlide();
|
ppt2.createSlide();
|
||||||
HSLFSlideShow ppt3 = HSLFTestDataSamples.writeOutAndReadBack(ppt2);
|
HSLFSlideShow ppt3 = HSLFTestDataSamples.writeOutAndReadBack(ppt2);
|
||||||
ppt3.createSlide();
|
ppt3.createSlide();
|
||||||
HSLFSlideShow ppt4 = HSLFTestDataSamples.writeOutAndReadBack(ppt3);
|
HSLFSlideShow ppt4 = HSLFTestDataSamples.writeOutAndReadBack(ppt3);
|
||||||
ppt4.createSlide();
|
ppt4.createSlide();
|
||||||
HSLFTestDataSamples.writeOutAndReadBack(ppt4).close();
|
HSLFTestDataSamples.writeOutAndReadBack(ppt4).close();
|
||||||
ppt4.close();
|
ppt4.close();
|
||||||
ppt3.close();
|
ppt3.close();
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
ppt1.close();
|
ppt1.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user