FileDocCategorySizeDatePackage
TestAddingSlides.javaAPI DocApache Poi 3.0.16679Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hslf.usermodel

TestAddingSlides

public class TestAddingSlides extends TestCase
Tests that SlideShow adds additional sheets properly
author
Nick Burch (nick at torchbox dot com)

Fields Summary
private HSLFSlideShow
hss_empty
private SlideShow
ss_empty
private HSLFSlideShow
hss_one
private SlideShow
ss_one
private HSLFSlideShow
hss_two
private SlideShow
ss_two
Constructors Summary
Methods Summary
public voidsetUp()
Create/open the slideshows

		hss_empty = new HSLFSlideShow();
		ss_empty = new SlideShow(hss_empty);
		
		String dirname = System.getProperty("HSLF.testdata.path");
		
		String filename = dirname + "/Single_Coloured_Page.ppt";
		hss_one = new HSLFSlideShow(filename);
		ss_one = new SlideShow(hss_one);
		
		filename = dirname + "/basic_test_ppt_file.ppt";
		hss_two = new HSLFSlideShow(filename);
		ss_two = new SlideShow(hss_two);
	
public voidtestAddSlideToEmpty()
Test adding a slide to an empty slideshow

		// Doesn't have any slides
		assertEquals(0, ss_empty.getSlides().length);
		
		// Should only have a master SLWT
		assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
		
		// Add one
		Slide slide = ss_empty.createSlide();
		assertEquals(1, ss_empty.getSlides().length);
		assertEquals(256, slide._getSheetNumber());
		assertEquals(3, slide._getSheetRefId());
		assertEquals(1, slide.getSlideNumber());
		
		// Write out, and read back in
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		hss_empty.write(baos);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		
		HSLFSlideShow hss_read = new HSLFSlideShow(bais);
		SlideShow ss_read = new SlideShow(hss_read);
		
		// Check it now has a slide
		assertEquals(1, ss_read.getSlides().length);

		// Check it now has two SLWTs
		assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
		
		// And check it's as expected
		slide = ss_read.getSlides()[0];
		assertEquals(256, slide._getSheetNumber());
		assertEquals(3, slide._getSheetRefId());
		assertEquals(1, slide.getSlideNumber());
	
public voidtestAddSlideToExisting()
Test adding a slide to an existing slideshow

		// Has one slide
		assertEquals(1, ss_one.getSlides().length);
		Slide s1 = ss_one.getSlides()[0];
		
		// Should have two SLTWs
		assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
		
		// Check slide 1 is as expected
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		
		// Add a second one
		Slide s2 = ss_one.createSlide();
		assertEquals(2, ss_one.getSlides().length);
		assertEquals(257, s2._getSheetNumber());
		assertEquals(4, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
		
		// Write out, and read back in
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		hss_one.write(baos);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		
		HSLFSlideShow hss_read = new HSLFSlideShow(bais);
		SlideShow ss_read = new SlideShow(hss_read);
		
		// Check it now has two slides
		assertEquals(2, ss_read.getSlides().length);
		
		// Should still have two SLTWs
		assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
		
		// And check it's as expected
		s1 = ss_read.getSlides()[0];
		s2 = ss_read.getSlides()[1];
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(257, s2._getSheetNumber());
		assertEquals(4, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
	
public voidtestAddSlideToExisting2()
Test adding a slide to an existing slideshow, with two slides already

		// Has two slides
		assertEquals(2, ss_two.getSlides().length);
		Slide s1 = ss_two.getSlides()[0];
		Slide s2 = ss_two.getSlides()[1];
		
		// Check slide 1 is as expected
		assertEquals(256, s1._getSheetNumber());
		assertEquals(4, s1._getSheetRefId()); // master has notes
		assertEquals(1, s1.getSlideNumber());
		// Check slide 2 is as expected
		assertEquals(257, s2._getSheetNumber());
		assertEquals(6, s2._getSheetRefId()); // master and 1 have notes
		assertEquals(2, s2.getSlideNumber());
		
		// Add a third one
		Slide s3 = ss_two.createSlide();
		assertEquals(3, ss_two.getSlides().length);
		assertEquals(258, s3._getSheetNumber());
		assertEquals(8, s3._getSheetRefId()); // lots of notes before us
		assertEquals(3, s3.getSlideNumber());
		
		// Write out, and read back in
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		hss_two.write(baos);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		
		HSLFSlideShow hss_read = new HSLFSlideShow(bais);
		SlideShow ss_read = new SlideShow(hss_read);
		
		// Check it now has three slides
		assertEquals(3, ss_read.getSlides().length);
		
		// And check it's as expected
		s1 = ss_read.getSlides()[0];
		s2 = ss_read.getSlides()[1];
		s3 = ss_read.getSlides()[2];
		assertEquals(256, s1._getSheetNumber());
		assertEquals(4, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(257, s2._getSheetNumber());
		assertEquals(6, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
		assertEquals(258, s3._getSheetNumber());
		assertEquals(8, s3._getSheetRefId());
		assertEquals(3, s3.getSlideNumber());