diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2014-09-22 02:52:37 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2014-09-22 02:52:37 +0000 |
commit | 8249b36e989a4151061741d4be70d957ef5ed864 (patch) | |
tree | c02c76e9aae9bf181c0a82a0d831f2e7d15c2ce4 /src/test | |
parent | 94148f092f4b65b3abde48a38f80076c6d4f9f78 (diff) | |
download | jackcess-8249b36e989a4151061741d4be70d957ef5ed864.tar.gz jackcess-8249b36e989a4151061741d4be70d957ef5ed864.zip |
add unit test for iteration early exit fix
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@882 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/healthmarketscience/jackcess/CursorTest.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java index d8beff3..caf048a 100644 --- a/src/test/java/com/healthmarketscience/jackcess/CursorTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/CursorTest.java @@ -38,6 +38,7 @@ import java.util.TreeSet; import static com.healthmarketscience.jackcess.Database.*; import static com.healthmarketscience.jackcess.DatabaseTest.*; +import com.healthmarketscience.jackcess.impl.ColumnImpl; import com.healthmarketscience.jackcess.impl.JetFormatTest; import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; import com.healthmarketscience.jackcess.impl.RowIdImpl; @@ -1285,5 +1286,62 @@ public class CursorTest extends TestCase { assertEquals(id - 1, cursor.getCurrentRow().get("id")); } + public void testIterationEarlyExit() throws Exception { + for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { + + Database db = create(fileFormat); + + Table table = new TableBuilder("test") + .addColumn(new ColumnBuilder("id", DataType.LONG)) + .addColumn(new ColumnBuilder("value", DataType.TEXT)) + .addColumn(new ColumnBuilder("memo", DataType.MEMO)) + .addIndex(new IndexBuilder("value_idx") + .addColumns("value")) + .toTable(db); + + for(int i = 0; i < 20; ++i) { + Object memo = "memo-" + i; + table.addRow(i, "val-" + (i/2), memo); + } + + // generate an "invalid" memo + byte[] b = new byte[12]; + b[3] = (byte)0xC0; + table.addRow(20, "val-9", ColumnImpl.rawDataWrapper(b)); + + IndexCursor cursor = CursorBuilder.createCursor( + table.getIndex("value_idx")); + + try { + cursor.newIterable() + .addMatchPattern("value", "val-9") + .addMatchPattern("memo", "anything") + .iterator().hasNext(); + fail("RuntimeIOException should have been thrown"); + } catch(RuntimeIOException ignored) { + // success + } + + List<Row> rows = new ArrayList<Row>(); + for (Row row : cursor.newIterable() + .addMatchPattern("value", "val-5") + .addMatchPattern("memo", "memo-11")) { + rows.add(row); + } + + assertEquals(rows, createExpectedTable( + createExpectedRow("id", 11, + "value", "val-5", + "memo", "memo-11"))); + + assertFalse(cursor.newIterable() + .addMatchPattern("value", "val-31") + .addMatchPattern("memo", "anything") + .iterator().hasNext()); + + db.close(); + } + } + } |