aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-04-08 21:01:43 +0000
committerJosh Micich <josh@apache.org>2009-04-08 21:01:43 +0000
commit9fa24eea2c441ef5ca6968ed2cf6dc403db8f722 (patch)
tree29e10e9902586ade18a33166d42dae071629f441 /src/testcases
parent0c1095db7616a38a6f320d8a1fd15b149f9c59d8 (diff)
downloadpoi-9fa24eea2c441ef5ca6968ed2cf6dc403db8f722.tar.gz
poi-9fa24eea2c441ef5ca6968ed2cf6dc403db8f722.zip
Bugzilla 47001 - Fixed WriteAccessRecord and LinkTable to handle unusual format written by Google Docs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@763391 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/data/ex42564-21435.xls (renamed from src/testcases/org/apache/poi/hssf/data/42564.xls)bin13824 -> 13824 bytes
-rw-r--r--src/testcases/org/apache/poi/hssf/data/ex42564-21503.xls (renamed from src/testcases/org/apache/poi/hssf/data/42564-2.xls)bin27136 -> 27136 bytes
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/model/AllModelTests.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/model/TestLinkTable.java (renamed from src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java)38
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/record/AllRecordTests.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java103
-rwxr-xr-xsrc/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java1
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java4
8 files changed, 143 insertions, 5 deletions
diff --git a/src/testcases/org/apache/poi/hssf/data/42564.xls b/src/testcases/org/apache/poi/hssf/data/ex42564-21435.xls
index dff150e2dc..dff150e2dc 100644
--- a/src/testcases/org/apache/poi/hssf/data/42564.xls
+++ b/src/testcases/org/apache/poi/hssf/data/ex42564-21435.xls
Binary files differ
diff --git a/src/testcases/org/apache/poi/hssf/data/42564-2.xls b/src/testcases/org/apache/poi/hssf/data/ex42564-21503.xls
index 3a93b40783..3a93b40783 100644
--- a/src/testcases/org/apache/poi/hssf/data/42564-2.xls
+++ b/src/testcases/org/apache/poi/hssf/data/ex42564-21503.xls
Binary files differ
diff --git a/src/testcases/org/apache/poi/hssf/model/AllModelTests.java b/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
index 35565a7a65..a243226867 100755
--- a/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
+++ b/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
@@ -34,6 +34,7 @@ public final class AllModelTests {
result.addTestSuite(TestFormulaParser.class);
result.addTestSuite(TestFormulaParserEval.class);
result.addTestSuite(TestFormulaParserIf.class);
+ result.addTestSuite(TestLinkTable.class);
result.addTestSuite(TestOperandClassTransformer.class);
result.addTestSuite(TestRowBlocksReader.class);
result.addTestSuite(TestRVA.class);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java b/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java
index 5a9696096b..f88cd4860f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestLinkTable.java
+++ b/src/testcases/org/apache/poi/hssf/model/TestLinkTable.java
@@ -15,12 +15,20 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.hssf.usermodel;
+package org.apache.poi.hssf.model;
+
+import java.util.Arrays;
+import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.SSTRecord;
+import org.apache.poi.hssf.record.SupBookRecord;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* Tests for {@link LinkTable}
*
@@ -81,7 +89,7 @@ public final class TestLinkTable extends TestCase {
The original file produces the same error.
This bug was caused by a combination of invalid sheet indexes in the EXTERNSHEET
- record, and eager initialisation of the extern sheet references. Note - the worbook
+ record, and eager initialisation of the extern sheet references. Note - the workbook
has 2 sheets, but the EXTERNSHEET record refers to sheet indexes 0, 1 and 2.
Offset 0x3954 (14676)
@@ -114,4 +122,30 @@ public final class TestLinkTable extends TestCase {
}
assertEquals("Data!$A2", cellFormula);
}
+
+ /**
+ * This problem was visible in POI svn r763332
+ * when reading the workbook of attachment 23468 from bugzilla 47001
+ */
+ public void testMissingExternSheetRecord_bug47001b() {
+
+ Record[] recs = {
+ SupBookRecord.createAddInFunctions(),
+ new SSTRecord(),
+ };
+ List<Record> recList = Arrays.asList(recs);
+ WorkbookRecordList wrl = new WorkbookRecordList();
+
+ LinkTable lt;
+ try {
+ lt = new LinkTable(recList, 0, wrl);
+ } catch (RuntimeException e) {
+ if (e.getMessage().equals("Expected an EXTERNSHEET record but got (org.apache.poi.hssf.record.SSTRecord)")) {
+ throw new AssertionFailedError("Identified bug 47001b");
+ }
+
+ throw e;
+ }
+ assertNotNull(lt);
+ }
}
diff --git a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
index 3458051ee7..e7d8c7f4a5 100755
--- a/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
+++ b/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
@@ -80,6 +80,7 @@ public final class AllRecordTests {
result.addTestSuite(TestTextObjectRecord.class);
result.addTestSuite(TestUnicodeNameRecord.class);
result.addTestSuite(TestUnicodeString.class);
+ result.addTestSuite(TestWriteAccessRecord.class);
result.addTestSuite(TestCellRange.class);
result.addTestSuite(TestConstantValueParser.class);
return result;
diff --git a/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
new file mode 100644
index 0000000000..8d170c0c4e
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/record/TestWriteAccessRecord.java
@@ -0,0 +1,103 @@
+/* ====================================================================
+ 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;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.apache.poi.util.HexRead;
+
+/**
+ * Tests for {@link WriteAccessRecord}
+ *
+ * @author Josh Micich
+ */
+public final class TestWriteAccessRecord extends TestCase {
+
+ private static final String HEX_SIXTYFOUR_SPACES = ""
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20";
+
+
+ public void testMissingStringHeader_bug47001a() {
+ /*
+ * Data taken from offset 0x0224 in
+ * attachment 23468 from bugzilla 47001
+ */
+ byte[] data = HexRead.readFromString(""
+ + "5C 00 70 00 "
+ + "4A 61 76 61 20 45 78 63 65 6C 20 41 50 49 20 76 "
+ + "32 2E 36 2E 34"
+ + "20 20 20 20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
+ + HEX_SIXTYFOUR_SPACES);
+
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+
+ WriteAccessRecord rec;
+ try {
+ rec = new WriteAccessRecord(in);
+ } catch (RecordFormatException e) {
+ if (e.getMessage().equals("Not enough data (0) to read requested (1) bytes")) {
+ throw new AssertionFailedError("Identified bug 47001a");
+ }
+ throw e;
+ }
+ assertEquals("Java Excel API v2.6.4", rec.getUsername());
+
+
+ byte[] expectedEncoding = HexRead.readFromString(""
+ + "15 00 00 4A 61 76 61 20 45 78 63 65 6C 20 41 50 "
+ + "49 20 76 32 2E 36 2E 34"
+ + "20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 "
+ + HEX_SIXTYFOUR_SPACES);
+
+ TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
+ }
+
+ public void testShortRecordWrittenByMSAccess() {
+ /*
+ * Data taken from two example files
+ * ex42564-21435.xls
+ * bug_42794.xls (from bug 42794 attachment 20429)
+ * In both cases, this data is found at offset 0x0C1C.
+ */
+ byte[] data = HexRead.readFromString(""
+ + "5C 00 39 00 "
+ + "36 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
+ + "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
+ + "20 55 73 65 72"
+ + "20 20 20 20 20 20 20 20 20 20 20 "
+ + "20 20 20 20 20 20 20 20 20");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ WriteAccessRecord rec = new WriteAccessRecord(in);
+ assertEquals("A satisfied Microsoft Office9 User", rec.getUsername());
+ byte[] expectedEncoding = HexRead.readFromString(""
+ + "22 00 00 41 20 73 61 74 69 73 66 69 65 64 20 4D "
+ + "69 63 72 6F 73 6F 66 74 20 4F 66 66 69 63 65 39 "
+ + "20 55 73 65 72"
+ + "20 20 20 20 20 20 20 20 20 20 20 "
+ + HEX_SIXTYFOUR_SPACES);
+
+ TestcaseRecordInputStream.confirmRecordEncoding(WriteAccessRecord.sid, expectedEncoding, rec.serialize());
+ }
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java b/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
index 6b3043c072..eec05641af 100755
--- a/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
@@ -59,7 +59,6 @@ public class AllUserModelTests {
result.addTestSuite(TestHSSFSheet.class);
result.addTestSuite(TestHSSFTextbox.class);
result.addTestSuite(TestHSSFWorkbook.class);
- result.addTestSuite(TestLinkTable.class);
result.addTestSuite(TestHSSFName.class);
result.addTestSuite(TestOLE2Embeding.class);
result.addTestSuite(TestPOIFSProperties.class);
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 44063e3c7a..d81441c003 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -586,7 +586,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* when reading the BOFRecord
*/
public void test42564() {
- HSSFWorkbook wb = openSample("42564.xls");
+ HSSFWorkbook wb = openSample("ex42564-21435.xls");
writeOutAndReadBack(wb);
}
@@ -596,7 +596,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
* issue.
*/
public void test42564Alt() {
- HSSFWorkbook wb = openSample("42564-2.xls");
+ HSSFWorkbook wb = openSample("ex42564-21503.xls");
writeOutAndReadBack(wb);
}