diff options
author | Josh Micich <josh@apache.org> | 2009-02-12 02:28:43 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2009-02-12 02:28:43 +0000 |
commit | 8dd000b7de187481a3e8e80bc05f96de76df92a7 (patch) | |
tree | 54b19bf9ba0da272aa15cde2385143a0736cc94a /src/testcases | |
parent | fd196fea1e660c14bdc6e48ee10c2256a59aa84d (diff) | |
download | poi-8dd000b7de187481a3e8e80bc05f96de76df92a7.tar.gz poi-8dd000b7de187481a3e8e80bc05f96de76df92a7.zip |
Fix for bug 46693 - serialization errors in CHARTFORMAT, SHTPROPS, SXVD and SXVDEX records
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@743601 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
7 files changed, 234 insertions, 15 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java index db6c7ff3f2..3458051ee7 100755 --- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java +++ b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java @@ -25,6 +25,7 @@ import org.apache.poi.hssf.record.cf.TestCellRange; import org.apache.poi.hssf.record.chart.AllChartRecordTests; import org.apache.poi.hssf.record.constant.TestConstantValueParser; import org.apache.poi.hssf.record.formula.AllFormulaTests; +import org.apache.poi.hssf.record.pivot.AllPivotRecordTests; /** * Collects all tests for package <tt>org.apache.poi.hssf.record</tt> and sub-packages. @@ -38,6 +39,7 @@ public final class AllRecordTests { result.addTest(AllChartRecordTests.suite()); result.addTest(AllFormulaTests.suite()); + result.addTest(AllPivotRecordTests.suite()); result.addTest(AllRecordAggregateTests.suite()); result.addTestSuite(TestBOFRecord.class); diff --git a/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java b/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java index 1714e91c02..d2fcf2bd05 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/AllChartRecordTests.java @@ -39,6 +39,7 @@ public final class AllChartRecordTests { result.addTestSuite(TestAxisUsedRecord.class); result.addTestSuite(TestBarRecord.class); result.addTestSuite(TestCategorySeriesAxisRecord.class); + result.addTestSuite(TestChartFormatRecord.class); result.addTestSuite(TestChartRecord.class); result.addTestSuite(TestChartTitleFormatRecord.class); result.addTestSuite(TestDatRecord.class); diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java new file mode 100644 index 0000000000..52b25057d5 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java @@ -0,0 +1,61 @@ +/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.chart;
+
+import java.util.Arrays;
+
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.record.TestcaseRecordInputStream;
+import org.apache.poi.util.HexRead;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link ChartFormatRecord} Test data taken directly from a real
+ * Excel file.
+ *
+ * @author Josh Micich
+ */
+public final class TestChartFormatRecord extends TestCase {
+ /**
+ * This rather uninteresting data came from attachment 23347 of bug 46693 at
+ * offsets 0x6BB2 and 0x7BAF
+ */
+ private static final byte[] data = HexRead.readFromString(
+ "14 10 14 00 " // BIFF header
+ + "00 00 00 00 00 00 00 00 "
+ + "00 00 00 00 00 00 00 00 "
+ + "00 00 00 00");
+
+ /**
+ * The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header).
+ */
+ public void testLoad() {
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ ChartFormatRecord record = new ChartFormatRecord(in);
+ if (in.remaining() == 2) {
+ throw new AssertionFailedError("Identified bug 44693d");
+ }
+ assertEquals(0, in.remaining());
+ assertEquals(24, record.getRecordSize());
+
+ byte[] data2 = record.serialize();
+ assertTrue(Arrays.equals(data, data2));
+ }
+}
diff --git a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java index 51794029ef..ba1415e4db 100644 --- a/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/chart/TestSheetPropertiesRecord.java @@ -18,27 +18,32 @@ package org.apache.poi.hssf.record.chart; +import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; /** - * Tests the serialization and deserialization of the SheetPropertiesRecord - * class works correctly. Test data taken directly from a real - * Excel file. + * Tests for {@link SheetPropertiesRecord} + * Test data taken directly from a real Excel file. * - * @author Glen Stampoultzis (glens at apache.org) */ public final class TestSheetPropertiesRecord extends TestCase { - byte[] data = new byte[] { + private static final byte[] data = { (byte)0x0A,(byte)0x00, - (byte)0x00 - //,(byte)0x00 // not sure where that last byte comes from + (byte)0x00, + (byte)0x00, // not sure where that last byte comes from }; public void testLoad() { - SheetPropertiesRecord record = new SheetPropertiesRecord(TestcaseRecordInputStream.create(0x1044, data)); + RecordInputStream in = TestcaseRecordInputStream.create(0x1044, data); + SheetPropertiesRecord record = new SheetPropertiesRecord(in); + if (in.remaining() == 1) { + throw new AssertionFailedError("Identified bug 44693c"); + } + assertEquals(0, in.remaining()); assertEquals( 10, record.getFlags()); assertEquals( false, record.isChartTypeManuallyFormatted() ); assertEquals( true, record.isPlotVisibleOnly() ); @@ -47,12 +52,10 @@ public final class TestSheetPropertiesRecord extends TestCase { assertEquals( false, record.isAutoPlotArea() ); assertEquals( 0, record.getEmpty()); - - assertEquals( 7, record.getRecordSize() ); + assertEquals( 8, record.getRecordSize() ); } - public void testStore() - { + public void testStore() { SheetPropertiesRecord record = new SheetPropertiesRecord(); record.setChartTypeManuallyFormatted( false ); record.setPlotVisibleOnly( true ); @@ -63,8 +66,6 @@ public final class TestSheetPropertiesRecord extends TestCase { 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]); + TestcaseRecordInputStream.confirmRecordEncoding(SheetPropertiesRecord.sid, data, recordBytes); } } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java b/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java new file mode 100644 index 0000000000..39546135ad --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/pivot/AllPivotRecordTests.java @@ -0,0 +1,36 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.record.pivot; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Collects all tests for <tt>org.apache.poi.hssf.record.pivot</tt>. + * + * @author Josh Micich + */ +public final class AllPivotRecordTests { + + public static Test suite() { + TestSuite result = new TestSuite(AllPivotRecordTests.class.getName()); + + result.addTestSuite(TestExtendedPivotTableViewFieldsRecord.class); + return result; + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java new file mode 100644 index 0000000000..7ba15d5c26 --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java @@ -0,0 +1,54 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.record.pivot; + +import org.apache.poi.hssf.record.RecordFormatException; +import org.apache.poi.hssf.record.RecordInputStream; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord; +import org.apache.poi.util.HexRead; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +/** + * Tests for {@link ExtendedPivotTableViewFieldsRecord} + * + * @author Josh Micich + */ +public final class TestExtendedPivotTableViewFieldsRecord extends TestCase { + + public void testSubNameNotPresent_bug46693() { + // This data came from attachment 23347 of bug 46693 at offset 0xAA43 + byte[] data = HexRead.readFromString( + "00 01 14 00" + // BIFF header + "1E 14 00 0A FF FF FF FF 00 00 FF FF 00 00 00 00 00 00 00 00"); + RecordInputStream in = TestcaseRecordInputStream.create(data); + ExtendedPivotTableViewFieldsRecord rec; + try { + rec = new ExtendedPivotTableViewFieldsRecord(in); + } catch (RecordFormatException e) { + if (e.getMessage().equals("Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars")) { + throw new AssertionFailedError("Identified bug 46693a"); + } + throw e; + } + + assertEquals(data.length, rec.getRecordSize()); + } +} diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java new file mode 100644 index 0000000000..448a2acb3d --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java @@ -0,0 +1,64 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.hssf.record.pivot; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +import org.apache.poi.hssf.record.RecordInputStream; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.apache.poi.hssf.record.pivottable.ViewFieldsRecord; +import org.apache.poi.util.HexRead; + +/** + * Tests for {@link ViewFieldsRecord} + * + * @author Josh Micich + */ +public final class TestViewFieldsRecord extends TestCase { + + public void testUnicodeFlag_bug46693() { + byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F"); + RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data); + ViewFieldsRecord rec = new ViewFieldsRecord(in); + if (in.remaining() == 1) { + throw new AssertionFailedError("Identified bug 46693b"); + } + assertEquals(0, in.remaining()); + assertEquals(4+data.length, rec.getRecordSize()); + } + + public void testSerialize() { + // This hex data was produced by changing the 'Custom Name' property, + // available under 'Field Settings' from the 'PivotTable Field List' (Excel 2007) + confirmSerialize("00 00 01 00 01 00 00 00 FF FF"); + confirmSerialize("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F"); + confirmSerialize("01 00 01 00 01 00 04 00 0A 00 01 48 00 69 00 73 00 74 00 6F 00 72 00 79 00 2D 00 82 69 81 89"); + } + + private static ViewFieldsRecord confirmSerialize(String hexDump) { + byte[] data = HexRead.readFromString(hexDump); + RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data); + ViewFieldsRecord rec = new ViewFieldsRecord(in); + assertEquals(0, in.remaining()); + assertEquals(4+data.length, rec.getRecordSize()); + byte[] data2 = rec.serialize(); + TestcaseRecordInputStream.confirmRecordEncoding(ViewFieldsRecord.sid, data, data2); + return rec; + } +} |