From 1369bb93140e3d6014b19716f1afcb192fd3e669 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Thu, 23 Oct 2008 21:42:05 +0000 Subject: [PATCH] fixed re-serialization of tAttrChoose git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@707481 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/AttrPtg.java | 3 -- .../hssf/record/formula/AllFormulaTests.java | 1 + .../poi/hssf/record/formula/TestAttrPtg.java | 50 +++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java diff --git a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java index 701a7aee7..ea0afcc37 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java @@ -221,15 +221,12 @@ public final class AttrPtg extends ControlPtg { int[] jt = _jumpTable; if (jt != null) { int joff = offset+4; - LittleEndian.putUShort(array, joff, _chooseFuncOffset); - joff+=2; for (int i = 0; i < jt.length; i++) { LittleEndian.putUShort(array, joff, jt[i]); joff+=2; } LittleEndian.putUShort(array, joff, _chooseFuncOffset); } - } public int getSize() diff --git a/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java b/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java index 5f63f31a0..248f7ca59 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java @@ -41,6 +41,7 @@ public final class AllFormulaTests { result.addTestSuite(TestAreaErrPtg.class); result.addTestSuite(TestAreaPtg.class); result.addTestSuite(TestArrayPtg.class); + result.addTestSuite(TestAttrPtg.class); result.addTestSuite(TestErrPtg.class); result.addTestSuite(TestExternalFunctionFormulas.class); result.addTestSuite(TestFormulaShifter.class); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java new file mode 100644 index 000000000..d9342d61c --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java @@ -0,0 +1,50 @@ +/* ==================================================================== + 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.formula; + +import java.util.Arrays; + +import junit.framework.AssertionFailedError; + +import org.apache.poi.hssf.record.RecordInputStream; +import org.apache.poi.hssf.record.TestcaseRecordInputStream; +import org.apache.poi.util.HexRead; + +/** + * Tests for {@link AttrPtg}. + * + * @author Josh Micich + */ +public final class TestAttrPtg extends AbstractPtgTestCase { + + /** + * Fix for bug visible around svn r706772. + */ + public void testReserializeAttrChoose() { + byte[] data = HexRead.readFromString("19, 04, 03, 00, 08, 00, 11, 00, 1A, 00, 23, 00"); + RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(data); + Ptg[] ptgs = Ptg.readTokens(data.length, in); + byte[] data2 = new byte[data.length]; + try { + Ptg.serializePtgs(ptgs, data2, 0); + } catch (ArrayIndexOutOfBoundsException e) { + throw new AssertionFailedError("incorrect re-serialization of tAttrChoose"); + } + assertTrue(Arrays.equals(data, data2)); + } +}