summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2010-11-12 04:05:30 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2010-11-12 04:05:30 +0000
commitdaa13d12fe6e38a4ab4f42340469f42a054ba4b1 (patch)
tree8d7f4b972b52dbd302ac3cf20f8605167ee42566 /test
parentab5fead7ce3b2aed414e72e141d6a1b8fdd9e75d (diff)
downloadjackcess-daa13d12fe6e38a4ab4f42340469f42a054ba4b1.tar.gz
jackcess-daa13d12fe6e38a4ab4f42340469f42a054ba4b1.zip
add ability to customize column value matching in cursor findRow (fixes #3105829)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@498 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/CursorTest.java103
1 files changed, 102 insertions, 1 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
index 4fda31a..c8e5d7e 100644
--- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
@@ -71,7 +71,9 @@ public class CursorTest extends TestCase {
return expectedRows;
}
- private static Database createTestTable(final FileFormat fileFormat) throws Exception {
+ private static Database createTestTable(final FileFormat fileFormat)
+ throws Exception
+ {
Database db = create(fileFormat);
Table table = new TableBuilder("test")
@@ -720,4 +722,103 @@ public class CursorTest extends TestCase {
}
}
+ public void testColmnMatcher() throws Exception {
+
+
+ for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
+ Database db = createTestTable(fileFormat);
+
+ Table table = db.getTable("test");
+
+ doTestMatchers(table, SimpleColumnMatcher.INSTANCE, false);
+ doTestMatchers(table, CaseInsensitiveColumnMatcher.INSTANCE, true);
+
+ Cursor cursor = Cursor.createCursor(table);
+ doTestMatcher(table, cursor, SimpleColumnMatcher.INSTANCE, false);
+ doTestMatcher(table, cursor, CaseInsensitiveColumnMatcher.INSTANCE,
+ true);
+ db.close();
+ }
+ }
+
+ private void doTestMatchers(Table table, ColumnMatcher columnMatcher,
+ boolean caseInsensitive)
+ throws Exception
+ {
+ assertTrue(columnMatcher.matches(table, "value", null, null));
+ assertFalse(columnMatcher.matches(table, "value", "foo", null));
+ assertFalse(columnMatcher.matches(table, "value", null, "foo"));
+ assertTrue(columnMatcher.matches(table, "value", "foo", "foo"));
+ assertTrue(columnMatcher.matches(table, "value", "foo", "Foo")
+ == caseInsensitive);
+
+ assertFalse(columnMatcher.matches(table, "value", 13, null));
+ assertFalse(columnMatcher.matches(table, "value", null, 13));
+ assertTrue(columnMatcher.matches(table, "value", 13, 13));
+ }
+
+ private void doTestMatcher(Table table, Cursor cursor,
+ ColumnMatcher columnMatcher,
+ boolean caseInsensitive)
+ throws Exception
+ {
+ cursor.setColumnMatcher(columnMatcher);
+
+ assertTrue(cursor.findRow(table.getColumn("id"), 3));
+ assertEquals(createExpectedRow("id", 3,
+ "value", "data" + 3),
+ cursor.getCurrentRow());
+
+ assertTrue(cursor.findRow(createExpectedRow(
+ "id", 6,
+ "value", "data" + 6)));
+ assertEquals(createExpectedRow("id", 6,
+ "value", "data" + 6),
+ cursor.getCurrentRow());
+
+ assertTrue(cursor.findRow(createExpectedRow(
+ "id", 6,
+ "value", "Data" + 6)) == caseInsensitive);
+ if(caseInsensitive) {
+ assertEquals(createExpectedRow("id", 6,
+ "value", "data" + 6),
+ cursor.getCurrentRow());
+ }
+
+ assertFalse(cursor.findRow(createExpectedRow(
+ "id", 8,
+ "value", "data" + 13)));
+ assertFalse(cursor.findRow(table.getColumn("id"), 13));
+ assertEquals(createExpectedRow("id", 6,
+ "value", "data" + 6),
+ cursor.getCurrentRow());
+
+ assertTrue(cursor.findRow(createExpectedRow(
+ "value", "data" + 7)));
+ assertEquals(createExpectedRow("id", 7,
+ "value", "data" + 7),
+ cursor.getCurrentRow());
+
+ assertTrue(cursor.findRow(createExpectedRow(
+ "value", "Data" + 7)) == caseInsensitive);
+ if(caseInsensitive) {
+ assertEquals(createExpectedRow("id", 7,
+ "value", "data" + 7),
+ cursor.getCurrentRow());
+ }
+
+ assertTrue(cursor.findRow(table.getColumn("value"), "data" + 4));
+ assertEquals(createExpectedRow("id", 4,
+ "value", "data" + 4),
+ cursor.getCurrentRow());
+
+ assertTrue(cursor.findRow(table.getColumn("value"), "Data" + 4)
+ == caseInsensitive);
+ if(caseInsensitive) {
+ assertEquals(createExpectedRow("id", 4,
+ "value", "data" + 4),
+ cursor.getCurrentRow());
+ }
+ }
+
}