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 [33/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/record/cf/TestCellRange.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/cf/TestCellRange.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/cf/TestCellRange.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/cf/TestCellRange.java Sat May 22 20:56:44 2021
@@ -31,164 +31,164 @@ import org.junit.jupiter.api.Test;
* Tests CellRange operations.
*/
final class TestCellRange {
- private static final CellRangeAddress biggest = createCR( 0, -1, 0,-1);
- private static final CellRangeAddress tenthColumn = createCR( 0, -1,10,10);
- private static final CellRangeAddress tenthRow = createCR(10, 10, 0,-1);
- private static final CellRangeAddress box10x10 = createCR( 0, 10, 0,10);
- private static final CellRangeAddress box9x9 = createCR( 0, 9, 0, 9);
- private static final CellRangeAddress box10to20c = createCR( 0, 10,10,20);
- private static final CellRangeAddress oneCell = createCR(10, 10,10,10);
-
- private static final CellRangeAddress[] sampleRanges = {
- biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell,
- };
+ private static final CellRangeAddress biggest = createCR( 0, -1, 0,-1);
+ private static final CellRangeAddress tenthColumn = createCR( 0, -1,10,10);
+ private static final CellRangeAddress tenthRow = createCR(10, 10, 0,-1);
+ private static final CellRangeAddress box10x10 = createCR( 0, 10, 0,10);
+ private static final CellRangeAddress box9x9 = createCR( 0, 9, 0, 9);
+ private static final CellRangeAddress box10to20c = createCR( 0, 10,10,20);
+ private static final CellRangeAddress oneCell = createCR(10, 10,10,10);
+
+ private static final CellRangeAddress[] sampleRanges = {
+ biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell,
+ };
- /** cross-reference of {@code contains()} operations for sampleRanges against itself */
- private static final boolean [][] containsExpectedResults =
+ /** cross-reference of {@code contains()} operations for sampleRanges against itself */
+ private static final boolean [][] containsExpectedResults =
{
- // biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell
- /*biggest */ {true, true , true , true , true , true , true},
- /*tenthColumn*/ {false, true , false, false, false, false, true},
- /*tenthRow */ {false, false, true , false, false, false, true},
- /*box10x10 */ {false, false, false, true , true , false, true},
- /*box9x9 */ {false, false, false, false, true , false, false},
- /*box10to20c */ {false, false, false, false, false, true , true},
- /*oneCell */ {false, false, false, false, false, false, true},
+ // biggest, tenthColumn, tenthRow, box10x10, box9x9, box10to20c, oneCell
+ /*biggest */ {true, true , true , true , true , true , true},
+ /*tenthColumn*/ {false, true , false, false, false, false, true},
+ /*tenthRow */ {false, false, true , false, false, false, true},
+ /*box10x10 */ {false, false, false, true , true , false, true},
+ /*box9x9 */ {false, false, false, false, true , false, false},
+ /*box10to20c */ {false, false, false, false, false, true , true},
+ /*oneCell */ {false, false, false, false, false, false, true},
} ;
- /**
- * @param lastRow pass -1 for max row index
- * @param lastCol pass -1 for max col index
- */
- private static CellRangeAddress createCR(int firstRow, int lastRow, int firstCol, int lastCol) {
- // max row & max col limit as per BIFF8
- return new CellRangeAddress(
- firstRow,
- lastRow == -1 ? 0xFFFF : lastRow,
- firstCol,
- lastCol == -1 ? 0x00FF : lastCol);
- }
-
- @Test
- void testContainsMethod()
- {
- CellRangeAddress [] ranges = sampleRanges;
- for(int i=0; i!=ranges.length;i++)
- {
- for(int j=0; j!=ranges.length;j++)
- {
- boolean expectedResult = containsExpectedResults[i][j];
- assertEquals(expectedResult, CellRangeUtil.contains(ranges[i], ranges[j]), "("+i+","+j+"): ");
- }
- }
- }
-
- private static final CellRangeAddress col1 = createCR( 0, -1, 1,1);
- private static final CellRangeAddress col2 = createCR( 0, -1, 2,2);
- private static final CellRangeAddress row1 = createCR( 1, 1, 0,-1);
- private static final CellRangeAddress row2 = createCR( 2, 2, 0,-1);
-
- private static final CellRangeAddress box0 = createCR( 0, 2, 0,2);
- private static final CellRangeAddress box1 = createCR( 0, 1, 0,1);
- private static final CellRangeAddress box2 = createCR( 0, 1, 2,3);
- private static final CellRangeAddress box3 = createCR( 2, 3, 0,1);
- private static final CellRangeAddress box4 = createCR( 2, 3, 2,3);
- private static final CellRangeAddress box5 = createCR( 1, 3, 1,3);
-
- @Test
- void testHasSharedBorderMethod() {
- assertFalse(CellRangeUtil.hasExactSharedBorder(col1, col1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(col2, col2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(col1, col2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(col2, col1));
-
- assertFalse(CellRangeUtil.hasExactSharedBorder(row1, row1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(row2, row2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(row1, row2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(row2, row1));
-
- assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col2));
- assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(col2, row1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(row2, col1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(row2, col2));
- assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row2));
- assertFalse(CellRangeUtil.hasExactSharedBorder(col2, row2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(col2, col1));
-
- assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box1));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box3));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box4));
-
- assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box2));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box3));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box4));
-
- assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box1));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box2));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box3));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box4));
-
- assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box1));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box2));
- assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box3));
- assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box4));
- }
-
- @Test
- void testIntersectMethod() {
- assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box0, box5));
- assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box5, box0));
- assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box1, box4));
- assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box4, box1));
- assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box2, box3));
- assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box3, box2));
- assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(box0, box1));
- assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(box0, box0));
- assertEquals(CellRangeUtil.ENCLOSES, CellRangeUtil.intersect(box1, box0));
- assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthColumn, oneCell));
- assertEquals(CellRangeUtil.ENCLOSES, CellRangeUtil.intersect(oneCell, tenthColumn));
- assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(tenthColumn, tenthRow));
- assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(tenthRow, tenthColumn));
- assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthColumn, tenthColumn));
- assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthRow, tenthRow));
-
- // Bug 55380
- assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(
- CellRangeAddress.valueOf("C1:D2"), CellRangeAddress.valueOf("C2:C3")));
- }
-
- /**
- * Cell ranges like the following are valid
- * =$C:$IV,$B$1:$B$8,$B$10:$B$65536,$A:$A
- */
- @Test
- void testCreate() {
- CellRangeAddress cr = createCR(0, -1, 2, 255); // $C:$IV
-
- assertFalse(cr.isFullRowRange(), "isFullRowRange");
- assertTrue(cr.isFullColumnRange(), "isFullColumnRange");
-
- createCR(0, 7, 1, 1); // $B$1:$B$8
-
- // bug 44739 - invalid cell range
- createCR(9, -1, 1, 1); // $B$65536
-
- createCR(0, -1, 0, 0); // $A:$A
- }
-
- @Test
- void testNumberOfCells() {
- assertEquals(1, oneCell.getNumberOfCells());
- assertEquals(100, box9x9.getNumberOfCells());
- assertEquals(121, box10to20c.getNumberOfCells());
- }
+ /**
+ * @param lastRow pass -1 for max row index
+ * @param lastCol pass -1 for max col index
+ */
+ private static CellRangeAddress createCR(int firstRow, int lastRow, int firstCol, int lastCol) {
+ // max row & max col limit as per BIFF8
+ return new CellRangeAddress(
+ firstRow,
+ lastRow == -1 ? 0xFFFF : lastRow,
+ firstCol,
+ lastCol == -1 ? 0x00FF : lastCol);
+ }
+
+ @Test
+ void testContainsMethod()
+ {
+ CellRangeAddress [] ranges = sampleRanges;
+ for(int i=0; i!=ranges.length;i++)
+ {
+ for(int j=0; j!=ranges.length;j++)
+ {
+ boolean expectedResult = containsExpectedResults[i][j];
+ assertEquals(expectedResult, CellRangeUtil.contains(ranges[i], ranges[j]), "("+i+","+j+"): ");
+ }
+ }
+ }
+
+ private static final CellRangeAddress col1 = createCR( 0, -1, 1,1);
+ private static final CellRangeAddress col2 = createCR( 0, -1, 2,2);
+ private static final CellRangeAddress row1 = createCR( 1, 1, 0,-1);
+ private static final CellRangeAddress row2 = createCR( 2, 2, 0,-1);
+
+ private static final CellRangeAddress box0 = createCR( 0, 2, 0,2);
+ private static final CellRangeAddress box1 = createCR( 0, 1, 0,1);
+ private static final CellRangeAddress box2 = createCR( 0, 1, 2,3);
+ private static final CellRangeAddress box3 = createCR( 2, 3, 0,1);
+ private static final CellRangeAddress box4 = createCR( 2, 3, 2,3);
+ private static final CellRangeAddress box5 = createCR( 1, 3, 1,3);
+
+ @Test
+ void testHasSharedBorderMethod() {
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col1, col1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col2, col2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(col1, col2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(col2, col1));
+
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row1, row1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row2, row2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(row1, row2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(row2, row1));
+
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row1, col2));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col2, row1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row2, col1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(row2, col2));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col1, row2));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(col2, row2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(col2, col1));
+
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box1));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box1, box3));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box1, box4));
+
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box2));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box2, box3));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box2, box4));
+
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box1));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box2));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box3, box3));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box3, box4));
+
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box1));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box2));
+ assertTrue(CellRangeUtil.hasExactSharedBorder(box4, box3));
+ assertFalse(CellRangeUtil.hasExactSharedBorder(box4, box4));
+ }
+
+ @Test
+ void testIntersectMethod() {
+ assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box0, box5));
+ assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(box5, box0));
+ assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box1, box4));
+ assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box4, box1));
+ assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box2, box3));
+ assertEquals(CellRangeUtil.NO_INTERSECTION, CellRangeUtil.intersect(box3, box2));
+ assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(box0, box1));
+ assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(box0, box0));
+ assertEquals(CellRangeUtil.ENCLOSES, CellRangeUtil.intersect(box1, box0));
+ assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthColumn, oneCell));
+ assertEquals(CellRangeUtil.ENCLOSES, CellRangeUtil.intersect(oneCell, tenthColumn));
+ assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(tenthColumn, tenthRow));
+ assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(tenthRow, tenthColumn));
+ assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthColumn, tenthColumn));
+ assertEquals(CellRangeUtil.INSIDE, CellRangeUtil.intersect(tenthRow, tenthRow));
+
+ // Bug 55380
+ assertEquals(CellRangeUtil.OVERLAP, CellRangeUtil.intersect(
+ CellRangeAddress.valueOf("C1:D2"), CellRangeAddress.valueOf("C2:C3")));
+ }
+
+ /**
+ * Cell ranges like the following are valid
+ * =$C:$IV,$B$1:$B$8,$B$10:$B$65536,$A:$A
+ */
+ @Test
+ void testCreate() {
+ CellRangeAddress cr = createCR(0, -1, 2, 255); // $C:$IV
+
+ assertFalse(cr.isFullRowRange(), "isFullRowRange");
+ assertTrue(cr.isFullColumnRange(), "isFullColumnRange");
+
+ createCR(0, 7, 1, 1); // $B$1:$B$8
+
+ // bug 44739 - invalid cell range
+ createCR(9, -1, 1, 1); // $B$65536
+
+ createCR(0, -1, 0, 0); // $A:$A
+ }
+
+ @Test
+ void testNumberOfCells() {
+ assertEquals(1, oneCell.getNumberOfCells());
+ assertEquals(100, box9x9.getNumberOfCells());
+ assertEquals(121, box10to20c.getNumberOfCells());
+ }
- @SuppressWarnings("RedundantArrayCreation")
- @Test
+ @SuppressWarnings("RedundantArrayCreation")
+ @Test
void testMergeCellRanges() {
// no result on empty
cellRangeTest(new String[]{ });
@@ -220,8 +220,8 @@ final class TestCellRange {
cellRangeTest(new String[]{"A1:C3", "B1:D1"}, new String[] {"A1:C3", "B1:D1"}); // could be one region "A1:D3"
}
- @SuppressWarnings("RedundantArrayCreation")
- @Test
+ @SuppressWarnings("RedundantArrayCreation")
+ @Test
void testMergeCellRanges55380() {
cellRangeTest(new String[]{"C1:D2", "C2:C3"}, new String[] {"C1:D2", "C2:C3"});
cellRangeTest(new String[]{"A1:C3", "B2:D2"}, new String[] {"A1:C3", "B2:D2"});
@@ -250,14 +250,14 @@ final class TestCellRange {
private void verifyExpectedResult(CellRangeAddress[] result, String... expectedOutput) {
assertEquals(expectedOutput.length, result.length,
- "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
+ "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
for(int i = 0;i < expectedOutput.length;i++) {
assertEquals(expectedOutput[i], result[i].formatAsString(),
- "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
+ "\nExpected: " + Arrays.toString(expectedOutput) + "\nHad: " + Arrays.toString(result));
}
}
- @Test
+ @Test
void testValueOf() {
CellRangeAddress cr1 = CellRangeAddress.valueOf("A1:B1");
assertEquals(0, cr1.getFirstColumn());
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartFormatRecord.java Sat May 22 20:56:44 2021
@@ -31,28 +31,28 @@ import org.junit.jupiter.api.Test;
* Excel file.
*/
final class TestChartFormatRecord {
- /**
- * This rather uninteresting data came from attachment 23347 of bug 46693 at
- * offsets 0x6BB2 and 0x7BAF
- */
- private static final byte[] data = HexRead.readFromString(
- "14 10 14 00 " // BIFF header
- + "00 00 00 00 00 00 00 00 "
- + "00 00 00 00 00 00 00 00 "
- + "00 00 00 00");
+ /**
+ * This rather uninteresting data came from attachment 23347 of bug 46693 at
+ * offsets 0x6BB2 and 0x7BAF
+ */
+ private static final byte[] data = HexRead.readFromString(
+ "14 10 14 00 " // BIFF header
+ + "00 00 00 00 00 00 00 00 "
+ + "00 00 00 00 00 00 00 00 "
+ + "00 00 00 00");
- /**
- * The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header).
- */
- @Test
- void testLoad() {
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- ChartFormatRecord record = new ChartFormatRecord(in);
- assertNotEquals(2, in.remaining(), "Identified bug 44693d");
- assertEquals(0, in.remaining());
- assertEquals(24, record.getRecordSize());
+ /**
+ * The correct size of a {@link ChartFormatRecord} is 20 bytes (not including header).
+ */
+ @Test
+ void testLoad() {
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ ChartFormatRecord record = new ChartFormatRecord(in);
+ assertNotEquals(2, in.remaining(), "Identified bug 44693d");
+ assertEquals(0, in.remaining());
+ assertEquals(24, record.getRecordSize());
- byte[] data2 = record.serialize();
- assertArrayEquals(data, data2);
- }
+ byte[] data2 = record.serialize();
+ assertArrayEquals(data, data2);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestChartTitleFormatRecord.java Sat May 22 20:56:44 2021
@@ -33,48 +33,48 @@ import org.junit.jupiter.api.Test;
final class TestChartTitleFormatRecord {
- @Test
+ @Test
void testRecord() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(
- HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
+ POIFSFileSystem fs = new POIFSFileSystem(
+ HSSFTestDataSamples.getSampleFile("WithFormattedGraphTitle.xls"));
- // Check we can open the file via usermodel
- HSSFWorkbook hssf = new HSSFWorkbook(fs);
+ // Check we can open the file via usermodel
+ HSSFWorkbook hssf = new HSSFWorkbook(fs);
- // Now process it through eventusermodel, and
- // look out for the title records
- ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
- InputStream din = fs.createDocumentInputStream("Workbook");
- HSSFRequest req = new HSSFRequest();
- req.addListenerForAllRecords(grabber);
- HSSFEventFactory factory = new HSSFEventFactory();
- factory.processEvents(req, din);
- din.close();
-
- // Should've found one
- assertEquals(1, grabber.chartTitleFormatRecords.size());
- // And it should be of something interesting
- ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
- assertEquals(3, r.getFormatCount());
-
- hssf.close();
- fs.close();
-
- }
-
- private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
- private final List<ChartTitleFormatRecord> chartTitleFormatRecords;
-
- ChartTitleFormatRecordGrabber() {
- chartTitleFormatRecords = new ArrayList<>();
- }
+ // Now process it through eventusermodel, and
+ // look out for the title records
+ ChartTitleFormatRecordGrabber grabber = new ChartTitleFormatRecordGrabber();
+ InputStream din = fs.createDocumentInputStream("Workbook");
+ HSSFRequest req = new HSSFRequest();
+ req.addListenerForAllRecords(grabber);
+ HSSFEventFactory factory = new HSSFEventFactory();
+ factory.processEvents(req, din);
+ din.close();
+
+ // Should've found one
+ assertEquals(1, grabber.chartTitleFormatRecords.size());
+ // And it should be of something interesting
+ ChartTitleFormatRecord r = grabber.chartTitleFormatRecords.get(0);
+ assertEquals(3, r.getFormatCount());
+
+ hssf.close();
+ fs.close();
+
+ }
+
+ private static final class ChartTitleFormatRecordGrabber implements HSSFListener {
+ private final List<ChartTitleFormatRecord> chartTitleFormatRecords;
+
+ ChartTitleFormatRecordGrabber() {
+ chartTitleFormatRecords = new ArrayList<>();
+ }
- @Override
+ @Override
public void processRecord(org.apache.poi.hssf.record.Record record) {
- if(record instanceof ChartTitleFormatRecord) {
- chartTitleFormatRecords.add((ChartTitleFormatRecord)record);
- }
- }
+ if(record instanceof ChartTitleFormatRecord) {
+ chartTitleFormatRecords.add((ChartTitleFormatRecord)record);
+ }
+ }
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLegendRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLegendRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLegendRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLegendRecord.java Sat May 22 20:56:44 2021
@@ -30,28 +30,28 @@ import org.junit.jupiter.api.Test;
* correctly. Test data taken directly from a real Excel file.
*/
final class TestLegendRecord {
- byte[] data = new byte[] { (byte) 0x76, (byte) 0x0E, (byte) 0x00, (byte) 0x00, (byte) 0x86,
- (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x19, (byte) 0x01, (byte) 0x00,
- (byte) 0x00, (byte) 0x8B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
- (byte) 0x01, (byte) 0x1F, (byte) 0x00 };
+ byte[] data = new byte[] { (byte) 0x76, (byte) 0x0E, (byte) 0x00, (byte) 0x00, (byte) 0x86,
+ (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x19, (byte) 0x01, (byte) 0x00,
+ (byte) 0x00, (byte) 0x8B, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
+ (byte) 0x01, (byte) 0x1F, (byte) 0x00 };
- @Test
- void testLoad() {
- LegendRecord record = new LegendRecord(TestcaseRecordInputStream.create(0x1015, data));
+ @Test
+ void testLoad() {
+ LegendRecord record = new LegendRecord(TestcaseRecordInputStream.create(0x1015, data));
- assertEquals(0xe76, record.getXAxisUpperLeft());
+ assertEquals(0xe76, record.getXAxisUpperLeft());
- assertEquals(0x786, record.getYAxisUpperLeft());
+ assertEquals(0x786, record.getYAxisUpperLeft());
- assertEquals(0x119, record.getXSize());
+ assertEquals(0x119, record.getXSize());
- assertEquals(0x8b, record.getYSize());
+ assertEquals(0x8b, record.getYSize());
- assertEquals((byte) 0x3, record.getType());
+ assertEquals((byte) 0x3, record.getType());
- assertEquals((byte) 0x1, record.getSpacing());
+ assertEquals((byte) 0x1, record.getSpacing());
- assertEquals((short) 0x1f, record.getOptions());
+ assertEquals((short) 0x1f, record.getOptions());
assertTrue(record.isAutoPosition());
assertTrue(record.isAutoSeries());
assertTrue(record.isAutoXPositioning());
@@ -59,29 +59,29 @@ final class TestLegendRecord {
assertTrue(record.isVertical());
assertFalse(record.isDataTable());
- assertEquals(24, record.getRecordSize());
- }
+ assertEquals(24, record.getRecordSize());
+ }
- @SuppressWarnings("squid:S2699")
- @Test
- void testStore() {
- LegendRecord record = new LegendRecord();
-
- record.setXAxisUpperLeft(0xe76);
- record.setYAxisUpperLeft(0x786);
- record.setXSize(0x119);
- record.setYSize(0x8b);
- record.setType((byte) 0x3);
- record.setSpacing((byte) 0x1);
- record.setOptions((short) 0x1f);
- record.setAutoPosition(true);
- record.setAutoSeries(true);
- record.setAutoXPositioning(true);
- record.setAutoYPositioning(true);
- record.setVertical(true);
- record.setDataTable(false);
-
- byte[] recordBytes = record.serialize();
- confirmRecordEncoding(LegendRecord.sid, data, recordBytes);
- }
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testStore() {
+ LegendRecord record = new LegendRecord();
+
+ record.setXAxisUpperLeft(0xe76);
+ record.setYAxisUpperLeft(0x786);
+ record.setXSize(0x119);
+ record.setYSize(0x8b);
+ record.setType((byte) 0x3);
+ record.setSpacing((byte) 0x1);
+ record.setOptions((short) 0x1f);
+ record.setAutoPosition(true);
+ record.setAutoSeries(true);
+ record.setAutoXPositioning(true);
+ record.setAutoYPositioning(true);
+ record.setVertical(true);
+ record.setDataTable(false);
+
+ byte[] recordBytes = record.serialize();
+ confirmRecordEncoding(LegendRecord.sid, data, recordBytes);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestLinkedDataRecord.java Sat May 22 20:56:44 2021
@@ -185,7 +185,7 @@ recordid = 0x1051, size =8
record.setCustomNumberFormat( false );
record.setIndexNumberFmtRecord( (short)0 );
Area3DPtg ptg = new Area3DPtg(0, 7936, 0, 0,
- false, false, false, false, 0);
+ false, false, false, false, 0);
record.setFormulaOfLink(new Ptg[] { ptg, } );
byte [] recordBytes = record.serialize();
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestObjectLinkRecord.java Sat May 22 20:56:44 2021
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
*/
final class TestObjectLinkRecord {
byte[] data = new byte[] {
- (byte)0x03,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
+ (byte)0x03,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
};
@Test
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesIndexRecord.java Sat May 22 20:56:44 2021
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
*/
final class TestSeriesIndexRecord {
byte[] data = new byte[] {
- (byte)0x03,(byte)0x00
+ (byte)0x03,(byte)0x00
};
@Test
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/chart/TestSeriesTextRecord.java Sat May 22 20:56:44 2021
@@ -31,65 +31,65 @@ import org.junit.jupiter.api.Test;
* works correctly. Test data taken directly from a real Excel file.
*/
final class TestSeriesTextRecord {
- private static final byte[] SIMPLE_DATA = HexRead
- .readFromString("00 00 0C 00 56 61 6C 75 65 20 4E 75 6D 62 65 72");
+ private static final byte[] SIMPLE_DATA = HexRead
+ .readFromString("00 00 0C 00 56 61 6C 75 65 20 4E 75 6D 62 65 72");
- @Test
- void testLoad() {
- SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, SIMPLE_DATA));
-
- assertEquals((short) 0, record.getId());
- assertEquals("Value Number", record.getText());
-
- assertEquals(SIMPLE_DATA.length + 4, record.getRecordSize());
- }
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testStore() {
- SeriesTextRecord record = new SeriesTextRecord();
-
- record.setId(0);
- record.setText("Value Number");
-
- byte[] recordBytes = record.serialize();
- confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, recordBytes);
- }
-
- @Test
- void testReserializeLongTitle() {
- // Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1
- byte[] data = HexRead.readFromString(
- "00 00, "
- + "82 "
- + "01 "
- + "50 00 6C 00 61 00 73 00 6D 00 61 00 20 00 4C 00 "
- + "65 00 76 00 65 00 6C 00 73 00 20 00 6F 00 66 00 "
- + "20 00 4C 00 2D 00 30 00 30 00 30 00 31 00 31 00 "
- + "31 00 32 00 32 00 32 00 2D 00 33 00 33 00 33 00 "
- + "58 00 34 00 34 00 34 00 20 00 69 00 6E 00 20 00 "
- + "53 00 44 00 20 00 72 00 61 00 74 00 0A 00 50 00 "
- + "4F 00 20 00 33 00 2E 00 30 00 20 00 6D 00 67 00 "
- + "2F 00 6B 00 67 00 20 00 28 00 35 00 2E 00 30 00 "
- + "20 00 6D 00 4C 00 2F 00 6B 00 67 00 29 00 20 00 "
- + "69 00 6E 00 20 00 4D 00 65 00 74 00 68 00 6F 00 "
- + "63 00 65 00 6C 00 0A 00 49 00 56 00 20 00 30 00 "
- + "2E 00 35 00 20 00 6D 00 67 00 2F 00 6B 00 67 00 "
- + "20 00 28 00 31 00 2E 00 30 00 20 00 6D 00 4C 00 "
- + "2F 00 6B 00 67 00 29 00 20 00 69 00 6E 00 20 00 "
- + "36 00 30 00 25 00 20 00 50 00 45 00 47 00 20 00 "
- + "32 00 30 00 30 00 0A 00 46 00 20 00 3D 00 61 00 "
- + "62 00 63 00");
-
- RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data);
- // Identified bug 45784a
- // 'would be' error msg changed at svn r703620
- // "Illegal length - asked for -126 but only 130 left!"
- // "Bad requested string length (-126)"
- SeriesTextRecord str = new SeriesTextRecord(in);
-
- assertTrue(str.getRecordSize() >= 0, "Identified bug 45784b");
- byte[] ser = str.serialize();
- confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
- }
+ @Test
+ void testLoad() {
+ SeriesTextRecord record = new SeriesTextRecord(TestcaseRecordInputStream.create(0x100d, SIMPLE_DATA));
+
+ assertEquals((short) 0, record.getId());
+ assertEquals("Value Number", record.getText());
+
+ assertEquals(SIMPLE_DATA.length + 4, record.getRecordSize());
+ }
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testStore() {
+ SeriesTextRecord record = new SeriesTextRecord();
+
+ record.setId(0);
+ record.setText("Value Number");
+
+ byte[] recordBytes = record.serialize();
+ confirmRecordEncoding(SeriesTextRecord.sid, SIMPLE_DATA, recordBytes);
+ }
+
+ @Test
+ void testReserializeLongTitle() {
+ // Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1
+ byte[] data = HexRead.readFromString(
+ "00 00, "
+ + "82 "
+ + "01 "
+ + "50 00 6C 00 61 00 73 00 6D 00 61 00 20 00 4C 00 "
+ + "65 00 76 00 65 00 6C 00 73 00 20 00 6F 00 66 00 "
+ + "20 00 4C 00 2D 00 30 00 30 00 30 00 31 00 31 00 "
+ + "31 00 32 00 32 00 32 00 2D 00 33 00 33 00 33 00 "
+ + "58 00 34 00 34 00 34 00 20 00 69 00 6E 00 20 00 "
+ + "53 00 44 00 20 00 72 00 61 00 74 00 0A 00 50 00 "
+ + "4F 00 20 00 33 00 2E 00 30 00 20 00 6D 00 67 00 "
+ + "2F 00 6B 00 67 00 20 00 28 00 35 00 2E 00 30 00 "
+ + "20 00 6D 00 4C 00 2F 00 6B 00 67 00 29 00 20 00 "
+ + "69 00 6E 00 20 00 4D 00 65 00 74 00 68 00 6F 00 "
+ + "63 00 65 00 6C 00 0A 00 49 00 56 00 20 00 30 00 "
+ + "2E 00 35 00 20 00 6D 00 67 00 2F 00 6B 00 67 00 "
+ + "20 00 28 00 31 00 2E 00 30 00 20 00 6D 00 4C 00 "
+ + "2F 00 6B 00 67 00 29 00 20 00 69 00 6E 00 20 00 "
+ + "36 00 30 00 25 00 20 00 50 00 45 00 47 00 20 00 "
+ + "32 00 30 00 30 00 0A 00 46 00 20 00 3D 00 61 00 "
+ + "62 00 63 00");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data);
+ // Identified bug 45784a
+ // 'would be' error msg changed at svn r703620
+ // "Illegal length - asked for -126 but only 130 left!"
+ // "Bad requested string length (-126)"
+ SeriesTextRecord str = new SeriesTextRecord(in);
+
+ assertTrue(str.getRecordSize() >= 0, "Identified bug 45784b");
+ byte[] ser = str.serialize();
+ confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java Sat May 22 20:56:44 2021
@@ -31,33 +31,33 @@ import org.junit.jupiter.api.Test;
*/
final class TestExtendedPivotTableViewFieldsRecord {
- @Test
- void testSubNameNotPresent_bug46693() {
- // This data came from attachment 23347 of bug 46693 at offset 0xAA43
- byte[] data = HexRead.readFromString(
- "00 01 14 00" + // BIFF header
- "1E 14 00 0A FF FF FF FF 00 00 FF FF 00 00 00 00 00 00 00 00");
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- // bug 46693a - Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars
- ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in);
-
- assertEquals(data.length, rec.getRecordSize());
- }
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testOlderFormat_bug46918() {
- // There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918
- // They all had the following hex encoding:
+ @Test
+ void testSubNameNotPresent_bug46693() {
+ // This data came from attachment 23347 of bug 46693 at offset 0xAA43
+ byte[] data = HexRead.readFromString(
+ "00 01 14 00" + // BIFF header
+ "1E 14 00 0A FF FF FF FF 00 00 FF FF 00 00 00 00 00 00 00 00");
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ // bug 46693a - Expected to find a ContinueRecord in order to read remaining 65535 of 65535 chars
+ ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in);
+
+ assertEquals(data.length, rec.getRecordSize());
+ }
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testOlderFormat_bug46918() {
+ // There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918
+ // They all had the following hex encoding:
byte[] data = HexRead.readFromString("00 01 0A 00 1E 14 00 0A FF FF FF FF 00 00");
- RecordInputStream in = TestcaseRecordInputStream.create(data);
- // bug 46918 - Not enough data (0) to read requested (2) bytes
- ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in);
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
+ // bug 46918 - Not enough data (0) to read requested (2) bytes
+ ExtendedPivotTableViewFieldsRecord rec = new ExtendedPivotTableViewFieldsRecord(in);
byte[] expReserData = HexRead.readFromString("1E 14 00 0A FF FF FF FF 00 00" +
"FF FF 00 00 00 00 00 00 00 00");
- confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize());
- }
+ confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize());
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestPageItemRecord.java Sat May 22 20:56:44 2021
@@ -31,31 +31,31 @@ import org.junit.jupiter.api.Test;
* Tests for {@link PageItemRecord}
*/
final class TestPageItemRecord {
- @Test
- void testMoreThanOneInfoItem_bug46917() {
- byte[] data = HexRead.readFromString("01 02 03 04 05 06 07 08 09 0A 0B 0C");
- RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data);
- PageItemRecord rec = new PageItemRecord(in);
- assertNotEquals(6, in.remaining(), "Identified bug 46917");
- assertEquals(0, in.remaining());
+ @Test
+ void testMoreThanOneInfoItem_bug46917() {
+ byte[] data = HexRead.readFromString("01 02 03 04 05 06 07 08 09 0A 0B 0C");
+ RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data);
+ PageItemRecord rec = new PageItemRecord(in);
+ assertNotEquals(6, in.remaining(), "Identified bug 46917");
+ assertEquals(0, in.remaining());
- assertEquals(4+data.length, rec.getRecordSize());
- }
+ assertEquals(4+data.length, rec.getRecordSize());
+ }
- @Test
- void testSerialize() {
- confirmSerialize("01 02 03 04 05 06");
- confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C");
- confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12");
- }
+ @Test
+ void testSerialize() {
+ confirmSerialize("01 02 03 04 05 06");
+ confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C");
+ confirmSerialize("01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12");
+ }
- private static void confirmSerialize(String hexDump) {
- byte[] data = HexRead.readFromString(hexDump);
- RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data);
- PageItemRecord rec = new PageItemRecord(in);
- assertEquals(0, in.remaining());
- assertEquals(4+data.length, rec.getRecordSize());
- byte[] data2 = rec.serialize();
- confirmRecordEncoding(PageItemRecord.sid, data, data2);
- }
+ private static void confirmSerialize(String hexDump) {
+ byte[] data = HexRead.readFromString(hexDump);
+ RecordInputStream in = TestcaseRecordInputStream.create(PageItemRecord.sid, data);
+ PageItemRecord rec = new PageItemRecord(in);
+ assertEquals(0, in.remaining());
+ assertEquals(4+data.length, rec.getRecordSize());
+ byte[] data2 = rec.serialize();
+ confirmRecordEncoding(PageItemRecord.sid, data, data2);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/pivot/TestViewFieldsRecord.java Sat May 22 20:56:44 2021
@@ -32,32 +32,32 @@ import org.junit.jupiter.api.Test;
*/
final class TestViewFieldsRecord {
- @Test
- void testUnicodeFlag_bug46693() {
- byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
- RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
- ViewFieldsRecord rec = new ViewFieldsRecord(in);
- assertNotEquals(1, in.remaining(), "Identified bug 46693b");
- assertEquals(0, in.remaining());
- assertEquals(4+data.length, rec.getRecordSize());
- }
+ @Test
+ void testUnicodeFlag_bug46693() {
+ byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
+ RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
+ ViewFieldsRecord rec = new ViewFieldsRecord(in);
+ assertNotEquals(1, in.remaining(), "Identified bug 46693b");
+ assertEquals(0, in.remaining());
+ assertEquals(4+data.length, rec.getRecordSize());
+ }
- @Test
- void testSerialize() {
- // This hex data was produced by changing the 'Custom Name' property,
- // available under 'Field Settings' from the 'PivotTable Field List' (Excel 2007)
- confirmSerialize("00 00 01 00 01 00 00 00 FF FF");
- confirmSerialize("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
- confirmSerialize("01 00 01 00 01 00 04 00 0A 00 01 48 00 69 00 73 00 74 00 6F 00 72 00 79 00 2D 00 82 69 81 89");
- }
+ @Test
+ void testSerialize() {
+ // This hex data was produced by changing the 'Custom Name' property,
+ // available under 'Field Settings' from the 'PivotTable Field List' (Excel 2007)
+ confirmSerialize("00 00 01 00 01 00 00 00 FF FF");
+ confirmSerialize("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
+ confirmSerialize("01 00 01 00 01 00 04 00 0A 00 01 48 00 69 00 73 00 74 00 6F 00 72 00 79 00 2D 00 82 69 81 89");
+ }
- private static void confirmSerialize(String hexDump) {
- byte[] data = HexRead.readFromString(hexDump);
- RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
- ViewFieldsRecord rec = new ViewFieldsRecord(in);
- assertEquals(0, in.remaining());
- assertEquals(4+data.length, rec.getRecordSize());
- byte[] data2 = rec.serialize();
- confirmRecordEncoding(ViewFieldsRecord.sid, data, data2);
- }
+ private static void confirmSerialize(String hexDump) {
+ byte[] data = HexRead.readFromString(hexDump);
+ RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
+ ViewFieldsRecord rec = new ViewFieldsRecord(in);
+ assertEquals(0, in.remaining());
+ assertEquals(4+data.length, rec.getRecordSize());
+ byte[] data2 = rec.serialize();
+ confirmRecordEncoding(ViewFieldsRecord.sid, data, data2);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/FormulaExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/FormulaExtractor.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/FormulaExtractor.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/FormulaExtractor.java Sat May 22 20:56:44 2021
@@ -26,16 +26,16 @@ import org.apache.poi.ss.formula.ptg.Ptg
*/
public final class FormulaExtractor {
- private FormulaExtractor() {
- // no instances of this class
- }
+ private FormulaExtractor() {
+ // no instances of this class
+ }
- public static Ptg[] getPtgs(HSSFCell cell) {
- CellValueRecordInterface vr = cell.getCellValueRecord();
- if (!(vr instanceof FormulaRecordAggregate)) {
- throw new IllegalArgumentException("Not a formula cell");
- }
- FormulaRecordAggregate fra = (FormulaRecordAggregate) vr;
- return fra.getFormulaRecord().getParsedExpression();
- }
+ public static Ptg[] getPtgs(HSSFCell cell) {
+ CellValueRecordInterface vr = cell.getCellValueRecord();
+ if (!(vr instanceof FormulaRecordAggregate)) {
+ throw new IllegalArgumentException("Not a formula cell");
+ }
+ FormulaRecordAggregate fra = (FormulaRecordAggregate) vr;
+ return fra.getFormulaRecord().getParsedExpression();
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFEvaluationTestHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFEvaluationTestHelper.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFEvaluationTestHelper.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFEvaluationTestHelper.java Sat May 22 20:56:44 2021
@@ -24,8 +24,8 @@ import org.apache.poi.ss.formula.Evaluat
*/
public final class HSSFEvaluationTestHelper {
- public static EvaluationCell wrapCell(HSSFCell cell) {
- return new HSSFEvaluationCell(cell);
- }
+ public static EvaluationCell wrapCell(HSSFCell cell) {
+ return new HSSFEvaluationCell(cell);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFTestHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFTestHelper.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFTestHelper.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/HSSFTestHelper.java Sat May 22 20:56:44 2021
@@ -54,15 +54,15 @@ public class HSSFTestHelper {
return dg;
}
}
- /**
- * Lets non UserModel tests at the low level Workbook
- */
- public static InternalWorkbook getWorkbookForTest(HSSFWorkbook wb) {
- return wb.getWorkbook();
- }
- public static InternalSheet getSheetForTest(HSSFSheet sheet) {
- return sheet.getSheet();
- }
+ /**
+ * Lets non UserModel tests at the low level Workbook
+ */
+ public static InternalWorkbook getWorkbookForTest(HSSFWorkbook wb) {
+ return wb.getWorkbook();
+ }
+ public static InternalSheet getSheetForTest(HSSFSheet sheet) {
+ return sheet.getSheet();
+ }
public static HSSFPatriarch createTestPatriarch(HSSFSheet sheet, EscherAggregate agg){
return new HSSFPatriarch(sheet, agg);
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/StreamUtility.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/StreamUtility.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/StreamUtility.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/StreamUtility.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,100 +30,100 @@ import java.util.List;
*/
public final class StreamUtility {
- /**
- * Compares two streams with expected differences in specified regions. The streams are
- * expected to be of equal length and comparison is always byte for byte. That is -
- * differences can only involve exchanging each individual byte for another single byte.<br>
- * Both input streams are closed.
- *
- * @param allowableDifferenceRegions array of integer pairs: (offset, length).
- * Any differences encountered in these regions of the streams will be ignored
- * @return <code>null</code> if streams are identical, else the
- * byte indexes of differing data. If streams were different lengths,
- * the returned indexes will be -1 and the length of the shorter stream
- */
- public static int[] diffStreams(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) {
-
- if((allowableDifferenceRegions.length % 2) != 0) {
- throw new RuntimeException("allowableDifferenceRegions length is odd");
- }
- boolean success = false;
- int[] result;
- try {
- result = diffInternal(isA, isB, allowableDifferenceRegions);
- success = true;
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- close(isA, success);
- close(isB, success);
- }
- return result;
- }
-
- /**
- * @param success <code>false</code> if the outer method is throwing an exception.
- */
- private static void close(InputStream is, boolean success) {
- try {
- is.close();
- } catch (IOException e) {
- if(success) {
- // this is a new error. ok to throw
- throw new RuntimeException(e);
- }
- // else don't subvert original exception. just print stack trace for this one
- e.printStackTrace();
- }
- }
-
- private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions)
- throws IOException {
- int offset = 0;
- List<Integer> temp = new ArrayList<>();
- while (true) {
- int b = isA.read();
- int b2 = isB.read();
- if (b == -1) {
- // EOF
- if (b2 == -1) {
- return toPrimitiveIntArray(temp);
- }
- return new int[] { -1, offset, };
- }
- if (b2 == -1) {
- return new int[] { -1, offset, };
- }
- if (b != b2 && !isIgnoredRegion(allowableDifferenceRegions, offset)) {
- temp.add(Integer.valueOf(offset));
- }
- offset++;
- }
- }
-
- private static boolean isIgnoredRegion(int[] allowableDifferenceRegions, int offset) {
- for (int i = 0; i < allowableDifferenceRegions.length; i+=2) {
- int start = allowableDifferenceRegions[i];
- int end = start + allowableDifferenceRegions[i+1];
- if(start <= offset && offset < end) {
- return true;
- }
- }
- return false;
- }
-
- private static int[] toPrimitiveIntArray(List<Integer> temp) {
- int nItems = temp.size();
- if(nItems < 1) {
- return null;
- }
- Integer[] boxInts = new Integer[nItems];
- temp.toArray(boxInts);
-
- int[] result = new int[nItems];
- for (int i = 0; i < result.length; i++) {
- result[i] = boxInts[i].intValue();
- }
- return result;
- }
+ /**
+ * Compares two streams with expected differences in specified regions. The streams are
+ * expected to be of equal length and comparison is always byte for byte. That is -
+ * differences can only involve exchanging each individual byte for another single byte.<br>
+ * Both input streams are closed.
+ *
+ * @param allowableDifferenceRegions array of integer pairs: (offset, length).
+ * Any differences encountered in these regions of the streams will be ignored
+ * @return <code>null</code> if streams are identical, else the
+ * byte indexes of differing data. If streams were different lengths,
+ * the returned indexes will be -1 and the length of the shorter stream
+ */
+ public static int[] diffStreams(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) {
+
+ if((allowableDifferenceRegions.length % 2) != 0) {
+ throw new RuntimeException("allowableDifferenceRegions length is odd");
+ }
+ boolean success = false;
+ int[] result;
+ try {
+ result = diffInternal(isA, isB, allowableDifferenceRegions);
+ success = true;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ close(isA, success);
+ close(isB, success);
+ }
+ return result;
+ }
+
+ /**
+ * @param success <code>false</code> if the outer method is throwing an exception.
+ */
+ private static void close(InputStream is, boolean success) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ if(success) {
+ // this is a new error. ok to throw
+ throw new RuntimeException(e);
+ }
+ // else don't subvert original exception. just print stack trace for this one
+ e.printStackTrace();
+ }
+ }
+
+ private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions)
+ throws IOException {
+ int offset = 0;
+ List<Integer> temp = new ArrayList<>();
+ while (true) {
+ int b = isA.read();
+ int b2 = isB.read();
+ if (b == -1) {
+ // EOF
+ if (b2 == -1) {
+ return toPrimitiveIntArray(temp);
+ }
+ return new int[] { -1, offset, };
+ }
+ if (b2 == -1) {
+ return new int[] { -1, offset, };
+ }
+ if (b != b2 && !isIgnoredRegion(allowableDifferenceRegions, offset)) {
+ temp.add(Integer.valueOf(offset));
+ }
+ offset++;
+ }
+ }
+
+ private static boolean isIgnoredRegion(int[] allowableDifferenceRegions, int offset) {
+ for (int i = 0; i < allowableDifferenceRegions.length; i+=2) {
+ int start = allowableDifferenceRegions[i];
+ int end = start + allowableDifferenceRegions[i+1];
+ if(start <= offset && offset < end) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static int[] toPrimitiveIntArray(List<Integer> temp) {
+ int nItems = temp.size();
+ if(nItems < 1) {
+ return null;
+ }
+ Integer[] boxInts = new Integer[nItems];
+ temp.toArray(boxInts);
+
+ int[] result = new int[nItems];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = boxInts[i].intValue();
+ }
+ return result;
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBug42464.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBug42464.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBug42464.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestBug42464.java Sat May 22 20:56:44 2021
@@ -37,56 +37,56 @@ import org.junit.jupiter.api.Test;
final class TestBug42464 {
@Test
- void testOKFile() throws Exception {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-ok.xls");
- process(wb);
- wb.close();
- }
+ void testOKFile() throws Exception {
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-ok.xls");
+ process(wb);
+ wb.close();
+ }
@Test
- void testExpSharedBadFile() throws Exception {
- HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
- process(wb);
- wb.close();
- }
-
- private static void process(HSSFWorkbook wb) {
- HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
- for(int i=0; i<wb.getNumberOfSheets(); i++) {
- HSSFSheet s = wb.getSheetAt(i);
-
- Iterator<Row> it = s.rowIterator();
- while(it.hasNext()) {
- HSSFRow r = (HSSFRow)it.next();
- process(r, eval);
- }
- }
- }
-
- private static void process(HSSFRow row, HSSFFormulaEvaluator eval) {
- Iterator<Cell> it = row.cellIterator();
- while(it.hasNext()) {
- HSSFCell cell = (HSSFCell)it.next();
- if(cell.getCellType() != CellType.FORMULA) {
- continue;
- }
- FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord();
- FormulaRecord r = record.getFormulaRecord();
- /*Ptg[] ptgs =*/ r.getParsedExpression();
-
- /*String cellRef =*/ new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
-// if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
-// System.out.print(cellRef);
-// System.out.println(" - has " + ptgs.length + " ptgs:");
-// for(int i=0; i<ptgs.length; i++) {
-// String c = ptgs[i].getClass().toString();
-// System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
-// }
-// System.out.println("-> " + cell.getCellFormula());
-// }
-
- CellValue evalResult = eval.evaluate(cell);
- assertNotNull(evalResult);
- }
- }
+ void testExpSharedBadFile() throws Exception {
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("42464-ExpPtg-bad.xls");
+ process(wb);
+ wb.close();
+ }
+
+ private static void process(HSSFWorkbook wb) {
+ HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
+ for(int i=0; i<wb.getNumberOfSheets(); i++) {
+ HSSFSheet s = wb.getSheetAt(i);
+
+ Iterator<Row> it = s.rowIterator();
+ while(it.hasNext()) {
+ HSSFRow r = (HSSFRow)it.next();
+ process(r, eval);
+ }
+ }
+ }
+
+ private static void process(HSSFRow row, HSSFFormulaEvaluator eval) {
+ Iterator<Cell> it = row.cellIterator();
+ while(it.hasNext()) {
+ HSSFCell cell = (HSSFCell)it.next();
+ if(cell.getCellType() != CellType.FORMULA) {
+ continue;
+ }
+ FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord();
+ FormulaRecord r = record.getFormulaRecord();
+ /*Ptg[] ptgs =*/ r.getParsedExpression();
+
+ /*String cellRef =*/ new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
+// if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
+// System.out.print(cellRef);
+// System.out.println(" - has " + ptgs.length + " ptgs:");
+// for(int i=0; i<ptgs.length; i++) {
+// String c = ptgs[i].getClass().toString();
+// System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
+// }
+// System.out.println("-> " + cell.getCellFormula());
+// }
+
+ CellValue evalResult = eval.evaluate(cell);
+ assertNotNull(evalResult);
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestCellStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestCellStyle.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestCellStyle.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestCellStyle.java Sat May 22 20:56:44 2021
@@ -379,8 +379,8 @@ final class TestCellStyle {
@Test
void testShrinkToFit() throws IOException {
- // Existing file
- try (HSSFWorkbook wb1 = openSample("ShrinkToFit.xls")) {
+ // Existing file
+ try (HSSFWorkbook wb1 = openSample("ShrinkToFit.xls")) {
HSSFSheet s = wb1.getSheetAt(0);
HSSFRow r = s.getRow(0);
HSSFCellStyle cs = r.getCell(0).getCellStyle();
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestDataValidation.java Sat May 22 20:56:44 2021
@@ -58,67 +58,67 @@ final class TestDataValidation extends B
}
- void assertDataValidation(Workbook wb) {
+ void assertDataValidation(Workbook wb) {
byte[] generatedContent;
- try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(22000)) {
- wb.write(baos);
+ try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(22000)) {
+ wb.write(baos);
generatedContent = baos.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- boolean isSame;
-// if (false) {
-// // TODO - add proof spreadsheet and compare
-// InputStream proofStream = HSSFTestDataSamples.openSampleFileStream("TestDataValidation.xls");
-// isSame = compareStreams(proofStream, generatedContent);
-// }
- isSame = true;
-
- if (isSame) {
- return;
- }
- File tempDir = new File(System.getProperty("java.io.tmpdir"));
- File generatedFile = new File(tempDir, "GeneratedTestDataValidation.xls");
- try (FileOutputStream fileOut = new FileOutputStream(generatedFile)) {
- fileOut.write(generatedContent);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- PrintStream ps = System.out;
-
- ps.println("This test case has failed because the generated file differs from proof copy '"
- ); // TODO+ proofFile.getAbsolutePath() + "'.");
- ps.println("The cause is usually a change to this test, or some common spreadsheet generation code. "
- + "The developer has to decide whether the changes were wanted or unwanted.");
- ps.println("If the changes to the generated version were unwanted, "
- + "make the fix elsewhere (do not modify this test or the proof spreadsheet to get the test working).");
- ps.println("If the changes were wanted, make sure to open the newly generated file in Excel "
- + "and verify it manually. The new proof file should be submitted after it is verified to be correct.");
- ps.println();
- ps.println("One other possible (but less likely) cause of a failed test is a problem in the "
- + "comparison logic used here. Perhaps some extra file regions need to be ignored.");
- ps.println("The generated file has been saved to '" + generatedFile.getAbsolutePath() + "' for manual inspection.");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ boolean isSame;
+// if (false) {
+// // TODO - add proof spreadsheet and compare
+// InputStream proofStream = HSSFTestDataSamples.openSampleFileStream("TestDataValidation.xls");
+// isSame = compareStreams(proofStream, generatedContent);
+// }
+ isSame = true;
+
+ if (isSame) {
+ return;
+ }
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ File generatedFile = new File(tempDir, "GeneratedTestDataValidation.xls");
+ try (FileOutputStream fileOut = new FileOutputStream(generatedFile)) {
+ fileOut.write(generatedContent);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
- fail("Generated file differs from proof copy. See sysout comments for details on how to fix.");
+ PrintStream ps = System.out;
- }
+ ps.println("This test case has failed because the generated file differs from proof copy '"
+ ); // TODO+ proofFile.getAbsolutePath() + "'.");
+ ps.println("The cause is usually a change to this test, or some common spreadsheet generation code. "
+ + "The developer has to decide whether the changes were wanted or unwanted.");
+ ps.println("If the changes to the generated version were unwanted, "
+ + "make the fix elsewhere (do not modify this test or the proof spreadsheet to get the test working).");
+ ps.println("If the changes were wanted, make sure to open the newly generated file in Excel "
+ + "and verify it manually. The new proof file should be submitted after it is verified to be correct.");
+ ps.println();
+ ps.println("One other possible (but less likely) cause of a failed test is a problem in the "
+ + "comparison logic used here. Perhaps some extra file regions need to be ignored.");
+ ps.println("The generated file has been saved to '" + generatedFile.getAbsolutePath() + "' for manual inspection.");
+
+ fail("Generated file differs from proof copy. See sysout comments for details on how to fix.");
+
+ }
/* package */ static void setCellValue(HSSFCell cell, String text) {
- cell.setCellValue(new HSSFRichTextString(text));
+ cell.setCellValue(new HSSFRichTextString(text));
}
- @Test
+ @Test
void testAddToExistingSheet() throws Exception {
- // dvEmpty.xls is a simple one sheet workbook. With a DataValidations header record but no
- // DataValidations. It's important that the example has one SHEETPROTECTION record.
- // Such a workbook can be created in Excel (2007) by adding datavalidation for one cell
- // and then deleting the row that contains the cell.
- try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("dvEmpty.xls")) {
+ // dvEmpty.xls is a simple one sheet workbook. With a DataValidations header record but no
+ // DataValidations. It's important that the example has one SHEETPROTECTION record.
+ // Such a workbook can be created in Excel (2007) by adding datavalidation for one cell
+ // and then deleting the row that contains the cell.
+ try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("dvEmpty.xls")) {
int dvRow = 0;
Sheet sheet = wb.getSheetAt(0);
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
@@ -138,19 +138,19 @@ final class TestDataValidation extends B
byte[] wbData = baos.toByteArray();
-// if (false) { // TODO (Jul 2008) fix EventRecordFactory to process unknown records, (and DV records for that matter)
+// if (false) { // TODO (Jul 2008) fix EventRecordFactory to process unknown records, (and DV records for that matter)
//
-// ERFListener erfListener = null; // new MyERFListener();
-// EventRecordFactory erf = new EventRecordFactory(erfListener, null);
-// try {
-// POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
-// erf.processRecords(fs.createDocumentInputStream("Workbook"));
-// } catch (RecordFormatException e) {
-// throw new RuntimeException(e);
-// } catch (IOException e) {
-// throw new RuntimeException(e);
-// }
-// }
+// ERFListener erfListener = null; // new MyERFListener();
+// EventRecordFactory erf = new EventRecordFactory(erfListener, null);
+// try {
+// POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
+// erf.processRecords(fs.createDocumentInputStream("Workbook"));
+// } catch (RecordFormatException e) {
+// throw new RuntimeException(e);
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// }
// else verify record ordering by navigating the raw bytes
byte[] dvHeaderRecStart = {(byte) 0xB2, 0x01, 0x12, 0x00,};
@@ -166,29 +166,29 @@ final class TestDataValidation extends B
assertNotEquals(0x0867, nextSid, "Identified bug 45519");
assertEquals(DVRecord.sid, nextSid);
}
- }
+ }
- private int findIndex(byte[] largeData, byte[] searchPattern) {
- byte firstByte = searchPattern[0];
- for (int i = 0; i < largeData.length; i++) {
- if(largeData[i] != firstByte) {
- continue;
- }
- boolean match = true;
- for (int j = 1; j < searchPattern.length; j++) {
- if(searchPattern[j] != largeData[i+j]) {
- match = false;
- break;
- }
- }
- if (match) {
- return i;
- }
- }
- return -1;
- }
+ private int findIndex(byte[] largeData, byte[] searchPattern) {
+ byte firstByte = searchPattern[0];
+ for (int i = 0; i < largeData.length; i++) {
+ if(largeData[i] != firstByte) {
+ continue;
+ }
+ boolean match = true;
+ for (int j = 1; j < searchPattern.length; j++) {
+ if(searchPattern[j] != largeData[i+j]) {
+ match = false;
+ break;
+ }
+ }
+ if (match) {
+ return i;
+ }
+ }
+ return -1;
+ }
- @Test
+ @Test
void testGetDataValidationsAny() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -233,7 +233,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsIntegerFormula() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -260,7 +260,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsIntegerValue() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -287,7 +287,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsDecimal() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -314,7 +314,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsDate() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -341,7 +341,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsListExplicit() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -375,7 +375,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsListFormula() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
@@ -404,7 +404,7 @@ final class TestDataValidation extends B
}
}
- @Test
+ @Test
void testGetDataValidationsFormula() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestEscherGraphics.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestEscherGraphics.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestEscherGraphics.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestEscherGraphics.java Sat May 22 20:56:44 2021
@@ -39,8 +39,8 @@ import org.junit.jupiter.api.Test;
* at 20,30,500,200
*/
final class TestEscherGraphics {
- private HSSFWorkbook workbook;
- private HSSFPatriarch patriarch;
+ private HSSFWorkbook workbook;
+ private HSSFPatriarch patriarch;
private HSSFShapeGroup escherGroupA;
private EscherGraphics graphics;
@@ -112,185 +112,185 @@ final class TestEscherGraphics {
@Test
void testGetDataBackAgain() {
- HSSFSheet s;
- HSSFShapeGroup s1;
- HSSFShapeGroup s2;
-
- patriarch.setCoordinates(10, 20, 30, 40);
-
- workbook = writeOutAndReadBack(workbook);
- s = workbook.getSheetAt(0);
- patriarch = s.getDrawingPatriarch();
-
- assertNotNull(patriarch);
- assertEquals(10, patriarch.getX1());
- assertEquals(20, patriarch.getY1());
- assertEquals(30, patriarch.getX2());
- assertEquals(40, patriarch.getY2());
-
- // Check the two groups too
- assertEquals(2, patriarch.countOfAllChildren());
- assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
- assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
-
- s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
- s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
-
- assertEquals(0, s1.getX1());
- assertEquals(0, s1.getY1());
- assertEquals(1023, s1.getX2());
- assertEquals(255, s1.getY2());
- assertEquals(0, s2.getX1());
- assertEquals(0, s2.getY1());
- assertEquals(1023, s2.getX2());
- assertEquals(255, s2.getY2());
-
- assertEquals(0, s1.getAnchor().getDx1());
- assertEquals(0, s1.getAnchor().getDy1());
- assertEquals(1022, s1.getAnchor().getDx2());
- assertEquals(255, s1.getAnchor().getDy2());
- assertEquals(20, s2.getAnchor().getDx1());
- assertEquals(30, s2.getAnchor().getDy1());
- assertEquals(500, s2.getAnchor().getDx2());
- assertEquals(200, s2.getAnchor().getDy2());
-
-
- // Write and re-load once more, to check that's ok
- workbook = writeOutAndReadBack(workbook);
- s = workbook.getSheetAt(0);
- patriarch = s.getDrawingPatriarch();
-
- assertNotNull(patriarch);
- assertEquals(10, patriarch.getX1());
- assertEquals(20, patriarch.getY1());
- assertEquals(30, patriarch.getX2());
- assertEquals(40, patriarch.getY2());
-
- // Check the two groups too
- assertEquals(2, patriarch.countOfAllChildren());
- assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
- assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
-
- s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
- s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
-
- assertEquals(0, s1.getX1());
- assertEquals(0, s1.getY1());
- assertEquals(1023, s1.getX2());
- assertEquals(255, s1.getY2());
- assertEquals(0, s2.getX1());
- assertEquals(0, s2.getY1());
- assertEquals(1023, s2.getX2());
- assertEquals(255, s2.getY2());
-
- assertEquals(0, s1.getAnchor().getDx1());
- assertEquals(0, s1.getAnchor().getDy1());
- assertEquals(1022, s1.getAnchor().getDx2());
- assertEquals(255, s1.getAnchor().getDy2());
- assertEquals(20, s2.getAnchor().getDx1());
- assertEquals(30, s2.getAnchor().getDy1());
- assertEquals(500, s2.getAnchor().getDx2());
- assertEquals(200, s2.getAnchor().getDy2());
-
- // Change the positions of the first groups,
- // but not of their anchors
- s1.setCoordinates(2, 3, 1021, 242);
-
- workbook = writeOutAndReadBack(workbook);
- s = workbook.getSheetAt(0);
- patriarch = s.getDrawingPatriarch();
-
- assertNotNull(patriarch);
- assertEquals(10, patriarch.getX1());
- assertEquals(20, patriarch.getY1());
- assertEquals(30, patriarch.getX2());
- assertEquals(40, patriarch.getY2());
-
- // Check the two groups too
- assertEquals(2, patriarch.countOfAllChildren());
- assertEquals(2, patriarch.getChildren().size());
- assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
- assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
-
- s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
- s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
-
- assertEquals(2, s1.getX1());
- assertEquals(3, s1.getY1());
- assertEquals(1021, s1.getX2());
- assertEquals(242, s1.getY2());
- assertEquals(0, s2.getX1());
- assertEquals(0, s2.getY1());
- assertEquals(1023, s2.getX2());
- assertEquals(255, s2.getY2());
-
- assertEquals(0, s1.getAnchor().getDx1());
- assertEquals(0, s1.getAnchor().getDy1());
- assertEquals(1022, s1.getAnchor().getDx2());
- assertEquals(255, s1.getAnchor().getDy2());
- assertEquals(20, s2.getAnchor().getDx1());
- assertEquals(30, s2.getAnchor().getDy1());
- assertEquals(500, s2.getAnchor().getDx2());
- assertEquals(200, s2.getAnchor().getDy2());
-
-
- // Now add some text to one group, and some more
- // to the base, and check we can get it back again
- HSSFTextbox tbox1 =
- patriarch.createTextbox(new HSSFClientAnchor(1,2,3,4, (short)0,0,(short)0,0));
- tbox1.setString(new HSSFRichTextString("I am text box 1"));
- HSSFTextbox tbox2 =
- s2.createTextbox(new HSSFChildAnchor(41,42,43,44));
- tbox2.setString(new HSSFRichTextString("This is text box 2"));
-
- assertEquals(3, patriarch.getChildren().size());
-
-
- workbook = writeOutAndReadBack(workbook);
- s = workbook.getSheetAt(0);
- patriarch = s.getDrawingPatriarch();
-
- assertNotNull(patriarch);
- assertEquals(10, patriarch.getX1());
- assertEquals(20, patriarch.getY1());
- assertEquals(30, patriarch.getX2());
- assertEquals(40, patriarch.getY2());
-
- // Check the two groups and the text
- // Result of patriarch.countOfAllChildren() makes no sense:
- // Returns 4 for 2 empty groups + 1 TextBox.
- //assertEquals(3, patriarch.countOfAllChildren());
- assertEquals(3, patriarch.getChildren().size());
-
- // Should be two groups and a text
- assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
- assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
- assertTrue(patriarch.getChildren().get(2) instanceof HSSFTextbox);
-
- s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
- tbox1 = (HSSFTextbox)patriarch.getChildren().get(2);
-
- s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
-
- assertEquals(2, s1.getX1());
- assertEquals(3, s1.getY1());
- assertEquals(1021, s1.getX2());
- assertEquals(242, s1.getY2());
- assertEquals(0, s2.getX1());
- assertEquals(0, s2.getY1());
- assertEquals(1023, s2.getX2());
- assertEquals(255, s2.getY2());
-
- assertEquals(0, s1.getAnchor().getDx1());
- assertEquals(0, s1.getAnchor().getDy1());
- assertEquals(1022, s1.getAnchor().getDx2());
- assertEquals(255, s1.getAnchor().getDy2());
- assertEquals(20, s2.getAnchor().getDx1());
- assertEquals(30, s2.getAnchor().getDy1());
- assertEquals(500, s2.getAnchor().getDx2());
- assertEquals(200, s2.getAnchor().getDy2());
+ HSSFSheet s;
+ HSSFShapeGroup s1;
+ HSSFShapeGroup s2;
+
+ patriarch.setCoordinates(10, 20, 30, 40);
+
+ workbook = writeOutAndReadBack(workbook);
+ s = workbook.getSheetAt(0);
+ patriarch = s.getDrawingPatriarch();
+
+ assertNotNull(patriarch);
+ assertEquals(10, patriarch.getX1());
+ assertEquals(20, patriarch.getY1());
+ assertEquals(30, patriarch.getX2());
+ assertEquals(40, patriarch.getY2());
+
+ // Check the two groups too
+ assertEquals(2, patriarch.countOfAllChildren());
+ assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+ assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+
+ s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+ s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+
+ assertEquals(0, s1.getX1());
+ assertEquals(0, s1.getY1());
+ assertEquals(1023, s1.getX2());
+ assertEquals(255, s1.getY2());
+ assertEquals(0, s2.getX1());
+ assertEquals(0, s2.getY1());
+ assertEquals(1023, s2.getX2());
+ assertEquals(255, s2.getY2());
+
+ assertEquals(0, s1.getAnchor().getDx1());
+ assertEquals(0, s1.getAnchor().getDy1());
+ assertEquals(1022, s1.getAnchor().getDx2());
+ assertEquals(255, s1.getAnchor().getDy2());
+ assertEquals(20, s2.getAnchor().getDx1());
+ assertEquals(30, s2.getAnchor().getDy1());
+ assertEquals(500, s2.getAnchor().getDx2());
+ assertEquals(200, s2.getAnchor().getDy2());
+
+
+ // Write and re-load once more, to check that's ok
+ workbook = writeOutAndReadBack(workbook);
+ s = workbook.getSheetAt(0);
+ patriarch = s.getDrawingPatriarch();
+
+ assertNotNull(patriarch);
+ assertEquals(10, patriarch.getX1());
+ assertEquals(20, patriarch.getY1());
+ assertEquals(30, patriarch.getX2());
+ assertEquals(40, patriarch.getY2());
+
+ // Check the two groups too
+ assertEquals(2, patriarch.countOfAllChildren());
+ assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+ assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+
+ s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+ s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+
+ assertEquals(0, s1.getX1());
+ assertEquals(0, s1.getY1());
+ assertEquals(1023, s1.getX2());
+ assertEquals(255, s1.getY2());
+ assertEquals(0, s2.getX1());
+ assertEquals(0, s2.getY1());
+ assertEquals(1023, s2.getX2());
+ assertEquals(255, s2.getY2());
+
+ assertEquals(0, s1.getAnchor().getDx1());
+ assertEquals(0, s1.getAnchor().getDy1());
+ assertEquals(1022, s1.getAnchor().getDx2());
+ assertEquals(255, s1.getAnchor().getDy2());
+ assertEquals(20, s2.getAnchor().getDx1());
+ assertEquals(30, s2.getAnchor().getDy1());
+ assertEquals(500, s2.getAnchor().getDx2());
+ assertEquals(200, s2.getAnchor().getDy2());
+
+ // Change the positions of the first groups,
+ // but not of their anchors
+ s1.setCoordinates(2, 3, 1021, 242);
+
+ workbook = writeOutAndReadBack(workbook);
+ s = workbook.getSheetAt(0);
+ patriarch = s.getDrawingPatriarch();
+
+ assertNotNull(patriarch);
+ assertEquals(10, patriarch.getX1());
+ assertEquals(20, patriarch.getY1());
+ assertEquals(30, patriarch.getX2());
+ assertEquals(40, patriarch.getY2());
+
+ // Check the two groups too
+ assertEquals(2, patriarch.countOfAllChildren());
+ assertEquals(2, patriarch.getChildren().size());
+ assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+ assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+
+ s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+ s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+
+ assertEquals(2, s1.getX1());
+ assertEquals(3, s1.getY1());
+ assertEquals(1021, s1.getX2());
+ assertEquals(242, s1.getY2());
+ assertEquals(0, s2.getX1());
+ assertEquals(0, s2.getY1());
+ assertEquals(1023, s2.getX2());
+ assertEquals(255, s2.getY2());
+
+ assertEquals(0, s1.getAnchor().getDx1());
+ assertEquals(0, s1.getAnchor().getDy1());
+ assertEquals(1022, s1.getAnchor().getDx2());
+ assertEquals(255, s1.getAnchor().getDy2());
+ assertEquals(20, s2.getAnchor().getDx1());
+ assertEquals(30, s2.getAnchor().getDy1());
+ assertEquals(500, s2.getAnchor().getDx2());
+ assertEquals(200, s2.getAnchor().getDy2());
+
+
+ // Now add some text to one group, and some more
+ // to the base, and check we can get it back again
+ HSSFTextbox tbox1 =
+ patriarch.createTextbox(new HSSFClientAnchor(1,2,3,4, (short)0,0,(short)0,0));
+ tbox1.setString(new HSSFRichTextString("I am text box 1"));
+ HSSFTextbox tbox2 =
+ s2.createTextbox(new HSSFChildAnchor(41,42,43,44));
+ tbox2.setString(new HSSFRichTextString("This is text box 2"));
+
+ assertEquals(3, patriarch.getChildren().size());
+
+
+ workbook = writeOutAndReadBack(workbook);
+ s = workbook.getSheetAt(0);
+ patriarch = s.getDrawingPatriarch();
+
+ assertNotNull(patriarch);
+ assertEquals(10, patriarch.getX1());
+ assertEquals(20, patriarch.getY1());
+ assertEquals(30, patriarch.getX2());
+ assertEquals(40, patriarch.getY2());
+
+ // Check the two groups and the text
+ // Result of patriarch.countOfAllChildren() makes no sense:
+ // Returns 4 for 2 empty groups + 1 TextBox.
+ //assertEquals(3, patriarch.countOfAllChildren());
+ assertEquals(3, patriarch.getChildren().size());
+
+ // Should be two groups and a text
+ assertTrue(patriarch.getChildren().get(0) instanceof HSSFShapeGroup);
+ assertTrue(patriarch.getChildren().get(1) instanceof HSSFShapeGroup);
+ assertTrue(patriarch.getChildren().get(2) instanceof HSSFTextbox);
+
+ s1 = (HSSFShapeGroup)patriarch.getChildren().get(0);
+ tbox1 = (HSSFTextbox)patriarch.getChildren().get(2);
+
+ s2 = (HSSFShapeGroup)patriarch.getChildren().get(1);
+
+ assertEquals(2, s1.getX1());
+ assertEquals(3, s1.getY1());
+ assertEquals(1021, s1.getX2());
+ assertEquals(242, s1.getY2());
+ assertEquals(0, s2.getX1());
+ assertEquals(0, s2.getY1());
+ assertEquals(1023, s2.getX2());
+ assertEquals(255, s2.getY2());
+
+ assertEquals(0, s1.getAnchor().getDx1());
+ assertEquals(0, s1.getAnchor().getDy1());
+ assertEquals(1022, s1.getAnchor().getDx2());
+ assertEquals(255, s1.getAnchor().getDy2());
+ assertEquals(20, s2.getAnchor().getDx1());
+ assertEquals(30, s2.getAnchor().getDy1());
+ assertEquals(500, s2.getAnchor().getDx2());
+ assertEquals(200, s2.getAnchor().getDy2());
- // Not working just yet
- assertEquals("I am text box 1", tbox1.getString().getString());
+ // Not working just yet
+ assertEquals("I am text box 1", tbox1.getString().getString());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org