poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1829518 - /poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
Date Thu, 19 Apr 2018 08:37:17 GMT
Author: centic
Date: Thu Apr 19 08:37:17 2018
New Revision: 1829518

URL: http://svn.apache.org/viewvc?rev=1829518&view=rev
Log:
Add some unit-tests for setActiveCell(), although bug 61905 reports that Excel still does
not read this correctly for HSSF workbooks

Modified:
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java?rev=1829518&r1=1829517&r2=1829518&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java Thu Apr 19 08:37:17
2018
@@ -36,6 +36,7 @@ import java.util.Iterator;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
+import org.apache.poi.ss.util.CellAddress;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.NullOutputStream;
 import org.apache.poi.util.TempFile;
@@ -279,53 +280,66 @@ public abstract class BaseTestWorkbook {
 
     @Test
     public void removeSheetAt() throws IOException {
-        Workbook workbook = _testDataProvider.createWorkbook();
-        try {
+        try (Workbook workbook = _testDataProvider.createWorkbook()) {
             workbook.createSheet("sheet1");
             workbook.createSheet("sheet2");
             workbook.createSheet("sheet3");
             assertEquals(3, workbook.getNumberOfSheets());
-    
+
             assertEquals(0, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(1);
             assertEquals(2, workbook.getNumberOfSheets());
             assertEquals("sheet3", workbook.getSheetName(1));
             assertEquals(0, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(0);
             assertEquals(1, workbook.getNumberOfSheets());
             assertEquals("sheet3", workbook.getSheetName(0));
             assertEquals(0, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(0);
             assertEquals(0, workbook.getNumberOfSheets());
             assertEquals(0, workbook.getActiveSheetIndex());
-    
+
             //re-create the sheets
             workbook.createSheet("sheet1");
             workbook.createSheet("sheet2");
             workbook.createSheet("sheet3");
             workbook.createSheet("sheet4");
             assertEquals(4, workbook.getNumberOfSheets());
-    
+
             assertEquals(0, workbook.getActiveSheetIndex());
             workbook.setActiveSheet(2);
             assertEquals(2, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(2);
             assertEquals(2, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(1);
             assertEquals(1, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(0);
             assertEquals(0, workbook.getActiveSheetIndex());
-    
+
             workbook.removeSheetAt(0);
             assertEquals(0, workbook.getActiveSheetIndex());
-        } finally {
-            workbook.close();
+        }
+    }
+
+    @Test
+    public void testSetActiveCell() throws IOException {
+        try (Workbook wb = _testDataProvider.createWorkbook()) {
+            Sheet sheet = wb.createSheet("new sheet");
+            assertEquals(new CellAddress("A1"), sheet.getActiveCell());
+            sheet.setActiveCell(new CellAddress("E11"));
+            assertEquals(new CellAddress("E11"), sheet.getActiveCell());
+
+            Workbook wbr = _testDataProvider.writeOutAndReadBack(wb);
+            sheet = wbr.getSheet("new sheet");
+            assertEquals(new CellAddress("E11"), sheet.getActiveCell());
+
+            //wbr.write(new FileOutputStream("c:/temp/yyy." + _testDataProvider.getStandardFileNameExtension()));
         }
     }
 
@@ -619,7 +633,7 @@ public abstract class BaseTestWorkbook {
         wb2.close();
     }
 
-    private Workbook newSetSheetNameTestingWorkbook() throws IOException {
+    private Workbook newSetSheetNameTestingWorkbook() {
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sh1 = wb.createSheet("Worksheet");
         Sheet sh2 = wb.createSheet("Testing 47100");
@@ -797,11 +811,8 @@ public abstract class BaseTestWorkbook {
             c.setCellStyle(cs);
             c.setCellValue("AAA");                
         }
-        OutputStream os = new NullOutputStream();
-        try {
+        try (OutputStream os = new NullOutputStream()) {
             workbook.write(os);
-        } finally {
-            os.close();
         }
         //workbook.dispose();
         workbook.close();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message