Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextRulerAtom.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextRulerAtom.java?rev=1823893&r1=1823892&r2=1823893&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextRulerAtom.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTextRulerAtom.java Sun Feb 11 20:39:18 2018 @@ -18,17 +18,17 @@ package org.apache.poi.hslf.record; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.io.ByteArrayOutputStream; +import java.util.List; -import junit.framework.TestCase; +import org.apache.poi.hslf.model.textproperties.HSLFTabStop; +import org.junit.Test; -/** - * Tests TextRulerAtom - * - * @author Yegor Kozlov - */ -public final class TestTextRulerAtom extends TestCase { +public final class TestTextRulerAtom { //from a real file private final byte[] data_1 = new byte[] { @@ -40,25 +40,27 @@ public final class TestTextRulerAtom ext private final byte[] data_2 = new byte[] { 0x00, 0x00, (byte)0xA6, 0x0F, 0x0A, 0x00, 0x00, 0x00, - 0x10, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01 + 0x08, 0x03, 0x00, 0x00, (byte)0xF9, 0x00, 0x41, 0x01, 0x41, 0x01 }; + @Test public void testReadRuler() { TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length); assertEquals(ruler.getNumberOfLevels(), 0); assertEquals(ruler.getDefaultTabSize(), 0); - int[] tabStops = ruler.getTabStops(); - assertNull(tabStops); + List<HSLFTabStop> tabStops = ruler.getTabStops(); + assertNotNull(tabStops); - int[] textOffsets = ruler.getTextOffsets(); - assertArrayEquals(new int[]{226, 451, 903, 1129, 1526}, textOffsets); + Integer[] textOffsets = ruler.getTextOffsets(); + assertArrayEquals(new Integer[]{226, 451, 903, 1129, 1526}, textOffsets); - int[] bulletOffsets = ruler.getBulletOffsets(); - assertArrayEquals(new int[]{117, 345, 794, 1016, 1526}, bulletOffsets); + Integer[] bulletOffsets = ruler.getBulletOffsets(); + assertArrayEquals(new Integer[]{117, 345, 794, 1016, 1526}, bulletOffsets); } + @Test public void testWriteRuler() throws Exception { TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -68,6 +70,7 @@ public final class TestTextRulerAtom ext assertArrayEquals(result, data_1); } + @Test public void testRead2() throws Exception { TextRulerAtom ruler = TextRulerAtom.getParagraphInstance(); ruler.setParagraphIndent((short)249, (short)321); @@ -75,6 +78,6 @@ public final class TestTextRulerAtom ext ruler.writeOut(out); byte[] result = out.toByteArray(); - assertArrayEquals(result, data_2); + assertArrayEquals(data_2, result); } }
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java?rev=1823893&r1=1823892&r2=1823893&view=diff ============================================================================== --- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java (original) +++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestHSLFSlideShow.java Sun Feb 11 20:39:18 2018 @@ -17,8 +17,14 @@ package org.apache.poi.hslf.usermodel; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import org.apache.poi.sl.usermodel.BaseTestSlideShow; +import org.apache.poi.sl.usermodel.SlideShow; import org.junit.Test; public class TestHSLFSlideShow extends BaseTestSlideShow { @@ -32,4 +38,25 @@ public class TestHSLFSlideShow extends B public void dummy() { assertNotNull(createSlideShow()); } + + public SlideShow<?, ?> reopen(SlideShow<?, ?> show) { + return reopen((HSLFSlideShow)show); + } + + public static HSLFSlideShow reopen(HSLFSlideShow show) { + try { + BufAccessBAOS bos = new BufAccessBAOS(); + show.write(bos); + return new HSLFSlideShow(new ByteArrayInputStream(bos.getBuf())); + } catch (IOException e) { + fail(e.getMessage()); + return null; + } + } + + private static class BufAccessBAOS extends ByteArrayOutputStream { + public byte[] getBuf() { + return buf; + } + } } Modified: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java?rev=1823893&r1=1823892&r2=1823893&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java (original) +++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShow.java Sun Feb 11 20:39:18 2018 @@ -21,18 +21,24 @@ import static org.junit.Assert.assertNot import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import java.awt.Color; +import java.awt.geom.Rectangle2D; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.List; import org.apache.poi.POIDataSamples; import org.apache.poi.sl.usermodel.PictureData.PictureType; +import org.apache.poi.sl.usermodel.TabStop.TabStopType; import org.junit.Test; public abstract class BaseTestSlideShow { protected static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); public abstract SlideShow<?, ?> createSlideShow(); + + public abstract SlideShow<?, ?> reopen(SlideShow<?, ?> show); @Test public void addPicture_File() throws IOException { @@ -92,4 +98,63 @@ public abstract class BaseTestSlideShow show.close(); } + + @Test + public void addTabStops() throws IOException { + try (final SlideShow<?,?> show1 = createSlideShow()) { + // first set the TabStops in the Master sheet + final MasterSheet<?, ?> master1 = show1.getSlideMasters().get(0); + final AutoShape<?, ?> master1_as = (AutoShape<?,?>)master1.getPlaceholder(Placeholder.BODY); + final TextParagraph<?, ?, ? extends TextRun> master1_tp = master1_as.getTextParagraphs().get(0); + master1_tp.clearTabStops(); + int i1 = 0; + for (final TabStopType tst : TabStopType.values()) { + master1_tp.addTabStops(10+i1*10, tst); + i1++; + } + + // then set it on a normal slide + final Slide<?,?> slide1 = show1.createSlide(); + final AutoShape<?, ?> slide1_as = slide1.createAutoShape(); + slide1_as.setText("abc"); + slide1_as.setAnchor(new Rectangle2D.Double(100,100,100,100)); + final TextParagraph<?, ?, ? extends TextRun> slide1_tp = slide1_as.getTextParagraphs().get(0); + slide1_tp.getTextRuns().get(0).setFontColor(new Color(0x563412)); + slide1_tp.clearTabStops(); + int i2 = 0; + for (final TabStopType tst : TabStopType.values()) { + slide1_tp.addTabStops(15+i2*5, tst); + i2++; + } + + try (final SlideShow<?, ?> show2 = reopen(show1)) { + final MasterSheet<?, ?> master2 = show2.getSlideMasters().get(0); + final AutoShape<?, ?> master2_as = (AutoShape<?,?>)master2.getPlaceholder(Placeholder.BODY); + final TextParagraph<?, ?, ? extends TextRun> master2_tp = master2_as.getTextParagraphs().get(0); + final List<? extends TabStop> master2_tabStops = master2_tp.getTabStops(); + assertNotNull(master2_tabStops); + int i3 = 0; + for (final TabStopType tst : TabStopType.values()) { + final TabStop ts = master2_tabStops.get(i3); + assertEquals(10+i3*10, ts.getPositionInPoints(), 0.0); + assertEquals(tst, ts.getType()); + i3++; + } + + + final Slide<?,?> slide2 = show2.getSlides().get(0); + final AutoShape<?,?> slide2_as = (AutoShape<?,?>)slide2.getShapes().get(0); + final TextParagraph<?, ?, ? extends TextRun> slide2_tp = slide2_as.getTextParagraphs().get(0); + final List<? extends TabStop> slide2_tabStops = slide2_tp.getTabStops(); + assertNotNull(slide2_tabStops); + int i4 = 0; + for (final TabStopType tst : TabStopType.values()) { + final TabStop ts = slide2_tabStops.get(i4); + assertEquals(15+i4*5, ts.getPositionInPoints(), 0.0); + assertEquals(tst, ts.getType()); + i4++; + } + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
