poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1747657 [5/7] - in /poi/trunk: ./ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/ss/formula/ src/java/org/apache/poi/ss/formula/functions/ src/java/org/apache/poi/ss/formula/ptg/ src/oox...
Date Fri, 10 Jun 2016 07:41:09 GMT
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java?rev=1747657&r1=1747656&r2=1747657&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java Fri Jun 10 07:41:09 2016
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
+
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
@@ -41,12 +43,15 @@ import org.junit.Test;
 import java.util.Arrays;
 
 public final class TestXSSFFormulaParser {
-	private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla) {
-		return FormulaParser.parse(fmla, fpb, FormulaType.CELL, -1);
-	}
+    private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla) {
+        return FormulaParser.parse(fmla, fpb, FormulaType.CELL, -1);
+    }
+    private static Ptg[] parse(FormulaParsingWorkbook fpb, String fmla, int rowIndex) {
+        return FormulaParser.parse(fmla, fpb, FormulaType.CELL, -1, rowIndex);
+    }
 
-	@Test
-    public void basicParsing() {
+    @Test
+    public void basicParsing() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -118,10 +123,12 @@ public final class TestXSSFFormulaParser
         assertEquals(AttrPtg.class,  ptgs[1].getClass());
         assertEquals("Sheet1!A1:B3", ptgs[0].toFormulaString());
         assertEquals("SUM",          ptgs[1].toFormulaString());
+
+        wb.close();
     }
 
-	@Test
-    public void builtInFormulas() {
+    @Test
+    public void builtInFormulas() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -134,10 +141,12 @@ public final class TestXSSFFormulaParser
         assertEquals(2, ptgs.length);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof IntPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof FuncPtg);
+
+        wb.close();
     }
     
     @Test
-    public void formaulReferncesSameWorkbook() {
+    public void formulaReferencesSameWorkbook() throws IOException {
         // Use a test file with "other workbook" style references
         //  to itself
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");
@@ -153,10 +162,12 @@ public final class TestXSSFFormulaParser
         assertEquals(null, ((NameXPxg)ptgs[0]).getSheetName());
         assertEquals("NR_Global_B2",((NameXPxg)ptgs[0]).getNameName());
         assertEquals("[0]!NR_Global_B2",((NameXPxg)ptgs[0]).toFormulaString());
+
+        wb.close();
     }
    
-	@Test
-    public void formulaReferencesOtherSheets() {
+    @Test
+    public void formulaReferencesOtherSheets() throws IOException {
         // Use a test file with the named ranges in place
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56737.xlsx");
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
@@ -193,10 +204,12 @@ public final class TestXSSFFormulaParser
         assertEquals(1, ptgs.length);
         assertEquals(NamePtg.class, ptgs[0].getClass());
         assertEquals("NR_Global_B2",((NamePtg)ptgs[0]).toFormulaString(fpb));
+
+        wb.close();
     }
     
     @Test
-    public void formulaReferencesOtherWorkbook() {
+    public void formulaReferencesOtherWorkbook() throws IOException {
         // Use a test file with the external linked table in place
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("ref-56737.xlsx");
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
@@ -228,6 +241,8 @@ public final class TestXSSFFormulaParser
         assertEquals(null, ((NameXPxg)ptgs[0]).getSheetName());
         assertEquals("NR_Global_B2",((NameXPxg)ptgs[0]).getNameName());
         assertEquals("[1]!NR_Global_B2",((NameXPxg)ptgs[0]).toFormulaString());
+
+        wb.close();
     }
     
     /**
@@ -241,7 +256,7 @@ public final class TestXSSFFormulaParser
      * (but not evaluate - that's elsewhere in the test suite)
      */
     @Test
-    public void multiSheetReferencesHSSFandXSSF() throws Exception {
+    public void multiSheetReferencesHSSFandXSSF() throws IOException {
         Workbook[] wbs = new Workbook[] {
                 HSSFTestDataSamples.openSampleWorkbook("55906-MultiSheetRefs.xls"),
                 XSSFTestDataSamples.openSampleWorkbook("55906-MultiSheetRefs.xlsx")
@@ -363,6 +378,8 @@ public final class TestXSSFFormulaParser
             newF = s1.getRow(0).createCell(11, Cell.CELL_TYPE_FORMULA);
             newF.setCellFormula("MIN(Sheet1:Sheet2!A1:B2)");
             assertEquals("MIN(Sheet1:Sheet2!A1:B2)", newF.getCellFormula());
+
+            wb.close();
         }
     }
 
@@ -374,7 +391,7 @@ public final class TestXSSFFormulaParser
     }
 
     @Test
-    public void test58648Single() {
+    public void test58648Single() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -384,10 +401,12 @@ public final class TestXSSFFormulaParser
                 2, ptgs.length);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg);
+
+        wb.close();
     }
 
     @Test
-    public void test58648Basic() {
+    public void test58648Basic() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -431,10 +450,12 @@ public final class TestXSSFFormulaParser
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[0] instanceof RefPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof ParenthesisPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof ParenthesisPtg);
+
+        wb.close();
     }
 
     @Test
-    public void test58648FormulaParsing() {
+    public void test58648FormulaParsing() throws IOException {
         Workbook wb = XSSFTestDataSamples.openSampleWorkbook("58648.xlsx");
 
         FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
@@ -460,10 +481,12 @@ public final class TestXSSFFormulaParser
         Cell cell = sheet.getRow(1).getCell(4);
 
         assertEquals(5d, cell.getNumericCellValue(), 0d);
+
+        wb.close();
     }
 
     @Test
-    public void testWhitespaceInFormula() {
+    public void testWhitespaceInFormula() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -505,10 +528,12 @@ public final class TestXSSFFormulaParser
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof AreaPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof IntersectionPtg);
+
+        wb.close();
     }
 
     @Test
-    public void testWhitespaceInComplexFormula() {
+    public void testWhitespaceInComplexFormula() throws IOException {
         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         Ptg[] ptgs;
@@ -529,5 +554,172 @@ public final class TestXSSFFormulaParser
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[1] instanceof RefPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[2] instanceof AreaPtg);
         assertTrue("Had " + Arrays.toString(ptgs), ptgs[3] instanceof NameXPxg);
+
+        wb.close();
+    }
+
+    @Test
+    public void parseStructuredReferences() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
+
+        XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
+        Ptg[] ptgs;
+
+        /*
+        The following cases are tested (copied from FormulaParser.parseStructuredReference)
+           1 Table1[col]
+           2 Table1[[#Totals],[col]]
+           3 Table1[#Totals]
+           4 Table1[#All]
+           5 Table1[#Data]
+           6 Table1[#Headers]
+           7 Table1[#Totals]
+           8 Table1[#This Row]
+           9 Table1[[#All],[col]]
+          10 Table1[[#Headers],[col]]
+          11 Table1[[#Totals],[col]]
+          12 Table1[[#All],[col1]:[col2]]
+          13 Table1[[#Data],[col1]:[col2]]
+          14 Table1[[#Headers],[col1]:[col2]]
+          15 Table1[[#Totals],[col1]:[col2]]
+          16 Table1[[#Headers],[#Data],[col2]]
+          17 Table1[[#This Row], [col1]]
+          18 Table1[ [col1]:[col2] ]
+        */
+
+        final String tbl = "\\_Prime.1";
+        final String noTotalsRowReason = ": Tables without a Totals row should return #REF! on [#Totals]";
+
+        ////// Case 1: Evaluate Table1[col] with apostrophe-escaped #-signs ////////
+        ptgs = parse(fpb, "SUM("+tbl+"[calc='#*'#])");
+        assertEquals(2, ptgs.length);
+
+        // Area3DPxg [sheet=Table ! A2:A7]
+        assertTrue(ptgs[0] instanceof Area3DPxg);
+        Area3DPxg ptg0 = (Area3DPxg) ptgs[0];
+        assertEquals("Table", ptg0.getSheetName());
+        assertEquals("A2:A7", ptg0.format2DRefAsString());
+        // Note: structured references are evaluated and resolved to regular 3D area references.
+        assertEquals("Table!A2:A7", ptg0.toFormulaString());
+
+        // AttrPtg [sum ]
+        assertTrue(ptgs[1] instanceof AttrPtg);
+        AttrPtg ptg1 = (AttrPtg) ptgs[1];
+        assertTrue(ptg1.isSum());
+
+        ////// Case 1: Evaluate "Table1[col]" ////////
+        ptgs = parse(fpb, tbl+"[Name]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[col]", "Table!B2:B7", ptgs[0].toFormulaString());
+
+        ////// Case 2: Evaluate "Table1[[#Totals],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Totals],[col]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Totals],[col]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]);
+
+        ////// Case 3: Evaluate "Table1[#Totals]" ////////
+        ptgs = parse(fpb, tbl+"[#Totals]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#Totals]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]);
+
+        ////// Case 4: Evaluate "Table1[#All]" ////////
+        ptgs = parse(fpb, tbl+"[#All]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#All]", "Table!A1:C7", ptgs[0].toFormulaString());
+
+        ////// Case 5: Evaluate "Table1[#Data]" (excludes Header and Data rows) ////////
+        ptgs = parse(fpb, tbl+"[#Data]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#Data]", "Table!A2:C7", ptgs[0].toFormulaString());
+
+        ////// Case 6: Evaluate "Table1[#Headers]" ////////
+        ptgs = parse(fpb, tbl+"[#Headers]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#Headers]", "Table!A1:C1", ptgs[0].toFormulaString());
+
+        ////// Case 7: Evaluate "Table1[#Totals]" ////////
+        ptgs = parse(fpb, tbl+"[#Totals]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#Totals]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]);
+
+        ////// Case 8: Evaluate "Table1[#This Row]" ////////
+        ptgs = parse(fpb, tbl+"[#This Row]", 2);
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#This Row]", "Table!A3:C3", ptgs[0].toFormulaString());
+
+        ////// Evaluate "Table1[@]" (equivalent to "Table1[#This Row]") ////////
+        ptgs = parse(fpb, tbl+"[@]", 2);
+        assertEquals(1, ptgs.length);
+        assertEquals("Table!A3:C3", ptgs[0].toFormulaString());
+
+        ////// Evaluate "Table1[#This Row]" when rowIndex is outside Table ////////
+        ptgs = parse(fpb, tbl+"[#This Row]", 10);
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[#This Row]", ErrPtg.VALUE_INVALID, ptgs[0]);
+
+        ////// Evaluate "Table1[@]" when rowIndex is outside Table ////////
+        ptgs = parse(fpb, tbl+"[@]", 10);
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[@]", ErrPtg.VALUE_INVALID, ptgs[0]);
+
+        ////// Evaluate "Table1[[#Data],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Data], [Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Data],[col]]", "Table!C2:C7", ptgs[0].toFormulaString());
+
+
+        ////// Case 9: Evaluate "Table1[[#All],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#All], [Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#All],[col]]", "Table!C1:C7", ptgs[0].toFormulaString());
+
+        ////// Case 10: Evaluate "Table1[[#Headers],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Headers], [Number]]");
+        assertEquals(1, ptgs.length);
+        // also acceptable: Table1!B1
+        assertEquals("Table1[[#Headers],[col]]", "Table!C1:C1", ptgs[0].toFormulaString());
+
+        ////// Case 11: Evaluate "Table1[[#Totals],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Totals],[Name]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Totals],[col]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]);
+
+        ////// Case 12: Evaluate "Table1[[#All],[col1]:[col2]]" ////////
+        ptgs = parse(fpb, tbl+"[[#All], [Name]:[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#All],[col1]:[col2]]", "Table!B1:C7", ptgs[0].toFormulaString());
+
+        ////// Case 13: Evaluate "Table1[[#Data],[col]:[col2]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Data], [Name]:[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Data],[col]:[col2]]", "Table!B2:C7", ptgs[0].toFormulaString());
+
+        ////// Case 14: Evaluate "Table1[[#Headers],[col1]:[col2]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Headers], [Name]:[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Headers],[col1]:[col2]]", "Table!B1:C1", ptgs[0].toFormulaString());
+
+        ////// Case 15: Evaluate "Table1[[#Totals],[col]:[col2]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Totals], [Name]:[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Totals],[col]:[col2]]" + noTotalsRowReason, ErrPtg.REF_INVALID, ptgs[0]);
+
+        ////// Case 16: Evaluate "Table1[[#Headers],[#Data],[col]]" ////////
+        ptgs = parse(fpb, tbl+"[[#Headers],[#Data],[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[#Headers],[#Data],[col]]", "Table!C1:C7", ptgs[0].toFormulaString());
+
+        ////// Case 17: Evaluate "Table1[[#This Row], [col1]]" ////////
+        ptgs = parse(fpb, tbl+"[[#This Row], [Number]]", 2);
+        assertEquals(1, ptgs.length);
+        // also acceptable: Table!C3
+        assertEquals("Table1[[#This Row], [col1]]", "Table!C3:C3", ptgs[0].toFormulaString());
+
+        ////// Case 18: Evaluate "Table1[[col]:[col2]]" ////////
+        ptgs = parse(fpb, tbl+"[[Name]:[Number]]");
+        assertEquals(1, ptgs.length);
+        assertEquals("Table1[[col]:[col2]]", "Table!B2:C7", ptgs[0].toFormulaString());
+
+        wb.close();
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1747657&r1=1747656&r2=1747657&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Fri Jun 10 07:41:09 2016
@@ -1137,7 +1137,7 @@ public final class TestXSSFSheet extends
     }
 
     /**
-     * See bug #50829
+     * See bug #50829 test data tables
      */
     @Test
     public void tables() throws IOException {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1747657&r1=1747656&r2=1747657&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Fri Jun 10 07:41:09 2016
@@ -79,432 +79,432 @@ import org.openxmlformats.schemas.spread
 
 public final class TestXSSFWorkbook extends BaseTestXWorkbook {
 
-	public TestXSSFWorkbook() {
-		super(XSSFITestDataProvider.instance);
-	}
-
-	/**
-	 * Tests that we can save, and then re-load a new document
-	 */
-	@Test
-	public void saveLoadNew() throws IOException, InvalidFormatException {
+    public TestXSSFWorkbook() {
+        super(XSSFITestDataProvider.instance);
+    }
+
+    /**
+     * Tests that we can save, and then re-load a new document
+     */
+    @Test
+    public void saveLoadNew() throws IOException, InvalidFormatException {
         XSSFWorkbook wb1 = new XSSFWorkbook();
 
-		//check that the default date system is set to 1900
-		CTWorkbookPr pr = wb1.getCTWorkbook().getWorkbookPr();
-		assertNotNull(pr);
-		assertTrue(pr.isSetDate1904());
-		assertFalse("XSSF must use the 1900 date system", pr.getDate1904());
-
-		Sheet sheet1 = wb1.createSheet("sheet1");
-		Sheet sheet2 = wb1.createSheet("sheet2");
-		wb1.createSheet("sheet3");
-
-		RichTextString rts = wb1.getCreationHelper().createRichTextString("hello world");
-
-		sheet1.createRow(0).createCell((short)0).setCellValue(1.2);
-		sheet1.createRow(1).createCell((short)0).setCellValue(rts);
-		sheet2.createRow(0);
-
-		assertEquals(0, wb1.getSheetAt(0).getFirstRowNum());
-		assertEquals(1, wb1.getSheetAt(0).getLastRowNum());
-		assertEquals(0, wb1.getSheetAt(1).getFirstRowNum());
-		assertEquals(0, wb1.getSheetAt(1).getLastRowNum());
-		assertEquals(0, wb1.getSheetAt(2).getFirstRowNum());
-		assertEquals(0, wb1.getSheetAt(2).getLastRowNum());
-
-		File file = TempFile.createTempFile("poi-", ".xlsx");
-		OutputStream out = new FileOutputStream(file);
-		wb1.write(out);
-		out.close();
-
-		// Check the package contains what we'd expect it to
-		OPCPackage pkg = OPCPackage.open(file.toString());
-		PackagePart wbRelPart =
-			pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
-		assertNotNull(wbRelPart);
-		assertTrue(wbRelPart.isRelationshipPart());
-		assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType());
-
-		PackagePart wbPart =
-			pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
-		// Links to the three sheets, shared strings and styles
-		assertTrue(wbPart.hasRelationships());
-		assertEquals(5, wbPart.getRelationships().size());
-		wb1.close();
+        //check that the default date system is set to 1900
+        CTWorkbookPr pr = wb1.getCTWorkbook().getWorkbookPr();
+        assertNotNull(pr);
+        assertTrue(pr.isSetDate1904());
+        assertFalse("XSSF must use the 1900 date system", pr.getDate1904());
+
+        Sheet sheet1 = wb1.createSheet("sheet1");
+        Sheet sheet2 = wb1.createSheet("sheet2");
+        wb1.createSheet("sheet3");
+
+        RichTextString rts = wb1.getCreationHelper().createRichTextString("hello world");
+
+        sheet1.createRow(0).createCell((short)0).setCellValue(1.2);
+        sheet1.createRow(1).createCell((short)0).setCellValue(rts);
+        sheet2.createRow(0);
+
+        assertEquals(0, wb1.getSheetAt(0).getFirstRowNum());
+        assertEquals(1, wb1.getSheetAt(0).getLastRowNum());
+        assertEquals(0, wb1.getSheetAt(1).getFirstRowNum());
+        assertEquals(0, wb1.getSheetAt(1).getLastRowNum());
+        assertEquals(0, wb1.getSheetAt(2).getFirstRowNum());
+        assertEquals(0, wb1.getSheetAt(2).getLastRowNum());
 
-		// Load back the XSSFWorkbook
-		@SuppressWarnings("resource")
+        File file = TempFile.createTempFile("poi-", ".xlsx");
+        OutputStream out = new FileOutputStream(file);
+        wb1.write(out);
+        out.close();
+
+        // Check the package contains what we'd expect it to
+        OPCPackage pkg = OPCPackage.open(file.toString());
+        PackagePart wbRelPart =
+            pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
+        assertNotNull(wbRelPart);
+        assertTrue(wbRelPart.isRelationshipPart());
+        assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType());
+
+        PackagePart wbPart =
+            pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
+        // Links to the three sheets, shared strings and styles
+        assertTrue(wbPart.hasRelationships());
+        assertEquals(5, wbPart.getRelationships().size());
+        wb1.close();
+
+        // Load back the XSSFWorkbook
+        @SuppressWarnings("resource")
         XSSFWorkbook wb2 = new XSSFWorkbook(pkg);
-		assertEquals(3, wb2.getNumberOfSheets());
-		assertNotNull(wb2.getSheetAt(0));
-		assertNotNull(wb2.getSheetAt(1));
-		assertNotNull(wb2.getSheetAt(2));
-
-		assertNotNull(wb2.getSharedStringSource());
-		assertNotNull(wb2.getStylesSource());
-
-		assertEquals(0, wb2.getSheetAt(0).getFirstRowNum());
-		assertEquals(1, wb2.getSheetAt(0).getLastRowNum());
-		assertEquals(0, wb2.getSheetAt(1).getFirstRowNum());
-		assertEquals(0, wb2.getSheetAt(1).getLastRowNum());
-		assertEquals(0, wb2.getSheetAt(2).getFirstRowNum());
-		assertEquals(0, wb2.getSheetAt(2).getLastRowNum());
-
-		sheet1 = wb2.getSheetAt(0);
-		assertEquals(1.2, sheet1.getRow(0).getCell(0).getNumericCellValue(), 0.0001);
-		assertEquals("hello world", sheet1.getRow(1).getCell(0).getRichStringCellValue().getString());
-
-		pkg.close();
-	}
-
-    @Test
-	public void existing() throws Exception {
-
-		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
-		assertNotNull(workbook.getSharedStringSource());
-		assertNotNull(workbook.getStylesSource());
-
-		// And check a few low level bits too
-		OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
-		PackagePart wbPart =
-			pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
-
-		// Links to the three sheets, shared, styles and themes
-		assertTrue(wbPart.hasRelationships());
-		assertEquals(6, wbPart.getRelationships().size());
-
-		pkg.close();
-		workbook.close();
-	}
-
-    @Test
-	public void getCellStyleAt() throws IOException{
-	 	XSSFWorkbook workbook = new XSSFWorkbook();
-	 	try {
-    		short i = 0;
-    		//get default style
-    		CellStyle cellStyleAt = workbook.getCellStyleAt(i);
-    		assertNotNull(cellStyleAt);
-
-    		//get custom style
-    		StylesTable styleSource = workbook.getStylesSource();
-    		XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
-    		XSSFFont font = new XSSFFont();
-    		font.setFontName("Verdana");
-    		customStyle.setFont(font);
-    		int x = styleSource.putStyle(customStyle);
-    		cellStyleAt = workbook.getCellStyleAt((short)x);
-    		assertNotNull(cellStyleAt);
-	 	} finally {
-	 	    workbook.close();
-	 	}
-	}
-
-    @Test
-	public void getFontAt() throws IOException{
-	 	XSSFWorkbook workbook = new XSSFWorkbook();
-	 	try {
-    		StylesTable styleSource = workbook.getStylesSource();
-    		short i = 0;
-    		//get default font
-    		Font fontAt = workbook.getFontAt(i);
-    		assertNotNull(fontAt);
-
-    		//get customized font
-    		XSSFFont customFont = new XSSFFont();
-    		customFont.setItalic(true);
-    		int x = styleSource.putFont(customFont);
-    		fontAt = workbook.getFontAt((short)x);
-    		assertNotNull(fontAt);
-	 	} finally {
-	 	    workbook.close();
-	 	}
-	}
-
-    @Test
-	public void getNumCellStyles() throws IOException{
-	 	XSSFWorkbook workbook = new XSSFWorkbook();
-	 	try {
-    		//get default cellStyles
-    		assertEquals(1, workbook.getNumCellStyles());
-	 	} finally {
-	 	    workbook.close();
-	 	}
-	}
-
-    @Test
-	public void loadSave() throws IOException {
-		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
-		assertEquals(3, workbook.getNumberOfSheets());
-		assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
-		assertNotNull(workbook.getSharedStringSource());
-		assertNotNull(workbook.getStylesSource());
-
-		// Write out, and check
-		// Load up again, check all still there
-		XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		assertEquals(3, wb2.getNumberOfSheets());
-		assertNotNull(wb2.getSheetAt(0));
-		assertNotNull(wb2.getSheetAt(1));
-		assertNotNull(wb2.getSheetAt(2));
-
-		assertEquals("dd/mm/yyyy", wb2.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
-		assertEquals("yyyy/mm/dd", wb2.getSheetAt(0).getRow(2).getCell(0).getRichStringCellValue().getString());
-		assertEquals("yyyy-mm-dd", wb2.getSheetAt(0).getRow(3).getCell(0).getRichStringCellValue().getString());
-		assertEquals("yy/mm/dd", wb2.getSheetAt(0).getRow(4).getCell(0).getRichStringCellValue().getString());
-		assertNotNull(wb2.getSharedStringSource());
-		assertNotNull(wb2.getStylesSource());
-
-		workbook.close();
-		wb2.close();
-	}
-
-    @Test
-	public void styles() throws IOException {
-		XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
-
-		StylesTable ss = wb1.getStylesSource();
-		assertNotNull(ss);
-		StylesTable st = ss;
-
-		// Has 8 number formats
-		assertEquals(8, st.getNumDataFormats());
-		// Has 2 fonts
-		assertEquals(2, st.getFonts().size());
-		// Has 2 fills
-		assertEquals(2, st.getFills().size());
-		// Has 1 border
-		assertEquals(1, st.getBorders().size());
-
-		// Add two more styles
-		assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
-				st.putNumberFormat("testFORMAT"));
-		assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
-				st.putNumberFormat("testFORMAT"));
-		assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 9,
-				st.putNumberFormat("testFORMAT2"));
-		assertEquals(10, st.getNumDataFormats());
-
-
-		// Save, load back in again, and check
-		XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
-		wb1.close();
-
-		ss = wb2.getStylesSource();
-		assertNotNull(ss);
-
-		assertEquals(10, st.getNumDataFormats());
-		assertEquals(2, st.getFonts().size());
-		assertEquals(2, st.getFills().size());
-		assertEquals(1, st.getBorders().size());
-		wb2.close();
-	}
-
-    @Test
-	public void incrementSheetId() throws IOException {
-		XSSFWorkbook wb = new XSSFWorkbook();
-		try {
-    		int sheetId = (int)wb.createSheet().sheet.getSheetId();
-    		assertEquals(1, sheetId);
-    		sheetId = (int)wb.createSheet().sheet.getSheetId();
-    		assertEquals(2, sheetId);
-
-    		//test file with gaps in the sheetId sequence
-    		XSSFWorkbook wbBack = XSSFTestDataSamples.openSampleWorkbook("47089.xlsm");
-    		try {
-        		int lastSheetId = (int)wbBack.getSheetAt(wbBack.getNumberOfSheets() - 1).sheet.getSheetId();
-        		sheetId = (int)wbBack.createSheet().sheet.getSheetId();
-        		assertEquals(lastSheetId+1, sheetId);
-    		} finally {
-    		    wbBack.close();
-    		}
-		} finally {
-		    wb.close();
-		}
-	}
-
-	/**
-	 *  Test setting of core properties such as Title and Author
-	 * @throws IOException
-	 */
-    @Test
-	public void workbookProperties() throws IOException {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		try {
-    		POIXMLProperties props = workbook.getProperties();
-    		assertNotNull(props);
-    		//the Application property must be set for new workbooks, see Bugzilla #47559
-    		assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
-
-    		PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
-    		assertNotNull(opcProps);
-
-    		opcProps.setTitleProperty("Testing Bugzilla #47460");
-    		assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
-    		opcProps.setCreatorProperty("poi-dev@poi.apache.org");
-
-    		XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-    		assertEquals("Apache POI", wbBack.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
-    		opcProps = wbBack.getProperties().getCoreProperties().getUnderlyingProperties();
-    		assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
-    		assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
-    		wbBack.close();
-		} finally {
-		    workbook.close();
-		}
-	}
-
-	/**
-	 * Verify that the attached test data was not modified. If this test method
-	 * fails, the test data is not working properly.
-	 */
-    @Test
-	public void bug47668() throws Exception {
-		XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx");
-		List<XSSFPictureData> allPictures = workbook.getAllPictures();
-		assertEquals(1, allPictures.size());
-
-		PackagePartName imagePartName = PackagingURIHelper
-				.createPartName("/xl/media/image1.jpeg");
-		PackagePart imagePart = workbook.getPackage().getPart(imagePartName);
-		assertNotNull(imagePart);
-
-		for (XSSFPictureData pictureData : allPictures) {
-			PackagePart picturePart = pictureData.getPackagePart();
-			assertSame(imagePart, picturePart);
-		}
-
-		XSSFSheet sheet0 = workbook.getSheetAt(0);
-		XSSFDrawing drawing0 = sheet0.createDrawingPatriarch();
-		XSSFPictureData pictureData0 = (XSSFPictureData) drawing0.getRelations().get(0);
-		byte[] data0 = pictureData0.getData();
-		CRC32 crc0 = new CRC32();
-		crc0.update(data0);
-
-		XSSFSheet sheet1 = workbook.getSheetAt(1);
-		XSSFDrawing drawing1 = sheet1.createDrawingPatriarch();
-		XSSFPictureData pictureData1 = (XSSFPictureData) drawing1.getRelations().get(0);
-		byte[] data1 = pictureData1.getData();
-		CRC32 crc1 = new CRC32();
-		crc1.update(data1);
-
-		assertEquals(crc0.getValue(), crc1.getValue());
-		workbook.close();
-	}
-
-	/**
-	 * When deleting a sheet make sure that we adjust sheet indices of named ranges
-	 */
-    @Test
-	public void bug47737() throws IOException {
-		XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
-		assertEquals(2, wb.getNumberOfNames());
-		assertNotNull(wb.getCalculationChain());
-
-		XSSFName nm0 = wb.getNameAt(0);
-		assertTrue(nm0.getCTName().isSetLocalSheetId());
-		assertEquals(0, nm0.getCTName().getLocalSheetId());
-
-		XSSFName nm1 = wb.getNameAt(1);
-		assertTrue(nm1.getCTName().isSetLocalSheetId());
-		assertEquals(1, nm1.getCTName().getLocalSheetId());
-
-		wb.removeSheetAt(0);
-		assertEquals(1, wb.getNumberOfNames());
-		XSSFName nm2 = wb.getNameAt(0);
-		assertTrue(nm2.getCTName().isSetLocalSheetId());
-		assertEquals(0, nm2.getCTName().getLocalSheetId());
-		//calculation chain is removed as well
-		assertNull(wb.getCalculationChain());
-		wb.close();
-
-	}
-
-	/**
-	 * Problems with XSSFWorkbook.removeSheetAt when workbook contains charts
-	 */
-    @Test
-	public void bug47813() throws IOException {
-		XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
-		assertEquals(3, wb1.getNumberOfSheets());
-		assertNotNull(wb1.getCalculationChain());
-
-		assertEquals("Numbers", wb1.getSheetName(0));
-		//the second sheet is of type 'chartsheet'
-		assertEquals("Chart", wb1.getSheetName(1));
-		assertTrue(wb1.getSheetAt(1) instanceof XSSFChartSheet);
-		assertEquals("SomeJunk", wb1.getSheetName(2));
-
-		wb1.removeSheetAt(2);
-		assertEquals(2, wb1.getNumberOfSheets());
-		assertNull(wb1.getCalculationChain());
-
-		XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
-		assertEquals(2, wb2.getNumberOfSheets());
-		assertNull(wb2.getCalculationChain());
-
-		assertEquals("Numbers", wb2.getSheetName(0));
-		assertEquals("Chart", wb2.getSheetName(1));
-		wb2.close();
-		wb1.close();
-	}
-
-	/**
-	 * Problems with the count of the number of styles
-	 *  coming out wrong
-	 */
-    @Test
-	public void bug49702() throws IOException {
-	    // First try with a new file
-	    XSSFWorkbook wb1 = new XSSFWorkbook();
-
-	    // Should have one style
-	    assertEquals(1, wb1.getNumCellStyles());
-	    wb1.getCellStyleAt((short)0);
-	    try {
-	        wb1.getCellStyleAt((short)1);
-	        fail("Shouldn't be able to get style at 1 that doesn't exist");
-	    } catch(IndexOutOfBoundsException e) {}
-
-	    // Add another one
-	    CellStyle cs = wb1.createCellStyle();
-	    cs.setDataFormat((short)11);
-
-	    // Re-check
-	    assertEquals(2, wb1.getNumCellStyles());
-	    wb1.getCellStyleAt((short)0);
-	    wb1.getCellStyleAt((short)1);
-	    try {
-	        wb1.getCellStyleAt((short)2);
-	        fail("Shouldn't be able to get style at 2 that doesn't exist");
-	    } catch(IndexOutOfBoundsException e) {}
-
-	    // Save and reload
-	    XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb1);
-	    assertEquals(2, nwb.getNumCellStyles());
-	    nwb.getCellStyleAt((short)0);
-	    nwb.getCellStyleAt((short)1);
-	    try {
-	        nwb.getCellStyleAt((short)2);
-	        fail("Shouldn't be able to get style at 2 that doesn't exist");
-	    } catch(IndexOutOfBoundsException e) {}
-
-	    // Now with an existing file
-	    XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
-	    assertEquals(3, wb2.getNumCellStyles());
-	    wb2.getCellStyleAt((short)0);
-	    wb2.getCellStyleAt((short)1);
-	    wb2.getCellStyleAt((short)2);
-	    try {
-	        wb2.getCellStyleAt((short)3);
-	        fail("Shouldn't be able to get style at 3 that doesn't exist");
-	    } catch(IndexOutOfBoundsException e) {}
-
-	    wb2.close();
-	    wb1.close();
-	    nwb.close();
-	}
+        assertEquals(3, wb2.getNumberOfSheets());
+        assertNotNull(wb2.getSheetAt(0));
+        assertNotNull(wb2.getSheetAt(1));
+        assertNotNull(wb2.getSheetAt(2));
+
+        assertNotNull(wb2.getSharedStringSource());
+        assertNotNull(wb2.getStylesSource());
+
+        assertEquals(0, wb2.getSheetAt(0).getFirstRowNum());
+        assertEquals(1, wb2.getSheetAt(0).getLastRowNum());
+        assertEquals(0, wb2.getSheetAt(1).getFirstRowNum());
+        assertEquals(0, wb2.getSheetAt(1).getLastRowNum());
+        assertEquals(0, wb2.getSheetAt(2).getFirstRowNum());
+        assertEquals(0, wb2.getSheetAt(2).getLastRowNum());
+
+        sheet1 = wb2.getSheetAt(0);
+        assertEquals(1.2, sheet1.getRow(0).getCell(0).getNumericCellValue(), 0.0001);
+        assertEquals("hello world", sheet1.getRow(1).getCell(0).getRichStringCellValue().getString());
+
+        pkg.close();
+    }
+
+    @Test
+    public void existing() throws Exception {
+
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+        assertNotNull(workbook.getSharedStringSource());
+        assertNotNull(workbook.getStylesSource());
+
+        // And check a few low level bits too
+        OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
+        PackagePart wbPart =
+            pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
+
+        // Links to the three sheets, shared, styles and themes
+        assertTrue(wbPart.hasRelationships());
+        assertEquals(6, wbPart.getRelationships().size());
+
+        pkg.close();
+        workbook.close();
+    }
+
+    @Test
+    public void getCellStyleAt() throws IOException{
+         XSSFWorkbook workbook = new XSSFWorkbook();
+         try {
+            short i = 0;
+            //get default style
+            CellStyle cellStyleAt = workbook.getCellStyleAt(i);
+            assertNotNull(cellStyleAt);
+
+            //get custom style
+            StylesTable styleSource = workbook.getStylesSource();
+            XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
+            XSSFFont font = new XSSFFont();
+            font.setFontName("Verdana");
+            customStyle.setFont(font);
+            int x = styleSource.putStyle(customStyle);
+            cellStyleAt = workbook.getCellStyleAt((short)x);
+            assertNotNull(cellStyleAt);
+         } finally {
+             workbook.close();
+         }
+    }
+
+    @Test
+    public void getFontAt() throws IOException{
+         XSSFWorkbook workbook = new XSSFWorkbook();
+         try {
+            StylesTable styleSource = workbook.getStylesSource();
+            short i = 0;
+            //get default font
+            Font fontAt = workbook.getFontAt(i);
+            assertNotNull(fontAt);
+
+            //get customized font
+            XSSFFont customFont = new XSSFFont();
+            customFont.setItalic(true);
+            int x = styleSource.putFont(customFont);
+            fontAt = workbook.getFontAt((short)x);
+            assertNotNull(fontAt);
+         } finally {
+             workbook.close();
+         }
+    }
+
+    @Test
+    public void getNumCellStyles() throws IOException{
+         XSSFWorkbook workbook = new XSSFWorkbook();
+         try {
+            //get default cellStyles
+            assertEquals(1, workbook.getNumCellStyles());
+         } finally {
+             workbook.close();
+         }
+    }
+
+    @Test
+    public void loadSave() throws IOException {
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+        assertEquals(3, workbook.getNumberOfSheets());
+        assertEquals("dd/mm/yyyy", workbook.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
+        assertNotNull(workbook.getSharedStringSource());
+        assertNotNull(workbook.getStylesSource());
+
+        // Write out, and check
+        // Load up again, check all still there
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        assertEquals(3, wb2.getNumberOfSheets());
+        assertNotNull(wb2.getSheetAt(0));
+        assertNotNull(wb2.getSheetAt(1));
+        assertNotNull(wb2.getSheetAt(2));
+
+        assertEquals("dd/mm/yyyy", wb2.getSheetAt(0).getRow(1).getCell(0).getRichStringCellValue().getString());
+        assertEquals("yyyy/mm/dd", wb2.getSheetAt(0).getRow(2).getCell(0).getRichStringCellValue().getString());
+        assertEquals("yyyy-mm-dd", wb2.getSheetAt(0).getRow(3).getCell(0).getRichStringCellValue().getString());
+        assertEquals("yy/mm/dd", wb2.getSheetAt(0).getRow(4).getCell(0).getRichStringCellValue().getString());
+        assertNotNull(wb2.getSharedStringSource());
+        assertNotNull(wb2.getStylesSource());
+
+        workbook.close();
+        wb2.close();
+    }
+
+    @Test
+    public void styles() throws IOException {
+        XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+
+        StylesTable ss = wb1.getStylesSource();
+        assertNotNull(ss);
+        StylesTable st = ss;
+
+        // Has 8 number formats
+        assertEquals(8, st.getNumDataFormats());
+        // Has 2 fonts
+        assertEquals(2, st.getFonts().size());
+        // Has 2 fills
+        assertEquals(2, st.getFills().size());
+        // Has 1 border
+        assertEquals(1, st.getBorders().size());
+
+        // Add two more styles
+        assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
+                st.putNumberFormat("testFORMAT"));
+        assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
+                st.putNumberFormat("testFORMAT"));
+        assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 9,
+                st.putNumberFormat("testFORMAT2"));
+        assertEquals(10, st.getNumDataFormats());
+
+
+        // Save, load back in again, and check
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
+        wb1.close();
+
+        ss = wb2.getStylesSource();
+        assertNotNull(ss);
+
+        assertEquals(10, st.getNumDataFormats());
+        assertEquals(2, st.getFonts().size());
+        assertEquals(2, st.getFills().size());
+        assertEquals(1, st.getBorders().size());
+        wb2.close();
+    }
+
+    @Test
+    public void incrementSheetId() throws IOException {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        try {
+            int sheetId = (int)wb.createSheet().sheet.getSheetId();
+            assertEquals(1, sheetId);
+            sheetId = (int)wb.createSheet().sheet.getSheetId();
+            assertEquals(2, sheetId);
+
+            //test file with gaps in the sheetId sequence
+            XSSFWorkbook wbBack = XSSFTestDataSamples.openSampleWorkbook("47089.xlsm");
+            try {
+                int lastSheetId = (int)wbBack.getSheetAt(wbBack.getNumberOfSheets() - 1).sheet.getSheetId();
+                sheetId = (int)wbBack.createSheet().sheet.getSheetId();
+                assertEquals(lastSheetId+1, sheetId);
+            } finally {
+                wbBack.close();
+            }
+        } finally {
+            wb.close();
+        }
+    }
+
+    /**
+     *  Test setting of core properties such as Title and Author
+     * @throws IOException
+     */
+    @Test
+    public void workbookProperties() throws IOException {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        try {
+            POIXMLProperties props = workbook.getProperties();
+            assertNotNull(props);
+            //the Application property must be set for new workbooks, see Bugzilla #47559
+            assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
+
+            PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
+            assertNotNull(opcProps);
+
+            opcProps.setTitleProperty("Testing Bugzilla #47460");
+            assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
+            opcProps.setCreatorProperty("poi-dev@poi.apache.org");
+
+            XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+            assertEquals("Apache POI", wbBack.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
+            opcProps = wbBack.getProperties().getCoreProperties().getUnderlyingProperties();
+            assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
+            assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
+            wbBack.close();
+        } finally {
+            workbook.close();
+        }
+    }
+
+    /**
+     * Verify that the attached test data was not modified. If this test method
+     * fails, the test data is not working properly.
+     */
+    @Test
+    public void bug47668() throws Exception {
+        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx");
+        List<XSSFPictureData> allPictures = workbook.getAllPictures();
+        assertEquals(1, allPictures.size());
+
+        PackagePartName imagePartName = PackagingURIHelper
+                .createPartName("/xl/media/image1.jpeg");
+        PackagePart imagePart = workbook.getPackage().getPart(imagePartName);
+        assertNotNull(imagePart);
+
+        for (XSSFPictureData pictureData : allPictures) {
+            PackagePart picturePart = pictureData.getPackagePart();
+            assertSame(imagePart, picturePart);
+        }
+
+        XSSFSheet sheet0 = workbook.getSheetAt(0);
+        XSSFDrawing drawing0 = sheet0.createDrawingPatriarch();
+        XSSFPictureData pictureData0 = (XSSFPictureData) drawing0.getRelations().get(0);
+        byte[] data0 = pictureData0.getData();
+        CRC32 crc0 = new CRC32();
+        crc0.update(data0);
+
+        XSSFSheet sheet1 = workbook.getSheetAt(1);
+        XSSFDrawing drawing1 = sheet1.createDrawingPatriarch();
+        XSSFPictureData pictureData1 = (XSSFPictureData) drawing1.getRelations().get(0);
+        byte[] data1 = pictureData1.getData();
+        CRC32 crc1 = new CRC32();
+        crc1.update(data1);
+
+        assertEquals(crc0.getValue(), crc1.getValue());
+        workbook.close();
+    }
+
+    /**
+     * When deleting a sheet make sure that we adjust sheet indices of named ranges
+     */
+    @Test
+    public void bug47737() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("47737.xlsx");
+        assertEquals(2, wb.getNumberOfNames());
+        assertNotNull(wb.getCalculationChain());
+
+        XSSFName nm0 = wb.getNameAt(0);
+        assertTrue(nm0.getCTName().isSetLocalSheetId());
+        assertEquals(0, nm0.getCTName().getLocalSheetId());
+
+        XSSFName nm1 = wb.getNameAt(1);
+        assertTrue(nm1.getCTName().isSetLocalSheetId());
+        assertEquals(1, nm1.getCTName().getLocalSheetId());
+
+        wb.removeSheetAt(0);
+        assertEquals(1, wb.getNumberOfNames());
+        XSSFName nm2 = wb.getNameAt(0);
+        assertTrue(nm2.getCTName().isSetLocalSheetId());
+        assertEquals(0, nm2.getCTName().getLocalSheetId());
+        //calculation chain is removed as well
+        assertNull(wb.getCalculationChain());
+        wb.close();
+
+    }
+
+    /**
+     * Problems with XSSFWorkbook.removeSheetAt when workbook contains charts
+     */
+    @Test
+    public void bug47813() throws IOException {
+        XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("47813.xlsx");
+        assertEquals(3, wb1.getNumberOfSheets());
+        assertNotNull(wb1.getCalculationChain());
+
+        assertEquals("Numbers", wb1.getSheetName(0));
+        //the second sheet is of type 'chartsheet'
+        assertEquals("Chart", wb1.getSheetName(1));
+        assertTrue(wb1.getSheetAt(1) instanceof XSSFChartSheet);
+        assertEquals("SomeJunk", wb1.getSheetName(2));
+
+        wb1.removeSheetAt(2);
+        assertEquals(2, wb1.getNumberOfSheets());
+        assertNull(wb1.getCalculationChain());
+
+        XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
+        assertEquals(2, wb2.getNumberOfSheets());
+        assertNull(wb2.getCalculationChain());
+
+        assertEquals("Numbers", wb2.getSheetName(0));
+        assertEquals("Chart", wb2.getSheetName(1));
+        wb2.close();
+        wb1.close();
+    }
+
+    /**
+     * Problems with the count of the number of styles
+     *  coming out wrong
+     */
+    @Test
+    public void bug49702() throws IOException {
+        // First try with a new file
+        XSSFWorkbook wb1 = new XSSFWorkbook();
+
+        // Should have one style
+        assertEquals(1, wb1.getNumCellStyles());
+        wb1.getCellStyleAt((short)0);
+        try {
+            wb1.getCellStyleAt((short)1);
+            fail("Shouldn't be able to get style at 1 that doesn't exist");
+        } catch(IndexOutOfBoundsException e) {}
+
+        // Add another one
+        CellStyle cs = wb1.createCellStyle();
+        cs.setDataFormat((short)11);
+
+        // Re-check
+        assertEquals(2, wb1.getNumCellStyles());
+        wb1.getCellStyleAt((short)0);
+        wb1.getCellStyleAt((short)1);
+        try {
+            wb1.getCellStyleAt((short)2);
+            fail("Shouldn't be able to get style at 2 that doesn't exist");
+        } catch(IndexOutOfBoundsException e) {}
+
+        // Save and reload
+        XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb1);
+        assertEquals(2, nwb.getNumCellStyles());
+        nwb.getCellStyleAt((short)0);
+        nwb.getCellStyleAt((short)1);
+        try {
+            nwb.getCellStyleAt((short)2);
+            fail("Shouldn't be able to get style at 2 that doesn't exist");
+        } catch(IndexOutOfBoundsException e) {}
+
+        // Now with an existing file
+        XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
+        assertEquals(3, wb2.getNumCellStyles());
+        wb2.getCellStyleAt((short)0);
+        wb2.getCellStyleAt((short)1);
+        wb2.getCellStyleAt((short)2);
+        try {
+            wb2.getCellStyleAt((short)3);
+            fail("Shouldn't be able to get style at 3 that doesn't exist");
+        } catch(IndexOutOfBoundsException e) {}
+
+        wb2.close();
+        wb1.close();
+        nwb.close();
+    }
 
     @Test
     public void recalcId() throws IOException {
@@ -542,14 +542,14 @@ public final class TestXSSFWorkbook exte
     }
 
     @Test
-	public void columnWidthPOI52233() throws Exception {
-		XSSFWorkbook workbook = new XSSFWorkbook();
-		XSSFSheet sheet = workbook.createSheet();
-		XSSFRow row = sheet.createRow(0);
-		XSSFCell cell = row.createCell(0);
-		cell.setCellValue("hello world");
+    public void columnWidthPOI52233() throws Exception {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet = workbook.createSheet();
+        XSSFRow row = sheet.createRow(0);
+        XSSFCell cell = row.createCell(0);
+        cell.setCellValue("hello world");
 
-		sheet = workbook.createSheet();
+        sheet = workbook.createSheet();
         sheet.setColumnWidth(4, 5000);
         sheet.setColumnWidth(5, 5000);
 
@@ -557,114 +557,114 @@ public final class TestXSSFWorkbook exte
 
         accessWorkbook(workbook);
 
-		ByteArrayOutputStream stream = new ByteArrayOutputStream();
-		try {
-			workbook.write(stream);
-		} finally {
-			stream.close();
-		}
-
-		accessWorkbook(workbook);
-		workbook.close();
-	}
-
-	private void accessWorkbook(XSSFWorkbook workbook) {
-		workbook.getSheetAt(1).setColumnGroupCollapsed(4, true);
-		workbook.getSheetAt(1).setColumnGroupCollapsed(4, false);
-
-		assertEquals("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
-		assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
-	}
-
-    @Test
-	public void bug48495() throws IOException {
-		Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx");
-
-		assertSheetOrder(wb, "Sheet1");
-
-		Sheet sheet = wb.getSheetAt(0);
-		sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false);
-		Row newRow = sheet.getRow(2);
-		if (newRow == null) newRow = sheet.createRow(2);
-		newRow.createCell(0).setCellValue(" Another Header");
-		wb.cloneSheet(0);
-
-		assertSheetOrder(wb, "Sheet1", "Sheet1 (2)");
-
-		//		    FileOutputStream fileOut = new FileOutputStream("/tmp/bug48495.xlsx");
-//		    try {
-//		    	wb.write(fileOut);
-//		    } finally {
-//		    	fileOut.close();
-//		    }
-
-		Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
-		assertNotNull(read);
-		assertSheetOrder(read, "Sheet1", "Sheet1 (2)");
-		read.close();
-		wb.close();
-	}
-
-    @Test
-	public void bug47090a() throws IOException {
-	    Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
-		assertSheetOrder(workbook, "Sheet1", "Sheet2");
-	    workbook.removeSheetAt(0);
-		assertSheetOrder(workbook, "Sheet2");
-	    workbook.createSheet();
-		assertSheetOrder(workbook, "Sheet2", "Sheet1");
-	    Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		assertSheetOrder(read, "Sheet2", "Sheet1");
-		read.close();
-		workbook.close();
-	}
-
-    @Test
-	public void bug47090b() throws IOException {
-	    Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
-	    assertSheetOrder(workbook, "Sheet1", "Sheet2");
-	    workbook.removeSheetAt(1);
-		assertSheetOrder(workbook, "Sheet1");
-	    workbook.createSheet();
-		assertSheetOrder(workbook, "Sheet1", "Sheet0");		// Sheet0 because it uses "Sheet" + sheets.size() as starting point!
-	    Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		assertSheetOrder(read, "Sheet1", "Sheet0");
-		read.close();
-		workbook.close();
-	}
-
-    @Test
-	public void bug47090c() throws IOException {
-	    Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
-	    assertSheetOrder(workbook, "Sheet1", "Sheet2");
-	    workbook.removeSheetAt(0);
-		assertSheetOrder(workbook, "Sheet2");
-	    workbook.cloneSheet(0);
-		assertSheetOrder(workbook, "Sheet2", "Sheet2 (2)");
-	    Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		assertSheetOrder(read, "Sheet2", "Sheet2 (2)");
-		read.close();
-		workbook.close();
-	}
-
-    @Test
-	public void bug47090d() throws IOException {
-	    Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
-	    assertSheetOrder(workbook, "Sheet1", "Sheet2");
-	    workbook.createSheet();
-		assertSheetOrder(workbook, "Sheet1", "Sheet2", "Sheet0");
-	    workbook.removeSheetAt(0);
-		assertSheetOrder(workbook, "Sheet2", "Sheet0");
-	    workbook.createSheet();
-		assertSheetOrder(workbook, "Sheet2", "Sheet0", "Sheet1");
-	    Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
-		assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1");
-		read.close();
-		workbook.close();
-	}
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+        try {
+            workbook.write(stream);
+        } finally {
+            stream.close();
+        }
+
+        accessWorkbook(workbook);
+        workbook.close();
+    }
+
+    private void accessWorkbook(XSSFWorkbook workbook) {
+        workbook.getSheetAt(1).setColumnGroupCollapsed(4, true);
+        workbook.getSheetAt(1).setColumnGroupCollapsed(4, false);
+
+        assertEquals("hello world", workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+        assertEquals(2048, workbook.getSheetAt(0).getColumnWidth(0)); // <-works
+    }
+
+    @Test
+    public void bug48495() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("48495.xlsx");
+
+        assertSheetOrder(wb, "Sheet1");
+
+        Sheet sheet = wb.getSheetAt(0);
+        sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false);
+        Row newRow = sheet.getRow(2);
+        if (newRow == null) newRow = sheet.createRow(2);
+        newRow.createCell(0).setCellValue(" Another Header");
+        wb.cloneSheet(0);
+
+        assertSheetOrder(wb, "Sheet1", "Sheet1 (2)");
+
+        //            FileOutputStream fileOut = new FileOutputStream("/tmp/bug48495.xlsx");
+//            try {
+//                wb.write(fileOut);
+//            } finally {
+//                fileOut.close();
+//            }
+
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertNotNull(read);
+        assertSheetOrder(read, "Sheet1", "Sheet1 (2)");
+        read.close();
+        wb.close();
+    }
+
+    @Test
+    public void bug47090a() throws IOException {
+        Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
+        assertSheetOrder(workbook, "Sheet1", "Sheet2");
+        workbook.removeSheetAt(0);
+        assertSheetOrder(workbook, "Sheet2");
+        workbook.createSheet();
+        assertSheetOrder(workbook, "Sheet2", "Sheet1");
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        assertSheetOrder(read, "Sheet2", "Sheet1");
+        read.close();
+        workbook.close();
+    }
+
+    @Test
+    public void bug47090b() throws IOException {
+        Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
+        assertSheetOrder(workbook, "Sheet1", "Sheet2");
+        workbook.removeSheetAt(1);
+        assertSheetOrder(workbook, "Sheet1");
+        workbook.createSheet();
+        assertSheetOrder(workbook, "Sheet1", "Sheet0");        // Sheet0 because it uses "Sheet" + sheets.size() as starting point!
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        assertSheetOrder(read, "Sheet1", "Sheet0");
+        read.close();
+        workbook.close();
+    }
+
+    @Test
+    public void bug47090c() throws IOException {
+        Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
+        assertSheetOrder(workbook, "Sheet1", "Sheet2");
+        workbook.removeSheetAt(0);
+        assertSheetOrder(workbook, "Sheet2");
+        workbook.cloneSheet(0);
+        assertSheetOrder(workbook, "Sheet2", "Sheet2 (2)");
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        assertSheetOrder(read, "Sheet2", "Sheet2 (2)");
+        read.close();
+        workbook.close();
+    }
+
+    @Test
+    public void bug47090d() throws IOException {
+        Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx");
+        assertSheetOrder(workbook, "Sheet1", "Sheet2");
+        workbook.createSheet();
+        assertSheetOrder(workbook, "Sheet1", "Sheet2", "Sheet0");
+        workbook.removeSheetAt(0);
+        assertSheetOrder(workbook, "Sheet2", "Sheet0");
+        workbook.createSheet();
+        assertSheetOrder(workbook, "Sheet2", "Sheet0", "Sheet1");
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook);
+        assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1");
+        read.close();
+        workbook.close();
+    }
 
     @Test
-	public void bug51158() throws IOException {
+    public void bug51158() throws IOException {
         // create a workbook
         final XSSFWorkbook wb1 = new XSSFWorkbook();
         XSSFSheet sheet = wb1.createSheet("Test Sheet");
@@ -706,10 +706,10 @@ public final class TestXSSFWorkbook exte
         wb3.close();
         wb2.close();
         wb1.close();
-	}
+    }
 
     @Test
-	public void bug51158a() throws IOException {
+    public void bug51158a() throws IOException {
         // create a workbook
         final XSSFWorkbook workbook = new XSSFWorkbook();
         try {
@@ -1091,20 +1091,52 @@ public final class TestXSSFWorkbook exte
         //assertCloseDoesNotModifyFile(filename, wb);
     }
 
-	@Test
-	public void testCloseBeforeWrite() throws IOException {
-		Workbook wb = new XSSFWorkbook();
-		wb.createSheet("somesheet");
-
-		// test what happens if we close the Workbook before we write it out
-		wb.close();
-
-		try {
-			XSSFTestDataSamples.writeOutAndReadBack(wb);
-			fail("Expecting IOException here");
-		} catch (RuntimeException e) {
-			// expected here
-			assertTrue("Had: " + e.getCause(), e.getCause() instanceof IOException);
-		}
-	}
+    @Test
+    public void testCloseBeforeWrite() throws IOException {
+        Workbook wb = new XSSFWorkbook();
+        wb.createSheet("somesheet");
+
+        // test what happens if we close the Workbook before we write it out
+        wb.close();
+
+        try {
+            XSSFTestDataSamples.writeOutAndReadBack(wb);
+            fail("Expecting IOException here");
+        } catch (RuntimeException e) {
+            // expected here
+            assertTrue("Had: " + e.getCause(), e.getCause() instanceof IOException);
+        }
+    }
+
+    /**
+     * See bug #57840 test data tables
+     */
+    @Test
+    public void getTable() throws IOException {
+       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTable.xlsx");
+       XSSFTable table1 = wb.getTable("Tabella1");
+       assertNotNull("Tabella1 was not found in workbook", table1);
+       assertEquals("Table name", "Tabella1", table1.getName());
+       assertEquals("Sheet name", "Foglio1", table1.getSheetName());
+
+       // Table lookup should be case-insensitive
+       assertSame("Case insensitive table name lookup", table1, wb.getTable("TABELLA1"));
+
+       // If workbook does not contain any data tables matching the provided name, getTable should return null
+       assertNull("Null table name should not throw NPE", wb.getTable(null));
+       assertNull("Should not be able to find non-existent table", wb.getTable("Foglio1"));
+
+       // If a table is added after getTable is called it should still be reachable by XSSFWorkbook.getTable
+       // This test makes sure that if any caching is done that getTable never uses a stale cache
+       XSSFTable table2 = wb.getSheet("Foglio2").createTable();
+       table2.setName("Table2");
+       assertSame("Did not find Table2", table2, wb.getTable("Table2"));
+       
+       // If table name is modified after getTable is called, the table can only be found by its new name
+       // This test makes sure that if any caching is done that getTable never uses a stale cache
+       table1.setName("Table1");
+       assertSame("Did not find Tabella1 renamed to Table1", table1, wb.getTable("TABLE1"));
+
+       wb.close();
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/AllModelTests.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/AllModelTests.java?rev=1747657&r1=1747656&r2=1747657&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/AllModelTests.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/AllModelTests.java Fri Jun 10 07:41:09 2016
@@ -27,7 +27,7 @@ import org.junit.runners.Suite;
 @Suite.SuiteClasses({
     TestDrawingManager.class,
     TestDrawingManager2.class,
-    TestFormulaParser.class,
+    //TestFormulaParser.class, //converted to junit4
     TestFormulaParserEval.class,
     TestFormulaParserIf.class,
     TestLinkTable.class,



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


Mime
View raw message