poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r449983 - in /jakarta/poi/trunk/src/scratchpad: src/org/apache/poi/hslf/record/ testcases/org/apache/poi/hslf/data/ testcases/org/apache/poi/hslf/record/ testcases/org/apache/poi/hslf/usermodel/
Date Tue, 26 Sep 2006 11:19:31 GMT
Author: nick
Date: Tue Sep 26 04:19:30 2006
New Revision: 449983

URL: http://svn.apache.org/viewvc?view=rev&rev=449983
Log:
Handle the case where a StyleTextPropAtom has a mask that codes for more properties than we
have data for (+tests for this)

Added:
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt  
(with props)
Modified:
    jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
    jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java?view=diff&rev=449983&r1=449982&r2=449983
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java
Tue Sep 26 04:19:30 2006
@@ -266,6 +266,7 @@
 			pos += 4;
 
 			// Now make sense of those properties
+			// (Assuming we actually have some)
 			TextPropCollection thisCollection = new TextPropCollection(textLen, no_val);
 			int chSize = thisCollection.buildTextPropList(
 					charFlags, characterTextPropTypes, rawContents, pos);
@@ -411,8 +412,15 @@
 			// For each possible entry, see if we match the mask
 			// If we do, decode that, save it, and shuffle on
 			for(int i=0; i<potentialProperties.length; i++) {
+				// Check there's still data left to read
+				if(dataOffset+bytesPassed >= data.length) {
+					// Out of data, can't be any more properties to go
+					return bytesPassed;
+				}
+				
+				// Check if this property is found in the mask
 				if((containsField & potentialProperties[i].getMask()) != 0) {
-					// Bingo, contained
+					// Bingo, data contains this property
 					TextProp prop = (TextProp)potentialProperties[i].clone();
 					int val = 0;
 					if(prop.getSize() == 2) {

Added: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt?view=auto&rev=449983
==============================================================================
Binary file - no diff available.

Propchange: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/data/iisd_report.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java?view=diff&rev=449983&r1=449982&r2=449983
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java
Tue Sep 26 04:19:30 2006
@@ -19,7 +19,9 @@
 
 package org.apache.poi.hslf.record;
 
+import org.apache.poi.hslf.HSLFSlideShow;
 import org.apache.poi.hslf.record.StyleTextPropAtom.*;
+import org.apache.poi.hslf.usermodel.SlideShow;
 
 import junit.framework.TestCase;
 import java.io.ByteArrayOutputStream;
@@ -31,7 +33,7 @@
  * @author Nick Burch (nick at torchbox dot com)
  */
 public class TestStyleTextPropAtom extends TestCase {
-	// From a real file: a paragraph with 4 different styles
+	/** From a real file: a paragraph with 4 different styles */
 	private byte[] data_a = new byte[] { 
 	  0, 0, 0xA1-256, 0x0F, 0x2A, 0, 0, 0,
       0x36, 00, 00, 00, // paragraph is 54 long 
@@ -48,12 +50,14 @@
 	};
 	private int data_a_text_len = 54;
 
-	// From a real file: 4 paragraphs with text in 4 different styles:
-	// left aligned+bold (30)
-	// centre aligned+italic+blue (28)
-	// right aligned+red (25)
-	// left aligned+underlined+larger font size (96)
-	// left aligned+underlined+larger font size+red (1)
+	/** 
+	 * From a real file: 4 paragraphs with text in 4 different styles:
+	 * left aligned+bold (30)
+	 * centre aligned+italic+blue (28)
+	 * right aligned+red (25)
+	 * left aligned+underlined+larger font size (96)
+	 * left aligned+underlined+larger font size+red (1)
+	 */
 	private byte[] data_b = new byte[] { 
 		0, 0, 0xA1-256, 0x0F, 0x80-256, 0, 0, 0, 
 		0x1E, 00, 00, 00,     // paragraph is 30 long 
@@ -104,12 +108,32 @@
 	};
 	private int data_b_text_len = 0xB3;
 	
+	/**
+	 * From a real file. Has a mask with more bits
+	 *  set than it actually has data for. Shouldn't do,
+	 *  but some real files do :(
+	 */
+	private byte[] data_c = new byte[] {
+		0, 0, -95, 15, 62, 0, 0, 0,
+		123, 0, 0, 0, 0, 0, 48, 8, 
+		10, 0, 1, 0, 0, 0, 0, 0, 
+		1, 0, 2, 0, 1, 0, 0, 0, 
+		0, 0, 48, 0, 10, 0, 1, 0, 
+		0, 0, 0, 0, 2, 0, 123, 0, 
+		0, 0, 0, 0, 3, 0, 1, 0, 
+		28, 0, 1, 0, 0, 0, 0, 0, 
+		3, 0, 1, 0, 24, 0
+	};
+	private int data_c_text_len = 123;
 
+	
     public void testRecordType() throws Exception {
 		StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
 		StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
+		StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
 		assertEquals(4001l, stpa.getRecordType());
 		assertEquals(4001l, stpb.getRecordType());
+		assertEquals(4001l, stpc.getRecordType());
 	}
 
 
@@ -662,5 +686,16 @@
 			//System.out.println(i + "\t" + b[i] + "\t" + data_b[i] + "\t" + Integer.toHexString(b[i])
);
 			assertEquals(data_b[i],b[i]);
 		}
+	}
+	
+	
+	public void testNotEnoughDataProp() throws Exception {
+		// We don't have enough data in the record to cover
+		//  all the properties the mask says we have
+		// Make sure we just do the best we can
+		StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
+		stpc.setParentTextSize(data_c_text_len);
+		
+		// If we get here, we didn't break
 	}
 }

Modified: jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java?view=diff&rev=449983&r1=449982&r2=449983
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
(original)
+++ jakarta/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestSheetText.java
Tue Sep 26 04:19:30 2006
@@ -58,4 +58,34 @@
 			assertEquals(expectText[i], slideTwo.getTextRuns()[i].getText());
 		}
 	}
+	
+	/**
+	 * Check we can still get the text from a file where the
+	 *  TextProps don't have enough data.
+	 * (Make sure we don't screw up / throw an exception etc)
+	 */
+	public void testWithShortTextPropData() throws Exception {
+		String dirname = System.getProperty("HSLF.testdata.path");
+		String filename = dirname + "/iisd_report.ppt";
+		HSLFSlideShow hss = new HSLFSlideShow(filename);
+		SlideShow sss = new SlideShow(hss);
+		
+		// Should come out with 10 slides, no notes
+		assertEquals(10, sss.getSlides().length);
+		assertEquals(0, sss.getNotes().length);
+		
+		// Check text on first slide
+		Slide s = sss.getSlides()[0];
+		String exp = 
+			"Realizing the Development Dividend:\n" +
+			"Community Capacity Building and CDM.\n" +
+			"Can they co-exist?\n\n" +
+			"Gay Harley\n" +
+			"Clean Development Alliance\n" +
+			"COP 11 – MOP 1\n" +
+			"December 5, 2005\n";
+
+		assertEquals(1, s.getTextRuns().length);
+		assertEquals(exp, s.getTextRuns()[0].getText());
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/


Mime
View raw message