From a002b7287e84ff8d90d49218c764fb75ce4aa118 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Wed, 8 Feb 2017 01:12:22 +0000 Subject: #60625 - Rendering issue with background and shape overlayed by image git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1782096 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/record/TestSlideAtom.java | 65 ++++++++++++---------- .../org/apache/poi/hslf/usermodel/TestBugs.java | 26 ++++++--- .../org/apache/poi/hslf/usermodel/TestCounts.java | 39 ++++++------- 3 files changed, 73 insertions(+), 57 deletions(-) (limited to 'src/scratchpad/testcases/org/apache') diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java index 7e6137ba47..c32d37bd65 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java @@ -17,36 +17,43 @@ package org.apache.poi.hslf.record; -import java.io.ByteArrayInputStream; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayOutputStream; +import java.io.IOException; -import org.apache.poi.hslf.record.SlideAtom.SSlideLayoutAtom; +import org.apache.poi.hslf.HSLFTestDataSamples; +import org.apache.poi.hslf.record.SlideAtomLayout.SlideLayoutType; +import org.apache.poi.hslf.usermodel.HSLFSlide; import org.apache.poi.hslf.usermodel.HSLFSlideShow; - -import junit.framework.TestCase; +import org.junit.Test; /** * Tests that SlideAtom works properly - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestSlideAtom extends TestCase { +public final class TestSlideAtom { // From a real file - private final byte[] data_a = new byte[] { 1, 0, 0xEF-256, 3, 0x18, 0, 0, 0, + private static final byte[] data_a = new byte[] { 1, 0, 0xEF-256, 3, 0x18, 0, 0, 0, 0, 0, 0, 0, 0x0F, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80-256, 0, 1, 0, 0, 7, 0, 0x0C, 0x30 }; - public void testRecordType() { + @Test + public void testRecordType() { SlideAtom sa = new SlideAtom(data_a, 0, data_a.length); assertEquals(1007l, sa.getRecordType()); } + + @Test public void testFlags() { SlideAtom sa = new SlideAtom(data_a, 0, data_a.length); // First 12 bytes are a SSlideLayoutAtom, checked elsewhere // Check the IDs - assertEquals(0x80000000, sa.getMasterID()); + assertEquals(SlideAtom.USES_MASTER_SLIDE_ID, sa.getMasterID()); assertEquals(256, sa.getNotesID()); // Check the flags @@ -54,39 +61,37 @@ public final class TestSlideAtom extends TestCase { assertEquals(true, sa.getFollowMasterScheme()); assertEquals(true, sa.getFollowMasterBackground()); } - public void testSSlideLayoutAtom() { + + @Test + public void testSSlideLayoutAtom() { SlideAtom sa = new SlideAtom(data_a, 0, data_a.length); - SSlideLayoutAtom ssla = sa.getSSlideLayoutAtom(); + SlideAtomLayout ssla = sa.getSSlideLayoutAtom(); - assertEquals(0, ssla.getGeometryType()); + assertEquals(SlideLayoutType.TITLE_SLIDE, ssla.getGeometryType()); - // Should also check the placehold IDs at some point + // Should also check the placeholder IDs at some point } - public void testWrite() throws Exception { + @Test + public void testWrite() throws IOException { SlideAtom sa = new SlideAtom(data_a, 0, data_a.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(); sa.writeOut(baos); - byte[] b = baos.toByteArray(); - - assertEquals(data_a.length, b.length); - for(int i=0; i tr : _slides.get(0).getTextParagraphs()) { - if (! tr.get(0).isDrawingBased()) str++; + if (! tr.get(0).isDrawingBased()) { + str++; + } } assertEquals(2, str); @@ -758,7 +767,7 @@ public final class TestBugs { public void bug47904() throws IOException { HSLFSlideShow ppt1 = new HSLFSlideShow(); HSLFSlideMaster sm = ppt1.getSlideMasters().get(0); - HSLFAutoShape as = (HSLFAutoShape)sm.getShapes().get(0); + HSLFAutoShape as = (HSLFAutoShape)sm.getPlaceholder(Placeholder.TITLE); HSLFTextParagraph tp = as.getTextParagraphs().get(0); HSLFTextRun tr = tp.getTextRuns().get(0); tr.setFontFamily("Tahoma"); @@ -766,8 +775,9 @@ public final class TestBugs { tr.setFontSize(44.); tr.setFontColor(Color.red); tp.setTextAlign(TextAlign.RIGHT); - ppt1.createSlide().addTitle().setText("foobaa"); - + HSLFTextBox tb = ppt1.createSlide().addTitle(); + tb.setText("foobaa"); + HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1); ppt1.close(); @@ -877,7 +887,7 @@ public final class TestBugs { StringBuffer sb = new StringBuffer(); for (char c = iterator.first(); - c != AttributedCharacterIterator.DONE; + c != CharacterIterator.DONE; c = iterator.next()) { sb.append(c); attributes = iterator.getAttributes(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java index a52cee4129..baed0386d3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java @@ -18,29 +18,23 @@ package org.apache.poi.hslf.usermodel; -import java.util.List; +import static org.junit.Assert.assertEquals; -import junit.framework.TestCase; +import java.io.IOException; +import java.util.List; -import org.apache.poi.POIDataSamples; +import org.apache.poi.hslf.HSLFTestDataSamples; +import org.junit.Test; /** * Tests that SlideShow returns the right number of Sheets and MetaSheets - * - * @author Nick Burch (nick at torchbox dot com) */ -public final class TestCounts extends TestCase { - // SlideShow primed on the test data - private final HSLFSlideShow ss; - - public TestCounts() throws Exception { - POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); - HSLFSlideShowImpl hss = new HSLFSlideShowImpl(slTests.openResourceAsStream("basic_test_ppt_file.ppt")); - ss = new HSLFSlideShow(hss); - } - - public void testSheetsCount() { - List slides = ss.getSlides(); +public final class TestCounts { + @Test + public void testSheetsCount() throws IOException { + HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); + + List slides = ppt.getSlides(); // Two sheets - master sheet is separate assertEquals(2, slides.size()); @@ -55,10 +49,15 @@ public final class TestCounts extends TestCase { // These are slides 1+2 -> 256+257 assertEquals(256, slides.get(0)._getSheetNumber()); assertEquals(257, slides.get(1)._getSheetNumber()); + + ppt.close(); } - public void testNotesCount() { - List notes = ss.getNotes(); + @Test + public void testNotesCount() throws IOException { + HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt"); + + List notes = ppt.getNotes(); // Two sheets -> two notes // Note: there are also notes on the slide master //assertEquals(3, notes.length); // When we do slide masters @@ -74,5 +73,7 @@ public final class TestCounts extends TestCase { // They happen to go between the two slides in Ref terms assertEquals(5, notes.get(0)._getSheetRefId()); assertEquals(7, notes.get(1)._getSheetRefId()); + + ppt.close(); } } -- cgit v1.2.3