]> source.dussan.org Git - poi.git/commitdiff
[35799] Added testXFIndexForColumn
authorAmol S. Deshmukh <amol@apache.org>
Wed, 20 Jul 2005 14:12:51 +0000 (14:12 +0000)
committerAmol S. Deshmukh <amol@apache.org>
Wed, 20 Jul 2005 14:12:51 +0000 (14:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353754 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/model/TestSheet.java

index 8388788c495aa90355784de3ff4204164d94092a..3c31f4b7b9d9d4fef8d8f6dca7d0904176eacb45 100644 (file)
@@ -280,5 +280,77 @@ public class TestSheet extends TestCase
         assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
     }
 
+    /**
+     * test newly added method Sheet.getXFIndexForColAt(..)
+     * works as designed.
+     */
+    public void testXFIndexForColumn() {
+        try{
+            final short TEST_IDX = 10;
+            final short DEFAULT_IDX = 0xF; // 15
+            short xfindex = Short.MIN_VALUE;
+            Sheet sheet = Sheet.createSheet();
+            
+            // without ColumnInfoRecord
+            xfindex = sheet.getXFIndexForColAt((short) 0);
+            assertEquals(DEFAULT_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 1);
+            assertEquals(DEFAULT_IDX, xfindex);
+            
+            ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
+            sheet.columns.insertColumn(nci);
+            
+            // single column ColumnInfoRecord
+            nci.setFirstColumn((short) 2);
+            nci.setLastColumn((short) 2);
+            nci.setXFIndex(TEST_IDX);            
+            xfindex = sheet.getXFIndexForColAt((short) 0);
+            assertEquals(DEFAULT_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 1);
+            assertEquals(DEFAULT_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 2);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 3);
+            assertEquals(DEFAULT_IDX, xfindex);
+
+            // ten column ColumnInfoRecord
+            nci.setFirstColumn((short) 2);
+            nci.setLastColumn((short) 11);
+            nci.setXFIndex(TEST_IDX);            
+            xfindex = sheet.getXFIndexForColAt((short) 1);
+            assertEquals(DEFAULT_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 2);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 6);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 11);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 12);
+            assertEquals(DEFAULT_IDX, xfindex);
+
+            // single column ColumnInfoRecord starting at index 0
+            nci.setFirstColumn((short) 0);
+            nci.setLastColumn((short) 0);
+            nci.setXFIndex(TEST_IDX);            
+            xfindex = sheet.getXFIndexForColAt((short) 0);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 1);
+            assertEquals(DEFAULT_IDX, xfindex);
+
+            // ten column ColumnInfoRecord starting at index 0
+            nci.setFirstColumn((short) 0);
+            nci.setLastColumn((short) 9);
+            nci.setXFIndex(TEST_IDX);            
+            xfindex = sheet.getXFIndexForColAt((short) 0);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 7);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 9);
+            assertEquals(TEST_IDX, xfindex);
+            xfindex = sheet.getXFIndexForColAt((short) 10);
+            assertEquals(DEFAULT_IDX, xfindex);
+        }
+        catch(Exception e){e.printStackTrace();fail(e.getMessage());}
+    }
 
 }