diff options
Diffstat (limited to 'src')
3 files changed, 32 insertions, 19 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 06a05b8..2ea9e29 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -684,11 +684,9 @@ public class DatabaseTest extends TestCase } } - public void testAncientDates() throws Exception + public void testAncientDatesWrite() throws Exception { - TimeZone tz = TimeZone.getTimeZone("America/New_York"); SimpleDateFormat sdf = DatabaseBuilder.createDateFormat("yyyy-MM-dd"); - sdf.getCalendar().setTimeZone(tz); List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", "1492-01-10", "1392-01-10"); @@ -697,7 +695,6 @@ public class DatabaseTest extends TestCase for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); db.setDateTimeType(DateTimeType.DATE); - db.setTimeZone(tz); Table table = newTable("test") .addColumn(newColumn("name", DataType.TEXT)) @@ -718,8 +715,23 @@ public class DatabaseTest extends TestCase db.close(); } + } + + /** + * Test ancient date handling against test database {@code oldDates*.accdb}. + */ + public void testAncientDatesRead() throws Exception + { + TimeZone tz = TimeZone.getTimeZone("America/New_York"); + SimpleDateFormat sdf = DatabaseBuilder.createDateFormat("yyyy-MM-dd"); + sdf.getCalendar().setTimeZone(tz); + + List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", + "1492-01-10", "1392-01-10"); + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.OLD_DATES)) { Database db = openCopy(testDB); + db.setTimeZone(tz); // explicitly set database time zone db.setDateTimeType(DateTimeType.DATE); Table t = db.getTable("Table1"); diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java index e2f76b7..4cea253 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java @@ -21,22 +21,20 @@ import java.time.LocalDateTime; import java.util.Calendar; import com.healthmarketscience.jackcess.expr.EvalException; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.eval; import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.toBD; +import junit.framework.AssertionFailedError; +import static junit.framework.TestCase.*; +import org.junit.Test; /** * * @author James Ahlborn */ -public class DefaultFunctionsTest extends TestCase +public class DefaultFunctionsTest { - public DefaultFunctionsTest(String name) { - super(name); - } - + @Test public void testFuncs() throws Exception { assertEval("foo", "=IIf(10 > 1, \"foo\", \"bar\")"); @@ -266,6 +264,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("13:37", "=FormatDateTime(#1/1/1973 1:37:25 PM#,4)"); } + @Test public void testFormat() throws Exception { assertEval("12345.6789", "=Format(12345.6789, 'General Number')"); @@ -330,6 +329,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); } + @Test public void testCustomFormat() throws Exception { assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); @@ -578,6 +578,7 @@ public class DefaultFunctionsTest extends TestCase } } + @Test public void testNumberFuncs() throws Exception { assertEval(1, "=Abs(1)"); @@ -619,6 +620,7 @@ public class DefaultFunctionsTest extends TestCase assertEval(-4, "=Round(-4, 2)"); } + @Test public void testDateFuncs() throws Exception { assertEval("1/2/2003", "=CStr(DateValue(#01/02/2003 7:00:00 AM#))"); @@ -775,6 +777,7 @@ public class DefaultFunctionsTest extends TestCase assertEval(-83421497, "=DateDiff('s',#11/3/2018 2:15:30 PM#,#3/13/2016 1:37:13 AM#)"); } + @Test public void testFinancialFuncs() throws Exception { assertEval("-9.57859403981306", "=CStr(NPer(0.12/12,-100,-1000))"); diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java index 4d26c1b..acc2a1a 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/NumberFormatterTest.java @@ -16,23 +16,19 @@ limitations under the License. package com.healthmarketscience.jackcess.impl.expr; - import java.math.BigDecimal; -import junit.framework.TestCase; - +import static junit.framework.TestCase.assertEquals; +import org.junit.Test; /** * * @author James Ahlborn */ -public class NumberFormatterTest extends TestCase +public class NumberFormatterTest { - public NumberFormatterTest(String name) { - super(name); - } - + @Test public void testDoubleFormat() throws Exception { assertEquals("894984737284944", NumberFormatter.format(894984737284944d)); @@ -60,6 +56,7 @@ public class NumberFormatterTest extends TestCase assertEquals("1.#QNAN", NumberFormatter.format(Double.NaN)); } + @Test public void testFloatFormat() throws Exception { assertEquals("8949847", NumberFormatter.format(8949847f)); @@ -87,6 +84,7 @@ public class NumberFormatterTest extends TestCase assertEquals("1.#QNAN", NumberFormatter.format(Float.NaN)); } + @Test public void testDecimalFormat() throws Exception { assertEquals("9874539485972.2342342234234", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234"))); |