diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2017-06-30 20:21:33 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2017-06-30 20:21:33 +0000 |
commit | 6e6136ba89111a11cceb064ee71df5345072adcb (patch) | |
tree | e9e2b09d0783dc8117d5302bfc8301c7c6bf2c1d /src/testcases/org/apache/poi/ddf | |
parent | a420b9090603d46364051710ed74517ad11f5c27 (diff) | |
download | poi-6e6136ba89111a11cceb064ee71df5345072adcb.tar.gz poi-6e6136ba89111a11cceb064ee71df5345072adcb.zip |
#61243 - Refactor and unify toString/toXml in DDF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1800452 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ddf')
15 files changed, 348 insertions, 263 deletions
diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java index 6b26799f66..903ccb24b7 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java @@ -17,11 +17,18 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherBSERecord extends TestCase { +public final class TestEscherBSERecord { + @Test public void testFillFields() { 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 " + @@ -43,17 +50,16 @@ public final class TestEscherBSERecord extends TestCase { assertEquals( 0, r.getRemainingData().length ); } - public void testSerialize() { + @Test + public void testSerialize() throws IOException { EscherBSERecord r = createRecord(); - + String exp64 = "H4sIAAAAAAAAAGNkYP+gwsDAwMrKyMTMwsrGzsHJxc3Dy8fPwMgAAkxAzAzEICkAgs9OoSwAAAA="; + byte[] expected = RawDataUtil.decompress(exp64); + 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)); - + assertEquals(data.length, bytesWritten); + assertArrayEquals(expected, data); } private EscherBSERecord createRecord() { @@ -74,26 +80,31 @@ public final class TestEscherBSERecord extends TestCase { } + @Test public void testToString() { + String nl = System.getProperty("line.separator"); EscherBSERecord record = createRecord(); - String expected = "org.apache.poi.ddf.EscherBSERecord:" + '\n' + - " RecordId: 0xF007" + '\n' + - " Version: 0x0001" + '\n' + - " Instance: 0x0000" + '\n' + - " BlipTypeWin32: 5" + '\n' + - " BlipTypeMacOS: 5" + '\n' + - " SUID: [01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00]" + '\n' + - " Tag: 1" + '\n' + - " Size: 0" + '\n' + - " Ref: 2" + '\n' + - " Offset: 3" + '\n' + - " Usage: 4" + '\n' + - " Name: 5" + '\n' + - " Unused2: 6" + '\n' + - " Unused3: 7" + '\n' + - " blipRecord: null" + '\n' + - " Extra Data:" + '\n' + - ": 0"; + String expected = + "org.apache.poi.ddf.EscherBSERecord (BSE):" + nl + + " RecordId: 0xF007" + nl + + " Version: 0x0001" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0001" + nl + + " Record Size: 44" + nl + + " BlipTypeWin32: 0x05" + nl + + " BlipTypeMacOS: 0x05" + nl + + " SUID: " + nl + + " 00: 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F, 00" + nl + + " Tag: 0x0001" + nl + + " Size: 0x00000000" + nl + + " Ref: 0x00000002" + nl + + " Offset: 0x00000003" + nl + + " Usage: 0x04" + nl + + " Name: 0x05" + nl + + " Unused2: 0x06" + nl + + " Unused3: 0x07" + nl + + " Extra Data: " + nl + + " : 0"; String actual = record.toString(); assertEquals( expected, actual ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java index 899af6e462..8061186557 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBlipRecord.java @@ -18,24 +18,21 @@ package org.apache.poi.ddf; import static org.junit.Assert.assertArrayEquals; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; - -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.apache.poi.POIDataSamples; +import org.junit.Test; /** * Test read/serialize of escher blip records - * - * @author Yegor Kozlov - */ -public final class TestEscherBlipRecord extends TestCase { +*/ +public final class TestEscherBlipRecord { private static final POIDataSamples _samples = POIDataSamples.getDDFInstance(); //test reading/serializing of a PNG blip + @Test public void testReadPNG() { //provided in bug-44886 byte[] data = _samples.readFile("Container.dat"); @@ -81,6 +78,7 @@ public final class TestEscherBlipRecord extends TestCase { } //test reading/serializing of a PICT metafile + @Test public void testReadPICT() { //provided in bug-44886 byte[] data = _samples.readFile("Container.dat"); @@ -133,6 +131,7 @@ public final class TestEscherBlipRecord extends TestCase { } //integral test: check that the read-write-read round trip is consistent + @Test public void testContainer() { byte[] data = _samples.readFile("Container.dat"); @@ -143,21 +142,10 @@ public final class TestEscherBlipRecord extends TestCase { assertArrayEquals(data, ser); } - private byte[] read(File file) { - byte[] data = new byte[(int)file.length()]; - try { - FileInputStream is = new FileInputStream(file); - is.read(data); - is.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - return data; - } - /** * The test data was created from pl031405.xls attached to Bugzilla #47143 */ + @Test public void test47143() { byte[] data = _samples.readFile("47143.dat"); EscherBSERecord bse = new EscherBSERecord(); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java index f1713533aa..5e65da8987 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBoolProperty.java @@ -17,9 +17,12 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; -public final class TestEscherBoolProperty extends TestCase { +import org.junit.Test; + +public final class TestEscherBoolProperty { + @Test public void testToString() { EscherBoolProperty p = new EscherBoolProperty((short)1, 1); assertEquals("propNum: 1, RAW: 0x0001, 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 index 4f8815ade3..c1cc52c841 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java @@ -17,17 +17,20 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherChildAnchorRecord extends TestCase { +public final class TestEscherChildAnchorRecord { + @Test public void testSerialize() { EscherChildAnchorRecord r = createRecord(); byte[] data = new byte[8 + 16]; int bytesWritten = r.serialize( 0, data, new NullEscherSerializationListener() ); - assertEquals( 24, bytesWritten ); + assertEquals( data.length, bytesWritten ); assertEquals( "[01, 00, " + "0F, F0, " + "10, 00, 00, 00, " + @@ -37,6 +40,7 @@ public final class TestEscherChildAnchorRecord extends TestCase { "04, 00, 00, 00]", HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "01 00 " + "0F F0 " + @@ -58,17 +62,21 @@ public final class TestEscherChildAnchorRecord extends TestCase { assertEquals( (short) 0x0001, r.getOptions() ); } + @Test public void testToString(){ String nl = System.getProperty( "line.separator" ); - String expected = "org.apache.poi.ddf.EscherChildAnchorRecord:" + nl + - " RecordId: 0xF00F" + nl + - " Version: 0x0001" + nl + - " Instance: 0x0000" + nl + - " X1: 1" + nl + - " Y1: 2" + nl + - " X2: 3" + nl + - " Y2: 4" + nl; + String expected = + "org.apache.poi.ddf.EscherChildAnchorRecord (ChildAnchor):" + nl + + " RecordId: 0xF00F" + nl + + " Version: 0x0001" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0001" + nl + + " Record Size: 24" + nl + + " X1: 0x00000001" + nl + + " Y1: 0x00000002" + nl + + " X2: 0x00000003" + nl + + " Y2: 0x00000004"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java index a1eb171f4a..e9f1536994 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java @@ -17,12 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public class TestEscherClientAnchorRecord extends TestCase -{ +public class TestEscherClientAnchorRecord { + @Test public void testSerialize() { EscherClientAnchorRecord r = createRecord(); @@ -38,6 +40,7 @@ public class TestEscherClientAnchorRecord extends TestCase "FF, DD]", HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "01 00 " + "10 F0 " + @@ -65,24 +68,27 @@ public class TestEscherClientAnchorRecord extends TestCase assertEquals( (byte) 0xDD, r.getRemainingData()[1] ); } + @Test public void testToString() { String nl = System.getProperty("line.separator"); - - String expected = "org.apache.poi.ddf.EscherClientAnchorRecord:" + nl + - " RecordId: 0xF010" + nl + - " Version: 0x0001" + nl + - " Instance: 0x0000" + 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; + String expected = + "org.apache.poi.ddf.EscherClientAnchorRecord (ClientAnchor):" + nl + + " RecordId: 0xF010" + nl + + " Version: 0x0001" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0001" + nl + + " Record Size: 28" + nl + + " Flag: 0x004D" + nl + + " Col1: 0x0037" + nl + + " DX1: 0x0021" + nl + + " Row1: 0x0058" + nl + + " DY1: 0x000B" + nl + + " Col2: 0x002C" + nl + + " DX2: 0x0016" + nl + + " Row2: 0x0063" + nl + + " DY2: 0x0042" + nl + + " Extra Data: " + nl + + " 0: FF, DD"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java index 0282ed091d..4844c06829 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java @@ -17,12 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public class TestEscherClientDataRecord extends TestCase -{ +public class TestEscherClientDataRecord { + @Test public void testSerialize() { EscherClientDataRecord r = createRecord(); @@ -35,6 +37,7 @@ public class TestEscherClientDataRecord extends TestCase HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "02 00 " + "11 F0 " + @@ -48,15 +51,19 @@ public class TestEscherClientDataRecord extends TestCase assertEquals( "[]", HexDump.toHex(r.getRemainingData()) ); } + @Test public void testToString() { String nl = System.getProperty("line.separator"); - String expected = "org.apache.poi.ddf.EscherClientDataRecord:" + nl + - " RecordId: 0xF011" + nl + - " Version: 0x0002" + nl + - " Instance: 0x0000" + nl + - " Extra Data:" + nl + - "No Data" + nl ; + String expected = + "org.apache.poi.ddf.EscherClientDataRecord (ClientData):" + nl + + " RecordId: 0xF011" + nl + + " Version: 0x0002" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0002" + nl + + " Record Size: 8" + nl + + " Extra Data: " + nl + + " : 0"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java index 026bc41def..dd57d837e6 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java @@ -17,19 +17,24 @@ package org.apache.poi.ddf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.List; -import junit.framework.TestCase; import org.apache.poi.POIDataSamples; import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests for {@link EscherContainerRecord} */ -public final class TestEscherContainerRecord extends TestCase { +public final class TestEscherContainerRecord { private static final POIDataSamples _samples = POIDataSamples.getDDFInstance(); + @Test public void testFillFields() { EscherRecordFactory f = new DefaultEscherRecordFactory(); byte[] data = HexRead.readFromString("0F 02 11 F1 00 00 00 00"); @@ -49,6 +54,7 @@ public final class TestEscherContainerRecord extends TestCase { assertEquals((short) 0xF222, c.getRecordId()); } + @Test public void testSerialize() { UnknownEscherRecord r = new UnknownEscherRecord(); r.setOptions((short) 0x123F); @@ -69,72 +75,79 @@ public final class TestEscherContainerRecord extends TestCase { } + @Test public void testToString() { 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 + - " version: 0x000F" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF004" + nl + - " numchildren: 0" + nl - , r.toString()); + String expected = + "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + + " RecordId: 0xF004" + nl + + " Version: 0x000F" + nl + + " Instance: 0x0000" + nl + + " Options: 0x000F" + nl + + " Record Size: 8" + nl + + " isContainer: true" + nl + + " children: 0x00000000"; + assertEquals(expected, r.toString()); EscherOptRecord r2 = new EscherOptRecord(); // don't try to shoot in foot, please -- vlsergey // r2.setOptions((short) 0x9876); r2.setRecordId(EscherOptRecord.RECORD_ID); - String expected; r.addChildRecord(r2); - expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + - " isContainer: true" + nl + - " version: 0x000F" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF004" + nl + - " numchildren: 1" + nl + - " children: " + nl + - " Child 0:" + nl + - " org.apache.poi.ddf.EscherOptRecord:" + nl + - " isContainer: false" + nl + - " version: 0x0003" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF00B" + nl + - " numchildren: 0" + nl + - " properties:" + nl + - " " + nl; - assertEquals(expected, r.toString()); + expected = + "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + + " RecordId: 0xF004" + nl + + " Version: 0x000F" + nl + + " Instance: 0x0000" + nl + + " Options: 0x000F" + nl + + " Record Size: 16" + nl + + " isContainer: true" + nl + + " children: 0x00000001" + nl + + " Child 0: org.apache.poi.ddf.EscherOptRecord (Opt):" + nl + + " RecordId: 0xF00B" + nl + + " Version: 0x0003" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0003" + nl + + " Record Size: 8" + nl + + " isContainer: false" + nl + + " numchildren: 0x00000000" + nl + + " properties: 0x00000000"; + assertEquals(expected, r.toString()); r.addChildRecord(r2); - expected = "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + - " isContainer: true" + nl + - " version: 0x000F" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF004" + nl + - " numchildren: 2" + nl + - " children: " + nl + - " Child 0:" + nl + - " org.apache.poi.ddf.EscherOptRecord:" + nl + - " isContainer: false" + nl + - " version: 0x0003" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF00B" + nl + - " numchildren: 0" + nl + - " properties:" + nl + - " " + nl + - " Child 1:" + nl + - " org.apache.poi.ddf.EscherOptRecord:" + nl + - " isContainer: false" + nl + - " version: 0x0003" + nl + - " instance: 0x0000" + nl + - " recordId: 0xF00B" + nl + - " numchildren: 0" + nl + - " properties:" + nl + - " " + nl; + expected = + "org.apache.poi.ddf.EscherContainerRecord (SpContainer):" + nl + + " RecordId: 0xF004" + nl + + " Version: 0x000F" + nl + + " Instance: 0x0000" + nl + + " Options: 0x000F" + nl + + " Record Size: 24" + nl + + " isContainer: true" + nl + + " children: 0x00000002" + nl + + " Child 0: org.apache.poi.ddf.EscherOptRecord (Opt):" + nl + + " RecordId: 0xF00B" + nl + + " Version: 0x0003" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0003" + nl + + " Record Size: 8" + nl + + " isContainer: false" + nl + + " numchildren: 0x00000000" + nl + + " properties: 0x00000000" + nl + + " Child 1: org.apache.poi.ddf.EscherOptRecord (Opt):" + nl + + " RecordId: 0xF00B" + nl + + " Version: 0x0003" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0003" + nl + + " Record Size: 8" + nl + + " isContainer: false" + nl + + " numchildren: 0x00000000" + nl + + " properties: 0x00000000"; assertEquals(expected, r.toString()); - } + } private static final class DummyEscherRecord extends EscherRecord { public DummyEscherRecord() { } @@ -146,8 +159,11 @@ public final class TestEscherContainerRecord extends TestCase { public int getRecordSize() { return 10; } @Override public String getRecordName() { return ""; } + @Override + protected Object[][] getAttributeMap() { return null; } } + @Test public void testGetRecordSize() { EscherContainerRecord r = new EscherContainerRecord(); r.addChildRecord(new DummyEscherRecord()); @@ -158,6 +174,7 @@ public final class TestEscherContainerRecord extends TestCase { * We were having problems with reading too much data on an UnknownEscherRecord, * but hopefully we now read the correct size. */ + @Test public void testBug44857() throws Exception { byte[] data = _samples.readFile("Container.dat"); @@ -169,6 +186,7 @@ public final class TestEscherContainerRecord extends TestCase { /** * Ensure {@link EscherContainerRecord} doesn't spill its guts everywhere */ + @Test public void testChildren() { EscherContainerRecord ecr = new EscherContainerRecord(); List<EscherRecord> children0 = ecr.getChildRecords(); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java index 2e0fd4b102..159781d410 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java @@ -17,11 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherDgRecord extends TestCase { +public final class TestEscherDgRecord { + @Test public void testSerialize() { EscherDgRecord r = createRecord(); @@ -36,6 +39,7 @@ public final class TestEscherDgRecord extends TestCase { HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "10 00 " + "08 F0 " + @@ -51,13 +55,18 @@ public final class TestEscherDgRecord extends TestCase { assertEquals( 1025, r.getLastMSOSPID() ); } + @Test public void testToString() { - String expected = "org.apache.poi.ddf.EscherDgRecord:" + '\n' + - " RecordId: 0xF008" + '\n' + - " Version: 0x0000" + '\n' + - " Instance: 0x0001" + '\n' + - " NumShapes: 2" + '\n' + - " LastMSOSPID: 1025" + '\n'; + String nl = System.getProperty("line.separator"); + String expected = + "org.apache.poi.ddf.EscherDgRecord (Dg):" + nl + + " RecordId: 0xF008" + nl + + " Version: 0x0000" + nl + + " Instance: 0x0001" + nl + + " Options: 0x0010" + nl + + " Record Size: 16" + nl + + " NumShapes: 0x00000002" + nl + + " LastMSOSPID: 0x00000401"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java index 2587a3b2d0..1008c1de21 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java @@ -17,11 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherDggRecord extends TestCase { +public final class TestEscherDggRecord { + @Test public void testSerialize() { EscherDggRecord r = createRecord(); @@ -39,6 +42,7 @@ public final class TestEscherDggRecord extends TestCase { HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "00 00 " + "06 F0 " + @@ -62,17 +66,22 @@ public final class TestEscherDggRecord extends TestCase { assertEquals( 0x02, r.getFileIdClusters()[0].getNumShapeIdsUsed()); } + @Test public void testToString() { - String expected = "org.apache.poi.ddf.EscherDggRecord:" + '\n' + - " RecordId: 0xF006" + '\n' + - " Version: 0x0000" + '\n' + - " Instance: 0x0000" + '\n' + - " ShapeIdMax: 1026" + '\n' + - " NumIdClusters: 2" + '\n' + - " NumShapesSaved: 2" + '\n' + - " DrawingsSaved: 1" + '\n' + - " DrawingGroupId1: 1" + '\n' + - " NumShapeIdsUsed1: 2" + '\n'; + String nl = System.getProperty("line.separator"); + String expected = + "org.apache.poi.ddf.EscherDggRecord (Dgg):" + nl + + " RecordId: 0xF006" + nl + + " Version: 0x0000" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0000" + nl + + " Record Size: 32" + nl + + " ShapeIdMax: 0x00000402" + nl + + " NumIdClusters: 0x00000002" + nl + + " NumShapesSaved: 0x00000002" + nl + + " DrawingsSaved: 0x00000001" + nl + + " FileId Clusters: 0x00000001" + nl + + " Group1: 0x00000002"; assertEquals( expected, createRecord().toString() ); } @@ -90,6 +99,7 @@ public final class TestEscherDggRecord extends TestCase { return r; } + @Test public void testGetRecordSize() { EscherDggRecord r = new EscherDggRecord(); r.setFileIdClusters(new EscherDggRecord.FileIdCluster[] { new EscherDggRecord.FileIdCluster(0,0) } ); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java index 0b43a0edfb..0359f50296 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java @@ -18,13 +18,18 @@ package org.apache.poi.ddf; import static org.junit.Assert.assertArrayEquals; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import java.io.IOException; + +import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherOptRecord extends TestCase { +public final class TestEscherOptRecord { + @Test public void testFillFields() { checkFillFieldsSimple(); checkFillFieldsComplex(); @@ -74,6 +79,7 @@ public final class TestEscherOptRecord extends TestCase { assertEquals( prop3, r.getEscherProperty( 2 ) ); } + @Test public void testSerialize() { checkSerializeSimple(); checkSerializeComplex(); @@ -130,6 +136,7 @@ public final class TestEscherOptRecord extends TestCase { assertEquals( 26, bytesWritten ); } + @Test public void testToString() { String nl = System.getProperty("line.separator"); EscherOptRecord r = new EscherOptRecord(); @@ -138,21 +145,25 @@ public final class TestEscherOptRecord extends TestCase { r.setRecordId(EscherOptRecord.RECORD_ID); EscherProperty prop1 = new EscherBoolProperty((short)1, 1); r.addEscherProperty(prop1); - String expected = "org.apache.poi.ddf.EscherOptRecord:" + nl + - " isContainer: false" + nl + - " version: 0x0003" + nl + - " instance: 0x0001" + nl + - " recordId: 0x" + HexDump.toHex(EscherOptRecord.RECORD_ID) + nl + - " numchildren: 0" + nl + - " properties:" + nl + - " propNum: 1, RAW: 0x0001, propName: unknown, complex: false, blipId: false, value: 1 (0x00000001)" + nl; + String expected = + "org.apache.poi.ddf.EscherOptRecord (Opt):" + nl + + " RecordId: 0xF00B" + nl + + " Version: 0x0003" + nl + + " Instance: 0x0001" + nl + + " Options: 0x0013" + nl + + " Record Size: 14" + nl + + " isContainer: false" + nl + + " numchildren: 0x00000000" + nl + + " properties: 0x00000001" + nl + + " unknown: propNum: 1, RAW: 0x0001, propName: unknown, complex: false, blipId: false, value: 1 (0x00000001)"; assertEquals( expected, r.toString()); } /** - * Test serialisation of a particually complex example + * Test serialization of a particularly complex example * This test is currently broken! */ + @Test public void testComplexSerialise() { byte[] data = { 0x53, 0x01, 0x0B, 0xF0-256, 0x9C-256, 0x01, 0x00, 0x00, @@ -233,15 +244,13 @@ public final class TestEscherOptRecord extends TestCase { assertEquals(data.length, filled); assertEquals(data.length, r.getRecordSize()); - // Serialise it + // Serialize it byte[] dest = new byte[data.length]; int written = r.serialize(0, dest); // Check it serialised it back to the same data assertEquals(data.length, written); - for(int i=0; i<data.length; i++) { - assertEquals(data[i], dest[i]); - } + assertArrayEquals(data, dest); } /** @@ -254,43 +263,20 @@ public final class TestEscherOptRecord extends TestCase { * * See Bug 41946 for details. */ - public void test41946() { - String dataStr1 = - "03 08 0B F0 00 03 00 00 81 00 30 65 01 00 82 00 98 B2 00 00 83 00 30 65 01 " + - "00 84 00 98 B2 00 00 85 00 00 00 00 00 87 00 01 00 00 00 88 00 00 00 00 00 " + - "89 00 00 00 00 00 BF 00 00 00 0F 00 0C 01 F4 00 00 10 0D 01 00 00 00 20 0E " + - "01 00 00 00 20 80 01 00 00 00 00 81 01 04 00 00 08 82 01 00 00 01 00 83 01 " + - "00 00 00 08 84 01 00 00 01 00 85 01 00 00 00 20 86 41 00 00 00 00 87 C1 00 " + - "00 00 00 88 01 00 00 00 00 89 01 00 00 00 00 8A 01 00 00 00 00 8B 01 00 00 " + - "00 00 8C 01 00 00 00 00 8D 01 00 00 00 00 8E 01 00 00 00 00 8F 01 00 00 00 " + - "00 90 01 00 00 00 00 91 01 00 00 00 00 92 01 00 00 00 00 93 01 00 00 00 00 " + - "94 01 00 00 00 00 95 01 00 00 00 00 96 01 00 00 00 00 97 C1 00 00 00 00 98 " + - "01 00 00 00 00 99 01 00 00 00 00 9A 01 00 00 00 00 9B 01 00 00 00 00 9C 01 " + - "03 00 00 40 BF 01 0C 00 1E 00 C0 01 01 00 00 08 C1 01 00 00 01 00 C2 01 FF " + - "FF FF 00 C3 01 00 00 00 20 C4 01 00 00 00 00 C5 41 00 00 00 00 C6 C1 00 00 " + - "00 00 C7 01 00 00 00 00 C8 01 00 00 00 00 C9 01 00 00 00 00 CA 01 00 00 00 " + - "00 CB 01 35 25 00 00 CC 01 00 00 08 00 CD 01 00 00 00 00 CE 01 00 00 00 00 " + - "CF C1 00 00 00 00 D7 01 02 00 00 00 FF 01 06 00 0E 00 00 02 00 00 00 00 01 " + - "02 02 00 00 08 02 02 CB CB CB 00 03 02 00 00 00 20 04 02 00 00 01 00 05 02 " + - "38 63 00 00 06 02 38 63 00 00 07 02 00 00 00 00 08 02 00 00 00 00 09 02 00 " + - "00 01 00 0A 02 00 00 00 00 0B 02 00 00 00 00 0C 02 00 00 01 00 0D 02 00 00 " + - "00 00 0E 02 00 00 00 00 0F 02 00 01 00 00 10 02 00 00 00 00 11 02 00 00 00 " + - "00 3F 02 00 00 03 00 80 02 00 00 00 00 81 02 00 00 01 00 82 02 05 00 00 00 " + - "83 02 9C 31 00 00 84 02 00 00 00 00 85 02 F0 F9 06 00 86 02 00 00 00 00 87 " + - "02 F7 00 00 10 88 02 00 00 00 20 BF 02 01 00 0F 00 C0 02 00 00 00 00 C1 02 " + - "00 00 00 00 C2 02 64 00 00 00 C3 02 00 00 00 00 C4 02 00 00 00 00 C5 02 00 " + - "00 00 00 C6 02 00 00 00 00 C7 02 00 00 00 00 C8 02 00 00 00 00 C9 02 00 00 " + - "00 00 CA 02 30 75 00 00 CB 02 D0 12 13 00 CC 02 30 ED EC FF CD 02 40 54 89 " + - "00 CE 02 00 80 00 00 CF 02 00 80 FF FF D0 02 00 00 79 FF D1 02 32 00 00 00 " + - "D2 02 20 4E 00 00 D3 02 50 C3 00 00 D4 02 00 00 00 00 D5 02 10 27 00 00 D6 " + - "02 70 94 00 00 D7 02 B0 3C FF FF D8 02 00 00 00 00 D9 02 10 27 00 00 DA 02 " + - "70 94 00 00 FF 02 16 00 1F 00 04 03 01 00 00 00 41 03 A8 29 01 00 42 03 00 " + - "00 00 00 43 03 03 00 00 00 44 03 7C BE 01 00 45 03 00 00 00 00 7F 03 00 00 " + - "0F 00 84 03 7C BE 01 00 85 03 00 00 00 00 86 03 7C BE 01 00 87 03 00 00 00 " + - "00"; + @Test + public void test41946() throws IOException { + String data64 = + "H4sIAAAAAAAAAB3SuW5TQRjF8TPfOOZCHMeARAluEKIzSEgUSCQsLaLgDYCehgIJCe8L+xIgQB6"+ + "AEvEAOI6zOwlhX54BpBRIiGqY+Vvy7x6d+3k8nmufje/ISzVVrjrVNftWapCb5JbSqyMX7ZJ72I"+ + "/vSRXcH6k0kW6Wi1hNquZyUlaP2amRmqxJbjHTnmbNQbLLfA9v4x28i/fwPj7Ah/gIH+MTnMGn+"+ + "Ayfs/4s+QW+xFc45+KPnuq7gg5q3sUqG7DDBRdC0JB9LjK5xG6XWW2FZhXXcB1H7sRhaSMto02a"+ + "LXzPp745iwaXV1FKUc7iJTMbjUbyqSnnLH37mJ28LOVxF5MZ7ubuHvI4FmgmyEWctPSQSuS9eDr"+ + "qVSXXmK/bWMwNmzsmNelbtvMvrza5Y3/jAl320zcXn+88/QAX7Ep0SF7EJVzGFVzFNVy3yvV4Mr"+ + "a9b782rPL7V9i0qUs9bZmq8WSiIWzHyRvhgx2P8x+tfEH6ZBeH0mdW+GKlI9JXuzYTz9DenArhO"+ + "/0P+p/0wQ7okHI+Hfe0f33U6YxPM2d9upzzN985nae55dM/tknTommTO+T/V9IPpAgDAAA="; EscherOptRecord r = new EscherOptRecord(); - byte[] data = HexRead.readFromString( dataStr1 ); + byte[] data = RawDataUtil.decompress(data64); r.fillFields( data, 0, new DefaultEscherRecordFactory() ); assertEquals( (short) 0xF00B, r.getRecordId() ); @@ -306,6 +292,7 @@ public final class TestEscherOptRecord extends TestCase { * Test that EscherOptRecord can properly read/write array properties * with empty complex part. */ + @Test public void testEmptyArrayProperty() { EscherOptRecord r = new EscherOptRecord(); EscherArrayProperty p = new EscherArrayProperty((short)(EscherProperties.FILL__SHADECOLORS + 0x8000), new byte[0] ); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherProperty.java b/src/testcases/org/apache/poi/ddf/TestEscherProperty.java index c7d704ff14..b102af43f8 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherProperty.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherProperty.java @@ -17,18 +17,19 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; -/** - * @author Yegor Kozlov - */ -public class TestEscherProperty extends TestCase -{ + +public class TestEscherProperty { /** * assure that EscherProperty.getName() returns correct name for complex properties * See Bugzilla 50401 */ + @Test public void testPropertyNames() throws Exception { EscherProperty p1 = new EscherSimpleProperty( EscherProperties.GROUPSHAPE__SHAPENAME, 0); assertEquals("groupshape.shapename", p1.getName()); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java index f0daf07bd2..eec0d40d55 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java @@ -17,12 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public class TestEscherSpRecord extends TestCase -{ +public class TestEscherSpRecord { + @Test public void testSerialize() { EscherSpRecord r = createRecord(); @@ -37,6 +39,7 @@ public class TestEscherSpRecord extends TestCase HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "02 00 " + "0A F0 " + @@ -52,15 +55,20 @@ public class TestEscherSpRecord extends TestCase assertEquals( 0x05, r.getFlags() ); } + @Test public void testToString() { String nl = System.getProperty("line.separator"); - String expected = "org.apache.poi.ddf.EscherSpRecord:" + nl + - " RecordId: 0xF00A" + nl + - " Version: 0x0002" + nl + - " ShapeType: 0x0000" + nl + - " ShapeId: 1024" + nl + - " Flags: GROUP|PATRIARCH (0x00000005)" + nl; + String expected = + "org.apache.poi.ddf.EscherSpRecord (Sp):" + nl + + " RecordId: 0xF00A" + nl + + " Version: 0x0002" + nl + + " Instance: 0x0000" + nl + + " Options: 0x0002" + nl + + " Record Size: 16" + nl + + " ShapeType: 0x0000" + nl + + " ShapeId: 0x00000400" + nl + + " Flags: GROUP|PATRIARCH (0x00000005)"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java index e70934ec95..6020b4667f 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java @@ -17,11 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherSpgrRecord extends TestCase { +public final class TestEscherSpgrRecord { + @Test public void testSerialize() { EscherSpgrRecord r = createRecord(); @@ -38,6 +41,7 @@ public final class TestEscherSpgrRecord extends TestCase { HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "10 00 " + "09 F0 " + @@ -57,16 +61,20 @@ public final class TestEscherSpgrRecord extends TestCase { assertEquals( 4, r.getRectY2() ); } + @Test public void testToString() { - - String expected = "org.apache.poi.ddf.EscherSpgrRecord:" + '\n' + - " RecordId: 0xF009" + '\n' + - " Version: 0x0000" + '\n' + - " Instance: 0x0001" + '\n' + - " RectX: 1" + '\n' + - " RectY: 2" + '\n' + - " RectWidth: 3" + '\n' + - " RectHeight: 4" + '\n'; + String nl = System.getProperty("line.separator"); + String expected = + "org.apache.poi.ddf.EscherSpgrRecord (Spgr):" + nl + + " RecordId: 0xF009" + nl + + " Version: 0x0000" + nl + + " Instance: 0x0001" + nl + + " Options: 0x0010" + nl + + " Record Size: 24" + nl + + " RectX: 0x00000001" + nl + + " RectY: 0x00000002" + nl + + " RectWidth: 0x00000003" + nl + + " RectHeight: 0x00000004"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java index 60facfb33d..084a452fec 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java @@ -17,11 +17,14 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + import org.apache.poi.util.HexDump; import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestEscherSplitMenuColorsRecord extends TestCase { +public final class TestEscherSplitMenuColorsRecord { + @Test public void testSerialize() { EscherSplitMenuColorsRecord r = createRecord(); @@ -38,6 +41,7 @@ public final class TestEscherSplitMenuColorsRecord extends TestCase { HexDump.toHex( data ) ); } + @Test public void testFillFields() { String hexData = "40 00 " + "1E F1 " + @@ -57,16 +61,20 @@ public final class TestEscherSplitMenuColorsRecord extends TestCase { assertEquals( 0x01, r.getColor4() ); } + @Test public void testToString() { - String expected = "org.apache.poi.ddf.EscherSplitMenuColorsRecord:" + '\n' + - " RecordId: 0xF11E" + '\n' + - " Version: 0x0000" + '\n' + - " Instance: 0x0004" + '\n' + - " Color1: 0x00000402" + '\n' + - " Color2: 0x00000002" + '\n' + - " Color3: 0x00000002" + '\n' + - " Color4: 0x00000001" + '\n' + - ""; + String nl = System.getProperty("line.separator"); + String expected = + "org.apache.poi.ddf.EscherSplitMenuColorsRecord (SplitMenuColors):" + nl + + " RecordId: 0xF11E" + nl + + " Version: 0x0000" + nl + + " Instance: 0x0004" + nl + + " Options: 0x0040" + nl + + " Record Size: 24" + nl + + " Color1: 0x00000402" + nl + + " Color2: 0x00000002" + nl + + " Color3: 0x00000002" + nl + + " Color4: 0x00000001"; assertEquals( expected, createRecord().toString() ); } diff --git a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java index b42c98c6ca..70429a9672 100644 --- a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java @@ -17,11 +17,16 @@ package org.apache.poi.ddf; -import junit.framework.TestCase; -import org.apache.poi.util.HexRead; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.poi.util.HexDump; +import org.apache.poi.util.HexRead; +import org.junit.Test; -public final class TestUnknownEscherRecord extends TestCase { +public final class TestUnknownEscherRecord { + @Test public void testFillFields() { String testData = "0F 02 " + // options @@ -117,6 +122,7 @@ public final class TestUnknownEscherRecord extends TestCase { assertEquals( (short) 0xFFFF, r.getChild( 0 ).getRecordId() ); } + @Test public void testSerialize() { UnknownEscherRecord r = new UnknownEscherRecord(); r.setOptions( (short) 0x1234 ); @@ -137,20 +143,27 @@ public final class TestUnknownEscherRecord extends TestCase { assertEquals( "[3F, 12, 12, F1, 08, 00, 00, 00, 99, 99, 01, FF, 00, 00, 00, 00]", HexDump.toHex( data ) ); } + @Test public void testToString() { UnknownEscherRecord r = new UnknownEscherRecord(); r.setOptions( (short) 0x1234 ); r.setRecordId( (short) 0xF112 ); byte[] data = new byte[8]; r.serialize( 0, data, new NullEscherSerializationListener() ); - - assertEquals( "org.apache.poi.ddf.UnknownEscherRecord:" + '\n' + - " isContainer: false" + '\n' + - " version: 0x0004" + '\n' + - " instance: 0x0123" + '\n' + - " recordId: 0xF112" + '\n' + - " numchildren: 0" + '\n' + - ": 0" - , r.toString() ); + String nl = System.getProperty("line.separator"); + String expected = + "org.apache.poi.ddf.UnknownEscherRecord (Unknown 0xF112):" + nl + + " RecordId: 0xF112" + nl + + " Version: 0x0004" + nl + + " Instance: 0x0123" + nl + + " Options: 0x1234" + nl + + " Record Size: 8" + nl + + " isContainer: false" + nl + + " children: 0x00000000" + nl + + " Extra Data: " + nl + + " : 0"; + + + assertEquals(expected, r.toString() ); } } |