From 0aed737c34ad1a7155111a42ea241dccd7c0f29f Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 20 Jun 2016 04:21:26 +0000 Subject: [PATCH] whitespace (tabs to 4 spaces) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749264 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/TestXSSFSheetShiftRows.java | 206 +++++++++--------- .../ss/usermodel/BaseTestSheetShiftRows.java | 26 +-- 2 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java index a3da6c7c24..a477d586cc 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java @@ -44,115 +44,115 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { @Override @Test - public void testShiftRowBreaks() { + public void testShiftRowBreaks() { // disabled test from superclass // TODO - support shifting of page breaks } @Test - public void testBug54524() throws IOException { + public void testBug54524() throws IOException { XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx"); XSSFSheet sheet = workbook.getSheetAt(0); - sheet.shiftRows(3, 5, -1); + sheet.shiftRows(3, 5, -1); Cell cell = CellUtil.getCell(sheet.getRow(1), 0); - assertEquals(1.0, cell.getNumericCellValue(), 0); - cell = CellUtil.getCell(sheet.getRow(2), 0); - assertEquals("SUM(A2:A2)", cell.getCellFormula()); - cell = CellUtil.getCell(sheet.getRow(3), 0); - assertEquals("X", cell.getStringCellValue()); - workbook.close(); - } + assertEquals(1.0, cell.getNumericCellValue(), 0); + cell = CellUtil.getCell(sheet.getRow(2), 0); + assertEquals("SUM(A2:A2)", cell.getCellFormula()); + cell = CellUtil.getCell(sheet.getRow(3), 0); + assertEquals("X", cell.getStringCellValue()); + workbook.close(); + } @Test - public void testBug53798() throws IOException { - // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected - Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx"); - - Sheet testSheet = wb.getSheetAt(0); - // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about - // when shifted by less than -1 negative amount (try -2) - testSheet.shiftRows(3, 3, -2); - - Row newRow = null; Cell newCell = null; - // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted - // xlsx file with unreadable data in the negative shifted row. - // NOTE it's ok to create any other row. - newRow = testSheet.createRow(3); - newCell = newRow.createCell(0); - newCell.setCellValue("new Cell in row "+newRow.getRowNum()); - - // 3) once a negative shift has been made any attempt to shift another group of rows - // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception: - // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException. - // NOTE: another negative shift on another group of rows is successful, provided no new rows in - // place of previously shifted rows were attempted to be created as explained above. - - // -- CHANGE the shift to positive once the behaviour of the above has been tested - testSheet.shiftRows(6, 7, 1); - - Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); - wb.close(); - assertNotNull(read); - - Sheet readSheet = read.getSheetAt(0); - verifyCellContent(readSheet, 0, "0.0"); - verifyCellContent(readSheet, 1, "3.0"); - verifyCellContent(readSheet, 2, "2.0"); - verifyCellContent(readSheet, 3, "new Cell in row 3"); - verifyCellContent(readSheet, 4, "4.0"); - verifyCellContent(readSheet, 5, "5.0"); - verifyCellContent(readSheet, 6, null); - verifyCellContent(readSheet, 7, "6.0"); - verifyCellContent(readSheet, 8, "7.0"); - read.close(); - } - - private void verifyCellContent(Sheet readSheet, int row, String expect) { - Row readRow = readSheet.getRow(row); - if(expect == null) { - assertNull(readRow); - return; - } - Cell readCell = readRow.getCell(0); - if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) { - assertEquals(expect, Double.toString(readCell.getNumericCellValue())); - } else { - assertEquals(expect, readCell.getStringCellValue()); - } - } - - @Test - public void testBug53798a() throws IOException { - Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx"); - - Sheet testSheet = wb.getSheetAt(0); - testSheet.shiftRows(3, 3, -1); + public void testBug53798() throws IOException { + // NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx"); + + Sheet testSheet = wb.getSheetAt(0); + // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about + // when shifted by less than -1 negative amount (try -2) + testSheet.shiftRows(3, 3, -2); + + Row newRow = null; Cell newCell = null; + // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted + // xlsx file with unreadable data in the negative shifted row. + // NOTE it's ok to create any other row. + newRow = testSheet.createRow(3); + newCell = newRow.createCell(0); + newCell.setCellValue("new Cell in row "+newRow.getRowNum()); + + // 3) once a negative shift has been made any attempt to shift another group of rows + // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception: + // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException. + // NOTE: another negative shift on another group of rows is successful, provided no new rows in + // place of previously shifted rows were attempted to be created as explained above. + + // -- CHANGE the shift to positive once the behaviour of the above has been tested + testSheet.shiftRows(6, 7, 1); + + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); + wb.close(); + assertNotNull(read); + + Sheet readSheet = read.getSheetAt(0); + verifyCellContent(readSheet, 0, "0.0"); + verifyCellContent(readSheet, 1, "3.0"); + verifyCellContent(readSheet, 2, "2.0"); + verifyCellContent(readSheet, 3, "new Cell in row 3"); + verifyCellContent(readSheet, 4, "4.0"); + verifyCellContent(readSheet, 5, "5.0"); + verifyCellContent(readSheet, 6, null); + verifyCellContent(readSheet, 7, "6.0"); + verifyCellContent(readSheet, 8, "7.0"); + read.close(); + } + + private void verifyCellContent(Sheet readSheet, int row, String expect) { + Row readRow = readSheet.getRow(row); + if(expect == null) { + assertNull(readRow); + return; + } + Cell readCell = readRow.getCell(0); + if(readCell.getCellType() == Cell.CELL_TYPE_NUMERIC) { + assertEquals(expect, Double.toString(readCell.getNumericCellValue())); + } else { + assertEquals(expect, readCell.getStringCellValue()); + } + } + + @Test + public void testBug53798a() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx"); + + Sheet testSheet = wb.getSheetAt(0); + testSheet.shiftRows(3, 3, -1); for (Row r : testSheet) { - r.getRowNum(); + r.getRowNum(); } - testSheet.shiftRows(6, 6, 1); - - Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); - wb.close(); - assertNotNull(read); - - Sheet readSheet = read.getSheetAt(0); - verifyCellContent(readSheet, 0, "0.0"); - verifyCellContent(readSheet, 1, "1.0"); - verifyCellContent(readSheet, 2, "3.0"); - verifyCellContent(readSheet, 3, null); - verifyCellContent(readSheet, 4, "4.0"); - verifyCellContent(readSheet, 5, "5.0"); - verifyCellContent(readSheet, 6, null); - verifyCellContent(readSheet, 7, "6.0"); - verifyCellContent(readSheet, 8, "8.0"); - read.close(); - } - - @Test - public void testBug56017() throws IOException { - Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx"); + testSheet.shiftRows(6, 6, 1); + + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb); + wb.close(); + assertNotNull(read); + + Sheet readSheet = read.getSheetAt(0); + verifyCellContent(readSheet, 0, "0.0"); + verifyCellContent(readSheet, 1, "1.0"); + verifyCellContent(readSheet, 2, "3.0"); + verifyCellContent(readSheet, 3, null); + verifyCellContent(readSheet, 4, "4.0"); + verifyCellContent(readSheet, 5, "5.0"); + verifyCellContent(readSheet, 6, null); + verifyCellContent(readSheet, 7, "6.0"); + verifyCellContent(readSheet, 8, "8.0"); + read.close(); + } + + @Test + public void testBug56017() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx"); Sheet sheet = wb.getSheetAt(0); @@ -189,11 +189,11 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { assertEquals("Amdocs", comment.getAuthor()); assertEquals("Amdocs:\ntest\n", comment.getString().getString()); wbBack.close(); - } + } - @Test + @Test public void test57171() throws IOException { - Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); assertEquals(5, wb.getActiveSheetIndex()); removeAllSheetsBut(5, wb); // 5 is the active / selected sheet assertEquals(0, wb.getActiveSheetIndex()); @@ -208,7 +208,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { wbRead.close(); } - @Test + @Test public void test57163() throws IOException { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); assertEquals(5, wb.getActiveSheetIndex()); @@ -218,7 +218,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { wb.close(); } - @Test + @Test public void testSetSheetOrderAndAdjustActiveSheet() throws IOException { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); @@ -268,7 +268,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { wb.close(); } - @Test + @Test public void testRemoveSheetAndAdjustActiveSheet() throws IOException { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); @@ -312,7 +312,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows { wb.close(); } - @Test + @Test public void test57165() throws IOException { Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx"); assertEquals(5, wb.getActiveSheetIndex()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java index 7709552e2e..d06da8b458 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetShiftRows.java @@ -123,7 +123,7 @@ public abstract class BaseTestSheetShiftRows { @Test public final void testShiftRow() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); - Sheet s = wb.createSheet(); + Sheet s = wb.createSheet(); s.createRow(0).createCell(0).setCellValue("TEST1"); s.createRow(3).createCell(0).setCellValue("TEST2"); s.shiftRows(0,4,1); @@ -136,7 +136,7 @@ public abstract class BaseTestSheetShiftRows { @Test public final void testActiveCell() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); - Sheet s = wb.createSheet(); + Sheet s = wb.createSheet(); s.createRow(0).createCell(0).setCellValue("TEST1"); s.createRow(3).createCell(0).setCellValue("TEST2"); @@ -150,7 +150,7 @@ public abstract class BaseTestSheetShiftRows { @Test public void testShiftRowBreaks() throws IOException { // TODO - enable XSSF test Workbook wb = _testDataProvider.createWorkbook(); - Sheet s = wb.createSheet(); + Sheet s = wb.createSheet(); Row row = s.createRow(4); row.createCell(0).setCellValue("test"); s.setRowBreak(4); @@ -228,13 +228,13 @@ public abstract class BaseTestSheetShiftRows { // TODO: it seems HSSFSheet does not correctly remove comments from rows that are overwritten // by shifting rows... if(!(wb2 instanceof HSSFWorkbook)) { - assertEquals(2, sheet.getLastRowNum()); - - // Verify comments are in the position expected - assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()), - sheet.getCellComment(new CellAddress(0,0))); - assertNotNull(sheet.getCellComment(new CellAddress(1,0))); - assertNotNull(sheet.getCellComment(new CellAddress(2,0))); + assertEquals(2, sheet.getLastRowNum()); + + // Verify comments are in the position expected + assertNull("Had: " + (sheet.getCellComment(new CellAddress(0,0)) == null ? "null" : sheet.getCellComment(new CellAddress(0,0)).getString()), + sheet.getCellComment(new CellAddress(0,0))); + assertNotNull(sheet.getCellComment(new CellAddress(1,0))); + assertNotNull(sheet.getCellComment(new CellAddress(2,0))); } comment1 = sheet.getCellComment(new CellAddress(1,0)).getString().getString(); @@ -293,7 +293,7 @@ public abstract class BaseTestSheetShiftRows { @Test public final void testShiftWithMergedRegions() throws IOException { Workbook wb = _testDataProvider.createWorkbook(); - Sheet sheet = wb.createSheet(); + Sheet sheet = wb.createSheet(); Row row = sheet.createRow(0); row.createCell(0).setCellValue(1.1); row.createCell(1).setCellValue(2.2); @@ -481,7 +481,7 @@ public abstract class BaseTestSheetShiftRows { } @Test - public void testBug55280() throws IOException { + public void testBug55280() throws IOException { Workbook w = _testDataProvider.createWorkbook(); Sheet s = w.createSheet(); for (int row = 0; row < 5000; ++row) @@ -489,7 +489,7 @@ public abstract class BaseTestSheetShiftRows { s.shiftRows(0, 4999, 1); // takes a long time... w.close(); - } + } @Test public void test47169() throws IOException { -- 2.39.5