bug 58775: fix a>b which should be a>=b; use shorts instead of ints to hold number format index

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1721923 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2015-12-28 14:19:50 +00:00
parent f3c14d82a6
commit 0849d8c34a

View File

@ -38,17 +38,20 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
public void test49928() { public void test49928() {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("49928.xlsx");
doTest49928Core(wb); doTest49928Core(wb);
DataFormat dataFormat = wb.createDataFormat();
// an attempt to register an existing format returns its index // As of 2015-12-27, there is no way to override a built-in number format with POI XSSFWorkbook
int poundFmtIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getDataFormat(); // 49928.xlsx has been saved with a poundFmt that overrides the default value (dollar)
assertEquals(poundFmtIdx, wb.getStylesSource().putNumberFormat(poundFmt)); short poundFmtIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getDataFormat();
assertEquals(poundFmtIdx, dataFormat.getFormat(poundFmt));
// now create a custom format with Pound (\u00a3) // now create a custom format with Pound (\u00a3)
DataFormat dataFormat = wb.createDataFormat();
String customFmt = "\u00a3##.00[Yellow]"; String customFmt = "\u00a3##.00[Yellow]";
assertNotBuiltInFormat(customFmt); assertNotBuiltInFormat(customFmt);
short customFmtIdx = dataFormat.getFormat(customFmt); short customFmtIdx = dataFormat.getFormat(customFmt);
assertTrue(customFmtIdx > BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX ); assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX);
assertEquals(customFmt, dataFormat.getFormat(customFmtIdx)); assertEquals(customFmt, dataFormat.getFormat(customFmtIdx));
} }