aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2019-08-19 01:07:26 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2019-08-19 01:07:26 +0000
commitfefce70e973175f2124e2737c4fb77a2ffa39c29 (patch)
tree128920ff91d70d52efe65fbeb0e953b5ab83c66f /src/test
parentf9202b4fabd510611c13a18c3e5e1542760447a2 (diff)
downloadjackcess-fefce70e973175f2124e2737c4fb77a2ffa39c29.tar.gz
jackcess-fefce70e973175f2124e2737c4fb77a2ffa39c29.zip
add unit tests for access 97 text indexesa97_indexes
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/a97_indexes@1313 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test')
-rw-r--r--src/test/data/V1997/testIndexCodesV1997.mdbbin0 -> 364544 bytes
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/CursorTest.java201
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/TestUtil.java18
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java10
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java20
5 files changed, 141 insertions, 108 deletions
diff --git a/src/test/data/V1997/testIndexCodesV1997.mdb b/src/test/data/V1997/testIndexCodesV1997.mdb
new file mode 100644
index 0000000..f52a4ea
--- /dev/null
+++ b/src/test/data/V1997/testIndexCodesV1997.mdb
Binary files differ
diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
index 16ed72a..e108ae4 100644
--- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java
@@ -43,7 +43,7 @@ import static com.healthmarketscience.jackcess.TestUtil.*;
*/
public class CursorTest extends TestCase {
- static final List<TestDB> INDEX_CURSOR_DBS =
+ static final List<TestDB> INDEX_CURSOR_DBS =
TestDB.getSupportedForBasename(Basename.INDEX_CURSOR);
@@ -82,9 +82,9 @@ public class CursorTest extends TestCase {
expectedRows.subList(0, startIdx).clear();
return expectedRows;
}
-
- private static Database createTestTable(final FileFormat fileFormat)
- throws Exception
+
+ private static Database createTestTable(final FileFormat fileFormat)
+ throws Exception
{
Database db = createMem(fileFormat);
@@ -110,10 +110,10 @@ public class CursorTest extends TestCase {
expectedRows.add(createExpectedRow("id", i, "value", "data" + i));
}
return expectedRows;
- }
+ }
- static Database createTestIndexTable(final TestDB indexCursorDB)
- throws Exception
+ static Database createTestIndexTable(final TestDB indexCursorDB)
+ throws Exception
{
Database db = openMem(indexCursorDB);
@@ -141,8 +141,8 @@ public class CursorTest extends TestCase {
return expectedRows;
}
- private static Database createDupeTestTable(final FileFormat fileFormat)
- throws Exception
+ private static Database createDupeTestTable(final FileFormat fileFormat)
+ throws Exception
{
Database db = createMem(fileFormat);
@@ -158,8 +158,8 @@ public class CursorTest extends TestCase {
return db;
}
- static Database createDupeTestTable(final TestDB indexCursorDB)
- throws Exception
+ static Database createDupeTestTable(final TestDB indexCursorDB)
+ throws Exception
{
Database db = openMem(indexCursorDB);
@@ -185,7 +185,7 @@ public class CursorTest extends TestCase {
.setEndRowInclusive(type == 0)
.toCursor();
}
-
+
public void testRowId() throws Exception {
// test special cases
RowIdImpl rowId1 = new RowIdImpl(1, 2);
@@ -201,7 +201,7 @@ public class CursorTest extends TestCase {
RowIdImpl.LAST_ROW_ID),
sortedRowIds);
}
-
+
public void testSimple() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -266,7 +266,7 @@ public class CursorTest extends TestCase {
assertTrue(cursor.moveToNextRow());
assertTrue(cursor.moveToPreviousRow());
assertEquals(expectedRow, cursor.getCurrentRow());
-
+
while(cursor.moveToNextRow()) {
foundRows.add(cursor.getCurrentRow());
}
@@ -285,7 +285,7 @@ public class CursorTest extends TestCase {
assertTrue(cursor.isAfterLast());
cursor.restoreSavepoint(savepoint);
- assertEquals(expectedRow, cursor.getCurrentRow());
+ assertEquals(expectedRow, cursor.getCurrentRow());
}
public void testMoveNoReset() throws Exception {
@@ -305,18 +305,18 @@ public class CursorTest extends TestCase {
{
List<Map<String, Object>> expectedRows = createTestTableData();
List<Map<String, Object>> foundRows = new ArrayList<Map<String, Object>>();
-
+
Iterator<Row> iter = cursor.newIterable().iterator();
for(int i = 0; i < 6; ++i) {
foundRows.add(iter.next());
- }
+ }
iter = cursor.newIterable().reset(false).reverse().iterator();
iter.next();
Map<String, Object> row = iter.next();
assertEquals(expectedRows.get(4), row);
-
+
iter = cursor.newIterable().reset(false).iterator();
iter.next();
row = iter.next();
@@ -326,11 +326,11 @@ public class CursorTest extends TestCase {
iter = cursor.newIterable().reset(false).iterator();
for(int i = 6; i < 10; ++i) {
foundRows.add(iter.next());
- }
+ }
assertEquals(expectedRows, foundRows);
}
-
+
public void testSearch() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -372,7 +372,7 @@ public class CursorTest extends TestCase {
assertEquals(createExpectedRow("id", 7,
"value", "data" + 7),
cursor.getCurrentRow());
-
+
assertTrue(cursor.findFirstRow(table.getColumn("value"), "data" + 4));
assertEquals(createExpectedRow("id", 4,
"value", "data" + 4),
@@ -387,7 +387,7 @@ public class CursorTest extends TestCase {
"id", outOfRangeValue,
"value", "data" + outOfRangeValue)));
}
-
+
assertEquals("data" + 5,
CursorBuilder.findValue(table,
table.getColumn("value"),
@@ -441,9 +441,9 @@ public class CursorTest extends TestCase {
for(Map<String, Object> row : cursor.newIterable().reverse()) {
foundRows.add(row);
}
- assertEquals(expectedRows, foundRows);
+ assertEquals(expectedRows, foundRows);
}
-
+
public void testLiveAddition() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -470,7 +470,7 @@ public class CursorTest extends TestCase {
assertTrue(cursor2.isAfterLast());
table.addRow(newRowNum, "data" + newRowNum);
- Map<String,Object> expectedRow =
+ Map<String,Object> expectedRow =
createExpectedRow("id", newRowNum, "value", "data" + newRowNum);
assertFalse(cursor1.isAfterLast());
@@ -484,7 +484,7 @@ public class CursorTest extends TestCase {
assertTrue(cursor2.isAfterLast());
}
-
+
public void testLiveDeletion() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -524,7 +524,7 @@ public class CursorTest extends TestCase {
assertEquals(expectedDeletedRow, cursor2.getCurrentRow());
assertEquals(expectedDeletedRow, cursor3.getCurrentRow());
-
+
assertFalse(cursor2.isCurrentRowDeleted());
assertFalse(cursor3.isCurrentRowDeleted());
@@ -536,7 +536,7 @@ public class CursorTest extends TestCase {
assertEquals(expectedNextRow, cursor1.getNextRow());
assertEquals(expectedNextRow, cursor2.getNextRow());
assertEquals(expectedNextRow, cursor3.getNextRow());
-
+
assertEquals(expectedPrevRow, cursor3.getPreviousRow());
assertTrue(cursor3.moveToNextRow());
@@ -606,7 +606,7 @@ public class CursorTest extends TestCase {
db.close();
}
}
-
+
public void testReverseIndex() throws Exception {
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) {
Database db = createTestIndexTable(indexCursorDB);
@@ -684,7 +684,7 @@ public class CursorTest extends TestCase {
}
}
}
-
+
public void testMoveIndexSubRange() throws Exception {
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) {
for(int i = 0; i < 2; ++i) {
@@ -704,7 +704,7 @@ public class CursorTest extends TestCase {
}
}
}
-
+
public void testSearchIndexSubRange() throws Exception {
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) {
for(int i = 0; i < 2; ++i) {
@@ -759,7 +759,7 @@ public class CursorTest extends TestCase {
}
}
}
-
+
public void testLiveDeletionIndexSubRange() throws Exception {
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) {
for(int i = 0; i < 2; ++i) {
@@ -873,7 +873,7 @@ public class CursorTest extends TestCase {
rows = RowFilterTest.toList(
cursor.newIterable().setMatchPattern(
Collections.singletonMap("id", 8)));
-
+
expectedRows =
createExpectedTable(
createExpectedRow(
@@ -883,7 +883,7 @@ public class CursorTest extends TestCase {
assertEquals(expectedRows, rows);
for(Map<String,Object> row : table) {
-
+
List<Map<String,Object>> tmpRows = new ArrayList<Map<String,Object>>();
for(Map<String,Object> tmpRow : cursor) {
if(row.equals(tmpRow)) {
@@ -892,7 +892,7 @@ public class CursorTest extends TestCase {
}
expectedRows = tmpRows;
assertFalse(expectedRows.isEmpty());
-
+
rows = RowFilterTest.toList(cursor.newIterable().setMatchPattern(row));
assertEquals(expectedRows, rows);
@@ -944,9 +944,9 @@ public class CursorTest extends TestCase {
db.close();
}
}
-
+
public void testColumnMatcher() throws Exception {
-
+
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -958,7 +958,7 @@ public class CursorTest extends TestCase {
Cursor cursor = CursorBuilder.createCursor(table);
doTestMatcher(table, cursor, SimpleColumnMatcher.INSTANCE, false);
- doTestMatcher(table, cursor, CaseInsensitiveColumnMatcher.INSTANCE,
+ doTestMatcher(table, cursor, CaseInsensitiveColumnMatcher.INSTANCE,
true);
db.close();
}
@@ -979,8 +979,8 @@ public class CursorTest extends TestCase {
assertFalse(columnMatcher.matches(table, "value", null, 13));
assertTrue(columnMatcher.matches(table, "value", 13, 13));
}
-
- private static void doTestMatcher(Table table, Cursor cursor,
+
+ private static void doTestMatcher(Table table, Cursor cursor,
ColumnMatcher columnMatcher,
boolean caseInsensitive)
throws Exception
@@ -1021,7 +1021,7 @@ public class CursorTest extends TestCase {
assertEquals(createExpectedRow("id", 7,
"value", "data" + 7),
cursor.getCurrentRow());
-
+
assertTrue(cursor.findFirstRow(createExpectedRow(
"value", "Data" + 7)) == caseInsensitive);
if(caseInsensitive) {
@@ -1029,13 +1029,13 @@ public class CursorTest extends TestCase {
"value", "data" + 7),
cursor.getCurrentRow());
}
-
+
assertTrue(cursor.findFirstRow(table.getColumn("value"), "data" + 4));
assertEquals(createExpectedRow("id", 4,
"value", "data" + 4),
cursor.getCurrentRow());
- assertTrue(cursor.findFirstRow(table.getColumn("value"), "Data" + 4)
+ assertTrue(cursor.findFirstRow(table.getColumn("value"), "Data" + 4)
== caseInsensitive);
if(caseInsensitive) {
assertEquals(createExpectedRow("id", 4,
@@ -1067,8 +1067,8 @@ public class CursorTest extends TestCase {
}
public void testIndexCursor() throws Exception
- {
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
+ {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) {
Database db = openMem(testDB);
Table t1 = db.getTable("Table1");
@@ -1081,7 +1081,7 @@ public class CursorTest extends TestCase {
assertTrue(cursor.findFirstRowByEntry(1));
assertEquals(1, cursor.getCurrentRow().get("id"));
-
+
cursor.findClosestRowByEntry(2);
assertEquals(2, cursor.getCurrentRow().get("id"));
@@ -1090,11 +1090,11 @@ public class CursorTest extends TestCase {
assertTrue(cursor.isAfterLast());
db.close();
- }
+ }
}
-
+
public void testIndexCursorDelete() throws Exception
- {
+ {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
Database db = openMem(testDB);
@@ -1111,7 +1111,7 @@ public class CursorTest extends TestCase {
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
expectedData = new ArrayList<String>();
- for(Iterator<? extends Row> iter =
+ for(Iterator<? extends Row> iter =
cursor.newEntryIterable(1).iterator();
iter.hasNext(); ) {
expectedData.add(iter.next().getString("data"));
@@ -1134,7 +1134,7 @@ public class CursorTest extends TestCase {
}
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
-
+
expectedData = new ArrayList<String>();
for(Row row : cursor.newEntryIterable(1)
.addColumnNames("data")) {
@@ -1142,13 +1142,13 @@ public class CursorTest extends TestCase {
}
assertTrue(expectedData.isEmpty());
-
+
db.close();
- }
+ }
}
-
+
public void testCursorDelete() throws Exception
- {
+ {
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
Database db = openMem(testDB);
@@ -1191,7 +1191,7 @@ public class CursorTest extends TestCase {
}
assertEquals(Arrays.asList("baz11", "baz11-2"), expectedData);
-
+
expectedData = new ArrayList<String>();
for(Row row : cursor.newIterable().setColumnNames(
Arrays.asList("otherfk1", "data"))) {
@@ -1201,11 +1201,11 @@ public class CursorTest extends TestCase {
}
assertTrue(expectedData.isEmpty());
-
+
db.close();
- }
+ }
}
-
+
public void testFindByRowId() throws Exception {
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
Database db = createTestTable(fileFormat);
@@ -1233,25 +1233,25 @@ public class CursorTest extends TestCase {
}
}
- private static void doTestFindByRowId(Cursor cursor)
+ private static void doTestFindByRowId(Cursor cursor)
throws Exception
{
for(int i = 0; i < 3; ++i) {
cursor.moveToNextRow();
- }
+ }
Row r1 = cursor.getCurrentRow();
for(int i = 0; i < 3; ++i) {
cursor.moveToNextRow();
- }
+ }
Row r2 = cursor.getCurrentRow();
doTestFindByRowId(cursor, r1, 2);
doTestFindByRowId(cursor, r2, 5);
- }
+ }
private static void doTestFindByRowId(Cursor cursor, Row row, int id)
throws Exception
@@ -1273,7 +1273,7 @@ public class CursorTest extends TestCase {
assertFalse(cursor.findRow(RowIdImpl.FIRST_ROW_ID));
- assertEquals(id - 1, cursor.getCurrentRow().get("id"));
+ assertEquals(id - 1, cursor.getCurrentRow().get("id"));
}
public void testIterationEarlyExit() throws Exception {
@@ -1301,7 +1301,7 @@ public class CursorTest extends TestCase {
IndexCursor cursor = CursorBuilder.createCursor(
table.getIndex("value_idx"));
-
+
try {
cursor.newIterable()
.addMatchPattern("value", "val-9")
@@ -1336,7 +1336,7 @@ public class CursorTest extends TestCase {
public void testPartialIndexFind() throws Exception
{
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
-
+
Database db = createMem(fileFormat);
TableImpl t = (TableImpl)new TableBuilder("Test")
@@ -1348,23 +1348,23 @@ public class CursorTest extends TestCase {
.addIndex(new IndexBuilder("idx3").addColumns("data1", "num2", "key3"))
.toTable(db);
- Index idx = t.findIndexForColumns(Arrays.asList("data1"),
+ Index idx = t.findIndexForColumns(Arrays.asList("data1"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx3", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx3", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx3", idx.getName());
- assertNull(t.findIndexForColumns(Arrays.asList("num2"),
+ assertNull(t.findIndexForColumns(Arrays.asList("num2"),
TableImpl.IndexFeature.ANY_MATCH));
- assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
+ assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
TableImpl.IndexFeature.ANY_MATCH));
- assertNull(t.findIndexForColumns(Arrays.asList("data1"),
+ assertNull(t.findIndexForColumns(Arrays.asList("data1"),
TableImpl.IndexFeature.EXACT_MATCH));
@@ -1372,23 +1372,23 @@ public class CursorTest extends TestCase {
.addColumns("data1", "num2")
.addToTable(t);
- idx = t.findIndexForColumns(Arrays.asList("data1"),
+ idx = t.findIndexForColumns(Arrays.asList("data1"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx2", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx2", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx3", idx.getName());
- assertNull(t.findIndexForColumns(Arrays.asList("num2"),
+ assertNull(t.findIndexForColumns(Arrays.asList("num2"),
TableImpl.IndexFeature.ANY_MATCH));
- assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
+ assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
TableImpl.IndexFeature.ANY_MATCH));
- assertNull(t.findIndexForColumns(Arrays.asList("data1"),
+ assertNull(t.findIndexForColumns(Arrays.asList("data1"),
TableImpl.IndexFeature.EXACT_MATCH));
@@ -1396,21 +1396,21 @@ public class CursorTest extends TestCase {
.addColumns("data1")
.addToTable(t);
- idx = t.findIndexForColumns(Arrays.asList("data1"),
+ idx = t.findIndexForColumns(Arrays.asList("data1"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx1", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx2", idx.getName());
- idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
+ idx = t.findIndexForColumns(Arrays.asList("data1", "num2", "key3"),
TableImpl.IndexFeature.ANY_MATCH);
assertEquals("idx3", idx.getName());
- assertNull(t.findIndexForColumns(Arrays.asList("num2"),
+ assertNull(t.findIndexForColumns(Arrays.asList("num2"),
TableImpl.IndexFeature.ANY_MATCH));
- assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
+ assertNull(t.findIndexForColumns(Arrays.asList("data1", "key3"),
TableImpl.IndexFeature.ANY_MATCH));
db.close();
@@ -1420,7 +1420,7 @@ public class CursorTest extends TestCase {
public void testPartialIndexLookup() throws Exception
{
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
-
+
Database db = createMem(fileFormat);
TableImpl t = (TableImpl)new TableBuilder("Test")
@@ -1482,7 +1482,7 @@ public class CursorTest extends TestCase {
doFindFirstByEntry(c, 27, "C", 1, "K1");
doFindFirstByEntry(c, null, "C", 4, "K3");
}
-
+
try {
if(colCount > 2) {
c.findFirstRowByEntry("C", 4, "K1", 14);
@@ -1509,27 +1509,27 @@ public class CursorTest extends TestCase {
doFindByEntry(c, new int[]{}, "B", 3, "K3");
}
- doFindByRow(idx, 13,
+ doFindByRow(idx, 13,
"data1", "B", "value", "value13");
- doFindByRow(idx, 13,
+ doFindByRow(idx, 13,
"data1", "B", "key3", "K1", "value", "value13");
- doFindByRow(idx, 13,
+ doFindByRow(idx, 13,
"data1", "B", "num2", 3, "key3", "K1", "value", "value13");
- doFindByRow(idx, 13,
+ doFindByRow(idx, 13,
"num2", 3, "value", "value13");
- doFindByRow(idx, 13,
+ doFindByRow(idx, 13,
"value", "value13");
- doFindByRow(idx, null,
+ doFindByRow(idx, null,
"data1", "B", "num2", 5, "key3", "K1", "value", "value13");
- doFindByRow(idx, null,
+ doFindByRow(idx, null,
"data1", "B", "value", "value4");
Column col = idx.getTable().getColumn("data1");
doFindValue(idx, 21, col, "C");
- doFindValue(idx, null, col, "Z");
+ doFindValue(idx, null, col, "Z");
col = idx.getTable().getColumn("value");
doFindValue(idx, 21, col, "value21");
- doFindValue(idx, null, col, "valueZ");
+ doFindValue(idx, null, col, "valueZ");
}
private static void doFindFirstByEntry(IndexCursor c, Integer expectedId,
@@ -1543,7 +1543,7 @@ public class CursorTest extends TestCase {
assertFalse(c.findFirstRowByEntry(entry));
}
}
-
+
private static void doFindByEntryRange(IndexCursor c, int start, int end,
Object... entry)
{
@@ -1553,7 +1553,7 @@ public class CursorTest extends TestCase {
}
doFindByEntry(c, expectedIds, entry);
}
-
+
private static void doFindByEntry(IndexCursor c, int[] ids,
Object... entry)
{
@@ -1563,7 +1563,7 @@ public class CursorTest extends TestCase {
}
doFindByEntry(c, expectedIds, entry);
}
-
+
private static void doFindByEntry(IndexCursor c, List<Integer> expectedIds,
Object... entry)
{
@@ -1585,9 +1585,9 @@ public class CursorTest extends TestCase {
} else {
assertNull(r);
}
- }
+ }
- private static void doFindValue(Index idx, Integer id,
+ private static void doFindValue(Index idx, Integer id,
Column columnPattern, Object valuePattern)
throws Exception
{
@@ -1598,6 +1598,5 @@ public class CursorTest extends TestCase {
} else {
assertNull(value);
}
- }
+ }
}
-
diff --git a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java
index fef09cc..d4bccd8 100644
--- a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java
+++ b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java
@@ -26,11 +26,11 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
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;
@@ -90,11 +90,19 @@ public class TestUtil
public static Database open(FileFormat fileFormat, File file, boolean inMem)
throws Exception
{
+ return open(fileFormat, file, inMem, null);
+ }
+
+ public static Database open(FileFormat fileFormat, File file, boolean inMem,
+ Charset charset)
+ throws Exception
+ {
FileChannel channel = (inMem ? MemFileChannel.newChannel(
file, MemFileChannel.RW_CHANNEL_MODE)
: null);
final Database db = new DatabaseBuilder(file).setReadOnly(true)
- .setAutoSync(getTestAutoSync()).setChannel(channel).open();
+ .setAutoSync(getTestAutoSync()).setChannel(channel)
+ .setCharset(charset).open();
Assert.assertEquals("Wrong JetFormat.",
DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
((DatabaseImpl)db).getFormat());
@@ -103,11 +111,13 @@ public class TestUtil
}
public static Database open(TestDB testDB) throws Exception {
- return open(testDB.getExpectedFileFormat(), testDB.getFile());
+ return open(testDB.getExpectedFileFormat(), testDB.getFile(), false,
+ testDB.getExpectedCharset());
}
public static Database openMem(TestDB testDB) throws Exception {
- return open(testDB.getExpectedFileFormat(), testDB.getFile(), true);
+ return open(testDB.getExpectedFileFormat(), testDB.getFile(), true,
+ testDB.getExpectedCharset());
}
public static Database create(FileFormat fileFormat) throws Exception {
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
index 878ffdc..bf386d8 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
@@ -63,7 +63,7 @@ public class IndexCodesTest extends TestCase {
public void testIndexCodes() throws Exception
{
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX_CODES)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX_CODES, true)) {
Database db = openMem(testDB);
for(Table t : db) {
@@ -86,6 +86,14 @@ public class IndexCodesTest extends TestCase {
while(cursor.moveToNextRow()) {
Row row = cursor.getCurrentRow();
+
+ Object data = row.get("data");
+ if((testDB.getExpectedFileFormat() == Database.FileFormat.V1997) &&
+ (data instanceof String) && ((String)data).contains("\uFFFD")) {
+ // this row has a character not supported in the v1997 charset
+ continue;
+ }
+
Cursor.Position curPos = cursor.getSavepoint().getCurrentPosition();
boolean success = false;
try {
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
index 66c8a71..9257e5e 100644
--- a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
@@ -3,6 +3,7 @@ package com.healthmarketscience.jackcess.impl;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.nio.channels.FileChannel;
import java.nio.channels.NonWritableChannelException;
import java.sql.SQLException;
@@ -67,6 +68,9 @@ public class JetFormatTest extends TestCase {
public String toString() { return _basename; }
}
+ /** charset for access 97 dbs */
+ public static final Charset A97_CHARSET = Charset.forName("windows-1252");
+
/** Defines currently supported db file formats. (can be modified at
runtime via the system property
"com.healthmarketscience.jackcess.testFormats") */
@@ -109,12 +113,15 @@ public class JetFormatTest extends TestCase {
private final File dbFile;
private final FileFormat expectedFileFormat;
+ private final Charset _charset;
private TestDB(File databaseFile,
- FileFormat expectedDBFileFormat) {
+ FileFormat expectedDBFileFormat,
+ Charset charset) {
dbFile = databaseFile;
expectedFileFormat = expectedDBFileFormat;
+ _charset = charset;
}
public final File getFile() { return dbFile; }
@@ -127,6 +134,10 @@ public class JetFormatTest extends TestCase {
return DatabaseImpl.getFileFormatDetails(expectedFileFormat).getFormat();
}
+ public final Charset getExpectedCharset() {
+ return _charset;
+ }
+
@Override
public final String toString() {
return "dbFile: " + dbFile.getAbsolutePath()
@@ -162,7 +173,12 @@ public class JetFormatTest extends TestCase {
throw new RuntimeException(e);
}
- supportedTestDBs.add(new TestDB(testFile, fileFormat));
+ Charset charset = null;
+ if(fileFormat == FileFormat.V1997) {
+ charset = A97_CHARSET;
+ }
+
+ supportedTestDBs.add(new TestDB(testFile, fileFormat, charset));
}
return supportedTestDBs;
}