poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r711755 [2/2] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/constant/ src/java/org/apache/poi/hssf/record/cont/ src...
Date Thu, 06 Nov 2008 02:38:08 GMT
Modified: poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
Wed Nov  5 18:38:06 2008
@@ -24,7 +24,7 @@
  * 
  * @author Josh Micich
  */
-public final class LittleEndianByteArrayOutputStream implements LittleEndianOutput {
+public final class LittleEndianByteArrayOutputStream implements LittleEndianOutput, DelayableLittleEndianOutput
{
 	private final byte[] _buf;
 	private final int _endIndex;
 	private int _writeIndex;
@@ -89,4 +89,10 @@
 	public int getWriteIndex() {
 		return _writeIndex;
 	}
+	public LittleEndianOutput createDelayedOutput(int size) {
+		checkPosition(size);
+		LittleEndianOutput result = new LittleEndianByteArrayOutputStream(_buf, _writeIndex, _writeIndex+size);
+		_writeIndex += size;
+		return result;
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java Wed Nov  5 18:38:06 2008
@@ -163,6 +163,15 @@
 	}
 
 	/**
+	 * @return the number of bytes that would be written by {@link #writeUnicodeString(LittleEndianOutput,
String)}
+	 */
+	public static int getEncodedSize(String value) {
+		int result = 2 + 1;
+		result += value.length() * (StringUtil.hasMultibyte(value) ? 2 : 1);
+		return result;
+	}
+
+	/**
 	 * Takes a unicode (java) string, and returns it as 8 bit data (in ISO-8859-1
 	 * codepage).
 	 * (In Excel terms, write compressed 8 bit unicode)

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Wed Nov 
5 18:38:06 2008
@@ -196,10 +196,14 @@
         Document doc = ppt.getDocumentRecord();
         EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
         EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer,
EscherContainerRecord.BSTORE_CONTAINER);
-
+        if(bstore == null) {
+            logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found
");
+            return null;
+        }
         List lst = bstore.getChildRecords();
         int idx = getPictureIndex();
         if (idx == 0){
+            logger.log(POILogger.DEBUG, "picture index was not found, returning ");
             return null;
         } else {
             return (EscherBSERecord)lst.get(idx-1);
@@ -263,7 +267,7 @@
         ShapePainter.paint(this, graphics);
 
         PictureData data = getPictureData();
-        data.draw(graphics, this);
+        if(data != null) data.draw(graphics, this);
 
         graphics.setTransform(at);
     }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/model/TableCell.java Wed Nov
 5 18:38:06 2008
@@ -56,8 +56,8 @@
         super(parent);
 
         setShapeType(ShapeTypes.Rectangle);
-        _txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
-        _txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
+        //_txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
+        //_txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
     }
 
     protected EscherContainerRecord createSpContainer(boolean isChild){

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
(original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java
Wed Nov  5 18:38:06 2008
@@ -20,9 +20,12 @@
 
 import java.io.FileOutputStream;
 import java.io.File;
+import java.io.IOException;
 import java.awt.*;
+import java.awt.image.BufferedImage;
 
 import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.PictureData;
 import org.apache.poi.hslf.HSLFSlideShow;
 import org.apache.poi.ddf.EscherBSERecord;
 
@@ -70,4 +73,24 @@
 
     }
 
+    /**
+     * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER
+     * was not found. The correct behaviour is to return null.
+     */
+    public void test46122() throws IOException {
+        SlideShow ppt = new SlideShow();
+        Slide slide = ppt.createSlide();
+
+        Picture pict = new Picture(-1); //index to non-existing picture data
+        pict.setSheet(slide);
+        PictureData data = pict.getPictureData();
+        assertNull(data);
+
+        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
+        Graphics2D graphics = img.createGraphics();
+        pict.draw(graphics);
+
+        assertTrue("no errors rendering Picture with null data", true);
+    }
+
 }

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java Wed
Nov  5 18:38:06 2008
@@ -24,6 +24,7 @@
 
 import org.apache.poi.hslf.usermodel.SlideShow;
 import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.record.TextHeaderAtom;
 
 /**
  * Test <code>Table</code> object.
@@ -43,6 +44,10 @@
         Table tbl = new Table(2, 5);
         slide.addShape(tbl);
 
+        TableCell cell = tbl.getCell(0, 0);
+        //table cells have type=TextHeaderAtom.OTHER_TYPE, see bug #46033
+        assertEquals(TextHeaderAtom.OTHER_TYPE, cell.getTextRun().getRunType());
+
         assertTrue(slide.getShapes()[0] instanceof Table);
         Table tbl2 = (Table)slide.getShapes()[0];
         assertEquals(tbl.getNumberOfColumns(), tbl2.getNumberOfColumns());

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java Wed
Nov  5 18:38:06 2008
@@ -48,7 +48,6 @@
         byte[]   data    = {
             0, 6, 5, 0, -2, 28, -51, 7, -55, 64, 0, 0, 6, 1, 0, 0
         };
-        short    size    = 16;
         Record[] record  = RecordFactory.createRecord(TestcaseRecordInputStream.create(recType,
data));
 
         assertEquals(BOFRecord.class.getName(),
@@ -64,7 +63,6 @@
         assertEquals(5, bofRecord.getType());
         assertEquals(1536, bofRecord.getVersion());
         recType = MMSRecord.sid;
-        size    = 2;
         data    = new byte[]
         {
             0, 0
@@ -93,7 +91,6 @@
         byte[]   data    = {
             0, 0, 0, 0, 21, 0, 0, 0, 0, 0
         };
-        short    size    = 10;
         Record[] record  = RecordFactory.createRecord(TestcaseRecordInputStream.create(recType,
data));
 
         assertEquals(NumberRecord.class.getName(),
@@ -154,34 +151,34 @@
      */
     public void testMixedContinue() throws Exception {
         /**
-         *  Taken from a real test sample file 39512.xls. See Bug 39512 for details.
+         *  Adapted from a real test sample file 39512.xls (Offset 0x4854). 
+         *  See Bug 39512 for details.
          */
         String dump =
                 //OBJ
-                "5D, 00, 48, 00, 15, 00, 12, 00, 0C, 00, 3C, 00, 11, 00, A0, 2E, 03, 01,
CC, 42, " +
-                "CF, 00, 00, 00, 00, 00, 0A, 00, 0C, 00, 00, 00, 00, 00, 00, 00, 00, 00,
00, 00, " +
-                "03, 00, 0B, 00, 06, 00, 28, 01, 03, 01, 00, 00, 12, 00, 08, 00, 00, 00,
00, 00, " +
-                "00, 00, 03, 00, 11, 00, 04, 00, 3D, 00, 00, 00, 00, 00, 00, 00, " +
+                "5D 00 48 00 15 00 12 00 0C 00 3C 00 11 00 A0 2E 03 01 CC 42 " +
+                "CF 00 00 00 00 00 0A 00 0C 00 00 00 00 00 00 00 00 00 00 00 " +
+                "03 00 0B 00 06 00 28 01 03 01 00 00 12 00 08 00 00 00 00 00 " +
+                "00 00 03 00 11 00 04 00 3D 00 00 00 00 00 00 00 " +
                  //MSODRAWING
-                "EC, 00, 08, 00, 00, 00, 0D, F0, 00, 00, 00, 00, " +
-                //TXO
-                "B6, 01, 12, 00, 22, 02, 00, 00, 00, 00, 00, 00, 00, 00, 10, 00, 10, 00,
00, 00, " +
-                "00, 00, 3C, 00, 21, 00, 01, 4F, 00, 70, 00, 74, 00, 69, 00, 6F, 00, 6E,
00, 20, " +
-                "00, 42, 00, 75, 00, 74, 00, 74, 00, 6F, 00, 6E, 00, 20, 00, 33, 00, 39,
00, 3C, " +
-                "00, 10, 00, 00, 00, 05, 00, 00, 00, 00, 00, 10, 00, 00, 00, 00, 00, 00,
00, " +
-                //CONTINUE
-                "3C, 00, 7E, 00, 0F, 00, 04, F0, 7E, 00, 00, 00, 92, 0C, 0A, F0, 08, 00,
00, 00, " +
-                "3D, 04, 00, 00, 00, 0A, 00, 00, A3, 00, 0B, F0, 3C, 00, 00, 00, 7F, 00,
00, 01, " +
-                "00, 01, 80, 00, 8C, 01, 03, 01, 85, 00, 01, 00, 00, 00, 8B, 00, 02, 00,
00, 00, " +
-                "BF, 00, 08, 00, 1A, 00, 7F, 01, 29, 00, 29, 00, 81, 01, 41, 00, 00, 08,
BF, 01, " +
-                "00, 00, 10, 00, C0, 01, 40, 00, 00, 08, FF, 01, 00, 00, 08, 00, 00, 00,
10, F0, " +
-                "12, 00, 00, 00, 02, 00, 02, 00, A0, 03, 18, 00, B5, 00, 04, 00, 30, 02,
1A, 00, " +
-                "00, 00, 00, 00, 11, F0, 00, 00, 00, 00, " +
+                "EC 00 08 00 00 00 0D F0 00 00 00 00 " +
+                //TXO (and 2 trailing CONTINUE records)
+                "B6 01 12 00 22 02 00 00 00 00 00 00 00 00 10 00 10 00 00 00 00 00 " +
+                "3C 00 11 00 00 4F 70 74 69 6F 6E 20 42 75 74 74 6F 6E 20 33 39 " +
+                "3C 00 10 00 00 00 05 00 00 00 00 00 10 00 00 00 00 00 00 00 " +
+                // another CONTINUE
+                "3C 00 7E 00 0F 00 04 F0 7E 00 00 00 92 0C 0A F0 08 00 00 00 " +
+                "3D 04 00 00 00 0A 00 00 A3 00 0B F0 3C 00 00 00 7F 00 00 01 " +
+                "00 01 80 00 8C 01 03 01 85 00 01 00 00 00 8B 00 02 00 00 00 " +
+                "BF 00 08 00 1A 00 7F 01 29 00 29 00 81 01 41 00 00 08 BF 01 " +
+                "00 00 10 00 C0 01 40 00 00 08 FF 01 00 00 08 00 00 00 10 F0 " +
+                "12 00 00 00 02 00 02 00 A0 03 18 00 B5 00 04 00 30 02 1A 00 " +
+                "00 00 00 00 11 F0 00 00 00 00 " +
                 //OBJ
-                "5D, 00, 48, 00, 15, 00, 12, 00, 0C, 00, 3D, 00, 11, 00, 8C, 01, 03, 01,
C8, 59, CF, 00, 00, " +
-                "00, 00, 00, 0A, 00, 0C, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 03,
00, 0B, 00, 06, 00, " +
-                "7C, 16, 03, 01, 00, 00, 12, 00, 08, 00, 00, 00, 00, 00, 00, 00, 03, 00,
11, 00, 04, 00, 01, " +
-                "00, 00, 00, 00, 00, 00, 00";
+                "5D 00 48 00 15 00 12 00 0C 00 3D 00 11 00 8C 01 03 01 C8 59 CF 00 00 " +
+                "00 00 00 0A 00 0C 00 00 00 00 00 00 00 00 00 00 00 03 00 0B 00 06 00 " +
+                "7C 16 03 01 00 00 12 00 08 00 00 00 00 00 00 00 03 00 11 00 04 00 01 " +
+                "00 00 00 00 00 00 00";
         byte[] data = HexRead.readFromString(dump);
 
         List records = RecordFactory.createRecords(new ByteArrayInputStream(data));

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTRecordSizeCalculator.java
Wed Nov  5 18:38:06 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,133 +14,106 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
 import org.apache.poi.util.IntMapper;
 
 /**
  * Tests that records size calculates correctly.
- *
+ * 
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class TestSSTRecordSizeCalculator
-        extends TestCase
-{
-    private static final String SMALL_STRING = "Small string";
-    private static final int COMPRESSED_PLAIN_STRING_OVERHEAD = 3;
-//    private List recordLengths;
-    private IntMapper strings;
-    private static final int OPTION_FIELD_SIZE = 1;
-
-    public TestSSTRecordSizeCalculator( String s )
-    {
-        super( s );
-    }
-
-    public void testBasic()
-            throws Exception
-    {
-        strings.add(makeUnicodeString(SMALL_STRING));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD + COMPRESSED_PLAIN_STRING_OVERHEAD + SMALL_STRING.length(),
-                calculator.getRecordSize());
-    }
-
-    public void testBigStringAcrossUnicode()
-            throws Exception
-    {
-        String bigString = new String(new char[SSTRecord.MAX_DATA_SPACE + 100]);
-        strings.add(makeUnicodeString(bigString));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + SSTRecord.MAX_DATA_SPACE
-                + SSTRecord.STD_RECORD_OVERHEAD
-                + OPTION_FIELD_SIZE
-                + 100,
-                calculator.getRecordSize());
-    }
-
-    public void testPerfectFit()
-            throws Exception
-    {
-        String perfectFit = new String(new char[SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD]);
-        strings.add(makeUnicodeString(perfectFit));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + perfectFit.length(),
-                calculator.getRecordSize());
-    }
-
-    public void testJustOversized()
-            throws Exception
-    {
-        String tooBig = new String(new char[SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD
+ 1]);
-        strings.add(makeUnicodeString(tooBig));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + tooBig.length() - 1
-                // continue record
-                + SSTRecord.STD_RECORD_OVERHEAD
-                + OPTION_FIELD_SIZE
-                + 1,
-                calculator.getRecordSize());
-
-    }
-
-    public void testSecondStringStartsOnNewContinuation()
-            throws Exception
-    {
-        String perfectFit = new String(new char[SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD]);
-        strings.add(makeUnicodeString(perfectFit));
-        strings.add(makeUnicodeString(SMALL_STRING));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD
-                + SSTRecord.MAX_DATA_SPACE
-                // second string
-                + SSTRecord.STD_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + SMALL_STRING.length(),
-                calculator.getRecordSize());
-    }
-
-    public void testHeaderCrossesNormalContinuePoint()
-            throws Exception
-    {
-        String almostPerfectFit = new String(new char[SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD
- 2]);
-        strings.add(makeUnicodeString(almostPerfectFit));
-        String oneCharString = new String(new char[1]);
-        strings.add(makeUnicodeString(oneCharString));
-        SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(strings);
-        assertEquals(SSTRecord.SST_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + almostPerfectFit.length()
-                // second string
-                + SSTRecord.STD_RECORD_OVERHEAD
-                + COMPRESSED_PLAIN_STRING_OVERHEAD
-                + oneCharString.length(),
-                calculator.getRecordSize());
-
-    }
-
-
-    public void setUp()
-    {
-        strings = new IntMapper();
-    }
-
-
-    private UnicodeString makeUnicodeString( String s )
-    {
-      UnicodeString st = new UnicodeString(s);
-      st.setOptionFlags((byte)0);
-      return st;
-    }
-
+public final class TestSSTRecordSizeCalculator extends TestCase {
+	private static final String SMALL_STRING = "Small string";
+	private static final int COMPRESSED_PLAIN_STRING_OVERHEAD = 3;
+	private static final int OPTION_FIELD_SIZE = 1;
+	
+	private final IntMapper strings = new IntMapper();
+
+	
+	private void confirmSize(int expectedSize) {
+		ContinuableRecordOutput cro = ContinuableRecordOutput.createForCountingOnly();
+		SSTSerializer ss = new SSTSerializer(strings, 0, 0);
+		ss.serialize(cro);
+		assertEquals(expectedSize, cro.getTotalSize());
+	}
+
+	public void testBasic() {
+		strings.add(makeUnicodeString(SMALL_STRING));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ SMALL_STRING.length());
+	}
+
+	public void testBigStringAcrossUnicode() {
+		int bigString = SSTRecord.MAX_DATA_SPACE + 100;
+		strings.add(makeUnicodeString(bigString));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ SSTRecord.MAX_DATA_SPACE
+				+ SSTRecord.STD_RECORD_OVERHEAD
+				+ OPTION_FIELD_SIZE
+				+ 100);
+	}
+
+	public void testPerfectFit() {
+		int perfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
+		strings.add(makeUnicodeString(perfectFit));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ perfectFit);
+	}
+
+	public void testJustOversized() {
+		int tooBig = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD + 1;
+		strings.add(makeUnicodeString(tooBig));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ tooBig - 1
+				// continue record
+				+ SSTRecord.STD_RECORD_OVERHEAD
+				+ OPTION_FIELD_SIZE + 1);
+
+	}
+
+	public void testSecondStringStartsOnNewContinuation() {
+		int perfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD;
+		strings.add(makeUnicodeString(perfectFit));
+		strings.add(makeUnicodeString(SMALL_STRING));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ SSTRecord.MAX_DATA_SPACE
+				// second string
+				+ SSTRecord.STD_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ SMALL_STRING.length());
+	}
+
+	public void testHeaderCrossesNormalContinuePoint() {
+		int almostPerfectFit = SSTRecord.MAX_DATA_SPACE - COMPRESSED_PLAIN_STRING_OVERHEAD - 2;
+		strings.add(makeUnicodeString(almostPerfectFit));
+		String oneCharString = new String(new char[1]);
+		strings.add(makeUnicodeString(oneCharString));
+		confirmSize(SSTRecord.SST_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ almostPerfectFit
+				// second string
+				+ SSTRecord.STD_RECORD_OVERHEAD
+				+ COMPRESSED_PLAIN_STRING_OVERHEAD
+				+ oneCharString.length());
+
+	}
+	private static UnicodeString makeUnicodeString(int size) {
+		String s = new String(new char[size]);
+		return makeUnicodeString(s);
+	}
+
+	private static UnicodeString makeUnicodeString(String s) {
+		UnicodeString st = new UnicodeString(s);
+		st.setOptionFlags((byte) 0);
+		return st;
+	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestStringRecord.java Wed
Nov  5 18:38:06 2008
@@ -18,6 +18,12 @@
 package org.apache.poi.hssf.record;
 
 
+import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
+import org.apache.poi.util.LittleEndianInput;
+
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 /**
@@ -28,29 +34,66 @@
  * @author Glen Stampoultzis (glens at apache.org)
  */
 public final class TestStringRecord extends TestCase {
-    byte[] data = new byte[] {
-        (byte)0x0B,(byte)0x00,   // length
-        (byte)0x00,              // option
-        // string
-        (byte)0x46,(byte)0x61,(byte)0x68,(byte)0x72,(byte)0x7A,(byte)0x65,(byte)0x75,(byte)0x67,(byte)0x74,(byte)0x79,(byte)0x70
-    };
-
-    public void testLoad() {
-
-        StringRecord record = new StringRecord(TestcaseRecordInputStream.create(0x207, data));
-        assertEquals( "Fahrzeugtyp", record.getString());
-
-        assertEquals( 18, record.getRecordSize() );
-    }
-
-    public void testStore()
-    {
-        StringRecord record = new StringRecord();
-        record.setString("Fahrzeugtyp");
-
-        byte [] recordBytes = record.serialize();
-        assertEquals(recordBytes.length - 4, data.length);
-        for (int i = 0; i < data.length; i++)
-            assertEquals("At offset " + i, data[i], recordBytes[i+4]);
-    }
+	private static final byte[] data = HexRead.readFromString(
+			"0B 00 " + // length
+			"00 " +    // option
+			// string
+			"46 61 68 72 7A 65 75 67 74 79 70"
+	);
+
+	public void testLoad() {
+
+		StringRecord record = new StringRecord(TestcaseRecordInputStream.create(0x207, data));
+		assertEquals( "Fahrzeugtyp", record.getString());
+
+		assertEquals( 18, record.getRecordSize() );
+	}
+
+	public void testStore() {
+		StringRecord record = new StringRecord();
+		record.setString("Fahrzeugtyp");
+
+		byte [] recordBytes = record.serialize();
+		assertEquals(recordBytes.length - 4, data.length);
+		for (int i = 0; i < data.length; i++)
+			assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+	}
+    
+	public void testContinue() {
+		int MAX_BIFF_DATA = RecordInputStream.MAX_RECORD_DATA_SIZE;
+		int TEXT_LEN = MAX_BIFF_DATA + 1000; // deliberately over-size
+		String textChunk = "ABCDEGGHIJKLMNOP"; // 16 chars
+		StringBuffer sb = new StringBuffer(16384);
+		while (sb.length() < TEXT_LEN) {
+			sb.append(textChunk);
+		}
+		sb.setLength(TEXT_LEN);
+
+		StringRecord sr = new StringRecord();
+		sr.setString(sb.toString());
+		byte[] ser = sr.serialize();
+		assertEquals(StringRecord.sid, LittleEndian.getUShort(ser, 0));
+		if (LittleEndian.getUShort(ser, 2) > MAX_BIFF_DATA) {
+			throw new AssertionFailedError(
+					"StringRecord should have been split with a continue record");
+		}
+		// Confirm expected size of first record, and ushort strLen.
+		assertEquals(MAX_BIFF_DATA, LittleEndian.getUShort(ser, 2));
+		assertEquals(TEXT_LEN, LittleEndian.getUShort(ser, 4));
+
+		// Confirm first few bytes of ContinueRecord
+		LittleEndianInput crIn = new LittleEndianByteArrayInputStream(ser, (MAX_BIFF_DATA + 4));
+		int nCharsInFirstRec = MAX_BIFF_DATA - (2 + 1); // strLen, optionFlags
+		int nCharsInSecondRec = TEXT_LEN - nCharsInFirstRec;
+		assertEquals(ContinueRecord.sid, crIn.readUShort());
+		assertEquals(1 + nCharsInSecondRec, crIn.readUShort());
+		assertEquals(0, crIn.readUByte());
+		assertEquals('N', crIn.readUByte());
+		assertEquals('O', crIn.readUByte());
+
+		// re-read and make sure string value is the same
+		RecordInputStream in = TestcaseRecordInputStream.create(ser);
+		StringRecord sr2 = new StringRecord(in);
+		assertEquals(sb.toString(), sr2.getString());
+	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSupBookRecord.java Wed
Nov  5 18:38:06 2008
@@ -69,10 +69,10 @@
         assertEquals( 34, record.getRecordSize() );  //sid+size+data
         
         assertEquals("testURL", record.getURL());
-        UnicodeString[] sheetNames = record.getSheetNames();
+        String[] sheetNames = record.getSheetNames();
         assertEquals(2, sheetNames.length);
-        assertEquals("Sheet1", sheetNames[0].getString());
-        assertEquals("Sheet2", sheetNames[1].getString());
+        assertEquals("Sheet1", sheetNames[0]);
+        assertEquals("Sheet2", sheetNames[1]);
     }
     
     /**
@@ -97,11 +97,8 @@
     }   
     
     public void testStoreER() {
-        UnicodeString url = new UnicodeString("testURL");
-        UnicodeString[] sheetNames = {
-                new UnicodeString("Sheet1"),
-                new UnicodeString("Sheet2"),
-        };
+        String url = "testURL";
+        String[] sheetNames = { "Sheet1", "Sheet2", };
         SupBookRecord record = SupBookRecord.createExternalReferences(url, sheetNames);
 
         TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize());

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
Wed Nov  5 18:38:06 2008
@@ -44,9 +44,9 @@
         "00 00" +
         "00 00 " +
         "3C 00 " + // ContinueRecord.sid
-        "05 00 " + // size 5
-        "01 " + // unicode uncompressed
-        "41 00 42 00 " + // 'AB'
+        "03 00 " + // size 3
+        "00 " + // unicode compressed
+        "41 42 " + // 'AB'
         "3C 00 " + // ContinueRecord.sid
         "10 00 " + // size 16 
         "00 00 18 00 00 00 00 00 " +
@@ -63,7 +63,7 @@
         assertEquals(true, record.isTextLocked());
         assertEquals(TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT, record.getTextOrientation());
 
-        assertEquals(51, record.getRecordSize() );
+        assertEquals(49, record.getRecordSize() );
     }
 
     public void testStore()

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
Wed Nov  5 18:38:06 2008
@@ -37,16 +37,14 @@
 public final class TestTextObjectRecord extends TestCase {
 
     private static final byte[] simpleData = HexRead.readFromString(
-    	"B6 01 12 00 " +
-    	"12 02 00 00 00 00 00 00" +
-    	"00 00 0D 00 08 00	00 00" +
-    	"00 00 " +
-    	"3C 00 1B 00 " +
-    	"01 48 00 65 00 6C 00 6C 00 6F 00 " +
-    	"2C 00 20 00 57 00 6F 00 72 00 6C " +
-    	"00 64 00 21 00 " + 
-    	"3C 00 08 " +
-    	"00 0D 00 00 00 00 00 00 00"
+        "B6 01 12 00 " +
+        "12 02 00 00 00 00 00 00" +
+        "00 00 0D 00 08 00    00 00" +
+        "00 00 " +
+        "3C 00 0E 00 " +
+        "00 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 " +
+        "3C 00 08 " +
+        "00 0D 00 00 00 00 00 00 00"
     );
 
 
@@ -92,12 +90,12 @@
         record.setStr(str);
 
         byte [] ser = record.serialize();
-        
+
         int formatDataLen = LittleEndian.getUShort(ser, 16);
         assertEquals("formatDataLength", 0, formatDataLen);
 
         assertEquals(22, ser.length); // just the TXO record
-        
+
         //read again
         RecordInputStream is = TestcaseRecordInputStream.create(ser);
         record = new TextObjectRecord(is);
@@ -152,38 +150,38 @@
         byte[] cln = cloned.serialize();
         assertTrue(Arrays.equals(src, cln));
     }
-    
-    /** similar to {@link #simpleData} but with link formula at end of TXO rec*/ 
+
+    /** similar to {@link #simpleData} but with link formula at end of TXO rec*/
     private static final byte[] linkData = HexRead.readFromString(
-        	"B6 01 " + // TextObjectRecord.sid
-        	"1E 00 " + // size 18
-    	    "44 02 02 00 00 00 00 00" +
-    	    "00 00 " +
-    	    "02 00 " + // strLen 2
-    	    "10 00 " + // 16 bytes for 2 format runs
-    	    "00 00 00 00 " +
+            "B6 01 " + // TextObjectRecord.sid
+            "1E 00 " + // size 18
+            "44 02 02 00 00 00 00 00" +
+            "00 00 " +
+            "02 00 " + // strLen 2
+            "10 00 " + // 16 bytes for 2 format runs
+            "00 00 00 00 " +
 
             "05 00 " +          // formula size
             "D4 F0 8A 03 " +    // unknownInt
             "24 01 00 13 C0 " + //tRef(T2)
             "13 " +             // ??
 
-        	"3C 00 " + // ContinueRecord.sid
-    	    "05 00 " + // size 5
-    	    "01 " + // unicode uncompressed
-    	    "41 00 42 00 " + // 'AB'
-        	"3C 00 " + // ContinueRecord.sid
-    	    "10 00 " + // size 16 
-    	    "00 00 18 00 00 00 00 00 " +
-    	    "02 00 00 00 00 00 00 00 " 
+            "3C 00 " + // ContinueRecord.sid
+            "03 00 " + // size 3
+            "00 " + // unicode compressed
+            "41 42 " + // 'AB'
+            "3C 00 " + // ContinueRecord.sid
+            "10 00 " + // size 16
+            "00 00 18 00 00 00 00 00 " +
+            "02 00 00 00 00 00 00 00 "
         );
-    
-    
+
+
     public void testLinkFormula() {
         RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(linkData));
         is.nextRecord();
         TextObjectRecord rec = new TextObjectRecord(is);
-		
+
         Ptg ptg = rec.getLinkRefPtg();
         assertNotNull(ptg);
         assertEquals(RefPtg.class, ptg.getClass());
@@ -193,6 +191,6 @@
         byte [] data2 = rec.serialize();
         assertEquals(linkData.length, data2.length);
         assertTrue(Arrays.equals(linkData, data2));
-	}
-    
+    }
+
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeString.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeString.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeString.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnicodeString.java Wed
Nov  5 18:38:06 2008
@@ -15,115 +15,123 @@
    limitations under the License.
 ==================================================================== */
 
-
 package org.apache.poi.hssf.record;
 
-import org.apache.poi.util.HexRead;
-
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
+
 /**
- * Tests that records size calculates correctly.
+ * Tests that {@link UnicodeString} record size calculates correctly.  The record size
+ * is used when serializing {@link SSTRecord}s.
  *
  * @author Jason Height (jheight at apache.org)
  */
 public final class TestUnicodeString extends TestCase {
+    private static final int MAX_DATA_SIZE = RecordInputStream.MAX_RECORD_DATA_SIZE;
 
+    /** a 4 character string requiring 16 bit encoding */
+    private static final String STR_16_BIT = "A\u591A\u8A00\u8A9E";
+
+    private static void confirmSize(int expectedSize, UnicodeString s) {
+        confirmSize(expectedSize, s, 0);
+    }
+    /**
+     * Note - a value of zero for <tt>amountUsedInCurrentRecord</tt> would only
ever occur just
+     * after a {@link ContinueRecord} had been started.  In the initial {@link SSTRecord}
this 
+     * value starts at 8 (for the first {@link UnicodeString} written).  In general, it can
be
+     * any value between 0 and {@link #MAX_DATA_SIZE}
+     */
+    private static void confirmSize(int expectedSize, UnicodeString s, int amountUsedInCurrentRecord)
{
+        ContinuableRecordOutput out = ContinuableRecordOutput.createForCountingOnly();
+        out.writeContinue();
+        for(int i=amountUsedInCurrentRecord; i>0; i--) {
+            out.writeByte(0);
+        }
+        int size0 = out.getTotalSize();
+        s.serialize(out);
+        int size1 = out.getTotalSize();
+        int actualSize = size1-size0;
+        assertEquals(expectedSize, actualSize);
+    }
 
     public void testSmallStringSize() {
         //Test a basic string
         UnicodeString s = makeUnicodeString("Test");
-        UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(7, stats.recordSize);
+        confirmSize(7, s);
 
         //Test a small string that is uncompressed
+        s = makeUnicodeString(STR_16_BIT);
         s.setOptionFlags((byte)0x01);
-        stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(11, stats.recordSize);
+        confirmSize(11, s);
 
         //Test a compressed small string that has rich text formatting
+        s.setString("Test");
         s.setOptionFlags((byte)0x8);
         UnicodeString.FormatRun r = new UnicodeString.FormatRun((short)0,(short)1);
         s.addFormatRun(r);
         UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short)2,(short)2);
         s.addFormatRun(r2);
-        stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(17, stats.recordSize);
+        confirmSize(17, s);
 
         //Test a uncompressed small string that has rich text formatting
+        s.setString(STR_16_BIT);
         s.setOptionFlags((byte)0x9);
-        stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(21, stats.recordSize);
+        confirmSize(21, s);
 
         //Test a compressed small string that has rich text and extended text
+        s.setString("Test");
         s.setOptionFlags((byte)0xC);
         s.setExtendedRst(new byte[]{(byte)0x1,(byte)0x2,(byte)0x3,(byte)0x4,(byte)0x5});
-        stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(26, stats.recordSize);
+        confirmSize(26, s);
 
         //Test a uncompressed small string that has rich text and extended text
+        s.setString(STR_16_BIT);
         s.setOptionFlags((byte)0xD);
-        stats = new UnicodeString.UnicodeRecordStats();
-        s.getRecordSize(stats);
-        assertEquals(30, stats.recordSize);
+        confirmSize(30, s);
     }
 
     public void testPerfectStringSize() {
       //Test a basic string
-      UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1);
-      UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE, stats.recordSize);
+      UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1);
+      confirmSize(MAX_DATA_SIZE, s);
 
       //Test an uncompressed string
       //Note that we can only ever get to a maximim size of 8227 since an uncompressed
       //string is writing double bytes.
-      s = makeUnicodeString((SSTRecord.MAX_RECORD_SIZE-2-1)/2);
+      s = makeUnicodeString((MAX_DATA_SIZE-2-1)/2, true);
       s.setOptionFlags((byte)0x1);
-      stats = new UnicodeString.UnicodeRecordStats();
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
+      confirmSize(MAX_DATA_SIZE-1, s);
     }
 
     public void testPerfectRichStringSize() {
       //Test a rich text string
-      UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1-8-2);
+      UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1-8-2);
       s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
       s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
-      UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
       s.setOptionFlags((byte)0x8);
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE, stats.recordSize);
+      confirmSize(MAX_DATA_SIZE, s);
 
       //Test an uncompressed rich text string
-      //Note that we can only ever get to a maximim size of 8227 since an uncompressed
+      //Note that we can only ever get to a maximum size of 8227 since an uncompressed
       //string is writing double bytes.
-      s = makeUnicodeString((SSTRecord.MAX_RECORD_SIZE-2-1-8-2)/2);
+      s = makeUnicodeString((MAX_DATA_SIZE-2-1-8-2)/2, true);
       s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
       s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
       s.setOptionFlags((byte)0x9);
-      stats = new UnicodeString.UnicodeRecordStats();
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
+      confirmSize(MAX_DATA_SIZE-1, s);
     }
 
     public void testContinuedStringSize() {
       //Test a basic string
-      UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1+20);
-      UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE+4+1+20, stats.recordSize);
+      UnicodeString s = makeUnicodeString(MAX_DATA_SIZE-2-1+20);
+      confirmSize(MAX_DATA_SIZE+4+1+20, s);
     }
 
     /** Tests that a string size calculation that fits neatly in two records, the second
being a continue*/
     public void testPerfectContinuedStringSize() {
       //Test a basic string
-      int strSize = SSTRecord.MAX_RECORD_SIZE*2;
+      int strSize = MAX_DATA_SIZE*2;
       //String overhead
       strSize -= 3;
       //Continue Record overhead
@@ -131,25 +139,29 @@
       //Continue Record additional byte overhead
       strSize -= 1;
       UnicodeString s = makeUnicodeString(strSize);
-      UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
-      s.getRecordSize(stats);
-      assertEquals(SSTRecord.MAX_RECORD_SIZE*2, stats.recordSize);
+      confirmSize(MAX_DATA_SIZE*2, s);
     }
 
 
-
-
-    private static UnicodeString makeUnicodeString( String s )
-    {
+    private static UnicodeString makeUnicodeString(String s) {
       UnicodeString st = new UnicodeString(s);
       st.setOptionFlags((byte)0);
       return st;
     }
 
-    private static UnicodeString makeUnicodeString( int numChars) {
+    private static UnicodeString makeUnicodeString(int numChars) {
+        return makeUnicodeString(numChars, false);
+    }
+    /**
+     * @param is16Bit if <code>true</code> the created string will have characters
> 0x00FF
+     * @return a string of the specified number of characters
+     */
+    private static UnicodeString makeUnicodeString(int numChars, boolean is16Bit) {
       StringBuffer b = new StringBuffer(numChars);
+      int charBase = is16Bit ? 0x8A00 : 'A';
       for (int i=0;i<numChars;i++) {
-        b.append(i%10);
+        char ch = (char) ((i%16)+charBase);
+        b.append(ch);
       }
       return makeUnicodeString(b.toString());
     }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
Wed Nov  5 18:38:06 2008
@@ -22,7 +22,6 @@
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.record.TestcaseRecordInputStream;
-import org.apache.poi.hssf.record.UnicodeString;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
 import org.apache.poi.util.HexRead;
 import org.apache.poi.util.LittleEndianByteArrayOutputStream;
@@ -36,7 +35,7 @@
 			Boolean.TRUE,
 			null,
 			new Double(1.1),
-			new UnicodeString("Sample text"),
+			"Sample text",
 			ErrorConstant.valueOf(HSSFErrorConstants.ERROR_DIV_0),
 		};
 	private static final byte[] SAMPLE_ENCODING = HexRead.readFromString(

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
Wed Nov  5 18:38:06 2008
@@ -66,10 +66,10 @@
 		
 		
 		assertEquals(Boolean.TRUE, values[0][0]);
-		assertEquals(new UnicodeString("ABCD"), values[0][1]);
+		assertEquals("ABCD", values[0][1]);
 		assertEquals(new Double(0), values[1][0]);
 		assertEquals(Boolean.FALSE, values[1][1]);
-		assertEquals(new UnicodeString("FG"), values[1][2]);
+		assertEquals("FG", values[1][2]);
 		
 		byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
 		ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java?rev=711755&r1=711754&r2=711755&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java Wed Nov
 5 18:38:06 2008
@@ -28,8 +28,8 @@
 import org.apache.poi.hssf.util.HSSFColor;
 
 /**
- * Tests various functionity having to do with HSSFCell.  For instance support for
- * paticular datatypes, etc.
+ * Tests various functionality having to do with {@link HSSFCell}.  For instance support
for
+ * particular datatypes, etc.
  * @author Andrew C. Oliver (andy at superlinksoftware dot com)
  * @author  Dan Sherman (dsherman at isisph.com)
  * @author Alex Jacoby (ajacoby at gmail.com)
@@ -345,41 +345,82 @@
         }
     }
 
-    /**
-     * Test to ensure we can only assign cell styles that belong
-     *  to our workbook, and not those from other workbooks.
-     */
-    public void testCellStyleWorkbookMatch() throws Exception {
-    	HSSFWorkbook wbA = new HSSFWorkbook();
-    	HSSFWorkbook wbB = new HSSFWorkbook();
-    	
-    	HSSFCellStyle styA = wbA.createCellStyle();
-    	HSSFCellStyle styB = wbB.createCellStyle();
-    	
-    	styA.verifyBelongsToWorkbook(wbA);
-    	styB.verifyBelongsToWorkbook(wbB);
-    	try {
-    		styA.verifyBelongsToWorkbook(wbB);
-    		fail();
-    	} catch(IllegalArgumentException e) {}
-    	try {
-    		styB.verifyBelongsToWorkbook(wbA);
-    		fail();
-    	} catch(IllegalArgumentException e) {}
-    	
-    	HSSFCell cellA = wbA.createSheet().createRow(0).createCell(0);
-    	HSSFCell cellB = wbB.createSheet().createRow(0).createCell(0);
-    	
-    	cellA.setCellStyle(styA);
-    	cellB.setCellStyle(styB);
-    	try {
-        	cellA.setCellStyle(styB);
-    		fail();
-    	} catch(IllegalArgumentException e) {}
-    	try {
-        	cellB.setCellStyle(styA);
-    		fail();
-    	} catch(IllegalArgumentException e) {}
-    }
+	/**
+	 * Test to ensure we can only assign cell styles that belong
+	 *  to our workbook, and not those from other workbooks.
+	 */
+	public void testCellStyleWorkbookMatch() {
+		HSSFWorkbook wbA = new HSSFWorkbook();
+		HSSFWorkbook wbB = new HSSFWorkbook();
+
+		HSSFCellStyle styA = wbA.createCellStyle();
+		HSSFCellStyle styB = wbB.createCellStyle();
+
+		styA.verifyBelongsToWorkbook(wbA);
+		styB.verifyBelongsToWorkbook(wbB);
+		try {
+			styA.verifyBelongsToWorkbook(wbB);
+			fail();
+		} catch (IllegalArgumentException e) {}
+		try {
+			styB.verifyBelongsToWorkbook(wbA);
+			fail();
+		} catch (IllegalArgumentException e) {}
+
+		HSSFCell cellA = wbA.createSheet().createRow(0).createCell(0);
+		HSSFCell cellB = wbB.createSheet().createRow(0).createCell(0);
+
+		cellA.setCellStyle(styA);
+		cellB.setCellStyle(styB);
+		try {
+			cellA.setCellStyle(styB);
+			fail();
+		} catch (IllegalArgumentException e) {}
+		try {
+			cellB.setCellStyle(styA);
+			fail();
+		} catch (IllegalArgumentException e) {}
+	}
+
+	public void testChangeTypeStringToBool() {
+		HSSFCell cell = new HSSFWorkbook().createSheet("Sheet1").createRow(0).createCell(0);
+
+		cell.setCellValue(new HSSFRichTextString("TRUE"));
+		assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
+		try {
+			cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+		} catch (ClassCastException e) {
+			throw new AssertionFailedError(
+					"Identified bug in conversion of cell from text to boolean");
+		}
+
+		assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cell.getCellType());
+		assertEquals(true, cell.getBooleanCellValue());
+		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+		assertEquals("TRUE", cell.getRichStringCellValue().getString());
+
+		// 'false' text to bool and back
+		cell.setCellValue(new HSSFRichTextString("FALSE"));
+		cell.setCellType(HSSFCell.CELL_TYPE_BOOLEAN);
+		assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, cell.getCellType());
+		assertEquals(false, cell.getBooleanCellValue());
+		cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+		assertEquals("FALSE", cell.getRichStringCellValue().getString());
+	}
+
+	public void testChangeTypeBoolToString() {
+		HSSFCell cell = new HSSFWorkbook().createSheet("Sheet1").createRow(0).createCell(0);
+		cell.setCellValue(true);
+		try {
+			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
+		} catch (IllegalStateException e) {
+			if (e.getMessage().equals("Cannot get a text value from a boolean cell")) {
+				throw new AssertionFailedError(
+						"Identified bug in conversion of cell from boolean to text");
+			}
+			throw e;
+		}
+		assertEquals("TRUE", cell.getRichStringCellValue().getString());
+	}
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message