From 80ba3cd553d27ca563deca4464ff4220618ca759 Mon Sep 17 00:00:00 2001 From: Glen Stampoultzis Date: Tue, 10 Feb 2004 22:07:51 +0000 Subject: [PATCH] Test cases for office drawing support. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353502 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ddf/TestEscherBSERecord.java | 87 +++++++++++ .../apache/poi/ddf/TestEscherBlipRecord.java | 110 ++++++++++++++ .../poi/ddf/TestEscherBoolProperty.java | 13 ++ .../poi/ddf/TestEscherChildAnchorRecord.java | 73 +++++++++ .../poi/ddf/TestEscherClientAnchorRecord.java | 91 ++++++++++++ .../poi/ddf/TestEscherClientDataRecord.java | 57 +++++++ .../poi/ddf/TestEscherContainerRecord.java | 98 ++++++++++++ .../apache/poi/ddf/TestEscherDgRecord.java | 62 ++++++++ .../apache/poi/ddf/TestEscherDggRecord.java | 89 +++++++++++ .../apache/poi/ddf/TestEscherOptRecord.java | 140 ++++++++++++++++++ .../poi/ddf/TestEscherPropertyFactory.java | 42 ++++++ .../apache/poi/ddf/TestEscherSpRecord.java | 62 ++++++++ .../apache/poi/ddf/TestEscherSpgrRecord.java | 73 +++++++++ .../ddf/TestEscherSplitMenuColorsRecord.java | 73 +++++++++ .../poi/ddf/TestUnknownEscherRecord.java | 106 +++++++++++++ .../poi/hssf/model/TestDrawingManager.java | 81 ++++++++++ .../record/TestCommonObjectDataSubRecord.java | 127 ++++++++++++++++ .../hssf/record/TestDrawingGroupRecord.java | 36 +++++ .../poi/hssf/record/TestEndSubRecord.java | 102 +++++++++++++ .../poi/hssf/record/TestEscherAggregate.java | 124 ++++++++++++++++ .../hssf/record/TestTextObjectBaseRecord.java | 137 +++++++++++++++++ .../hssf/usermodel/TestEscherGraphics.java | 71 +++++++++ .../hssf/usermodel/TestEscherGraphics2d.java | 74 +++++++++ .../poi/hssf/usermodel/TestFontDetails.java | 45 ++++++ .../hssf/usermodel/TestHSSFClientAnchor.java | 44 ++++++ .../poi/hssf/usermodel/TestHSSFPalette.java | 15 +- .../usermodel/TestHSSFRichTextString.java | 50 +++++++ 27 files changed, 2081 insertions(+), 1 deletion(-) create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java create mode 100644 src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java create mode 100644 src/testcases/org/apache/poi/hssf/model/TestDrawingManager.java create mode 100644 src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java create mode 100644 src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java create mode 100644 src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java create mode 100644 src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java create mode 100644 src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java create mode 100644 src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java new file mode 100644 index 0000000000..3778347d71 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java @@ -0,0 +1,87 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +import java.io.IOException; + +public class TestEscherBSERecord extends TestCase +{ + public void testFillFields() throws Exception + { + String data = "01 00 00 00 24 00 00 00 05 05 01 02 03 04 " + + " 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 01 00 00 00 " + + " 00 00 02 00 00 00 03 00 00 00 04 05 06 07"; + EscherBSERecord r = new EscherBSERecord(); + int bytesWritten = r.fillFields( HexRead.readFromString( data ), 0, new DefaultEscherRecordFactory() ); + assertEquals( 44, bytesWritten ); + assertEquals( (short) 0x0001, r.getOptions() ); + assertEquals( EscherBSERecord.BT_JPEG, r.getBlipTypeWin32() ); + assertEquals( EscherBSERecord.BT_JPEG, r.getBlipTypeMacOS() ); + assertEquals( "[01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]", HexDump.toHex( r.getUid() ) ); + assertEquals( (short) 1, r.getTag() ); + assertEquals( 2, r.getRef() ); + assertEquals( 3, r.getOffset() ); + assertEquals( (byte) 4, r.getUsage() ); + assertEquals( (byte) 5, r.getName() ); + assertEquals( (byte) 6, r.getUnused2() ); + assertEquals( (byte) 7, r.getUnused3() ); + assertEquals( 0, r.getRemainingData().length ); + } + + public void testSerialize() throws Exception + { + EscherBSERecord r = createRecord(); + + byte[] data = new byte[8 + 36]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 44, bytesWritten ); + assertEquals( "[01, 00, 00, 00, 24, 00, 00, 00, 05, 05, 01, 02, 03, 04, " + + "05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, 01, 00, 00, 00, " + + "00, 00, 02, 00, 00, 00, 03, 00, 00, 00, 04, 05, 06, 07, ]", + HexDump.toHex( data ) ); + + } + + private EscherBSERecord createRecord() throws IOException + { + EscherBSERecord r = new EscherBSERecord(); + r.setOptions( (short) 0x0001 ); + r.setBlipTypeWin32( EscherBSERecord.BT_JPEG ); + r.setBlipTypeMacOS( EscherBSERecord.BT_JPEG ); + r.setUid( HexRead.readFromString( "01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00" ) ); + r.setTag( (short) 1 ); + r.setRef( 2 ); + r.setOffset( 3 ); + r.setUsage( (byte) 4 ); + r.setName( (byte) 5 ); + r.setUnused2( (byte) 6 ); + r.setUnused3( (byte) 7 ); + r.setRemainingData( new byte[0] ); + return r; + + } + + public void testToString() throws Exception + { + EscherBSERecord record = createRecord(); + String nl = System.getProperty("line.separator"); + assertEquals( "org.apache.poi.ddf.EscherBSERecord:" + nl + + " RecordId: 0xF007" + nl + + " Options: 0x0001" + nl + + " BlipTypeWin32: 5" + nl + + " BlipTypeMacOS: 5" + nl + + " SUID: [01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00, ]" + nl + + " Tag: 1" + nl + + " Size: 0" + nl + + " Ref: 2" + nl + + " Offset: 3" + nl + + " Usage: 4" + nl + + " Name: 5" + nl + + " Unused2: 6" + nl + + " Unused3: 7" + nl + + " Extra Data:" + nl, record.toString() ); + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java new file mode 100644 index 0000000000..184dc53590 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java @@ -0,0 +1,110 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherBlipRecord extends TestCase +{ + private String dataStr; + private byte[] data; + + protected void setUp() throws Exception + { + dataStr = "2C 15 18 F0 34 00 00 00 01 01 01 01 01 01 01 01 " + + "01 01 01 01 01 01 01 01 06 00 00 00 03 00 00 00 " + + "01 00 00 00 04 00 00 00 02 00 00 00 0A 00 00 00 " + + "0B 00 00 00 05 00 00 00 08 07 01 02"; + data = HexRead.readFromString(dataStr); + } + + public void testSerialize() throws Exception + { + EscherBlipRecord r = new EscherBlipRecord(); + r.setBoundaryLeft(1); + r.setBoundaryHeight(2); + r.setBoundaryTop(3); + r.setBoundaryWidth(4); + r.setCacheOfSavedSize(5); + r.setCacheOfSize(6); + r.setFilter((byte)7); + r.setCompressionFlag((byte)8); + r.setSecondaryUID(new byte[] { (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, + (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, + (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, + (byte)0x01, (byte)0x01, (byte)0x01, (byte)0x01, }); + r.setWidth(10); + r.setHeight(11); + r.setRecordId(EscherBlipRecord.RECORD_ID_START); + r.setOptions((short)5420); + r.setData(new byte[] { (byte)0x01, (byte)0x02 } ); + + byte[] buf = new byte[r.getRecordSize()]; + r.serialize(0, buf, new NullEscherSerializationListener() ); + + assertEquals("[2C, 15, 18, F0, 26, 00, 00, 00, " + + "01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, " + + "06, 00, 00, 00, " + // field_2_cacheOfSize + "03, 00, 00, 00, " + // field_3_boundaryTop + "01, 00, 00, 00, " + // field_4_boundaryLeft + "04, 00, 00, 00, " + // field_5_boundaryWidth + "02, 00, 00, 00, " + // field_6_boundaryHeight + "0A, 00, 00, 00, " + // field_7_x + "0B, 00, 00, 00, " + // field_8_y + "05, 00, 00, 00, " + // field_9_cacheOfSavedSize + "08, " + // field_10_compressionFlag + "07, " + // field_11_filter + "01, 02, ]", // field_12_data + HexDump.toHex(buf)); + assertEquals(60, r.getRecordSize() ); + + } + + public void testFillFields() throws Exception + { + EscherBlipRecord r = new EscherBlipRecord(); + r.fillFields( data, 0, new DefaultEscherRecordFactory()); + + assertEquals( EscherBlipRecord.RECORD_ID_START, r.getRecordId() ); + assertEquals( 1, r.getBoundaryLeft() ); + assertEquals( 2, r.getBoundaryHeight() ); + assertEquals( 3, r.getBoundaryTop() ); + assertEquals( 4, r.getBoundaryWidth() ); + assertEquals( 5, r.getCacheOfSavedSize() ); + assertEquals( 6, r.getCacheOfSize() ); + assertEquals( 7, r.getFilter() ); + assertEquals( 8, r.getCompressionFlag() ); + assertEquals( "[01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]", HexDump.toHex(r.getSecondaryUID() ) ); + assertEquals( 10, r.getWidth() ); + assertEquals( 11, r.getHeight() ); + assertEquals( (short)5420, r.getOptions() ); + assertEquals( "[01, 02, ]", HexDump.toHex( r.getData() ) ); + } + + public void testToString() throws Exception + { + EscherBlipRecord r = new EscherBlipRecord(); + r.fillFields( data, 0, new DefaultEscherRecordFactory() ); + + String nl = System.getProperty("line.separator"); + + assertEquals( "org.apache.poi.ddf.EscherBlipRecord:" + nl + + " RecordId: 0xF018" + nl + + " Options: 0x152C" + nl + + " Secondary UID: [01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, ]" + nl + + " CacheOfSize: 6" + nl + + " BoundaryTop: 3" + nl + + " BoundaryLeft: 1" + nl + + " BoundaryWidth: 4" + nl + + " BoundaryHeight: 2" + nl + + " X: 10" + nl + + " Y: 11" + nl + + " CacheOfSavedSize: 5" + nl + + " CompressionFlag: 8" + nl + + " Filter: 7" + nl + + " Data:" + nl + + "00000000 01 02 .." + nl + , r.toString() ); + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java new file mode 100644 index 0000000000..4f16ffddfd --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java @@ -0,0 +1,13 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; + +public class TestEscherBoolProperty extends TestCase +{ + public void testToString() throws Exception + { + EscherBoolProperty p = new EscherBoolProperty((short)1, 1); + assertEquals("propNum: 1, propName: unknown, complex: false, blipId: false, value: 1 (0x00000001)", p.toString()); + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java new file mode 100644 index 0000000000..6c58d449e3 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java @@ -0,0 +1,73 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherChildAnchorRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherChildAnchorRecord r = createRecord(); + + byte[] data = new byte[8 + 16]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 24, bytesWritten ); + assertEquals( "[01, 00, " + + "0F, F0, " + + "10, 00, 00, 00, " + + "01, 00, 00, 00, " + + "02, 00, 00, 00, " + + "03, 00, 00, 00, " + + "04, 00, 00, 00, ]", HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "01 00 " + + "0F F0 " + + "10 00 00 00 " + + "01 00 00 00 " + + "02 00 00 00 " + + "03 00 00 00 " + + "04 00 00 00 "; + + byte[] data = HexRead.readFromString( hexData ); + EscherChildAnchorRecord r = new EscherChildAnchorRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 24, bytesWritten ); + assertEquals( 1, r.getDx1() ); + assertEquals( 2, r.getDy1() ); + assertEquals( 3, r.getDx2() ); + assertEquals( 4, r.getDy2() ); + assertEquals( (short) 0x0001, r.getOptions() ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty( "line.separator" ); + + String expected = "org.apache.poi.ddf.EscherChildAnchorRecord:" + nl + + " RecordId: 0xF00F" + nl + + " Options: 0x0001" + nl + + " X1: 1" + nl + + " Y1: 2" + nl + + " X2: 3" + nl + + " Y2: 4" + nl; + assertEquals( expected, createRecord().toString() ); + } + + private EscherChildAnchorRecord createRecord() + { + EscherChildAnchorRecord r = new EscherChildAnchorRecord(); + r.setRecordId( EscherChildAnchorRecord.RECORD_ID ); + r.setOptions( (short) 0x0001 ); + r.setDx1( 1 ); + r.setDy1( 2 ); + r.setDx2( 3 ); + r.setDy2( 4 ); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java new file mode 100644 index 0000000000..acd84625df --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java @@ -0,0 +1,91 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherClientAnchorRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherClientAnchorRecord r = createRecord(); + + byte[] data = new byte[8 + 18 + 2]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 28, bytesWritten ); + assertEquals( "[01, 00, " + + "10, F0, " + + "14, 00, 00, 00, " + + "4D, 00, 37, 00, 21, 00, 58, 00, " + + "0B, 00, 2C, 00, 16, 00, 63, 00, " + + "42, 00, " + + "FF, DD, ]", HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "01 00 " + + "10 F0 " + + "14 00 00 00 " + + "4D 00 37 00 21 00 58 00 " + + "0B 00 2C 00 16 00 63 00 " + + "42 00 " + + "FF DD"; + byte[] data = HexRead.readFromString( hexData ); + EscherClientAnchorRecord r = new EscherClientAnchorRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 28, bytesWritten ); + assertEquals( (short) 55, r.getCol1() ); + assertEquals( (short) 44, r.getCol2() ); + assertEquals( (short) 33, r.getDx1() ); + assertEquals( (short) 22, r.getDx2() ); + assertEquals( (short) 11, r.getDy1() ); + assertEquals( (short) 66, r.getDy2() ); + assertEquals( (short) 77, r.getFlag() ); + assertEquals( (short) 88, r.getRow1() ); + assertEquals( (short) 99, r.getRow2() ); + assertEquals( (short) 0x0001, r.getOptions() ); + assertEquals( (byte) 0xFF, r.getRemainingData()[0] ); + assertEquals( (byte) 0xDD, r.getRemainingData()[1] ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherClientAnchorRecord:" + nl + + " RecordId: 0xF010" + nl + + " Options: 0x0001" + nl + + " Flag: 77" + nl + + " Col1: 55" + nl + + " DX1: 33" + nl + + " Row1: 88" + nl + + " DY1: 11" + nl + + " Col2: 44" + nl + + " DX2: 22" + nl + + " Row2: 99" + nl + + " DY2: 66" + nl + + " Extra Data:" + nl + + "00000000 FF DD .." + nl; + assertEquals( expected, createRecord().toString() ); + } + + private EscherClientAnchorRecord createRecord() + { + EscherClientAnchorRecord r = new EscherClientAnchorRecord(); + r.setCol1( (short) 55 ); + r.setCol2( (short) 44 ); + r.setDx1( (short) 33 ); + r.setDx2( (short) 22 ); + r.setDy1( (short) 11 ); + r.setDy2( (short) 66 ); + r.setFlag( (short) 77 ); + r.setRow1( (short) 88 ); + r.setRow2( (short) 99 ); + r.setOptions( (short) 0x0001 ); + r.setRemainingData( new byte[]{(byte) 0xFF, (byte) 0xDD} ); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java new file mode 100644 index 0000000000..a91e36896a --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java @@ -0,0 +1,57 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherClientDataRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherClientDataRecord r = createRecord(); + + byte[] data = new byte[8]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 8, bytesWritten ); + assertEquals( "[02, 00, " + + "11, F0, " + + "00, 00, 00, 00, ]", + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "02 00 " + + "11 F0 " + + "00 00 00 00 "; + byte[] data = HexRead.readFromString( hexData ); + EscherClientDataRecord r = new EscherClientDataRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 8, bytesWritten ); + assertEquals( (short)0xF011, r.getRecordId() ); + assertEquals( "[]", HexDump.toHex(r.getRemainingData()) ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherClientDataRecord:" + nl + + " RecordId: 0xF011" + nl + + " Options: 0x0002" + nl + + " Extra Data:" + nl + + "" ; + assertEquals( expected, createRecord().toString() ); + } + + private EscherClientDataRecord createRecord() + { + EscherClientDataRecord r = new EscherClientDataRecord(); + r.setOptions( (short) 0x0002 ); + r.setRecordId( EscherClientDataRecord.RECORD_ID ); + r.setRemainingData( new byte[] {} ); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java new file mode 100644 index 0000000000..9d74a3ee3e --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java @@ -0,0 +1,98 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.apache.poi.util.HexDump; + +public class TestEscherContainerRecord extends TestCase +{ + public void testFillFields() throws Exception + { + EscherRecordFactory f = new DefaultEscherRecordFactory(); + byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" ); + EscherRecord r = f.createRecord( data, 0 ); + r.fillFields( data, 0, f ); + assertTrue( r instanceof EscherContainerRecord ); + assertEquals( (short) 0x020F, r.getOptions() ); + assertEquals( (short) 0xF111, r.getRecordId() ); + + data = HexRead.readFromString( "0F 02 11 F1 08 00 00 00" + + " 02 00 22 F2 00 00 00 00" ); + r = f.createRecord( data, 0 ); + r.fillFields( data, 0, f ); + EscherRecord c = r.getChild( 0 ); + assertFalse( c instanceof EscherContainerRecord ); + assertEquals( (short) 0x0002, c.getOptions() ); + assertEquals( (short) 0xF222, c.getRecordId() ); + } + + public void testSerialize() throws Exception + { + UnknownEscherRecord r = new UnknownEscherRecord(); + r.setOptions( (short) 0x123F ); + r.setRecordId( (short) 0xF112 ); + byte[] data = new byte[8]; + r.serialize( 0, data, new NullEscherSerializationListener() ); + + assertEquals( "[3F, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); + + EscherRecord childRecord = new UnknownEscherRecord(); + childRecord.setOptions( (short) 0x9999 ); + childRecord.setRecordId( (short) 0xFF01 ); + r.addChildRecord( childRecord ); + data = new byte[16]; + r.serialize( 0, data, new NullEscherSerializationListener() ); + + assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); + + } + + public void testToString() throws Exception + { + EscherContainerRecord r = new EscherContainerRecord(); + r.setRecordId( EscherContainerRecord.SP_CONTAINER ); + r.setOptions( (short) 0x000F ); + String nl = System.getProperty( "line.separator" ); + assertEquals( "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + + " isContainer: true" + nl + + " options: 0x000F" + nl + + " recordId: 0xF004" + nl + + " numchildren: 0" + nl + , r.toString() ); + + EscherOptRecord r2 = new EscherOptRecord(); + r2.setOptions( (short) 0x9876 ); + r2.setRecordId( EscherOptRecord.RECORD_ID ); + + r.addChildRecord( r2 ); + String expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + + " isContainer: true" + nl + + " options: 0x000F" + nl + + " recordId: 0xF004" + nl + + " numchildren: 1" + nl + + " children: " + nl + + "org.apache.poi.ddf.EscherOptRecord:" + nl + + " isContainer: false" + nl + + " options: 0x0003" + nl + + " recordId: 0xF00B" + nl + + " numchildren: 0" + nl + + " properties:" + nl; + assertEquals( expected, r.toString() ); + + } + + public void testGetRecordSize() throws Exception + { + EscherContainerRecord r = new EscherContainerRecord(); + r.addChildRecord(new EscherRecord() + { + public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) { return 0; } + public int serialize( int offset, byte[] data, EscherSerializationListener listener ) { return 0; } + public int getRecordSize() { return 10; } + public String getRecordName() { return ""; } + } ); + + assertEquals(18, r.getRecordSize()); + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java new file mode 100644 index 0000000000..a7fa9bb52e --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java @@ -0,0 +1,62 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherDgRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherDgRecord r = createRecord(); + + byte[] data = new byte[16]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 16, bytesWritten ); + assertEquals( "[10, 00, " + + "08, F0, " + + "08, 00, 00, 00, " + + "02, 00, 00, 00, " + // num shapes in drawing + "01, 04, 00, 00, ]", // The last MSOSPID given to an SP in this DG + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "10 00 " + + "08 F0 " + + "08 00 00 00 " + + "02 00 00 00 " + + "01 04 00 00 "; + byte[] data = HexRead.readFromString( hexData ); + EscherDgRecord r = new EscherDgRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 16, bytesWritten ); + assertEquals( 2, r.getNumShapes() ); + assertEquals( 1025, r.getLastMSOSPID() ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherDgRecord:" + nl + + " RecordId: 0xF008" + nl + + " Options: 0x0010" + nl + + " NumShapes: 2" + nl + + " LastMSOSPID: 1025" + nl; + assertEquals( expected, createRecord().toString() ); + } + + private EscherDgRecord createRecord() + { + EscherDgRecord r = new EscherDgRecord(); + r.setOptions( (short) 0x0010 ); + r.setRecordId( EscherDgRecord.RECORD_ID ); + r.setNumShapes(2); + r.setLastMSOSPID(1025); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java new file mode 100644 index 0000000000..b632ae9902 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java @@ -0,0 +1,89 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherDggRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherDggRecord r = createRecord(); + + byte[] data = new byte[32]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 32, bytesWritten ); + assertEquals( "[00, 00, " + + "06, F0, " + + "18, 00, 00, 00, " + + "02, 04, 00, 00, " + + "02, 00, 00, 00, " + + "02, 00, 00, 00, " + + "01, 00, 00, 00, " + + "01, 00, 00, 00, 02, 00, 00, 00, ]", + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "00 00 " + + "06 F0 " + + "18 00 00 00 " + + "02 04 00 00 " + + "02 00 00 00 " + + "02 00 00 00 " + + "01 00 00 00 " + + "01 00 00 00 02 00 00 00"; + byte[] data = HexRead.readFromString( hexData ); + EscherDggRecord r = new EscherDggRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 32, bytesWritten ); + assertEquals( 0x402, r.getShapeIdMax() ); + assertEquals( 0x02, r.getNumIdClusters() ); + assertEquals( 0x02, r.getNumShapesSaved() ); + assertEquals( 0x01, r.getDrawingsSaved() ); + assertEquals( 1, r.getFileIdClusters().length ); + assertEquals( 0x01, r.getFileIdClusters()[0].getDrawingGroupId()); + assertEquals( 0x02, r.getFileIdClusters()[0].getNumShapeIdsUsed()); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherDggRecord:" + nl + + " RecordId: 0xF006" + nl + + " Options: 0x0000" + nl + + " ShapeIdMax: 1026" + nl + + " NumIdClusters: 2" + nl + + " NumShapesSaved: 2" + nl + + " DrawingsSaved: 1" + nl + + " DrawingGroupId1: 1" + nl + + " NumShapeIdsUsed1: 2" + nl; + assertEquals( expected, createRecord().toString() ); + } + + private EscherDggRecord createRecord() + { + EscherDggRecord r = new EscherDggRecord(); + r.setOptions( (short) 0x0000 ); + r.setRecordId( EscherDggRecord.RECORD_ID ); + r.setShapeIdMax( 0x402 ); + r.setNumShapesSaved( 0x02 ); + r.setDrawingsSaved( 0x01 ); + r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { + new EscherDggRecord.FileIdCluster( 1, 2 ) + }); + return r; + } + + public void testGetRecordSize() throws Exception + { + EscherDggRecord r = new EscherDggRecord(); + r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { new EscherDggRecord.FileIdCluster(0,0) } ); + assertEquals(32,r.getRecordSize()); + + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java new file mode 100644 index 0000000000..dc5511a7b9 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java @@ -0,0 +1,140 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.apache.poi.util.HexDump; + +import java.io.IOException; + +public class TestEscherOptRecord extends TestCase +{ + + public void testFillFields() throws Exception + { + checkFillFieldsSimple(); + checkFillFieldsComplex(); + } + + private void checkFillFieldsComplex() throws IOException + { + String dataStr = "33 00 " + + "0B F0 " + + "14 00 00 00 " + + "BF 00 01 00 00 00 " + + "01 80 02 00 00 00 " + + "BF 00 01 00 00 00 " + + "01 02"; + + EscherOptRecord r = new EscherOptRecord(); + r.fillFields( HexRead.readFromString( dataStr ), new DefaultEscherRecordFactory() ); + assertEquals( (short) 0x0033, r.getOptions() ); + assertEquals( (short) 0xF00B, r.getRecordId() ); + assertEquals( 3, r.getEscherProperties().size() ); + EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); + EscherComplexProperty prop2 = new EscherComplexProperty( (short) 1, false, new byte[] { 0x01, 0x02 } ); + EscherBoolProperty prop3 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); + assertEquals( prop1, r.getEscherProperty( 0 ) ); + assertEquals( prop2, r.getEscherProperty( 1 ) ); + assertEquals( prop3, r.getEscherProperty( 2 ) ); + + } + + private void checkFillFieldsSimple() + throws IOException + { + String dataStr = "33 00 " + // options + "0B F0 " + // recordid + "12 00 00 00 " + // remaining bytes + "BF 00 08 00 08 00 " + + "81 01 09 00 00 08 " + + "C0 01 40 00 00 08"; + + EscherOptRecord r = new EscherOptRecord(); + r.fillFields( HexRead.readFromString( dataStr ), new DefaultEscherRecordFactory() ); + assertEquals( (short) 0x0033, r.getOptions() ); + assertEquals( (short) 0xF00B, r.getRecordId() ); + assertEquals( 3, r.getEscherProperties().size() ); + EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296 ); + EscherRGBProperty prop2 = new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, 0x08000009 ); + EscherRGBProperty prop3 = new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, 0x08000040 ); + assertEquals( prop1, r.getEscherProperty( 0 ) ); + assertEquals( prop2, r.getEscherProperty( 1 ) ); + assertEquals( prop3, r.getEscherProperty( 2 ) ); + } + + public void testSerialize() throws Exception + { + checkSerializeSimple(); + checkSerializeComplex(); + } + + private void checkSerializeComplex() + { + //Complex escher record + EscherOptRecord r = new EscherOptRecord(); + r.setOptions( (short) 0x0033 ); + r.setRecordId( (short) 0xF00B ); + EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); + EscherComplexProperty prop2 = new EscherComplexProperty( (short) 1, false, new byte[] { 0x01, 0x02 } ); + EscherBoolProperty prop3 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); + r.addEscherProperty( prop1 ); + r.addEscherProperty( prop2 ); + r.addEscherProperty( prop3 ); + + byte[] data = new byte[28]; + int bytesWritten = r.serialize(0, data, new NullEscherSerializationListener() ); + assertEquals( 28, bytesWritten ); + String dataStr = "[33, 00, " + + "0B, F0, " + + "14, 00, 00, 00, " + + "BF, 00, 01, 00, 00, 00, " + + "01, 80, 02, 00, 00, 00, " + + "BF, 00, 01, 00, 00, 00, " + + "01, 02, ]"; + assertEquals( dataStr, HexDump.toHex(data) ); + + } + + private void checkSerializeSimple() + { + EscherOptRecord r = new EscherOptRecord(); + r.setOptions( (short) 0x0033 ); + r.setRecordId( (short) 0xF00B ); + EscherBoolProperty prop1 = new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 1 ); + EscherRGBProperty prop2 = new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, 0x08000009 ); + EscherRGBProperty prop3 = new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, 0x08000040 ); + r.addEscherProperty( prop1 ); + r.addEscherProperty( prop2 ); + r.addEscherProperty( prop3 ); + + byte[] data = new byte[26]; + int bytesWritten = r.serialize(0, data, new NullEscherSerializationListener() ); + String dataStr = "[33, 00, " + + "0B, F0, " + + "12, 00, 00, 00, " + + "BF, 00, 01, 00, 00, 00, " + + "81, 01, 09, 00, 00, 08, " + + "C0, 01, 40, 00, 00, 08, ]"; + assertEquals( dataStr, HexDump.toHex(data) ); + assertEquals( 26, bytesWritten ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + EscherOptRecord r = new EscherOptRecord(); + r.setOptions((short)0x000F); + r.setRecordId(EscherOptRecord.RECORD_ID); + EscherProperty prop1 = new EscherBoolProperty((short)1, 1); + r.addEscherProperty(prop1); + String expected = "org.apache.poi.ddf.EscherOptRecord:" + nl + + " isContainer: true" + nl + + " options: 0x0013" + nl + + " recordId: 0x" + HexDump.toHex(EscherOptRecord.RECORD_ID) + nl + + " numchildren: 0" + nl + + " properties:" + nl + + " propNum: 1, propName: unknown, complex: false, blipId: false, value: 1 (0x00000001)" + nl; + assertEquals( expected, r.toString()); + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java new file mode 100644 index 0000000000..3caa156ad6 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java @@ -0,0 +1,42 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; + +import java.util.List; + +import org.apache.poi.util.HexRead; +import org.apache.poi.util.HexDump; + +/** + * @author Glen Stampoultzis (glens @ superlinksoftware.com) + */ +public class TestEscherPropertyFactory extends TestCase +{ + public void testCreateProperties() throws Exception + { + String dataStr = "41 C1 " + // propid, complex ind + "03 00 00 00 " + // size of complex property + "01 00 " + // propid, complex ind + "00 00 00 00 " + // value + "41 C1 " + // propid, complex ind + "03 00 00 00 " + // size of complex property + "01 02 03 " + + "01 02 03 " + ; + byte[] data = HexRead.readFromString( dataStr ); + EscherPropertyFactory f = new EscherPropertyFactory(); + List props = f.createProperties( data, 0, (short)3 ); + EscherComplexProperty p1 = (EscherComplexProperty) props.get( 0 ); + assertEquals( (short)0xC141, p1.getId() ); + assertEquals( "[01, 02, 03, ]", HexDump.toHex( p1.getComplexData() ) ); + + EscherComplexProperty p3 = (EscherComplexProperty) props.get( 2 ); + assertEquals( (short)0xC141, p3.getId() ); + assertEquals( "[01, 02, 03, ]", HexDump.toHex( p3.getComplexData() ) ); + + + } + + + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java new file mode 100644 index 0000000000..448aee6540 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java @@ -0,0 +1,62 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherSpRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherSpRecord r = createRecord(); + + byte[] data = new byte[16]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 16, bytesWritten ); + assertEquals( "[02, 00, " + + "0A, F0, " + + "08, 00, 00, 00, " + + "00, 04, 00, 00, " + + "05, 00, 00, 00, ]", + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "02 00 " + + "0A F0 " + + "08 00 00 00 " + + "00 04 00 00 " + + "05 00 00 00 "; + byte[] data = HexRead.readFromString( hexData ); + EscherSpRecord r = new EscherSpRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 16, bytesWritten ); + assertEquals( 0x0400, r.getShapeId() ); + assertEquals( 0x05, r.getFlags() ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherSpRecord:" + nl + + " RecordId: 0xF00A" + nl + + " Options: 0x0002" + nl + + " ShapeId: 1024" + nl + + " Flags: GROUP|PATRIARCH (0x00000005)" + nl; + assertEquals( expected, createRecord().toString() ); + } + + private EscherSpRecord createRecord() + { + EscherSpRecord r = new EscherSpRecord(); + r.setOptions( (short) 0x0002 ); + r.setRecordId( EscherSpRecord.RECORD_ID ); + r.setShapeId(0x0400); + r.setFlags(0x05); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java new file mode 100644 index 0000000000..3ec276ab97 --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java @@ -0,0 +1,73 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherSpgrRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherSpgrRecord r = createRecord(); + + byte[] data = new byte[24]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 24, bytesWritten ); + assertEquals( "[10, 00, " + + "09, F0, " + + "10, 00, 00, 00, " + + "01, 00, 00, 00, " + // x + "02, 00, 00, 00, " + // y + "03, 00, 00, 00, " + // width + "04, 00, 00, 00, ]", // height + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "10 00 " + + "09 F0 " + + "10 00 00 00 " + + "01 00 00 00 " + + "02 00 00 00 " + + "03 00 00 00 " + + "04 00 00 00 "; + byte[] data = HexRead.readFromString( hexData ); + EscherSpgrRecord r = new EscherSpgrRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 24, bytesWritten ); + assertEquals( 1, r.getRectX1() ); + assertEquals( 2, r.getRectY1() ); + assertEquals( 3, r.getRectX2() ); + assertEquals( 4, r.getRectY2() ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherSpgrRecord:" + nl + + " RecordId: 0xF009" + nl + + " Options: 0x0010" + nl + + " RectX: 1" + nl + + " RectY: 2" + nl + + " RectWidth: 3" + nl + + " RectHeight: 4" + nl; + ; + assertEquals( expected, createRecord().toString() ); + } + + private EscherSpgrRecord createRecord() + { + EscherSpgrRecord r = new EscherSpgrRecord(); + r.setOptions( (short) 0x0010 ); + r.setRecordId( EscherSpgrRecord.RECORD_ID ); + r.setRectX1(1); + r.setRectY1(2); + r.setRectX2(3); + r.setRectY2(4); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java new file mode 100644 index 0000000000..2550800c2e --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java @@ -0,0 +1,73 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; + +public class TestEscherSplitMenuColorsRecord extends TestCase +{ + public void testSerialize() throws Exception + { + EscherSplitMenuColorsRecord r = createRecord(); + + byte[] data = new byte[24]; + int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); + assertEquals( 24, bytesWritten ); + assertEquals( "[40, 00, " + + "1E, F1, " + + "10, 00, 00, 00, " + + "02, 04, 00, 00, " + + "02, 00, 00, 00, " + + "02, 00, 00, 00, " + + "01, 00, 00, 00, ]", + HexDump.toHex( data ) ); + } + + public void testFillFields() throws Exception + { + String hexData = "40 00 " + + "1E F1 " + + "10 00 00 00 " + + "02 04 00 00 " + + "02 00 00 00 " + + "02 00 00 00 " + + "01 00 00 00 "; + byte[] data = HexRead.readFromString( hexData ); + EscherSplitMenuColorsRecord r = new EscherSplitMenuColorsRecord(); + int bytesWritten = r.fillFields( data, new DefaultEscherRecordFactory() ); + + assertEquals( 24, bytesWritten ); + assertEquals( 0x0402, r.getColor1() ); + assertEquals( 0x02, r.getColor2() ); + assertEquals( 0x02, r.getColor3() ); + assertEquals( 0x01, r.getColor4() ); + } + + public void testToString() throws Exception + { + String nl = System.getProperty("line.separator"); + + String expected = "org.apache.poi.ddf.EscherSplitMenuColorsRecord:" + nl + + " RecordId: 0xF11E" + nl + + " Options: 0x0040" + nl + + " Color1: 0x00000402" + nl + + " Color2: 0x00000002" + nl + + " Color3: 0x00000002" + nl + + " Color4: 0x00000001" + nl + + ""; + assertEquals( expected, createRecord().toString() ); + } + + private EscherSplitMenuColorsRecord createRecord() + { + EscherSplitMenuColorsRecord r = new EscherSplitMenuColorsRecord(); + r.setOptions( (short) 0x0040 ); + r.setRecordId( EscherSplitMenuColorsRecord.RECORD_ID ); + r.setColor1( 0x402 ); + r.setColor2( 0x2 ); + r.setColor3( 0x2 ); + r.setColor4( 0x1 ); + return r; + } + +} diff --git a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java new file mode 100644 index 0000000000..f61cfc6b4d --- /dev/null +++ b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java @@ -0,0 +1,106 @@ +package org.apache.poi.ddf; + +import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.apache.poi.util.HexDump; + +public class TestUnknownEscherRecord extends TestCase +{ + public void testFillFields() throws Exception + { + String testData = + "0F 02 " + // options + "11 F1 " + // record id + "00 00 00 00"; // remaining bytes + + UnknownEscherRecord r = new UnknownEscherRecord(); + EscherRecordFactory factory = new DefaultEscherRecordFactory(); + r.fillFields( HexRead.readFromString( testData ), factory ); + + assertEquals( 0x020F, r.getOptions() ); + assertEquals( (short) 0xF111, r.getRecordId() ); + assertTrue( r.isContainerRecord() ); + assertEquals( 8, r.getRecordSize() ); + assertEquals( 0, r.getChildRecords().size() ); + assertEquals( 0, r.getData().length ); + + testData = + "00 02 " + // options + "11 F1 " + // record id + "04 00 00 00 " + // remaining bytes + "01 02 03 04"; + + r = new UnknownEscherRecord(); + r.fillFields( HexRead.readFromString( testData ), factory ); + + assertEquals( 0x0200, r.getOptions() ); + assertEquals( (short) 0xF111, r.getRecordId() ); + assertEquals( 12, r.getRecordSize() ); + assertFalse( r.isContainerRecord() ); + assertEquals( 0, r.getChildRecords().size() ); + assertEquals( 4, r.getData().length ); + assertEquals( 1, r.getData()[0] ); + assertEquals( 2, r.getData()[1] ); + assertEquals( 3, r.getData()[2] ); + assertEquals( 4, r.getData()[3] ); + + testData = + "0F 02 " + // options + "11 F1 " + // record id + "08 00 00 00 " + // remaining bytes + "00 02 " + // options + "FF FF " + // record id + "00 00 00 00"; // remaining bytes + + r = new UnknownEscherRecord(); + r.fillFields( HexRead.readFromString( testData ), factory ); + + assertEquals( 0x020F, r.getOptions() ); + assertEquals( (short) 0xF111, r.getRecordId() ); + assertEquals( 8, r.getRecordSize() ); + assertTrue( r.isContainerRecord() ); + assertEquals( 1, r.getChildRecords().size() ); + assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() ); + + } + + public void testSerialize() throws Exception + { + UnknownEscherRecord r = new UnknownEscherRecord(); + r.setOptions( (short) 0x1234 ); + r.setRecordId( (short) 0xF112 ); + byte[] data = new byte[8]; + r.serialize( 0, data, new NullEscherSerializationListener() ); + + assertEquals( "[34, 12, 12, F1, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); + + EscherRecord childRecord = new UnknownEscherRecord(); + childRecord.setOptions( (short) 0x9999 ); + childRecord.setRecordId( (short) 0xFF01 ); + r.addChildRecord( childRecord ); + r.setOptions( (short) 0x123F ); + data = new byte[16]; + r.serialize( 0, data, new NullEscherSerializationListener() ); + + assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00, ]", HexDump.toHex( data ) ); + } + + public void testToString() throws Exception + { + UnknownEscherRecord r = new UnknownEscherRecord(); + r.setOptions( (short) 0x1234 ); + r.setRecordId( (short) 0xF112 ); + byte[] data = new byte[8]; + r.serialize( 0, data, new NullEscherSerializationListener() ); + + String nl = System.getProperty("line.separator"); + assertEquals( "org.apache.poi.ddf.UnknownEscherRecord:" + nl + + " isContainer: false" + nl + + " options: 0x1234" + nl + + " recordId: 0xF112" + nl + + " numchildren: 0" + nl + , r.toString() ); + } + + +} diff --git a/src/testcases/org/apache/poi/hssf/model/TestDrawingManager.java b/src/testcases/org/apache/poi/hssf/model/TestDrawingManager.java new file mode 100644 index 0000000000..606ffccc34 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/model/TestDrawingManager.java @@ -0,0 +1,81 @@ +package org.apache.poi.hssf.model; + +import junit.framework.TestCase; +import org.apache.poi.ddf.EscherDggRecord; +import org.apache.poi.ddf.EscherDgRecord; + +public class TestDrawingManager extends TestCase +{ + public void testFindFreeSPIDBlock() throws Exception + { + EscherDggRecord dgg = new EscherDggRecord(); + DrawingManager dm = new DrawingManager( dgg ); + dgg.setShapeIdMax( 1024 ); + assertEquals( 2048, dm.findFreeSPIDBlock() ); + dgg.setShapeIdMax( 1025 ); + assertEquals( 2048, dm.findFreeSPIDBlock() ); + dgg.setShapeIdMax( 2047 ); + assertEquals( 2048, dm.findFreeSPIDBlock() ); + } + + public void testFindNewDrawingGroupId() throws Exception + { + EscherDggRecord dgg = new EscherDggRecord(); + dgg.setDrawingsSaved( 1 ); + dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{ + new EscherDggRecord.FileIdCluster( 2, 10 )} ); + DrawingManager dm = new DrawingManager( dgg ); + assertEquals( 1, dm.findNewDrawingGroupId() ); + dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{ + new EscherDggRecord.FileIdCluster( 1, 10 ), + new EscherDggRecord.FileIdCluster( 2, 10 )} ); + assertEquals( 3, dm.findNewDrawingGroupId() ); + } + + public void testDrawingGroupExists() throws Exception + { + EscherDggRecord dgg = new EscherDggRecord(); + dgg.setDrawingsSaved( 1 ); + dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{ + new EscherDggRecord.FileIdCluster( 2, 10 )} ); + DrawingManager dm = new DrawingManager( dgg ); + assertFalse( dm.drawingGroupExists( (short) 1 ) ); + assertTrue( dm.drawingGroupExists( (short) 2 ) ); + assertFalse( dm.drawingGroupExists( (short) 3 ) ); + } + + public void testCreateDgRecord() throws Exception + { + EscherDggRecord dgg = new EscherDggRecord(); + dgg.setDrawingsSaved( 0 ); + dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{} ); + DrawingManager dm = new DrawingManager( dgg ); + + EscherDgRecord dgRecord = dm.createDgRecord(); + assertEquals( -1, dgRecord.getLastMSOSPID() ); + assertEquals( 0, dgRecord.getNumShapes() ); + assertEquals( 1, dm.getDgg().getDrawingsSaved() ); + assertEquals( 1, dm.getDgg().getFileIdClusters().length ); + assertEquals( 1, dm.getDgg().getFileIdClusters()[0].getDrawingGroupId() ); + assertEquals( 0, dm.getDgg().getFileIdClusters()[0].getNumShapeIdsUsed() ); + } + + public void testAllocateShapeId() throws Exception + { + EscherDggRecord dgg = new EscherDggRecord(); + dgg.setDrawingsSaved( 0 ); + dgg.setFileIdClusters( new EscherDggRecord.FileIdCluster[]{} ); + DrawingManager dm = new DrawingManager( dgg ); + + EscherDgRecord dg = dm.createDgRecord(); + int shapeId = dm.allocateShapeId( dg.getDrawingGroupId() ); + assertEquals( 1024, shapeId ); + assertEquals( 1025, dgg.getShapeIdMax() ); + assertEquals( 1, dgg.getDrawingsSaved() ); + assertEquals( 1, dgg.getFileIdClusters()[0].getDrawingGroupId() ); + assertEquals( 1, dgg.getFileIdClusters()[0].getNumShapeIdsUsed() ); + assertEquals( 1024, dg.getLastMSOSPID() ); + assertEquals( 1, dg.getNumShapes() ); + } + +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java new file mode 100644 index 0000000000..2ffe2c2ce2 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java @@ -0,0 +1,127 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the CommonObjectDataSubRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestCommonObjectDataSubRecord + extends TestCase +{ + byte[] data = new byte[] { + (byte)0x12,(byte)0x00,(byte)0x01,(byte)0x00, + (byte)0x01,(byte)0x00,(byte)0x11,(byte)0x60, + (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, + (byte)0x00,(byte)0x0D,(byte)0x26,(byte)0x01, + (byte)0x00,(byte)0x00, + }; + + public TestCommonObjectDataSubRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + CommonObjectDataSubRecord record = new CommonObjectDataSubRecord((short)0x15, (short)data.length, data); + + + assertEquals( CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX, record.getObjectType()); + assertEquals( (short)1, record.getObjectId()); + assertEquals( (short)1, record.getOption()); + assertEquals( true , record.isLocked() ); + assertEquals( false, record.isPrintable() ); + assertEquals( false, record.isAutofill() ); + assertEquals( false, record.isAutoline() ); + assertEquals( (int)24593, record.getReserved1()); + assertEquals( (int)218103808, record.getReserved2()); + assertEquals( (int)294, record.getReserved3()); + assertEquals( 22 , record.getRecordSize() ); + + record.validateSid((short)0x15); + } + + public void testStore() + { + CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(); + + record.setObjectType( CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX ); + record.setObjectId( (short) 1); + record.setOption( (short) 1); + record.setLocked( true ); + record.setPrintable( false ); + record.setAutofill( false ); + record.setAutoline( false ); + record.setReserved1( (int) 24593); + record.setReserved2( (int) 218103808); + record.setReserved3( (int) 294); + + 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]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java new file mode 100644 index 0000000000..4c42eca886 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java @@ -0,0 +1,36 @@ +package org.apache.poi.hssf.record; + +import junit.framework.TestCase; +import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.ddf.EscherSpRecord; +import org.apache.poi.util.HexDump; + +public class TestDrawingGroupRecord extends TestCase +{ + public void testGetRecordSize() + throws Exception + { + DrawingGroupRecord r = new DrawingGroupRecord(); + assertEquals(4, r.getRecordSize()); + + EscherSpRecord sp = new EscherSpRecord(); + sp.setRecordId(EscherSpRecord.RECORD_ID); + sp.setOptions((short) 0x1111); + sp.setFlags(-1); + sp.setShapeId(-1); + EscherContainerRecord dggContainer = new EscherContainerRecord(); + dggContainer.setOptions((short) 0x000F); + dggContainer.setRecordId((short) 0xF000); + dggContainer.addChildRecord(sp); + + r.addEscherRecord(dggContainer); + assertEquals(28, r.getRecordSize()); + + byte[] data = new byte[28]; + int size = r.serialize(0, data); + assertEquals("[EB, 00, 18, 00, 0F, 00, 00, F0, 10, 00, 00, 00, 11, 11, 0A, F0, 08, 00, 00, 00, FF, FF, FF, FF, FF, FF, FF, FF, ]", HexDump.toHex(data)); + assertEquals(28, size); + + assertEquals(24, dggContainer.getRecordSize()); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java new file mode 100644 index 0000000000..d338601948 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestEndSubRecord.java @@ -0,0 +1,102 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the EndSubRecord + * class works correctly. Test data taken directly from a real + * Excel file. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestEndSubRecord + extends TestCase +{ + byte[] data = new byte[] { + + }; + + public TestEndSubRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + EndSubRecord record = new EndSubRecord((short)0x00, (short)data.length, data); + + + + assertEquals( 4, record.getRecordSize() ); + + record.validateSid((short)0x00); + } + + public void testStore() + { + EndSubRecord record = new EndSubRecord(); + + 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]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java new file mode 100644 index 0000000000..f7acf2f0d5 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java @@ -0,0 +1,124 @@ +package org.apache.poi.hssf.record; + +import junit.framework.TestCase; +import org.apache.poi.util.HexRead; +import org.apache.poi.util.HexDump; +import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.ddf.EscherSpRecord; +import org.apache.poi.ddf.EscherClientDataRecord; +import org.apache.poi.ddf.EscherDggRecord; +import org.apache.poi.hssf.model.DrawingManager; +import org.apache.poi.hssf.model.Sheet; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tests the EscherAggregate class. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestEscherAggregate extends TestCase +{ + /** + * Tests that the create aggregate method correctly rejoins escher records together. + * + * @throws Exception + */ + public void testCreateAggregate() throws Exception + { + String msoDrawingRecord1 = + "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" + + "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" + + "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" + + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" + + "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" + + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" + + "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" + + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" + + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" + + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" + + "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" + + "05 00 94 00 00 00 11 F0 00 00 00 00"; + + String msoDrawingRecord2 = + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + + "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " + + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + + "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " + + "0B 00 0C 00 00 00 11 F0 00 00 00 00"; + + DrawingRecord d1 = new DrawingRecord(); + d1.setData( HexRead.readFromString( msoDrawingRecord1 ) ); + + ObjRecord r1 = new ObjRecord(); + + DrawingRecord d2 = new DrawingRecord(); + d2.setData( HexRead.readFromString( msoDrawingRecord2 ) ); + + ObjRecord r2 = new ObjRecord(); + + List records = new ArrayList(); + records.add( d1 ); + records.add( r1 ); + records.add( d2 ); + records.add( r2 ); + + DrawingManager drawingManager = new DrawingManager(new EscherDggRecord() ); + EscherAggregate aggregate = EscherAggregate.createAggregate( records, 0, drawingManager ); + + assertEquals( 1, aggregate.getEscherRecords().size() ); + assertEquals( (short) 0xF002, aggregate.getEscherRecord( 0 ).getRecordId() ); + assertEquals( 2, aggregate.getEscherRecord( 0 ).getChildRecords().size() ); + +// System.out.println( "aggregate = " + aggregate ); + } + + public void testSerialize() throws Exception + { + + EscherContainerRecord container1 = new EscherContainerRecord(); + EscherContainerRecord spContainer1 = new EscherContainerRecord(); + EscherContainerRecord spContainer2 = new EscherContainerRecord(); + EscherContainerRecord spContainer3 = new EscherContainerRecord(); + EscherSpRecord sp1 = new EscherSpRecord(); + EscherSpRecord sp2 = new EscherSpRecord(); + EscherSpRecord sp3 = new EscherSpRecord(); + EscherClientDataRecord d2 = new EscherClientDataRecord(); + EscherClientDataRecord d3 = new EscherClientDataRecord(); + + container1.setOptions( (short) 0x000F ); + spContainer1.setOptions( (short) 0x000F ); + spContainer1.setRecordId( EscherContainerRecord.SP_CONTAINER ); + spContainer2.setOptions( (short) 0x000F ); + spContainer2.setRecordId( EscherContainerRecord.SP_CONTAINER ); + spContainer3.setOptions( (short) 0x000F ); + spContainer3.setRecordId( EscherContainerRecord.SP_CONTAINER ); + d2.setRecordId( EscherClientDataRecord.RECORD_ID ); + d2.setRemainingData( new byte[0] ); + d3.setRecordId( EscherClientDataRecord.RECORD_ID ); + d3.setRemainingData( new byte[0] ); + container1.addChildRecord( spContainer1 ); + container1.addChildRecord( spContainer2 ); + container1.addChildRecord( spContainer3 ); + spContainer1.addChildRecord( sp1 ); + spContainer2.addChildRecord( sp2 ); + spContainer3.addChildRecord( sp3 ); + spContainer2.addChildRecord( d2 ); + spContainer3.addChildRecord( d3 ); + + EscherAggregate aggregate = new EscherAggregate(null); + aggregate.addEscherRecord( container1 ); + aggregate.assoicateShapeToObjRecord( d2, new ObjRecord() ); + aggregate.assoicateShapeToObjRecord( d3, new ObjRecord() ); + + byte[] data = new byte[112]; + int bytesWritten = aggregate.serialize( 0, data ); + assertEquals( 112, bytesWritten ); + assertEquals( "[EC, 00, 40, 00, 0F, 00, 00, 00, 58, 00, 00, 00, 0F, 00, 04, F0, 10, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, EC, 00, 20, 00, 0F, 00, 04, F0, 18, 00, 00, 00, 00, 00, 0A, F0, 08, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 11, F0, 00, 00, 00, 00, 5D, 00, 00, 00, ]", + HexDump.toHex( data ) ); + } + +} diff --git a/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java new file mode 100644 index 0000000000..1e95653aef --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java @@ -0,0 +1,137 @@ + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache POI" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache POI", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + + +package org.apache.poi.hssf.record; + + +import junit.framework.TestCase; + +/** + * Tests the serialization and deserialization of the TextObjectBaseRecord + * 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 TestTextObjectBaseRecord(String name) + { + super(name); + } + + public void testLoad() + throws Exception + { + TextObjectBaseRecord record = new TextObjectBaseRecord((short)0x1B6, (short)data.length, data); + + +// 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( 22, record.getRecordSize() ); + + record.validateSid((short)0x1B6); + } + + public void testStore() + { + TextObjectBaseRecord record = new TextObjectBaseRecord(); + + + +// 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 ); + + 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]); + } +} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java new file mode 100644 index 0000000000..336b961f42 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics.java @@ -0,0 +1,71 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +import java.awt.*; + +/** + * Tests the capabilities of the EscherGraphics class. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestEscherGraphics extends TestCase +{ + private HSSFShapeGroup escherGroup; + private EscherGraphics graphics; + + protected void setUp() throws Exception + { + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("test"); + escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); + escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); + graphics = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); + super.setUp(); + } + + public void testGetFont() throws Exception + { + Font f = graphics.getFont(); + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); + } + + public void testGetFontMetrics() throws Exception + { + FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); + assertEquals(7, fontMetrics.charWidth('X')); + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); + } + + public void testSetFont() throws Exception + { + Font f = new Font("Helvetica", 0, 12); + graphics.setFont(f); + assertEquals(f, graphics.getFont()); + } + + public void testSetColor() throws Exception + { + graphics.setColor(Color.red); + assertEquals(Color.red, graphics.getColor()); + } + + public void testFillRect() throws Exception + { + graphics.fillRect( 10, 10, 20, 20 ); + HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); + assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); + assertEquals(10, s.getAnchor().getDx1()); + assertEquals(10, s.getAnchor().getDy1()); + assertEquals(30, s.getAnchor().getDy2()); + assertEquals(30, s.getAnchor().getDx2()); + } + + public void testDrawString() throws Exception + { + graphics.drawString("This is a test", 10, 10); + HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); + assertEquals("This is a test", t.getString().toString()); + } + +} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java new file mode 100644 index 0000000000..22f0e28c45 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java @@ -0,0 +1,74 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +import java.awt.*; +import java.io.FileOutputStream; + +/** + * Tests the Graphics2d drawing capability. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestEscherGraphics2d extends TestCase +{ + private HSSFShapeGroup escherGroup; + private EscherGraphics2d graphics; + + protected void setUp() throws Exception + { + super.setUp(); + + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("test"); + escherGroup = sheet.createDrawingPatriarch().createGroup(new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short) 0,0)); + escherGroup = new HSSFShapeGroup(null, new HSSFChildAnchor()); + EscherGraphics g = new EscherGraphics(this.escherGroup, workbook, Color.black, 1.0f); + graphics = new EscherGraphics2d(g); + + } + + public void testDrawString() throws Exception + { + graphics.drawString("This is a test", 10, 10); + HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0); + assertEquals("This is a test", t.getString().toString()); + } + + public void testFillRect() throws Exception + { + graphics.fillRect( 10, 10, 20, 20 ); + HSSFSimpleShape s = (HSSFSimpleShape) escherGroup.getChildren().get(0); + assertEquals(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE, s.getShapeType()); + assertEquals(10, s.getAnchor().getDx1()); + assertEquals(10, s.getAnchor().getDy1()); + assertEquals(30, s.getAnchor().getDy2()); + assertEquals(30, s.getAnchor().getDx2()); + } + + public void testGetFontMetrics() throws Exception + { + FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont()); + assertEquals(7, fontMetrics.charWidth('X')); + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString()); + } + + public void testSetFont() throws Exception + { + Font f = new Font("Helvetica", 0, 12); + graphics.setFont(f); + assertEquals(f, graphics.getFont()); + } + + public void testSetColor() throws Exception + { + graphics.setColor(Color.red); + assertEquals(Color.red, graphics.getColor()); + } + + public void testGetFont() throws Exception + { + Font f = graphics.getFont(); + assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", f.toString()); + } +} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java new file mode 100644 index 0000000000..532e62568b --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFontDetails.java @@ -0,0 +1,45 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +import java.util.Properties; + +/** + * Tests the implementation of the FontDetails class. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestFontDetails extends TestCase +{ + private Properties properties; + private FontDetails fontDetails; + + protected void setUp() throws Exception + { + properties = new Properties(); + properties.setProperty("font.Arial.height", "13"); + properties.setProperty("font.Arial.characters", "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "); + properties.setProperty("font.Arial.widths", "6, 6, 6, 6, 6, 3, 6, 6, 3, 4, 6, 3, 9, 6, 6, 6, 6, 4, 6, 3, 6, 7, 9, 6, 5, 5, 7, 7, 7, 7, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 8, 7, 8, 7, 7, 5, 7, 7, 9, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, "); + fontDetails = FontDetails.create("Arial", properties); + + } + + public void testCreate() throws Exception + { + assertEquals(13, fontDetails.getHeight()); + assertEquals(6, fontDetails.getCharWidth('a')); + assertEquals(3, fontDetails.getCharWidth('f')); + } + + public void testGetStringWidth() throws Exception + { + assertEquals(9, fontDetails.getStringWidth("af")); + } + + public void testGetCharWidth() throws Exception + { + assertEquals(6, fontDetails.getCharWidth('a')); + assertEquals(9, fontDetails.getCharWidth('=')); + } + +} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java new file mode 100644 index 0000000000..ab3e06a3d6 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFClientAnchor.java @@ -0,0 +1,44 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +/** + * Various tests for HSSFClientAnchor. + * + * @author Glen Stampoultzis (glens at apache.org) + */ +public class TestHSSFClientAnchor extends TestCase +{ + public void testGetAnchorHeightInPoints() throws Exception + { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet("test"); + HSSFClientAnchor a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0); + float p = a.getAnchorHeightInPoints(sheet); + assertEquals(11.953,p,0.001); + + sheet.createRow(0).setHeightInPoints(14); + a = new HSSFClientAnchor(0,0,1023,255,(short)0,0,(short)0,0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(13.945,p,0.001); + + a = new HSSFClientAnchor(0,0,1023,127,(short)0,0,(short)0,0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(6.945,p,0.001); + + a = new HSSFClientAnchor(0,126,1023,127,(short)0,0,(short)0,0); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(0.054,p,0.001); + + a = new HSSFClientAnchor(0,0,1023,0,(short)0,0,(short)0,1); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(14.0,p,0.001); + + sheet.createRow(0).setHeightInPoints(12); + a = new HSSFClientAnchor(0,127,1023,127,(short)0,0,(short)0,1); + p = a.getAnchorHeightInPoints(sheet); + assertEquals(12.0,p,0.001); + + } + +} diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java index 788eeef0f3..ae914ba4c8 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPalette.java @@ -178,7 +178,20 @@ public class TestHSSFPalette extends TestCase c.compare(expectedColor, paletteColor); } } - + + public void testAddColor() throws Exception + { + try + { + HSSFColor hssfColor = hssfPalette.addColor((byte)10,(byte)10,(byte)10); + fail(); + } + catch ( RuntimeException e ) + { + // Failing because by default there are no colours left in the palette. + } + } + private static interface ColorComparator { void compare(HSSFColor expected, HSSFColor palette); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java new file mode 100644 index 0000000000..69dcb78e7e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRichTextString.java @@ -0,0 +1,50 @@ +package org.apache.poi.hssf.usermodel; + +import junit.framework.TestCase; + +public class TestHSSFRichTextString extends TestCase +{ + public void testApplyFont() throws Exception + { + + HSSFRichTextString r = new HSSFRichTextString("testing"); + assertEquals(1,r.numFormattingRuns()); + r.applyFont(2,4, new HSSFFont((short)1, null)); + assertEquals(3,r.numFormattingRuns()); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1)); + assertEquals(1, r.getFontAtIndex(2)); + assertEquals(1, r.getFontAtIndex(3)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(6)); + + r.applyFont(6,7, new HSSFFont((short)2, null)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1)); + assertEquals(1, r.getFontAtIndex(2)); + assertEquals(1, r.getFontAtIndex(3)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5)); + assertEquals(2, r.getFontAtIndex(6)); + + r.applyFont(HSSFRichTextString.NO_FONT); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(2)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(3)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4)); + assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5)); + + r.applyFont(new HSSFFont((short)1, null)); + assertEquals(1, r.getFontAtIndex(0)); + assertEquals(1, r.getFontAtIndex(1)); + assertEquals(1, r.getFontAtIndex(2)); + assertEquals(1, r.getFontAtIndex(3)); + assertEquals(1, r.getFontAtIndex(4)); + assertEquals(1, r.getFontAtIndex(5)); + assertEquals(1, r.getFontAtIndex(6)); + + } + +} -- 2.39.5