diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java index ed6f12882..c5ebab30a 100644 --- a/src/java/org/apache/poi/util/HexDump.java +++ b/src/java/org/apache/poi/util/HexDump.java @@ -255,8 +255,10 @@ public class HexDump { retVal.append('['); for(int x = 0; x < value.length; x++) { + if (x>0) { + retVal.append(", "); + } retVal.append(toHex(value[x])); - retVal.append(", "); } retVal.append(']'); return retVal.toString(); diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index cd11ccc64..91632e8fc 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -172,9 +172,12 @@ public class HexRead return rval; } - static public byte[] readFromString(String data) throws IOException - { - return readData(new ByteArrayInputStream( data.getBytes() ), -1); + static public byte[] readFromString(String data) { + try { + return readData(new ByteArrayInputStream( data.getBytes() ), -1); + } catch (IOException e) { + throw new RuntimeException(e); + } } static private void readToEOL( InputStream stream ) throws IOException diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java index 7d4dc7bee..7db08a34a 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBSERecord.java @@ -37,7 +37,7 @@ public class TestEscherBSERecord extends TestCase 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( "[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() ); @@ -57,7 +57,7 @@ public class TestEscherBSERecord extends TestCase 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, ]", + "00, 00, 02, 00, 00, 00, 03, 00, 00, 00, 04, 05, 06, 07]", HexDump.toHex( data ) ); } @@ -90,7 +90,7 @@ public class TestEscherBSERecord extends TestCase " 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 + + " 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 + diff --git a/src/testcases/org/apache/poi/ddf/TestEscherBlipWMFRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherBlipWMFRecord.java index 3f73ccb1c..8db7c4be3 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherBlipWMFRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherBlipWMFRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -36,8 +35,7 @@ public class TestEscherBlipWMFRecord extends TestCase data = HexRead.readFromString(dataStr); } - public void testSerialize() throws Exception - { + public void testSerialize() { EscherBlipWMFRecord r = new EscherBlipWMFRecord(); r.setBoundaryLeft(1); r.setBoundaryHeight(2); @@ -72,14 +70,13 @@ public class TestEscherBlipWMFRecord extends TestCase "05, 00, 00, 00, " + // field_9_cacheOfSavedSize "08, " + // field_10_compressionFlag "07, " + // field_11_filter - "01, 02, ]", // field_12_data + "01, 02]", // field_12_data HexDump.toHex(buf)); assertEquals(60, r.getRecordSize() ); } - public void testFillFields() throws Exception - { + public void testFillFields() { EscherBlipWMFRecord r = new EscherBlipWMFRecord(); r.fillFields( data, 0, new DefaultEscherRecordFactory()); @@ -92,15 +89,14 @@ public class TestEscherBlipWMFRecord extends TestCase 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( "[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() ) ); + assertEquals( "[01, 02]", HexDump.toHex( r.getData() ) ); } - public void testToString() throws Exception - { + public void testToString() { EscherBlipWMFRecord r = new EscherBlipWMFRecord(); r.fillFields( data, 0, new DefaultEscherRecordFactory() ); @@ -109,7 +105,7 @@ public class TestEscherBlipWMFRecord extends TestCase assertEquals( "org.apache.poi.ddf.EscherBlipWMFRecord:" + 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 + + " 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 + @@ -124,5 +120,5 @@ public class TestEscherBlipWMFRecord extends TestCase "00000000 01 02 .." + nl , r.toString() ); } - } + diff --git a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java index 545351a3f..9cf14e47b 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherChildAnchorRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherChildAnchorRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherChildAnchorRecord r = createRecord(); byte[] data = new byte[8 + 16]; @@ -37,7 +35,7 @@ public class TestEscherChildAnchorRecord extends TestCase "01, 00, 00, 00, " + "02, 00, 00, 00, " + "03, 00, 00, 00, " + - "04, 00, 00, 00, ]", HexDump.toHex( data ) ); + "04, 00, 00, 00]", HexDump.toHex( data ) ); } public void testFillFields() throws Exception @@ -62,8 +60,7 @@ public class TestEscherChildAnchorRecord extends TestCase assertEquals( (short) 0x0001, r.getOptions() ); } - public void testToString() throws Exception - { + public void testToString(){ String nl = System.getProperty( "line.separator" ); String expected = "org.apache.poi.ddf.EscherChildAnchorRecord:" + nl + @@ -76,7 +73,7 @@ public class TestEscherChildAnchorRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherChildAnchorRecord createRecord() + private static EscherChildAnchorRecord createRecord() { EscherChildAnchorRecord r = new EscherChildAnchorRecord(); r.setRecordId( EscherChildAnchorRecord.RECORD_ID ); @@ -87,5 +84,5 @@ public class TestEscherChildAnchorRecord extends TestCase 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 index c058622db..3a1e5c2b6 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientAnchorRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherClientAnchorRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherClientAnchorRecord r = createRecord(); byte[] data = new byte[8 + 18 + 2]; @@ -37,11 +35,10 @@ public class TestEscherClientAnchorRecord extends TestCase "4D, 00, 37, 00, 21, 00, 58, 00, " + "0B, 00, 2C, 00, 16, 00, 63, 00, " + "42, 00, " + - "FF, DD, ]", HexDump.toHex( data ) ); + "FF, DD]", HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "01 00 " + "10 F0 " + "14 00 00 00 " + @@ -68,8 +65,7 @@ public class TestEscherClientAnchorRecord extends TestCase assertEquals( (byte) 0xDD, r.getRemainingData()[1] ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherClientAnchorRecord:" + nl + diff --git a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java index 22a11181c..2f26a37c5 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherClientDataRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherClientDataRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherClientDataRecord r = createRecord(); byte[] data = new byte[8]; @@ -33,12 +31,11 @@ public class TestEscherClientDataRecord extends TestCase assertEquals( 8, bytesWritten ); assertEquals( "[02, 00, " + "11, F0, " + - "00, 00, 00, 00, ]", + "00, 00, 00, 00]", HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "02 00 " + "11 F0 " + "00 00 00 00 "; @@ -51,8 +48,7 @@ public class TestEscherClientDataRecord extends TestCase assertEquals( "[]", HexDump.toHex(r.getRemainingData()) ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherClientDataRecord:" + nl + @@ -63,7 +59,7 @@ public class TestEscherClientDataRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherClientDataRecord createRecord() + private static EscherClientDataRecord createRecord() { EscherClientDataRecord r = new EscherClientDataRecord(); r.setOptions( (short) 0x0002 ); @@ -71,5 +67,4 @@ public class TestEscherClientDataRecord extends TestCase 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 index 0f1fc9c73..490a3d50c 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherContainerRecord.java @@ -30,13 +30,11 @@ public class TestEscherContainerRecord extends TestCase { private String ESCHER_DATA_PATH; - protected void setUp() throws Exception { - super.setUp(); + protected void setUp() { ESCHER_DATA_PATH = System.getProperty("DDF.testdata.path"); } - public void testFillFields() throws Exception - { + public void testFillFields() { EscherRecordFactory f = new DefaultEscherRecordFactory(); byte[] data = HexRead.readFromString( "0F 02 11 F1 00 00 00 00" ); EscherRecord r = f.createRecord( data, 0 ); @@ -55,15 +53,14 @@ public class TestEscherContainerRecord extends TestCase assertEquals( (short) 0xF222, c.getRecordId() ); } - public void testSerialize() throws Exception - { + public void testSerialize() { 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 ) ); + assertEquals( "[3F, 12, 12, F1, 00, 00, 00, 00]", HexDump.toHex( data ) ); EscherRecord childRecord = new UnknownEscherRecord(); childRecord.setOptions( (short) 0x9999 ); @@ -72,12 +69,11 @@ public class TestEscherContainerRecord extends TestCase 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 ) ); + 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 - { + public void testToString() { EscherContainerRecord r = new EscherContainerRecord(); r.setRecordId( EscherContainerRecord.SP_CONTAINER ); r.setOptions( (short) 0x000F ); @@ -134,8 +130,7 @@ public class TestEscherContainerRecord extends TestCase assertEquals( expected, r.toString() ); } - public void testGetRecordSize() throws Exception - { + public void testGetRecordSize() { EscherContainerRecord r = new EscherContainerRecord(); r.addChildRecord(new EscherRecord() { diff --git a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java index c1be28172..70ddd4733 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherDgRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherDgRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherDgRecord r = createRecord(); byte[] data = new byte[16]; @@ -35,12 +33,11 @@ public class TestEscherDgRecord extends TestCase "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 + "01, 04, 00, 00]", // The last MSOSPID given to an SP in this DG HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "10 00 " + "08 F0 " + "08 00 00 00 " + @@ -55,8 +52,7 @@ public class TestEscherDgRecord extends TestCase assertEquals( 1025, r.getLastMSOSPID() ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherDgRecord:" + nl + @@ -67,7 +63,7 @@ public class TestEscherDgRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherDgRecord createRecord() + private static EscherDgRecord createRecord() { EscherDgRecord r = new EscherDgRecord(); r.setOptions( (short) 0x0010 ); @@ -76,5 +72,4 @@ public class TestEscherDgRecord extends TestCase 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 index afecbf3c9..896806695 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherDggRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherDggRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherDggRecord r = createRecord(); byte[] data = new byte[32]; @@ -38,12 +36,11 @@ public class TestEscherDggRecord extends TestCase "02, 00, 00, 00, " + "02, 00, 00, 00, " + "01, 00, 00, 00, " + - "01, 00, 00, 00, 02, 00, 00, 00, ]", + "01, 00, 00, 00, 02, 00, 00, 00]", HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "00 00 " + "06 F0 " + "18 00 00 00 " + @@ -66,8 +63,7 @@ public class TestEscherDggRecord extends TestCase assertEquals( 0x02, r.getFileIdClusters()[0].getNumShapeIdsUsed()); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherDggRecord:" + nl + @@ -82,7 +78,7 @@ public class TestEscherDggRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherDggRecord createRecord() + private static EscherDggRecord createRecord() { EscherDggRecord r = new EscherDggRecord(); r.setOptions( (short) 0x0000 ); @@ -96,12 +92,9 @@ public class TestEscherDggRecord extends TestCase return r; } - public void testGetRecordSize() throws Exception - { + public void testGetRecordSize() { 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 index fe996f636..a96ba8496 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherOptRecord.java @@ -24,20 +24,16 @@ import org.apache.poi.util.HexDump; import java.io.IOException; import java.util.Arrays; -import java.util.List; -import java.util.Iterator; public class TestEscherOptRecord extends TestCase { - public void testFillFields() throws Exception - { + public void testFillFields() { checkFillFieldsSimple(); checkFillFieldsComplex(); } - private void checkFillFieldsComplex() throws IOException - { + private void checkFillFieldsComplex() { String dataStr = "33 00 " + "0B F0 " + "14 00 00 00 " + @@ -60,9 +56,7 @@ public class TestEscherOptRecord extends TestCase } - private void checkFillFieldsSimple() - throws IOException - { + private void checkFillFieldsSimple() { String dataStr = "33 00 " + // options "0B F0 " + // recordid "12 00 00 00 " + // remaining bytes @@ -83,8 +77,7 @@ public class TestEscherOptRecord extends TestCase assertEquals( prop3, r.getEscherProperty( 2 ) ); } - public void testSerialize() throws Exception - { + public void testSerialize() { checkSerializeSimple(); checkSerializeComplex(); } @@ -111,7 +104,7 @@ public class TestEscherOptRecord extends TestCase "BF, 00, 01, 00, 00, 00, " + "01, 80, 02, 00, 00, 00, " + "BF, 00, 01, 00, 00, 00, " + - "01, 02, ]"; + "01, 02]"; assertEquals( dataStr, HexDump.toHex(data) ); } @@ -135,13 +128,12 @@ public class TestEscherOptRecord extends TestCase "12, 00, 00, 00, " + "BF, 00, 01, 00, 00, 00, " + "81, 01, 09, 00, 00, 08, " + - "C0, 01, 40, 00, 00, 08, ]"; + "C0, 01, 40, 00, 00, 08]"; assertEquals( dataStr, HexDump.toHex(data) ); assertEquals( 26, bytesWritten ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); EscherOptRecord r = new EscherOptRecord(); r.setOptions((short)0x000F); @@ -162,8 +154,8 @@ public class TestEscherOptRecord extends TestCase * Test serialisation of a particually complex example * This test is currently broken! */ - public void testComplexSerialise() throws Exception { - byte[] data = new byte[] { + public void testComplexSerialise() { + byte[] data = { 0x53, 0x01, 0x0B, 0xF0-256, 0x9C-256, 0x01, 0x00, 0x00, // Simple data follows 0x42, 0x01, 0x49, 0x00, 0x00, 0x00, // SP @ 8 @@ -263,7 +255,7 @@ public class TestEscherOptRecord extends TestCase * * See Bug 41946 for details. */ - public void test41946() throws IOException { + 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 " + @@ -315,7 +307,7 @@ public class TestEscherOptRecord extends TestCase * Test that EscherOptRecord can properly read/write array properties * with empty complex part. */ - public void testEmptyArrayProperty() throws IOException { + public void testEmptyArrayProperty() { EscherOptRecord r = new EscherOptRecord(); EscherArrayProperty p = new EscherArrayProperty((short)(EscherProperties.FILL__SHADECOLORS + 0x8000), new byte[0] ); assertEquals(0, p.getNumberOfElementsInArray()); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java index f79b27c63..aef2c72ad 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherPropertyFactory.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -30,8 +29,7 @@ import org.apache.poi.util.HexDump; */ public class TestEscherPropertyFactory extends TestCase { - public void testCreateProperties() throws Exception - { + public void testCreateProperties() { String dataStr = "41 C1 " + // propid, complex ind "03 00 00 00 " + // size of complex property "01 00 " + // propid, complex ind @@ -46,15 +44,11 @@ public class TestEscherPropertyFactory extends TestCase 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() ) ); + 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() ) ); - - + 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 index 4521727e0..b4ab900ea 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherSpRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherSpRecord r = createRecord(); byte[] data = new byte[16]; @@ -35,12 +33,11 @@ public class TestEscherSpRecord extends TestCase "0A, F0, " + "08, 00, 00, 00, " + "00, 04, 00, 00, " + - "05, 00, 00, 00, ]", + "05, 00, 00, 00]", HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "02 00 " + "0A F0 " + "08 00 00 00 " + @@ -55,8 +52,7 @@ public class TestEscherSpRecord extends TestCase assertEquals( 0x05, r.getFlags() ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherSpRecord:" + nl + @@ -67,7 +63,7 @@ public class TestEscherSpRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherSpRecord createRecord() + private static EscherSpRecord createRecord() { EscherSpRecord r = new EscherSpRecord(); r.setOptions( (short) 0x0002 ); diff --git a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java index f64018309..9feca0abb 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSpgrRecord.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.ddf; import junit.framework.TestCase; @@ -24,8 +23,7 @@ import org.apache.poi.util.HexRead; public class TestEscherSpgrRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherSpgrRecord r = createRecord(); byte[] data = new byte[24]; @@ -37,12 +35,11 @@ public class TestEscherSpgrRecord extends TestCase "01, 00, 00, 00, " + // x "02, 00, 00, 00, " + // y "03, 00, 00, 00, " + // width - "04, 00, 00, 00, ]", // height + "04, 00, 00, 00]", // height HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "10 00 " + "09 F0 " + "10 00 00 00 " + @@ -61,8 +58,7 @@ public class TestEscherSpgrRecord extends TestCase assertEquals( 4, r.getRectY2() ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherSpgrRecord:" + nl + @@ -72,11 +68,10 @@ public class TestEscherSpgrRecord extends TestCase " RectY: 2" + nl + " RectWidth: 3" + nl + " RectHeight: 4" + nl; - ; assertEquals( expected, createRecord().toString() ); } - private EscherSpgrRecord createRecord() + private static EscherSpgrRecord createRecord() { EscherSpgrRecord r = new EscherSpgrRecord(); r.setOptions( (short) 0x0010 ); @@ -87,5 +82,4 @@ public class TestEscherSpgrRecord extends TestCase 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 index 1163575eb..d9a908071 100644 --- a/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestEscherSplitMenuColorsRecord.java @@ -24,8 +24,7 @@ import org.apache.poi.util.HexRead; public class TestEscherSplitMenuColorsRecord extends TestCase { - public void testSerialize() throws Exception - { + public void testSerialize() { EscherSplitMenuColorsRecord r = createRecord(); byte[] data = new byte[24]; @@ -37,12 +36,11 @@ public class TestEscherSplitMenuColorsRecord extends TestCase "02, 04, 00, 00, " + "02, 00, 00, 00, " + "02, 00, 00, 00, " + - "01, 00, 00, 00, ]", + "01, 00, 00, 00]", HexDump.toHex( data ) ); } - public void testFillFields() throws Exception - { + public void testFillFields() { String hexData = "40 00 " + "1E F1 " + "10 00 00 00 " + @@ -61,8 +59,7 @@ public class TestEscherSplitMenuColorsRecord extends TestCase assertEquals( 0x01, r.getColor4() ); } - public void testToString() throws Exception - { + public void testToString() { String nl = System.getProperty("line.separator"); String expected = "org.apache.poi.ddf.EscherSplitMenuColorsRecord:" + nl + @@ -76,7 +73,7 @@ public class TestEscherSplitMenuColorsRecord extends TestCase assertEquals( expected, createRecord().toString() ); } - private EscherSplitMenuColorsRecord createRecord() + private static EscherSplitMenuColorsRecord createRecord() { EscherSplitMenuColorsRecord r = new EscherSplitMenuColorsRecord(); r.setOptions( (short) 0x0040 ); @@ -87,5 +84,4 @@ public class TestEscherSplitMenuColorsRecord extends TestCase 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 index 9845a5889..d8c36e1a5 100644 --- a/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java +++ b/src/testcases/org/apache/poi/ddf/TestUnknownEscherRecord.java @@ -24,8 +24,7 @@ import org.apache.poi.util.HexDump; public class TestUnknownEscherRecord extends TestCase { - public void testFillFields() throws Exception - { + public void testFillFields() { String testData = "0F 02 " + // options "11 F1 " + // record id @@ -82,15 +81,14 @@ public class TestUnknownEscherRecord extends TestCase } - public void testSerialize() throws Exception - { + public void testSerialize() { 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 ) ); + assertEquals( "[34, 12, 12, F1, 00, 00, 00, 00]", HexDump.toHex( data ) ); EscherRecord childRecord = new UnknownEscherRecord(); childRecord.setOptions( (short) 0x9999 ); @@ -100,11 +98,10 @@ public class TestUnknownEscherRecord extends TestCase 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 ) ); + 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 - { + public void testToString() { UnknownEscherRecord r = new UnknownEscherRecord(); r.setOptions( (short) 0x1234 ); r.setRecordId( (short) 0xF112 ); @@ -119,6 +116,4 @@ public class TestUnknownEscherRecord extends TestCase " numchildren: 0" + nl , r.toString() ); } - - } diff --git a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java index d248baf30..17d6475e8 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestDrawingGroupRecord.java @@ -22,14 +22,11 @@ import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherSpRecord; import org.apache.poi.util.HexDump; -public class TestDrawingGroupRecord extends TestCase -{ - static final int MAX_RECORD_SIZE = 8228; +public final class TestDrawingGroupRecord extends TestCase { + private static final int MAX_RECORD_SIZE = 8228; private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4; - public void testGetRecordSize() - throws Exception - { + public void testGetRecordSize() { DrawingGroupRecord r = new DrawingGroupRecord(); assertEquals(4, r.getRecordSize()); @@ -48,7 +45,7 @@ public class TestDrawingGroupRecord extends TestCase 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("[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()); @@ -65,8 +62,7 @@ public class TestDrawingGroupRecord extends TestCase assertEquals( MAX_RECORD_SIZE * 2 + 5, r.getRecordSize() ); } - public void testSerialize() throws Exception - { + public void testSerialize() { // Check under max record size DrawingGroupRecord r = new DrawingGroupRecord(); byte[] rawData = new byte[100]; @@ -76,7 +72,7 @@ public class TestDrawingGroupRecord extends TestCase byte[] buffer = new byte[r.getRecordSize()]; int size = r.serialize( 0, buffer ); assertEquals( 104, size ); - assertEquals("[EB, 00, 64, 00, 64, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, C8, ]", HexDump.toHex(buffer)); + assertEquals("[EB, 00, 64, 00, 64, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, C8]", HexDump.toHex(buffer)); // check at max record size rawData = new byte[MAX_DATA_SIZE]; @@ -92,8 +88,8 @@ public class TestDrawingGroupRecord extends TestCase buffer = new byte[r.getRecordSize()]; size = r.serialize( 0, buffer ); assertEquals( MAX_RECORD_SIZE + 5, size ); - assertEquals( "[EB, 00, 20, 20, ]", HexDump.toHex(cut(buffer, 0, 4) )); - assertEquals( "[00, EB, 00, 01, 00, FF, ]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE - 1, MAX_RECORD_SIZE + 5) )); + assertEquals( "[EB, 00, 20, 20]", HexDump.toHex(cut(buffer, 0, 4) )); + assertEquals( "[00, EB, 00, 01, 00, FF]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE - 1, MAX_RECORD_SIZE + 5) )); // check continue record rawData = new byte[MAX_DATA_SIZE * 2 + 1]; @@ -103,9 +99,9 @@ public class TestDrawingGroupRecord extends TestCase size = r.serialize( 0, buffer ); assertEquals( MAX_RECORD_SIZE * 2 + 5, size ); assertEquals( MAX_RECORD_SIZE * 2 + 5, r.getRecordSize() ); - assertEquals( "[EB, 00, 20, 20, ]", HexDump.toHex(cut(buffer, 0, 4) )); - assertEquals( "[EB, 00, 20, 20, ]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE, MAX_RECORD_SIZE + 4) )); - assertEquals( "[3C, 00, 01, 00, FF, ]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE * 2, MAX_RECORD_SIZE * 2 + 5) )); + assertEquals( "[EB, 00, 20, 20]", HexDump.toHex(cut(buffer, 0, 4) )); + assertEquals( "[EB, 00, 20, 20]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE, MAX_RECORD_SIZE + 4) )); + assertEquals( "[3C, 00, 01, 00, FF]", HexDump.toHex(cut(buffer, MAX_RECORD_SIZE * 2, MAX_RECORD_SIZE * 2 + 5) )); // check continue record rawData = new byte[664532]; @@ -116,7 +112,7 @@ public class TestDrawingGroupRecord extends TestCase assertEquals( 664856, r.getRecordSize() ); } - private byte[] cut( byte[] data, int fromInclusive, int toExclusive ) + private static byte[] cut( byte[] data, int fromInclusive, int toExclusive ) { int length = toExclusive - fromInclusive; byte[] result = new byte[length]; @@ -124,8 +120,7 @@ public class TestDrawingGroupRecord extends TestCase return result; } - public void testGrossSizeFromDataSize() throws Exception - { + public void testGrossSizeFromDataSize() { for (int i = 0; i < MAX_RECORD_SIZE * 4; i += 11) { //System.out.print( "data size = " + i + ", gross size = " + DrawingGroupRecord.grossSizeFromDataSize( i ) ); @@ -139,6 +134,4 @@ public class TestDrawingGroupRecord extends TestCase assertEquals( MAX_RECORD_SIZE * 2, DrawingGroupRecord.grossSizeFromDataSize( MAX_DATA_SIZE * 2 ) ); assertEquals( MAX_RECORD_SIZE * 2 + 5, DrawingGroupRecord.grossSizeFromDataSize( MAX_DATA_SIZE * 2 + 1 ) ); } - - } diff --git a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java index 21be7ad1d..593290b33 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/TestEscherAggregate.java @@ -133,7 +133,7 @@ public class TestEscherAggregate extends TestCase 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, ]", + 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 ) ); }