sophia-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +22 -0
- data/ext/extconf.rb +13 -0
- data/ext/sophia.c +220 -0
- data/lib/sophia-ruby.rb +1 -0
- data/lib/sophia/version.rb +3 -0
- data/sophia-ruby.gemspec +47 -0
- data/test/test_sophia.rb +33 -0
- data/vendor/sophia/.gitignore +18 -0
- data/vendor/sophia/COPYRIGHT +29 -0
- data/vendor/sophia/README +5 -0
- data/vendor/sophia/db/a.h +58 -0
- data/vendor/sophia/db/cat.c +195 -0
- data/vendor/sophia/db/cat.h +32 -0
- data/vendor/sophia/db/core.h +129 -0
- data/vendor/sophia/db/crc.c +343 -0
- data/vendor/sophia/db/crc.h +14 -0
- data/vendor/sophia/db/cursor.c +551 -0
- data/vendor/sophia/db/cursor.h +47 -0
- data/vendor/sophia/db/e.c +49 -0
- data/vendor/sophia/db/e.h +49 -0
- data/vendor/sophia/db/file.c +355 -0
- data/vendor/sophia/db/file.h +106 -0
- data/vendor/sophia/db/gc.c +71 -0
- data/vendor/sophia/db/gc.h +14 -0
- data/vendor/sophia/db/i.c +368 -0
- data/vendor/sophia/db/i.h +155 -0
- data/vendor/sophia/db/list.h +91 -0
- data/vendor/sophia/db/lock.h +77 -0
- data/vendor/sophia/db/macro.h +20 -0
- data/vendor/sophia/db/makefile +44 -0
- data/vendor/sophia/db/merge.c +662 -0
- data/vendor/sophia/db/merge.h +14 -0
- data/vendor/sophia/db/meta.h +87 -0
- data/vendor/sophia/db/recover.c +433 -0
- data/vendor/sophia/db/recover.h +14 -0
- data/vendor/sophia/db/ref.h +111 -0
- data/vendor/sophia/db/rep.c +128 -0
- data/vendor/sophia/db/rep.h +120 -0
- data/vendor/sophia/db/sophia.h +84 -0
- data/vendor/sophia/db/sp.c +626 -0
- data/vendor/sophia/db/sp.h +50 -0
- data/vendor/sophia/db/task.h +70 -0
- data/vendor/sophia/db/track.h +99 -0
- data/vendor/sophia/db/util.c +105 -0
- data/vendor/sophia/db/util.h +25 -0
- data/vendor/sophia/makefile +7 -0
- data/vendor/sophia/sophia.gyp +30 -0
- data/vendor/sophia/test/common.c +870 -0
- data/vendor/sophia/test/crash.c +492 -0
- data/vendor/sophia/test/i.c +403 -0
- data/vendor/sophia/test/limit.c +65 -0
- data/vendor/sophia/test/makefile +30 -0
- data/vendor/sophia/test/merge.c +890 -0
- data/vendor/sophia/test/recover.c +1550 -0
- data/vendor/sophia/test/test.h +66 -0
- metadata +134 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
#ifndef SP_H_
|
2
|
+
#define SP_H_
|
3
|
+
|
4
|
+
/*
|
5
|
+
* sophia database
|
6
|
+
* sphia.org
|
7
|
+
*
|
8
|
+
* Copyright (c) Dmitry Simonenko
|
9
|
+
* BSD License
|
10
|
+
*/
|
11
|
+
|
12
|
+
#define _GNU_SOURCE 1
|
13
|
+
|
14
|
+
#include <stdlib.h>
|
15
|
+
#include <stdarg.h>
|
16
|
+
#include <stdio.h>
|
17
|
+
#include <stdint.h>
|
18
|
+
#include <inttypes.h>
|
19
|
+
#include <limits.h>
|
20
|
+
#include <string.h>
|
21
|
+
#include <assert.h>
|
22
|
+
#include <pthread.h>
|
23
|
+
#include <sys/types.h>
|
24
|
+
#include <sys/stat.h>
|
25
|
+
#include <sys/uio.h>
|
26
|
+
#include <errno.h>
|
27
|
+
|
28
|
+
#include <sophia.h>
|
29
|
+
|
30
|
+
#include <macro.h>
|
31
|
+
#include <crc.h>
|
32
|
+
#include <lock.h>
|
33
|
+
#include <list.h>
|
34
|
+
#include <e.h>
|
35
|
+
#include <a.h>
|
36
|
+
#include <meta.h>
|
37
|
+
#include <file.h>
|
38
|
+
#include <ref.h>
|
39
|
+
#include <i.h>
|
40
|
+
#include <rep.h>
|
41
|
+
#include <cat.h>
|
42
|
+
#include <task.h>
|
43
|
+
#include <core.h>
|
44
|
+
#include <util.h>
|
45
|
+
#include <recover.h>
|
46
|
+
#include <merge.h>
|
47
|
+
#include <gc.h>
|
48
|
+
#include <cursor.h>
|
49
|
+
|
50
|
+
#endif
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#ifndef SP_TASK_H_
|
2
|
+
#define SP_TASK_H_
|
3
|
+
|
4
|
+
/*
|
5
|
+
* sophia database
|
6
|
+
* sphia.org
|
7
|
+
*
|
8
|
+
* Copyright (c) Dmitry Simonenko
|
9
|
+
* BSD License
|
10
|
+
*/
|
11
|
+
|
12
|
+
typedef struct sptask sptask;
|
13
|
+
|
14
|
+
struct sptask {
|
15
|
+
volatile int run;
|
16
|
+
void *arg;
|
17
|
+
pthread_t id;
|
18
|
+
pthread_mutex_t l;
|
19
|
+
pthread_cond_t c;
|
20
|
+
};
|
21
|
+
|
22
|
+
static inline int
|
23
|
+
sp_taskstart(sptask *t, void*(*f)(void*), void *arg) {
|
24
|
+
t->run = 1;
|
25
|
+
t->arg = arg;
|
26
|
+
pthread_mutex_init(&t->l, NULL);
|
27
|
+
pthread_cond_init(&t->c, NULL);
|
28
|
+
return pthread_create(&t->id, NULL, f, t);
|
29
|
+
}
|
30
|
+
|
31
|
+
static inline int
|
32
|
+
sp_taskstop(sptask *t) {
|
33
|
+
pthread_mutex_lock(&t->l);
|
34
|
+
if (t->run == 0) {
|
35
|
+
pthread_mutex_unlock(&t->l);
|
36
|
+
return 0;
|
37
|
+
}
|
38
|
+
t->run = 0;
|
39
|
+
pthread_cond_signal(&t->c);
|
40
|
+
pthread_mutex_unlock(&t->l);
|
41
|
+
return pthread_join(t->id, NULL);
|
42
|
+
}
|
43
|
+
|
44
|
+
static inline void
|
45
|
+
sp_taskwakeup(sptask *t) {
|
46
|
+
pthread_mutex_lock(&t->l);
|
47
|
+
pthread_cond_signal(&t->c);
|
48
|
+
pthread_mutex_unlock(&t->l);
|
49
|
+
}
|
50
|
+
|
51
|
+
static inline int
|
52
|
+
sp_taskwait(sptask *t) {
|
53
|
+
pthread_mutex_lock(&t->l);
|
54
|
+
if (t->run == 0) {
|
55
|
+
pthread_mutex_unlock(&t->l);
|
56
|
+
return 0;
|
57
|
+
}
|
58
|
+
pthread_cond_wait(&t->c, &t->l);
|
59
|
+
pthread_mutex_unlock(&t->l);
|
60
|
+
return t->run;
|
61
|
+
}
|
62
|
+
|
63
|
+
static inline void
|
64
|
+
sp_taskdone(sptask *t) {
|
65
|
+
pthread_mutex_lock(&t->l);
|
66
|
+
t->run = 0;
|
67
|
+
pthread_mutex_unlock(&t->l);
|
68
|
+
}
|
69
|
+
|
70
|
+
#endif
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#ifndef SP_TRACK_H_
|
2
|
+
#define SP_TRACK_H_
|
3
|
+
|
4
|
+
/*
|
5
|
+
* sophia database
|
6
|
+
* sphia.org
|
7
|
+
*
|
8
|
+
* Copyright (c) Dmitry Simonenko
|
9
|
+
* BSD License
|
10
|
+
*/
|
11
|
+
|
12
|
+
typedef struct sptrack sptrack;
|
13
|
+
|
14
|
+
struct sptrack {
|
15
|
+
spa *a;
|
16
|
+
uint64_t max;
|
17
|
+
uint64_t *i;
|
18
|
+
int count;
|
19
|
+
int size;
|
20
|
+
};
|
21
|
+
|
22
|
+
static inline int
|
23
|
+
sp_trackinit(sptrack *t, spa *a, int size) {
|
24
|
+
t->a = a;
|
25
|
+
t->max = 0;
|
26
|
+
t->count = 0;
|
27
|
+
t->size = size;
|
28
|
+
int sz = size * sizeof(uint64_t);
|
29
|
+
t->i = sp_malloc(a, sz);
|
30
|
+
if (spunlikely(t->i == NULL))
|
31
|
+
return -1;
|
32
|
+
memset(t->i, 0, sz);
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
static inline void sp_trackfree(sptrack *t) {
|
37
|
+
if (spunlikely(t->i == NULL))
|
38
|
+
return;
|
39
|
+
sp_free(t->a, t->i);
|
40
|
+
t->i = NULL;
|
41
|
+
}
|
42
|
+
|
43
|
+
static inline void
|
44
|
+
sp_trackinsert(sptrack *t, uint64_t id) {
|
45
|
+
uint32_t pos = id % t->size;
|
46
|
+
for (;;) {
|
47
|
+
if (spunlikely(t->i[pos] != 0)) {
|
48
|
+
pos = (pos + 1) % t->size;
|
49
|
+
continue;
|
50
|
+
}
|
51
|
+
if (id > t->max)
|
52
|
+
t->max = id;
|
53
|
+
t->i[pos] = id;
|
54
|
+
break;
|
55
|
+
}
|
56
|
+
t->count++;
|
57
|
+
}
|
58
|
+
|
59
|
+
static inline int
|
60
|
+
sp_trackresize(sptrack *t) {
|
61
|
+
sptrack nt;
|
62
|
+
int rc = sp_trackinit(&nt, t->a, t->size * 2);
|
63
|
+
if (spunlikely(rc == -1))
|
64
|
+
return -1;
|
65
|
+
int i = 0;
|
66
|
+
while (i < t->size) {
|
67
|
+
if (t->i[i])
|
68
|
+
sp_trackinsert(&nt, t->i[i]);
|
69
|
+
i++;
|
70
|
+
}
|
71
|
+
sp_trackfree(t);
|
72
|
+
*t = nt;
|
73
|
+
return 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
static inline int
|
77
|
+
sp_trackset(sptrack *t, uint64_t id) {
|
78
|
+
if (spunlikely(t->count > (t->size / 2)))
|
79
|
+
if (spunlikely(sp_trackresize(t) == -1))
|
80
|
+
return -1;
|
81
|
+
sp_trackinsert(t, id);
|
82
|
+
return 0;
|
83
|
+
}
|
84
|
+
|
85
|
+
static inline int
|
86
|
+
sp_trackhas(sptrack *t, uint64_t id) {
|
87
|
+
uint32_t pos = id % t->size;
|
88
|
+
for (;;) {
|
89
|
+
if (spunlikely(t->i[pos] == 0))
|
90
|
+
return 0;
|
91
|
+
if (t->i[pos] == id)
|
92
|
+
return 1;
|
93
|
+
pos = (pos + 1) % t->size;
|
94
|
+
continue;
|
95
|
+
}
|
96
|
+
return 0;
|
97
|
+
}
|
98
|
+
|
99
|
+
#endif
|
@@ -0,0 +1,105 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* sophia database
|
4
|
+
* sphia.org
|
5
|
+
*
|
6
|
+
* Copyright (c) Dmitry Simonenko
|
7
|
+
* BSD License
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <sp.h>
|
11
|
+
|
12
|
+
char *sp_memdup(sp *s, void *src, size_t size)
|
13
|
+
{
|
14
|
+
char *v = sp_malloc(&s->a, size);
|
15
|
+
if (spunlikely(v == NULL))
|
16
|
+
return NULL;
|
17
|
+
memcpy(v, src, size);
|
18
|
+
return v;
|
19
|
+
}
|
20
|
+
|
21
|
+
sppage *sp_pagenew(sp *s, spepoch *e) {
|
22
|
+
sppage *page = sp_malloc(&s->a, sizeof(sppage));
|
23
|
+
if (spunlikely(page == NULL))
|
24
|
+
return NULL;
|
25
|
+
memset(page, 0, sizeof(sppage));
|
26
|
+
page->epoch = e;
|
27
|
+
sp_listinit(&page->link);
|
28
|
+
return page;
|
29
|
+
}
|
30
|
+
|
31
|
+
void sp_pageattach(sppage *p) {
|
32
|
+
assert(p->epoch != NULL);
|
33
|
+
sp_listappend(&((spepoch*)p->epoch)->pages, &p->link);
|
34
|
+
}
|
35
|
+
|
36
|
+
void sp_pagedetach(sppage *p) {
|
37
|
+
assert(p->epoch != NULL);
|
38
|
+
sp_listunlink(&p->link);
|
39
|
+
}
|
40
|
+
|
41
|
+
void sp_pagefree(sp *s, sppage *p) {
|
42
|
+
sp_listunlink(&p->link);
|
43
|
+
sp_free(&s->a, p->min);
|
44
|
+
sp_free(&s->a, p->max);
|
45
|
+
sp_free(&s->a, p);
|
46
|
+
}
|
47
|
+
|
48
|
+
static inline spv*
|
49
|
+
sp_vnewof(sp *s, void *k, uint16_t size, int reserve) {
|
50
|
+
spv *v = sp_malloc(&s->a, sizeof(spv) + size + reserve);
|
51
|
+
if (spunlikely(v == NULL))
|
52
|
+
return NULL;
|
53
|
+
v->epoch = 0;
|
54
|
+
v->size = size;
|
55
|
+
v->flags = 0;
|
56
|
+
memcpy(v->key, k, size);
|
57
|
+
return v;
|
58
|
+
}
|
59
|
+
|
60
|
+
spv *sp_vnew(sp *s, void *k, uint16_t size) {
|
61
|
+
return sp_vnewof(s, k, size, 0);
|
62
|
+
}
|
63
|
+
|
64
|
+
spv *sp_vnewv(sp *s, void *k, uint16_t size, void *v, uint32_t vsize)
|
65
|
+
{
|
66
|
+
spv *vn = sp_vnewof(s, k, size, sizeof(uint32_t) + vsize);
|
67
|
+
if (spunlikely(vn == NULL))
|
68
|
+
return NULL;
|
69
|
+
memcpy(vn->key + vn->size, &vsize, sizeof(uint32_t));
|
70
|
+
memcpy(vn->key + vn->size + sizeof(uint32_t), v, vsize);
|
71
|
+
return vn;
|
72
|
+
}
|
73
|
+
|
74
|
+
spv *sp_vnewh(sp *s, spvh *v) {
|
75
|
+
spv *vn = sp_vnewof(s, v->key, v->size, 0);
|
76
|
+
if (spunlikely(vn == NULL))
|
77
|
+
return NULL;
|
78
|
+
vn->flags = v->flags;
|
79
|
+
return vn;
|
80
|
+
}
|
81
|
+
|
82
|
+
spv *sp_vdup(sp *s, spv *v)
|
83
|
+
{
|
84
|
+
spv *vn = sp_malloc(&s->a, sizeof(spv) + v->size);
|
85
|
+
if (spunlikely(vn == NULL))
|
86
|
+
return NULL;
|
87
|
+
memcpy(vn, v, sizeof(spv) + v->size);
|
88
|
+
return vn;
|
89
|
+
}
|
90
|
+
|
91
|
+
spv *sp_vdupref(sp *s, spref *r, uint32_t epoch)
|
92
|
+
{
|
93
|
+
spv *vn = NULL;
|
94
|
+
switch (r->type) {
|
95
|
+
case SPREFM: vn = sp_vdup(s, r->v.v);
|
96
|
+
break;
|
97
|
+
case SPREFD: vn = sp_vnewh(s, r->v.vh);
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
if (spunlikely(vn == NULL))
|
101
|
+
return NULL;
|
102
|
+
vn->epoch = epoch;
|
103
|
+
vn->flags = 0;
|
104
|
+
return vn;
|
105
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#ifndef SP_UTIL_H_
|
2
|
+
#define SP_UTIL_H_
|
3
|
+
|
4
|
+
/*
|
5
|
+
* sophia database
|
6
|
+
* sphia.org
|
7
|
+
*
|
8
|
+
* Copyright (c) Dmitry Simonenko
|
9
|
+
* BSD License
|
10
|
+
*/
|
11
|
+
|
12
|
+
char *sp_memdup(sp*, void*, size_t);
|
13
|
+
|
14
|
+
spv *sp_vnew(sp*, void*, uint16_t);
|
15
|
+
spv *sp_vnewv(sp*, void*, uint16_t, void*, uint32_t);
|
16
|
+
spv *sp_vnewh(sp*, spvh*);
|
17
|
+
spv *sp_vdup(sp*, spv*);
|
18
|
+
spv *sp_vdupref(sp*, spref*, uint32_t);
|
19
|
+
|
20
|
+
sppage *sp_pagenew(sp*, spepoch*);
|
21
|
+
void sp_pagefree(sp*, sppage*);
|
22
|
+
void sp_pageattach(sppage*);
|
23
|
+
void sp_pagedetach(sppage*);
|
24
|
+
|
25
|
+
#endif
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
'targets': [
|
3
|
+
{
|
4
|
+
'target_name': 'sophia',
|
5
|
+
'product_prefix': 'lib',
|
6
|
+
'type': 'static_library',
|
7
|
+
'include_dirs': ['db'],
|
8
|
+
'link_settings': {
|
9
|
+
'libraries': ['-lpthread'],
|
10
|
+
},
|
11
|
+
'direct_dependent_settings': {
|
12
|
+
'include_dirs': ['db'],
|
13
|
+
},
|
14
|
+
'sources': [
|
15
|
+
'db/cat.c',
|
16
|
+
'db/crc.c',
|
17
|
+
'db/cursor.c',
|
18
|
+
'db/e.c',
|
19
|
+
'db/file.c',
|
20
|
+
'db/gc.c',
|
21
|
+
'db/i.c',
|
22
|
+
'db/merge.c',
|
23
|
+
'db/recover.c',
|
24
|
+
'db/rep.c',
|
25
|
+
'db/sp.c',
|
26
|
+
'db/util.c',
|
27
|
+
],
|
28
|
+
},
|
29
|
+
],
|
30
|
+
}
|
@@ -0,0 +1,870 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
* sophia database
|
4
|
+
* sphia.org
|
5
|
+
*
|
6
|
+
* Copyright (c) Dmitry Simonenko
|
7
|
+
* BSD License
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include <sophia.h>
|
11
|
+
#include "test.h"
|
12
|
+
|
13
|
+
static char *dbrep = "./rep";
|
14
|
+
|
15
|
+
static inline int
|
16
|
+
cmp(char *a, size_t asz, char *b, size_t bsz, void *arg) {
|
17
|
+
register uint32_t av = *(uint32_t*)a;
|
18
|
+
register uint32_t bv = *(uint32_t*)b;
|
19
|
+
if (av == bv)
|
20
|
+
return 0;
|
21
|
+
return (av > bv) ? 1 : -1;
|
22
|
+
}
|
23
|
+
|
24
|
+
static void
|
25
|
+
env(void) {
|
26
|
+
void *env = sp_env();
|
27
|
+
t( env != NULL );
|
28
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
29
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
30
|
+
t( sp_destroy(env) == 0 );
|
31
|
+
}
|
32
|
+
|
33
|
+
static void
|
34
|
+
env_opts(void) {
|
35
|
+
void *env = sp_env();
|
36
|
+
t( env != NULL );
|
37
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
38
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
39
|
+
t( sp_ctl(env, SPALLOC, NULL, NULL) == 0 );
|
40
|
+
t( sp_ctl(env, SPPAGE, 1024) == 0 );
|
41
|
+
t( sp_ctl(env, SPGC, 0.5) == 0 );
|
42
|
+
t( sp_ctl(env, SPGROW, 16 * 1024 * 1024, 2.0) == 0 );
|
43
|
+
t( sp_ctl(env, SPMERGE, 1) == 0 );
|
44
|
+
uint32_t major, minor;
|
45
|
+
t( sp_ctl(NULL, SPVERSION, &major, &minor) == 0 );
|
46
|
+
t( major == 1 );
|
47
|
+
t( minor == 1 );
|
48
|
+
t( sp_destroy(env) == 0 );
|
49
|
+
}
|
50
|
+
|
51
|
+
static void
|
52
|
+
open_ro_creat(void) {
|
53
|
+
void *env = sp_env();
|
54
|
+
t( env != NULL );
|
55
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDONLY, dbrep) == 0 );
|
56
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
57
|
+
void *db = sp_open(env);
|
58
|
+
t( db == NULL );
|
59
|
+
t( sp_error(env) != NULL );
|
60
|
+
t( sp_destroy(env) == 0 );
|
61
|
+
}
|
62
|
+
|
63
|
+
static void
|
64
|
+
open_rdwr(void) {
|
65
|
+
void *env = sp_env();
|
66
|
+
t( env != NULL );
|
67
|
+
t( sp_ctl(env, SPDIR, SPO_RDWR, dbrep) == 0 );
|
68
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
69
|
+
void *db = sp_open(env);
|
70
|
+
t( db == NULL );
|
71
|
+
t( sp_error(env) != NULL );
|
72
|
+
t( sp_destroy(env) == 0 );
|
73
|
+
}
|
74
|
+
|
75
|
+
static void
|
76
|
+
open_rdwr_creat(void) {
|
77
|
+
void *env = sp_env();
|
78
|
+
t( env != NULL );
|
79
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
80
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
81
|
+
void *db = sp_open(env);
|
82
|
+
t( db != NULL );
|
83
|
+
t( sp_destroy(db) == 0 );
|
84
|
+
t( sp_destroy(env) == 0 );
|
85
|
+
t( rmrf(dbrep) == 0 );
|
86
|
+
}
|
87
|
+
|
88
|
+
static void
|
89
|
+
open_reopen(void) {
|
90
|
+
void *env = sp_env();
|
91
|
+
t( env != NULL );
|
92
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
93
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
94
|
+
void *db = sp_open(env);
|
95
|
+
t( db != NULL );
|
96
|
+
t( sp_destroy(db) == 0 );
|
97
|
+
db = sp_open(env);
|
98
|
+
t( db != NULL );
|
99
|
+
t( sp_destroy(db) == 0 );
|
100
|
+
t( sp_destroy(env) == 0 );
|
101
|
+
t( rmrf(dbrep) == 0 );
|
102
|
+
}
|
103
|
+
|
104
|
+
static void
|
105
|
+
open_reopen_ro(void) {
|
106
|
+
void *env = sp_env();
|
107
|
+
t( env != NULL );
|
108
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
109
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
110
|
+
void *db = sp_open(env);
|
111
|
+
t( db != NULL );
|
112
|
+
t( sp_destroy(db) == 0 );
|
113
|
+
t( sp_ctl(env, SPDIR, SPO_RDONLY, dbrep) == 0 );
|
114
|
+
db = sp_open(env);
|
115
|
+
t( db != NULL );
|
116
|
+
t( sp_destroy(db) == 0 );
|
117
|
+
t( sp_destroy(env) == 0 );
|
118
|
+
t( rmrf(dbrep) == 0 );
|
119
|
+
}
|
120
|
+
|
121
|
+
static void
|
122
|
+
set(void) {
|
123
|
+
void *env = sp_env();
|
124
|
+
t( env != NULL );
|
125
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
126
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
127
|
+
void *db = sp_open(env);
|
128
|
+
t( db != NULL );
|
129
|
+
uint32_t k = 1, v = 1;
|
130
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
|
131
|
+
t( sp_destroy(db) == 0 );
|
132
|
+
t( sp_destroy(env) == 0 );
|
133
|
+
t( rmrf(dbrep) == 0 );
|
134
|
+
}
|
135
|
+
|
136
|
+
static void
|
137
|
+
set_get(void) {
|
138
|
+
void *env = sp_env();
|
139
|
+
t( env != NULL );
|
140
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
141
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
142
|
+
void *db = sp_open(env);
|
143
|
+
t( db != NULL );
|
144
|
+
uint32_t k = 1, v = 1;
|
145
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
146
|
+
size_t vsize = 0;
|
147
|
+
void *vp = NULL;
|
148
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
149
|
+
t( vsize == sizeof(v) );
|
150
|
+
t( *(uint32_t*)vp == v );
|
151
|
+
free(vp);
|
152
|
+
t( sp_destroy(db) == 0 );
|
153
|
+
t( sp_destroy(env) == 0 );
|
154
|
+
t( rmrf(dbrep) == 0 );
|
155
|
+
}
|
156
|
+
|
157
|
+
static void
|
158
|
+
set_get_zerovalue(void) {
|
159
|
+
void *env = sp_env();
|
160
|
+
t( env != NULL );
|
161
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
162
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
163
|
+
void *db = sp_open(env);
|
164
|
+
t( db != NULL );
|
165
|
+
uint32_t k = 1;
|
166
|
+
t( sp_set(db, &k, sizeof(k), NULL, 0) == 0 );
|
167
|
+
size_t vsize = 0;
|
168
|
+
void *vp = NULL;
|
169
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
170
|
+
t( vsize == 0 );
|
171
|
+
t( vp == NULL );
|
172
|
+
t( sp_destroy(db) == 0 );
|
173
|
+
t( sp_destroy(env) == 0 );
|
174
|
+
t( rmrf(dbrep) == 0 );
|
175
|
+
}
|
176
|
+
|
177
|
+
static void
|
178
|
+
replace(void) {
|
179
|
+
void *env = sp_env();
|
180
|
+
t( env != NULL );
|
181
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
182
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
183
|
+
void *db = sp_open(env);
|
184
|
+
t( db != NULL );
|
185
|
+
uint32_t k = 1, v = 1;
|
186
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
|
187
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
|
188
|
+
t( sp_destroy(db) == 0 );
|
189
|
+
t( sp_destroy(env) == 0 );
|
190
|
+
t( rmrf(dbrep) == 0 );
|
191
|
+
}
|
192
|
+
|
193
|
+
static void
|
194
|
+
replace_get(void) {
|
195
|
+
void *env = sp_env();
|
196
|
+
t( env != NULL );
|
197
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
198
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
199
|
+
void *db = sp_open(env);
|
200
|
+
t( db != NULL );
|
201
|
+
uint32_t k = 1, v = 1;
|
202
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
|
203
|
+
size_t vsize = 0;
|
204
|
+
void *vp = NULL;
|
205
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
206
|
+
t( vsize == sizeof(v) );
|
207
|
+
t( *(uint32_t*)vp == 1 );
|
208
|
+
free(vp);
|
209
|
+
v = 2;
|
210
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
|
211
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
212
|
+
t( vsize == sizeof(v) );
|
213
|
+
t( *(uint32_t*)vp == 2 );
|
214
|
+
free(vp);
|
215
|
+
t( sp_destroy(db) == 0 );
|
216
|
+
t( sp_destroy(env) == 0 );
|
217
|
+
t( rmrf(dbrep) == 0 );
|
218
|
+
}
|
219
|
+
|
220
|
+
static void
|
221
|
+
set_delete(void) {
|
222
|
+
void *env = sp_env();
|
223
|
+
t( env != NULL );
|
224
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
225
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
226
|
+
void *db = sp_open(env);
|
227
|
+
t( db != NULL );
|
228
|
+
uint32_t k = 1, v = 1;
|
229
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
230
|
+
t( sp_delete(db, &k, sizeof(k)) == 0 );
|
231
|
+
t( sp_destroy(db) == 0 );
|
232
|
+
t( sp_destroy(env) == 0 );
|
233
|
+
t( rmrf(dbrep) == 0 );
|
234
|
+
}
|
235
|
+
|
236
|
+
static void
|
237
|
+
set_delete_get(void) {
|
238
|
+
void *env = sp_env();
|
239
|
+
t( env != NULL );
|
240
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
241
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
242
|
+
void *db = sp_open(env);
|
243
|
+
t( db != NULL );
|
244
|
+
uint32_t k = 1, v = 1;
|
245
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
246
|
+
t( sp_delete(db, &k, sizeof(k)) == 0 );
|
247
|
+
size_t vsize = 0;
|
248
|
+
void *vp = NULL;
|
249
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
|
250
|
+
t( sp_destroy(db) == 0 );
|
251
|
+
t( sp_destroy(env) == 0 );
|
252
|
+
t( rmrf(dbrep) == 0 );
|
253
|
+
}
|
254
|
+
|
255
|
+
static void
|
256
|
+
set_delete_set_get(void) {
|
257
|
+
void *env = sp_env();
|
258
|
+
t( env != NULL );
|
259
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
260
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
261
|
+
void *db = sp_open(env);
|
262
|
+
t( db != NULL );
|
263
|
+
uint32_t k = 1, v = 1;
|
264
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
265
|
+
t( sp_delete(db, &k, sizeof(k)) == 0 );
|
266
|
+
v = 2;
|
267
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
268
|
+
size_t vsize = 0;
|
269
|
+
void *vp = NULL;
|
270
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
271
|
+
t( vsize == sizeof(v) );
|
272
|
+
t( *(uint32_t*)vp == 2 );
|
273
|
+
free(vp);
|
274
|
+
t( sp_destroy(db) == 0 );
|
275
|
+
t( sp_destroy(env) == 0 );
|
276
|
+
t( rmrf(dbrep) == 0 );
|
277
|
+
}
|
278
|
+
|
279
|
+
static void
|
280
|
+
delete(void) {
|
281
|
+
void *env = sp_env();
|
282
|
+
t( env != NULL );
|
283
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
284
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
285
|
+
void *db = sp_open(env);
|
286
|
+
t( db != NULL );
|
287
|
+
uint32_t k = 1;
|
288
|
+
t( sp_delete(db, &k, sizeof(k)) == 0 );
|
289
|
+
t( sp_destroy(db) == 0 );
|
290
|
+
t( sp_destroy(env) == 0 );
|
291
|
+
t( rmrf(dbrep) == 0 );
|
292
|
+
}
|
293
|
+
|
294
|
+
static void
|
295
|
+
delete_set_get(void) {
|
296
|
+
void *env = sp_env();
|
297
|
+
t( env != NULL );
|
298
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
299
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
300
|
+
void *db = sp_open(env);
|
301
|
+
t( db != NULL );
|
302
|
+
uint32_t k = 1, v = 1;
|
303
|
+
t( sp_delete(db, &k, sizeof(k)) == 0 );
|
304
|
+
v = 2;
|
305
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
306
|
+
size_t vsize = 0;
|
307
|
+
void *vp = NULL;
|
308
|
+
t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
|
309
|
+
t( vsize == sizeof(v) );
|
310
|
+
t( *(uint32_t*)vp == 2 );
|
311
|
+
free(vp);
|
312
|
+
t( sp_destroy(db) == 0 );
|
313
|
+
t( sp_destroy(env) == 0 );
|
314
|
+
t( rmrf(dbrep) == 0 );
|
315
|
+
}
|
316
|
+
|
317
|
+
static void
|
318
|
+
cursor(void) {
|
319
|
+
void *env = sp_env();
|
320
|
+
t( env != NULL );
|
321
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
322
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
323
|
+
void *db = sp_open(env);
|
324
|
+
t( db != NULL );
|
325
|
+
void *cur = sp_cursor(db, SPGTE, NULL, 0);
|
326
|
+
t( cur != NULL );
|
327
|
+
t( sp_destroy(cur) == 0 );
|
328
|
+
t( sp_destroy(db) == 0 );
|
329
|
+
t( sp_destroy(env) == 0 );
|
330
|
+
t( rmrf(dbrep) == 0 );
|
331
|
+
}
|
332
|
+
|
333
|
+
static void
|
334
|
+
fetch_gte_empty(void) {
|
335
|
+
void *env = sp_env();
|
336
|
+
t( env != NULL );
|
337
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
338
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
339
|
+
void *db = sp_open(env);
|
340
|
+
t( db != NULL );
|
341
|
+
void *cur = sp_cursor(db, SPGTE, NULL, 0);
|
342
|
+
t( cur != NULL );
|
343
|
+
t( sp_fetch(cur) == 0 );
|
344
|
+
t( sp_fetch(cur) == 0 );
|
345
|
+
t( sp_destroy(cur) == 0 );
|
346
|
+
t( sp_destroy(db) == 0 );
|
347
|
+
t( sp_destroy(env) == 0 );
|
348
|
+
t( rmrf(dbrep) == 0 );
|
349
|
+
}
|
350
|
+
|
351
|
+
static void
|
352
|
+
fetch_gt_empty(void) {
|
353
|
+
void *env = sp_env();
|
354
|
+
t( env != NULL );
|
355
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
356
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
357
|
+
void *db = sp_open(env);
|
358
|
+
t( db != NULL );
|
359
|
+
void *cur = sp_cursor(db, SPGT, NULL, 0);
|
360
|
+
t( cur != NULL );
|
361
|
+
t( sp_fetch(cur) == 0 );
|
362
|
+
t( sp_fetch(cur) == 0 );
|
363
|
+
t( sp_destroy(cur) == 0 );
|
364
|
+
t( sp_destroy(db) == 0 );
|
365
|
+
t( sp_destroy(env) == 0 );
|
366
|
+
t( rmrf(dbrep) == 0 );
|
367
|
+
}
|
368
|
+
|
369
|
+
static void
|
370
|
+
fetch_lte_empty(void) {
|
371
|
+
void *env = sp_env();
|
372
|
+
t( env != NULL );
|
373
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
374
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
375
|
+
void *db = sp_open(env);
|
376
|
+
t( db != NULL );
|
377
|
+
void *cur = sp_cursor(db, SPLTE, NULL, 0);
|
378
|
+
t( cur != NULL );
|
379
|
+
t( sp_fetch(cur) == 0 );
|
380
|
+
t( sp_fetch(cur) == 0 );
|
381
|
+
t( sp_destroy(cur) == 0 );
|
382
|
+
t( sp_destroy(db) == 0 );
|
383
|
+
t( sp_destroy(env) == 0 );
|
384
|
+
t( rmrf(dbrep) == 0 );
|
385
|
+
}
|
386
|
+
|
387
|
+
static void
|
388
|
+
fetch_lt_empty(void) {
|
389
|
+
void *env = sp_env();
|
390
|
+
t( env != NULL );
|
391
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
392
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
393
|
+
void *db = sp_open(env);
|
394
|
+
t( db != NULL );
|
395
|
+
void *cur = sp_cursor(db, SPLT, NULL, 0);
|
396
|
+
t( cur != NULL );
|
397
|
+
t( sp_fetch(cur) == 0 );
|
398
|
+
t( sp_fetch(cur) == 0 );
|
399
|
+
t( sp_destroy(cur) == 0 );
|
400
|
+
t( sp_destroy(db) == 0 );
|
401
|
+
t( sp_destroy(env) == 0 );
|
402
|
+
t( rmrf(dbrep) == 0 );
|
403
|
+
}
|
404
|
+
|
405
|
+
static void
|
406
|
+
fetch_kgte_empty(void) {
|
407
|
+
void *env = sp_env();
|
408
|
+
t( env != NULL );
|
409
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
410
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
411
|
+
void *db = sp_open(env);
|
412
|
+
t( db != NULL );
|
413
|
+
uint32_t k = 1;
|
414
|
+
void *cur = sp_cursor(db, SPGTE, &k, sizeof(k));
|
415
|
+
t( cur != NULL );
|
416
|
+
t( sp_fetch(cur) == 0 );
|
417
|
+
t( sp_fetch(cur) == 0 );
|
418
|
+
t( sp_destroy(cur) == 0 );
|
419
|
+
t( sp_destroy(db) == 0 );
|
420
|
+
t( sp_destroy(env) == 0 );
|
421
|
+
t( rmrf(dbrep) == 0 );
|
422
|
+
}
|
423
|
+
|
424
|
+
static void
|
425
|
+
fetch_kgt_empty(void) {
|
426
|
+
void *env = sp_env();
|
427
|
+
t( env != NULL );
|
428
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
429
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
430
|
+
void *db = sp_open(env);
|
431
|
+
t( db != NULL );
|
432
|
+
uint32_t k = 1;
|
433
|
+
void *cur = sp_cursor(db, SPGT, &k, sizeof(k));
|
434
|
+
t( cur != NULL );
|
435
|
+
t( sp_fetch(cur) == 0 );
|
436
|
+
t( sp_fetch(cur) == 0 );
|
437
|
+
t( sp_destroy(cur) == 0 );
|
438
|
+
t( sp_destroy(db) == 0 );
|
439
|
+
t( sp_destroy(env) == 0 );
|
440
|
+
t( rmrf(dbrep) == 0 );
|
441
|
+
}
|
442
|
+
|
443
|
+
static void
|
444
|
+
fetch_klte_empty(void) {
|
445
|
+
void *env = sp_env();
|
446
|
+
t( env != NULL );
|
447
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
448
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
449
|
+
void *db = sp_open(env);
|
450
|
+
t( db != NULL );
|
451
|
+
uint32_t k = 1;
|
452
|
+
void *cur = sp_cursor(db, SPLTE, &k, sizeof(k));
|
453
|
+
t( cur != NULL );
|
454
|
+
t( sp_fetch(cur) == 0 );
|
455
|
+
t( sp_fetch(cur) == 0 );
|
456
|
+
t( sp_destroy(cur) == 0 );
|
457
|
+
t( sp_destroy(db) == 0 );
|
458
|
+
t( sp_destroy(env) == 0 );
|
459
|
+
t( rmrf(dbrep) == 0 );
|
460
|
+
}
|
461
|
+
|
462
|
+
static void
|
463
|
+
fetch_klt_empty(void) {
|
464
|
+
void *env = sp_env();
|
465
|
+
t( env != NULL );
|
466
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
467
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
468
|
+
void *db = sp_open(env);
|
469
|
+
t( db != NULL );
|
470
|
+
uint32_t k = 1;
|
471
|
+
void *cur = sp_cursor(db, SPLT, &k, sizeof(k));
|
472
|
+
t( cur != NULL );
|
473
|
+
t( sp_fetch(cur) == 0 );
|
474
|
+
t( sp_fetch(cur) == 0 );
|
475
|
+
t( sp_destroy(cur) == 0 );
|
476
|
+
t( sp_destroy(db) == 0 );
|
477
|
+
t( sp_destroy(env) == 0 );
|
478
|
+
t( rmrf(dbrep) == 0 );
|
479
|
+
}
|
480
|
+
|
481
|
+
static void
|
482
|
+
fetch_gte(void) {
|
483
|
+
void *env = sp_env();
|
484
|
+
t( env != NULL );
|
485
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
486
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
487
|
+
void *db = sp_open(env);
|
488
|
+
t( db != NULL );
|
489
|
+
uint32_t k = 1, v = 2;
|
490
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
491
|
+
k = 2;
|
492
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
493
|
+
k = 3;
|
494
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
495
|
+
void *cur = sp_cursor(db, SPGTE, NULL, 0);
|
496
|
+
t( cur != NULL );
|
497
|
+
t( sp_fetch(cur) == 1 );
|
498
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
499
|
+
t( sp_keysize(cur) == sizeof(k) );
|
500
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
501
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
502
|
+
t( sp_fetch(cur) == 1 );
|
503
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
504
|
+
t( sp_keysize(cur) == sizeof(k) );
|
505
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
506
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
507
|
+
t( sp_fetch(cur) == 1 );
|
508
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
509
|
+
t( sp_keysize(cur) == sizeof(k) );
|
510
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
511
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
512
|
+
t( sp_fetch(cur) == 0 );
|
513
|
+
t( sp_fetch(cur) == 0 );
|
514
|
+
t( sp_destroy(cur) == 0 );
|
515
|
+
t( sp_destroy(db) == 0 );
|
516
|
+
t( sp_destroy(env) == 0 );
|
517
|
+
t( rmrf(dbrep) == 0 );
|
518
|
+
}
|
519
|
+
|
520
|
+
static void
|
521
|
+
fetch_gt(void) {
|
522
|
+
void *env = sp_env();
|
523
|
+
t( env != NULL );
|
524
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
525
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
526
|
+
void *db = sp_open(env);
|
527
|
+
t( db != NULL );
|
528
|
+
uint32_t k = 1, v = 2;
|
529
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
530
|
+
k = 2;
|
531
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
532
|
+
k = 3;
|
533
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
534
|
+
void *cur = sp_cursor(db, SPGT, NULL, 0);
|
535
|
+
t( cur != NULL );
|
536
|
+
t( sp_fetch(cur) == 1 );
|
537
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
538
|
+
t( sp_keysize(cur) == sizeof(k) );
|
539
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
540
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
541
|
+
t( sp_fetch(cur) == 1 );
|
542
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
543
|
+
t( sp_keysize(cur) == sizeof(k) );
|
544
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
545
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
546
|
+
t( sp_fetch(cur) == 1 );
|
547
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
548
|
+
t( sp_keysize(cur) == sizeof(k) );
|
549
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
550
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
551
|
+
t( sp_fetch(cur) == 0 );
|
552
|
+
t( sp_fetch(cur) == 0 );
|
553
|
+
t( sp_destroy(cur) == 0 );
|
554
|
+
t( sp_destroy(db) == 0 );
|
555
|
+
t( sp_destroy(env) == 0 );
|
556
|
+
t( rmrf(dbrep) == 0 );
|
557
|
+
}
|
558
|
+
|
559
|
+
static void
|
560
|
+
fetch_lte(void) {
|
561
|
+
void *env = sp_env();
|
562
|
+
t( env != NULL );
|
563
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
564
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
565
|
+
void *db = sp_open(env);
|
566
|
+
t( db != NULL );
|
567
|
+
uint32_t k = 1, v = 2;
|
568
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
569
|
+
k = 2;
|
570
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
571
|
+
k = 3;
|
572
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
573
|
+
void *cur = sp_cursor(db, SPLTE, NULL, 0);
|
574
|
+
t( cur != NULL );
|
575
|
+
t( sp_fetch(cur) == 1 );
|
576
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
577
|
+
t( sp_keysize(cur) == sizeof(k) );
|
578
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
579
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
580
|
+
t( sp_fetch(cur) == 1 );
|
581
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
582
|
+
t( sp_keysize(cur) == sizeof(k) );
|
583
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
584
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
585
|
+
t( sp_fetch(cur) == 1 );
|
586
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
587
|
+
t( sp_keysize(cur) == sizeof(k) );
|
588
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
589
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
590
|
+
t( sp_fetch(cur) == 0 );
|
591
|
+
t( sp_fetch(cur) == 0 );
|
592
|
+
t( sp_destroy(cur) == 0 );
|
593
|
+
t( sp_destroy(db) == 0 );
|
594
|
+
t( sp_destroy(env) == 0 );
|
595
|
+
t( rmrf(dbrep) == 0 );
|
596
|
+
}
|
597
|
+
|
598
|
+
static void
|
599
|
+
fetch_lt(void) {
|
600
|
+
void *env = sp_env();
|
601
|
+
t( env != NULL );
|
602
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
603
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
604
|
+
void *db = sp_open(env);
|
605
|
+
t( db != NULL );
|
606
|
+
uint32_t k = 1, v = 2;
|
607
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
608
|
+
k = 2;
|
609
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
610
|
+
k = 3;
|
611
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
612
|
+
void *cur = sp_cursor(db, SPLT, NULL, 0);
|
613
|
+
t( cur != NULL );
|
614
|
+
t( sp_fetch(cur) == 1 );
|
615
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
616
|
+
t( sp_keysize(cur) == sizeof(k) );
|
617
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
618
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
619
|
+
t( sp_fetch(cur) == 1 );
|
620
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
621
|
+
t( sp_keysize(cur) == sizeof(k) );
|
622
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
623
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
624
|
+
t( sp_fetch(cur) == 1 );
|
625
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
626
|
+
t( sp_keysize(cur) == sizeof(k) );
|
627
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
628
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
629
|
+
t( sp_fetch(cur) == 0 );
|
630
|
+
t( sp_fetch(cur) == 0 );
|
631
|
+
t( sp_destroy(cur) == 0 );
|
632
|
+
t( sp_destroy(db) == 0 );
|
633
|
+
t( sp_destroy(env) == 0 );
|
634
|
+
t( rmrf(dbrep) == 0 );
|
635
|
+
}
|
636
|
+
|
637
|
+
static void
|
638
|
+
fetch_kgte(void) {
|
639
|
+
void *env = sp_env();
|
640
|
+
t( env != NULL );
|
641
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
642
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
643
|
+
void *db = sp_open(env);
|
644
|
+
t( db != NULL );
|
645
|
+
uint32_t k = 1, v = 2;
|
646
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
647
|
+
k = 2;
|
648
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
649
|
+
k = 3;
|
650
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
651
|
+
|
652
|
+
k = 2;
|
653
|
+
void *cur = sp_cursor(db, SPGTE, &k, sizeof(k));
|
654
|
+
t( cur != NULL );
|
655
|
+
t( sp_fetch(cur) == 1 );
|
656
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
657
|
+
t( sp_keysize(cur) == sizeof(k) );
|
658
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
659
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
660
|
+
t( sp_fetch(cur) == 1 );
|
661
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
662
|
+
t( sp_keysize(cur) == sizeof(k) );
|
663
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
664
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
665
|
+
t( sp_fetch(cur) == 0 );
|
666
|
+
t( sp_fetch(cur) == 0 );
|
667
|
+
t( sp_destroy(cur) == 0 );
|
668
|
+
t( sp_destroy(db) == 0 );
|
669
|
+
t( sp_destroy(env) == 0 );
|
670
|
+
t( rmrf(dbrep) == 0 );
|
671
|
+
}
|
672
|
+
|
673
|
+
static void
|
674
|
+
fetch_kgt(void) {
|
675
|
+
void *env = sp_env();
|
676
|
+
t( env != NULL );
|
677
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
678
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
679
|
+
void *db = sp_open(env);
|
680
|
+
t( db != NULL );
|
681
|
+
uint32_t k = 1, v = 2;
|
682
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
683
|
+
k = 2;
|
684
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
685
|
+
k = 3;
|
686
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
687
|
+
k = 2;
|
688
|
+
void *cur = sp_cursor(db, SPGT, &k, sizeof(k));
|
689
|
+
t( cur != NULL );
|
690
|
+
t( sp_fetch(cur) == 1 );
|
691
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
692
|
+
t( sp_keysize(cur) == sizeof(k) );
|
693
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
694
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
695
|
+
t( sp_fetch(cur) == 0 );
|
696
|
+
t( sp_fetch(cur) == 0 );
|
697
|
+
t( sp_destroy(cur) == 0 );
|
698
|
+
t( sp_destroy(db) == 0 );
|
699
|
+
t( sp_destroy(env) == 0 );
|
700
|
+
t( rmrf(dbrep) == 0 );
|
701
|
+
}
|
702
|
+
|
703
|
+
static void
|
704
|
+
fetch_klte(void) {
|
705
|
+
void *env = sp_env();
|
706
|
+
t( env != NULL );
|
707
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
708
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
709
|
+
void *db = sp_open(env);
|
710
|
+
t( db != NULL );
|
711
|
+
uint32_t k = 1, v = 2;
|
712
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
713
|
+
k = 2;
|
714
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
715
|
+
k = 3;
|
716
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
717
|
+
k = 2;
|
718
|
+
void *cur = sp_cursor(db, SPLTE, &k, sizeof(k) );
|
719
|
+
t( cur != NULL );
|
720
|
+
t( sp_fetch(cur) == 1 );
|
721
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
722
|
+
t( sp_keysize(cur) == sizeof(k) );
|
723
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
724
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
725
|
+
t( sp_fetch(cur) == 1 );
|
726
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
727
|
+
t( sp_keysize(cur) == sizeof(k) );
|
728
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
729
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
730
|
+
t( sp_fetch(cur) == 0 );
|
731
|
+
t( sp_fetch(cur) == 0 );
|
732
|
+
t( sp_destroy(cur) == 0 );
|
733
|
+
t( sp_destroy(db) == 0 );
|
734
|
+
t( sp_destroy(env) == 0 );
|
735
|
+
t( rmrf(dbrep) == 0 );
|
736
|
+
}
|
737
|
+
|
738
|
+
static void
|
739
|
+
fetch_klt(void) {
|
740
|
+
void *env = sp_env();
|
741
|
+
t( env != NULL );
|
742
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
743
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
744
|
+
void *db = sp_open(env);
|
745
|
+
t( db != NULL );
|
746
|
+
uint32_t k = 1, v = 2;
|
747
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
748
|
+
k = 2;
|
749
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
750
|
+
k = 3;
|
751
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
752
|
+
k = 2;
|
753
|
+
void *cur = sp_cursor(db, SPLT, &k, sizeof(k) );
|
754
|
+
t( cur != NULL );
|
755
|
+
t( sp_fetch(cur) == 1 );
|
756
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
757
|
+
t( sp_keysize(cur) == sizeof(k) );
|
758
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
759
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
760
|
+
t( sp_fetch(cur) == 0 );
|
761
|
+
t( sp_fetch(cur) == 0 );
|
762
|
+
t( sp_destroy(cur) == 0 );
|
763
|
+
t( sp_destroy(db) == 0 );
|
764
|
+
t( sp_destroy(env) == 0 );
|
765
|
+
t( rmrf(dbrep) == 0 );
|
766
|
+
}
|
767
|
+
|
768
|
+
static void
|
769
|
+
fetch_after_end(void) {
|
770
|
+
void *env = sp_env();
|
771
|
+
t( env != NULL );
|
772
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
773
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
774
|
+
void *db = sp_open(env);
|
775
|
+
t( db != NULL );
|
776
|
+
uint32_t k = 1, v = 2;
|
777
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
778
|
+
k = 2;
|
779
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
780
|
+
k = 3;
|
781
|
+
t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
|
782
|
+
void *cur = sp_cursor(db, SPGTE, NULL, 0);
|
783
|
+
t( cur != NULL );
|
784
|
+
t( sp_fetch(cur) == 1 );
|
785
|
+
t( *(uint32_t*)sp_key(cur) == 1 );
|
786
|
+
t( sp_keysize(cur) == sizeof(k) );
|
787
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
788
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
789
|
+
t( sp_fetch(cur) == 1 );
|
790
|
+
t( *(uint32_t*)sp_key(cur) == 2 );
|
791
|
+
t( sp_keysize(cur) == sizeof(k) );
|
792
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
793
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
794
|
+
t( sp_fetch(cur) == 1 );
|
795
|
+
t( *(uint32_t*)sp_key(cur) == 3 );
|
796
|
+
t( sp_keysize(cur) == sizeof(k) );
|
797
|
+
t( *(uint32_t*)sp_value(cur) == 2 );
|
798
|
+
t( sp_valuesize(cur) == sizeof(v) );
|
799
|
+
t( sp_fetch(cur) == 0 );
|
800
|
+
t( sp_keysize(cur) == 0 );
|
801
|
+
t( sp_key(cur) == NULL );
|
802
|
+
t( sp_valuesize(cur) == 0 );
|
803
|
+
t( sp_value(cur) == NULL );
|
804
|
+
t( sp_destroy(cur) == 0 );
|
805
|
+
t( sp_destroy(db) == 0 );
|
806
|
+
t( sp_destroy(env) == 0 );
|
807
|
+
t( rmrf(dbrep) == 0 );
|
808
|
+
}
|
809
|
+
|
810
|
+
static void
|
811
|
+
cursor_set(void) {
|
812
|
+
void *env = sp_env();
|
813
|
+
t( env != NULL );
|
814
|
+
t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
|
815
|
+
t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
|
816
|
+
void *db = sp_open(env);
|
817
|
+
t( db != NULL );
|
818
|
+
void *cur = sp_cursor(db, SPGTE, NULL, 0);
|
819
|
+
t( cur != NULL );
|
820
|
+
uint32_t k = 1;
|
821
|
+
t( sp_set(db, &k, sizeof(k), &k, sizeof(k)) == -1 );
|
822
|
+
t( sp_destroy(cur) == 0 );
|
823
|
+
t( sp_destroy(db) == 0 );
|
824
|
+
t( sp_destroy(env) == 0 );
|
825
|
+
t( rmrf(dbrep) == 0 );
|
826
|
+
}
|
827
|
+
|
828
|
+
int
|
829
|
+
main(int argc, char *argv[])
|
830
|
+
{
|
831
|
+
rmrf(dbrep);
|
832
|
+
|
833
|
+
test(env);
|
834
|
+
test(env_opts);
|
835
|
+
test(open_ro_creat);
|
836
|
+
test(open_rdwr);
|
837
|
+
test(open_rdwr_creat);
|
838
|
+
test(open_reopen);
|
839
|
+
test(open_reopen_ro);
|
840
|
+
test(set);
|
841
|
+
test(set_get);
|
842
|
+
test(set_get_zerovalue);
|
843
|
+
test(replace);
|
844
|
+
test(replace_get);
|
845
|
+
test(set_delete);
|
846
|
+
test(set_delete_get);
|
847
|
+
test(set_delete_set_get);
|
848
|
+
test(delete);
|
849
|
+
test(delete_set_get);
|
850
|
+
test(cursor);
|
851
|
+
test(fetch_gte_empty);
|
852
|
+
test(fetch_gt_empty);
|
853
|
+
test(fetch_lte_empty);
|
854
|
+
test(fetch_lt_empty);
|
855
|
+
test(fetch_kgte_empty);
|
856
|
+
test(fetch_kgt_empty);
|
857
|
+
test(fetch_klte_empty);
|
858
|
+
test(fetch_klt_empty);
|
859
|
+
test(fetch_gte);
|
860
|
+
test(fetch_gt);
|
861
|
+
test(fetch_lte);
|
862
|
+
test(fetch_lt);
|
863
|
+
test(fetch_kgte);
|
864
|
+
test(fetch_kgt);
|
865
|
+
test(fetch_klte);
|
866
|
+
test(fetch_klt);
|
867
|
+
test(fetch_after_end);
|
868
|
+
test(cursor_set);
|
869
|
+
return 0;
|
870
|
+
}
|