Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java?rev=1782096&r1=1782095&r2=1782096&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java
 (original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestSlideAtom.java
 Wed Feb  8 01:12:22 2017
@@ -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
                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<data_a.length; i++) {
-                       assertEquals(data_a[i],b[i]);
-               }
+               assertArrayEquals(data_a, baos.toByteArray());
        }
        
-       public void testSSSlideInfoAtom() throws Exception {
-               HSLFSlideShow ss = new HSLFSlideShow();
-               org.apache.poi.hslf.usermodel.HSLFSlide slide1 = 
ss.createSlide(), slide2 = ss.createSlide();
+    @Test
+       public void testSSSlideInfoAtom() throws IOException {
+               HSLFSlideShow ss1 = new HSLFSlideShow();
+               HSLFSlide slide1 = ss1.createSlide(), slide2 = 
ss1.createSlide();
                slide2.setHidden(true);
 
-               ByteArrayOutputStream bos = new ByteArrayOutputStream(4096);
-               ss.write(bos);
-               ByteArrayInputStream bis = new 
ByteArrayInputStream(bos.toByteArray());
-               ss = new HSLFSlideShow(bis);
-               slide1 = ss.getSlides().get(0);
-               slide2 = ss.getSlides().get(1);
+               HSLFSlideShow ss2 = 
HSLFTestDataSamples.writeOutAndReadBack(ss1);
+               slide1 = ss2.getSlides().get(0);
+               slide2 = ss2.getSlides().get(1);
                assertFalse(slide1.getHidden());
                assertTrue(slide2.getHidden());
+               ss2.close();
+               ss1.close();
        }
 }

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=1782096&r1=1782095&r2=1782096&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java 
(original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java 
Wed Feb  8 01:12:22 2017
@@ -38,6 +38,7 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedCharacterIterator.Attribute;
+import java.text.CharacterIterator;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -466,12 +467,16 @@ public final class TestBugs {
         // get slides
         for (HSLFSlide slide : ppt.getSlides()) {
             for (HSLFShape shape : slide.getShapes()) {
-                if (!(shape instanceof HSLFTextBox)) continue;
+                if (!(shape instanceof HSLFTextBox)) {
+                    continue;
+                }
                 HSLFTextBox tb = (HSLFTextBox) shape;
                 // work with TextBox
                 String str = tb.getText();
 
-                if (!str.contains("$$DATE$$")) continue;
+                if (!str.contains("$$DATE$$")) {
+                    continue;
+                }
                 str = str.replace("$$DATE$$", new Date().toString());
                 tb.setText(str);
 
@@ -512,7 +517,9 @@ public final class TestBugs {
 
         int tha = 0;
         for (Record r : s1.getSlideRecords()) {
-            if (r instanceof TextHeaderAtom) tha++;
+            if (r instanceof TextHeaderAtom) {
+                tha++;
+            }
         }
         assertEquals(2, tha);
 
@@ -525,7 +532,9 @@ public final class TestBugs {
         // Will have skipped the empty one
         int str = 0;
         for (List<HSLFTextParagraph> 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();

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java?rev=1782096&r1=1782095&r2=1782096&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
 (original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestCounts.java
 Wed Feb  8 01:12:22 2017
@@ -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<HSLFSlide> slides = ss.getSlides();
+public final class TestCounts {
+    @Test
+       public void testSheetsCount() throws IOException {
+           HSLFSlideShow ppt = 
HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+           
+               List<HSLFSlide> slides = ppt.getSlides();
                // Two sheets - master sheet is separate
                assertEquals(2, slides.size());
 
@@ -55,10 +49,15 @@ public final class TestCounts extends Te
                // 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<HSLFNotes> notes = ss.getNotes();
+    @Test
+    public void testNotesCount() throws IOException {
+        HSLFSlideShow ppt = 
HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+        
+               List<HSLFNotes> 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 Te
                // 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();
        }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to