diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2006-09-26 13:39:56 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2006-09-26 13:39:56 +0000 |
commit | 0fbd0d45ecfcb310452b246824883e74241de39f (patch) | |
tree | 8947e252e0af7f6ea254a533ecfe26bdae5bfdcc /test | |
parent | c68aa36c48da14ec6db83945d23ee7a4a2803a51 (diff) | |
download | jackcess-0fbd0d45ecfcb310452b246824883e74241de39f.tar.gz jackcess-0fbd0d45ecfcb310452b246824883e74241de39f.zip |
support reading 'compressed' indexes (fix 1563654)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@124 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r-- | test/data/compIndexTest.mdb | bin | 0 -> 143360 bytes | |||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java | 52 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/IndexTest.java | 28 |
3 files changed, 50 insertions, 30 deletions
diff --git a/test/data/compIndexTest.mdb b/test/data/compIndexTest.mdb Binary files differnew file mode 100644 index 0000000..b93db5b --- /dev/null +++ b/test/data/compIndexTest.mdb diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 541f321..4fc8722 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -3,8 +3,12 @@ package com.healthmarketscience.jackcess; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigDecimal; import java.nio.ByteBuffer; @@ -323,19 +327,6 @@ public class DatabaseTest extends TestCase { assertTrue(!bogusFile.exists()); } - public void testPrimaryKey() throws Exception { - Table table = open().getTable("Table1"); - Map<String, Boolean> foundPKs = new HashMap<String, Boolean>(); - for(Index index : table.getIndexes()) { - foundPKs.put(index.getColumns().iterator().next().getName(), - index.isPrimaryKey()); - } - Map<String, Boolean> expectedPKs = new HashMap<String, Boolean>(); - expectedPKs.put("A", Boolean.TRUE); - expectedPKs.put("B", Boolean.FALSE); - assertEquals(expectedPKs, foundPKs); - } - public void testReadWithDeletedCols() throws Exception { Table table = Database.open(new File("test/data/delColTest.mdb")).getTable("Table1"); @@ -498,23 +489,6 @@ public class DatabaseTest extends TestCase { } } - public void testIndexSlots() throws Exception - { - Database mdb = Database.open(new File("test/data/indexTest.mdb")); - - Table table = mdb.getTable("Table1"); - assertEquals(4, table.getIndexes().size()); - assertEquals(4, table.getIndexSlotCount()); - - table = mdb.getTable("Table2"); - assertEquals(2, table.getIndexes().size()); - assertEquals(3, table.getIndexSlotCount()); - - table = mdb.getTable("Table3"); - assertEquals(2, table.getIndexes().size()); - assertEquals(3, table.getIndexSlotCount()); - } - public void testMultiPageTableDef() throws Exception { List<Column> columns = open().getTable("Table2").getColumns(); @@ -643,5 +617,23 @@ public class DatabaseTest extends TestCase { writer.println(row); } } + + static void copyFile(File srcFile, File dstFile) + throws IOException + { + // FIXME should really be using commons io FileUtils here, but don't want + // to add dep for one simple test method + byte[] buf = new byte[1024]; + OutputStream ostream = new FileOutputStream(dstFile); + InputStream istream = new FileInputStream(srcFile); + try { + int numBytes = 0; + while((numBytes = istream.read(buf)) >= 0) { + ostream.write(buf, 0, numBytes); + } + } finally { + ostream.close(); + } + } } diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index 0adeb10..33967bb 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -3,6 +3,7 @@ package com.healthmarketscience.jackcess; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -92,5 +93,32 @@ public class IndexTest extends TestCase { assertEquals(3, table.getIndexSlotCount()); } + public void testComplexIndex() throws Exception + { + // this file has an index with "compressed" entries and node pages + File origFile = new File("test/data/compIndexTest.mdb"); + Database db = Database.open(origFile); + Table t = db.getTable("Table1"); + assertEquals(512, countRows(t)); + db.close(); + + // copy to temp file and attemp to edit + File testFile = File.createTempFile("databaseTest", ".mdb"); + testFile.deleteOnExit(); + + copyFile(origFile, testFile); + + db = Database.open(testFile); + t = db.getTable("Table1"); + + try { + // we don't support writing these indexes + t.addRow(99, "abc", "def"); + fail("Should have thrown IOException"); + } catch(UnsupportedOperationException e) { + // success + } + } + } |