]> source.dussan.org Git - jackcess.git/commitdiff
remove unsupported v1997, minor reformats
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 7 Apr 2010 02:33:49 +0000 (02:33 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 7 Apr 2010 02:33:49 +0000 (02:33 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@457 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/Database.java
src/java/com/healthmarketscience/jackcess/JetFormat.java
test/src/java/com/healthmarketscience/jackcess/CursorTest.java
test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java

index 5044de72bce625f6ccf0c5423ec146173f852a38..73a851495f46eb93a49b0e084cfa0d6e8617853d 100644 (file)
@@ -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");
index f5cc175f0bfd946dff0784c8324995e2224c333a..56309a867e2152e0b570274374d711c124ba9dd0 100644 (file)
@@ -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<Database.FileFormat,byte[]> POSSIBLE_VERSION_3 = 
-      Collections.singletonMap(Database.FileFormat.V1997, (byte[])null);
-
     private static final Map<Database.FileFormat,byte[]> POSSIBLE_VERSION_4 = 
       new EnumMap<Database.FileFormat,byte[]>(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<Database.FileFormat,byte[]> getPossibleFileFormats() {
-      return PossibleFileFormats.POSSIBLE_VERSION_3;
-    }
-
-  }
-
   private static final class Jet5Format extends Jet4Format {
       private Jet5Format() {
         super("VERSION_5");
index 63eab0c312900a5c6e10418dd6e0634c9cc6e1f2..12b4d44727954eb604f125a04d250d1a68a5c41e 100644 (file)
@@ -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<TestDB> 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");
index 96365e4a353a3ebcc41b59adcb1177bf0c653cf7..c4b9b1f9e31c821896fe8ffd52d928aac732bbff 100644 (file)
@@ -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<TestDB> 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<TestDB> supportedTestDBs = new ArrayList<TestDB>();
+          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<TestDB> 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();
+        }
+    }
+
 }
index 85b063057ef24d3abf38c484bd1bd7003f5aa78f..dcc2052052150e62f3d05a9bea7a2dd1754952e5 100644 (file)
@@ -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;