diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/accdb/test.accdb | bin | 0 -> 413696 bytes | |||
-rw-r--r-- | test/data/mdb2003/test2003.mdb | bin | 0 -> 3162112 bytes | |||
-rw-r--r-- | test/data/mdb97/test97.mdb | bin | 0 -> 118784 bytes | |||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java | 49 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java | 39 |
5 files changed, 88 insertions, 0 deletions
diff --git a/test/data/accdb/test.accdb b/test/data/accdb/test.accdb Binary files differnew file mode 100644 index 0000000..67bea0c --- /dev/null +++ b/test/data/accdb/test.accdb diff --git a/test/data/mdb2003/test2003.mdb b/test/data/mdb2003/test2003.mdb Binary files differnew file mode 100644 index 0000000..a1a7fd8 --- /dev/null +++ b/test/data/mdb2003/test2003.mdb diff --git a/test/data/mdb97/test97.mdb b/test/data/mdb97/test97.mdb Binary files differnew file mode 100644 index 0000000..2aa1060 --- /dev/null +++ b/test/data/mdb97/test97.mdb diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java new file mode 100644 index 0000000..ca46cdb --- /dev/null +++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java @@ -0,0 +1,49 @@ +package com.healthmarketscience.jackcess; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; +import java.nio.channels.FileChannel; + +/** + * @author Dan Rollo + * Date: Mar 5, 2010 + * Time: 12:44:21 PM + */ +public final class JetFormatTest extends TestCase { + + static final File DB_1997 = new File("test/data/mdb97/test97.mdb"); + static final File DB_2000 = new File("test/data/test.mdb"); + static final File DB_2003 = new File("test/data/mdb2003/test2003.mdb"); + static final File DB_2007 = new File("test/data/accdb/test.accdb"); + + public void testGetFormat() throws Exception { + try { + JetFormat.getFormat(null); + fail("npe"); + } catch (NullPointerException e) { + assertNull(e.getMessage()); + } + + checkJetFormat(DB_1997, JetFormat.VERSION_3); + checkJetFormat(DB_2000, JetFormat.VERSION_4); + checkJetFormat(DB_2003, JetFormat.VERSION_4); + checkJetFormat(DB_2007, JetFormat.VERSION_5); + } + + private static void checkJetFormat(final File dbFile, final JetFormat fmtExpected) + throws IOException { + + final FileChannel channel = Database.openChannel(dbFile, false); + try { + + final JetFormat fmtActual = JetFormat.getFormat(channel); + assertEquals("Unexpected JetFormat for dbFile: " + dbFile.getAbsolutePath(), + fmtExpected, fmtActual); + + } finally { + channel.close(); + } + } +} diff --git a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java new file mode 100644 index 0000000..47937b5 --- /dev/null +++ b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java @@ -0,0 +1,39 @@ +package com.healthmarketscience.jackcess; + +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; + +/** + * @author Dan Rollo + * Date: Mar 5, 2010 + * Time: 2:21:22 PM + */ +public final class UsageMapTest extends TestCase { + + public void testRead() throws Exception { + try { + Database.open(JetFormatTest.DB_1997); + fail("mdb v97 usage map unsupported"); + } catch (IOException e) { + assertEquals(UsageMap.MSG_PREFIX_UNRECOGNIZED_MAP + 2, e.getMessage()); + } + + checkUsageMapRead(JetFormatTest.DB_2000, 743, 767); + checkUsageMapRead(JetFormatTest.DB_2007, 42, 511); + } + + private static void checkUsageMapRead(final File dbFile, + final int expectedFirstPage, final int expectedLastPage) + throws IOException { + + final Database db = Database.open(dbFile); + final UsageMap usageMap = UsageMap.read(db, + 1, //PageChannel.PAGE_GLOBAL_USAGE_MAP, + 0, //PageChannel.ROW_GLOBAL_USAGE_MAP, + true); + assertEquals("Unexpected FirstPageNumber.", expectedFirstPage, usageMap.getFirstPageNumber()); + assertEquals("Unexpected LastPageNumber.", expectedLastPage, usageMap.getLastPageNumber()); + } +} |