From 8249b36e989a4151061741d4be70d957ef5ed864 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 22 Sep 2014 02:52:37 +0000 Subject: [PATCH] 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 --- .../jackcess/impl/ColumnImpl.java | 8 +-- .../jackcess/CursorTest.java | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java index 0fbe7c2..5e3fe88 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java @@ -223,9 +223,6 @@ public class ColumnImpl implements Column, Comparable { /** * Read a column definition in from a buffer - * @param table owning table - * @param buffer Buffer containing column definition - * @param offset Offset in the buffer at which the column definition starts * @usage _advanced_method_ */ ColumnImpl(InitArgs args) @@ -1538,12 +1535,12 @@ public class ColumnImpl implements Column, Comparable { * understanding the data. Useful for wrapping unparseable data for * re-writing. */ - static RawData rawDataWrapper(byte[] bytes) { + public static RawData rawDataWrapper(byte[] bytes) { return new RawData(bytes); } /** - * Returs {@code true} if the given value is "raw" column data, + * Returns {@code true} if the given value is "raw" column data, * {@code false} otherwise. * @usage _advanced_method_ */ @@ -1554,7 +1551,6 @@ public class ColumnImpl implements Column, Comparable { /** * Writes the column definitions into a table definition buffer. * @param buffer Buffer to write to - * @param columns List of Columns to write definitions for */ protected static void writeDefinitions(TableCreator creator, ByteBuffer buffer) throws IOException 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 rows = new ArrayList(); + 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(); + } + } + } -- 2.39.5