git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1405 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-4.0.6
<value>${jackcess.testFormats}</value> | <value>${jackcess.testFormats}</value> | ||||
</property> | </property> | ||||
</systemProperties> | </systemProperties> | ||||
<argLine>-Duser.language=en -Duser.region=US</argLine> | |||||
</configuration> | </configuration> | ||||
</plugin> | </plugin> | ||||
</plugins> | </plugins> |
} | } | ||||
} | } | ||||
public void testAncientDates() throws Exception | |||||
public void testAncientDatesWrite() throws Exception | |||||
{ | { | ||||
TimeZone tz = TimeZone.getTimeZone("America/New_York"); | |||||
SimpleDateFormat sdf = DatabaseBuilder.createDateFormat("yyyy-MM-dd"); | SimpleDateFormat sdf = DatabaseBuilder.createDateFormat("yyyy-MM-dd"); | ||||
sdf.getCalendar().setTimeZone(tz); | |||||
List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", | List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", | ||||
"1492-01-10", "1392-01-10"); | "1492-01-10", "1392-01-10"); | ||||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | ||||
Database db = createMem(fileFormat); | Database db = createMem(fileFormat); | ||||
db.setDateTimeType(DateTimeType.DATE); | db.setDateTimeType(DateTimeType.DATE); | ||||
db.setTimeZone(tz); | |||||
Table table = newTable("test") | Table table = newTable("test") | ||||
.addColumn(newColumn("name", DataType.TEXT)) | .addColumn(newColumn("name", DataType.TEXT)) | ||||
db.close(); | 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)) { | for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.OLD_DATES)) { | ||||
Database db = openCopy(testDB); | Database db = openCopy(testDB); | ||||
db.setTimeZone(tz); // explicitly set database time zone | |||||
db.setDateTimeType(DateTimeType.DATE); | db.setDateTimeType(DateTimeType.DATE); | ||||
Table t = db.getTable("Table1"); | Table t = db.getTable("Table1"); |
import java.util.Calendar; | import java.util.Calendar; | ||||
import com.healthmarketscience.jackcess.expr.EvalException; | 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.eval; | ||||
import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.toBD; | 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 | * @author James Ahlborn | ||||
*/ | */ | ||||
public class DefaultFunctionsTest extends TestCase | |||||
public class DefaultFunctionsTest | |||||
{ | { | ||||
public DefaultFunctionsTest(String name) { | |||||
super(name); | |||||
} | |||||
@Test | |||||
public void testFuncs() throws Exception | public void testFuncs() throws Exception | ||||
{ | { | ||||
assertEval("foo", "=IIf(10 > 1, \"foo\", \"bar\")"); | assertEval("foo", "=IIf(10 > 1, \"foo\", \"bar\")"); | ||||
assertEval("13:37", "=FormatDateTime(#1/1/1973 1:37:25 PM#,4)"); | assertEval("13:37", "=FormatDateTime(#1/1/1973 1:37:25 PM#,4)"); | ||||
} | } | ||||
@Test | |||||
public void testFormat() throws Exception | public void testFormat() throws Exception | ||||
{ | { | ||||
assertEval("12345.6789", "=Format(12345.6789, 'General Number')"); | assertEval("12345.6789", "=Format(12345.6789, 'General Number')"); | ||||
assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); | assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); | ||||
} | } | ||||
@Test | |||||
public void testCustomFormat() throws Exception | public void testCustomFormat() throws Exception | ||||
{ | { | ||||
assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); | assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); | ||||
} | } | ||||
} | } | ||||
@Test | |||||
public void testNumberFuncs() throws Exception | public void testNumberFuncs() throws Exception | ||||
{ | { | ||||
assertEval(1, "=Abs(1)"); | assertEval(1, "=Abs(1)"); | ||||
assertEval(-4, "=Round(-4, 2)"); | assertEval(-4, "=Round(-4, 2)"); | ||||
} | } | ||||
@Test | |||||
public void testDateFuncs() throws Exception | public void testDateFuncs() throws Exception | ||||
{ | { | ||||
assertEval("1/2/2003", "=CStr(DateValue(#01/02/2003 7:00:00 AM#))"); | assertEval("1/2/2003", "=CStr(DateValue(#01/02/2003 7:00:00 AM#))"); | ||||
assertEval(-83421497, "=DateDiff('s',#11/3/2018 2:15:30 PM#,#3/13/2016 1:37:13 AM#)"); | assertEval(-83421497, "=DateDiff('s',#11/3/2018 2:15:30 PM#,#3/13/2016 1:37:13 AM#)"); | ||||
} | } | ||||
@Test | |||||
public void testFinancialFuncs() throws Exception | public void testFinancialFuncs() throws Exception | ||||
{ | { | ||||
assertEval("-9.57859403981306", "=CStr(NPer(0.12/12,-100,-1000))"); | assertEval("-9.57859403981306", "=CStr(NPer(0.12/12,-100,-1000))"); |
package com.healthmarketscience.jackcess.impl.expr; | package com.healthmarketscience.jackcess.impl.expr; | ||||
import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
import junit.framework.TestCase; | |||||
import static junit.framework.TestCase.assertEquals; | |||||
import org.junit.Test; | |||||
/** | /** | ||||
* | * | ||||
* @author James Ahlborn | * @author James Ahlborn | ||||
*/ | */ | ||||
public class NumberFormatterTest extends TestCase | |||||
public class NumberFormatterTest | |||||
{ | { | ||||
public NumberFormatterTest(String name) { | |||||
super(name); | |||||
} | |||||
@Test | |||||
public void testDoubleFormat() throws Exception | public void testDoubleFormat() throws Exception | ||||
{ | { | ||||
assertEquals("894984737284944", NumberFormatter.format(894984737284944d)); | assertEquals("894984737284944", NumberFormatter.format(894984737284944d)); | ||||
assertEquals("1.#QNAN", NumberFormatter.format(Double.NaN)); | assertEquals("1.#QNAN", NumberFormatter.format(Double.NaN)); | ||||
} | } | ||||
@Test | |||||
public void testFloatFormat() throws Exception | public void testFloatFormat() throws Exception | ||||
{ | { | ||||
assertEquals("8949847", NumberFormatter.format(8949847f)); | assertEquals("8949847", NumberFormatter.format(8949847f)); | ||||
assertEquals("1.#QNAN", NumberFormatter.format(Float.NaN)); | assertEquals("1.#QNAN", NumberFormatter.format(Float.NaN)); | ||||
} | } | ||||
@Test | |||||
public void testDecimalFormat() throws Exception | public void testDecimalFormat() throws Exception | ||||
{ | { | ||||
assertEquals("9874539485972.2342342234234", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234"))); | assertEquals("9874539485972.2342342234234", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234"))); |