From: Nick Burch Date: Wed, 26 May 2010 14:51:49 +0000 (+0000) Subject: Add unit test to show that the behaviour in bug #48923 is as expected X-Git-Tag: REL_3_7_BETA1~54 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=93449602c572ecd8008053a1d4c19c7e7294779f;p=poi.git Add unit test to show that the behaviour in bug #48923 is as expected git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@948462 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index f521cb53ba..ea2c8fd59f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -24,6 +24,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; +import org.apache.poi.ss.usermodel.Name; import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFTestDataSamples; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; @@ -158,4 +159,38 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { CTWorksheet sh = wb.getSheetAt(0).getCTWorksheet(); assertNotNull(sh.getPhoneticPr()); } + + /** + * Names which are defined with a Sheet + * should return that sheet index properly + */ + public void test48923() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48923.xlsx"); + assertEquals(4, wb.getNumberOfNames()); + + Name b1 = wb.getName("NameB1"); + Name b2 = wb.getName("NameB2"); + Name sheet2 = wb.getName("NameSheet2"); + Name test = wb.getName("Test"); + + assertNotNull(b1); + assertEquals("NameB1", b1.getNameName()); + assertEquals("Sheet1", b1.getSheetName()); + assertEquals(-1, b1.getSheetIndex()); + + assertNotNull(b2); + assertEquals("NameB2", b2.getNameName()); + assertEquals("Sheet1", b2.getSheetName()); + assertEquals(-1, b2.getSheetIndex()); + + assertNotNull(sheet2); + assertEquals("NameSheet2", sheet2.getNameName()); + assertEquals("Sheet2", sheet2.getSheetName()); + assertEquals(-1, sheet2.getSheetIndex()); + + assertNotNull(test); + assertEquals("Test", test.getNameName()); + assertEquals("Sheet1", test.getSheetName()); + assertEquals(-1, test.getSheetIndex()); + } } diff --git a/test-data/spreadsheet/48923.xlsx b/test-data/spreadsheet/48923.xlsx new file mode 100644 index 0000000000..34aba5902b Binary files /dev/null and b/test-data/spreadsheet/48923.xlsx differ