aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2014-12-22 12:08:59 +0000
committerDominik Stadler <centic@apache.org>2014-12-22 12:08:59 +0000
commitdd25abcc68717e53e12cee42ebc8a6f207a9acff (patch)
tree2eeded7ebd7bdb34b93051657e3de277d58ecf0c /src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
parent6efbd16c7b32dfc7c6615362640b688f7e0d5a11 (diff)
downloadpoi-dd25abcc68717e53e12cee42ebc8a6f207a9acff.tar.gz
poi-dd25abcc68717e53e12cee42ebc8a6f207a9acff.zip
Bug 56595: Also switch the cache in DateUtil.isADateFormat() to ThreadLocals to not have another syncpoint here. Again only very little data is kept, so no memory bloat should happen because of this.
Also do more simple checks before actually looking at the cache git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647296 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 06ad051a38..08f21a5900 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -21,6 +21,7 @@
package org.apache.poi.ss.usermodel;
+import java.io.IOException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -158,7 +159,7 @@ public class TestDataFormatter extends TestCase {
String p2dp_n1dp_z0 = "00.00;(00.0);0";
String all2dpTSP = "00.00_x";
String p2dp_n2dpTSP = "00.00_x;(00.00)_x";
- String p2dp_n1dpTSP = "00.00_x;(00.0)_x";
+ //String p2dp_n1dpTSP = "00.00_x;(00.0)_x";
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, all2dp));
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, p2dp_n1dp));
@@ -493,20 +494,24 @@ public class TestDataFormatter extends TestCase {
assertEquals(" $- ", dfUS.formatRawCellContents(0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
}
- public void testErrors() {
+ public void testErrors() throws IOException {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
// Create a spreadsheet with some formula errors in it
Workbook wb = new HSSFWorkbook();
- Sheet s = wb.createSheet();
- Row r = s.createRow(0);
- Cell c = r.createCell(0, Cell.CELL_TYPE_ERROR);
-
- c.setCellErrorValue(FormulaError.DIV0.getCode());
- assertEquals(FormulaError.DIV0.getString(), dfUS.formatCellValue(c));
-
- c.setCellErrorValue(FormulaError.REF.getCode());
- assertEquals(FormulaError.REF.getString(), dfUS.formatCellValue(c));
+ try {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0, Cell.CELL_TYPE_ERROR);
+
+ c.setCellErrorValue(FormulaError.DIV0.getCode());
+ assertEquals(FormulaError.DIV0.getString(), dfUS.formatCellValue(c));
+
+ c.setCellErrorValue(FormulaError.REF.getCode());
+ assertEquals(FormulaError.REF.getString(), dfUS.formatCellValue(c));
+ } finally {
+ wb.close();
+ }
}
/**
@@ -607,4 +612,25 @@ public class TestDataFormatter extends TestCase {
assertTrue(e.getMessage().contains("Cannot format given Object as a Number"));
}
}
+
+ public void testIsADateFormat() {
+ // first check some cases that should not be a date, also call multiple times to ensure the cache is used
+ assertFalse(DateUtil.isADateFormat(-1, null));
+ assertFalse(DateUtil.isADateFormat(-1, null));
+ assertFalse(DateUtil.isADateFormat(123, null));
+ assertFalse(DateUtil.isADateFormat(123, ""));
+ assertFalse(DateUtil.isADateFormat(124, ""));
+ assertFalse(DateUtil.isADateFormat(-1, ""));
+ assertFalse(DateUtil.isADateFormat(-1, ""));
+ assertFalse(DateUtil.isADateFormat(-1, "nodateformat"));
+
+ // then also do the same for some valid date formats
+ assertTrue(DateUtil.isADateFormat(0x0e, null));
+ assertTrue(DateUtil.isADateFormat(0x2f, null));
+ assertTrue(DateUtil.isADateFormat(-1, "yyyy"));
+ assertTrue(DateUtil.isADateFormat(-1, "yyyy"));
+ assertTrue(DateUtil.isADateFormat(-1, "dd/mm/yy;[red]dd/mm/yy"));
+ assertTrue(DateUtil.isADateFormat(-1, "dd/mm/yy;[red]dd/mm/yy"));
+ assertTrue(DateUtil.isADateFormat(-1, "[h]"));
+ }
}