--- /dev/null
+/* ====================================================================\r
+ Copyright 2002-2004 Apache Software Foundation\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.hslf.model;\r
+\r
+import junit.framework.TestCase;\r
+import org.apache.poi.hslf.HSLFSlideShow;\r
+import org.apache.poi.hslf.usermodel.SlideShow;\r
+\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.ByteArrayInputStream;\r
+\r
+/**\r
+ * Test adding new slides to a ppt.\r
+ * \r
+ * Note - uses the same empty PPT file as the core "new Slideshow" \r
+ * stuff does\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TestSlides extends TestCase {\r
+\r
+ /**\r
+ * Add 1 slide to an empty ppt.\r
+ * @throws Exception\r
+ */\r
+ public void testAddSlides1() throws Exception {\r
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));\r
+ assertTrue(ppt.getSlides().length == 0);\r
+ ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 1);\r
+\r
+ //serialize and read again\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertTrue(ppt.getSlides().length == 1);\r
+ }\r
+\r
+ /**\r
+ * Add 2 slides to an empty ppt\r
+ * @throws Exception\r
+ */\r
+ public void testAddSlides2() throws Exception {\r
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));\r
+ assertTrue(ppt.getSlides().length == 0);\r
+ \r
+ Slide s1 = ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 1);\r
+ \r
+ Slide s2 = ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 2);\r
+\r
+ //serialize and read again\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertTrue(ppt.getSlides().length == 2);\r
+ }\r
+\r
+ /**\r
+ * Add 3 slides to an empty ppt\r
+ * @throws Exception\r
+ */\r
+ public void testAddSlides3() throws Exception {\r
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));\r
+ assertTrue(ppt.getSlides().length == 0);\r
+ \r
+ Slide s1 = ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 1);\r
+ \r
+ Slide s2 = ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 2);\r
+\r
+ Slide s3 = ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 3);\r
+\r
+ //serialize and read again\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertTrue(ppt.getSlides().length == 3);\r
+ }\r
+\r
+ /**\r
+ * Add slides to ppt which already has two slides\r
+ */\r
+ public void testAddSlides2to3() throws Exception {\r
+ String dirname = System.getProperty("HSLF.testdata.path");\r
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt"));\r
+ \r
+ assertTrue(ppt.getSlides().length == 2);\r
+ ppt.createSlide();\r
+ assertTrue(ppt.getSlides().length == 3);\r
+\r
+ //serialize and read again\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ ppt.write(out);\r
+ out.close();\r
+\r
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));\r
+ assertTrue(ppt.getSlides().length == 3);\r
+ }\r
+\r
+}\r