You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/10/25 03:47:28 UTC
svn commit: r707807 [3/3] - in /poi/branches/ooxml: ./
src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/dev/
src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/
src/java/org/apache/poi/hssf/record/formula/ src/java/org...
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSSTDeserializer.java Fri Oct 24 18:47:25 2008
@@ -32,31 +32,30 @@
* @author Glen Stampoultzis (glens at apache.org)
*/
public final class TestSSTDeserializer extends TestCase {
+ private static final int FAKE_SID = -5555;
-
- private byte[] joinArray(byte[] array1, byte[] array2) {
- byte[] bigArray = new byte[array1.length + array2.length];
- System.arraycopy(array1, 0, bigArray, 0, array1.length);
- System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
- return bigArray;
+ private static byte[] concat(byte[] a, byte[] b) {
+ byte[] result = new byte[a.length + b.length];
+ System.arraycopy(a, 0, result, 0, a.length);
+ System.arraycopy(b, 0, result, a.length, b.length);
+ return result;
}
- private static byte[] readSampleHexData(String sampleFileName, String sectionName) {
+ private static byte[] readSampleHexData(String sampleFileName, String sectionName, int recSid) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ byte[] data;
try {
- return HexRead.readData(is, sectionName);
+ data = HexRead.readData(is, sectionName);
} catch (IOException e) {
throw new RuntimeException(e);
}
+ return TestcaseRecordInputStream.mergeDataAndSid(recSid, data.length, data);
}
- public void testSpanRichTextToPlainText()
- throws Exception
- {
- byte[] header = readSampleHexData("richtextdata.txt", "header" );
- byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1" );
- continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
- TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
+ public void testSpanRichTextToPlainText() {
+ byte[] header = readSampleHexData("richtextdata.txt", "header", FAKE_SID);
+ byte[] continueBytes = readSampleHexData("richtextdata.txt", "continue1", ContinueRecord.sid);
+ RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
IntMapper strings = new IntMapper();
@@ -66,13 +65,10 @@
assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
}
- public void testContinuationWithNoOverlap()
- throws Exception
- {
- byte[] header = readSampleHexData("evencontinuation.txt", "header" );
- byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1" );
- continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
- TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
+ public void testContinuationWithNoOverlap() {
+ byte[] header = readSampleHexData("evencontinuation.txt", "header", FAKE_SID);
+ byte[] continueBytes = readSampleHexData("evencontinuation.txt", "continue1", ContinueRecord.sid);
+ RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
IntMapper strings = new IntMapper();
SSTDeserializer deserializer = new SSTDeserializer( strings );
@@ -85,18 +81,12 @@
/**
* Strings can actually span across more than one continuation.
*/
- public void testStringAcross2Continuations()
- throws Exception
- {
- byte[] header = readSampleHexData("stringacross2continuations.txt", "header" );
- byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1" );
- continue1 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue1.length, continue1);
- byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2" );
- continue2 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue2.length, continue2);
+ public void testStringAcross2Continuations() {
+ byte[] header = readSampleHexData("stringacross2continuations.txt", "header", FAKE_SID);
+ byte[] continue1 = readSampleHexData("stringacross2continuations.txt", "continue1", ContinueRecord.sid);
+ byte[] continue2 = readSampleHexData("stringacross2continuations.txt", "continue2", ContinueRecord.sid);
- byte[] bytes = joinArray(header, continue1);
- bytes = joinArray(bytes, continue2);
- TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, bytes);
+ RecordInputStream in = TestcaseRecordInputStream.create(concat(header, concat(continue1, continue2)));
IntMapper strings = new IntMapper();
SSTDeserializer deserializer = new SSTDeserializer( strings );
@@ -107,10 +97,9 @@
}
public void testExtendedStrings() {
- byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header" );
- byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1" );
- continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
- TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
+ byte[] header = readSampleHexData("extendedtextstrings.txt", "rich-header", FAKE_SID);
+ byte[] continueBytes = readSampleHexData("extendedtextstrings.txt", "rich-continue1", ContinueRecord.sid);
+ RecordInputStream in = TestcaseRecordInputStream.create(concat(header, continueBytes));
IntMapper strings = new IntMapper();
SSTDeserializer deserializer = new SSTDeserializer( strings );
@@ -119,10 +108,9 @@
assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
- header = readSampleHexData("extendedtextstrings.txt", "norich-header" );
- continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1" );
- continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
- in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
+ header = readSampleHexData("extendedtextstrings.txt", "norich-header", FAKE_SID);
+ continueBytes = readSampleHexData("extendedtextstrings.txt", "norich-continue1", ContinueRecord.sid);
+ in = TestcaseRecordInputStream.create(concat(header, continueBytes));
strings = new IntMapper();
deserializer = new SSTDeserializer( strings );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesChartGroupIndexRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesChartGroupIndexRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesChartGroupIndexRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesChartGroupIndexRecord.java Fri Oct 24 18:47:25 2008
@@ -33,7 +33,7 @@
};
public void testLoad() {
- SeriesChartGroupIndexRecord record = new SeriesChartGroupIndexRecord(new TestcaseRecordInputStream((short)0x1045, (short)data.length, data));
+ SeriesChartGroupIndexRecord record = new SeriesChartGroupIndexRecord(TestcaseRecordInputStream.create(0x1045, data));
assertEquals( 0, record.getChartGroupIndex());
assertEquals( 6, record.getRecordSize() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesIndexRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesIndexRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesIndexRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesIndexRecord.java Fri Oct 24 18:47:25 2008
@@ -34,7 +34,7 @@
};
public void testLoad() {
- SeriesIndexRecord record = new SeriesIndexRecord(new TestcaseRecordInputStream((short)0x1065, (short)data.length, data));
+ SeriesIndexRecord record = new SeriesIndexRecord(TestcaseRecordInputStream.create(0x1065, data));
assertEquals( (short)3, record.getIndex());
assertEquals( 6, record.getRecordSize() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesLabelsRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesLabelsRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesLabelsRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesLabelsRecord.java Fri Oct 24 18:47:25 2008
@@ -34,7 +34,7 @@
};
public void testLoad() {
- SeriesLabelsRecord record = new SeriesLabelsRecord(new TestcaseRecordInputStream((short)0x100c, (short)data.length, data));
+ SeriesLabelsRecord record = new SeriesLabelsRecord(TestcaseRecordInputStream.create(0x100c, data));
assertEquals( 3, record.getFormatFlags());
assertEquals( true, record.isShowActual() );
assertEquals( true, record.isShowPercent() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesListRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesListRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesListRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesListRecord.java Fri Oct 24 18:47:25 2008
@@ -35,7 +35,7 @@
public void testLoad() {
- SeriesListRecord record = new SeriesListRecord(new TestcaseRecordInputStream((short)0x1016, (short)data.length, data));
+ SeriesListRecord record = new SeriesListRecord(TestcaseRecordInputStream.create(0x1016, data));
assertEquals( (short)0x2001, record.getSeriesNumbers()[0]);
assertEquals( (short)0xf0ff, record.getSeriesNumbers()[1]);
assertEquals( 2, record.getSeriesNumbers().length);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesRecord.java Fri Oct 24 18:47:25 2008
@@ -39,7 +39,7 @@
public void testLoad() {
- SeriesRecord record = new SeriesRecord(new TestcaseRecordInputStream((short)0x1003, (short)data.length, data));
+ SeriesRecord record = new SeriesRecord(TestcaseRecordInputStream.create(0x1003, data));
assertEquals( SeriesRecord.CATEGORY_DATA_TYPE_NUMERIC, record.getCategoryDataType());
assertEquals( SeriesRecord.VALUES_DATA_TYPE_NUMERIC, record.getValuesDataType());
assertEquals( 27, record.getNumCategories());
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesTextRecord.java Fri Oct 24 18:47:25 2008
@@ -34,7 +34,7 @@
};
public void testLoad() {
- SeriesTextRecord record = new SeriesTextRecord(new TestcaseRecordInputStream((short)0x100d, (short)data.length, data));
+ SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, data));
assertEquals( (short)0, record.getId());
assertEquals( (byte)0x0C, record.getTextLength());
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesToChartGroupRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesToChartGroupRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesToChartGroupRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSeriesToChartGroupRecord.java Fri Oct 24 18:47:25 2008
@@ -34,7 +34,7 @@
};
public void testLoad() {
- SeriesToChartGroupRecord record = new SeriesToChartGroupRecord(new TestcaseRecordInputStream((short)0x1045, (short)data.length, data));
+ SeriesToChartGroupRecord record = new SeriesToChartGroupRecord(TestcaseRecordInputStream.create(0x1045, data));
assertEquals( 0x0, record.getChartGroupIndex());
assertEquals( 0x6, record.getRecordSize() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java Fri Oct 24 18:47:25 2008
@@ -59,7 +59,7 @@
*/
public void testConvertSharedFormulasOperandClasses_bug45123() {
- TestcaseRecordInputStream in = new TestcaseRecordInputStream(0, SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
+ RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
int encodedLen = in.readUShort();
Ptg[] sharedFormula = Ptg.readTokens(encodedLen, in);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSheetPropertiesRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSheetPropertiesRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSheetPropertiesRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSheetPropertiesRecord.java Fri Oct 24 18:47:25 2008
@@ -36,7 +36,7 @@
};
public void testLoad() {
- SheetPropertiesRecord record = new SheetPropertiesRecord(new TestcaseRecordInputStream((short)0x1044, (short)data.length, data));
+ SheetPropertiesRecord record = new SheetPropertiesRecord(TestcaseRecordInputStream.create(0x1044, data));
assertEquals( 10, record.getFlags());
assertEquals( false, record.isChartTypeManuallyFormatted() );
assertEquals( true, record.isPlotVisibleOnly() );
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -27,7 +27,7 @@
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class TestStringRecord extends TestCase {
+public final class TestStringRecord extends TestCase {
byte[] data = new byte[] {
(byte)0x0B,(byte)0x00, // length
(byte)0x00, // option
@@ -37,7 +37,7 @@
public void testLoad() {
- StringRecord record = new StringRecord(new TestcaseRecordInputStream((short)0x207, (short)data.length, data));
+ StringRecord record = new StringRecord(TestcaseRecordInputStream.create(0x207, data));
assertEquals( "Fahrzeugtyp", record.getString());
assertEquals( 18, record.getRecordSize() );
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -51,7 +51,7 @@
*/
public void testLoadIR() {
- SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataIR));
+ SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataIR));
assertTrue( record.isInternalReferences() ); //expected flag
assertEquals( 0x4, record.getNumberOfSheets() ); //expected # of sheets
@@ -62,7 +62,7 @@
*/
public void testLoadER() {
- SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataER));
+ SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataER));
assertTrue( record.isExternalReferences() ); //expected flag
assertEquals( 0x2, record.getNumberOfSheets() ); //expected # of sheets
@@ -80,7 +80,7 @@
*/
public void testLoadAIF() {
- SupBookRecord record = new SupBookRecord(new TestcaseRecordInputStream((short)0x01AE, dataAIF));
+ SupBookRecord record = new SupBookRecord(TestcaseRecordInputStream.create(0x01AE, dataAIF));
assertTrue( record.isAddInFunctions() ); //expected flag
assertEquals( 0x1, record.getNumberOfSheets() ); //expected # of sheets
assertEquals( 8, record.getRecordSize() ); //sid+size+data
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTableRecord.java Fri Oct 24 18:47:25 2008
@@ -44,7 +44,7 @@
public void testLoad() {
- TableRecord record = new TableRecord(new TestcaseRecordInputStream((short)0x236, (short)data.length, data));
+ TableRecord record = new TableRecord(TestcaseRecordInputStream.create(0x236, data));
CellRangeAddress8Bit range = record.getRange();
assertEquals(3, range.getFirstRow());
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -18,6 +18,11 @@
package org.apache.poi.hssf.record;
+import java.io.ByteArrayInputStream;
+
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.util.HexRead;
+
import junit.framework.TestCase;
/**
@@ -25,63 +30,62 @@
* class works correctly. Test data taken directly from a real
* Excel file.
*
-
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class TestTextObjectBaseRecord extends TestCase {
- byte[] data = new byte[] {
- 0x44, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00,
- };
+public final class TestTextObjectBaseRecord extends TestCase {
+ /** data for one TXO rec and two continue recs */
+ private static final byte[] data = HexRead.readFromString(
+ "B6 01 " + // TextObjectRecord.sid
+ "12 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 " +
+ "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 "
+ );
+
public void testLoad() {
- TextObjectBaseRecord record = new TextObjectBaseRecord(new TestcaseRecordInputStream((short)0x1B6, (short)data.length, data));
+ RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(data));
+ in.nextRecord();
+ TextObjectRecord record = new TextObjectRecord(in);
-// assertEquals( (short), record.getOptions());
- assertEquals( false, record.isReserved1() );
- assertEquals( TextObjectBaseRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED, record.getHorizontalTextAlignment() );
- assertEquals( TextObjectBaseRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY, record.getVerticalTextAlignment() );
- assertEquals( 0, record.getReserved2() );
- assertEquals( true, record.isTextLocked() );
- assertEquals( 0, record.getReserved3() );
- assertEquals( TextObjectBaseRecord.TEXT_ORIENTATION_ROT_RIGHT, record.getTextOrientation());
- assertEquals( 0, record.getReserved4());
- assertEquals( 0, record.getReserved5());
- assertEquals( 0, record.getReserved6());
- assertEquals( 2, record.getTextLength());
- assertEquals( 2, record.getFormattingRunLength());
- assertEquals( 0, record.getReserved7());
+ assertEquals(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED, record.getHorizontalTextAlignment());
+ assertEquals(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY, record.getVerticalTextAlignment());
+ assertEquals(true, record.isTextLocked());
+ assertEquals(TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT, record.getTextOrientation());
-
- assertEquals( 22, record.getRecordSize() );
+ assertEquals(51, record.getRecordSize() );
}
public void testStore()
{
- TextObjectBaseRecord record = new TextObjectBaseRecord();
-
+ TextObjectRecord record = new TextObjectRecord();
-// record.setOptions( (short) 0x0000);
- record.setReserved1( false );
- record.setHorizontalTextAlignment( TextObjectBaseRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED );
- record.setVerticalTextAlignment( TextObjectBaseRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY );
- record.setReserved2( (short)0 );
- record.setTextLocked( true );
- record.setReserved3( (short)0 );
- record.setTextOrientation( TextObjectBaseRecord.TEXT_ORIENTATION_ROT_RIGHT );
- record.setReserved4( (short)0 );
- record.setReserved5( (short)0 );
- record.setReserved6( (short)0 );
- record.setTextLength( (short)2 );
- record.setFormattingRunLength( (short)2 );
- record.setReserved7( 0 );
+ HSSFRichTextString str = new HSSFRichTextString("AB");
+ str.applyFont(0, 2, (short)0x0018);
+ str.applyFont(2, 2, (short)0x0320);
+
+ record.setHorizontalTextAlignment(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED);
+ record.setVerticalTextAlignment(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY);
+ record.setTextLocked(true);
+ record.setTextOrientation(TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT);
+ record.setStr(str);
byte [] recordBytes = record.serialize();
- assertEquals(recordBytes.length - 4, data.length);
+ assertEquals(recordBytes.length, data.length);
for (int i = 0; i < data.length; i++)
- assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ assertEquals("At offset " + i, data[i], recordBytes[i]);
}
}
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -22,7 +22,11 @@
import junit.framework.TestCase;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.RefPtg;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndian;
/**
* Tests that serialization and deserialization of the TextObjectRecord .
@@ -32,17 +36,23 @@
*/
public final class TestTextObjectRecord extends TestCase {
- byte[] data = {(byte)0xB6, 0x01, 0x12, 0x00, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3C, 0x00, 0x1B, 0x00, 0x01, 0x48, 0x00, 0x65, 0x00, 0x6C,
- 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x2C, 0x00, 0x20, 0x00, 0x57, 0x00,
- 0x6F, 0x00, 0x72, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x21, 0x00, 0x3C,
- 0x00, 0x08, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ 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"
+ );
public void testRead() {
- RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
+ RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(simpleData));
is.nextRecord();
TextObjectRecord record = new TextObjectRecord(is);
@@ -50,36 +60,51 @@
assertEquals(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED, record.getHorizontalTextAlignment());
assertEquals(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP, record.getVerticalTextAlignment());
assertEquals(TextObjectRecord.TEXT_ORIENTATION_NONE, record.getTextOrientation());
- assertEquals(0, record.getReserved7());
assertEquals("Hello, World!", record.getStr().getString());
-
}
- public void testWrite()
- {
+ public void testWrite() {
HSSFRichTextString str = new HSSFRichTextString("Hello, World!");
TextObjectRecord record = new TextObjectRecord();
- int frLength = ( str.numFormattingRuns() + 1 ) * 8;
- record.setFormattingRunLength( (short) frLength );
- record.setTextLength( (short) str.length() );
- record.setStr( str );
+ record.setStr(str);
record.setHorizontalTextAlignment( TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED );
record.setVerticalTextAlignment( TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP );
record.setTextLocked( true );
record.setTextOrientation( TextObjectRecord.TEXT_ORIENTATION_NONE );
- record.setReserved7( 0 );
byte [] ser = record.serialize();
- //assertEquals(ser.length , data.length);
+ assertEquals(ser.length , simpleData.length);
- //assertTrue(Arrays.equals(data, ser));
+ assertTrue(Arrays.equals(simpleData, ser));
//read again
- RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
+ RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(simpleData));
is.nextRecord();
record = new TextObjectRecord(is);
+ }
+
+ /**
+ * Zero {@link ContinueRecord}s follow a {@link TextObjectRecord} if the text is empty
+ */
+ public void testWriteEmpty() {
+ HSSFRichTextString str = new HSSFRichTextString("");
+
+ TextObjectRecord record = new TextObjectRecord();
+ 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 = new RecordInputStream(new ByteArrayInputStream(ser));
+ is.nextRecord();
+ record = new TextObjectRecord(is);
+ assertEquals(0, record.getStr().length());
}
/**
@@ -95,10 +120,7 @@
HSSFRichTextString str = new HSSFRichTextString(buff.toString());
TextObjectRecord obj = new TextObjectRecord();
- int frLength = ( str.numFormattingRuns() + 1 ) * 8;
- obj.setFormattingRunLength( (short) frLength );
- obj.setTextLength( (short) str.length() );
- obj.setStr( str );
+ obj.setStr(str);
byte [] data = obj.serialize();
RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(data));
@@ -120,30 +142,12 @@
HSSFRichTextString str = new HSSFRichTextString(text);
TextObjectRecord obj = new TextObjectRecord();
- int frLength = ( str.numFormattingRuns() + 1 ) * 8;
- obj.setFormattingRunLength( (short) frLength );
- obj.setTextLength( (short) str.length() );
- obj.setReserved1(true);
- obj.setReserved2((short)2);
- obj.setReserved3((short)3);
- obj.setReserved4((short)4);
- obj.setReserved5((short)5);
- obj.setReserved6((short)6);
- obj.setReserved7((short)7);
obj.setStr( str );
TextObjectRecord cloned = (TextObjectRecord)obj.clone();
- assertEquals(obj.getReserved2(), cloned.getReserved2());
- assertEquals(obj.getReserved3(), cloned.getReserved3());
- assertEquals(obj.getReserved4(), cloned.getReserved4());
- assertEquals(obj.getReserved5(), cloned.getReserved5());
- assertEquals(obj.getReserved6(), cloned.getReserved6());
- assertEquals(obj.getReserved7(), cloned.getReserved7());
assertEquals(obj.getRecordSize(), cloned.getRecordSize());
- assertEquals(obj.getOptions(), cloned.getOptions());
assertEquals(obj.getHorizontalTextAlignment(), cloned.getHorizontalTextAlignment());
- assertEquals(obj.getFormattingRunLength(), cloned.getFormattingRunLength());
assertEquals(obj.getStr().getString(), cloned.getStr().getString());
//finally check that the serialized data is the same
@@ -151,4 +155,47 @@
byte[] cln = cloned.serialize();
assertTrue(Arrays.equals(src, cln));
}
+
+ /** 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 " +
+
+ "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 "
+ );
+
+
+ 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());
+ RefPtg rptg = (RefPtg) ptg;
+ assertEquals("T2", rptg.toFormulaString());
+
+ 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/TestTextRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextRecord.java Fri Oct 24 18:47:25 2008
@@ -27,7 +27,7 @@
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class TestTextRecord extends TestCase {
+public final class TestTextRecord extends TestCase {
byte[] data = new byte[] {
(byte)0x02, // horiz align
(byte)0x02, // vert align
@@ -45,7 +45,7 @@
public void testLoad() {
- TextRecord record = new TextRecord(new TestcaseRecordInputStream((short)0x1025, (short)data.length, data));
+ TextRecord record = new TextRecord(TestcaseRecordInputStream.create(0x1025, data));
assertEquals( TextRecord.HORIZONTAL_ALIGNMENT_CENTER, record.getHorizontalAlignment());
assertEquals( TextRecord.VERTICAL_ALIGNMENT_CENTER, record.getVerticalAlignment());
assertEquals( TextRecord.DISPLAY_MODE_TRANSPARENT, record.getDisplayMode());
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java Fri Oct 24 18:47:25 2008
@@ -40,7 +40,7 @@
};
public void testLoad() {
- TickRecord record = new TickRecord(new TestcaseRecordInputStream((short)0x101e, (short)data.length, data));
+ TickRecord record = new TickRecord(TestcaseRecordInputStream.create(0x101e, data));
assertEquals( (byte)2, record.getMajorTickType());
assertEquals( (byte)0, record.getMinorTickType());
assertEquals( (byte)3, record.getLabelPosition());
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 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
@@ -19,6 +18,8 @@
package org.apache.poi.hssf.record;
+import org.apache.poi.util.HexRead;
+
import junit.framework.TestCase;
/**
@@ -26,18 +27,10 @@
*
* @author Jason Height (jheight at apache.org)
*/
-public class TestUnicodeString
- extends TestCase
-{
+public final class TestUnicodeString extends TestCase {
- public TestUnicodeString( String s )
- {
- super( s );
- }
- public void testSmallStringSize()
- throws Exception
- {
+ public void testSmallStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString("Test");
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
@@ -80,9 +73,7 @@
assertEquals(30, stats.recordSize);
}
- public void testPerfectStringSize()
- throws Exception
- {
+ public void testPerfectStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1);
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
@@ -99,9 +90,7 @@
assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
}
- public void testPerfectRichStringSize()
- throws Exception
- {
+ public void testPerfectRichStringSize() {
//Test a rich text string
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1-8-2);
s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
@@ -123,7 +112,7 @@
assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
}
- public void testContinuedStringSize() throws Exception {
+ public void testContinuedStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1+20);
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
@@ -132,7 +121,7 @@
}
/** Tests that a string size calculation that fits neatly in two records, the second being a continue*/
- public void testPerfectContinuedStringSize() throws Exception {
+ public void testPerfectContinuedStringSize() {
//Test a basic string
int strSize = SSTRecord.MAX_RECORD_SIZE*2;
//String overhead
@@ -150,19 +139,18 @@
- private UnicodeString makeUnicodeString( String s )
+ private static UnicodeString makeUnicodeString( String s )
{
UnicodeString st = new UnicodeString(s);
st.setOptionFlags((byte)0);
return st;
}
- private UnicodeString makeUnicodeString( int numChars) {
+ private static UnicodeString makeUnicodeString( int numChars) {
StringBuffer b = new StringBuffer(numChars);
for (int i=0;i<numChars;i++) {
b.append(i%10);
}
return makeUnicodeString(b.toString());
}
-
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnitsRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnitsRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnitsRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestUnitsRecord.java Fri Oct 24 18:47:25 2008
@@ -35,7 +35,7 @@
public void testLoad() {
- UnitsRecord record = new UnitsRecord(new TestcaseRecordInputStream((short)0x1001, (short)data.length, data));
+ UnitsRecord record = new UnitsRecord(TestcaseRecordInputStream.create(0x1001, data));
assertEquals( 0, record.getUnits());
assertEquals( 6, record.getRecordSize() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestValueRangeRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestValueRangeRecord.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestValueRangeRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestValueRangeRecord.java Fri Oct 24 18:47:25 2008
@@ -40,7 +40,7 @@
public void testLoad() {
- ValueRangeRecord record = new ValueRangeRecord(new TestcaseRecordInputStream((short)0x101f, (short)data.length, data));
+ ValueRangeRecord record = new ValueRangeRecord(TestcaseRecordInputStream.create(0x101f, data));
assertEquals( 0.0, record.getMinimumAxisValue(), 0.001);
assertEquals( 0.0, record.getMaximumAxisValue(), 0.001);
assertEquals( 0.0, record.getMajorIncrement(), 0.001);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java Fri Oct 24 18:47:25 2008
@@ -18,6 +18,7 @@
package org.apache.poi.hssf.record;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import junit.framework.Assert;
@@ -30,27 +31,51 @@
*
* @author Jason Height (jheight at apache.org)
*/
-public class TestcaseRecordInputStream
- extends RecordInputStream
-{
+public final class TestcaseRecordInputStream {
+
+ private TestcaseRecordInputStream() {
+ // no instances of this class
+ }
+
+ /**
+ * Prepends a mock record identifier to the supplied data and opens a record input stream
+ */
+ public static RecordInputStream createWithFakeSid(byte[] data) {
+ return create(-5555, data);
+
+ }
+ public static RecordInputStream create(int sid, byte[] data) {
+ return create(mergeDataAndSid(sid, data.length, data));
+ }
+ /**
+ * First 4 bytes of <tt>data</tt> are assumed to be record identifier and length. The supplied
+ * <tt>data</tt> can contain multiple records (sequentially encoded in the same way)
+ */
+ public static RecordInputStream create(byte[] data) {
+ InputStream is = new ByteArrayInputStream(data);
+ RecordInputStream result = new RecordInputStream(is);
+ result.nextRecord();
+ return result;
+ }
+
/**
* Convenience constructor
*/
- public TestcaseRecordInputStream(int sid, byte[] data)
- {
- super(new ByteArrayInputStream(mergeDataAndSid((short)sid, (short)data.length, data)));
- nextRecord();
- }
- public TestcaseRecordInputStream(short sid, short length, byte[] data)
- {
- super(new ByteArrayInputStream(mergeDataAndSid(sid, length, data)));
- nextRecord();
- }
+// public TestcaseRecordInputStream(int sid, byte[] data)
+// {
+// super(new ByteArrayInputStream(mergeDataAndSid(sid, data.length, data)));
+// nextRecord();
+// }
+// public TestcaseRecordInputStream(short sid, short length, byte[] data)
+// {
+// super(new ByteArrayInputStream(mergeDataAndSid(sid, length, data)));
+// nextRecord();
+// }
- public static byte[] mergeDataAndSid(short sid, short length, byte[] data) {
+ public static byte[] mergeDataAndSid(int sid, int length, byte[] data) {
byte[] result = new byte[data.length + 4];
- LittleEndian.putShort(result, 0, sid);
- LittleEndian.putShort(result, 2, length);
+ LittleEndian.putUShort(result, 0, sid);
+ LittleEndian.putUShort(result, 2, length);
System.arraycopy(data, 0, result, 4, data.length);
return result;
}
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -25,6 +25,7 @@
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;
/**
*
* @author Josh Micich
@@ -37,13 +38,12 @@
new UnicodeString("Sample text"),
ErrorConstant.valueOf(HSSFErrorConstants.ERROR_DIV_0),
};
- private static final byte[] SAMPLE_ENCODING = {
- 4, 1, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, -102, -103, -103, -103, -103, -103, -15, 63,
- 2, 11, 0, 0, 83, 97, 109, 112, 108, 101, 32, 116, 101, 120, 116,
- 16, 7, 0, 0, 0, 0, 0, 0, 0,
- };
+ private static final byte[] SAMPLE_ENCODING = HexRead.readFromString(
+ "04 01 00 00 00 00 00 00 00 " +
+ "00 00 00 00 00 00 00 00 00 " +
+ "01 9A 99 99 99 99 99 F1 3F " +
+ "02 0B 00 00 53 61 6D 70 6C 65 20 74 65 78 74 " +
+ "10 07 00 00 00 00 00 00 00");
public void testGetEncodedSize() {
int actual = ConstantValueParser.getEncodedSize(SAMPLE_VALUES);
@@ -59,7 +59,7 @@
}
}
public void testDecode() {
- RecordInputStream in = new TestcaseRecordInputStream(0x0001, SAMPLE_ENCODING);
+ RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(SAMPLE_ENCODING);
Object[] values = ConstantValueParser.parse(in, 4);
for (int i = 0; i < values.length; i++) {
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=707807&r1=707806&r2=707807&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 Fri Oct 24 18:47:25 2008
@@ -54,9 +54,9 @@
*/
public void testReadWriteTokenValueBytes() {
- ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
- ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
assertEquals(3, ptg.getColumnCount());
assertEquals(2, ptg.getRowCount());
Object[][] values = ptg.getTokenArrayValues();
@@ -82,8 +82,8 @@
* Excel stores array elements column by column. This test makes sure POI does the same.
*/
public void testElementOrdering() {
- ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
- ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
assertEquals(3, ptg.getColumnCount());
assertEquals(2, ptg.getRowCount());
@@ -113,9 +113,9 @@
}
public void testToFormulaString() {
- ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
- ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
String actualFormula;
try {
@@ -146,7 +146,7 @@
// Force encoded operand class for tArray
fullData[0] = (byte) (ArrayPtg.sid + operandClass);
- RecordInputStream in = new TestcaseRecordInputStream(ArrayPtg.sid, fullData);
+ RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(fullData);
Ptg[] ptgs = Ptg.readTokens(ENCODED_PTG_DATA.length, in);
assertEquals(1, ptgs.length);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java Fri Oct 24 18:47:25 2008
@@ -34,7 +34,7 @@
0,
};
- FuncPtg ptg = new FuncPtg( new TestcaseRecordInputStream((short)0, (short)fakeData.length, fakeData) );
+ FuncPtg ptg = new FuncPtg(TestcaseRecordInputStream.createWithFakeSid(fakeData) );
assertEquals( "Len formula index is not 32(20H)", 0x20, ptg.getFunctionIndex() );
assertEquals( "Number of operands in the len formula", 1, ptg.getNumberOfOperands() );
assertEquals( "Function Name", "LEN", ptg.getName() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java?rev=707807&r1=707806&r2=707807&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java Fri Oct 24 18:47:25 2008
@@ -18,12 +18,12 @@
package org.apache.poi.hssf.record.formula;
import java.util.Arrays;
-import java.util.Stack;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -94,10 +94,10 @@
0x2C, 33, 44, 55, 66,
};
public void testReadWrite_tRefN_bug45091() {
- TestcaseRecordInputStream in = new TestcaseRecordInputStream(-1, tRefN_data);
- Stack ptgs = Ptg.createParsedExpressionTokens((short)tRefN_data.length, in);
+ RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(tRefN_data);
+ Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in);
byte[] outData = new byte[5];
- Ptg.serializePtgStack(ptgs, outData, 0);
+ Ptg.serializePtgs(ptgs, outData, 0);
if (outData[0] == 0x24) {
throw new AssertionFailedError("Identified bug 45091");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org