diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2021-06-10 21:42:39 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2021-06-10 21:42:39 +0000 |
commit | 1ff24f80a1308c43bba7a6035b6d1d830c141545 (patch) | |
tree | b3492f81293a3ad4d93f92b056de62f7252c3557 /src/test/java/com/healthmarketscience | |
parent | d52519607f1d944aed33008be62a3bbfcf05ae52 (diff) | |
download | jackcess-1ff24f80a1308c43bba7a6035b6d1d830c141545.tar.gz jackcess-1ff24f80a1308c43bba7a6035b6d1d830c141545.zip |
tighten up readonly handling for external channels; minor test code refactor
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1368 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/TestUtil.java | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java index e10fd39..f06f89d 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java +++ b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java @@ -26,8 +26,8 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.lang.reflect.Field; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.nio.channels.FileChannel; +import java.nio.charset.Charset; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; @@ -97,17 +97,7 @@ public class TestUtil Charset charset) throws Exception { - FileChannel channel = (inMem ? MemFileChannel.newChannel( - file, MemFileChannel.RW_CHANNEL_MODE) - : null); - final Database db = new DatabaseBuilder(file).setReadOnly(true) - .setAutoSync(getTestAutoSync()).setChannel(channel) - .setCharset(charset).open(); - Assert.assertEquals("Wrong JetFormat.", - DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), - ((DatabaseImpl)db).getFormat()); - Assert.assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat()); - return db; + return openDB(fileFormat, file, inMem, charset, true); } public static Database open(TestDB testDB) throws Exception { @@ -116,8 +106,8 @@ public class TestUtil } public static Database openMem(TestDB testDB) throws Exception { - return open(testDB.getExpectedFileFormat(), testDB.getFile(), true, - testDB.getExpectedCharset()); + return openDB(testDB.getExpectedFileFormat(), testDB.getFile(), true, + testDB.getExpectedCharset(), false); } public static Database create(FileFormat fileFormat) throws Exception { @@ -196,15 +186,27 @@ public class TestUtil { File tmp = createTempFile(keep); copyFile(file, tmp); - Database db = new DatabaseBuilder(tmp).setAutoSync(getTestAutoSync()).open(); + return openDB(fileFormat, tmp, false, null, false); + } + + private static Database openDB( + FileFormat fileFormat, File file, boolean inMem, Charset charset, + boolean readOnly) + throws Exception + { + FileChannel channel = (inMem ? MemFileChannel.newChannel( + file, MemFileChannel.RW_CHANNEL_MODE) + : null); + final Database db = new DatabaseBuilder(file).setReadOnly(readOnly) + .setAutoSync(getTestAutoSync()).setChannel(channel) + .setCharset(charset).open(); Assert.assertEquals("Wrong JetFormat.", - DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), - ((DatabaseImpl)db).getFormat()); + DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), + ((DatabaseImpl)db).getFormat()); Assert.assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat()); return db; } - static Object[] createTestRow(String col1Val) { return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d, 777.88f, (short) 999, new Date()}; |