diff options
author | Dominik Stadler <centic@apache.org> | 2024-04-17 18:15:46 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2024-04-17 18:15:46 +0000 |
commit | 9453fa908ae9a0c9a602725f4d5e1d6994b2b3f3 (patch) | |
tree | 388e0ae83e242efde7dabdc692f9e6317c40203e /poi-ooxml/src | |
parent | c4e8388742ab1e6818306df38aa0095742828f5d (diff) | |
download | poi-9453fa908ae9a0c9a602725f4d5e1d6994b2b3f3.tar.gz poi-9453fa908ae9a0c9a602725f4d5e1d6994b2b3f3.zip |
Bug 66425: Avoid exceptions found via poi-fuzz
Use correct default date-format, add some tests
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66381
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1917070 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java index fe4aa0a00a..bc6ddf0c62 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java @@ -21,6 +21,7 @@ import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; +import java.util.Date; import org.apache.poi.ss.formula.ConditionalFormattingEvaluator; import org.apache.poi.ss.formula.WorkbookEvaluatorProvider; @@ -120,4 +121,37 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat { assertEquals("6.75", formatter.formatCellValue(d1)); } } + + @Test + public void testFormatCellValue() throws IOException { + DataFormatter df = new DataFormatter(); + + assertEquals("", df.formatCellValue(null)); + + try (Workbook wb = new XSSFWorkbook()) { + Cell cell = wb.createSheet("test").createRow(0).createCell(0); + assertEquals("", df.formatCellValue(cell)); + + cell.setCellValue(123); + assertEquals("123", df.formatCellValue(cell)); + + cell.setCellValue(new Date(234092383)); + assertEquals("25571.75107", df.formatCellValue(cell)); + + cell.setCellValue("abcdefgh"); + assertEquals("abcdefgh", df.formatCellValue(cell)); + + cell.setCellValue(true); + assertEquals("TRUE", df.formatCellValue(cell)); + + CellStyle cellStyle = wb.createCellStyle(); + cellStyle.setDataFormat((short)14); + cell.setCellStyle(cellStyle); + cell.setCellValue(new Date(234092383)); + assertEquals("1/3/70", df.formatCellValue(cell)); + + cellStyle.setDataFormat((short)9999); + assertEquals("25571.751069247686", df.formatCellValue(cell)); + } + } } |