]> source.dussan.org Git - poi.git/commitdiff
Make InternalSheet capture the feature related records
authorNick Burch <nick@apache.org>
Sun, 27 Dec 2009 17:13:44 +0000 (17:13 +0000)
committerNick Burch <nick@apache.org>
Sun, 27 Dec 2009 17:13:44 +0000 (17:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@894081 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/InternalSheet.java
src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java
src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java

index b734c60b1fbbce19c1e42a0d81d14401923b3347..a9414f20833126db6116b81efbd6b4f24167f9f6 100644 (file)
@@ -35,6 +35,8 @@ import org.apache.poi.hssf.record.DimensionsRecord;
 import org.apache.poi.hssf.record.DrawingRecord;
 import org.apache.poi.hssf.record.EOFRecord;
 import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.FeatHdrRecord;
+import org.apache.poi.hssf.record.FeatRecord;
 import org.apache.poi.hssf.record.GridsetRecord;
 import org.apache.poi.hssf.record.GutsRecord;
 import org.apache.poi.hssf.record.IndexRecord;
@@ -265,6 +267,12 @@ public final class InternalSheet {
                 continue;
             }
 
+            if (recSid == FeatRecord.sid ||
+                       recSid == FeatHdrRecord.sid) {
+                records.add(rec);
+                continue;
+            }
+            
             if (recSid == EOFRecord.sid) {
                 records.add(rec);
                 break;
index 0ba8b772737dfc3901e33fe23f18e3626643c640..4840561e01889f9e4086dd765083cbf8ac13b844 100644 (file)
@@ -18,7 +18,9 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.hssf.model.InternalSheet;
 import org.apache.poi.hssf.model.InternalWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFTestHelper;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
@@ -34,8 +36,12 @@ public final class TestFeatRecord extends TestCase {
                        HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
                InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
                
+               assertEquals(1, hssf.getNumberOfSheets());
+               
                int countFR = 0;
                int countFRH = 0;
+               
+               // Check on the workbook, but shouldn't be there!
                for(Record r : wb.getRecords()) {
                        if(r instanceof FeatRecord) {
                                countFR++;
@@ -51,19 +57,41 @@ public final class TestFeatRecord extends TestCase {
                
                assertEquals(0, countFR);
                assertEquals(0, countFRH);
+               
+               // Now check on the sheet
+               HSSFSheet s = hssf.getSheetAt(0);
+               InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
+               
+               for(RecordBase rb : sheet.getRecords()) {
+                       if(rb instanceof Record) {
+                               Record r = (Record)rb;
+                               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 {
+       public void testReadFeatRecord() throws Exception {
                HSSFWorkbook hssf = 
                        HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
                InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
                
                FeatRecord fr = null;
                
+               assertEquals(1, hssf.getNumberOfSheets());
+               
+               // First check it isn't on the Workbook
                int countFR = 0;
                int countFRH = 0;
                for(Record r : wb.getRecords()) {
@@ -80,6 +108,30 @@ public final class TestFeatRecord extends TestCase {
                        }
                }
                
+               assertEquals(0, countFR);
+               assertEquals(0, countFRH);
+               
+               // Now find it on our sheet
+               HSSFSheet s = hssf.getSheetAt(0);
+               InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
+               
+               for(RecordBase rb : sheet.getRecords()) {
+                       if(rb instanceof Record) {
+                               Record r = (Record)rb;
+                               if(r instanceof FeatRecord) {
+                                       fr = (FeatRecord)r;
+                                       countFR++;
+                               } else if (r.getSid() == FeatRecord.sid) {
+                                       countFR++;
+                               }
+                               if(r instanceof FeatHdrRecord) {
+                                       countFRH++;
+                               } else if (r.getSid() == FeatHdrRecord.sid) {
+                                       countFRH++;
+                               }
+                       }
+               }
+               
                assertEquals(1, countFR);
                assertEquals(1, countFRH);
                assertNotNull(fr);
index 132013da084e0ed919c751d701abe17c43c3a782..7c5a88bd4539fff946d92301127ca82935152085 100644 (file)
@@ -16,6 +16,7 @@
 ==================================================================== */
 
 package org.apache.poi.hssf.usermodel;
+import org.apache.poi.hssf.model.InternalSheet;
 import org.apache.poi.hssf.model.InternalWorkbook;
 
 /**
@@ -30,4 +31,7 @@ public class HSSFTestHelper {
        public static InternalWorkbook getWorkbookForTest(HSSFWorkbook wb) {
                return wb.getWorkbook();
        }
+       public static InternalSheet getSheetForTest(HSSFSheet sheet) {
+               return sheet.getSheet();
+       }
 }