From: James Ahlborn Date: Wed, 7 Apr 2010 02:33:49 +0000 (+0000) Subject: remove unsupported v1997, minor reformats X-Git-Tag: jackcess-1.2.0~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9081d98806033fd90cd16a33d1e6ee103cf2c499;p=jackcess.git remove unsupported v1997, minor reformats git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@457 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 5044de7..73a8514 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -173,7 +173,6 @@ public class Database public static enum FileFormat { - V1997(null, JetFormat.VERSION_3), // v97 is not supported, so no empty template is provided V2000("com/healthmarketscience/jackcess/empty.mdb", JetFormat.VERSION_4), V2003("com/healthmarketscience/jackcess/empty2003.mdb", JetFormat.VERSION_4), V2007("com/healthmarketscience/jackcess/empty2007.accdb", JetFormat.VERSION_5, ".accdb"); diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index f5cc175..56309a8 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -70,9 +70,6 @@ public abstract class JetFormat { // use nested inner class to avoid problematic static init loops private static final class PossibleFileFormats { - private static final Map POSSIBLE_VERSION_3 = - Collections.singletonMap(Database.FileFormat.V1997, (byte[])null); - private static final Map POSSIBLE_VERSION_4 = new EnumMap(Database.FileFormat.class); @@ -165,7 +162,6 @@ public abstract class JetFormat { public final Charset CHARSET; - public static final JetFormat VERSION_3 = new Jet3Format(); public static final JetFormat VERSION_4 = new Jet4Format(); public static final JetFormat VERSION_5 = new Jet5Format(); @@ -182,14 +178,14 @@ public abstract class JetFormat { } buffer.flip(); byte version = buffer.get(); - if (version == CODE_VERSION_3) { - return VERSION_3; - } else if (version == CODE_VERSION_4) { + if (version == CODE_VERSION_4) { return VERSION_4; } else if (version == CODE_VERSION_5) { return VERSION_5; } - throw new IOException("Unsupported version: " + version); + throw new IOException("Unsupported " + + ((version < CODE_VERSION_4) ? "older" : "newer") + + " version: " + version); } private JetFormat(String name) { @@ -499,18 +495,6 @@ public abstract class JetFormat { } - private static final class Jet3Format extends Jet4Format { - private Jet3Format() { - super("VERSION_3"); - } - - @Override - protected Map getPossibleFileFormats() { - return PossibleFileFormats.POSSIBLE_VERSION_3; - } - - } - private static final class Jet5Format extends Jet4Format { private Jet5Format() { super("VERSION_5"); diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java index 63eab0c..12b4d44 100644 --- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java @@ -98,9 +98,12 @@ public class CursorTest extends TestCase { return expectedRows; } - static final TestDB[] INDEX_CURSOR_DBS = TestDB.getSupportedForBasename(Basename.INDEX_CURSOR); + static final List INDEX_CURSOR_DBS = + TestDB.getSupportedForBasename(Basename.INDEX_CURSOR); - static Database createTestIndexTable(final TestDB indexCursorDB) throws Exception { + static Database createTestIndexTable(final TestDB indexCursorDB) + throws Exception + { Database db = openCopy(indexCursorDB); Table table = db.getTable("test"); diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java index 96365e4..c4b9b1f 100644 --- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java @@ -1,10 +1,12 @@ package com.healthmarketscience.jackcess; -import junit.framework.TestCase; - import java.io.File; import java.io.IOException; import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; /** * @author Dan Rollo @@ -37,20 +39,22 @@ public final class JetFormatTest extends TestCase { PROMOTION("testPromotion"), ; - private final String basename; + private final String _basename; - Basename(final String fileBasename) { - basename = fileBasename; + Basename(String fileBasename) { + _basename = fileBasename; } + @Override + public String toString() { return _basename; } } /** Defines currently supported db file formats. */ - final static Database.FileFormat[] SUPPORTED_FILEFORMATS = new Database.FileFormat[] { + final static Database.FileFormat[] SUPPORTED_FILEFORMATS = + new Database.FileFormat[] { Database.FileFormat.V2000, Database.FileFormat.V2003, Database.FileFormat.V2007, - // @todo Uncomment these elements to run test other formats }; /** @@ -61,45 +65,56 @@ public final class JetFormatTest extends TestCase { private final File dbFile; private final Database.FileFormat expectedFileFormat; - private TestDB(final File databaseFile, final Database.FileFormat expectedDBFileFormat) { + private TestDB(File databaseFile, + Database.FileFormat expectedDBFileFormat) { dbFile = databaseFile; expectedFileFormat = expectedDBFileFormat; } public final File getFile() { return dbFile; } - public final Database.FileFormat getExpectedFileFormat() { return expectedFileFormat; } - public final JetFormat getExpectedFormat() { return expectedFileFormat.getJetFormat(); } + public final Database.FileFormat getExpectedFileFormat() { + return expectedFileFormat; + } + + public final JetFormat getExpectedFormat() { + return expectedFileFormat.getJetFormat(); + } + + @Override public final String toString() { - return "dbFile: " + dbFile.getAbsolutePath() - + "; expectedFileFormat: " + expectedFileFormat; + return "dbFile: " + dbFile.getAbsolutePath() + + "; expectedFileFormat: " + expectedFileFormat; } - public static TestDB[] getSupportedForBasename(final Basename basename) { + public static List getSupportedForBasename(Basename basename) { - final TestDB[] supportedTestDBs = new TestDB[SUPPORTED_FILEFORMATS.length]; - int i = 0; - for (final Database.FileFormat fileFormat: SUPPORTED_FILEFORMATS) { - supportedTestDBs[i++] = new TestDB( - getFileForBasename(basename, fileFormat), - fileFormat); - } - return supportedTestDBs; + List supportedTestDBs = new ArrayList(); + for (Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + supportedTestDBs.add(new TestDB( + getFileForBasename(basename, fileFormat), + fileFormat)); + } + return supportedTestDBs; } - private static File getFileForBasename(Basename basename, Database.FileFormat fileFormat) { + private static File getFileForBasename( + Basename basename, Database.FileFormat fileFormat) { return new File(DIR_TEST_DATA, - fileFormat.name() + "/" + basename.basename + fileFormat.name() + + fileFormat.name() + File.separator + + basename + fileFormat.name() + fileFormat.getFileExtension()); } } - static final TestDB UNSUPPORTED_TEST_V1997 = new TestDB( - TestDB.getFileForBasename(Basename.TEST, Database.FileFormat.V1997), Database.FileFormat.V1997); + private static final File UNSUPPORTED_TEST_V1997 = + new File(DIR_TEST_DATA, "V1997" + File.separator + + Basename.TEST + "V1997.mdb"); - static final TestDB[] SUPPORTED_DBS_TEST= TestDB.getSupportedForBasename(Basename.TEST); + static final List SUPPORTED_DBS_TEST = + TestDB.getSupportedForBasename(Basename.TEST); public void testGetFormat() throws Exception { @@ -107,10 +122,10 @@ public final class JetFormatTest extends TestCase { JetFormat.getFormat(null); fail("npe"); } catch (NullPointerException e) { - assertNull(e.getMessage()); + // success } - checkJetFormat(UNSUPPORTED_TEST_V1997); + checkUnsupportedJetFormat(UNSUPPORTED_TEST_V1997); for (final TestDB testDB : SUPPORTED_DBS_TEST) { checkJetFormat(testDB); @@ -123,12 +138,29 @@ public final class JetFormatTest extends TestCase { final FileChannel channel = Database.openChannel(testDB.dbFile, false); try { - final JetFormat fmtActual = JetFormat.getFormat(channel); - assertEquals("Unexpected JetFormat for dbFile: " + testDB.dbFile.getAbsolutePath(), - testDB.expectedFileFormat.getJetFormat(), fmtActual); + JetFormat fmtActual = JetFormat.getFormat(channel); + assertEquals("Unexpected JetFormat for dbFile: " + + testDB.dbFile.getAbsolutePath(), + testDB.expectedFileFormat.getJetFormat(), fmtActual); } finally { channel.close(); } } + + private static void checkUnsupportedJetFormat(File testDB) + throws IOException { + + 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(); + } + } + } diff --git a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java index 85b0630..dcc2052 100644 --- a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java @@ -15,13 +15,6 @@ import static com.healthmarketscience.jackcess.JetFormatTest.*; public final class UsageMapTest extends TestCase { public void testRead() throws Exception { - try { - Database.open(UNSUPPORTED_TEST_V1997.getFile()); - fail("mdb v97 usage map unsupported"); - } catch (IOException e) { - assertEquals(UsageMap.MSG_PREFIX_UNRECOGNIZED_MAP + 2, e.getMessage()); - } - for (final TestDB testDB : SUPPORTED_DBS_TEST) { final int expectedFirstPage; final int expectedLastPage;