aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2009-12-26 19:57:09 +0000
committerNick Burch <nick@apache.org>2009-12-26 19:57:09 +0000
commit0e9861932ae265f44c61d9a767d070941b5b6eb6 (patch)
treeae46aae60578e30f4eee89b6902a3169efae2542 /src/testcases
parentf1909f578d931b504cd290e4cca585accaa6f3ac (diff)
downloadpoi-0e9861932ae265f44c61d9a767d070941b5b6eb6.tar.gz
poi-0e9861932ae265f44c61d9a767d070941b5b6eb6.zip
More work on FeatRecord/Shared Features. More is still needed though, it's still WIP
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@894018 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java89
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java33
3 files changed, 128 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
index 74e1ceb4a5..9766331085 100644
--- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
+++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java
@@ -27,6 +27,7 @@ import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.DVALRecord;
import org.apache.poi.hssf.record.DVRecord;
import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.FeatHdrRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
@@ -86,9 +87,10 @@ public final class TestHSSFEventFactory extends TestCase {
// Check that the last few records are as we expect
// (Makes sure we don't accidently skip the end ones)
int numRec = recs.length;
- assertEquals(DVALRecord.class, recs[numRec-3].getClass());
- assertEquals(DVRecord.class, recs[numRec-2].getClass());
- assertEquals(EOFRecord.class, recs[numRec-1].getClass());
+ assertEquals(DVALRecord.class, recs[numRec-4].getClass());
+ assertEquals(DVRecord.class, recs[numRec-3].getClass());
+ assertEquals(FeatHdrRecord.class, recs[numRec-2].getClass());
+ assertEquals(EOFRecord.class, recs[numRec-1].getClass());
}
/**
@@ -110,7 +112,7 @@ public final class TestHSSFEventFactory extends TestCase {
}
private static class MockHSSFListener implements HSSFListener {
- private final List records = new ArrayList();
+ private final List<Record> records = new ArrayList<Record>();
public MockHSSFListener() {}
public Record[] getRecords() {
diff --git a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
new file mode 100644
index 0000000000..0ba8b77273
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
@@ -0,0 +1,89 @@
+/* ====================================================================
+ 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 org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.InternalWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFTestHelper;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+
+import junit.framework.TestCase;
+/**
+ * Tests for <tt>FeatRecord</tt>
+ *
+ * @author Josh Micich
+ */
+public final class TestFeatRecord extends TestCase {
+ public void testWithoutFeatRecord() throws Exception {
+ HSSFWorkbook hssf =
+ HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
+ InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
+
+ int countFR = 0;
+ int countFRH = 0;
+ for(Record r : wb.getRecords()) {
+ if(r instanceof FeatRecord) {
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ countFR++;
+ }
+ if(r instanceof FeatHdrRecord) {
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ countFRH++;
+ }
+ }
+
+ assertEquals(0, countFR);
+ assertEquals(0, countFRH);
+ }
+
+ /**
+ * TODO - make this work!
+ * (Need to have the Internal Workbook capture it or something)
+ */
+ public void DISABLEDtestReadFeatRecord() throws Exception {
+ HSSFWorkbook hssf =
+ HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
+ InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
+
+ FeatRecord fr = null;
+
+ int countFR = 0;
+ int countFRH = 0;
+ for(Record r : wb.getRecords()) {
+ if(r instanceof FeatRecord) {
+ fr = (FeatRecord)r;
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ fail("FeatRecord SID found but not created correctly!");
+ }
+ if(r instanceof FeatHdrRecord) {
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ fail("FeatHdrRecord SID found but not created correctly!");
+ }
+ }
+
+ assertEquals(1, countFR);
+ assertEquals(1, countFRH);
+ assertNotNull(fr);
+
+ // Now check the contents are as expected
+ }
+}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
new file mode 100644
index 0000000000..132013da08
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
@@ -0,0 +1,33 @@
+/* ====================================================================
+ 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.usermodel;
+import org.apache.poi.hssf.model.InternalWorkbook;
+
+/**
+ * Helper class for HSSF tests that aren't within the
+ * HSSF UserModel package, but need to do internal
+ * UserModel things.
+ */
+public class HSSFTestHelper {
+ /**
+ * Lets non UserModel tests at the low level Workbook
+ */
+ public static InternalWorkbook getWorkbookForTest(HSSFWorkbook wb) {
+ return wb.getWorkbook();
+ }
+}