summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2010-07-23 04:36:09 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2010-07-23 04:36:09 +0000
commit13e81be7d519cddd48a3f014f72f1086f8b9f291 (patch)
tree316118057c53db1bca4415e2cfdf4776b1842a8e /test
parent4a0bbd462cb4a1bed43934cefdf1087ed360b128 (diff)
downloadjackcess-13e81be7d519cddd48a3f014f72f1086f8b9f291.tar.gz
jackcess-13e81be7d519cddd48a3f014f72f1086f8b9f291.zip
add (initial) read-only support for Access 97 (jet format 3) databases (#3003375); add various ways to override charset and timezone (#2997751)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@475 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rwxr-xr-xtest/data/V1997/compIndexTestV1997.mdbbin0 -> 81920 bytes
-rwxr-xr-xtest/data/V1997/delColTestV1997.mdbbin0 -> 69632 bytes
-rwxr-xr-xtest/data/V1997/delTestV1997.mdbbin0 -> 65536 bytes
-rwxr-xr-xtest/data/V1997/test2V1997.mdbbin0 -> 122880 bytes
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java2
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java14
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/IndexTest.java4
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java148
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java2
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/TableTest.java10
10 files changed, 119 insertions, 61 deletions
diff --git a/test/data/V1997/compIndexTestV1997.mdb b/test/data/V1997/compIndexTestV1997.mdb
new file mode 100755
index 0000000..6121fc3
--- /dev/null
+++ b/test/data/V1997/compIndexTestV1997.mdb
Binary files differ
diff --git a/test/data/V1997/delColTestV1997.mdb b/test/data/V1997/delColTestV1997.mdb
new file mode 100755
index 0000000..9534e76
--- /dev/null
+++ b/test/data/V1997/delColTestV1997.mdb
Binary files differ
diff --git a/test/data/V1997/delTestV1997.mdb b/test/data/V1997/delTestV1997.mdb
new file mode 100755
index 0000000..add3763
--- /dev/null
+++ b/test/data/V1997/delTestV1997.mdb
Binary files differ
diff --git a/test/data/V1997/test2V1997.mdb b/test/data/V1997/test2V1997.mdb
new file mode 100755
index 0000000..b8b2ca2
--- /dev/null
+++ b/test/data/V1997/test2V1997.mdb
Binary files differ
diff --git a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
index c0ff64b..4f79602 100644
--- a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java
@@ -67,7 +67,7 @@ public class BigIndexTest extends TestCase {
public void testComplexIndex() throws Exception
{
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX, true)) {
// this file has an index with "compressed" entries and node pages
Database db = open(testDB);
Table t = db.getTable("Table1");
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index 4601cfa..1f993ee 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -176,7 +176,7 @@ public class DatabaseTest extends TestCase {
}
public void testReadDeletedRows() throws Exception {
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL, true)) {
Table table = open(testDB).getTable("Table");
int rows = 0;
while (table.getNextRow() != null) {
@@ -187,7 +187,7 @@ public class DatabaseTest extends TestCase {
}
public void testGetColumns() throws Exception {
- for (final TestDB testDB : SUPPORTED_DBS_TEST) {
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
List<Column> columns = open(testDB).getTable("Table1").getColumns();
assertEquals(9, columns.size());
@@ -213,7 +213,7 @@ public class DatabaseTest extends TestCase {
}
public void testGetNextRow() throws Exception {
- for (final TestDB testDB : SUPPORTED_DBS_TEST) {
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
final Database db = open(testDB);
assertEquals(4, db.getTableNames().size());
final Table table = db.getTable("Table1");
@@ -272,7 +272,7 @@ public class DatabaseTest extends TestCase {
assertEquals(Boolean.FALSE, row.get("I"));
}
- public void testCreate() throws Exception {
+ public void testCreate() throws Exception {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
assertEquals(0, db.getTableNames().size());
@@ -396,7 +396,7 @@ public class DatabaseTest extends TestCase {
public void testReadLongValue() throws Exception {
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) {
Database db = open(testDB);
Table table = db.getTable("MSP_PROJECTS");
Map<String, Object> row = table.getNextRow();
@@ -528,7 +528,7 @@ public class DatabaseTest extends TestCase {
}
public void testReadWithDeletedCols() throws Exception {
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL_COL)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL_COL, true)) {
Table table = open(testDB).getTable("Table1");
Map<String, Object> expectedRow0 = new LinkedHashMap<String, Object>();
@@ -733,7 +733,7 @@ public class DatabaseTest extends TestCase {
public void testMultiPageTableDef() throws Exception
{
- for (final TestDB testDB : SUPPORTED_DBS_TEST) {
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
List<Column> columns = open(testDB).getTable("Table2").getColumns();
assertEquals(89, columns.size());
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
index adf9985..504a3b8 100644
--- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java
@@ -84,7 +84,7 @@ public class IndexTest extends TestCase {
}
public void testPrimaryKey() throws Exception {
- for (final TestDB testDB : SUPPORTED_DBS_TEST) {
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
Table table = open(testDB).getTable("Table1");
Map<String, Boolean> foundPKs = new HashMap<String, Boolean>();
for(Index index : table.getIndexes()) {
@@ -100,7 +100,7 @@ public class IndexTest extends TestCase {
public void testIndexSlots() throws Exception
{
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) {
Database mdb = open(testDB);
Table table = mdb.getTable("Table1");
diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
index 44c5544..0c31519 100644
--- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
@@ -4,7 +4,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
@@ -12,6 +11,7 @@ import java.util.Set;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.Database.*;
+import static com.healthmarketscience.jackcess.DatabaseTest.*;
/**
* @author Dan Rollo
@@ -28,21 +28,20 @@ public class JetFormatTest extends TestCase {
public static enum Basename {
BIG_INDEX("bigIndexTest"),
- COMP_INDEX("compIndexTest"),
- DEL_COL("delColTest"),
- DEL("delTest"),
- FIXED_NUMERIC("fixedNumericTest"),
- FIXED_TEXT("fixedTextTest"),
- INDEX_CURSOR("indexCursorTest"),
- INDEX("indexTest"),
- OVERFLOW("overflowTest"),
- QUERY("queryTest"),
- TEST("test"),
- TEST2("test2"),
- INDEX_CODES("testIndexCodes"),
- INDEX_PROPERTIES("testIndexProperties"),
- PROMOTION("testPromotion"),
- ;
+ COMP_INDEX("compIndexTest"),
+ DEL_COL("delColTest"),
+ DEL("delTest"),
+ FIXED_NUMERIC("fixedNumericTest"),
+ FIXED_TEXT("fixedTextTest"),
+ INDEX_CURSOR("indexCursorTest"),
+ INDEX("indexTest"),
+ OVERFLOW("overflowTest"),
+ QUERY("queryTest"),
+ TEST("test"),
+ TEST2("test2"),
+ INDEX_CODES("testIndexCodes"),
+ INDEX_PROPERTIES("testIndexProperties"),
+ PROMOTION("testPromotion");
private final String _basename;
@@ -58,6 +57,7 @@ public class JetFormatTest extends TestCase {
runtime via the system property
"com.healthmarketscience.jackcess.testFormats") */
final static FileFormat[] SUPPORTED_FILEFORMATS;
+ final static FileFormat[] SUPPORTED_FILEFORMATS_FOR_READ;
static {
String testFormatStr = System.getProperty("com.healthmarketscience.jackcess.testFormats");
@@ -70,15 +70,21 @@ public class JetFormatTest extends TestCase {
}
List<FileFormat> supported = new ArrayList<FileFormat>();
- for(FileFormat ff : Arrays.asList(FileFormat.V2000, FileFormat.V2003,
- FileFormat.V2007)) {
+ List<FileFormat> supportedForRead = new ArrayList<FileFormat>();
+ for(FileFormat ff : FileFormat.values()) {
if(!testFormats.contains(ff)) {
continue;
}
+ supportedForRead.add(ff);
+ if(ff.getJetFormat().READ_ONLY) {
+ continue;
+ }
supported.add(ff);
}
SUPPORTED_FILEFORMATS = supported.toArray(new FileFormat[0]);
+ SUPPORTED_FILEFORMATS_FOR_READ =
+ supportedForRead.toArray(new FileFormat[0]);
}
/**
@@ -113,12 +119,36 @@ public class JetFormatTest extends TestCase {
}
public static List<TestDB> getSupportedForBasename(Basename basename) {
+ return getSupportedForBasename(basename, false);
+ }
+
+ public static List<TestDB> getSupportedForBasename(Basename basename,
+ boolean readOnly) {
List<TestDB> supportedTestDBs = new ArrayList<TestDB>();
- for (FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
- supportedTestDBs.add(new TestDB(
- getFileForBasename(basename, 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 {
+// System.out.println("FOO checking " + testFile);
+ Database db = Database.open(testFile, true);
+ FileFormat dbFileFormat = db.getFileFormat();
+ db.close();
+ if(dbFileFormat != fileFormat) {
+ throw new IllegalStateException("Expected " + fileFormat +
+ " was " + dbFileFormat);
+ }
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ supportedTestDBs.add(new TestDB(testFile, fileFormat));
}
return supportedTestDBs;
}
@@ -133,12 +163,10 @@ public class JetFormatTest extends TestCase {
}
}
- private static final File UNSUPPORTED_TEST_V1997 =
- new File(DIR_TEST_DATA, "V1997" + File.separator +
- Basename.TEST + "V1997.mdb");
-
static final List<TestDB> SUPPORTED_DBS_TEST =
TestDB.getSupportedForBasename(Basename.TEST);
+ static final List<TestDB> SUPPORTED_DBS_TEST_FOR_READ =
+ TestDB.getSupportedForBasename(Basename.TEST, true);
public void testGetFormat() throws Exception {
@@ -149,41 +177,61 @@ public class JetFormatTest extends TestCase {
// success
}
- checkUnsupportedJetFormat(UNSUPPORTED_TEST_V1997);
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
+
+ final FileChannel channel = Database.openChannel(testDB.dbFile, false);
+ try {
+
+ JetFormat fmtActual = JetFormat.getFormat(channel);
+ assertEquals("Unexpected JetFormat for dbFile: " +
+ testDB.dbFile.getAbsolutePath(),
+ testDB.expectedFileFormat.getJetFormat(), fmtActual);
+
+ } finally {
+ channel.close();
+ }
- for (final TestDB testDB : SUPPORTED_DBS_TEST) {
- checkJetFormat(testDB);
}
}
- private static void checkJetFormat(final TestDB testDB)
- throws IOException {
+ public void testReadOnlyFormat() throws Exception {
- final FileChannel channel = Database.openChannel(testDB.dbFile, false);
- try {
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
+
+ Database db = null;
+ IOException failure = null;
+ try {
+ db = openCopy(testDB);
+ } catch(IOException e) {
+ failure = e;
+ } finally {
+ if(db != null) {
+ db.close();
+ }
+ }
- JetFormat fmtActual = JetFormat.getFormat(channel);
- assertEquals("Unexpected JetFormat for dbFile: " +
- testDB.dbFile.getAbsolutePath(),
- testDB.expectedFileFormat.getJetFormat(), fmtActual);
+ if(!testDB.getExpectedFormat().READ_ONLY) {
+ assertNull(failure);
+ } else {
+ assertTrue(failure.getMessage().contains("does not support writing"));
+ }
- } finally {
- channel.close();
}
}
- private static void checkUnsupportedJetFormat(File testDB)
- throws IOException {
+ public void testFileFormat() throws Exception {
- final FileChannel channel = Database.openChannel(testDB, false);
- try {
- JetFormat.getFormat(channel);
- fail("Unexpected JetFormat for dbFile: " +
- testDB.getAbsolutePath());
- } catch(IOException ignored) {
- // success
- } finally {
- channel.close();
+ for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) {
+
+ Database db = null;
+ try {
+ db = open(testDB);
+ assertEquals(testDB.getExpectedFileFormat(), db.getFileFormat());
+ } finally {
+ if(db != null) {
+ db.close();
+ }
+ }
}
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
index a6f3c44..0311088 100644
--- a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java
@@ -45,7 +45,7 @@ public class RelationshipTest extends TestCase {
}
public void testSimple() throws Exception {
- for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) {
Database db = open(testDB);
Table t1 = db.getTable("Table1");
Table t2 = db.getTable("Table2");
diff --git a/test/src/java/com/healthmarketscience/jackcess/TableTest.java b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
index 54c819a..005d470 100644
--- a/test/src/java/com/healthmarketscience/jackcess/TableTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/TableTest.java
@@ -29,9 +29,11 @@ package com.healthmarketscience.jackcess;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.TimeZone;
import junit.framework.TestCase;
@@ -173,6 +175,14 @@ public class TableTest extends TestCase {
public Table getTable() {
return _testTable;
}
+ @Override
+ protected Charset getCharset() {
+ return getFormat().CHARSET;
+ }
+ @Override
+ protected TimeZone getTimeZone() {
+ return TimeZone.getDefault();
+ }
};
}