diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-17 04:14:00 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-17 04:14:00 +0000 |
commit | 1fcd851a9f5d780b3d78b92f89bd35a2d634b467 (patch) | |
tree | 1b6f37f25a95d3aaeb3d907f8d925f5889b39f4a /test/src/java | |
parent | 9ba0e78522e68b40c75b0cb86fe74815146ce20d (diff) | |
download | jackcess-1fcd851a9f5d780b3d78b92f89bd35a2d634b467.tar.gz jackcess-1fcd851a9f5d780b3d78b92f89bd35a2d634b467.zip |
Update table row count correctly on row deletion or bulk row addition,
bug #1681954.
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@174 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test/src/java')
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java | 27 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/IndexTest.java | 40 |
2 files changed, 58 insertions, 9 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 80c65cb..5235ef2 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -238,7 +238,8 @@ public class DatabaseTest extends TestCase { Object[] row3 = createTestRow("Tim3"); Table table = db.getTable("Test"); table.addRows(Arrays.asList(row1, row2, row3)); - + assertRowCount(3, table); + table.reset(); table.getNextRow(); table.getNextRow(); @@ -250,6 +251,7 @@ public class DatabaseTest extends TestCase { assertEquals("Tim1", outRow.get("A")); outRow = table.getNextRow(); assertEquals("Tim3", outRow.get("A")); + assertRowCount(2, table); // test multi row delete/add db = create(); @@ -261,29 +263,29 @@ public class DatabaseTest extends TestCase { table.addRow(row); } row[3] = 1974; - assertEquals(10, countRows(table)); + assertRowCount(10, table); table.reset(); table.getNextRow(); table.deleteCurrentRow(); - assertEquals(9, countRows(table)); + assertRowCount(9, table); table.reset(); table.getNextRow(); table.deleteCurrentRow(); - assertEquals(8, countRows(table)); + assertRowCount(8, table); table.reset(); for (int i = 0; i < 8; i++) { table.getNextRow(); } table.deleteCurrentRow(); - assertEquals(7, countRows(table)); + assertRowCount(7, table); table.addRow(row); - assertEquals(8, countRows(table)); + assertRowCount(8, table); table.reset(); for (int i = 0; i < 3; i++) { table.getNextRow(); } table.deleteCurrentRow(); - assertEquals(7, countRows(table)); + assertRowCount(7, table); table.reset(); assertEquals(2, table.getNextRow().get("D")); } @@ -607,7 +609,7 @@ public class DatabaseTest extends TestCase { new ArrayList<Object>(row.values())); table.reset(); - assertEquals(7, countRows(table)); + assertRowCount(7, table); } @@ -809,7 +811,14 @@ public class DatabaseTest extends TestCase { String str = builder.toString(); return str; } - + + static void assertRowCount(int expectedRowCount, Table table) + throws Exception + { + assertEquals(expectedRowCount, countRows(table)); + assertEquals(expectedRowCount, table.getRowCount()); + } + static int countRows(Table table) throws Exception { int rtn = 0; for(Map<String, Object> row : table) { diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index d8307a9..bbc0ab5 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -122,5 +122,45 @@ public class IndexTest extends TestCase { } } + public void testEntryDeletion() throws Exception { + File srcFile = new File("test/data/test.mdb"); + File dbFile = File.createTempFile("databaseTest", ".mdb"); + dbFile.deleteOnExit(); + copyFile(srcFile, dbFile); + + Table table = Database.open(dbFile).getTable("Table1"); + + for(int i = 0; i < 10; ++i) { + table.addRow("foo" + i, "bar" + i, (byte)42 + i, (short)53 + i, 13 * i, + (6.7d / i), null, null, true); + } + table.reset(); + assertRowCount(12, table); + + for(Index index : table.getIndexes()) { + assertEquals(12, index.getEntryCount()); + } + + table.reset(); + table.getNextRow(); + table.getNextRow(); + table.deleteCurrentRow(); + table.getNextRow(); + table.deleteCurrentRow(); + table.getNextRow(); + table.getNextRow(); + table.deleteCurrentRow(); + table.getNextRow(); + table.getNextRow(); + table.getNextRow(); + table.deleteCurrentRow(); + + table.reset(); + assertRowCount(8, table); + + for(Index index : table.getIndexes()) { + assertEquals(8, index.getEntryCount()); + } + } } |