]> source.dussan.org Git - poi.git/commitdiff
Tests for adding multiple slides
authorNick Burch <nick@apache.org>
Sun, 26 Mar 2006 17:37:36 +0000 (17:37 +0000)
committerNick Burch <nick@apache.org>
Sun, 26 Mar 2006 17:37:36 +0000 (17:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@388930 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java [new file with mode: 0644]

diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
new file mode 100644 (file)
index 0000000..a60c873
--- /dev/null
@@ -0,0 +1,123 @@
+/* ====================================================================\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