You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [29/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheet.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheet.java Sat May 22 20:56:44 2021
@@ -51,607 +51,607 @@ import org.junit.jupiter.api.Test;
* Unit test for the {@link InternalSheet} class.
*/
final class TestSheet {
- private static InternalSheet createSheet(List<org.apache.poi.hssf.record.Record> inRecs) {
- return InternalSheet.createSheet(new RecordStream(inRecs, 0));
- }
-
- @Test
- void testCreateSheet() {
- // Check we're adding row and cell aggregates
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
- records.add(BOFRecord.createSheetBOF());
- records.add( new DimensionsRecord() );
- records.add(createWindow2Record());
- records.add(EOFRecord.instance);
- InternalSheet sheet = createSheet(records);
-
- List<org.apache.poi.hssf.record.Record> outRecs = new ArrayList<>();
- sheet.visitContainedRecords(outRecs::add, 0);
-
- Iterator<org.apache.poi.hssf.record.Record> iter = outRecs.iterator();
- assertTrue(iter.next() instanceof BOFRecord );
- assertTrue(iter.next() instanceof IndexRecord);
- assertTrue(iter.next() instanceof DimensionsRecord);
- assertTrue(iter.next() instanceof WindowTwoRecord );
- assertTrue(iter.next() instanceof EOFRecord);
- }
-
- private static org.apache.poi.hssf.record.Record createWindow2Record() {
- WindowTwoRecord result = new WindowTwoRecord();
- result.setOptions(( short ) 0x6b6);
- result.setTopRow(( short ) 0);
- result.setLeftCol(( short ) 0);
- result.setHeaderColor(0x40);
- result.setPageBreakZoom(( short ) 0);
- result.setNormalZoom(( short ) 0);
- return result;
- }
-
- private static final class MergedCellListener implements RecordVisitor {
-
- private int _count;
- public MergedCellListener() {
- _count = 0;
- }
- @Override
+ private static InternalSheet createSheet(List<org.apache.poi.hssf.record.Record> inRecs) {
+ return InternalSheet.createSheet(new RecordStream(inRecs, 0));
+ }
+
+ @Test
+ void testCreateSheet() {
+ // Check we're adding row and cell aggregates
+ List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
+ records.add(BOFRecord.createSheetBOF());
+ records.add( new DimensionsRecord() );
+ records.add(createWindow2Record());
+ records.add(EOFRecord.instance);
+ InternalSheet sheet = createSheet(records);
+
+ List<org.apache.poi.hssf.record.Record> outRecs = new ArrayList<>();
+ sheet.visitContainedRecords(outRecs::add, 0);
+
+ Iterator<org.apache.poi.hssf.record.Record> iter = outRecs.iterator();
+ assertTrue(iter.next() instanceof BOFRecord );
+ assertTrue(iter.next() instanceof IndexRecord);
+ assertTrue(iter.next() instanceof DimensionsRecord);
+ assertTrue(iter.next() instanceof WindowTwoRecord );
+ assertTrue(iter.next() instanceof EOFRecord);
+ }
+
+ private static org.apache.poi.hssf.record.Record createWindow2Record() {
+ WindowTwoRecord result = new WindowTwoRecord();
+ result.setOptions(( short ) 0x6b6);
+ result.setTopRow(( short ) 0);
+ result.setLeftCol(( short ) 0);
+ result.setHeaderColor(0x40);
+ result.setPageBreakZoom(( short ) 0);
+ result.setNormalZoom(( short ) 0);
+ return result;
+ }
+
+ private static final class MergedCellListener implements RecordVisitor {
+
+ private int _count;
+ public MergedCellListener() {
+ _count = 0;
+ }
+ @Override
public void visitRecord(org.apache.poi.hssf.record.Record r) {
- if (r instanceof MergeCellsRecord) {
- _count++;
- }
- }
- public int getCount() {
- return _count;
- }
- }
-
- @Test
- void testAddMergedRegion() {
- InternalSheet sheet = InternalSheet.createSheet();
- final int regionsToAdd = 4096;
-
- //simple test that adds a load of regions
- for (int n = 0; n < regionsToAdd; n++)
- {
- int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
+ if (r instanceof MergeCellsRecord) {
+ _count++;
+ }
+ }
+ public int getCount() {
+ return _count;
+ }
+ }
+
+ @Test
+ void testAddMergedRegion() {
+ InternalSheet sheet = InternalSheet.createSheet();
+ final int regionsToAdd = 4096;
+
+ //simple test that adds a load of regions
+ for (int n = 0; n < regionsToAdd; n++)
+ {
+ int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
assertEquals(index, n, "Merged region index expected to be " + n + " got " + index);
- }
+ }
- //test all the regions were indeed added
+ //test all the regions were indeed added
assertEquals(sheet.getNumMergedRegions(), regionsToAdd);
- //test that the regions were spread out over the appropriate number of records
- MergedCellListener mcListener = new MergedCellListener();
- sheet.visitContainedRecords(mcListener, 0);
- int recordsAdded = mcListener.getCount();
- int recordsExpected = regionsToAdd/1027;
- //noinspection ConstantConditions
- if ((regionsToAdd % 1027) != 0) {
- recordsExpected++;
- }
+ //test that the regions were spread out over the appropriate number of records
+ MergedCellListener mcListener = new MergedCellListener();
+ sheet.visitContainedRecords(mcListener, 0);
+ int recordsAdded = mcListener.getCount();
+ int recordsExpected = regionsToAdd/1027;
+ //noinspection ConstantConditions
+ if ((regionsToAdd % 1027) != 0) {
+ recordsExpected++;
+ }
assertEquals(recordsAdded, recordsExpected,
- "The " + regionsToAdd + " merged regions should have been spread out over "
- + recordsExpected + " records, not " + recordsAdded);
- // Check we can't add one with invalid date
- IllegalArgumentException e;
- e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 9, (short)12));
- assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
-
- e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 12, (short)9));
- assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
- }
-
- @Test
- void testRemoveMergedRegion() {
- InternalSheet sheet = InternalSheet.createSheet();
- int regionsToAdd = 4096;
-
- for (int n = 0; n < regionsToAdd; n++) {
- sheet.addMergedRegion(n, 0, n, 1);
- }
-
- int nSheetRecords = sheet.getRecords().size();
-
- //remove a third from the beginning
- for (int n = 0; n < regionsToAdd/3; n++)
- {
- sheet.removeMergedRegion(0);
- //assert they have been deleted
- assertEquals(regionsToAdd - n - 1, sheet.getNumMergedRegions(), "Num of regions");
- }
-
- // merge records are removed from within the MergedCellsTable,
- // so the sheet record count should not change
- assertEquals(nSheetRecords, sheet.getRecords().size(), "Sheet Records");
- }
-
- /**
- * Bug: 22922 (Reported by Xuemin Guan)
- * <p>
- * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
- * fills up the records.
- *
- */
- @Test
- void testMovingMergedRegion() {
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
-
- CellRangeAddress[] cras = {
- new CellRangeAddress(0, 1, 0, 2),
- };
- MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
- records.add(BOFRecord.createSheetBOF());
- records.add(new DimensionsRecord());
- records.add(new RowRecord(0));
- records.add(new RowRecord(1));
- records.add(new RowRecord(2));
- records.add(createWindow2Record());
- records.add(EOFRecord.instance);
- records.add(merged);
-
- InternalSheet sheet = createSheet(records);
- sheet.getRecords().remove(0); // TODO - what does this line do?
-
- //stub object to throw off list INDEX operations
- sheet.removeMergedRegion(0);
- assertEquals(0, sheet.getNumMergedRegions(), "Should be no more merged regions");
- }
+ "The " + regionsToAdd + " merged regions should have been spread out over "
+ + recordsExpected + " records, not " + recordsAdded);
+ // Check we can't add one with invalid date
+ IllegalArgumentException e;
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 9, (short)12));
+ assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
+
+ e = assertThrows(IllegalArgumentException.class, () -> sheet.addMergedRegion(10, (short)10, 12, (short)9));
+ assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
+ }
+
+ @Test
+ void testRemoveMergedRegion() {
+ InternalSheet sheet = InternalSheet.createSheet();
+ int regionsToAdd = 4096;
+
+ for (int n = 0; n < regionsToAdd; n++) {
+ sheet.addMergedRegion(n, 0, n, 1);
+ }
+
+ int nSheetRecords = sheet.getRecords().size();
+
+ //remove a third from the beginning
+ for (int n = 0; n < regionsToAdd/3; n++)
+ {
+ sheet.removeMergedRegion(0);
+ //assert they have been deleted
+ assertEquals(regionsToAdd - n - 1, sheet.getNumMergedRegions(), "Num of regions");
+ }
+
+ // merge records are removed from within the MergedCellsTable,
+ // so the sheet record count should not change
+ assertEquals(nSheetRecords, sheet.getRecords().size(), "Sheet Records");
+ }
+
+ /**
+ * Bug: 22922 (Reported by Xuemin Guan)
+ * <p>
+ * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
+ * fills up the records.
+ *
+ */
+ @Test
+ void testMovingMergedRegion() {
+ List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
+
+ CellRangeAddress[] cras = {
+ new CellRangeAddress(0, 1, 0, 2),
+ };
+ MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
+ records.add(BOFRecord.createSheetBOF());
+ records.add(new DimensionsRecord());
+ records.add(new RowRecord(0));
+ records.add(new RowRecord(1));
+ records.add(new RowRecord(2));
+ records.add(createWindow2Record());
+ records.add(EOFRecord.instance);
+ records.add(merged);
+
+ InternalSheet sheet = createSheet(records);
+ sheet.getRecords().remove(0); // TODO - what does this line do?
+
+ //stub object to throw off list INDEX operations
+ sheet.removeMergedRegion(0);
+ assertEquals(0, sheet.getNumMergedRegions(), "Should be no more merged regions");
+ }
// @Test
- // void testGetMergedRegionAt() {
- // TODO
- // }
-
- // @Test
- // void testGetNumMergedRegions() {
- // TODO
- // }
-
- /**
- * Makes sure all rows registered for this sheet are aggregated, they were being skipped
- *
- */
- @Test
- void testRowAggregation() {
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
-
- records.add(InternalSheet.createBOF());
- records.add(new DimensionsRecord());
- records.add(new RowRecord(0));
- records.add(new RowRecord(1));
- FormulaRecord formulaRecord = new FormulaRecord();
- formulaRecord.setCachedResultTypeString();
- records.add(formulaRecord);
- records.add(new StringRecord());
- records.add(new RowRecord(2));
- records.add(createWindow2Record());
- records.add(EOFRecord.instance);
-
- InternalSheet sheet = createSheet(records);
- assertNotNull(sheet.getRow(2), "Row [2] was skipped");
- }
-
- /**
- * Make sure page break functionality works (in memory)
- *
- */
- @Test
- void testRowPageBreaks() {
- short colFrom = 0;
- short colTo = 255;
-
- InternalSheet worksheet = InternalSheet.createSheet();
- PageSettingsBlock sheet = worksheet.getPageSettings();
- sheet.setRowBreak(0, colFrom, colTo);
-
- assertTrue(sheet.isRowBroken(0), "no row break at 0");
- assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
-
- sheet.setRowBreak(0, colFrom, colTo);
- sheet.setRowBreak(0, colFrom, colTo);
-
- assertTrue(sheet.isRowBroken(0), "no row break at 0");
- assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
-
- sheet.setRowBreak(10, colFrom, colTo);
- sheet.setRowBreak(11, colFrom, colTo);
-
- assertTrue(sheet.isRowBroken(10), "no row break at 10");
- assertTrue(sheet.isRowBroken(11), "no row break at 11");
- assertEquals(3, sheet.getNumRowBreaks(), "3 row break available");
-
-
- boolean is10 = false;
- boolean is0 = false;
- boolean is11 = false;
-
- int[] rowBreaks = sheet.getRowBreaks();
- for (int main : rowBreaks) {
- assertTrue(main == 0 || main == 10 || main == 11, "Invalid page break");
- if (main == 0) is0 = true;
- if (main == 10) is10 = true;
- if (main == 11) is11 = true;
- }
-
- assertTrue(is0 && is10 && is11, "one of the breaks didnt make it");
-
- sheet.removeRowBreak(11);
- assertFalse(sheet.isRowBroken(11), "row should be removed");
-
- sheet.removeRowBreak(0);
- assertFalse(sheet.isRowBroken(0), "row should be removed");
-
- sheet.removeRowBreak(10);
- assertFalse(sheet.isRowBroken(10), "row should be removed");
-
- assertEquals(0, sheet.getNumRowBreaks(), "no more breaks");
- }
-
- /**
- * Make sure column pag breaks works properly (in-memory)
- *
- */
- @Test
- void testColPageBreaks() {
- short rowFrom = 0;
- short rowTo = (short)65535;
-
- InternalSheet worksheet = InternalSheet.createSheet();
- PageSettingsBlock sheet = worksheet.getPageSettings();
- sheet.setColumnBreak((short)0, rowFrom, rowTo);
-
- assertTrue(sheet.isColumnBroken(0), "no col break at 0");
- assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
-
- sheet.setColumnBreak((short)0, rowFrom, rowTo);
-
- assertTrue(sheet.isColumnBroken(0), "no col break at 0");
- assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
-
- sheet.setColumnBreak((short)1, rowFrom, rowTo);
- sheet.setColumnBreak((short)10, rowFrom, rowTo);
- sheet.setColumnBreak((short)15, rowFrom, rowTo);
-
- assertTrue(sheet.isColumnBroken(1), "no col break at 1");
- assertTrue(sheet.isColumnBroken(10), "no col break at 10");
- assertTrue(sheet.isColumnBroken(15), "no col break at 15");
- assertEquals(4, sheet.getNumColumnBreaks(), "4 col break available");
-
- boolean is10 = false;
- boolean is0 = false;
- boolean is1 = false;
- boolean is15 = false;
-
- int[] colBreaks = sheet.getColumnBreaks();
- for (int main : colBreaks) {
- assertTrue(main == 0 || main == 1 || main == 10 || main == 15, "Invalid page break");
- if (main == 0) is0 = true;
- if (main == 1) is1 = true;
- if (main == 10) is10= true;
- if (main == 15) is15 = true;
- }
-
- assertTrue(is0 && is1 && is10 && is15, "one of the breaks didnt make it");
-
- sheet.removeColumnBreak(15);
- assertFalse(sheet.isColumnBroken(15), "column break should not be there");
-
- sheet.removeColumnBreak(0);
- assertFalse(sheet.isColumnBroken(0), "column break should not be there");
-
- sheet.removeColumnBreak(1);
- assertFalse(sheet.isColumnBroken(1), "column break should not be there");
-
- sheet.removeColumnBreak(10);
- assertFalse(sheet.isColumnBroken(10), "column break should not be there");
-
- assertEquals(0, sheet.getNumColumnBreaks(), "no more breaks");
- }
-
- /**
- * test newly added method Sheet.getXFIndexForColAt(..)
- * works as designed.
- */
- @Test
- void testXFIndexForColumn() {
- final short TEST_IDX = 10;
- final short DEFAULT_IDX = 0xF; // 15
- InternalSheet sheet = InternalSheet.createSheet();
-
- // without ColumnInfoRecord
- int xfindex = sheet.getXFIndexForColAt((short) 0);
- assertEquals(DEFAULT_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 1);
- assertEquals(DEFAULT_IDX, xfindex);
-
- ColumnInfoRecord nci = new ColumnInfoRecord();
- sheet._columnInfos.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);
- }
-
- /**
- * Prior to bug 45066, POI would get the estimated sheet size wrong
- * when an {@code UncalcedRecord} was present.
- */
- @Test
- void testUncalcSize_bug45066() {
-
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
- records.add(BOFRecord.createSheetBOF());
- records.add(new UncalcedRecord());
- records.add(new DimensionsRecord());
- records.add(createWindow2Record());
- records.add(EOFRecord.instance);
- InternalSheet sheet = createSheet(records);
-
- // The original bug was due to different logic for collecting records for sizing and
- // serialization. The code has since been refactored into a single method for visiting
- // all contained records. Now this test is much less interesting
- int[] totalSize = { 0 };
- byte[] buf = new byte[100];
-
- sheet.visitContainedRecords(r -> {
- int estimatedSize = r.getRecordSize();
- int serializedSize = r.serialize(0, buf);
- assertEquals(estimatedSize, serializedSize, "serialized size mismatch for record (" + r.getClass().getName() + ")");
- totalSize[0] += estimatedSize;
- }, 0);
- assertEquals(90, totalSize[0]);
- }
-
- /**
- * Prior to bug 45145 {@code RowRecordsAggregate} and {@code ValueRecordsAggregate} could
- * sometimes occur in reverse order. This test reproduces one of those situations and makes
- * sure that RRA comes before VRA.<br>
- *
- * The code here represents a normal POI use case where a spreadsheet is created from scratch.
- */
- @Test
- void testRowValueAggregatesOrder_bug45145() {
-
- InternalSheet sheet = InternalSheet.createSheet();
-
- RowRecord rr = new RowRecord(5);
- sheet.addRow(rr);
-
- CellValueRecordInterface cvr = new BlankRecord();
- cvr.setColumn((short)0);
- cvr.setRow(5);
- sheet.addValueRecord(5, cvr);
-
-
- int dbCellRecordPos = getDbCellRecordPos(sheet);
- // The overt symptom of the bug
- // DBCELL record pos is calculated wrong if VRA comes before RRA
- assertNotEquals (252, dbCellRecordPos);
-
-// if (false) {
-// // make sure that RRA and VRA are in the right place
-// // (Aug 2008) since the VRA is now part of the RRA, there is much less chance that
-// // they could get out of order. Still, one could write serialize the sheet here,
-// // and read back with EventRecordFactory to make sure...
-// }
- assertEquals(242, dbCellRecordPos);
- }
-
- /**
- * @return the value calculated for the position of the first DBCELL record for this sheet.
- * That value is found on the IndexRecord.
- */
- private static int getDbCellRecordPos(InternalSheet sheet) {
-
- MyIndexRecordListener myIndexListener = new MyIndexRecordListener();
- sheet.visitContainedRecords(myIndexListener, 0);
- IndexRecord indexRecord = myIndexListener.getIndexRecord();
+ // void testGetMergedRegionAt() {
+ // TODO
+ // }
+
+ // @Test
+ // void testGetNumMergedRegions() {
+ // TODO
+ // }
+
+ /**
+ * Makes sure all rows registered for this sheet are aggregated, they were being skipped
+ *
+ */
+ @Test
+ void testRowAggregation() {
+ List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
+
+ records.add(InternalSheet.createBOF());
+ records.add(new DimensionsRecord());
+ records.add(new RowRecord(0));
+ records.add(new RowRecord(1));
+ FormulaRecord formulaRecord = new FormulaRecord();
+ formulaRecord.setCachedResultTypeString();
+ records.add(formulaRecord);
+ records.add(new StringRecord());
+ records.add(new RowRecord(2));
+ records.add(createWindow2Record());
+ records.add(EOFRecord.instance);
+
+ InternalSheet sheet = createSheet(records);
+ assertNotNull(sheet.getRow(2), "Row [2] was skipped");
+ }
+
+ /**
+ * Make sure page break functionality works (in memory)
+ *
+ */
+ @Test
+ void testRowPageBreaks() {
+ short colFrom = 0;
+ short colTo = 255;
+
+ InternalSheet worksheet = InternalSheet.createSheet();
+ PageSettingsBlock sheet = worksheet.getPageSettings();
+ sheet.setRowBreak(0, colFrom, colTo);
+
+ assertTrue(sheet.isRowBroken(0), "no row break at 0");
+ assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
+
+ sheet.setRowBreak(0, colFrom, colTo);
+ sheet.setRowBreak(0, colFrom, colTo);
+
+ assertTrue(sheet.isRowBroken(0), "no row break at 0");
+ assertEquals(1, sheet.getNumRowBreaks(), "1 row break available");
+
+ sheet.setRowBreak(10, colFrom, colTo);
+ sheet.setRowBreak(11, colFrom, colTo);
+
+ assertTrue(sheet.isRowBroken(10), "no row break at 10");
+ assertTrue(sheet.isRowBroken(11), "no row break at 11");
+ assertEquals(3, sheet.getNumRowBreaks(), "3 row break available");
+
+
+ boolean is10 = false;
+ boolean is0 = false;
+ boolean is11 = false;
+
+ int[] rowBreaks = sheet.getRowBreaks();
+ for (int main : rowBreaks) {
+ assertTrue(main == 0 || main == 10 || main == 11, "Invalid page break");
+ if (main == 0) is0 = true;
+ if (main == 10) is10 = true;
+ if (main == 11) is11 = true;
+ }
+
+ assertTrue(is0 && is10 && is11, "one of the breaks didnt make it");
+
+ sheet.removeRowBreak(11);
+ assertFalse(sheet.isRowBroken(11), "row should be removed");
+
+ sheet.removeRowBreak(0);
+ assertFalse(sheet.isRowBroken(0), "row should be removed");
+
+ sheet.removeRowBreak(10);
+ assertFalse(sheet.isRowBroken(10), "row should be removed");
+
+ assertEquals(0, sheet.getNumRowBreaks(), "no more breaks");
+ }
+
+ /**
+ * Make sure column pag breaks works properly (in-memory)
+ *
+ */
+ @Test
+ void testColPageBreaks() {
+ short rowFrom = 0;
+ short rowTo = (short)65535;
+
+ InternalSheet worksheet = InternalSheet.createSheet();
+ PageSettingsBlock sheet = worksheet.getPageSettings();
+ sheet.setColumnBreak((short)0, rowFrom, rowTo);
+
+ assertTrue(sheet.isColumnBroken(0), "no col break at 0");
+ assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
+
+ sheet.setColumnBreak((short)0, rowFrom, rowTo);
+
+ assertTrue(sheet.isColumnBroken(0), "no col break at 0");
+ assertEquals(1, sheet.getNumColumnBreaks(), "1 col break available");
+
+ sheet.setColumnBreak((short)1, rowFrom, rowTo);
+ sheet.setColumnBreak((short)10, rowFrom, rowTo);
+ sheet.setColumnBreak((short)15, rowFrom, rowTo);
+
+ assertTrue(sheet.isColumnBroken(1), "no col break at 1");
+ assertTrue(sheet.isColumnBroken(10), "no col break at 10");
+ assertTrue(sheet.isColumnBroken(15), "no col break at 15");
+ assertEquals(4, sheet.getNumColumnBreaks(), "4 col break available");
+
+ boolean is10 = false;
+ boolean is0 = false;
+ boolean is1 = false;
+ boolean is15 = false;
+
+ int[] colBreaks = sheet.getColumnBreaks();
+ for (int main : colBreaks) {
+ assertTrue(main == 0 || main == 1 || main == 10 || main == 15, "Invalid page break");
+ if (main == 0) is0 = true;
+ if (main == 1) is1 = true;
+ if (main == 10) is10= true;
+ if (main == 15) is15 = true;
+ }
+
+ assertTrue(is0 && is1 && is10 && is15, "one of the breaks didnt make it");
+
+ sheet.removeColumnBreak(15);
+ assertFalse(sheet.isColumnBroken(15), "column break should not be there");
+
+ sheet.removeColumnBreak(0);
+ assertFalse(sheet.isColumnBroken(0), "column break should not be there");
+
+ sheet.removeColumnBreak(1);
+ assertFalse(sheet.isColumnBroken(1), "column break should not be there");
+
+ sheet.removeColumnBreak(10);
+ assertFalse(sheet.isColumnBroken(10), "column break should not be there");
+
+ assertEquals(0, sheet.getNumColumnBreaks(), "no more breaks");
+ }
+
+ /**
+ * test newly added method Sheet.getXFIndexForColAt(..)
+ * works as designed.
+ */
+ @Test
+ void testXFIndexForColumn() {
+ final short TEST_IDX = 10;
+ final short DEFAULT_IDX = 0xF; // 15
+ InternalSheet sheet = InternalSheet.createSheet();
+
+ // without ColumnInfoRecord
+ int xfindex = sheet.getXFIndexForColAt((short) 0);
+ assertEquals(DEFAULT_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 1);
+ assertEquals(DEFAULT_IDX, xfindex);
+
+ ColumnInfoRecord nci = new ColumnInfoRecord();
+ sheet._columnInfos.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);
+ }
+
+ /**
+ * Prior to bug 45066, POI would get the estimated sheet size wrong
+ * when an {@code UncalcedRecord} was present.
+ */
+ @Test
+ void testUncalcSize_bug45066() {
+
+ List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
+ records.add(BOFRecord.createSheetBOF());
+ records.add(new UncalcedRecord());
+ records.add(new DimensionsRecord());
+ records.add(createWindow2Record());
+ records.add(EOFRecord.instance);
+ InternalSheet sheet = createSheet(records);
+
+ // The original bug was due to different logic for collecting records for sizing and
+ // serialization. The code has since been refactored into a single method for visiting
+ // all contained records. Now this test is much less interesting
+ int[] totalSize = { 0 };
+ byte[] buf = new byte[100];
+
+ sheet.visitContainedRecords(r -> {
+ int estimatedSize = r.getRecordSize();
+ int serializedSize = r.serialize(0, buf);
+ assertEquals(estimatedSize, serializedSize, "serialized size mismatch for record (" + r.getClass().getName() + ")");
+ totalSize[0] += estimatedSize;
+ }, 0);
+ assertEquals(90, totalSize[0]);
+ }
+
+ /**
+ * Prior to bug 45145 {@code RowRecordsAggregate} and {@code ValueRecordsAggregate} could
+ * sometimes occur in reverse order. This test reproduces one of those situations and makes
+ * sure that RRA comes before VRA.<br>
+ *
+ * The code here represents a normal POI use case where a spreadsheet is created from scratch.
+ */
+ @Test
+ void testRowValueAggregatesOrder_bug45145() {
+
+ InternalSheet sheet = InternalSheet.createSheet();
+
+ RowRecord rr = new RowRecord(5);
+ sheet.addRow(rr);
+
+ CellValueRecordInterface cvr = new BlankRecord();
+ cvr.setColumn((short)0);
+ cvr.setRow(5);
+ sheet.addValueRecord(5, cvr);
+
+
+ int dbCellRecordPos = getDbCellRecordPos(sheet);
+ // The overt symptom of the bug
+ // DBCELL record pos is calculated wrong if VRA comes before RRA
+ assertNotEquals (252, dbCellRecordPos);
+
+// if (false) {
+// // make sure that RRA and VRA are in the right place
+// // (Aug 2008) since the VRA is now part of the RRA, there is much less chance that
+// // they could get out of order. Still, one could write serialize the sheet here,
+// // and read back with EventRecordFactory to make sure...
+// }
+ assertEquals(242, dbCellRecordPos);
+ }
+
+ /**
+ * @return the value calculated for the position of the first DBCELL record for this sheet.
+ * That value is found on the IndexRecord.
+ */
+ private static int getDbCellRecordPos(InternalSheet sheet) {
+
+ MyIndexRecordListener myIndexListener = new MyIndexRecordListener();
+ sheet.visitContainedRecords(myIndexListener, 0);
+ IndexRecord indexRecord = myIndexListener.getIndexRecord();
return indexRecord.getDbcellAt(0);
- }
+ }
- private static final class MyIndexRecordListener implements RecordVisitor {
+ private static final class MyIndexRecordListener implements RecordVisitor {
- private IndexRecord _indexRecord;
- public MyIndexRecordListener() {
- // no-arg constructor
- }
- public IndexRecord getIndexRecord() {
- return _indexRecord;
- }
- @Override
+ private IndexRecord _indexRecord;
+ public MyIndexRecordListener() {
+ // no-arg constructor
+ }
+ public IndexRecord getIndexRecord() {
+ return _indexRecord;
+ }
+ @Override
public void visitRecord(org.apache.poi.hssf.record.Record r) {
- if (r instanceof IndexRecord) {
- if (_indexRecord != null) {
- throw new RuntimeException("too many index records");
- }
- _indexRecord = (IndexRecord)r;
- }
- }
- }
-
- /**
- * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
- * which in turn got the dimensions record out of alignment
- */
- @Test
- void testGutsRecord_bug45640() {
-
- InternalSheet sheet = InternalSheet.createSheet();
- sheet.addRow(new RowRecord(0));
- sheet.addRow(new RowRecord(1));
- sheet.groupRowRange( 0, 1, true );
- assertNotNull(sheet.toString());
- List<RecordBase> recs = sheet.getRecords();
- long count = recs.stream().filter(r -> r instanceof GutsRecord).count();
- assertNotEquals(2, count);
- assertEquals(1, count);
- }
-
- @Test
- void testMisplacedMergedCellsRecords_bug45699() throws Exception {
- try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls")) {
- HSSFSheet sheet = wb.getSheetAt(0);
- HSSFRow row = sheet.getRow(3);
- HSSFCell cell = row.getCell(4);
- assertNotNull(cell, "Identified bug 45699");
- assertEquals("Informations", cell.getRichStringCellValue().getString());
- }
- }
- /**
- * In 3.1, setting margins between creating first row and first cell caused an exception.
- */
- @Test
- void testSetMargins_bug45717() throws Exception {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HSSFSheet sheet = workbook.createSheet("Vorschauliste");
- HSSFRow row = sheet.createRow(0);
-
- sheet.setMargin(HSSFSheet.LeftMargin, 0.3);
- try {
- row.createCell(0);
- } catch (IllegalStateException e) {
- if (e.getMessage().equals("Cannot create value records before row records exist")) {
- fail("Identified bug 45717");
- }
- throw e;
- } finally {
- workbook.close();
- }
- }
-
- /**
- * Some apps seem to write files with missing DIMENSION records.
- * Excel(2007) tolerates this, so POI should too.
- */
- @Test
- void testMissingDims() {
-
- int rowIx = 5;
- int colIx = 6;
- NumberRecord nr = new NumberRecord();
- nr.setRow(rowIx);
- nr.setColumn((short) colIx);
- nr.setValue(3.0);
-
- List<org.apache.poi.hssf.record.Record> inRecs = new ArrayList<>();
- inRecs.add(BOFRecord.createSheetBOF());
- inRecs.add(new RowRecord(rowIx));
- inRecs.add(nr);
- inRecs.add(createWindow2Record());
- inRecs.add(EOFRecord.instance);
- InternalSheet sheet = createSheet(inRecs);
-
- List<org.apache.poi.hssf.record.Record> outRecs = new ArrayList<>();
- sheet.visitContainedRecords(outRecs::add, rowIx);
- assertEquals(8, outRecs.size());
- DimensionsRecord dims = (DimensionsRecord) outRecs.get(5);
- assertEquals(rowIx, dims.getFirstRow());
- assertEquals(rowIx, dims.getLastRow());
- assertEquals(colIx, dims.getFirstCol());
- assertEquals(colIx, dims.getLastCol());
- }
-
- /**
- * Prior to the fix for bug 46547, shifting formulas would have the side-effect
- * of creating a {@link ConditionalFormattingTable}. There was no impairment to
- * functionality since empty record aggregates are equivalent to missing record
- * aggregates. However, since this unnecessary creation helped expose bug 46547b,
- * and since there is a slight performance hit the fix was made to avoid it.
- */
- @Test
- void testShiftFormulasAddCondFormat_bug46547() {
- // Create a sheet with data validity (similar to bugzilla attachment id=23131).
- InternalSheet sheet = InternalSheet.createSheet();
-
- List<RecordBase> sheetRecs = sheet.getRecords();
- assertEquals(23, sheetRecs.size());
-
- FormulaShifter shifter = FormulaShifter.createForRowShift(0, "", 0, 0, 1, SpreadsheetVersion.EXCEL97);
- sheet.updateFormulasAfterCellShift(shifter, 0);
- assertFalse(sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable);
- assertEquals(23, sheetRecs.size());
- }
- /**
- * Bug 46547 happened when attempting to add conditional formatting to a sheet
- * which already had data validity constraints.
- */
- @Test
- void testAddCondFormatAfterDataValidation_bug46547() {
- // Create a sheet with data validity (similar to bugzilla attachment id=23131).
- InternalSheet sheet = InternalSheet.createSheet();
- sheet.getOrCreateDataValidityTable();
-
- // attempt to add conditional formatting
- ConditionalFormattingTable cft = sheet.getConditionalFormattingTable();
- assertNotNull(cft);
- }
-
- @Test
- void testCloneMulBlank_bug46776() {
- org.apache.poi.hssf.record.Record[] recs = {
- InternalSheet.createBOF(),
- new DimensionsRecord(),
- new RowRecord(1),
- new MulBlankRecord(1, 3, new short[] { 0x0F, 0x0F, 0x0F, } ),
- new RowRecord(2),
- createWindow2Record(),
- EOFRecord.instance,
- };
-
- InternalSheet sheet = createSheet(Arrays.asList(recs));
-
- InternalSheet sheet2 = sheet.cloneSheet();
-
- List<org.apache.poi.hssf.record.Record> clonedRecs = new ArrayList<>();
- sheet2.visitContainedRecords(clonedRecs::add, 0);
- // +2 for INDEX and DBCELL
- assertEquals(recs.length+2, clonedRecs.size());
- }
+ if (r instanceof IndexRecord) {
+ if (_indexRecord != null) {
+ throw new RuntimeException("too many index records");
+ }
+ _indexRecord = (IndexRecord)r;
+ }
+ }
+ }
+
+ /**
+ * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
+ * which in turn got the dimensions record out of alignment
+ */
+ @Test
+ void testGutsRecord_bug45640() {
+
+ InternalSheet sheet = InternalSheet.createSheet();
+ sheet.addRow(new RowRecord(0));
+ sheet.addRow(new RowRecord(1));
+ sheet.groupRowRange( 0, 1, true );
+ assertNotNull(sheet.toString());
+ List<RecordBase> recs = sheet.getRecords();
+ long count = recs.stream().filter(r -> r instanceof GutsRecord).count();
+ assertNotEquals(2, count);
+ assertEquals(1, count);
+ }
+
+ @Test
+ void testMisplacedMergedCellsRecords_bug45699() throws Exception {
+ try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex45698-22488.xls")) {
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFRow row = sheet.getRow(3);
+ HSSFCell cell = row.getCell(4);
+ assertNotNull(cell, "Identified bug 45699");
+ assertEquals("Informations", cell.getRichStringCellValue().getString());
+ }
+ }
+ /**
+ * In 3.1, setting margins between creating first row and first cell caused an exception.
+ */
+ @Test
+ void testSetMargins_bug45717() throws Exception {
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Vorschauliste");
+ HSSFRow row = sheet.createRow(0);
+
+ sheet.setMargin(HSSFSheet.LeftMargin, 0.3);
+ try {
+ row.createCell(0);
+ } catch (IllegalStateException e) {
+ if (e.getMessage().equals("Cannot create value records before row records exist")) {
+ fail("Identified bug 45717");
+ }
+ throw e;
+ } finally {
+ workbook.close();
+ }
+ }
+
+ /**
+ * Some apps seem to write files with missing DIMENSION records.
+ * Excel(2007) tolerates this, so POI should too.
+ */
+ @Test
+ void testMissingDims() {
+
+ int rowIx = 5;
+ int colIx = 6;
+ NumberRecord nr = new NumberRecord();
+ nr.setRow(rowIx);
+ nr.setColumn((short) colIx);
+ nr.setValue(3.0);
+
+ List<org.apache.poi.hssf.record.Record> inRecs = new ArrayList<>();
+ inRecs.add(BOFRecord.createSheetBOF());
+ inRecs.add(new RowRecord(rowIx));
+ inRecs.add(nr);
+ inRecs.add(createWindow2Record());
+ inRecs.add(EOFRecord.instance);
+ InternalSheet sheet = createSheet(inRecs);
+
+ List<org.apache.poi.hssf.record.Record> outRecs = new ArrayList<>();
+ sheet.visitContainedRecords(outRecs::add, rowIx);
+ assertEquals(8, outRecs.size());
+ DimensionsRecord dims = (DimensionsRecord) outRecs.get(5);
+ assertEquals(rowIx, dims.getFirstRow());
+ assertEquals(rowIx, dims.getLastRow());
+ assertEquals(colIx, dims.getFirstCol());
+ assertEquals(colIx, dims.getLastCol());
+ }
+
+ /**
+ * Prior to the fix for bug 46547, shifting formulas would have the side-effect
+ * of creating a {@link ConditionalFormattingTable}. There was no impairment to
+ * functionality since empty record aggregates are equivalent to missing record
+ * aggregates. However, since this unnecessary creation helped expose bug 46547b,
+ * and since there is a slight performance hit the fix was made to avoid it.
+ */
+ @Test
+ void testShiftFormulasAddCondFormat_bug46547() {
+ // Create a sheet with data validity (similar to bugzilla attachment id=23131).
+ InternalSheet sheet = InternalSheet.createSheet();
+
+ List<RecordBase> sheetRecs = sheet.getRecords();
+ assertEquals(23, sheetRecs.size());
+
+ FormulaShifter shifter = FormulaShifter.createForRowShift(0, "", 0, 0, 1, SpreadsheetVersion.EXCEL97);
+ sheet.updateFormulasAfterCellShift(shifter, 0);
+ assertFalse(sheetRecs.size() == 24 && sheetRecs.get(22) instanceof ConditionalFormattingTable);
+ assertEquals(23, sheetRecs.size());
+ }
+ /**
+ * Bug 46547 happened when attempting to add conditional formatting to a sheet
+ * which already had data validity constraints.
+ */
+ @Test
+ void testAddCondFormatAfterDataValidation_bug46547() {
+ // Create a sheet with data validity (similar to bugzilla attachment id=23131).
+ InternalSheet sheet = InternalSheet.createSheet();
+ sheet.getOrCreateDataValidityTable();
+
+ // attempt to add conditional formatting
+ ConditionalFormattingTable cft = sheet.getConditionalFormattingTable();
+ assertNotNull(cft);
+ }
+
+ @Test
+ void testCloneMulBlank_bug46776() {
+ org.apache.poi.hssf.record.Record[] recs = {
+ InternalSheet.createBOF(),
+ new DimensionsRecord(),
+ new RowRecord(1),
+ new MulBlankRecord(1, 3, new short[] { 0x0F, 0x0F, 0x0F, } ),
+ new RowRecord(2),
+ createWindow2Record(),
+ EOFRecord.instance,
+ };
+
+ InternalSheet sheet = createSheet(Arrays.asList(recs));
+
+ InternalSheet sheet2 = sheet.cloneSheet();
+
+ List<org.apache.poi.hssf.record.Record> clonedRecs = new ArrayList<>();
+ sheet2.visitContainedRecords(clonedRecs::add, 0);
+ // +2 for INDEX and DBCELL
+ assertEquals(recs.length+2, clonedRecs.size());
+ }
@Test
void testCreateAggregate() {
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheetAdditional.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheetAdditional.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheetAdditional.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestSheetAdditional.java Sat May 22 20:56:44 2021
@@ -6,7 +6,7 @@
(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
+ 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,
@@ -24,47 +24,47 @@ import org.apache.poi.hssf.record.Column
import org.junit.jupiter.api.Test;
final class TestSheetAdditional {
- @Test
- void testGetCellWidth() {
- InternalSheet sheet = InternalSheet.createSheet();
- ColumnInfoRecord nci = new ColumnInfoRecord();
-
- // Prepare test model
- nci.setFirstColumn(5);
- nci.setLastColumn(10);
- nci.setColumnWidth(100);
-
-
- sheet._columnInfos.insertColumn(nci);
-
- assertEquals(100,sheet.getColumnWidth(5));
- assertEquals(100,sheet.getColumnWidth(6));
- assertEquals(100,sheet.getColumnWidth(7));
- assertEquals(100,sheet.getColumnWidth(8));
- assertEquals(100,sheet.getColumnWidth(9));
- assertEquals(100,sheet.getColumnWidth(10));
-
- sheet.setColumnWidth(6,200);
-
- assertEquals(100,sheet.getColumnWidth(5));
- assertEquals(200,sheet.getColumnWidth(6));
- assertEquals(100,sheet.getColumnWidth(7));
- assertEquals(100,sheet.getColumnWidth(8));
- assertEquals(100,sheet.getColumnWidth(9));
- assertEquals(100,sheet.getColumnWidth(10));
- }
-
- @Test
- void testMaxColumnWidth() {
- InternalSheet sheet = InternalSheet.createSheet();
- // the limit
- sheet.setColumnWidth(0, 255*256);
-
- // over the limit
- IllegalArgumentException ex = assertThrows(
- IllegalArgumentException.class,
- () -> sheet.setColumnWidth(0, 256*256)
- );
- assertEquals("The maximum column width for an individual cell is 255 characters.", ex.getMessage());
- }
+ @Test
+ void testGetCellWidth() {
+ InternalSheet sheet = InternalSheet.createSheet();
+ ColumnInfoRecord nci = new ColumnInfoRecord();
+
+ // Prepare test model
+ nci.setFirstColumn(5);
+ nci.setLastColumn(10);
+ nci.setColumnWidth(100);
+
+
+ sheet._columnInfos.insertColumn(nci);
+
+ assertEquals(100,sheet.getColumnWidth(5));
+ assertEquals(100,sheet.getColumnWidth(6));
+ assertEquals(100,sheet.getColumnWidth(7));
+ assertEquals(100,sheet.getColumnWidth(8));
+ assertEquals(100,sheet.getColumnWidth(9));
+ assertEquals(100,sheet.getColumnWidth(10));
+
+ sheet.setColumnWidth(6,200);
+
+ assertEquals(100,sheet.getColumnWidth(5));
+ assertEquals(200,sheet.getColumnWidth(6));
+ assertEquals(100,sheet.getColumnWidth(7));
+ assertEquals(100,sheet.getColumnWidth(8));
+ assertEquals(100,sheet.getColumnWidth(9));
+ assertEquals(100,sheet.getColumnWidth(10));
+ }
+
+ @Test
+ void testMaxColumnWidth() {
+ InternalSheet sheet = InternalSheet.createSheet();
+ // the limit
+ sheet.setColumnWidth(0, 255*256);
+
+ // over the limit
+ IllegalArgumentException ex = assertThrows(
+ IllegalArgumentException.class,
+ () -> sheet.setColumnWidth(0, 256*256)
+ );
+ assertEquals("The maximum column width for an individual cell is 255 characters.", ex.getMessage());
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestWorkbook.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestWorkbook.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestWorkbook.java Sat May 22 20:56:44 2021
@@ -45,61 +45,61 @@ final class TestWorkbook {
@Test
void testFontStuff() throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
- InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb);
+ InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb);
- assertEquals(4, wb.getNumberOfFontRecords());
- assertEquals(68, wb.getRecords().size());
+ assertEquals(4, wb.getNumberOfFontRecords());
+ assertEquals(68, wb.getRecords().size());
- FontRecord f1 = wb.getFontRecordAt(0);
- FontRecord f4 = wb.getFontRecordAt(3);
+ FontRecord f1 = wb.getFontRecordAt(0);
+ FontRecord f4 = wb.getFontRecordAt(3);
- assertEquals(0, wb.getFontIndex(f1));
- assertEquals(3, wb.getFontIndex(f4));
-
- assertEquals(f1, wb.getFontRecordAt(0));
- assertEquals(f4, wb.getFontRecordAt(3));
-
- // There is no 4! new ones go in at 5
-
- FontRecord n = wb.createNewFont();
- assertEquals(69, wb.getRecords().size());
- assertEquals(5, wb.getNumberOfFontRecords());
- assertEquals(5, wb.getFontIndex(n));
- assertEquals(n, wb.getFontRecordAt(5));
-
- // And another
- FontRecord n6 = wb.createNewFont();
- assertEquals(70, wb.getRecords().size());
- assertEquals(6, wb.getNumberOfFontRecords());
- assertEquals(6, wb.getFontIndex(n6));
- assertEquals(n6, wb.getFontRecordAt(6));
-
-
- // Now remove the one formerly at 5
- assertEquals(70, wb.getRecords().size());
- wb.removeFontRecord(n);
-
- // Check that 6 has gone to 5
- assertEquals(69, wb.getRecords().size());
- assertEquals(5, wb.getNumberOfFontRecords());
- assertEquals(5, wb.getFontIndex(n6));
- assertEquals(n6, wb.getFontRecordAt(5));
-
- // Check that the earlier ones are unchanged
- assertEquals(0, wb.getFontIndex(f1));
- assertEquals(3, wb.getFontIndex(f4));
- assertEquals(f1, wb.getFontRecordAt(0));
- assertEquals(f4, wb.getFontRecordAt(3));
-
- // Finally, add another one
- FontRecord n7 = wb.createNewFont();
- assertEquals(70, wb.getRecords().size());
- assertEquals(6, wb.getNumberOfFontRecords());
- assertEquals(6, wb.getFontIndex(n7));
- assertEquals(n7, wb.getFontRecordAt(6));
+ assertEquals(0, wb.getFontIndex(f1));
+ assertEquals(3, wb.getFontIndex(f4));
+
+ assertEquals(f1, wb.getFontRecordAt(0));
+ assertEquals(f4, wb.getFontRecordAt(3));
+
+ // There is no 4! new ones go in at 5
+
+ FontRecord n = wb.createNewFont();
+ assertEquals(69, wb.getRecords().size());
+ assertEquals(5, wb.getNumberOfFontRecords());
+ assertEquals(5, wb.getFontIndex(n));
+ assertEquals(n, wb.getFontRecordAt(5));
+
+ // And another
+ FontRecord n6 = wb.createNewFont();
+ assertEquals(70, wb.getRecords().size());
+ assertEquals(6, wb.getNumberOfFontRecords());
+ assertEquals(6, wb.getFontIndex(n6));
+ assertEquals(n6, wb.getFontRecordAt(6));
+
+
+ // Now remove the one formerly at 5
+ assertEquals(70, wb.getRecords().size());
+ wb.removeFontRecord(n);
+
+ // Check that 6 has gone to 5
+ assertEquals(69, wb.getRecords().size());
+ assertEquals(5, wb.getNumberOfFontRecords());
+ assertEquals(5, wb.getFontIndex(n6));
+ assertEquals(n6, wb.getFontRecordAt(5));
+
+ // Check that the earlier ones are unchanged
+ assertEquals(0, wb.getFontIndex(f1));
+ assertEquals(3, wb.getFontIndex(f4));
+ assertEquals(f1, wb.getFontRecordAt(0));
+ assertEquals(f4, wb.getFontRecordAt(3));
+
+ // Finally, add another one
+ FontRecord n7 = wb.createNewFont();
+ assertEquals(70, wb.getRecords().size());
+ assertEquals(6, wb.getNumberOfFontRecords());
+ assertEquals(6, wb.getFontIndex(n7));
+ assertEquals(n7, wb.getFontRecordAt(6));
- hwb.close();
- }
+ hwb.close();
+ }
@Test
void testAddNameX() throws IOException {
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoolErrRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoolErrRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoolErrRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoolErrRecord.java Sat May 22 20:56:44 2021
@@ -6,7 +6,7 @@
(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
+ 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,
@@ -30,51 +30,51 @@ import org.junit.jupiter.api.Test;
*/
final class TestBoolErrRecord {
- @Test
- void testError() {
- byte[] data = HexRead.readFromString(
- "00 00 00 00 0F 00 " + // row, col, xfIndex
- "07 01 " // #DIV/0!, isError
- );
-
- RecordInputStream in = TestcaseRecordInputStream.create(BoolErrRecord.sid, data);
- BoolErrRecord ber = new BoolErrRecord(in);
- assertTrue(ber.isError());
- assertEquals(7, ber.getErrorValue());
-
- TestcaseRecordInputStream.confirmRecordEncoding(BoolErrRecord.sid, data, ber.serialize());
- }
-
- /**
- * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1)
- * writes the <i>value</i> field of BOOLERR records as 2 bytes instead of 1.<br>
- * Coincidentally, the extra byte written is zero, which is exactly the value
- * required by the <i>isError</i> field. This probably why Excel seems to have
- * no problem. OOO does not have the same bug for error values (which wouldn't
- * work by the same coincidence).
- */
- @Test
- void testOooBadFormat_bug47479() {
- byte[] data = HexRead.readFromString(
- "05 02 09 00 " + // sid, size
- "00 00 00 00 0F 00 " + // row, col, xfIndex
- "01 00 00 " // extra 00 byte here
- );
-
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- BoolErrRecord ber = new BoolErrRecord(in);
- boolean hasMore = in.hasNextRecord();
- assertFalse(hasMore);
- assertTrue(ber.isBoolean());
+ @Test
+ void testError() {
+ byte[] data = HexRead.readFromString(
+ "00 00 00 00 0F 00 " + // row, col, xfIndex
+ "07 01 " // #DIV/0!, isError
+ );
+
+ RecordInputStream in = TestcaseRecordInputStream.create(BoolErrRecord.sid, data);
+ BoolErrRecord ber = new BoolErrRecord(in);
+ assertTrue(ber.isError());
+ assertEquals(7, ber.getErrorValue());
+
+ TestcaseRecordInputStream.confirmRecordEncoding(BoolErrRecord.sid, data, ber.serialize());
+ }
+
+ /**
+ * Bugzilla 47479 was due to an apparent error in OOO which (as of version 3.0.1)
+ * writes the <i>value</i> field of BOOLERR records as 2 bytes instead of 1.<br>
+ * Coincidentally, the extra byte written is zero, which is exactly the value
+ * required by the <i>isError</i> field. This probably why Excel seems to have
+ * no problem. OOO does not have the same bug for error values (which wouldn't
+ * work by the same coincidence).
+ */
+ @Test
+ void testOooBadFormat_bug47479() {
+ byte[] data = HexRead.readFromString(
+ "05 02 09 00 " + // sid, size
+ "00 00 00 00 0F 00 " + // row, col, xfIndex
+ "01 00 00 " // extra 00 byte here
+ );
+
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ BoolErrRecord ber = new BoolErrRecord(in);
+ boolean hasMore = in.hasNextRecord();
+ assertFalse(hasMore);
+ assertTrue(ber.isBoolean());
assertTrue(ber.getBooleanValue());
- // Check that the record re-serializes correctly
- byte[] outData = ber.serialize();
- byte[] expData = HexRead.readFromString(
- "05 02 08 00 " +
- "00 00 00 00 0F 00 " +
- "01 00 " // normal number of data bytes
- );
- assertArrayEquals(expData, outData);
- }
+ // Check that the record re-serializes correctly
+ byte[] outData = ber.serialize();
+ byte[] expData = HexRead.readFromString(
+ "05 02 08 00 " +
+ "00 00 00 00 0F 00 " +
+ "01 00 " // normal number of data bytes
+ );
+ assertArrayEquals(expData, outData);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoundSheetRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoundSheetRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoundSheetRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestBoundSheetRecord.java Sat May 22 20:56:44 2021
@@ -34,90 +34,90 @@ import org.junit.jupiter.api.Test;
*/
final class TestBoundSheetRecord {
- @Test
- void testRecordLength() {
- BoundSheetRecord record = new BoundSheetRecord("Sheet1");
- assertEquals(18, record.getRecordSize());
- }
-
- @Test
- void testWideRecordLength() {
- BoundSheetRecord record = new BoundSheetRecord("Sheet\u20ac");
- assertEquals(24, record.getRecordSize());
- }
-
- @Test
- void testName() {
- BoundSheetRecord record = new BoundSheetRecord("1234567890223456789032345678904");
- assertThrows(IllegalArgumentException.class, () -> record.setSheetname("s//*s"));
- }
-
- @Test
- void testDeserializeUnicode() {
-
- byte[] data = HexRead.readFromString(""
- + "85 00 1A 00" // sid, length
- + "3C 09 00 00" // bof
- + "00 00"// flags
- + "09 01" // str-len. unicode flag
- // string data
- + "21 04 42 04 40 04"
- + "30 04 3D 04 38 04"
- + "47 04 3A 04 30 04"
- );
-
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- BoundSheetRecord bsr = new BoundSheetRecord(in);
- // sheet name is unicode Russian for 'minor page'
- assertEquals("\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430", bsr.getSheetname());
-
- byte[] data2 = bsr.serialize();
- assertArrayEquals(data, data2);
- }
-
- @Test
- void testOrdering() {
- BoundSheetRecord bs1 = new BoundSheetRecord("SheetB");
- BoundSheetRecord bs2 = new BoundSheetRecord("SheetC");
- BoundSheetRecord bs3 = new BoundSheetRecord("SheetA");
- bs1.setPositionOfBof(11);
- bs2.setPositionOfBof(33);
- bs3.setPositionOfBof(22);
-
- List<BoundSheetRecord> l = new ArrayList<>();
- l.add(bs1);
- l.add(bs2);
- l.add(bs3);
-
- BoundSheetRecord[] r = BoundSheetRecord.orderByBofPosition(l);
- assertEquals(3, r.length);
- assertEquals(bs1, r[0]);
- assertEquals(bs3, r[1]);
- assertEquals(bs2, r[2]);
- }
-
- @Test
- void testValidNames() {
- assertTrue(isValid("Sheet1"));
- assertTrue(isValid("O'Brien's sales"));
- assertTrue(isValid(" data # "));
- assertTrue(isValid("data $1.00"));
-
- assertFalse(isValid("data?"));
- assertFalse(isValid("abc/def"));
- assertFalse(isValid("data[0]"));
- assertFalse(isValid("data*"));
- assertFalse(isValid("abc\\def"));
- assertFalse(isValid("'data"));
- assertFalse(isValid("data'"));
- }
-
- private static boolean isValid(String sheetName) {
- try {
- new BoundSheetRecord(sheetName);
- return true;
- } catch (IllegalArgumentException e) {
- return false;
- }
- }
+ @Test
+ void testRecordLength() {
+ BoundSheetRecord record = new BoundSheetRecord("Sheet1");
+ assertEquals(18, record.getRecordSize());
+ }
+
+ @Test
+ void testWideRecordLength() {
+ BoundSheetRecord record = new BoundSheetRecord("Sheet\u20ac");
+ assertEquals(24, record.getRecordSize());
+ }
+
+ @Test
+ void testName() {
+ BoundSheetRecord record = new BoundSheetRecord("1234567890223456789032345678904");
+ assertThrows(IllegalArgumentException.class, () -> record.setSheetname("s//*s"));
+ }
+
+ @Test
+ void testDeserializeUnicode() {
+
+ byte[] data = HexRead.readFromString(""
+ + "85 00 1A 00" // sid, length
+ + "3C 09 00 00" // bof
+ + "00 00"// flags
+ + "09 01" // str-len. unicode flag
+ // string data
+ + "21 04 42 04 40 04"
+ + "30 04 3D 04 38 04"
+ + "47 04 3A 04 30 04"
+ );
+
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ BoundSheetRecord bsr = new BoundSheetRecord(in);
+ // sheet name is unicode Russian for 'minor page'
+ assertEquals("\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430", bsr.getSheetname());
+
+ byte[] data2 = bsr.serialize();
+ assertArrayEquals(data, data2);
+ }
+
+ @Test
+ void testOrdering() {
+ BoundSheetRecord bs1 = new BoundSheetRecord("SheetB");
+ BoundSheetRecord bs2 = new BoundSheetRecord("SheetC");
+ BoundSheetRecord bs3 = new BoundSheetRecord("SheetA");
+ bs1.setPositionOfBof(11);
+ bs2.setPositionOfBof(33);
+ bs3.setPositionOfBof(22);
+
+ List<BoundSheetRecord> l = new ArrayList<>();
+ l.add(bs1);
+ l.add(bs2);
+ l.add(bs3);
+
+ BoundSheetRecord[] r = BoundSheetRecord.orderByBofPosition(l);
+ assertEquals(3, r.length);
+ assertEquals(bs1, r[0]);
+ assertEquals(bs3, r[1]);
+ assertEquals(bs2, r[2]);
+ }
+
+ @Test
+ void testValidNames() {
+ assertTrue(isValid("Sheet1"));
+ assertTrue(isValid("O'Brien's sales"));
+ assertTrue(isValid(" data # "));
+ assertTrue(isValid("data $1.00"));
+
+ assertFalse(isValid("data?"));
+ assertFalse(isValid("abc/def"));
+ assertFalse(isValid("data[0]"));
+ assertFalse(isValid("data*"));
+ assertFalse(isValid("abc\\def"));
+ assertFalse(isValid("'data"));
+ assertFalse(isValid("data'"));
+ }
+
+ private static boolean isValid(String sheetName) {
+ try {
+ new BoundSheetRecord(sheetName);
+ return true;
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCFHeaderRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCFHeaderRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCFHeaderRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCFHeaderRecord.java Sat May 22 20:56:44 2021
@@ -30,40 +30,40 @@ import org.junit.jupiter.api.Test;
* and {@link CFHeader12Record} classes works correctly.
*/
final class TestCFHeaderRecord {
- @Test
- void testCreateCFHeaderRecord () {
- CFHeaderRecord record = new CFHeaderRecord();
- CellRangeAddress[] ranges = {
- new CellRangeAddress(0,0xFFFF,5,5),
- new CellRangeAddress(0,0xFFFF,6,6),
- new CellRangeAddress(0,1,0,1),
- new CellRangeAddress(0,1,2,3),
- new CellRangeAddress(2,3,0,1),
- new CellRangeAddress(2,3,2,3),
- };
- record.setCellRanges(ranges);
- ranges = record.getCellRanges();
- assertEquals(6,ranges.length);
- CellRangeAddress enclosingCellRange = record.getEnclosingCellRange();
- assertEquals(0, enclosingCellRange.getFirstRow());
- assertEquals(65535, enclosingCellRange.getLastRow());
- assertEquals(0, enclosingCellRange.getFirstColumn());
- assertEquals(6, enclosingCellRange.getLastColumn());
+ @Test
+ void testCreateCFHeaderRecord () {
+ CFHeaderRecord record = new CFHeaderRecord();
+ CellRangeAddress[] ranges = {
+ new CellRangeAddress(0,0xFFFF,5,5),
+ new CellRangeAddress(0,0xFFFF,6,6),
+ new CellRangeAddress(0,1,0,1),
+ new CellRangeAddress(0,1,2,3),
+ new CellRangeAddress(2,3,0,1),
+ new CellRangeAddress(2,3,2,3),
+ };
+ record.setCellRanges(ranges);
+ ranges = record.getCellRanges();
+ assertEquals(6,ranges.length);
+ CellRangeAddress enclosingCellRange = record.getEnclosingCellRange();
+ assertEquals(0, enclosingCellRange.getFirstRow());
+ assertEquals(65535, enclosingCellRange.getLastRow());
+ assertEquals(0, enclosingCellRange.getFirstColumn());
+ assertEquals(6, enclosingCellRange.getLastColumn());
assertFalse(record.getNeedRecalculation());
- assertEquals(0, record.getID());
+ assertEquals(0, record.getID());
- record.setNeedRecalculation(true);
+ record.setNeedRecalculation(true);
assertTrue(record.getNeedRecalculation());
assertEquals(0, record.getID());
record.setID(7);
- record.setNeedRecalculation(false);
+ record.setNeedRecalculation(false);
assertFalse(record.getNeedRecalculation());
assertEquals(7, record.getID());
- }
+ }
- @Test
+ @Test
void testCreateCFHeader12Record () {
CFHeader12Record record = new CFHeader12Record();
CellRangeAddress[] ranges = {
@@ -96,107 +96,107 @@ final class TestCFHeaderRecord {
assertEquals(7, record.getID());
}
- @Test
- void testSerialization() {
- byte[] recordData =
- {
- (byte)0x03, (byte)0x00,
- (byte)0x01, (byte)0x00,
-
- (byte)0x00, (byte)0x00,
- (byte)0x03, (byte)0x00,
- (byte)0x00, (byte)0x00,
- (byte)0x03, (byte)0x00,
-
- (byte)0x04, (byte)0x00, // nRegions
-
- (byte)0x00, (byte)0x00,
- (byte)0x01, (byte)0x00,
- (byte)0x00, (byte)0x00,
- (byte)0x01, (byte)0x00,
-
- (byte)0x00, (byte)0x00,
- (byte)0x01, (byte)0x00,
- (byte)0x02, (byte)0x00,
- (byte)0x03, (byte)0x00,
-
- (byte)0x02, (byte)0x00,
- (byte)0x03, (byte)0x00,
- (byte)0x00, (byte)0x00,
- (byte)0x01, (byte)0x00,
-
- (byte)0x02, (byte)0x00,
- (byte)0x03, (byte)0x00,
- (byte)0x02, (byte)0x00,
- (byte)0x03, (byte)0x00,
- };
-
- CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
-
- assertEquals(3, record.getNumberOfConditionalFormats(), "#CFRULES");
- assertTrue(record.getNeedRecalculation());
- confirm(record.getEnclosingCellRange(), 0, 3, 0, 3);
- CellRangeAddress[] ranges = record.getCellRanges();
- assertEquals(4, ranges.length);
- confirm(ranges[0], 0, 1, 0, 1);
- confirm(ranges[1], 0, 1, 2, 3);
- confirm(ranges[2], 2, 3, 0, 1);
- confirm(ranges[3], 2, 3, 2, 3);
- assertEquals(recordData.length+4, record.getRecordSize());
-
- byte[] output = record.serialize();
- confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
- }
-
- @Test
- void testExtremeRows() {
- byte[] recordData = {
- (byte)0x13, (byte)0x00, // nFormats
- (byte)0x00, (byte)0x00,
-
- (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0xFF,
- (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00,
-
- (byte)0x03, (byte)0x00, // nRegions
-
- (byte)0x40, (byte)0x9C,
- (byte)0x50, (byte)0xC3,
- (byte)0x02, (byte)0x00,
- (byte)0x02, (byte)0x00,
-
- (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0xFF,
- (byte)0x05, (byte)0x00,
- (byte)0x05, (byte)0x00,
-
- (byte)0x07, (byte)0x00,
- (byte)0x07, (byte)0x00,
- (byte)0x00, (byte)0x00,
- (byte)0xFF, (byte)0x00,
- };
-
- // bug 44739b - invalid cell range (-25536, 2, -15536, 2)
- CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
-
- assertEquals(19, record.getNumberOfConditionalFormats(), "#CFRULES");
- assertFalse(record.getNeedRecalculation());
- confirm(record.getEnclosingCellRange(), 0, 65535, 0, 255);
- CellRangeAddress[] ranges = record.getCellRanges();
- assertEquals(3, ranges.length);
- confirm(ranges[0], 40000, 50000, 2, 2);
- confirm(ranges[1], 0, 65535, 5, 5);
- confirm(ranges[2], 7, 7, 0, 255);
-
- byte[] output = record.serialize();
- confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
- }
-
- private static void confirm(CellRangeAddress cr, int expFirstRow, int expLastRow, int expFirstCol, int expLastColumn) {
- assertEquals(expFirstRow, cr.getFirstRow(), "first row");
- assertEquals(expLastRow, cr.getLastRow(), "last row");
- assertEquals(expFirstCol, cr.getFirstColumn(), "first column");
- assertEquals(expLastColumn, cr.getLastColumn(), "last column");
- }
+ @Test
+ void testSerialization() {
+ byte[] recordData =
+ {
+ (byte)0x03, (byte)0x00,
+ (byte)0x01, (byte)0x00,
+
+ (byte)0x00, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+ (byte)0x00, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+
+ (byte)0x04, (byte)0x00, // nRegions
+
+ (byte)0x00, (byte)0x00,
+ (byte)0x01, (byte)0x00,
+ (byte)0x00, (byte)0x00,
+ (byte)0x01, (byte)0x00,
+
+ (byte)0x00, (byte)0x00,
+ (byte)0x01, (byte)0x00,
+ (byte)0x02, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+
+ (byte)0x02, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+ (byte)0x00, (byte)0x00,
+ (byte)0x01, (byte)0x00,
+
+ (byte)0x02, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+ (byte)0x02, (byte)0x00,
+ (byte)0x03, (byte)0x00,
+ };
+
+ CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
+
+ assertEquals(3, record.getNumberOfConditionalFormats(), "#CFRULES");
+ assertTrue(record.getNeedRecalculation());
+ confirm(record.getEnclosingCellRange(), 0, 3, 0, 3);
+ CellRangeAddress[] ranges = record.getCellRanges();
+ assertEquals(4, ranges.length);
+ confirm(ranges[0], 0, 1, 0, 1);
+ confirm(ranges[1], 0, 1, 2, 3);
+ confirm(ranges[2], 2, 3, 0, 1);
+ confirm(ranges[3], 2, 3, 2, 3);
+ assertEquals(recordData.length+4, record.getRecordSize());
+
+ byte[] output = record.serialize();
+ confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
+ }
+
+ @Test
+ void testExtremeRows() {
+ byte[] recordData = {
+ (byte)0x13, (byte)0x00, // nFormats
+ (byte)0x00, (byte)0x00,
+
+ (byte)0x00, (byte)0x00,
+ (byte)0xFF, (byte)0xFF,
+ (byte)0x00, (byte)0x00,
+ (byte)0xFF, (byte)0x00,
+
+ (byte)0x03, (byte)0x00, // nRegions
+
+ (byte)0x40, (byte)0x9C,
+ (byte)0x50, (byte)0xC3,
+ (byte)0x02, (byte)0x00,
+ (byte)0x02, (byte)0x00,
+
+ (byte)0x00, (byte)0x00,
+ (byte)0xFF, (byte)0xFF,
+ (byte)0x05, (byte)0x00,
+ (byte)0x05, (byte)0x00,
+
+ (byte)0x07, (byte)0x00,
+ (byte)0x07, (byte)0x00,
+ (byte)0x00, (byte)0x00,
+ (byte)0xFF, (byte)0x00,
+ };
+
+ // bug 44739b - invalid cell range (-25536, 2, -15536, 2)
+ CFHeaderRecord record = new CFHeaderRecord(TestcaseRecordInputStream.create(CFHeaderRecord.sid, recordData));
+
+ assertEquals(19, record.getNumberOfConditionalFormats(), "#CFRULES");
+ assertFalse(record.getNeedRecalculation());
+ confirm(record.getEnclosingCellRange(), 0, 65535, 0, 255);
+ CellRangeAddress[] ranges = record.getCellRanges();
+ assertEquals(3, ranges.length);
+ confirm(ranges[0], 40000, 50000, 2, 2);
+ confirm(ranges[1], 0, 65535, 5, 5);
+ confirm(ranges[2], 7, 7, 0, 255);
+
+ byte[] output = record.serialize();
+ confirmRecordEncoding(CFHeaderRecord.sid, recordData, output);
+ }
+
+ private static void confirm(CellRangeAddress cr, int expFirstRow, int expLastRow, int expFirstCol, int expLastColumn) {
+ assertEquals(expFirstRow, cr.getFirstRow(), "first row");
+ assertEquals(expLastRow, cr.getLastRow(), "last row");
+ assertEquals(expFirstCol, cr.getFirstColumn(), "first column");
+ assertEquals(expLastColumn, cr.getLastColumn(), "last column");
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestColumnInfoRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestColumnInfoRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestColumnInfoRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestColumnInfoRecord.java Sat May 22 20:56:44 2021
@@ -29,54 +29,54 @@ import org.junit.jupiter.api.Test;
*/
final class TestColumnInfoRecord {
- @Test
- void testBasic() {
- byte[] data = HexRead.readFromString("7D 00 0C 00 14 00 9B 00 C7 19 0F 00 01 13 00 00");
-
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- ColumnInfoRecord cir = new ColumnInfoRecord(in);
- assertEquals(0, in.remaining());
-
- assertEquals(20, cir.getFirstColumn());
- assertEquals(155, cir.getLastColumn());
- assertEquals(6599, cir.getColumnWidth());
- assertEquals(15, cir.getXFIndex());
+ @Test
+ void testBasic() {
+ byte[] data = HexRead.readFromString("7D 00 0C 00 14 00 9B 00 C7 19 0F 00 01 13 00 00");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ ColumnInfoRecord cir = new ColumnInfoRecord(in);
+ assertEquals(0, in.remaining());
+
+ assertEquals(20, cir.getFirstColumn());
+ assertEquals(155, cir.getLastColumn());
+ assertEquals(6599, cir.getColumnWidth());
+ assertEquals(15, cir.getXFIndex());
assertTrue(cir.getHidden());
- assertEquals(3, cir.getOutlineLevel());
+ assertEquals(3, cir.getOutlineLevel());
assertTrue(cir.getCollapsed());
- assertArrayEquals(data, cir.serialize());
- }
+ assertArrayEquals(data, cir.serialize());
+ }
- /**
- * Some applications skip the last reserved field when writing {@link ColumnInfoRecord}s
- * The attached file was apparently created by "SoftArtisans OfficeWriter for Excel".
- * Excel reads that file OK and assumes zero for the value of the reserved field.
- */
- @Test
- void testZeroResevedBytes_bug48332() {
- // Taken from bugzilla attachment 24661 (offset 0x1E73)
- byte[] inpData = HexRead.readFromString("7D 00 0A 00 00 00 00 00 D5 19 0F 00 02 00");
- byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 D5 19 0F 00 02 00 00 00");
-
- RecordInputStream in = TestcaseRecordInputStream.create(inpData);
- // bug 48332 - Unusual record size remaining=(0)
- ColumnInfoRecord cir = new ColumnInfoRecord(in);
- assertEquals(0, in.remaining());
- assertArrayEquals(outData, cir.serialize());
- }
-
- /**
- * Some sample files have just one reserved byte (field 6):
- * OddStyleRecord.xls, NoGutsRecords.xls, WORKBOOK_in_capitals.xls
- * but this seems to cause no problem to Excel
- */
- @Test
- void testOneReservedByte() {
- byte[] inpData = HexRead.readFromString("7D 00 0B 00 00 00 00 00 24 02 0F 00 00 00 01");
- byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 24 02 0F 00 00 00 01 00");
- RecordInputStream in = TestcaseRecordInputStream.create(inpData);
- ColumnInfoRecord cir = new ColumnInfoRecord(in);
- assertEquals(0, in.remaining());
- assertArrayEquals(outData, cir.serialize());
- }
+ /**
+ * Some applications skip the last reserved field when writing {@link ColumnInfoRecord}s
+ * The attached file was apparently created by "SoftArtisans OfficeWriter for Excel".
+ * Excel reads that file OK and assumes zero for the value of the reserved field.
+ */
+ @Test
+ void testZeroResevedBytes_bug48332() {
+ // Taken from bugzilla attachment 24661 (offset 0x1E73)
+ byte[] inpData = HexRead.readFromString("7D 00 0A 00 00 00 00 00 D5 19 0F 00 02 00");
+ byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 D5 19 0F 00 02 00 00 00");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(inpData);
+ // bug 48332 - Unusual record size remaining=(0)
+ ColumnInfoRecord cir = new ColumnInfoRecord(in);
+ assertEquals(0, in.remaining());
+ assertArrayEquals(outData, cir.serialize());
+ }
+
+ /**
+ * Some sample files have just one reserved byte (field 6):
+ * OddStyleRecord.xls, NoGutsRecords.xls, WORKBOOK_in_capitals.xls
+ * but this seems to cause no problem to Excel
+ */
+ @Test
+ void testOneReservedByte() {
+ byte[] inpData = HexRead.readFromString("7D 00 0B 00 00 00 00 00 24 02 0F 00 00 00 01");
+ byte[] outData = HexRead.readFromString("7D 00 0C 00 00 00 00 00 24 02 0F 00 00 00 01 00");
+ RecordInputStream in = TestcaseRecordInputStream.create(inpData);
+ ColumnInfoRecord cir = new ColumnInfoRecord(in);
+ assertEquals(0, in.remaining());
+ assertArrayEquals(outData, cir.serialize());
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java Sat May 22 20:56:44 2021
@@ -31,48 +31,48 @@ import org.junit.jupiter.api.Test;
* Excel file.
*/
final class TestCommonObjectDataSubRecord {
- byte[] data = new byte[] {
- (byte)0x12,(byte)0x00,(byte)0x01,(byte)0x00,
- (byte)0x01,(byte)0x00,(byte)0x11,(byte)0x60,
- (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
- (byte)0x00,(byte)0x0D,(byte)0x26,(byte)0x01,
- (byte)0x00,(byte)0x00,
- };
+ byte[] data = new byte[] {
+ (byte)0x12,(byte)0x00,(byte)0x01,(byte)0x00,
+ (byte)0x01,(byte)0x00,(byte)0x11,(byte)0x60,
+ (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,
+ (byte)0x00,(byte)0x0D,(byte)0x26,(byte)0x01,
+ (byte)0x00,(byte)0x00,
+ };
- @Test
- void testLoad() {
- CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createLittleEndian(data), data.length);
+ @Test
+ void testLoad() {
+ CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createLittleEndian(data), data.length);
- assertEquals( CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX, record.getObjectType());
- assertEquals((short) 1, record.getObjectId());
- assertEquals((short) 1, record.getOption());
+ assertEquals( CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX, record.getObjectType());
+ assertEquals((short) 1, record.getObjectId());
+ assertEquals((short) 1, record.getOption());
assertTrue(record.isLocked());
assertFalse(record.isPrintable());
assertFalse(record.isAutofill());
assertFalse(record.isAutoline());
- assertEquals(24593, record.getReserved1());
- assertEquals(218103808, record.getReserved2());
- assertEquals(294, record.getReserved3());
- assertEquals(18, record.getDataSize());
- }
+ assertEquals(24593, record.getReserved1());
+ assertEquals(218103808, record.getReserved2());
+ assertEquals(294, record.getReserved3());
+ assertEquals(18, record.getDataSize());
+ }
- @SuppressWarnings("squid:S2699")
- @Test
- void testStore() {
- CommonObjectDataSubRecord record = new CommonObjectDataSubRecord();
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testStore() {
+ CommonObjectDataSubRecord record = new CommonObjectDataSubRecord();
- record.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX);
- record.setObjectId( 1);
- record.setOption((short) 1);
- record.setLocked(true);
- record.setPrintable(false);
- record.setAutofill(false);
- record.setAutoline(false);
- record.setReserved1(24593);
- record.setReserved2(218103808);
- record.setReserved3(294);
+ record.setObjectType(CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX);
+ record.setObjectId( 1);
+ record.setOption((short) 1);
+ record.setLocked(true);
+ record.setPrintable(false);
+ record.setAutofill(false);
+ record.setAutoline(false);
+ record.setReserved1(24593);
+ record.setReserved2(218103808);
+ record.setReserved3(294);
- byte[] recordBytes = record.serialize();
- confirmRecordEncoding(CommonObjectDataSubRecord.sid, data, recordBytes);
- }
+ byte[] recordBytes = record.serialize();
+ confirmRecordEncoding(CommonObjectDataSubRecord.sid, data, recordBytes);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org