]> source.dussan.org Git - poi.git/commitdiff
fixed re-serialization of tAttrChoose
authorJosh Micich <josh@apache.org>
Thu, 23 Oct 2008 21:42:05 +0000 (21:42 +0000)
committerJosh Micich <josh@apache.org>
Thu, 23 Oct 2008 21:42:05 +0000 (21:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@707481 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java
src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java [new file with mode: 0644]

index 701a7aee749928a546b499736dc1e6165f3085ca..ea0afcc377913d6ef309653d2c143b7de7d586b6 100644 (file)
@@ -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()
index 5f63f31a0bee6d64c26653bbeb1eae47cbd7db2c..248f7ca59d785bf3a829e783b584ae915e54cf06 100644 (file)
@@ -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 (file)
index 0000000..d9342d6
--- /dev/null
@@ -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));
+       }
+}