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

TestReOrderingSlides

public class TestReOrderingSlides extends TestCase
Tests that SlideShow can re-order slides properly
author
Nick Burch (nick at torchbox dot com)

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

		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);
		
		filename = dirname + "/incorrect_slide_order.ppt";
		hss_three = new HSLFSlideShow(filename);
		ss_three = new SlideShow(hss_three);
	
public voidtestReOrder1()
Test that we can "re-order" a slideshow with only 1 slide on it

		// Has one slide
		assertEquals(1, ss_one.getSlides().length);
		Slide s1 = ss_one.getSlides()[0];
		
		// Check slide 1 is as expected
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		
		// Now move it to one
		ss_one.reorderSlide(1, 1);
				
		// 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 still has 1 slide
		assertEquals(1, ss_read.getSlides().length);
		
		// And check it's as expected
		s1 = ss_read.getSlides()[0];
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
	
public voidtestReOrder2()
Test doing a dummy re-order on a slideshow with two slides in it

		// 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());
		
		// Don't swap them around
		ss_two.reorderSlide(2, 2);
		
		// 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 still has 2 slides
		assertEquals(2, ss_read.getSlides().length);
		
		// And check it's as expected
		s1 = ss_read.getSlides()[0];
		s2 = ss_read.getSlides()[1];
		assertEquals(256, s1._getSheetNumber());
		assertEquals(4, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(257, s2._getSheetNumber());
		assertEquals(6, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
	
public voidtestReOrder2swap()
Test re-ordering slides in a slideshow with 2 slides on it

		// 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());
		
		// Swap them around
		ss_two.reorderSlide(2, 1);
		
		// 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 still has 2 slides
		assertEquals(2, ss_read.getSlides().length);
		
		// And check it's as expected
		s1 = ss_read.getSlides()[0];
		s2 = ss_read.getSlides()[1];
		assertEquals(257, s1._getSheetNumber());
		assertEquals(6, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(256, s2._getSheetNumber());
		assertEquals(4, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
	
public voidtestReOrder3()
Test doing a dummy re-order on a slideshow with three slides in it

		// Has three slides
		assertEquals(3, ss_three.getSlides().length);
		Slide s1 = ss_three.getSlides()[0];
		Slide s2 = ss_three.getSlides()[1];
		Slide s3 = ss_three.getSlides()[2];
		
		// Check slide 1 is as expected
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId()); // no notes on master
		assertEquals(1, s1.getSlideNumber());
		// Check slide 2 is as expected (was re-ordered from 3)
		assertEquals(258, s2._getSheetNumber());
		assertEquals(5, s2._getSheetRefId()); // no notes on slide
		assertEquals(2, s2.getSlideNumber());
		// Check slide 3 is as expected (was re-ordered from 2)
		assertEquals(257, s3._getSheetNumber());
		assertEquals(4, s3._getSheetRefId()); // no notes on slide
		assertEquals(3, s3.getSlideNumber());
		
		// Don't swap them around
		ss_three.reorderSlide(2, 2);
		
		// Write out, and read back in
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		hss_three.write(baos);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		
		HSLFSlideShow hss_read = new HSLFSlideShow(bais);
		SlideShow ss_read = new SlideShow(hss_read);
		
		// Check it still has 3 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(3, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(258, s2._getSheetNumber());
		assertEquals(5, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
		assertEquals(257, s3._getSheetNumber());
		assertEquals(4, s3._getSheetRefId());
		assertEquals(3, s3.getSlideNumber());
	
public voidtestReOrder3swap()
Test re-ordering slides in a slideshow with 3 slides on it

		// Has three slides
		assertEquals(3, ss_three.getSlides().length);
		Slide s1 = ss_three.getSlides()[0];
		Slide s2 = ss_three.getSlides()[1];
		Slide s3 = ss_three.getSlides()[2];
		
		// Check slide 1 is as expected
		assertEquals(256, s1._getSheetNumber());
		assertEquals(3, s1._getSheetRefId()); // no notes on master
		assertEquals(1, s1.getSlideNumber());
		// Check slide 2 is as expected (was re-ordered from 3)
		assertEquals(258, s2._getSheetNumber());
		assertEquals(5, s2._getSheetRefId()); // no notes on slide
		assertEquals(2, s2.getSlideNumber());
		// Check slide 3 is as expected (was re-ordered from 2)
		assertEquals(257, s3._getSheetNumber());
		assertEquals(4, s3._getSheetRefId()); // no notes on slide
		assertEquals(3, s3.getSlideNumber());
		
		// Put 3 in place of 1
		// (1 -> 2, 2 -> 3)
		ss_three.reorderSlide(3, 1);
		
		// Write out, and read back in
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		hss_three.write(baos);
		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		
		HSLFSlideShow hss_read = new HSLFSlideShow(bais);
		SlideShow ss_read = new SlideShow(hss_read);
		
		// Check it still has 3 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(257, s1._getSheetNumber());
		assertEquals(4, s1._getSheetRefId());
		assertEquals(1, s1.getSlideNumber());
		assertEquals(256, s2._getSheetNumber());
		assertEquals(3, s2._getSheetRefId());
		assertEquals(2, s2.getSlideNumber());
		assertEquals(258, s3._getSheetNumber());
		assertEquals(5, s3._getSheetRefId());
		assertEquals(3, s3.getSlideNumber());