diff --git a/src/tests/test_dup_next.c b/src/tests/test_dup_next.c index 8825f6f0e7056fb6fe8e120b51f6afd5269bf131..dc5fe581d4abd827e7c367dad801e2fe8d33d7f8 100644 --- a/src/tests/test_dup_next.c +++ b/src/tests/test_dup_next.c @@ -6,6 +6,7 @@ #include <assert.h> #include <unistd.h> #include <string.h> +#include <errno.h> #include <sys/stat.h> #include <arpa/inet.h> #include <db.h> @@ -78,19 +79,21 @@ void expect_cursor_set(DBC *cursor, int k, int expectv) { assert(expectv == vv); } -void expect_cursor_get(DBC *cursor, int expectk, int expectv, int op) { +int expect_cursor_get(DBC *cursor, int expectk, int expectv, int op) { DBT key, val; int r = cursor->c_get(cursor, dbt_init_zero(&key), dbt_init_zero(&val), op); - assert(r == 0); - assert(key.size == sizeof expectk); - int kk; - memcpy(&kk, key.data, key.size); - assert(val.size == sizeof expectv); - int vv; - memcpy(&vv, val.data, val.size); - if (kk != expectk || vv != expectv) printf("expect key %d got %d - %d %d\n", htonl(expectk), htonl(kk), htonl(expectv), htonl(vv)); - assert(kk == expectk); - assert(vv == expectv); + if (r == 0) { + assert(key.size == sizeof expectk); + int kk; + memcpy(&kk, key.data, key.size); + assert(val.size == sizeof expectv); + int vv; + memcpy(&vv, val.data, val.size); + if (kk != expectk || vv != expectv) printf("expect key %d got %d - %d %d\n", htonl(expectk), htonl(kk), htonl(expectv), htonl(vv)); + assert(kk == expectk); + assert(vv == expectv); + } + return r; } void test_dup_next(int n, int dup_mode) { @@ -124,12 +127,16 @@ void test_dup_next(int n, int dup_mode) { DBC *cursor; r = db->cursor(db, null_txn, &cursor, 0); assert(r == 0); + r = expect_cursor_get(cursor, htonl(1), htonl(0), DB_NEXT_DUP); assert(r == EINVAL); + expect_cursor_set(cursor, htonl(1), htonl(0)); for (i=1; i<n; i++) { - expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); + r = expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); assert(r == 0); } + r = expect_cursor_get(cursor, htonl(1), htonl(i), DB_NEXT_DUP); assert(r == DB_NOTFOUND); + r = cursor->c_close(cursor); assert(r == 0); r = db->close(db, 0); assert(r == 0);