From: James Ahlborn Date: Wed, 19 Mar 2008 01:59:48 +0000 (+0000) Subject: add test for uniqueEntryCount updates X-Git-Tag: rel_1_1_13~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9bd45a7a63925b4bbd3f2dd8962ecdf1a713ad5;p=jackcess.git add test for uniqueEntryCount updates git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@286 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index 4b21af3..cce6c62 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -307,7 +307,60 @@ public class IndexTest extends TestCase { } } } - + + public void testUniqueEntryCount() throws Exception { + Database db = openCopy(new File("test/data/test.mdb")); + Table table = db.getTable("Table1"); + Index indA = table.getIndex("PrimaryKey"); + Index indB = table.getIndex("B"); + + assertEquals(2, indA.getUniqueEntryCount()); + assertEquals(2, indB.getUniqueEntryCount()); + + List bElems = Arrays.asList("bar", null, "baz", "argle", null, + "bazzle", "37", "bar", "bar", "BAZ"); + + for(int i = 0; i < 10; ++i) { + table.addRow("foo" + i, bElems.get(i), (byte)42 + i, (short)53 + i, + 13 * i, (6.7d / i), null, null, true); + } + + assertEquals(12, indA.getEntryCount()); + assertEquals(12, indB.getEntryCount()); + + assertEquals(12, indA.getUniqueEntryCount()); + assertEquals(8, indB.getUniqueEntryCount()); + + table = null; + indA = null; + indB = null; + + table = db.getTable("Table1"); + indA = table.getIndex("PrimaryKey"); + indB = table.getIndex("B"); + + assertEquals(12, indA.getEntryCount()); + assertEquals(12, indB.getEntryCount()); + + assertEquals(12, indA.getUniqueEntryCount()); + assertEquals(8, indB.getUniqueEntryCount()); + + Cursor c = Cursor.createCursor(table); + assertTrue(c.moveToNextRow()); + Map row = c.getCurrentRow(); + assertEquals("abcdefg", row.get("A")); + assertEquals("hijklmnop", row.get("B")); + c.deleteCurrentRow(); + + assertEquals(11, indA.getEntryCount()); + assertEquals(11, indB.getEntryCount()); + + assertEquals(12, indA.getUniqueEntryCount()); + assertEquals(8, indB.getUniqueEntryCount()); + + db.close(); + } + private void checkIndexColumns(Table table, String... idxInfo) throws Exception {