diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2019-02-06 01:14:51 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2019-02-06 01:14:51 +0000 |
commit | d231efd46cd5f1e4c5c0fff850e10f860b7fced2 (patch) | |
tree | 184d70f9ca54fb22cdda8e600a505c0ec0d70f57 /src/test | |
parent | 67240a9bb59b3ddf05ce3833fde27de7d38b6ca5 (diff) | |
parent | 116fad0ad42bf89867091710d64ef8ef5d4ee0d4 (diff) | |
download | jackcess-d231efd46cd5f1e4c5c0fff850e10f860b7fced2.tar.gz jackcess-d231efd46cd5f1e4c5c0fff850e10f860b7fced2.zip |
merge branch jdk8 changes through r1279
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1280 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test')
16 files changed, 749 insertions, 187 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java b/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java index b4704bf..c8b81a3 100644 --- a/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java @@ -39,7 +39,8 @@ import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; * * @author James Ahlborn */ -public class ComplexColumnTest extends TestCase +@SuppressWarnings("deprecation") +public class ComplexColumnTest extends TestCase { public ComplexColumnTest(String name) { @@ -66,7 +67,7 @@ public class ComplexColumnTest extends TestCase (ComplexValueForeignKey)verCol.getRowValue(row); String curValue = (String)col.getRowValue(row); - + if(rowId.equals("row1")) { checkVersions(1, complexValueFk, curValue); } else if(rowId.equals("row2")) { @@ -94,7 +95,7 @@ public class ComplexColumnTest extends TestCase Date upTime = new Date(); row8ValFk.addVersion("row8-memo", upTime); checkVersions(row8ValFk.get(), row8ValFk, "row8-memo", - "row8-memo", upTime); + "row8-memo", upTime); Cursor cursor = CursorBuilder.createCursor(t1); assertTrue(cursor.findFirstRow(t1.getColumn("id"), "row3")); @@ -120,7 +121,7 @@ public class ComplexColumnTest extends TestCase "row3-memo-again", new Date(1315876965382L), "row3-memo-revised", new Date(1315876953077L), "row3-memo", new Date(1315876879126L)); - + try { v.delete(); fail("UnsupportedOperationException should have been thrown"); @@ -133,7 +134,7 @@ public class ComplexColumnTest extends TestCase "row3-memo-again", new Date(1315876965382L), "row3-memo-revised", new Date(1315876953077L), "row3-memo", new Date(1315876879126L)); - + try { v.getComplexValueForeignKey().deleteAllValues(); fail("UnsupportedOperationException should have been thrown"); @@ -146,7 +147,7 @@ public class ComplexColumnTest extends TestCase "row3-memo-again", new Date(1315876965382L), "row3-memo-revised", new Date(1315876953077L), "row3-memo", new Date(1315876879126L)); - + db.close(); } } @@ -154,7 +155,7 @@ public class ComplexColumnTest extends TestCase public void testAttachments() throws Exception { for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { - + Database db = openCopy(testDB); Table t1 = db.getTable("Table1"); @@ -187,12 +188,12 @@ public class ComplexColumnTest extends TestCase ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey) col.getRowValue(row8); row8ValFk.addAttachment(null, "test_data.txt", "txt", - getFileBytes("test_data.txt"), null, null); + getFileBytes("test_data.txt"), (Date)null, null); checkAttachments(row8ValFk.get(), row8ValFk, "test_data.txt"); row8ValFk.addEncodedAttachment(null, "test_data2.txt", "txt", - getEncodedFileBytes("test_data2.txt"), null, - null); - checkAttachments(row8ValFk.get(), row8ValFk, "test_data.txt", + getEncodedFileBytes("test_data2.txt"), + (Date)null, null); + checkAttachments(row8ValFk.get(), row8ValFk, "test_data.txt", "test_data2.txt"); Cursor cursor = CursorBuilder.createCursor(t1); @@ -200,8 +201,8 @@ public class ComplexColumnTest extends TestCase ComplexValueForeignKey row4ValFk = (ComplexValueForeignKey) cursor.getCurrentRowValue(col); Attachment a = row4ValFk.addAttachment(null, "test_data.txt", "txt", - getFileBytes("test_data.txt"), null, - null); + getFileBytes("test_data.txt"), + (Date)null, null); checkAttachments(4, row4ValFk, "test_data2.txt", "test_data.txt"); a.setFileType("zip"); @@ -230,8 +231,8 @@ public class ComplexColumnTest extends TestCase ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey) cursor.getCurrentRowValue(col); row2ValFk.deleteAllValues(); - checkAttachments(2, row2ValFk); - + checkAttachments(2, row2ValFk); + db.close(); } } @@ -239,7 +240,7 @@ public class ComplexColumnTest extends TestCase public void testMultiValues() throws Exception { for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { - + Database db = openCopy(testDB); Table t1 = db.getTable("Table1"); @@ -264,7 +265,7 @@ public class ComplexColumnTest extends TestCase } else { assertTrue(false); } - } + } Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo", Column.AUTO_NUMBER, Column.AUTO_NUMBER}; @@ -307,17 +308,17 @@ public class ComplexColumnTest extends TestCase PropertyMap props = col.getProperties(); assertEquals(Boolean.TRUE, props.getValue(PropertyMap.ALLOW_MULTI_VALUE_PROP)); assertEquals("Value List", props.getValue(PropertyMap.ROW_SOURCE_TYPE_PROP)); - assertEquals("\"value1\";\"value2\";\"value3\";\"value4\"", + assertEquals("\"value1\";\"value2\";\"value3\";\"value4\"", props.getValue(PropertyMap.ROW_SOURCE_PROP)); - + db.close(); } } - + public void testUnsupported() throws Exception { for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.UNSUPPORTED)) { - + Database db = openCopy(testDB); Table t1 = db.getTable("Test"); @@ -331,7 +332,7 @@ public class ComplexColumnTest extends TestCase (ComplexValueForeignKey)col.getRowValue(row); if(rowId.equals(1)) { - checkUnsupportedValues(1, complexValueFk, + checkUnsupportedValues(1, complexValueFk, "RawData[(5) FF FE 62 61 7A]"); } else if(rowId.equals(2)) { checkUnsupportedValues(2, complexValueFk, "RawData[(5) FF FE 66 6F 6F]", "RawData[(5) FF FE 62 61 7A]"); @@ -340,12 +341,12 @@ public class ComplexColumnTest extends TestCase } else { assertTrue(false); } - } - + } + db.close(); } } - + private static void checkVersions( int cValId, ComplexValueForeignKey complexValueFk, String curValue, Object... versionInfos) @@ -376,7 +377,7 @@ public class ComplexColumnTest extends TestCase throws Exception { assertEquals(cValId, complexValueFk.get()); - + List<Attachment> attachments = complexValueFk.getAttachments(); if(fileNames.length == 0) { assertTrue(attachments.isEmpty()); @@ -388,12 +389,12 @@ public class ComplexColumnTest extends TestCase assertEquals(fname, a.getFileName()); assertEquals("txt", a.getFileType()); assertTrue(Arrays.equals(getFileBytes(fname), a.getFileData())); - assertTrue(Arrays.equals(getEncodedFileBytes(fname), + assertTrue(Arrays.equals(getEncodedFileBytes(fname), a.getEncodedFileData())); } } } - + private static void checkMultiValues( int cValId, ComplexValueForeignKey complexValueFk, Object... expectedValues) @@ -411,7 +412,7 @@ public class ComplexColumnTest extends TestCase SingleValue v = values.get(i); assertEquals(value, v.get()); } - } + } } private static void checkUnsupportedValues( @@ -434,7 +435,7 @@ public class ComplexColumnTest extends TestCase assertTrue(ColumnImpl.isRawData(rv)); assertEquals(value, rv.toString()); } - } + } } private static byte[] getFileBytes(String fname) throws Exception @@ -447,7 +448,7 @@ public class ComplexColumnTest extends TestCase } throw new RuntimeException("unexpected bytes"); } - + private static byte[] getEncodedFileBytes(String fname) throws Exception { if("test_data.txt".equals(fname)) { @@ -458,9 +459,9 @@ public class ComplexColumnTest extends TestCase } throw new RuntimeException("unexpected bytes"); } - + private static byte b(int i) { return (byte)i; } - + private static byte[] getAsciiBytes(String str) { try { return str.getBytes("US-ASCII"); @@ -468,7 +469,7 @@ public class ComplexColumnTest extends TestCase throw new RuntimeException(e); } } - + private static final byte[] TEST_ENC_BYTES = new byte[] { b(0x01),b(0x00),b(0x00),b(0x00),b(0x3A),b(0x00),b(0x00),b(0x00),b(0x78),b(0x5E),b(0x13),b(0x61),b(0x60),b(0x60),b(0x60),b(0x04),b(0x62),b(0x16),b(0x20),b(0x2E),b(0x61),b(0xA8),b(0x00),b(0x62), b(0x20),b(0x9D),b(0x91),b(0x59),b(0xAC),b(0x00),b(0x44),b(0xC5),b(0xF9),b(0xB9),b(0xA9),b(0x0A),b(0x25),b(0xA9),b(0xC5),b(0x25),b(0x0A),b(0x29),b(0x89),b(0x25),b(0x89),b(0x0A),b(0x69),b(0xF9), @@ -476,7 +477,7 @@ public class ComplexColumnTest extends TestCase }; private static final byte[] TEST_BYTES = getAsciiBytes("this is some test data for attachment."); - + private static final byte[] TEST2_ENC_BYTES = new byte[] { b(0x01),b(0x00),b(0x00),b(0x00),b(0x3F),b(0x00),b(0x00),b(0x00),b(0x78),b(0x5E),b(0x13),b(0x61),b(0x60),b(0x60),b(0x60),b(0x04),b(0x62),b(0x16),b(0x20),b(0x2E),b(0x61),b(0xA8),b(0x00),b(0x62), b(0x20),b(0x9D),b(0x91),b(0x59),b(0xAC),b(0x00),b(0x44),b(0xC5),b(0xF9),b(0xB9),b(0xA9),b(0x0A),b(0xB9),b(0xF9),b(0x45),b(0xA9),b(0x0A),b(0x25),b(0xA9),b(0xC5),b(0x25),b(0x0A),b(0x29),b(0x89), @@ -484,5 +485,5 @@ public class ComplexColumnTest extends TestCase }; private static final byte[] TEST2_BYTES = getAsciiBytes("this is some more test data for attachment."); - + } diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 025e180..0a33a99 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -51,7 +52,8 @@ import static com.healthmarketscience.jackcess.TestUtil.*; /** * @author Tim McCune */ -public class DatabaseTest extends TestCase +@SuppressWarnings("deprecation") +public class DatabaseTest extends TestCase { public DatabaseTest(String name) throws Exception { super(name); @@ -114,7 +116,7 @@ public class DatabaseTest extends TestCase db.close(); } } - + public void testReadDeletedRows() throws Exception { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL, true)) { Table table = open(testDB).getTable("Table"); @@ -122,11 +124,11 @@ public class DatabaseTest extends TestCase while (table.getNextRow() != null) { rows++; } - assertEquals(2, rows); + assertEquals(2, rows); table.getDatabase().close(); } } - + public void testGetColumns() throws Exception { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { @@ -143,9 +145,9 @@ public class DatabaseTest extends TestCase checkColumn(columns, 8, "I", DataType.BOOLEAN); } } - + private static void checkColumn( - List<? extends Column> columns, int columnNumber, String name, + List<? extends Column> columns, int columnNumber, String name, DataType dataType) throws Exception { @@ -153,7 +155,7 @@ public class DatabaseTest extends TestCase assertEquals(name, column.getName()); assertEquals(dataType, column.getType()); } - + public void testGetNextRow() throws Exception { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { final Database db = open(testDB); @@ -183,7 +185,7 @@ public class DatabaseTest extends TestCase db.close(); } } - + public void testDeleteCurrentRow() throws Exception { // make sure correct row is deleted @@ -269,7 +271,7 @@ public class DatabaseTest extends TestCase table.reset(); List<Row> rows = RowFilterTest.toList(table); - + Row r1 = rows.remove(7); Row r2 = rows.remove(3); assertEquals(8, rows.size()); @@ -282,10 +284,10 @@ public class DatabaseTest extends TestCase table.deleteRow(r2); table.deleteRow(r1); - assertTable(rows, table); + assertTable(rows, table); } } - + public void testMissingFile() throws Exception { File bogusFile = new File("fooby-dooby.mdb"); assertTrue(!bogusFile.exists()); @@ -326,7 +328,7 @@ public class DatabaseTest extends TestCase } rowNum++; } - + table.getDatabase().close(); } } @@ -508,7 +510,7 @@ public class DatabaseTest extends TestCase db.close(); } - } + } public void testMultiPageTableDef() throws Exception { @@ -580,7 +582,7 @@ public class DatabaseTest extends TestCase db.close(); } - } + } public void testLargeTableDef() throws Exception { @@ -685,8 +687,8 @@ public class DatabaseTest extends TestCase 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", + + List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", "1492-01-10", "1392-01-10"); @@ -703,7 +705,7 @@ public class DatabaseTest extends TestCase Date d = sdf.parse(dateStr); table.addRow("row " + dateStr, d); } - + List<String> foundDates = new ArrayList<String>(); for(Row row : table) { foundDates.add(sdf.format(row.getDate("date"))); @@ -741,7 +743,7 @@ public class DatabaseTest extends TestCase sysTables.addAll( Arrays.asList("MSysObjects", "MSysQueries", "MSysACES", "MSysRelationships")); - + if (fileFormat == FileFormat.GENERIC_JET4) { assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); } else if (fileFormat.ordinal() < FileFormat.V2003.ordinal()) { @@ -766,11 +768,11 @@ public class DatabaseTest extends TestCase if(fileFormat.ordinal() >= FileFormat.V2010.ordinal()) { sysTables.add("f_12D7448B56564D8AAE333BCC9B3718E5_Data"); sysTables.add("MSysResources"); - } + } } assertEquals(sysTables, db.getSystemTableNames()); - + assertNotNull(db.getSystemTable("MSysObjects")); assertNotNull(db.getSystemTable("MSysQueries")); assertNotNull(db.getSystemTable("MSysACES")); @@ -782,7 +784,7 @@ public class DatabaseTest extends TestCase assertEquals("MSysObjects", tmd.getName()); assertFalse(tmd.isLinked()); assertTrue(tmd.isSystem()); - + db.close(); } } @@ -839,7 +841,7 @@ public class DatabaseTest extends TestCase "RawData[(12) FF FE 6F 74 68 65 72 20 64 61 74 61]", null); List<String> fixVals = Arrays.asList("RawData[(4) 37 00 00 00]", - "RawData[(4) F3 FF FF FF]", + "RawData[(4) F3 FF FF FF]", "RawData[(4) 02 00 00 00]"); int idx = 0; @@ -891,7 +893,8 @@ public class DatabaseTest extends TestCase Database linkeeDb = db.getLinkedDatabases().get(linkeeDbName); assertNotNull(linkeeDb); assertEquals(linkeeFile, linkeeDb.getFile()); - + assertEquals("linkeeTest.accdb", ((DatabaseImpl)linkeeDb).getName()); + List<? extends Map<String, Object>> expectedRows = createExpectedTable( createExpectedRow( @@ -900,7 +903,7 @@ public class DatabaseTest extends TestCase assertTable(expectedRows, t2); - db.createLinkedTable("FooTable", linkeeDbName, "Table2"); + db.createLinkedTable("FooTable", linkeeDbName, "Table2"); tmd = db.getTableMetaData("FooTable"); assertEquals("FooTable", tmd.getName()); @@ -929,7 +932,7 @@ public class DatabaseTest extends TestCase assertNull(tmd.getLinkedDbName()); Table t1 = tmd.open(db); - + assertFalse(db.isLinkedTable(null)); assertTrue(db.isLinkedTable(t2)); assertTrue(db.isLinkedTable(t3)); @@ -941,21 +944,21 @@ public class DatabaseTest extends TestCase assertTrue(tables.contains(t2)); assertTrue(tables.contains(t3)); assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); - + tables = getTables(db.newIterable().setIncludeNormalTables(false)); assertEquals(2, tables.size()); assertFalse(tables.contains(t1)); assertTrue(tables.contains(t2)); assertTrue(tables.contains(t3)); assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); - + tables = getTables(db.newIterable().withLocalUserTablesOnly()); assertEquals(1, tables.size()); assertTrue(tables.contains(t1)); assertFalse(tables.contains(t2)); assertFalse(tables.contains(t3)); assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); - + tables = getTables(db.newIterable().withSystemTablesOnly()); assertTrue(tables.size() > 5); assertFalse(tables.contains(t1)); @@ -975,7 +978,7 @@ public class DatabaseTest extends TestCase } return tableList; } - + public void testTimeZone() throws Exception { TimeZone tz = TimeZone.getTimeZone("America/New_York"); @@ -989,7 +992,13 @@ public class DatabaseTest extends TestCase { ColumnImpl col = new ColumnImpl(null, null, DataType.SHORT_DATE_TIME, 0, 0, 0) { @Override - protected Calendar getCalendar() { return Calendar.getInstance(tz); } + public TimeZone getTimeZone() { return tz; } + @Override + public ZoneId getZoneId() { return null; } + @Override + public ColumnImpl.DateTimeFactory getDateTimeFactory() { + return getDateTimeFactory(DateTimeType.DATE); + } }; SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd"); diff --git a/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java new file mode 100644 index 0000000..1eb11db --- /dev/null +++ b/src/test/java/com/healthmarketscience/jackcess/LocalDateTimeTest.java @@ -0,0 +1,275 @@ +/* +Copyright (c) 2018 James Ahlborn + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package com.healthmarketscience.jackcess; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import com.healthmarketscience.jackcess.impl.ColumnImpl; +import com.healthmarketscience.jackcess.impl.DatabaseImpl; +import junit.framework.TestCase; +import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import static com.healthmarketscience.jackcess.Database.*; + +/** + * + * @author James Ahlborn + */ +public class LocalDateTimeTest extends TestCase +{ + public LocalDateTimeTest(String name) throws Exception { + super(name); + } + + public void testWriteAndReadLocalDate() throws Exception { + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = createMem(fileFormat); + + db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); + + Table table = new TableBuilder("test") + .addColumn(new ColumnBuilder("name", DataType.TEXT)) + .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + .toTable(db); + + // since jackcess does not really store millis, shave them off before + // storing the current date/time + long curTimeNoMillis = (System.currentTimeMillis() / 1000L); + curTimeNoMillis *= 1000L; + + DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); + List<Date> dates = + new ArrayList<Date>( + Arrays.asList( + df.parse("19801231 00:00:00"), + df.parse("19930513 14:43:27"), + null, + df.parse("20210102 02:37:00"), + new Date(curTimeNoMillis))); + + Calendar c = Calendar.getInstance(); + for(int year = 1801; year < 2050; year +=3) { + for(int month = 0; month <= 12; ++month) { + for(int day = 1; day < 29; day += 3) { + c.clear(); + c.set(Calendar.YEAR, year); + c.set(Calendar.MONTH, month); + c.set(Calendar.DAY_OF_MONTH, day); + dates.add(c.getTime()); + } + } + } + + ((DatabaseImpl)db).getPageChannel().startWrite(); + try { + for(Date d : dates) { + table.addRow("row " + d, d); + } + } finally { + ((DatabaseImpl)db).getPageChannel().finishWrite(); + } + + List<LocalDateTime> foundDates = new ArrayList<LocalDateTime>(); + for(Row row : table) { + foundDates.add(row.getLocalDateTime("date")); + } + + assertEquals(dates.size(), foundDates.size()); + for(int i = 0; i < dates.size(); ++i) { + Date expected = dates.get(i); + LocalDateTime found = foundDates.get(i); + assertSameDate(expected, found); + } + + db.close(); + } + } + + public void testAncientLocalDates() throws Exception + { + ZoneId zoneId = ZoneId.of("America/New_York"); + DateTimeFormatter sdf = DateTimeFormatter.ofPattern("uuuu-MM-dd"); + + List<String> dates = Arrays.asList("1582-10-15", "1582-10-14", + "1492-01-10", "1392-01-10"); + + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = createMem(fileFormat); + db.setZoneId(zoneId); + db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); + + Table table = new TableBuilder("test") + .addColumn(new ColumnBuilder("name", DataType.TEXT)) + .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + .toTable(db); + + for(String dateStr : dates) { + LocalDate ld = LocalDate.parse(dateStr, sdf); + table.addRow("row " + dateStr, ld); + } + + List<String> foundDates = new ArrayList<String>(); + for(Row row : table) { + foundDates.add(sdf.format(row.getLocalDateTime("date"))); + } + + assertEquals(dates, foundDates); + + db.close(); + } + + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.OLD_DATES)) { + Database db = openCopy(testDB); + db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); + + Table t = db.getTable("Table1"); + + List<String> foundDates = new ArrayList<String>(); + for(Row row : t) { + foundDates.add(sdf.format(row.getLocalDateTime("DateField"))); + } + + assertEquals(dates, foundDates); + + db.close(); + } + + } + + public void testZoneId() throws Exception + { + ZoneId zoneId = ZoneId.of("America/New_York"); + doTestZoneId(zoneId); + + zoneId = ZoneId.of("Australia/Sydney"); + doTestZoneId(zoneId); + } + + private static void doTestZoneId(final ZoneId zoneId) throws Exception + { + final TimeZone tz = TimeZone.getTimeZone(zoneId); + ColumnImpl col = new ColumnImpl(null, null, DataType.SHORT_DATE_TIME, 0, 0, 0) { + @Override + public TimeZone getTimeZone() { return tz; } + @Override + public ZoneId getZoneId() { return zoneId; } + @Override + public ColumnImpl.DateTimeFactory getDateTimeFactory() { + return getDateTimeFactory(DateTimeType.LOCAL_DATE_TIME); + } + }; + + SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd"); + df.setTimeZone(tz); + + long startDate = df.parse("2012.01.01").getTime(); + long endDate = df.parse("2013.01.01").getTime(); + + Calendar curCal = Calendar.getInstance(tz); + curCal.setTimeInMillis(startDate); + + DateTimeFormatter sdf = DateTimeFormatter.ofPattern("uuuu.MM.dd HH:mm:ss"); + + while(curCal.getTimeInMillis() < endDate) { + Date curDate = curCal.getTime(); + LocalDateTime curLdt = LocalDateTime.ofInstant( + Instant.ofEpochMilli(curDate.getTime()), zoneId); + LocalDateTime newLdt = ColumnImpl.ldtFromLocalDateDouble( + col.toDateDouble(curDate)); + if(!curLdt.equals(newLdt)) { + System.out.println("FOO " + curLdt + " " + newLdt); + assertEquals(sdf.format(curLdt), sdf.format(newLdt)); + } + curCal.add(Calendar.MINUTE, 30); + } + } + + public void testWriteAndReadTemporals() throws Exception { + ZoneId zoneId = ZoneId.of("America/New_York"); + for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + Database db = createMem(fileFormat); + db.setZoneId(zoneId); + db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME); + + Table table = new TableBuilder("test") + .addColumn(new ColumnBuilder("name", DataType.TEXT)) + .addColumn(new ColumnBuilder("date", DataType.SHORT_DATE_TIME)) + .toTable(db); + + // since jackcess does not really store millis, shave them off before + // storing the current date/time + long curTimeNoMillis = (System.currentTimeMillis() / 1000L); + curTimeNoMillis *= 1000L; + + DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); + List<Date> tmpDates = + new ArrayList<Date>( + Arrays.asList( + df.parse("19801231 00:00:00"), + df.parse("19930513 14:43:27"), + df.parse("20210102 02:37:00"), + new Date(curTimeNoMillis))); + + List<Object> objs = new ArrayList<Object>(); + List<LocalDateTime> expected = new ArrayList<LocalDateTime>(); + for(Date d : tmpDates) { + Instant inst = Instant.ofEpochMilli(d.getTime()); + objs.add(inst); + ZonedDateTime zdt = inst.atZone(zoneId); + objs.add(zdt); + LocalDateTime ldt = zdt.toLocalDateTime(); + objs.add(ldt); + + for(int i = 0; i < 3; ++i) { + expected.add(ldt); + } + } + + ((DatabaseImpl)db).getPageChannel().startWrite(); + try { + for(Object o : objs) { + table.addRow("row " + o, o); + } + } finally { + ((DatabaseImpl)db).getPageChannel().finishWrite(); + } + + List<LocalDateTime> foundDates = new ArrayList<LocalDateTime>(); + for(Row row : table) { + foundDates.add(row.getLocalDateTime("date")); + } + + assertEquals(expected, foundDates); + + db.close(); + } + } + +} diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java index 384386e..bb26719 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertyExpressionTest.java @@ -294,8 +294,8 @@ public class PropertyExpressionTest extends TestCase public static void testCustomEvalConfig() throws Exception { - TemporalConfig tempConf = new TemporalConfig("yyyy/M/d", "M/d", - "yyyy-MMM-d", + TemporalConfig tempConf = new TemporalConfig("[uuuu/]M/d", + "uuuu-MMM-d", "hh.mm.ss a", "HH.mm.ss", '/', '.', Locale.US); diff --git a/src/test/java/com/healthmarketscience/jackcess/TableTest.java b/src/test/java/com/healthmarketscience/jackcess/TableTest.java index 339ba39..eaae617 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TableTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/TableTest.java @@ -21,8 +21,8 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.List; +import java.util.TimeZone; import com.healthmarketscience.jackcess.impl.ColumnImpl; import com.healthmarketscience.jackcess.impl.JetFormat; @@ -40,8 +40,8 @@ public class TableTest extends TestCase { private TestTable _testTable; private int _varLenIdx; private int _fixedOffset; - - + + public TableTest(String name) { super(name); } @@ -52,14 +52,14 @@ public class TableTest extends TestCase { _varLenIdx = 0; _fixedOffset = 0; } - + public void testCreateRow() throws Exception { reset(); newTestColumn(DataType.INT, false); newTestColumn(DataType.TEXT, false); newTestColumn(DataType.TEXT, false); newTestTable(); - + int colCount = _columns.size(); ByteBuffer buffer = createRow(9, "Tim", "McCune"); @@ -91,10 +91,10 @@ public class TableTest extends TestCase { newTestColumn(DataType.TEXT, true); newTestColumn(DataType.TEXT, true); newTestTable(); - + ByteBuffer[] bufCmp1 = encodeColumns(small, large); ByteBuffer[] bufCmp2 = encodeColumns(smallNotAscii, largeNotAscii); - + assertEquals(buf1[0].remaining(), (bufCmp1[0].remaining() + small.length() - 2)); assertEquals(buf1[1].remaining(), @@ -111,7 +111,7 @@ public class TableTest extends TestCase { } - private ByteBuffer createRow(Object... row) + private ByteBuffer createRow(Object... row) throws IOException { return _testTable.createRow(row); @@ -146,7 +146,7 @@ public class TableTest extends TestCase { return b; } - private TableImpl newTestTable() + private TableImpl newTestTable() throws Exception { _testTable = new TestTable(); @@ -185,8 +185,8 @@ public class TableTest extends TestCase { return getFormat().CHARSET; } @Override - protected Calendar getCalendar() { - return Calendar.getInstance(); + public TimeZone getTimeZone() { + return TimeZone.getDefault(); } @Override public boolean isCompressedUnicode() { diff --git a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java index 7680fb3..83b2d7d 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java +++ b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java @@ -27,6 +27,10 @@ import java.io.PrintWriter; import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -53,6 +57,7 @@ import org.junit.Assert; * * @author James Ahlborn */ +@SuppressWarnings("deprecation") public class TestUtil { public static final TimeZone TEST_TZ = @@ -86,7 +91,7 @@ public class TestUtil throws Exception { FileChannel channel = (inMem ? MemFileChannel.newChannel( - file, DatabaseImpl.RW_CHANNEL_MODE) + file, MemFileChannel.RW_CHANNEL_MODE) : null); final Database db = new DatabaseBuilder(file).setReadOnly(true) .setAutoSync(getTestAutoSync()).setChannel(channel).open(); @@ -378,6 +383,22 @@ public class TestUtil } } + static void assertSameDate(Date expected, LocalDateTime found) + { + if((expected == null) && (found == null)) { + return; + } + if((expected == null) || (found == null)) { + throw new AssertionError("Expected " + expected + ", found " + found); + } + + LocalDateTime expectedLdt = LocalDateTime.ofInstant( + Instant.ofEpochMilli(expected.getTime()), + ZoneId.systemDefault()); + + Assert.assertEquals(expectedLdt, found); + } + static void copyFile(File srcFile, File dstFile) throws IOException { diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java index 561f1e8..104b266 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/DatabaseReadWriteTest.java @@ -16,6 +16,9 @@ limitations under the License. package com.healthmarketscience.jackcess.impl; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -53,7 +56,7 @@ public class DatabaseReadWriteTest extends TestCase db.close(); } } - + public void testWriteAndReadInMem() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); @@ -61,7 +64,7 @@ public class DatabaseReadWriteTest extends TestCase db.close(); } } - + private static void doTestWriteAndRead(Database db) throws Exception { createTestTable(db); Object[] row = createTestRow(); @@ -117,7 +120,7 @@ public class DatabaseReadWriteTest extends TestCase } } - public void testUpdateRow() throws Exception + public void testUpdateRow() throws Exception { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = createMem(fileFormat); @@ -250,11 +253,18 @@ public class DatabaseReadWriteTest extends TestCase final long timeRange = 100000000L; final long timeStep = 37L; - for(long time = testTime - timeRange; time < testTime + timeRange; + for(long time = testTime - timeRange; time < testTime + timeRange; time += timeStep) { double accTime = ColumnImpl.toLocalDateDouble(time); long newTime = ColumnImpl.fromLocalDateDouble(accTime); assertEquals(time, newTime); + + Instant inst = Instant.ofEpochMilli(time); + LocalDateTime ldt = LocalDateTime.ofInstant(inst, ZoneOffset.UTC); + + accTime = ColumnImpl.toDateDouble(ldt); + LocalDateTime newLdt = ColumnImpl.ldtFromLocalDateDouble(accTime); + assertEquals(ldt, newLdt); } } } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java index 1ed17b7..66c8a71 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java @@ -98,7 +98,7 @@ public class JetFormatTest extends TestCase { } SUPPORTED_FILEFORMATS = supported.toArray(new FileFormat[0]); - SUPPORTED_FILEFORMATS_FOR_READ = + SUPPORTED_FILEFORMATS_FOR_READ = supportedForRead.toArray(new FileFormat[0]); } @@ -110,7 +110,7 @@ public class JetFormatTest extends TestCase { private final File dbFile; private final FileFormat expectedFileFormat; - private TestDB(File databaseFile, + private TestDB(File databaseFile, FileFormat expectedDBFileFormat) { dbFile = databaseFile; @@ -119,12 +119,12 @@ public class JetFormatTest extends TestCase { public final File getFile() { return dbFile; } - public final FileFormat getExpectedFileFormat() { - return expectedFileFormat; + public final FileFormat getExpectedFileFormat() { + return expectedFileFormat; } - public final JetFormat getExpectedFormat() { - return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat(); + public final JetFormat getExpectedFormat() { + return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat(); } @Override @@ -141,14 +141,14 @@ public class JetFormatTest extends TestCase { boolean readOnly) { List<TestDB> supportedTestDBs = new ArrayList<TestDB>(); - for (FileFormat fileFormat : + for (FileFormat fileFormat : (readOnly ? SUPPORTED_FILEFORMATS_FOR_READ : SUPPORTED_FILEFORMATS)) { File testFile = getFileForBasename(basename, fileFormat); if(!testFile.exists()) { continue; } - + // verify that the db is the file format expected try { Database db = new DatabaseBuilder(testFile).setReadOnly(true).open(); @@ -170,16 +170,16 @@ public class JetFormatTest extends TestCase { private static File getFileForBasename( Basename basename, FileFormat fileFormat) { - return new File(DIR_TEST_DATA, + return new File(DIR_TEST_DATA, fileFormat.name() + File.separator + - basename + fileFormat.name() + + basename + fileFormat.name() + fileFormat.getFileExtension()); } } - public static final List<TestDB> SUPPORTED_DBS_TEST = + public static final List<TestDB> SUPPORTED_DBS_TEST = TestDB.getSupportedForBasename(Basename.TEST); - public static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ = + public static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ = TestDB.getSupportedForBasename(Basename.TEST, true); @@ -193,11 +193,12 @@ public class JetFormatTest extends TestCase { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { - final FileChannel channel = DatabaseImpl.openChannel(testDB.dbFile, false); + final FileChannel channel = DatabaseImpl.openChannel( + testDB.dbFile.toPath(), false, false); try { JetFormat fmtActual = JetFormat.getFormat(channel); - assertEquals("Unexpected JetFormat for dbFile: " + + assertEquals("Unexpected JetFormat for dbFile: " + testDB.dbFile.getAbsolutePath(), testDB.getExpectedFormat(), fmtActual); @@ -221,7 +222,7 @@ public class JetFormatTest extends TestCase { PropertyMap props = db.getUserDefinedProperties(); props.put("foo", "bar"); props.save(); - } + } } catch(Exception e) { failure = e; @@ -268,7 +269,7 @@ public class JetFormatTest extends TestCase { } public void testSqlTypes() throws Exception { - + JetFormat v2000 = JetFormat.VERSION_4; for(DataType dt : DataType.values()) { if(v2000.isSupportedDataType(dt)) { 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 84cab7c..dc4cabb 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/DefaultFunctionsTest.java @@ -17,10 +17,11 @@ limitations under the License. package com.healthmarketscience.jackcess.impl.expr; import java.math.BigDecimal; +import java.time.LocalDateTime; import java.util.Calendar; -import java.util.Date; 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; @@ -78,9 +79,9 @@ public class DefaultFunctionsTest extends TestCase eval("=CSng(\"57.12345\")")); assertEval("9786", "=CStr(9786)"); assertEval("-42", "=CStr(-42)"); - assertEval(new Date(1041483600000L), "=CDate('01/02/2003')"); - assertEval(new Date(1041508800000L), "=CDate('01/02/2003 7:00:00 AM')"); - assertEval(new Date(-1948781520000L), "=CDate(3013.45)"); + assertEval(LocalDateTime.of(2003,1,2,0,0), "=CDate('01/02/2003')"); + assertEval(LocalDateTime.of(2003,1,2,7,0), "=CDate('01/02/2003 7:00:00 AM')"); + assertEval(LocalDateTime.of(1908,3,31,10,48), "=CDate(3013.45)"); assertEval(-1, "=IsNull(Null)"); @@ -251,6 +252,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("-.123%", "=FormatPercent(-0.0012345,3,False)"); assertEval("$12,345.00", "=FormatCurrency(12345)"); + assertEval("($12,345.00)", "=FormatCurrency(-12345)"); assertEval("-$12.34", "=FormatCurrency(-12.345,-1,True,False)"); assertEval("$12", "=FormatCurrency(12.345,0,True,True)"); assertEval("($.123)", "=FormatCurrency(-0.12345,3,False)"); @@ -285,6 +287,11 @@ public class DefaultFunctionsTest extends TestCase assertEval("-12345.68", "=Format(-12345.6789, 'Fixed')"); assertEval("-0.12", "=Format(-0.12345, 'Fixed')"); + assertEval("\u20AC12,345.68", "=Format(12345.6789, 'Euro')"); + assertEval("\u20AC0.12", "=Format(0.12345, 'Euro')"); + assertEval("(\u20AC12,345.68)", "=Format(-12345.6789, 'Euro')"); + assertEval("(\u20AC0.12)", "=Format(-0.12345, 'Euro')"); + assertEval("$12,345.68", "=Format(12345.6789, 'Currency')"); assertEval("$0.12", "=Format(0.12345, 'Currency')"); assertEval("($12,345.68)", "=Format(-12345.6789, 'Currency')"); @@ -312,6 +319,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("7:00:00 AM", "=Format(#7:00:00 AM#, 'General Date')"); assertEval("1/2/2003 7:00:00 AM", "=Format('37623.2916666667', 'General Date')"); assertEval("foo", "=Format('foo', 'General Date')"); + assertEval("", "=Format('', 'General Date')"); assertEval("Thursday, January 02, 2003", "=Format(#01/02/2003 7:00:00 AM#, 'Long Date')"); assertEval("02-Jan-03", "=Format(#01/02/2003 7:00:00 AM#, 'Medium Date')"); @@ -320,7 +328,254 @@ public class DefaultFunctionsTest extends TestCase assertEval("07:00 AM", "=Format(#01/02/2003 7:00:00 AM#, 'Medium Time')"); assertEval("07:00", "=Format(#01/02/2003 7:00:00 AM#, 'Short Time')"); assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); + } + + public void testCustomFormat() throws Exception + { + assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); + assertEval("07:00 p", "=Format(#01/10/2003 7:00:00 PM#, 'hh:nn a/p')"); + assertEval("07:00 a 6 2", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p w ww')"); + assertEval("07:00 a 4 1", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p w ww', 3, 3)"); + assertEval("1313", "=Format(#01/10/2003 7:13:00 AM#, 'nnnn; foo bar')"); + assertEval("1 1/10/2003 7:13:00 AM ttt this is text", + "=Format(#01/10/2003 7:13:00 AM#, 'q c ttt \"this is text\"')"); + assertEval("1 1/10/2003 ttt this is text", + "=Format(#01/10/2003#, 'q c ttt \"this is text\"')"); + assertEval("4 7:13:00 AM ttt this 'is' \"text\"", + "=Format(#7:13:00 AM#, \"q c ttt \"\"this 'is' \"\"\"\"text\"\"\"\"\"\"\")"); + assertEval("12/29/1899", "=Format('true', 'c')"); + assertEval("Tuesday, 00 Jan 2, 21:36:00 Y", + "=Format('3.9', '*~dddd, yy mmm d, hh:nn:ss \\Y[Yellow]')"); + assertEval("Tuesday, 00 Jan 01/2, 09:36:00 PM", + "=Format('3.9', 'dddd, yy mmm mm/d, hh:nn:ss AMPM')"); + assertEval("9:36:00 PM", + "=Format('3.9', 'ttttt')"); + assertEval("9:36:00 PM", + "=Format(3.9, 'ttttt')"); + assertEval("foo", + "=Format('foo', 'dddd, yy mmm mm d, hh:nn:ss AMPM')"); + + assertEvalFormat("';\\y;\\n'", + "foo", "'foo'", + "", "''", + "y", "True", + "n", "'0'", + "", "Null"); + + assertEvalFormat("'\\p;\"y\";!\\n;*~\\z[Blue];'", + "foo", "'foo'", + "", "''", + "y", "True", + "n", "'0'", + "p", "'10'", + "z", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\"'", + "p13.00blah", "13", + "-p13.00blah", "-13", + "p.00blah", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\";(\"p\"#.00#\"blah\")'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "p.00blah", "0", + "(p1.00blah)", "True", + "p.00blah", "'false'", + "p37623.292blah", "#01/02/2003 7:00:00 AM#", + "p37623.292blah", "'01/02/2003 7:00:00 AM'", + "NotANumber", "'NotANumber'", + "", "''", + "", "Null"); + + assertEvalFormat("'\"p\"#.00#\"blah\";!(\"p\"#.00#\"blah\")[Red];\"zero\"'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "zero", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'\\p#.00#\"blah\";*~(\"p\"#.00#\"blah\");\"zero\";\"yuck\"'", + "p13.00blah", "13", + "(p13.00blah)", "-13", + "zero", "0", + "", "''", + "yuck", "Null"); + + assertEvalFormat("'0.##;(0.###);\"zero\";\"yuck\";'", + "0.03", "0.03", + "zero", "0.003", + "(0.003)", "-0.003", + "zero", "-0.0003"); + + assertEvalFormat("'0.##;(0.###E+0)'", + "0.03", "0.03", + "(3.E-4)", "-0.0003", + "0.", "0", + "34223.", "34223", + "(3.422E+4)", "-34223"); + + assertEvalFormat("'0.###E-0'", + "3.E-4", "0.0003", + "3.422E4", "34223" + ); + + assertEvalFormat("'0.###e+0'", + "3.e-4", "0.0003", + "3.422e+4", "34223" + ); + + assertEvalFormat("'0.###e-0'", + "3.e-4", "0.0003", + "3.422e4", "34223" + ); + + assertEvalFormat("'#,##0.###'", + "0.003", "0.003", + "0.", "0.0003", + "34,223.", "34223" + ); + + assertEvalFormat("'0.'", + "13.", "13", + "0.", "0.003", + "-45.", "-45", + "0.", "-0.003", + "0.", "0" + ); + + assertEvalFormat("'0.#'", + "13.", "13", + "0.3", "0.3", + "0.", "0.003", + "-45.", "-45", + "0.", "-0.003", + "0.", "0" + ); + + assertEvalFormat("'0'", + "13", "13", + "0", "0.003", + "-45", "-45", + "0", "-0.003", + "0", "0" + ); + + assertEvalFormat("'%0'", + "%13", "0.13", + "%0", "0.003", + "-%45", "-0.45", + "%0", "-0.003", + "%0", "0" + ); + + assertEvalFormat("'#'", + "13", "13", + "", "0.003", + "-45", "-45", + "", "-0.003", + "", "0" + ); + + assertEvalFormat("'\\0\\[#.#\\]\\0'", + "0[13.]0", "13", + "0[.]0", "0.003", + "0[.3]0", "0.3", + "-0[45.]0", "-45", + "0[.]0", "-0.003", + "-0[.3]0", "-0.3", + "0[.]0", "0" + ); + + assertEvalFormat("\"#;n'g;'\"", + "5", "5", + "n'g", "-5", + "'", "0"); + + assertEvalFormat("'$0.0#'", + "$213.0", "213"); + + assertEvalFormat("'@'", + "foo", "'foo'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'>@'", + "FOO", "'foo'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'<@'", + "foo", "'FOO'", + "-13", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'!>@;'", + "O", "'foo'", + "3", "-13", + "0", "0", + "", "''", + "", "Null"); + + assertEvalFormat("'!>*~@[Red];\"empty\";'", + "O", "'foo'", + "3", "-13", + "0", "0", + "empty", "''", + "empty", "Null"); + + assertEvalFormat("'><@'", + "fOo", "'fOo'"); + + assertEvalFormat("'\\x@@@&&&\\y'", + "x fy", "'f'", + "x fooy", "'foo'", + "x foobay", "'fooba'", + "xfoobarybaz", "'foobarbaz'" + ); + + assertEvalFormat("'!\\x@@@&&&\\y'", + "xf y", "'f'", + "xfooy", "'foo'", + "xfoobay", "'fooba'", + "xbarbazy", "'foobarbaz'" + ); + + assertEvalFormat("'\\x&&&@@@\\y'", + "x fy", "'f'", + "xfooy", "'foo'", + "xfoobay", "'fooba'", + "xfoobarybaz", "'foobarbaz'" + ); + + assertEvalFormat("'!\\x&&&@@@\\y'", + "xf y", "'f'", + "xfoo y", "'foo'", + "xfooba y", "'fooba'", + "xbarbazy", "'foobarbaz'" + ); + } + private static void assertEvalFormat(String fmtStr, String... testStrs) { + for(int i = 0; i < testStrs.length; i+=2) { + String expected = testStrs[i]; + String val = testStrs[i + 1]; + + try { + assertEval(expected, + "=Format(" + val + ", " + fmtStr + ")"); + } catch(AssertionFailedError afe) { + throw new AssertionFailedError("Input " + val + ": " + + afe.getMessage()); + } + } } public void testNumberFuncs() throws Exception @@ -590,7 +845,7 @@ public class DefaultFunctionsTest extends TestCase assertEval("409.090909090909", "=CStr(SYD(30000,7500,10,10))"); assertEval("-1.63048347266756E-02", "=CStr(Rate(3,200,-610,0,-20,0.1))"); - assertEval("7.70147248820175E-03", "=CStr(Rate(4*12,-200,8000))"); + assertEval("7.70147248820165E-03", "=CStr(Rate(4*12,-200,8000))"); assertEval("-1.09802980531205", "=CStr(Rate(60,93.22,5000,0.1))"); } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java index c67dfe7..67ad20b 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/expr/ExpressionatorTest.java @@ -20,14 +20,13 @@ import java.io.BufferedReader; import java.io.FileReader; import java.math.BigDecimal; import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import javax.script.Bindings; import javax.script.SimpleBindings; import com.healthmarketscience.jackcess.DataType; -import com.healthmarketscience.jackcess.DatabaseBuilder; import com.healthmarketscience.jackcess.TestUtil; import com.healthmarketscience.jackcess.expr.EvalContext; import com.healthmarketscience.jackcess.expr.Expression; @@ -38,7 +37,6 @@ import com.healthmarketscience.jackcess.expr.ParseException; import com.healthmarketscience.jackcess.expr.TemporalConfig; import com.healthmarketscience.jackcess.expr.Value; import com.healthmarketscience.jackcess.impl.BaseEvalContext; -import com.healthmarketscience.jackcess.impl.expr.NumberFormatter; import junit.framework.TestCase; /** @@ -318,11 +316,11 @@ public class ExpressionatorTest extends TestCase public void testDateArith() throws Exception { - assertEquals(new Date(1041508800000L), eval("=#01/02/2003# + #7:00:00 AM#")); - assertEquals(new Date(1041458400000L), eval("=#01/02/2003# - #7:00:00 AM#")); - assertEquals(new Date(1044680400000L), eval("=#01/02/2003# + '37'")); - assertEquals(new Date(1044680400000L), eval("='37' + #01/02/2003#")); - assertEquals(new Date(1041508800000L), eval("=#01/02/2003 7:00:00 AM#")); + assertEquals(LocalDateTime.of(2003,1,2,7,0), eval("=#01/02/2003# + #7:00:00 AM#")); + assertEquals(LocalDateTime.of(2003,1,1,17,0), eval("=#01/02/2003# - #7:00:00 AM#")); + assertEquals(LocalDateTime.of(2003,2,8,0,0), eval("=#01/02/2003# + '37'")); + assertEquals(LocalDateTime.of(2003,2,8,0,0), eval("='37' + #01/02/2003#")); + assertEquals(LocalDateTime.of(2003,1,2,7,0), eval("=#01/02/2003 7:00:00 AM#")); assertEquals("2/8/2003", eval("=CStr(#01/02/2003# + '37')")); assertEquals("9:24:00 AM", eval("=CStr(#7:00:00 AM# + 0.1)")); @@ -404,7 +402,7 @@ public class ExpressionatorTest extends TestCase assertEquals("foo37", eval("=\"foo\" + (12 + 25)")); assertEquals("25foo12", eval("=\"25foo\" + 12")); - assertEquals(new Date(1485579600000L), eval("=#1/1/2017# + 27")); + assertEquals(LocalDateTime.of(2017,1,28,0,0), eval("=#1/1/2017# + 27")); assertEquals(128208, eval("=#1/1/2017# * 3")); } @@ -590,15 +588,14 @@ public class ExpressionatorTest extends TestCase return TemporalConfig.US_TEMPORAL_CONFIG; } - public SimpleDateFormat createDateFormat(String formatStr) { - SimpleDateFormat sdf = DatabaseBuilder.createDateFormat(formatStr); - sdf.setTimeZone(TestUtil.TEST_TZ); - return sdf; + public DateTimeFormatter createDateFormatter(String formatStr) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern( + formatStr, TemporalConfig.US_TEMPORAL_CONFIG.getLocale()); + return dtf; } - public Calendar getCalendar() { - return createDateFormat(getTemporalConfig().getDefaultDateTimeFormat()) - .getCalendar(); + public ZoneId getZoneId() { + return TestUtil.TEST_TZ.toZoneId(); } public NumericConfig getNumericConfig() { diff --git a/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java b/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java index f7e48f4..f2fe675 100644 --- a/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java @@ -29,9 +29,8 @@ import com.healthmarketscience.jackcess.TestUtil; import com.healthmarketscience.jackcess.impl.query.QueryImpl; import com.healthmarketscience.jackcess.impl.query.QueryImpl.Row; import junit.framework.TestCase; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; -import static org.apache.commons.lang.SystemUtils.LINE_SEPARATOR; import static com.healthmarketscience.jackcess.impl.query.QueryFormat.*; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -53,22 +52,22 @@ public class QueryTest extends TestCase String expr2 = "Select * from Table2"; UnionQuery query = (UnionQuery)newQuery( - Query.Type.UNION, + Query.Type.UNION, newRow(TABLE_ATTRIBUTE, expr1, null, UNION_PART1), newRow(TABLE_ATTRIBUTE, expr2, null, UNION_PART2)); setFlag(query, 3); assertEquals(multiline("Select * from Table1", - "UNION Select * from Table2;"), + "UNION Select * from Table2;"), query.toSQLString()); setFlag(query, 1); assertEquals(multiline("Select * from Table1", - "UNION ALL Select * from Table2;"), + "UNION ALL Select * from Table2;"), query.toSQLString()); - addRows(query, newRow(ORDERBY_ATTRIBUTE, "Table1.id", + addRows(query, newRow(ORDERBY_ATTRIBUTE, "Table1.id", null, null)); assertEquals(multiline("Select * from Table1", @@ -112,7 +111,7 @@ public class QueryTest extends TestCase public void testUpdateQuery() throws Exception { UpdateQuery query = (UpdateQuery)newQuery( - Query.Type.UPDATE, + Query.Type.UPDATE, newRow(TABLE_ATTRIBUTE, null, "Table1", null), newRow(COLUMN_ATTRIBUTE, "\"some string\"", null, "Table1.id"), newRow(COLUMN_ATTRIBUTE, "42", null, "Table1.col1")); @@ -122,7 +121,7 @@ public class QueryTest extends TestCase "SET Table1.id = \"some string\", Table1.col1 = 42;"), query.toSQLString()); - addRows(query, newRow(WHERE_ATTRIBUTE, "(Table1.col2 < 13)", + addRows(query, newRow(WHERE_ATTRIBUTE, "(Table1.col2 < 13)", null, null)); assertEquals( @@ -135,14 +134,14 @@ public class QueryTest extends TestCase public void testSelectQuery() throws Exception { SelectQuery query = (SelectQuery)newQuery( - Query.Type.SELECT, + Query.Type.SELECT, newRow(TABLE_ATTRIBUTE, null, "Table1", null)); setFlag(query, 1); assertEquals(multiline("SELECT *", "FROM Table1;"), query.toSQLString()); - + doTestColumns(query); doTestSelectFlags(query); doTestParameters(query); @@ -168,7 +167,7 @@ public class QueryTest extends TestCase } addRows(query, newRow(TYPE_ATTRIBUTE, null, -1, null, null)); - + try { query.getTypeRow(); fail("IllegalStateException should have been thrown"); @@ -265,7 +264,7 @@ public class QueryTest extends TestCase newRow(COLUMN_ATTRIBUTE, "54", APPEND_VALUE_FLAG, null, null), newRow(COLUMN_ATTRIBUTE, "'hello'", APPEND_VALUE_FLAG, null, null)); - assertEquals(multiline("INSERT INTO Table2", + assertEquals(multiline("INSERT INTO Table2", "VALUES (54, 'hello');"), query.toSQLString()); query = (AppendQuery)newQuery( @@ -274,7 +273,7 @@ public class QueryTest extends TestCase newRow(COLUMN_ATTRIBUTE, "54", APPEND_VALUE_FLAG, null, "ID"), newRow(COLUMN_ATTRIBUTE, "'hello'", APPEND_VALUE_FLAG, null, "Field 3")); - assertEquals(multiline("INSERT INTO Table2 (ID, [Field 3])", + assertEquals(multiline("INSERT INTO Table2 (ID, [Field 3])", "VALUES (54, 'hello');"), query.toSQLString()); } @@ -291,27 +290,27 @@ public class QueryTest extends TestCase private void doTestSelectFlags(SelectQuery query) throws Exception { setFlag(query, 3); - + assertEquals(multiline("SELECT DISTINCT Table1.id, Table1.col AS [Some.Alias], *", "FROM Table1;"), query.toSQLString()); setFlag(query, 9); - + assertEquals(multiline("SELECT DISTINCTROW Table1.id, Table1.col AS [Some.Alias], *", "FROM Table1;"), query.toSQLString()); setFlag(query, 7); - + assertEquals(multiline("SELECT DISTINCT Table1.id, Table1.col AS [Some.Alias], *", "FROM Table1", "WITH OWNERACCESS OPTION;"), query.toSQLString()); - replaceRows(query, + replaceRows(query, newRow(FLAG_ATTRIBUTE, null, 49, null, "5", null)); - + assertEquals(multiline("SELECT TOP 5 PERCENT Table1.id, Table1.col AS [Some.Alias], *", "FROM Table1;"), query.toSQLString()); @@ -354,7 +353,7 @@ public class QueryTest extends TestCase assertEquals(multiline("SELECT Table1.id, Table1.col AS [Some.Alias]", "FROM Table1, Table2 AS [Another Table], [Select val from Table3].val AS Table3Val;"), - query.toSQLString()); + query.toSQLString()); } private void doTestRemoteDb(SelectQuery query) throws Exception @@ -387,7 +386,7 @@ public class QueryTest extends TestCase assertEquals(multiline("SELECT Table1.id, Table1.col AS [Some.Alias]", "FROM [Select val from Table3].val AS Table3Val, Table1 INNER JOIN Table2 AS [Another Table] ON (Table1.id = [Another Table].id);"), query.toSQLString()); - + addRows(query, newRow(JOIN_ATTRIBUTE, "(Table1.id = Table3Val.id)", 2, "Table1", "Table3Val")); assertEquals(multiline("SELECT Table1.id, Table1.col AS [Some.Alias]", @@ -417,13 +416,13 @@ public class QueryTest extends TestCase private void doTestWhereExpression(SelectQuery query) throws Exception { - addRows(query, newRow(WHERE_ATTRIBUTE, "(Table1.col2 < 13)", + addRows(query, newRow(WHERE_ATTRIBUTE, "(Table1.col2 < 13)", null, null)); assertEquals(multiline("SELECT Table1.id, Table1.col AS [Some.Alias]", "FROM Table1, Table2 AS [Another Table], [Select val from Table3].val AS Table3Val", "WHERE (Table1.col2 < 13);"), - query.toSQLString()); + query.toSQLString()); } private void doTestGroupings(SelectQuery query) throws Exception @@ -435,7 +434,7 @@ public class QueryTest extends TestCase "FROM Table1, Table2 AS [Another Table], [Select val from Table3].val AS Table3Val", "WHERE (Table1.col2 < 13)", "GROUP BY Table1.id, SUM(Table1.val);"), - query.toSQLString()); + query.toSQLString()); } private void doTestHavingExpression(SelectQuery query) throws Exception @@ -447,7 +446,7 @@ public class QueryTest extends TestCase "WHERE (Table1.col2 < 13)", "GROUP BY Table1.id, SUM(Table1.val)", "HAVING (SUM(Table1.val) = 500);"), - query.toSQLString()); + query.toSQLString()); } private void doTestOrderings(SelectQuery query) throws Exception @@ -461,7 +460,7 @@ public class QueryTest extends TestCase "GROUP BY Table1.id, SUM(Table1.val)", "HAVING (SUM(Table1.val) = 500)", "ORDER BY Table1.id, Table2.val DESC;"), - query.toSQLString()); + query.toSQLString()); } public void testComplexJoins() throws Exception @@ -484,7 +483,7 @@ public class QueryTest extends TestCase addJoinRows(query, 1, 2, 1, 2, 1, 1); - + assertEquals(multiline("SELECT *", "FROM Table3, Table4, Table5, Table6, Table7, Table8, Table9, Table10, Table1 INNER JOIN Table2 ON (Table2.f3 = Table1.f3) AND (Table1.f0 = Table2.f0);"), query.toSQLString()); @@ -498,7 +497,7 @@ public class QueryTest extends TestCase } catch(IllegalStateException e) { // success } - + addJoinRows(query, 1, 2, 1, 3, 4, 1, 5, 6, 1, @@ -613,7 +612,7 @@ public class QueryTest extends TestCase private static void setFlag(Query query, Number newFlagNum) { - replaceRows(query, + replaceRows(query, newRow(FLAG_ATTRIBUTE, null, newFlagNum, null, null, null)); } @@ -646,7 +645,7 @@ public class QueryTest extends TestCase private static String multiline(String... strs) { - return StringUtils.join(strs, LINE_SEPARATOR); + return StringUtils.join(strs, System.lineSeparator()); } } diff --git a/src/test/java/com/healthmarketscience/jackcess/util/CustomLinkResolverTest.java b/src/test/java/com/healthmarketscience/jackcess/util/CustomLinkResolverTest.java index 87f8e6f..d0446b2 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/CustomLinkResolverTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/CustomLinkResolverTest.java @@ -16,9 +16,9 @@ limitations under the License. package com.healthmarketscience.jackcess.util; -import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.nio.file.Path; import com.healthmarketscience.jackcess.ColumnBuilder; import com.healthmarketscience.jackcess.DataType; @@ -149,7 +149,7 @@ public class CustomLinkResolverTest extends TestCase @Override protected Database createTempDb(Object customFile, FileFormat format, - boolean inMemory, File tempDir, + boolean inMemory, Path tempDir, boolean readOnly) throws IOException { diff --git a/src/test/java/com/healthmarketscience/jackcess/util/ExportTest.java b/src/test/java/com/healthmarketscience/jackcess/util/ExportTest.java index 754be06..5ffdbd9 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/ExportTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/ExportTest.java @@ -30,7 +30,6 @@ import com.healthmarketscience.jackcess.Table; import com.healthmarketscience.jackcess.TableBuilder; import com.healthmarketscience.jackcess.impl.JetFormatTest; import junit.framework.TestCase; -import org.apache.commons.lang.SystemUtils; import static com.healthmarketscience.jackcess.TestUtil.*; /** @@ -39,7 +38,7 @@ import static com.healthmarketscience.jackcess.TestUtil.*; */ public class ExportTest extends TestCase { - private static final String NL = SystemUtils.LINE_SEPARATOR; + private static final String NL = System.lineSeparator(); public ExportTest(String name) { @@ -78,7 +77,7 @@ public class ExportTest extends TestCase new ExportUtil.Builder(db, "test") .exportWriter(new BufferedWriter(out)); - String expected = + String expected = "some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64\",true," + testDate + NL + "\"crazy'data\"\"here\",-345,-3.45E-4,61 62 63 64 65 66 67,true," + NL + "C:\\temp\\some_file.txt,25,0.0,,false," + NL; @@ -86,14 +85,14 @@ public class ExportTest extends TestCase assertEquals(expected, out.toString()); out = new StringWriter(); - + new ExportUtil.Builder(db, "test") .setHeader(true) .setDelimiter("||") .setQuote('\'') .exportWriter(new BufferedWriter(out)); - expected = + expected = "col1||col2||col3||col4||col5||col6" + NL + "'some text||some more'||13||13.25||'61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64'||true||" + testDate + NL + "'crazy''data\"here'||-345||-3.45E-4||61 62 63 64 65 66 67||true||" + NL + @@ -117,7 +116,7 @@ public class ExportTest extends TestCase .setFilter(oddFilter) .exportWriter(new BufferedWriter(out)); - expected = + expected = "some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78\n79 7A 61 62 63 64\",true," + testDate + NL + "C:\\temp\\some_file.txt,25,0.0,,false," + NL; diff --git a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java index be3a0a9..725daa0 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java @@ -34,7 +34,7 @@ import com.healthmarketscience.jackcess.impl.CompoundOleUtil; import junit.framework.TestCase; import org.apache.poi.poifs.filesystem.DocumentEntry; import org.apache.poi.poifs.filesystem.DocumentInputStream; -import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import static com.healthmarketscience.jackcess.TestUtil.*; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; @@ -42,7 +42,7 @@ import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; * * @author James Ahlborn */ -public class OleBlobTest extends TestCase +public class OleBlobTest extends TestCase { public OleBlobTest(String name) { @@ -73,7 +73,7 @@ public class OleBlobTest extends TestCase } finally { ByteUtil.closeQuietly(blob); } - + try { blob = new OleBlob.Builder() .setLink(sampleFile) @@ -82,7 +82,7 @@ public class OleBlobTest extends TestCase } finally { ByteUtil.closeQuietly(blob); } - + try { blob = new OleBlob.Builder() .setPackagePrettyName("Text File") @@ -109,14 +109,14 @@ public class OleBlobTest extends TestCase assertEquals(sampleFilePath, spc.getFilePath()); assertEquals(sampleFilePath, spc.getLocalFilePath()); assertEquals(sampleFileName, spc.getFileName()); - assertEquals(OleBlob.Builder.PACKAGE_PRETTY_NAME, + assertEquals(OleBlob.Builder.PACKAGE_PRETTY_NAME, spc.getPrettyName()); - assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, + assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, spc.getTypeName()); - assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, + assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, spc.getClassName()); assertEquals(sampleFileBytes.length, spc.length()); - assertTrue(Arrays.equals(sampleFileBytes, + assertTrue(Arrays.equals(sampleFileBytes, toByteArray(spc.getStream(), spc.length()))); break; @@ -130,7 +130,7 @@ public class OleBlobTest extends TestCase assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, lc.getTypeName()); assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, lc.getClassName()); break; - + case 3: OleBlob.OtherContent oc = (OleBlob.OtherContent)content; assertEquals(OleBlob.ContentType.OTHER, oc.getType()); @@ -138,7 +138,7 @@ public class OleBlobTest extends TestCase assertEquals("Text.File", oc.getClassName()); assertEquals("TextFile", oc.getTypeName()); assertEquals(sampleFileBytes.length, oc.length()); - assertTrue(Arrays.equals(sampleFileBytes, + assertTrue(Arrays.equals(sampleFileBytes, toByteArray(oc.getStream(), oc.length()))); break; default: @@ -149,8 +149,8 @@ public class OleBlobTest extends TestCase } } - db.close(); - } + db.close(); + } } public void testReadBlob() throws Exception @@ -198,7 +198,7 @@ public class OleBlobTest extends TestCase } else { if("test_word.doc".equals(name)) { - checkCompoundEntries(cc, + checkCompoundEntries(cc, "/%02OlePres000", 466, "/WordDocument", 4096, "/%05SummaryInformation", 4096, @@ -210,7 +210,7 @@ public class OleBlobTest extends TestCase "/%01Ole", 20); checkCompoundStorage(cc, attach); } else if("test_excel.xls".equals(name)) { - checkCompoundEntries(cc, + checkCompoundEntries(cc, "/%02OlePres000", 1326, "/%03AccessObjSiteData", 56, "/%05SummaryInformation", 200, @@ -243,10 +243,10 @@ public class OleBlobTest extends TestCase } db.close(); - } + } } - private static void checkCompoundEntries(OleBlob.CompoundContent cc, + private static void checkCompoundEntries(OleBlob.CompoundContent cc, Object... entryInfo) throws Exception { @@ -262,7 +262,7 @@ public class OleBlobTest extends TestCase } } - private static void checkCompoundStorage(OleBlob.CompoundContent cc, + private static void checkCompoundStorage(OleBlob.CompoundContent cc, Attachment attach) throws Exception { @@ -273,7 +273,7 @@ public class OleBlobTest extends TestCase fout.write(attach.getFileData()); fout.close(); - NPOIFSFileSystem attachFs = new NPOIFSFileSystem(tmpData, true); + POIFSFileSystem attachFs = new POIFSFileSystem(tmpData, true); for(OleBlob.CompoundContent.Entry e : cc) { DocumentEntry attachE = null; @@ -284,7 +284,7 @@ public class OleBlobTest extends TestCase continue; } - byte[] attachEBytes = toByteArray(new DocumentInputStream(attachE), + byte[] attachEBytes = toByteArray(new DocumentInputStream(attachE), attachE.getSize()); byte[] entryBytes = toByteArray(e.getStream(), e.length()); @@ -292,9 +292,9 @@ public class OleBlobTest extends TestCase } ByteUtil.closeQuietly(attachFs); - + } finally { tmpData.delete(); - } + } } } diff --git a/src/test/resources/log4j_test.properties b/src/test/resources/log4j_test.properties deleted file mode 100644 index 6647228..0000000 --- a/src/test/resources/log4j_test.properties +++ /dev/null @@ -1,6 +0,0 @@ -log4j.rootCategory=INFO, stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=**** %-5p %d{MMM d HH:mm:ss} [%F] - %m%n - -log4j.category.com.healthmarketscience.jackcess=ERROR diff --git a/src/test/resources/logging_test.properties b/src/test/resources/logging_test.properties new file mode 100644 index 0000000..1d5324b --- /dev/null +++ b/src/test/resources/logging_test.properties @@ -0,0 +1 @@ +com.healthmarketscience.jackcess.level=SEVERE |