aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/testcases/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/scratchpad/testcases/org/apache')
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java364
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java176
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java166
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java452
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java366
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java788
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java182
7 files changed, 1247 insertions, 1247 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
index 0c36150e96..84eafaa4fd 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java
@@ -1,182 +1,182 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import junit.framework.TestCase;
-
-import java.io.*;
-import java.awt.*;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.HSLFSlideShow;
-
-/**
- * Test <code>Fill</code> object.
- *
- * @author Yegor Kozlov
- */
-public class TestBackground extends TestCase {
-
- /**
- * Default background for slide, shape and slide master.
- */
- public void testDefaults() throws Exception {
- SlideShow ppt = new SlideShow();
-
- assertEquals(Fill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
-
- Slide slide = ppt.createSlide();
- assertTrue(slide.getFollowMasterBackground());
- assertEquals(Fill.FILL_SOLID, slide.getBackground().getFill().getFillType());
-
- Shape shape = new AutoShape(ShapeTypes.Rectangle);
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
- }
-
- /**
- * Read fill information from an reference ppt file
- */
- public void testReadBackground() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/backgrounds.ppt"));
- Fill fill;
- Shape shape;
-
- Slide[] slide = ppt.getSlides();
-
- fill = slide[0].getBackground().getFill();
- assertEquals(Fill.FILL_PICTURE, fill.getFillType());
- shape = slide[0].getShapes()[0];
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
-
- fill = slide[1].getBackground().getFill();
- assertEquals(Fill.FILL_PATTERN, fill.getFillType());
- shape = slide[1].getShapes()[0];
- assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
-
- fill = slide[2].getBackground().getFill();
- assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
- shape = slide[2].getShapes()[0];
- assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
-
- fill = slide[3].getBackground().getFill();
- assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
- shape = slide[3].getShapes()[0];
- assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
- }
-
- /**
- * Create a ppt with various fill effects
- */
- public void testBackgroundPicture() throws Exception {
- SlideShow ppt = new SlideShow();
- Slide slide;
- Fill fill;
- Shape shape;
- int idx;
-
- //slide 1
- slide = ppt.createSlide();
- slide.setFollowMasterBackground(false);
- fill = slide.getBackground().getFill();
- idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PICTURE);
- fill.setPictureData(idx);
-
- shape = new AutoShape(ShapeTypes.Rectangle);
- shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
- fill = shape.getFill();
- fill.setFillType(Fill.FILL_SOLID);
- slide.addShape(shape);
-
- //slide 2
- slide = ppt.createSlide();
- slide.setFollowMasterBackground(false);
- fill = slide.getBackground().getFill();
- idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PATTERN);
- fill.setPictureData(idx);
- fill.setBackgroundColor(Color.green);
- fill.setForegroundColor(Color.red);
-
- shape = new AutoShape(ShapeTypes.Rectangle);
- shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
- fill = shape.getFill();
- fill.setFillType(Fill.FILL_BACKGROUND);
- slide.addShape(shape);
-
- //slide 3
- slide = ppt.createSlide();
- slide.setFollowMasterBackground(false);
- fill = slide.getBackground().getFill();
- idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_TEXTURE);
- fill.setPictureData(idx);
-
- shape = new AutoShape(ShapeTypes.Rectangle);
- shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
- fill = shape.getFill();
- fill.setFillType(Fill.FILL_PICTURE);
- idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/clock.jpg"), Picture.JPEG);
- fill.setPictureData(idx);
- slide.addShape(shape);
-
- // slide 4
- slide = ppt.createSlide();
- slide.setFollowMasterBackground(false);
- fill = slide.getBackground().getFill();
- fill.setFillType(Fill.FILL_SHADE_CENTER);
- fill.setBackgroundColor(Color.white);
- fill.setForegroundColor(Color.darkGray);
-
- shape = new AutoShape(ShapeTypes.Rectangle);
- shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
- fill = shape.getFill();
- fill.setFillType(Fill.FILL_SHADE);
- fill.setBackgroundColor(Color.red);
- fill.setForegroundColor(Color.green);
- slide.addShape(shape);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- Slide[] slides = ppt.getSlides();
-
- fill = slides[0].getBackground().getFill();
- assertEquals(Fill.FILL_PICTURE, fill.getFillType());
- shape = slides[0].getShapes()[0];
- assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
-
- fill = slides[1].getBackground().getFill();
- assertEquals(Fill.FILL_PATTERN, fill.getFillType());
- shape = slides[1].getShapes()[0];
- assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
-
- fill = slides[2].getBackground().getFill();
- assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
- shape = slides[2].getShapes()[0];
- assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
-
- fill = slides[3].getBackground().getFill();
- assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
- shape = slides[3].getShapes()[0];
- assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
-
- }
-
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.awt.*;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+/**
+ * Test <code>Fill</code> object.
+ *
+ * @author Yegor Kozlov
+ */
+public class TestBackground extends TestCase {
+
+ /**
+ * Default background for slide, shape and slide master.
+ */
+ public void testDefaults() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ assertEquals(Fill.FILL_SOLID, ppt.getSlidesMasters()[0].getBackground().getFill().getFillType());
+
+ Slide slide = ppt.createSlide();
+ assertTrue(slide.getFollowMasterBackground());
+ assertEquals(Fill.FILL_SOLID, slide.getBackground().getFill().getFillType());
+
+ Shape shape = new AutoShape(ShapeTypes.Rectangle);
+ assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+ }
+
+ /**
+ * Read fill information from an reference ppt file
+ */
+ public void testReadBackground() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(System.getProperty("HSLF.testdata.path") + "/backgrounds.ppt"));
+ Fill fill;
+ Shape shape;
+
+ Slide[] slide = ppt.getSlides();
+
+ fill = slide[0].getBackground().getFill();
+ assertEquals(Fill.FILL_PICTURE, fill.getFillType());
+ shape = slide[0].getShapes()[0];
+ assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+
+ fill = slide[1].getBackground().getFill();
+ assertEquals(Fill.FILL_PATTERN, fill.getFillType());
+ shape = slide[1].getShapes()[0];
+ assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
+
+ fill = slide[2].getBackground().getFill();
+ assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
+ shape = slide[2].getShapes()[0];
+ assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
+
+ fill = slide[3].getBackground().getFill();
+ assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
+ shape = slide[3].getShapes()[0];
+ assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
+ }
+
+ /**
+ * Create a ppt with various fill effects
+ */
+ public void testBackgroundPicture() throws Exception {
+ SlideShow ppt = new SlideShow();
+ Slide slide;
+ Fill fill;
+ Shape shape;
+ int idx;
+
+ //slide 1
+ slide = ppt.createSlide();
+ slide.setFollowMasterBackground(false);
+ fill = slide.getBackground().getFill();
+ idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
+ fill.setFillType(Fill.FILL_PICTURE);
+ fill.setPictureData(idx);
+
+ shape = new AutoShape(ShapeTypes.Rectangle);
+ shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
+ fill = shape.getFill();
+ fill.setFillType(Fill.FILL_SOLID);
+ slide.addShape(shape);
+
+ //slide 2
+ slide = ppt.createSlide();
+ slide.setFollowMasterBackground(false);
+ fill = slide.getBackground().getFill();
+ idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
+ fill.setFillType(Fill.FILL_PATTERN);
+ fill.setPictureData(idx);
+ fill.setBackgroundColor(Color.green);
+ fill.setForegroundColor(Color.red);
+
+ shape = new AutoShape(ShapeTypes.Rectangle);
+ shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
+ fill = shape.getFill();
+ fill.setFillType(Fill.FILL_BACKGROUND);
+ slide.addShape(shape);
+
+ //slide 3
+ slide = ppt.createSlide();
+ slide.setFollowMasterBackground(false);
+ fill = slide.getBackground().getFill();
+ idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/tomcat.png"), Picture.PNG);
+ fill.setFillType(Fill.FILL_TEXTURE);
+ fill.setPictureData(idx);
+
+ shape = new AutoShape(ShapeTypes.Rectangle);
+ shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
+ fill = shape.getFill();
+ fill.setFillType(Fill.FILL_PICTURE);
+ idx = ppt.addPicture(new File(System.getProperty("HSLF.testdata.path") + "/clock.jpg"), Picture.JPEG);
+ fill.setPictureData(idx);
+ slide.addShape(shape);
+
+ // slide 4
+ slide = ppt.createSlide();
+ slide.setFollowMasterBackground(false);
+ fill = slide.getBackground().getFill();
+ fill.setFillType(Fill.FILL_SHADE_CENTER);
+ fill.setBackgroundColor(Color.white);
+ fill.setForegroundColor(Color.darkGray);
+
+ shape = new AutoShape(ShapeTypes.Rectangle);
+ shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
+ fill = shape.getFill();
+ fill.setFillType(Fill.FILL_SHADE);
+ fill.setBackgroundColor(Color.red);
+ fill.setForegroundColor(Color.green);
+ slide.addShape(shape);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ Slide[] slides = ppt.getSlides();
+
+ fill = slides[0].getBackground().getFill();
+ assertEquals(Fill.FILL_PICTURE, fill.getFillType());
+ shape = slides[0].getShapes()[0];
+ assertEquals(Fill.FILL_SOLID, shape.getFill().getFillType());
+
+ fill = slides[1].getBackground().getFill();
+ assertEquals(Fill.FILL_PATTERN, fill.getFillType());
+ shape = slides[1].getShapes()[0];
+ assertEquals(Fill.FILL_BACKGROUND, shape.getFill().getFillType());
+
+ fill = slides[2].getBackground().getFill();
+ assertEquals(Fill.FILL_TEXTURE, fill.getFillType());
+ shape = slides[2].getShapes()[0];
+ assertEquals(Fill.FILL_PICTURE, shape.getFill().getFillType());
+
+ fill = slides[3].getBackground().getFill();
+ assertEquals(Fill.FILL_SHADE_CENTER, fill.getFillType());
+ shape = slides[3].getShapes()[0];
+ assertEquals(Fill.FILL_SHADE, shape.getFill().getFillType());
+
+ }
+
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
index 2b7d6cc601..c5bb16e4f1 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPPGraphics2D.java
@@ -1,88 +1,88 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.HSLFSlideShow;
-
-import java.awt.*;
-import java.awt.Rectangle;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-
-/**
- * Test drawing shapes via Graphics2D
- *
- * @author Yegor Kozlov
- */
-public class TestPPGraphics2D extends TestCase {
- private SlideShow ppt;
-
- protected void setUp() throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- String filename = dirname + "/empty.ppt";
- ppt = new SlideShow(new HSLFSlideShow(filename));
- }
-
- public void testGraphics() throws Exception {
- // Starts off empty
- assertEquals(0, ppt.getSlides().length);
-
- // Add a slide
- Slide slide = ppt.createSlide();
- assertEquals(1, ppt.getSlides().length);
-
- // Add some stuff into it
- ShapeGroup group = new ShapeGroup();
- Dimension pgsize = ppt.getPageSize();
- java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight());
- group.setAnchor(bounds);
- slide.addShape(group);
-
- PPGraphics2D graphics = new PPGraphics2D(group);
- graphics.setColor(Color.blue);
- graphics.draw(new Rectangle(1296, 2544, 1344, 0));
-
- graphics.setColor(Color.red);
- graphics.setStroke(new BasicStroke((float)2.5));
- graphics.drawLine(500, 500, 1500, 2500);
-
- graphics.setColor(Color.green);
- graphics.setPaint(Color.gray);
- graphics.drawOval(4000, 1000, 1000, 1000);
-
- // Write the file out
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- // And read it back in
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertEquals(1, ppt.getSlides().length);
-
- slide = ppt.getSlides()[0];
- Shape[] shape = slide.getShapes();
- assertEquals(shape.length, 1); //group shape
-
- assertTrue(shape[0] instanceof ShapeGroup); //group shape
-
- group = (ShapeGroup)shape[0];
- shape = group.getShapes();
- assertEquals(shape.length, 7);
- }
-
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+import java.awt.*;
+import java.awt.Rectangle;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Test drawing shapes via Graphics2D
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPPGraphics2D extends TestCase {
+ private SlideShow ppt;
+
+ protected void setUp() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ String filename = dirname + "/empty.ppt";
+ ppt = new SlideShow(new HSLFSlideShow(filename));
+ }
+
+ public void testGraphics() throws Exception {
+ // Starts off empty
+ assertEquals(0, ppt.getSlides().length);
+
+ // Add a slide
+ Slide slide = ppt.createSlide();
+ assertEquals(1, ppt.getSlides().length);
+
+ // Add some stuff into it
+ ShapeGroup group = new ShapeGroup();
+ Dimension pgsize = ppt.getPageSize();
+ java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, (int)pgsize.getWidth(), (int)pgsize.getHeight());
+ group.setAnchor(bounds);
+ slide.addShape(group);
+
+ PPGraphics2D graphics = new PPGraphics2D(group);
+ graphics.setColor(Color.blue);
+ graphics.draw(new Rectangle(1296, 2544, 1344, 0));
+
+ graphics.setColor(Color.red);
+ graphics.setStroke(new BasicStroke((float)2.5));
+ graphics.drawLine(500, 500, 1500, 2500);
+
+ graphics.setColor(Color.green);
+ graphics.setPaint(Color.gray);
+ graphics.drawOval(4000, 1000, 1000, 1000);
+
+ // Write the file out
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ // And read it back in
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertEquals(1, ppt.getSlides().length);
+
+ slide = ppt.getSlides()[0];
+ Shape[] shape = slide.getShapes();
+ assertEquals(shape.length, 1); //group shape
+
+ assertTrue(shape[0] instanceof ShapeGroup); //group shape
+
+ group = (ShapeGroup)shape[0];
+ shape = group.getShapes();
+ assertEquals(shape.length, 7);
+ }
+
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
index 7e53ebc226..b03ce94bb7 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSetBoldItalic.java
@@ -1,83 +1,83 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.HSLFSlideShow;
-
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-
-/**
- * Test setting text properties of newly added TextBoxes
- *
- * @author Yegor Kozlov
- */
-public class TestSetBoldItalic extends TestCase {
- /**
- * Verify that we can add TextBox shapes to a slide
- * and set some of the style attributes
- */
- public void testTextBoxWrite() throws Exception {
- //String dirname = System.getProperty("HSLF.testdata.path");
- //String filename = dirname + "/with_textbox.ppt";
- //new SlideShow(new HSLFSlideShow(filename));
-
- SlideShow ppt = new SlideShow();
- Slide sl = ppt.createSlide();
- RichTextRun rt;
-
- String val = "Hello, World!";
-
- // Create a new textbox, and give it lots of properties
- TextBox txtbox = new TextBox();
- rt = txtbox.getTextRun().getRichTextRuns()[0];
- txtbox.setText(val);
- rt.setFontSize(42);
- rt.setBold(true);
- rt.setItalic(true);
- rt.setUnderlined(false);
- sl.addShape(txtbox);
-
- // Check it before save
- rt = txtbox.getTextRun().getRichTextRuns()[0];
- assertEquals(val, rt.getText());
- assertEquals(42, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
-
- // Serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- sl = ppt.getSlides()[0];
-
- txtbox = (TextBox)sl.getShapes()[0];
- rt = txtbox.getTextRun().getRichTextRuns()[0];
-
- // Check after save
- assertEquals(val, rt.getText());
- assertEquals(42, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
- assertFalse(rt.isUnderlined());
- }
-
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Test setting text properties of newly added TextBoxes
+ *
+ * @author Yegor Kozlov
+ */
+public class TestSetBoldItalic extends TestCase {
+ /**
+ * Verify that we can add TextBox shapes to a slide
+ * and set some of the style attributes
+ */
+ public void testTextBoxWrite() throws Exception {
+ //String dirname = System.getProperty("HSLF.testdata.path");
+ //String filename = dirname + "/with_textbox.ppt";
+ //new SlideShow(new HSLFSlideShow(filename));
+
+ SlideShow ppt = new SlideShow();
+ Slide sl = ppt.createSlide();
+ RichTextRun rt;
+
+ String val = "Hello, World!";
+
+ // Create a new textbox, and give it lots of properties
+ TextBox txtbox = new TextBox();
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+ txtbox.setText(val);
+ rt.setFontSize(42);
+ rt.setBold(true);
+ rt.setItalic(true);
+ rt.setUnderlined(false);
+ sl.addShape(txtbox);
+
+ // Check it before save
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+ assertEquals(val, rt.getText());
+ assertEquals(42, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+
+ // Serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ sl = ppt.getSlides()[0];
+
+ txtbox = (TextBox)sl.getShapes()[0];
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+
+ // Check after save
+ assertEquals(val, rt.getText());
+ assertEquals(42, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+ assertFalse(rt.isUnderlined());
+ }
+
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
index 2c3a6d1899..2e732e04ae 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java
@@ -1,226 +1,226 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import junit.framework.TestCase;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.HSLFSlideShow;
-
-import java.awt.*;
-import java.awt.Rectangle;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-
-/**
- * Test drawing shapes via Graphics2D
- *
- * @author Yegor Kozlov
- */
-public class TestShapes extends TestCase {
- private SlideShow ppt;
- private SlideShow pptB;
-
- protected void setUp() throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- String filename = dirname + "/empty.ppt";
- ppt = new SlideShow(new HSLFSlideShow(filename));
-
- String filenameB = dirname + "/empty_textbox.ppt";
- pptB = new SlideShow(new HSLFSlideShow(filenameB));
- }
-
- public void testGraphics() throws Exception {
- Slide slide = ppt.createSlide();
-
- Line line = new Line();
- java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
- line.setAnchor(lineAnchor);
- line.setLineWidth(3);
- line.setLineStyle(Line.PEN_DASH);
- line.setLineColor(Color.red);
- slide.addShape(line);
-
- AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
- java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
- ellipse.setAnchor(ellipseAnchor);
- ellipse.setLineWidth(2);
- ellipse.setLineStyle(Line.PEN_SOLID);
- ellipse.setLineColor(Color.green);
- ellipse.setFillColor(Color.lightGray);
- slide.addShape(ellipse);
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- //read ppt from byte array
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertEquals(1, ppt.getSlides().length);
-
- slide = ppt.getSlides()[0];
- Shape[] shape = slide.getShapes();
- assertEquals(2, shape.length);
-
- assertTrue(shape[0] instanceof Line); //group shape
- assertEquals(lineAnchor, shape[0].getAnchor()); //group shape
-
- assertTrue(shape[1] instanceof AutoShape); //group shape
- assertEquals(ellipseAnchor, shape[1].getAnchor()); //group shape
- }
-
- /**
- * Verify that we can read TextBox shapes
- * @throws Exception
- */
- public void testTextBoxRead() throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- String filename = dirname + "/with_textbox.ppt";
- ppt = new SlideShow(new HSLFSlideShow(filename));
- Slide sl = ppt.getSlides()[0];
- Shape[] sh = sl.getShapes();
- for (int i = 0; i < sh.length; i++) {
- assertTrue(sh[i] instanceof TextBox);
- TextBox txtbox = (TextBox)sh[i];
- String text = txtbox.getText();
- assertNotNull(text);
-
- assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
- RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];
-
- if (text.equals("Hello, World!!!")){
- assertEquals(32, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
- } else if (text.equals("I am just a poor boy")){
- assertEquals(44, rt.getFontSize());
- assertTrue(rt.isBold());
- } else if (text.equals("This is Times New Roman")){
- assertEquals(16, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
- assertTrue(rt.isUnderlined());
- } else if (text.equals("Plain Text")){
- assertEquals(18, rt.getFontSize());
- }
- }
- }
-
- /**
- * Verify that we can add TextBox shapes to a slide
- * and set some of the style attributes
- */
- public void testTextBoxWriteBytes() throws Exception {
- ppt = new SlideShow();
- Slide sl = ppt.createSlide();
- RichTextRun rt;
-
- String val = "Hello, World!";
-
- // Create a new textbox, and give it lots of properties
- TextBox txtbox = new TextBox();
- rt = txtbox.getTextRun().getRichTextRuns()[0];
- txtbox.setText(val);
- rt.setFontName("Arial");
- rt.setFontSize(42);
- rt.setBold(true);
- rt.setItalic(true);
- rt.setUnderlined(false);
- rt.setFontColor(Color.red);
- sl.addShape(txtbox);
-
- // Check it before save
- rt = txtbox.getTextRun().getRichTextRuns()[0];
- assertEquals(val, rt.getText());
- assertEquals(42, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
- assertFalse(rt.isUnderlined());
- assertEquals("Arial", rt.getFontName());
- assertEquals(Color.red, rt.getFontColor());
-
- // Serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- txtbox = (TextBox)sl.getShapes()[0];
- rt = txtbox.getTextRun().getRichTextRuns()[0];
-
- // Check after save
- assertEquals(val, rt.getText());
- assertEquals(42, rt.getFontSize());
- assertTrue(rt.isBold());
- assertTrue(rt.isItalic());
- assertFalse(rt.isUnderlined());
- assertEquals("Arial", rt.getFontName());
- assertEquals(Color.red, rt.getFontColor());
- }
-
- /**
- * Test with an empty text box
- */
- public void testEmptyTextBox() throws Exception {
- assertEquals(2, pptB.getSlides().length);
- Slide s1 = pptB.getSlides()[0];
- Slide s2 = pptB.getSlides()[1];
-
- // Check we can get the shapes count
- assertEquals(2, s1.getShapes().length);
- assertEquals(2, s2.getShapes().length);
- }
-
- /**
- * If you iterate over text shapes in a slide and collect them in a set
- * it must be the same as returned by Slide.getTextRuns().
- */
- public void testTextBoxSet() throws Exception {
- textBoxSet("/with_textbox.ppt");
- textBoxSet("/basic_test_ppt_file.ppt");
- textBoxSet("/next_test_ppt_file.ppt");
- textBoxSet("/Single_Coloured_Page.ppt");
- textBoxSet("/Single_Coloured_Page_With_Fonts_and_Alignments.ppt");
- textBoxSet("/incorrect_slide_order.ppt");
- }
-
- private void textBoxSet(String filename) throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + filename));
- Slide[] sl = ppt.getSlides();
- for (int k = 0; k < sl.length; k++) {
- ArrayList lst1 = new ArrayList();
- TextRun[] txt = sl[k].getTextRuns();
- for (int i = 0; i < txt.length; i++) {
- lst1.add(txt[i].getText());
- }
-
- ArrayList lst2 = new ArrayList();
- Shape[] sh = sl[k].getShapes();
- for (int i = 0; i < sh.length; i++) {
- if (sh[i] instanceof TextBox){
- TextBox tbox = (TextBox)sh[i];
- lst2.add(tbox.getText());
- }
- }
- assertTrue(lst1.containsAll(lst2));
- assertTrue(lst2.containsAll(lst1));
- }
- }
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.HSLFSlideShow;
+
+import java.awt.*;
+import java.awt.Rectangle;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+
+/**
+ * Test drawing shapes via Graphics2D
+ *
+ * @author Yegor Kozlov
+ */
+public class TestShapes extends TestCase {
+ private SlideShow ppt;
+ private SlideShow pptB;
+
+ protected void setUp() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ String filename = dirname + "/empty.ppt";
+ ppt = new SlideShow(new HSLFSlideShow(filename));
+
+ String filenameB = dirname + "/empty_textbox.ppt";
+ pptB = new SlideShow(new HSLFSlideShow(filenameB));
+ }
+
+ public void testGraphics() throws Exception {
+ Slide slide = ppt.createSlide();
+
+ Line line = new Line();
+ java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
+ line.setAnchor(lineAnchor);
+ line.setLineWidth(3);
+ line.setLineStyle(Line.PEN_DASH);
+ line.setLineColor(Color.red);
+ slide.addShape(line);
+
+ AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
+ java.awt.Rectangle ellipseAnchor = new Rectangle(320, 154, 55, 111);
+ ellipse.setAnchor(ellipseAnchor);
+ ellipse.setLineWidth(2);
+ ellipse.setLineStyle(Line.PEN_SOLID);
+ ellipse.setLineColor(Color.green);
+ ellipse.setFillColor(Color.lightGray);
+ slide.addShape(ellipse);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ //read ppt from byte array
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertEquals(1, ppt.getSlides().length);
+
+ slide = ppt.getSlides()[0];
+ Shape[] shape = slide.getShapes();
+ assertEquals(2, shape.length);
+
+ assertTrue(shape[0] instanceof Line); //group shape
+ assertEquals(lineAnchor, shape[0].getAnchor()); //group shape
+
+ assertTrue(shape[1] instanceof AutoShape); //group shape
+ assertEquals(ellipseAnchor, shape[1].getAnchor()); //group shape
+ }
+
+ /**
+ * Verify that we can read TextBox shapes
+ * @throws Exception
+ */
+ public void testTextBoxRead() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ String filename = dirname + "/with_textbox.ppt";
+ ppt = new SlideShow(new HSLFSlideShow(filename));
+ Slide sl = ppt.getSlides()[0];
+ Shape[] sh = sl.getShapes();
+ for (int i = 0; i < sh.length; i++) {
+ assertTrue(sh[i] instanceof TextBox);
+ TextBox txtbox = (TextBox)sh[i];
+ String text = txtbox.getText();
+ assertNotNull(text);
+
+ assertEquals(txtbox.getTextRun().getRichTextRuns().length, 1);
+ RichTextRun rt = txtbox.getTextRun().getRichTextRuns()[0];
+
+ if (text.equals("Hello, World!!!")){
+ assertEquals(32, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+ } else if (text.equals("I am just a poor boy")){
+ assertEquals(44, rt.getFontSize());
+ assertTrue(rt.isBold());
+ } else if (text.equals("This is Times New Roman")){
+ assertEquals(16, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+ assertTrue(rt.isUnderlined());
+ } else if (text.equals("Plain Text")){
+ assertEquals(18, rt.getFontSize());
+ }
+ }
+ }
+
+ /**
+ * Verify that we can add TextBox shapes to a slide
+ * and set some of the style attributes
+ */
+ public void testTextBoxWriteBytes() throws Exception {
+ ppt = new SlideShow();
+ Slide sl = ppt.createSlide();
+ RichTextRun rt;
+
+ String val = "Hello, World!";
+
+ // Create a new textbox, and give it lots of properties
+ TextBox txtbox = new TextBox();
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+ txtbox.setText(val);
+ rt.setFontName("Arial");
+ rt.setFontSize(42);
+ rt.setBold(true);
+ rt.setItalic(true);
+ rt.setUnderlined(false);
+ rt.setFontColor(Color.red);
+ sl.addShape(txtbox);
+
+ // Check it before save
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+ assertEquals(val, rt.getText());
+ assertEquals(42, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+ assertFalse(rt.isUnderlined());
+ assertEquals("Arial", rt.getFontName());
+ assertEquals(Color.red, rt.getFontColor());
+
+ // Serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ txtbox = (TextBox)sl.getShapes()[0];
+ rt = txtbox.getTextRun().getRichTextRuns()[0];
+
+ // Check after save
+ assertEquals(val, rt.getText());
+ assertEquals(42, rt.getFontSize());
+ assertTrue(rt.isBold());
+ assertTrue(rt.isItalic());
+ assertFalse(rt.isUnderlined());
+ assertEquals("Arial", rt.getFontName());
+ assertEquals(Color.red, rt.getFontColor());
+ }
+
+ /**
+ * Test with an empty text box
+ */
+ public void testEmptyTextBox() throws Exception {
+ assertEquals(2, pptB.getSlides().length);
+ Slide s1 = pptB.getSlides()[0];
+ Slide s2 = pptB.getSlides()[1];
+
+ // Check we can get the shapes count
+ assertEquals(2, s1.getShapes().length);
+ assertEquals(2, s2.getShapes().length);
+ }
+
+ /**
+ * If you iterate over text shapes in a slide and collect them in a set
+ * it must be the same as returned by Slide.getTextRuns().
+ */
+ public void testTextBoxSet() throws Exception {
+ textBoxSet("/with_textbox.ppt");
+ textBoxSet("/basic_test_ppt_file.ppt");
+ textBoxSet("/next_test_ppt_file.ppt");
+ textBoxSet("/Single_Coloured_Page.ppt");
+ textBoxSet("/Single_Coloured_Page_With_Fonts_and_Alignments.ppt");
+ textBoxSet("/incorrect_slide_order.ppt");
+ }
+
+ private void textBoxSet(String filename) throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + filename));
+ Slide[] sl = ppt.getSlides();
+ for (int k = 0; k < sl.length; k++) {
+ ArrayList lst1 = new ArrayList();
+ TextRun[] txt = sl[k].getTextRuns();
+ for (int i = 0; i < txt.length; i++) {
+ lst1.add(txt[i].getText());
+ }
+
+ ArrayList lst2 = new ArrayList();
+ Shape[] sh = sl[k].getShapes();
+ for (int i = 0; i < sh.length; i++) {
+ if (sh[i] instanceof TextBox){
+ TextBox tbox = (TextBox)sh[i];
+ lst2.add(tbox.getText());
+ }
+ }
+ assertTrue(lst1.containsAll(lst2));
+ assertTrue(lst2.containsAll(lst1));
+ }
+ }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
index ded6519b1b..c20f983d56 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestSlides.java
@@ -1,183 +1,183 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model;
-
-import junit.framework.TestCase;
-import org.apache.poi.hslf.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.SlideShow;
-
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-
-/**
- * Test adding new slides to a ppt.
- *
- * Note - uses the same empty PPT file as the core "new Slideshow"
- * stuff does
- * @author Yegor Kozlov
- */
-public class TestSlides extends TestCase {
-
- /**
- * Add 1 slide to an empty ppt.
- * @throws Exception
- */
- public void testAddSlides1() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
- assertTrue(ppt.getSlides().length == 0);
-
- Slide s1 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 1);
- assertEquals(3, s1._getSheetRefId());
- assertEquals(256, s1._getSheetNumber());
- assertEquals(1, s1.getSlideNumber());
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertTrue(ppt.getSlides().length == 1);
- }
-
- /**
- * Add 2 slides to an empty ppt
- * @throws Exception
- */
- public void testAddSlides2() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
- assertTrue(ppt.getSlides().length == 0);
-
- Slide s1 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 1);
- assertEquals(3, s1._getSheetRefId());
- assertEquals(256, s1._getSheetNumber());
- assertEquals(1, s1.getSlideNumber());
-
- Slide s2 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 2);
- assertEquals(4, s2._getSheetRefId());
- assertEquals(257, s2._getSheetNumber());
- assertEquals(2, s2.getSlideNumber());
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertTrue(ppt.getSlides().length == 2);
- }
-
- /**
- * Add 3 slides to an empty ppt
- * @throws Exception
- */
- public void testAddSlides3() throws Exception {
- SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
- assertTrue(ppt.getSlides().length == 0);
-
- Slide s1 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 1);
- assertEquals(3, s1._getSheetRefId());
- assertEquals(256, s1._getSheetNumber());
- assertEquals(1, s1.getSlideNumber());
-
- Slide s2 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 2);
- assertEquals(4, s2._getSheetRefId());
- assertEquals(257, s2._getSheetNumber());
- assertEquals(2, s2.getSlideNumber());
-
- Slide s3 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 3);
- assertEquals(5, s3._getSheetRefId());
- assertEquals(258, s3._getSheetNumber());
- assertEquals(3, s3.getSlideNumber());
-
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertTrue(ppt.getSlides().length == 3);
-
- // Check IDs are still right
- s1 = ppt.getSlides()[0];
- assertEquals(256, s1._getSheetNumber());
- assertEquals(3, s1._getSheetRefId());
- s2 = ppt.getSlides()[1];
- assertEquals(257, s2._getSheetNumber());
- assertEquals(4, s2._getSheetRefId());
- s3 = ppt.getSlides()[2];;
- assertTrue(ppt.getSlides().length == 3);
- assertEquals(258, s3._getSheetNumber());
- assertEquals(5, s3._getSheetRefId());
- }
-
- /**
- * Add slides to ppt which already has two slides
- */
- public void testAddSlides2to3() throws Exception {
- String dirname = System.getProperty("HSLF.testdata.path");
- SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt"));
-
- assertTrue(ppt.getSlides().length == 2);
-
- // First slide is 256 / 4
- Slide s1 = ppt.getSlides()[0];
- assertEquals(256, s1._getSheetNumber());
- assertEquals(4, s1._getSheetRefId());
-
- // Last slide is 257 / 6
- Slide s2 = ppt.getSlides()[1];
- assertEquals(257, s2._getSheetNumber());
- assertEquals(6, s2._getSheetRefId());
-
- // Add another slide, goes in at the end
- Slide s3 = ppt.createSlide();
- assertTrue(ppt.getSlides().length == 3);
- assertEquals(258, s3._getSheetNumber());
- assertEquals(8, s3._getSheetRefId());
-
-
- // Serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
- assertTrue(ppt.getSlides().length == 3);
-
-
- // Check IDs are still right
- s1 = ppt.getSlides()[0];
- assertEquals(256, s1._getSheetNumber());
- assertEquals(4, s1._getSheetRefId());
- s2 = ppt.getSlides()[1];
- assertEquals(257, s2._getSheetNumber());
- assertEquals(6, s2._getSheetRefId());
- s3 = ppt.getSlides()[2];;
- assertTrue(ppt.getSlides().length == 3);
- assertEquals(258, s3._getSheetNumber());
- assertEquals(8, s3._getSheetRefId());
- }
-
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import junit.framework.TestCase;
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.SlideShow;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Test adding new slides to a ppt.
+ *
+ * Note - uses the same empty PPT file as the core "new Slideshow"
+ * stuff does
+ * @author Yegor Kozlov
+ */
+public class TestSlides extends TestCase {
+
+ /**
+ * Add 1 slide to an empty ppt.
+ * @throws Exception
+ */
+ public void testAddSlides1() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ assertTrue(ppt.getSlides().length == 0);
+
+ Slide s1 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 1);
+ assertEquals(3, s1._getSheetRefId());
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(1, s1.getSlideNumber());
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertTrue(ppt.getSlides().length == 1);
+ }
+
+ /**
+ * Add 2 slides to an empty ppt
+ * @throws Exception
+ */
+ public void testAddSlides2() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ assertTrue(ppt.getSlides().length == 0);
+
+ Slide s1 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 1);
+ assertEquals(3, s1._getSheetRefId());
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(1, s1.getSlideNumber());
+
+ Slide s2 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 2);
+ assertEquals(4, s2._getSheetRefId());
+ assertEquals(257, s2._getSheetNumber());
+ assertEquals(2, s2.getSlideNumber());
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertTrue(ppt.getSlides().length == 2);
+ }
+
+ /**
+ * Add 3 slides to an empty ppt
+ * @throws Exception
+ */
+ public void testAddSlides3() throws Exception {
+ SlideShow ppt = new SlideShow(new HSLFSlideShow( TestSlides.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt") ));
+ assertTrue(ppt.getSlides().length == 0);
+
+ Slide s1 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 1);
+ assertEquals(3, s1._getSheetRefId());
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(1, s1.getSlideNumber());
+
+ Slide s2 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 2);
+ assertEquals(4, s2._getSheetRefId());
+ assertEquals(257, s2._getSheetNumber());
+ assertEquals(2, s2.getSlideNumber());
+
+ Slide s3 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 3);
+ assertEquals(5, s3._getSheetRefId());
+ assertEquals(258, s3._getSheetNumber());
+ assertEquals(3, s3.getSlideNumber());
+
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertTrue(ppt.getSlides().length == 3);
+
+ // Check IDs are still right
+ s1 = ppt.getSlides()[0];
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(3, s1._getSheetRefId());
+ s2 = ppt.getSlides()[1];
+ assertEquals(257, s2._getSheetNumber());
+ assertEquals(4, s2._getSheetRefId());
+ s3 = ppt.getSlides()[2];;
+ assertTrue(ppt.getSlides().length == 3);
+ assertEquals(258, s3._getSheetNumber());
+ assertEquals(5, s3._getSheetRefId());
+ }
+
+ /**
+ * Add slides to ppt which already has two slides
+ */
+ public void testAddSlides2to3() throws Exception {
+ String dirname = System.getProperty("HSLF.testdata.path");
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(dirname + "/basic_test_ppt_file.ppt"));
+
+ assertTrue(ppt.getSlides().length == 2);
+
+ // First slide is 256 / 4
+ Slide s1 = ppt.getSlides()[0];
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(4, s1._getSheetRefId());
+
+ // Last slide is 257 / 6
+ Slide s2 = ppt.getSlides()[1];
+ assertEquals(257, s2._getSheetNumber());
+ assertEquals(6, s2._getSheetRefId());
+
+ // Add another slide, goes in at the end
+ Slide s3 = ppt.createSlide();
+ assertTrue(ppt.getSlides().length == 3);
+ assertEquals(258, s3._getSheetNumber());
+ assertEquals(8, s3._getSheetRefId());
+
+
+ // Serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+ assertTrue(ppt.getSlides().length == 3);
+
+
+ // Check IDs are still right
+ s1 = ppt.getSlides()[0];
+ assertEquals(256, s1._getSheetNumber());
+ assertEquals(4, s1._getSheetRefId());
+ s2 = ppt.getSlides()[1];
+ assertEquals(257, s2._getSheetNumber());
+ assertEquals(6, s2._getSheetRefId());
+ s3 = ppt.getSlides()[2];;
+ assertTrue(ppt.getSlides().length == 3);
+ assertEquals(258, s3._getSheetNumber());
+ assertEquals(8, s3._getSheetRefId());
+ }
+
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
index d61245e231..298d34165d 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java
@@ -1,394 +1,394 @@
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.usermodel;
-
-import org.apache.poi.hslf.*;
-import org.apache.poi.hslf.blip.*;
-import org.apache.poi.hslf.model.*;
-import junit.framework.TestCase;
-
-import java.io.*;
-import java.util.Arrays;
-
-/**
- * Test adding/reading pictures
- *
- * @author Yegor Kozlov
- */
-public class TestPictures extends TestCase{
-
- protected File cwd;
-
- public void setUp() throws Exception {
- cwd = new File(System.getProperty("HSLF.testdata.path"));
- }
-
- /**
- * Test read/write Macintosh PICT
- */
- public void testPICT() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "cow.pict");
- int idx = ppt.addPicture(img, Picture.PICT);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can read this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.PICT, pictures[0].getType());
- assertTrue(pictures[0] instanceof PICT);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertEquals(src_bytes.length, ppt_bytes.length);
- //in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them
- byte[] b1 = new byte[src_bytes.length-512];
- System.arraycopy(src_bytes, 512, b1, 0, b1.length);
- byte[] b2 = new byte[ppt_bytes.length-512];
- System.arraycopy(ppt_bytes, 512, b2, 0, b2.length);
- assertTrue(Arrays.equals(b1, b2));
- }
-
- /**
- * Test read/write WMF
- */
- public void testWMF() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "santa.wmf");
- int idx = ppt.addPicture(img, Picture.WMF);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can read this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.WMF, pictures[0].getType());
- assertTrue(pictures[0] instanceof WMF);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertEquals(src_bytes.length, ppt_bytes.length);
- //in WMF the first 22 bytes - is a metafile header
- byte[] b1 = new byte[src_bytes.length-22];
- System.arraycopy(src_bytes, 22, b1, 0, b1.length);
- byte[] b2 = new byte[ppt_bytes.length-22];
- System.arraycopy(ppt_bytes, 22, b2, 0, b2.length);
- assertTrue(Arrays.equals(b1, b2));
- }
-
- /**
- * Test read/write EMF
- */
- public void testEMF() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "wrench.emf");
- int idx = ppt.addPicture(img, Picture.EMF);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can get this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.EMF, pictures[0].getType());
- assertTrue(pictures[0] instanceof EMF);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
- }
-
- /**
- * Test read/write PNG
- */
- public void testPNG() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "tomcat.png");
- int idx = ppt.addPicture(img, Picture.PNG);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can read this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.PNG, pictures[0].getType());
- assertTrue(pictures[0] instanceof PNG);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
- }
-
- /**
- * Test read/write JPEG
- */
- public void testJPEG() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "clock.jpg");
- int idx = ppt.addPicture(img, Picture.JPEG);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can read this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.JPEG, pictures[0].getType());
- assertTrue(pictures[0] instanceof JPEG);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
- }
-
- /**
- * Test read/write DIB
- */
- public void testDIB() throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- File img = new File(cwd, "sci_cec.dib");
-
- // Check we can read the test DIB image
- assertTrue(img.exists());
-
- // Add the image
- int idx = ppt.addPicture(img, Picture.DIB);
- Picture pict = new Picture(idx);
- assertEquals(idx, pict.getPictureIndex());
- slide.addShape(pict);
-
- //serialize and read again
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ppt.write(out);
- out.close();
-
- ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
-
- //make sure we can read this picture shape and it refers to the correct picture data
- Shape[] sh = ppt.getSlides()[0].getShapes();
- assertEquals(1, sh.length);
- pict = (Picture)sh[0];
- assertEquals(idx, pict.getPictureIndex());
-
- //check picture data
- PictureData[] pictures = ppt.getPictureData();
- //the Picture shape refers to the PictureData object in the Presentation
- assertEquals(pict.getPictureData(), pictures[0]);
-
- assertEquals(1, pictures.length);
- assertEquals(Picture.DIB, pictures[0].getType());
- assertTrue(pictures[0] instanceof DIB);
- //compare the content of the initial file with what is stored in the PictureData
- byte[] src_bytes = read(img);
- byte[] ppt_bytes = pictures[0].getData();
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
- }
-
- /**
- * Read file into a byte array
- */
- protected byte[] read(File f) throws IOException {
- byte[] bytes = new byte[(int)f.length()];
- FileInputStream is = new FileInputStream(f);
- is.read(bytes);
- is.close();
- return bytes;
- }
-
- /**
- * Read pictures in different formats from a reference slide show
- */
- public void testReadPictures() throws Exception {
-
- byte[] src_bytes, ppt_bytes, b1, b2;
- Picture pict;
- PictureData pdata;
-
- SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(cwd, "pictures.ppt").getPath()));
- Slide[] slides = ppt.getSlides();
- PictureData[] pictures = ppt.getPictureData();
- assertEquals(5, pictures.length);
-
- pict = (Picture)slides[0].getShapes()[0]; //the first slide contains JPEG
- pdata = pict.getPictureData();
- assertTrue(pdata instanceof JPEG);
- assertEquals(Picture.JPEG, pdata.getType());
- src_bytes = pdata.getData();
- ppt_bytes = read(new File(cwd, "clock.jpg"));
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
-
- pict = (Picture)slides[1].getShapes()[0]; //the second slide contains PNG
- pdata = pict.getPictureData();
- assertTrue(pdata instanceof PNG);
- assertEquals(Picture.PNG, pdata.getType());
- src_bytes = pdata.getData();
- ppt_bytes = read(new File(cwd, "tomcat.png"));
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
-
- pict = (Picture)slides[2].getShapes()[0]; //the third slide contains WMF
- pdata = pict.getPictureData();
- assertTrue(pdata instanceof WMF);
- assertEquals(Picture.WMF, pdata.getType());
- src_bytes = pdata.getData();
- ppt_bytes = read(new File(cwd, "santa.wmf"));
- assertEquals(src_bytes.length, ppt_bytes.length);
- //ignore the first 22 bytes - it is a WMF metafile header
- b1 = new byte[src_bytes.length-22];
- System.arraycopy(src_bytes, 22, b1, 0, b1.length);
- b2 = new byte[ppt_bytes.length-22];
- System.arraycopy(ppt_bytes, 22, b2, 0, b2.length);
- assertTrue(Arrays.equals(b1, b2));
-
- pict = (Picture)slides[3].getShapes()[0]; //the forth slide contains PICT
- pdata = pict.getPictureData();
- assertTrue(pdata instanceof PICT);
- assertEquals(Picture.PICT, pdata.getType());
- src_bytes = pdata.getData();
- ppt_bytes = read(new File(cwd, "cow.pict"));
- assertEquals(src_bytes.length, ppt_bytes.length);
- //ignore the first 512 bytes - it is a MAC specific crap
- b1 = new byte[src_bytes.length-512];
- System.arraycopy(src_bytes, 512, b1, 0, b1.length);
- b2 = new byte[ppt_bytes.length-512];
- System.arraycopy(ppt_bytes, 512, b2, 0, b2.length);
- assertTrue(Arrays.equals(b1, b2));
-
- pict = (Picture)slides[4].getShapes()[0]; //the fifth slide contains EMF
- pdata = pict.getPictureData();
- assertTrue(pdata instanceof EMF);
- assertEquals(Picture.EMF, pdata.getType());
- src_bytes = pdata.getData();
- ppt_bytes = read(new File(cwd, "wrench.emf"));
- assertTrue(Arrays.equals(src_bytes, ppt_bytes));
-
- }
-
- /**
- * Test that on a party corrupt powerpoint document, which has
- * crazy pictures of type 0, we do our best.
- */
- public void testZeroPictureType() throws Exception {
- HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureTypeZero.ppt").getPath());
-
- // Should still have 2 real pictures
- assertEquals(2, hslf.getPictures().length);
- // Both are real pictures, both WMF
- assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
- assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
-
- // TODO: DISABLED: Pending bug #41176
-
- // Now test what happens when we use the SlideShow interface
- //SlideShow ppt = new SlideShow(hslf);
- }
-}
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.usermodel;
+
+import org.apache.poi.hslf.*;
+import org.apache.poi.hslf.blip.*;
+import org.apache.poi.hslf.model.*;
+import junit.framework.TestCase;
+
+import java.io.*;
+import java.util.Arrays;
+
+/**
+ * Test adding/reading pictures
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPictures extends TestCase{
+
+ protected File cwd;
+
+ public void setUp() throws Exception {
+ cwd = new File(System.getProperty("HSLF.testdata.path"));
+ }
+
+ /**
+ * Test read/write Macintosh PICT
+ */
+ public void testPICT() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "cow.pict");
+ int idx = ppt.addPicture(img, Picture.PICT);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can read this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.PICT, pictures[0].getType());
+ assertTrue(pictures[0] instanceof PICT);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertEquals(src_bytes.length, ppt_bytes.length);
+ //in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them
+ byte[] b1 = new byte[src_bytes.length-512];
+ System.arraycopy(src_bytes, 512, b1, 0, b1.length);
+ byte[] b2 = new byte[ppt_bytes.length-512];
+ System.arraycopy(ppt_bytes, 512, b2, 0, b2.length);
+ assertTrue(Arrays.equals(b1, b2));
+ }
+
+ /**
+ * Test read/write WMF
+ */
+ public void testWMF() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "santa.wmf");
+ int idx = ppt.addPicture(img, Picture.WMF);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can read this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.WMF, pictures[0].getType());
+ assertTrue(pictures[0] instanceof WMF);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertEquals(src_bytes.length, ppt_bytes.length);
+ //in WMF the first 22 bytes - is a metafile header
+ byte[] b1 = new byte[src_bytes.length-22];
+ System.arraycopy(src_bytes, 22, b1, 0, b1.length);
+ byte[] b2 = new byte[ppt_bytes.length-22];
+ System.arraycopy(ppt_bytes, 22, b2, 0, b2.length);
+ assertTrue(Arrays.equals(b1, b2));
+ }
+
+ /**
+ * Test read/write EMF
+ */
+ public void testEMF() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "wrench.emf");
+ int idx = ppt.addPicture(img, Picture.EMF);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can get this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.EMF, pictures[0].getType());
+ assertTrue(pictures[0] instanceof EMF);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+ }
+
+ /**
+ * Test read/write PNG
+ */
+ public void testPNG() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "tomcat.png");
+ int idx = ppt.addPicture(img, Picture.PNG);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can read this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.PNG, pictures[0].getType());
+ assertTrue(pictures[0] instanceof PNG);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+ }
+
+ /**
+ * Test read/write JPEG
+ */
+ public void testJPEG() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "clock.jpg");
+ int idx = ppt.addPicture(img, Picture.JPEG);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can read this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.JPEG, pictures[0].getType());
+ assertTrue(pictures[0] instanceof JPEG);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+ }
+
+ /**
+ * Test read/write DIB
+ */
+ public void testDIB() throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+ File img = new File(cwd, "sci_cec.dib");
+
+ // Check we can read the test DIB image
+ assertTrue(img.exists());
+
+ // Add the image
+ int idx = ppt.addPicture(img, Picture.DIB);
+ Picture pict = new Picture(idx);
+ assertEquals(idx, pict.getPictureIndex());
+ slide.addShape(pict);
+
+ //serialize and read again
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ppt.write(out);
+ out.close();
+
+ ppt = new SlideShow(new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())));
+
+ //make sure we can read this picture shape and it refers to the correct picture data
+ Shape[] sh = ppt.getSlides()[0].getShapes();
+ assertEquals(1, sh.length);
+ pict = (Picture)sh[0];
+ assertEquals(idx, pict.getPictureIndex());
+
+ //check picture data
+ PictureData[] pictures = ppt.getPictureData();
+ //the Picture shape refers to the PictureData object in the Presentation
+ assertEquals(pict.getPictureData(), pictures[0]);
+
+ assertEquals(1, pictures.length);
+ assertEquals(Picture.DIB, pictures[0].getType());
+ assertTrue(pictures[0] instanceof DIB);
+ //compare the content of the initial file with what is stored in the PictureData
+ byte[] src_bytes = read(img);
+ byte[] ppt_bytes = pictures[0].getData();
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+ }
+
+ /**
+ * Read file into a byte array
+ */
+ protected byte[] read(File f) throws IOException {
+ byte[] bytes = new byte[(int)f.length()];
+ FileInputStream is = new FileInputStream(f);
+ is.read(bytes);
+ is.close();
+ return bytes;
+ }
+
+ /**
+ * Read pictures in different formats from a reference slide show
+ */
+ public void testReadPictures() throws Exception {
+
+ byte[] src_bytes, ppt_bytes, b1, b2;
+ Picture pict;
+ PictureData pdata;
+
+ SlideShow ppt = new SlideShow(new HSLFSlideShow(new File(cwd, "pictures.ppt").getPath()));
+ Slide[] slides = ppt.getSlides();
+ PictureData[] pictures = ppt.getPictureData();
+ assertEquals(5, pictures.length);
+
+ pict = (Picture)slides[0].getShapes()[0]; //the first slide contains JPEG
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof JPEG);
+ assertEquals(Picture.JPEG, pdata.getType());
+ src_bytes = pdata.getData();
+ ppt_bytes = read(new File(cwd, "clock.jpg"));
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+
+ pict = (Picture)slides[1].getShapes()[0]; //the second slide contains PNG
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof PNG);
+ assertEquals(Picture.PNG, pdata.getType());
+ src_bytes = pdata.getData();
+ ppt_bytes = read(new File(cwd, "tomcat.png"));
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+
+ pict = (Picture)slides[2].getShapes()[0]; //the third slide contains WMF
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof WMF);
+ assertEquals(Picture.WMF, pdata.getType());
+ src_bytes = pdata.getData();
+ ppt_bytes = read(new File(cwd, "santa.wmf"));
+ assertEquals(src_bytes.length, ppt_bytes.length);
+ //ignore the first 22 bytes - it is a WMF metafile header
+ b1 = new byte[src_bytes.length-22];
+ System.arraycopy(src_bytes, 22, b1, 0, b1.length);
+ b2 = new byte[ppt_bytes.length-22];
+ System.arraycopy(ppt_bytes, 22, b2, 0, b2.length);
+ assertTrue(Arrays.equals(b1, b2));
+
+ pict = (Picture)slides[3].getShapes()[0]; //the forth slide contains PICT
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof PICT);
+ assertEquals(Picture.PICT, pdata.getType());
+ src_bytes = pdata.getData();
+ ppt_bytes = read(new File(cwd, "cow.pict"));
+ assertEquals(src_bytes.length, ppt_bytes.length);
+ //ignore the first 512 bytes - it is a MAC specific crap
+ b1 = new byte[src_bytes.length-512];
+ System.arraycopy(src_bytes, 512, b1, 0, b1.length);
+ b2 = new byte[ppt_bytes.length-512];
+ System.arraycopy(ppt_bytes, 512, b2, 0, b2.length);
+ assertTrue(Arrays.equals(b1, b2));
+
+ pict = (Picture)slides[4].getShapes()[0]; //the fifth slide contains EMF
+ pdata = pict.getPictureData();
+ assertTrue(pdata instanceof EMF);
+ assertEquals(Picture.EMF, pdata.getType());
+ src_bytes = pdata.getData();
+ ppt_bytes = read(new File(cwd, "wrench.emf"));
+ assertTrue(Arrays.equals(src_bytes, ppt_bytes));
+
+ }
+
+ /**
+ * Test that on a party corrupt powerpoint document, which has
+ * crazy pictures of type 0, we do our best.
+ */
+ public void testZeroPictureType() throws Exception {
+ HSLFSlideShow hslf = new HSLFSlideShow(new File(cwd, "PictureTypeZero.ppt").getPath());
+
+ // Should still have 2 real pictures
+ assertEquals(2, hslf.getPictures().length);
+ // Both are real pictures, both WMF
+ assertEquals(Picture.WMF, hslf.getPictures()[0].getType());
+ assertEquals(Picture.WMF, hslf.getPictures()[1].getType());
+
+ // TODO: DISABLED: Pending bug #41176
+
+ // Now test what happens when we use the SlideShow interface
+ //SlideShow ppt = new SlideShow(hslf);
+ }
+}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java
index bc0a6c0bee..2db5fc5c24 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestSavedByTable.java
@@ -1,91 +1,91 @@
-
-/* ====================================================================
- Copyright 2002-2004 Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-==================================================================== */
-
-
-package org.apache.poi.hwpf.model;
-
-import java.io.*;
-import java.util.*;
-import junit.framework.*;
-
-import org.apache.poi.hwpf.*;
-import org.apache.poi.hwpf.model.*;
-import org.apache.poi.util.*;
-
-/**
- * Unit test for {@link SavedByTable} and {@link SavedByEntry}.
- *
- * @author Daniel Noll
- */
-public class TestSavedByTable
- extends TestCase
-{
- /** Data dir */
- private File testFile = new File(new File(System.getProperty("HWPF.testdata.path")), "saved-by-table.doc");
-
- /** The expected entries in the test document. */
- private List expected = Arrays.asList(new Object[] {
- new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
- new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
- new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
- new SavedByEntry("JPratt", "C:\\TEMP\\Iraq - security.doc"),
- new SavedByEntry("JPratt", "A:\\Iraq - security.doc"),
- new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\Iraq - security.doc"),
- new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\A;Iraq - security.doc"),
- new SavedByEntry("ablackshaw", "A:\\Iraq - security.doc"),
- new SavedByEntry("MKhan", "C:\\TEMP\\Iraq - security.doc"),
- new SavedByEntry("MKhan", "C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc")
- });
-
- /**
- * Tests reading in the entries, comparing them against the expected entries.
- * Then tests writing the document out and reading the entries yet again.
- *
- * @throws Exception if an unexpected error occurs.
- */
- public void testReadWrite()
- throws Exception
- {
- // This document is widely available on the internet as "blair.doc".
- // I tried stripping the content and saving the document but my version
- // of Word (from Office XP) strips this table out.
- InputStream stream = new BufferedInputStream(new FileInputStream(testFile));
- HWPFDocument doc;
- try
- {
- doc = new HWPFDocument(stream);
- }
- finally
- {
- stream.close();
- }
-
- // Check what we just read.
- assertEquals("List of saved-by entries was not as expected",
- expected, doc.getSavedByTable().getEntries());
-
- // Now write the entire document out, and read it back in...
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- doc.write(byteStream);
- InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
- HWPFDocument copy = new HWPFDocument(copyStream);
-
- // And check again.
- assertEquals("List of saved-by entries was incorrect after writing",
- expected, copy.getSavedByTable().getEntries());
- }
-}
+
+/* ====================================================================
+ Copyright 2002-2004 Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+
+package org.apache.poi.hwpf.model;
+
+import java.io.*;
+import java.util.*;
+import junit.framework.*;
+
+import org.apache.poi.hwpf.*;
+import org.apache.poi.hwpf.model.*;
+import org.apache.poi.util.*;
+
+/**
+ * Unit test for {@link SavedByTable} and {@link SavedByEntry}.
+ *
+ * @author Daniel Noll
+ */
+public class TestSavedByTable
+ extends TestCase
+{
+ /** Data dir */
+ private File testFile = new File(new File(System.getProperty("HWPF.testdata.path")), "saved-by-table.doc");
+
+ /** The expected entries in the test document. */
+ private List expected = Arrays.asList(new Object[] {
+ new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
+ new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
+ new SavedByEntry("cic22", "C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd"),
+ new SavedByEntry("JPratt", "C:\\TEMP\\Iraq - security.doc"),
+ new SavedByEntry("JPratt", "A:\\Iraq - security.doc"),
+ new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\Iraq - security.doc"),
+ new SavedByEntry("ablackshaw", "C:\\ABlackshaw\\A;Iraq - security.doc"),
+ new SavedByEntry("ablackshaw", "A:\\Iraq - security.doc"),
+ new SavedByEntry("MKhan", "C:\\TEMP\\Iraq - security.doc"),
+ new SavedByEntry("MKhan", "C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc")
+ });
+
+ /**
+ * Tests reading in the entries, comparing them against the expected entries.
+ * Then tests writing the document out and reading the entries yet again.
+ *
+ * @throws Exception if an unexpected error occurs.
+ */
+ public void testReadWrite()
+ throws Exception
+ {
+ // This document is widely available on the internet as "blair.doc".
+ // I tried stripping the content and saving the document but my version
+ // of Word (from Office XP) strips this table out.
+ InputStream stream = new BufferedInputStream(new FileInputStream(testFile));
+ HWPFDocument doc;
+ try
+ {
+ doc = new HWPFDocument(stream);
+ }
+ finally
+ {
+ stream.close();
+ }
+
+ // Check what we just read.
+ assertEquals("List of saved-by entries was not as expected",
+ expected, doc.getSavedByTable().getEntries());
+
+ // Now write the entire document out, and read it back in...
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ doc.write(byteStream);
+ InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
+ HWPFDocument copy = new HWPFDocument(copyStream);
+
+ // And check again.
+ assertEquals("List of saved-by entries was incorrect after writing",
+ expected, copy.getSavedByTable().getEntries());
+ }
+}