2013-04-16 23:57:29 -04:00
|
|
|
#include "toku_portability.h"
|
2013-04-16 23:57:22 -04:00
|
|
|
#include <errno.h>
|
2013-04-16 23:57:32 -04:00
|
|
|
|
|
|
|
#include "test.h"
|
2013-04-16 23:57:22 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
typedef void *OMTVALUE;
|
|
|
|
#include "omt.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "toku_assert.h"
|
|
|
|
#include "brttypes.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-06-02 20:52:12 +00:00
|
|
|
|
|
|
|
enum { N=10 };
|
|
|
|
struct value { int x; } vs[N];
|
|
|
|
OMTVALUE ps[N];
|
|
|
|
|
2013-04-16 23:57:20 -04:00
|
|
|
#define V(x) ((struct value *)(x))
|
|
|
|
|
2008-06-02 20:52:12 +00:00
|
|
|
static void test (void) {
|
|
|
|
OMT o;
|
|
|
|
OMTCURSOR curs, curs2, curs3;
|
|
|
|
int i, r;
|
|
|
|
OMTVALUE v;
|
|
|
|
for (i=0; i<N; i++) {
|
|
|
|
vs[i].x=i;
|
|
|
|
ps[i]=&vs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// destroy the omt first
|
|
|
|
r = toku_omt_create_from_sorted_array(&o, ps, 10); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 5, &v, curs); assert(r==0);
|
|
|
|
toku_omt_destroy(&o);
|
|
|
|
toku_omt_cursor_destroy(&curs);
|
|
|
|
|
|
|
|
// destroy the cursor first
|
|
|
|
r = toku_omt_create_from_sorted_array(&o, ps, 10); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 5, &v, curs); assert(r==0);
|
2013-04-16 23:57:20 -04:00
|
|
|
assert(V(v)->x==5);
|
2008-06-02 20:52:12 +00:00
|
|
|
r = toku_omt_cursor_next(curs, &v);
|
2013-04-16 23:57:20 -04:00
|
|
|
assert(r==0 && V(v)->x==6);
|
2008-06-02 20:52:12 +00:00
|
|
|
r = toku_omt_cursor_prev(curs, &v);
|
2013-04-16 23:57:20 -04:00
|
|
|
assert(r==0 && V(v)->x==5);
|
2008-06-02 20:52:12 +00:00
|
|
|
toku_omt_cursor_destroy(&curs);
|
|
|
|
toku_omt_destroy(&o);
|
|
|
|
|
|
|
|
// Create two cursors, destroy omt first
|
|
|
|
r = toku_omt_create_from_sorted_array(&o, ps, 10); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 5, &v, curs); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs2); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 4, &v, curs2); assert(r==0);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_next(curs, &v); assert(r==0 && V(v)->x==6);
|
2008-06-02 20:52:12 +00:00
|
|
|
toku_omt_destroy(&o);
|
|
|
|
toku_omt_cursor_destroy(&curs);
|
|
|
|
toku_omt_cursor_destroy(&curs2);
|
|
|
|
|
|
|
|
// Create two cursors, destroy them first
|
|
|
|
r = toku_omt_create_from_sorted_array(&o, ps, 10); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 5, &v, curs); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs2); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 4, &v, curs2); assert(r==0);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_next(curs, &v); assert(r==0 && V(v)->x==6);
|
|
|
|
r = toku_omt_cursor_prev(curs2, &v); assert(r==0 && V(v)->x==3);
|
2008-06-02 20:52:12 +00:00
|
|
|
toku_omt_cursor_destroy(&curs);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_prev(curs2, &v); assert(r==0 && V(v)->x==2);
|
2008-06-02 20:52:12 +00:00
|
|
|
toku_omt_cursor_destroy(&curs2);
|
|
|
|
toku_omt_destroy(&o);
|
|
|
|
|
|
|
|
// Create three cursors, destroy them first
|
|
|
|
r = toku_omt_create_from_sorted_array(&o, ps, 10); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 5, &v, curs); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs2); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 4, &v, curs2); assert(r==0);
|
|
|
|
r = toku_omt_cursor_create(&curs3); assert(r==0);
|
|
|
|
r = toku_omt_fetch(o, 9, &v, curs3); assert(r==0);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_next(curs, &v); assert(r==0 && V(v)->x==6);
|
|
|
|
r = toku_omt_cursor_prev(curs2, &v); assert(r==0 && V(v)->x==3);
|
2008-06-02 20:52:12 +00:00
|
|
|
r = toku_omt_cursor_next(curs3, &v); assert(r!=0 && !toku_omt_cursor_is_valid(curs3));
|
|
|
|
toku_omt_cursor_destroy(&curs);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_prev(curs2, &v); assert(r==0 && V(v)->x==2);
|
|
|
|
r = toku_omt_cursor_prev(curs2, &v); assert(r==0 && V(v)->x==1);
|
2008-06-02 20:52:12 +00:00
|
|
|
r = toku_omt_fetch(o, 1, &v, curs3); assert(r==0);
|
2013-04-16 23:57:20 -04:00
|
|
|
r = toku_omt_cursor_prev(curs3, &v); assert(r==0 && V(v)->x==0);
|
2008-06-02 20:52:12 +00:00
|
|
|
r = toku_omt_cursor_prev(curs3, &v); assert(r!=0 && !toku_omt_cursor_is_valid(curs3));
|
|
|
|
toku_omt_cursor_destroy(&curs2);
|
|
|
|
toku_omt_destroy(&o);
|
|
|
|
toku_omt_cursor_destroy(&curs3);
|
|
|
|
}
|
|
|
|
|
2013-04-16 23:57:32 -04:00
|
|
|
int
|
|
|
|
test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
|
2008-06-02 20:52:12 +00:00
|
|
|
test();
|
|
|
|
return 0;
|
|
|
|
}
|