diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2016-12-31 17:55:42 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2016-12-31 17:55:42 +0000 |
commit | cec8681020e062c056233ef706af78d37d808f91 (patch) | |
tree | bcfe190fdeaa019d51e7286907bb3abd0463a6c1 /src/test/java | |
parent | 9664daf8b3d109ea34964cd0584a903190112c47 (diff) | |
parent | 0114aa89c5a9b9c1c66a1ea4fd70b311b6f0c2b0 (diff) | |
download | jackcess-cec8681020e062c056233ef706af78d37d808f91.tar.gz jackcess-cec8681020e062c056233ef706af78d37d808f91.zip |
merge trunk changes through r1077
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1078 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java | 16 | ||||
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java | 111 |
2 files changed, 89 insertions, 38 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java index 93c5ca9..4efbd60 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java @@ -1,8 +1,8 @@ package com.healthmarketscience.jackcess.impl; import java.io.File; -import java.io.IOException; import java.nio.channels.FileChannel; +import java.nio.channels.NonWritableChannelException; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; @@ -11,6 +11,7 @@ import java.util.Set; import com.healthmarketscience.jackcess.Database; import static com.healthmarketscience.jackcess.Database.*; import com.healthmarketscience.jackcess.DatabaseBuilder; +import com.healthmarketscience.jackcess.PropertyMap; import junit.framework.TestCase; import static com.healthmarketscience.jackcess.TestUtil.*; @@ -208,10 +209,17 @@ public class JetFormatTest extends TestCase { for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { Database db = null; - IOException failure = null; + Exception failure = null; try { db = openCopy(testDB); - } catch(IOException e) { + + if(testDB.getExpectedFormat().READ_ONLY) { + PropertyMap props = db.getUserDefinedProperties(); + props.put("foo", "bar"); + props.save(); + } + + } catch(Exception e) { failure = e; } finally { if(db != null) { @@ -222,7 +230,7 @@ public class JetFormatTest extends TestCase { if(!testDB.getExpectedFormat().READ_ONLY) { assertNull(failure); } else { - assertTrue(failure.getMessage().contains("does not support writing")); + assertTrue(failure instanceof NonWritableChannelException); } } diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java index aad1ddf..539a7c0 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/UsageMapTest.java @@ -2,11 +2,18 @@ package com.healthmarketscience.jackcess.impl; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import com.healthmarketscience.jackcess.ColumnBuilder; +import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.Database; import com.healthmarketscience.jackcess.DatabaseBuilder; -import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import com.healthmarketscience.jackcess.Table; +import com.healthmarketscience.jackcess.TableBuilder; import junit.framework.TestCase; +import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; /** * @author Dan Rollo @@ -15,40 +22,76 @@ import junit.framework.TestCase; */ public final class UsageMapTest extends TestCase { - public void testRead() throws Exception { - for (final TestDB testDB : SUPPORTED_DBS_TEST) { - final int expectedFirstPage; - final int expectedLastPage; - final Database.FileFormat expectedFileFormat = testDB.getExpectedFileFormat(); - if (Database.FileFormat.V2000.equals(expectedFileFormat)) { - expectedFirstPage = 743; - expectedLastPage = 767; - } else if (Database.FileFormat.V2003.equals(expectedFileFormat)) { - expectedFirstPage = 16; - expectedLastPage = 799; - } else if (Database.FileFormat.V2007.equals(expectedFileFormat)) { - expectedFirstPage = 94; - expectedLastPage = 511; - } else if (Database.FileFormat.V2010.equals(expectedFileFormat)) { - expectedFirstPage = 109; - expectedLastPage = 511; - } else { - throw new IllegalAccessException("Unknown file format: " + expectedFileFormat); - } - checkUsageMapRead(testDB.getFile(), expectedFirstPage, expectedLastPage); - } + public void testRead() throws Exception { + for (final TestDB testDB : SUPPORTED_DBS_TEST) { + final int expectedFirstPage; + final int expectedLastPage; + final Database.FileFormat expectedFileFormat = testDB.getExpectedFileFormat(); + if (Database.FileFormat.V2000.equals(expectedFileFormat)) { + expectedFirstPage = 743; + expectedLastPage = 767; + } else if (Database.FileFormat.V2003.equals(expectedFileFormat)) { + expectedFirstPage = 16; + expectedLastPage = 799; + } else if (Database.FileFormat.V2007.equals(expectedFileFormat)) { + expectedFirstPage = 94; + expectedLastPage = 511; + } else if (Database.FileFormat.V2010.equals(expectedFileFormat)) { + expectedFirstPage = 109; + expectedLastPage = 511; + } else { + throw new IllegalAccessException("Unknown file format: " + expectedFileFormat); + } + checkUsageMapRead(testDB.getFile(), expectedFirstPage, expectedLastPage); } + } + + private static void checkUsageMapRead( + final File dbFile, final int expectedFirstPage, final int expectedLastPage) + throws IOException { + + final Database db = DatabaseBuilder.open(dbFile); + final UsageMap usageMap = UsageMap.read((DatabaseImpl)db, + PageChannel.PAGE_GLOBAL_USAGE_MAP, + PageChannel.ROW_GLOBAL_USAGE_MAP, + true); + assertEquals("Unexpected FirstPageNumber.", expectedFirstPage, + usageMap.getFirstPageNumber()); + assertEquals("Unexpected LastPageNumber.", expectedLastPage, + usageMap.getLastPageNumber()); + } + + public void testGobalReferenceUsageMap() throws Exception + { + Database db = openCopy( + Database.FileFormat.V2000, + new File("src/test/data/V2000/testRefGlobalV2000.mdb")); - private static void checkUsageMapRead(final File dbFile, - final int expectedFirstPage, final int expectedLastPage) - throws IOException { - - final Database db = DatabaseBuilder.open(dbFile); - final UsageMap usageMap = UsageMap.read((DatabaseImpl)db, - PageChannel.PAGE_GLOBAL_USAGE_MAP, - PageChannel.ROW_GLOBAL_USAGE_MAP, - true); - assertEquals("Unexpected FirstPageNumber.", expectedFirstPage, usageMap.getFirstPageNumber()); - assertEquals("Unexpected LastPageNumber.", expectedLastPage, usageMap.getLastPageNumber()); + Table t = new TableBuilder("Test2") + .addColumn(new ColumnBuilder("id", DataType.LONG)) + .addColumn(new ColumnBuilder("data1", DataType.TEXT)) + .addColumn(new ColumnBuilder("data2", DataType.TEXT)) + .toTable(db); + + + ((DatabaseImpl)db).getPageChannel().startWrite(); + try { + List<Object[]> rows = new ArrayList<Object[]>(); + for(int i = 0; i < 300000; ++i) { + String s1 = "r" + i + "-" + createString(100); + String s2 = "r" + i + "-" + createString(200); + + rows.add(new Object[]{i, s1, s2}); + + if((i % 2000) == 0) { + t.addRows(rows); + rows.clear(); + } + } + } finally { + ((DatabaseImpl)db).getPageChannel().finishWrite(); } + + db.close(); + } } |