]> source.dussan.org Git - jackcess.git/commitdiff
add unit test for iteration early exit fix
authorJames Ahlborn <jtahlborn@yahoo.com>
Mon, 22 Sep 2014 02:52:37 +0000 (02:52 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Mon, 22 Sep 2014 02:52:37 +0000 (02:52 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@882 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java
src/test/java/com/healthmarketscience/jackcess/CursorTest.java

index 0fbe7c2f068031c77ff820736001d223c25b50ff..5e3fe88049d5ec3c8905ca2b55cde3a47cf1ae09 100644 (file)
@@ -223,9 +223,6 @@ public class ColumnImpl implements Column, Comparable<ColumnImpl> {
     
   /**
    * 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<ColumnImpl> {
    * 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<ColumnImpl> {
   /**
    * 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
index d8beff37c42b24ceb0bb62bec513d756a49bf38a..caf048ae7c1a00e092fcd78240ce4fd59cce63ba 100644 (file)
@@ -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();
+    }
+  }
+
 }