7 ** Test that the rules for when lsm_csr_next() and lsm_csr_prev() are
8 ** enforced. Specifically:
10 ** * Both functions always return LSM_MISUSE if the cursor is at EOF
11 ** when they are called.
13 ** * lsm_csr_next() may only be used after lsm_csr_seek(LSM_SEEK_GE) or
16 ** * lsm_csr_prev() may only be used after lsm_csr_seek(LSM_SEEK_LE) or
19 static void do_test_api1_lsm(lsm_db
*pDb
, int *pRc
){
26 ret
= lsm_csr_open(pDb
, &pCsr
);
27 testCompareInt(LSM_OK
, ret
, pRc
);
29 ret
= lsm_csr_next(pCsr
);
30 testCompareInt(LSM_MISUSE
, ret
, pRc
);
31 ret
= lsm_csr_prev(pCsr
);
32 testCompareInt(LSM_MISUSE
, ret
, pRc
);
34 ret
= lsm_csr_seek(pCsr
, "jjj", 3, LSM_SEEK_GE
);
35 testCompareInt(LSM_OK
, ret
, pRc
);
36 ret
= lsm_csr_next(pCsr
);
37 testCompareInt(LSM_OK
, ret
, pRc
);
38 ret
= lsm_csr_prev(pCsr
);
39 testCompareInt(LSM_MISUSE
, ret
, pRc
);
41 ret
= lsm_csr_seek(pCsr
, "jjj", 3, LSM_SEEK_LE
);
42 testCompareInt(LSM_OK
, ret
, pRc
);
43 ret
= lsm_csr_next(pCsr
);
44 testCompareInt(LSM_MISUSE
, ret
, pRc
);
45 ret
= lsm_csr_prev(pCsr
);
46 testCompareInt(LSM_OK
, ret
, pRc
);
48 ret
= lsm_csr_seek(pCsr
, "jjj", 3, LSM_SEEK_LEFAST
);
49 testCompareInt(LSM_OK
, ret
, pRc
);
50 ret
= lsm_csr_next(pCsr
);
51 testCompareInt(LSM_MISUSE
, ret
, pRc
);
52 ret
= lsm_csr_prev(pCsr
);
53 testCompareInt(LSM_MISUSE
, ret
, pRc
);
55 ret
= lsm_csr_key(pCsr
, &pKey
, &nKey
);
56 testCompareInt(LSM_OK
, ret
, pRc
);
58 ret
= lsm_csr_open(pDb
, &pCsr2
);
59 testCompareInt(LSM_OK
, ret
, pRc
);
61 ret
= lsm_csr_seek(pCsr2
, pKey
, nKey
, LSM_SEEK_EQ
);
62 testCompareInt(LSM_OK
, ret
, pRc
);
63 testCompareInt(1, lsm_csr_valid(pCsr2
), pRc
);
64 ret
= lsm_csr_next(pCsr2
);
65 testCompareInt(LSM_MISUSE
, ret
, pRc
);
66 ret
= lsm_csr_prev(pCsr2
);
67 testCompareInt(LSM_MISUSE
, ret
, pRc
);
71 ret
= lsm_csr_first(pCsr
);
72 testCompareInt(LSM_OK
, ret
, pRc
);
73 ret
= lsm_csr_next(pCsr
);
74 testCompareInt(LSM_OK
, ret
, pRc
);
75 ret
= lsm_csr_prev(pCsr
);
76 testCompareInt(LSM_MISUSE
, ret
, pRc
);
78 ret
= lsm_csr_last(pCsr
);
79 testCompareInt(LSM_OK
, ret
, pRc
);
80 ret
= lsm_csr_prev(pCsr
);
81 testCompareInt(LSM_OK
, ret
, pRc
);
82 ret
= lsm_csr_next(pCsr
);
83 testCompareInt(LSM_MISUSE
, ret
, pRc
);
85 ret
= lsm_csr_first(pCsr
);
86 while( lsm_csr_valid(pCsr
) ){
87 ret
= lsm_csr_next(pCsr
);
88 testCompareInt(LSM_OK
, ret
, pRc
);
90 ret
= lsm_csr_next(pCsr
);
91 testCompareInt(LSM_OK
, ret
, pRc
);
92 ret
= lsm_csr_prev(pCsr
);
93 testCompareInt(LSM_MISUSE
, ret
, pRc
);
95 ret
= lsm_csr_last(pCsr
);
96 while( lsm_csr_valid(pCsr
) ){
97 ret
= lsm_csr_prev(pCsr
);
98 testCompareInt(LSM_OK
, ret
, pRc
);
100 ret
= lsm_csr_prev(pCsr
);
101 testCompareInt(LSM_OK
, ret
, pRc
);
102 ret
= lsm_csr_next(pCsr
);
103 testCompareInt(LSM_MISUSE
, ret
, pRc
);
108 static void do_test_api1(const char *zPattern
, int *pRc
){
109 if( testCaseBegin(pRc
, zPattern
, "api1.lsm") ){
110 const DatasourceDefn defn
= { TEST_DATASOURCE_RANDOM
, 10, 15, 200, 250 };
115 pDb
= testOpen("lsm_lomem", 1, &rc
);
116 pData
= testDatasourceNew(&defn
);
117 testWriteDatasourceRange(pDb
, pData
, 0, 1000, pRc
);
119 do_test_api1_lsm(tdb_lsm(pDb
), pRc
);
121 testDatasourceFree(pData
);
124 testCaseFinish(*pRc
);
128 static lsm_db
*newLsmConnection(
138 *pRc
= lsm_new(tdb_lsm_env(), &db
);
140 if( n1
) lsm_config(db
, LSM_CONFIG_PAGE_SIZE
, &n1
);
141 if( n2
) lsm_config(db
, LSM_CONFIG_BLOCK_SIZE
, &n2
);
142 *pRc
= lsm_open(db
, "testdb.lsm");
148 static void testPagesize(lsm_db
*db
, int nPgsz
, int nBlksz
, int *pRc
){
153 lsm_config(db
, LSM_CONFIG_PAGE_SIZE
, &n1
);
154 lsm_config(db
, LSM_CONFIG_BLOCK_SIZE
, &n2
);
156 testCompareInt(n1
, nPgsz
, pRc
);
157 testCompareInt(n2
, nBlksz
, pRc
);
162 ** Test case "api2" tests that the default page and block sizes of a
163 ** database may only be modified before lsm_open() is called. And that
164 ** after lsm_open() is called lsm_config() may be used to read the
165 ** actual page and block size of the db.
167 static void do_test_api2(const char *zPattern
, int *pRc
){
168 if( *pRc
==0 && testCaseBegin(pRc
, zPattern
, "api2.lsm") ){
172 testDeleteLsmdb("testdb.lsm");
173 db1
= newLsmConnection("testdb.lsm", 0, 0, pRc
);
174 testPagesize(db1
, 4096, 1024, pRc
);
175 db2
= newLsmConnection("testdb.lsm", 1024, 64*1024, pRc
);
176 testPagesize(db2
, 4096, 1024, pRc
);
180 testDeleteLsmdb("testdb.lsm");
181 db1
= newLsmConnection("testdb.lsm", 1024, 64*1024, pRc
);
182 testPagesize(db1
, 1024, 64*1024, pRc
);
183 db2
= newLsmConnection("testdb.lsm", 0, 0, pRc
);
184 testPagesize(db2
, 1024, 64*1024, pRc
);
188 testDeleteLsmdb("testdb.lsm");
189 db1
= newLsmConnection("testdb.lsm", 8192, 2*1024, pRc
);
190 testPagesize(db1
, 8192, 2*1024, pRc
);
191 db2
= newLsmConnection("testdb.lsm", 1024, 64*1024, pRc
);
192 testPagesize(db2
, 8192, 2*1024, pRc
);
196 testCaseFinish(*pRc
);
201 const char *zPattern
, /* Run test cases that match this pattern */
202 int *pRc
/* IN/OUT: Error code */
204 do_test_api1(zPattern
, pRc
);
205 do_test_api2(zPattern
, pRc
);