Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 788 lines (638 sloc) 24.448 kb
b1b5aed @cruppstahl recno unittests
authored
1 /**
691b505 @cruppstahl header comment: copyright is now 2008
authored
2 * Copyright (C) 2005-2008 Christoph Rupp (chris@crupp.de).
b1b5aed @cruppstahl recno unittests
authored
3 *
4004231 @cruppstahl fixed header comments
authored
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
b1b5aed @cruppstahl recno unittests
authored
8 *
9be0b64 @cruppstahl added COPYING.COM
authored
9 * See files COPYING.* for License information.
b1b5aed @cruppstahl recno unittests
authored
10 */
11
41d2dd2 @cruppstahl adding config.h
authored
12 #include "../src/config.h"
13
b1b5aed @cruppstahl recno unittests
authored
14 #include <stdexcept>
15 #include <string.h>
16 #include <ham/hamsterdb.h>
17 #include "../src/db.h"
90bfd4f @cruppstahl many refactorings and beautifications; unittests are broken - progress i...
authored
18 #include "../src/env.h"
9309ce3 @cruppstahl refactoring/review of util.c
authored
19 #include "../src/btree.h"
1eb7909 @cruppstahl unit tests no longer modify big/little endian samples
authored
20 #include "os.hpp"
b1b5aed @cruppstahl recno unittests
authored
21
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
22 #include "bfc-testsuite.hpp"
c72c72c @cruppstahl using different fixture as base class
authored
23 #include "hamster_fixture.hpp"
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
24
25 using namespace bfc;
26
c72c72c @cruppstahl using different fixture as base class
authored
27 class RecNoTest : public hamsterDB_fixture
b1b5aed @cruppstahl recno unittests
authored
28 {
54e175f @cruppstahl whitespace fixes
authored
29 define_super(hamsterDB_fixture);
c72c72c @cruppstahl using different fixture as base class
authored
30
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
31 public:
c72c72c @cruppstahl using different fixture as base class
authored
32 RecNoTest(ham_u32_t flags=0, const char *name="RecNoTest")
33 : hamsterDB_fixture(name), m_flags(flags)
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
34 {
35 testrunner::get_instance()->register_fixture(this);
36 BFC_REGISTER_TEST(RecNoTest, createCloseTest);
37 BFC_REGISTER_TEST(RecNoTest, createCloseOpenCloseTest);
38 BFC_REGISTER_TEST(RecNoTest, createInsertCloseTest);
39 BFC_REGISTER_TEST(RecNoTest, createInsertManyCloseTest);
40 BFC_REGISTER_TEST(RecNoTest, createInsertCloseCursorTest);
41 BFC_REGISTER_TEST(RecNoTest, createInsertCloseReopenTest);
42 BFC_REGISTER_TEST(RecNoTest, createInsertCloseReopenCursorTest);
43 BFC_REGISTER_TEST(RecNoTest, createInsertCloseReopenTwiceTest);
44 BFC_REGISTER_TEST(RecNoTest, createInsertCloseReopenTwiceCursorTest);
45 BFC_REGISTER_TEST(RecNoTest, insertBadKeyTest);
46 BFC_REGISTER_TEST(RecNoTest, insertBadKeyCursorTest);
47 BFC_REGISTER_TEST(RecNoTest, createBadKeysizeTest);
48 BFC_REGISTER_TEST(RecNoTest, envTest);
49 BFC_REGISTER_TEST(RecNoTest, endianTestOpenDatabase);
50 BFC_REGISTER_TEST(RecNoTest, overwriteTest);
51 BFC_REGISTER_TEST(RecNoTest, overwriteCursorTest);
52 BFC_REGISTER_TEST(RecNoTest, eraseLastReopenTest);
53 BFC_REGISTER_TEST(RecNoTest, uncoupleTest);
54 }
b1b5aed @cruppstahl recno unittests
authored
55
56 protected:
57 ham_u32_t m_flags;
58 ham_db_t *m_db;
59
60 public:
c72c72c @cruppstahl using different fixture as base class
authored
61 virtual void setup()
54e175f @cruppstahl whitespace fixes
authored
62 {
63 __super::setup();
c72c72c @cruppstahl using different fixture as base class
authored
64
2319df2 @cruppstahl all tests are working now
authored
65 (void)os::unlink(BFC_OPATH(".test"));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
66 BFC_ASSERT_EQUAL(0, ham_new(&m_db));
b1b5aed @cruppstahl recno unittests
authored
67 }
68
c72c72c @cruppstahl using different fixture as base class
authored
69 virtual void teardown()
54e175f @cruppstahl whitespace fixes
authored
70 {
71 __super::teardown();
c72c72c @cruppstahl using different fixture as base class
authored
72
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
73 BFC_ASSERT_EQUAL(0, ham_delete(m_db));
b1b5aed @cruppstahl recno unittests
authored
74 }
75
76 void createCloseTest(void)
77 {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
78 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
79 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
80 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
81 }
82
83 void createCloseOpenCloseTest(void)
84 {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
85 BFC_ASSERT_EQUAL(0,
90bfd4f @cruppstahl many refactorings and beautifications; unittests are broken - progress i...
authored
86 ham_create(m_db, BFC_OPATH(".test"),
87 m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
88 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
89 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
90 ham_open(m_db, BFC_OPATH(".test"), m_flags));
5b9b697 @cruppstahl Database is C++-ified; WIP
authored
91 BFC_ASSERT(((Database *)m_db)->get_rt_flags()&HAM_RECORD_NUMBER);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
92 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
93 }
94
95 void createInsertCloseReopenTest(void)
96 {
97 ham_key_t key;
98 ham_record_t rec;
99 ham_u64_t recno, value=1;
100
101 memset(&key, 0, sizeof(key));
102 memset(&rec, 0, sizeof(rec));
103
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
104 key.flags=HAM_KEY_USER_ALLOC;
b1b5aed @cruppstahl recno unittests
authored
105 key.data=&recno;
106 key.size=sizeof(recno);
107
108 rec.data=&value;
109 rec.size=sizeof(value);
110
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
111 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
112 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
b1b5aed @cruppstahl recno unittests
authored
113
114 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
115 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
116 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
117 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
118 }
119
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
120 key.flags=HAM_KEY_USER_ALLOC;
121 key.data=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
122 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
123 ham_insert(m_db, 0, &key, &rec, 0));
124 key.data=&recno;
125 key.size=4;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
126 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
127 ham_insert(m_db, 0, &key, &rec, 0));
128 key.size=sizeof(recno);
129
130 key.flags=0;
131 key.size=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
132 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
133 ham_insert(m_db, 0, &key, &rec, 0));
134 key.size=8;
135 key.data=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
136 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
137 ham_insert(m_db, 0, &key, &rec, 0));
138 key.data=&recno;
139 key.flags=HAM_KEY_USER_ALLOC;
140
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
141 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
142 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
143 ham_open(m_db, BFC_OPATH(".test"), m_flags));
b1b5aed @cruppstahl recno unittests
authored
144
145 for (int i=5; i<10; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
146 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
147 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
148 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
149 }
150
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
151 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
152 }
153
929d4cb @cruppstahl added env test (broken!)
authored
154 void createInsertCloseReopenCursorTest(void)
155 {
156 ham_key_t key;
157 ham_record_t rec;
158 ham_cursor_t *cursor;
159 ham_u64_t recno, value=1;
160
161 memset(&key, 0, sizeof(key));
162 memset(&rec, 0, sizeof(rec));
163
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
164 key.flags=HAM_KEY_USER_ALLOC;
929d4cb @cruppstahl added env test (broken!)
authored
165 key.data=&recno;
166 key.size=sizeof(recno);
167
168 rec.data=&value;
169 rec.size=sizeof(value);
170
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
171 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
172 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
173 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
174 ham_cursor_create(m_db, 0, 0, &cursor));
175
176 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
177 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
178 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
179 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
929d4cb @cruppstahl added env test (broken!)
authored
180 }
181
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
182 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
183 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
184 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
185 ham_open(m_db, BFC_OPATH(".test"), m_flags));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
186 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
187 ham_cursor_create(m_db, 0, 0, &cursor));
188
189 for (int i=5; i<10; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
190 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
191 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
192 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
929d4cb @cruppstahl added env test (broken!)
authored
193 }
194
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
195 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
196 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
929d4cb @cruppstahl added env test (broken!)
authored
197 }
198
b1b5aed @cruppstahl recno unittests
authored
199 void createInsertCloseTest(void)
200 {
201 ham_key_t key;
202 ham_record_t rec;
203 ham_u64_t recno, value=1;
204
205 memset(&key, 0, sizeof(key));
206 memset(&rec, 0, sizeof(rec));
207
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
208 key.flags=HAM_KEY_USER_ALLOC;
b1b5aed @cruppstahl recno unittests
authored
209 key.data=&recno;
210 key.size=sizeof(recno);
211
212 rec.data=&value;
213 rec.size=sizeof(value);
214
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
215 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
216 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
b1b5aed @cruppstahl recno unittests
authored
217
218 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
219 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
220 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
221 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
222 }
223
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
224 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
225 }
226
c95f9ce @cruppstahl new recno tests
authored
227 void createInsertManyCloseTest(void)
228 {
229 ham_key_t key;
230 ham_record_t rec;
231 ham_u64_t recno, value=1;
232
233 memset(&key, 0, sizeof(key));
234 memset(&rec, 0, sizeof(rec));
235
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
236 key.flags=HAM_KEY_USER_ALLOC;
c95f9ce @cruppstahl new recno tests
authored
237 key.data=&recno;
238 key.size=sizeof(recno);
239
240 rec.data=&value;
241 rec.size=sizeof(value);
242
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
243 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
244 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
c95f9ce @cruppstahl new recno tests
authored
245
dbf0766 @cruppstahl added key_set_record
authored
246 for (int i=0; i<500; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
247 BFC_ASSERT_EQUAL(0,
c95f9ce @cruppstahl new recno tests
authored
248 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
249 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
c95f9ce @cruppstahl new recno tests
authored
250 }
251
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
252 key.size=4;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
253 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
254 ham_find(m_db, 0, &key, &rec, 0));
255 key.size=0;
256 key.data=&key;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
257 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
258 ham_find(m_db, 0, &key, &rec, 0));
259
dbf0766 @cruppstahl added key_set_record
authored
260 for (int i=0; i<500; i++) {
261 recno=i+1;
262 memset(&key, 0, sizeof(key));
263 memset(&rec, 0, sizeof(rec));
264 key.data=&recno;
265 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
266 BFC_ASSERT_EQUAL(0,
dbf0766 @cruppstahl added key_set_record
authored
267 ham_find(m_db, 0, &key, &rec, 0));
268 }
269
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
270 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
c95f9ce @cruppstahl new recno tests
authored
271 }
272
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
273 void createInsertCloseCursorTest(void)
274 {
275 ham_key_t key;
276 ham_record_t rec;
277 ham_cursor_t *cursor;
278 ham_u64_t recno, value=1;
279
280 memset(&key, 0, sizeof(key));
281 memset(&rec, 0, sizeof(rec));
282
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
283 key.flags=HAM_KEY_USER_ALLOC;
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
284 key.data=&recno;
285 key.size=sizeof(recno);
286
287 rec.data=&value;
288 rec.size=sizeof(value);
289
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
290 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
291 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
292
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
293 BFC_ASSERT_EQUAL(0,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
294 ham_cursor_create(m_db, 0, 0, &cursor));
295
296 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
297 BFC_ASSERT_EQUAL(0,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
298 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
299 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
300 }
301
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
302 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
303 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
304 }
305
b1b5aed @cruppstahl recno unittests
authored
306 void createInsertCloseReopenTwiceTest(void)
307 {
308 ham_key_t key;
309 ham_record_t rec;
310 ham_u64_t recno, value=1;
311
312 memset(&key, 0, sizeof(key));
313 memset(&rec, 0, sizeof(rec));
314
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
315 key.flags=HAM_KEY_USER_ALLOC;
b1b5aed @cruppstahl recno unittests
authored
316 key.data=&recno;
317 key.size=sizeof(recno);
318
319 rec.data=&value;
320 rec.size=sizeof(value);
321
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
322 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
323 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
b1b5aed @cruppstahl recno unittests
authored
324
325 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
326 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
327 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
328 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
329 }
330
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
331 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
332 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
333 ham_open(m_db, BFC_OPATH(".test"), m_flags));
b1b5aed @cruppstahl recno unittests
authored
334
335 for (int i=5; i<10; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
336 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
337 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
338 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
339 }
340
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
341 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
342 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
343 ham_open(m_db, BFC_OPATH(".test"), m_flags));
b1b5aed @cruppstahl recno unittests
authored
344
345 for (int i=10; i<15; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
346 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
347 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
348 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
b1b5aed @cruppstahl recno unittests
authored
349 }
350
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
351 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
352 }
353
929d4cb @cruppstahl added env test (broken!)
authored
354 void createInsertCloseReopenTwiceCursorTest(void)
355 {
356 ham_key_t key;
357 ham_record_t rec;
358 ham_u64_t recno, value=1;
359 ham_cursor_t *cursor;
360
361 memset(&key, 0, sizeof(key));
362 memset(&rec, 0, sizeof(rec));
363
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
364 key.flags=HAM_KEY_USER_ALLOC;
929d4cb @cruppstahl added env test (broken!)
authored
365 key.data=&recno;
366 key.size=sizeof(recno);
367
368 rec.data=&value;
369 rec.size=sizeof(value);
370
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
371 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
372 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
373 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
374 ham_cursor_create(m_db, 0, 0, &cursor));
375
376 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
377 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
378 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
379 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
929d4cb @cruppstahl added env test (broken!)
authored
380 }
381
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
382 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
383 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
384 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
385 ham_open(m_db, BFC_OPATH(".test"), m_flags));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
386 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
387 ham_cursor_create(m_db, 0, 0, &cursor));
388
389 for (int i=5; i<10; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
390 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
391 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
392 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
929d4cb @cruppstahl added env test (broken!)
authored
393 }
394
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
395 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
396 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
397 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
398 ham_open(m_db, BFC_OPATH(".test"), m_flags));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
399 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
400 ham_cursor_create(m_db, 0, 0, &cursor));
401
402 for (int i=10; i<15; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
403 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
404 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
405 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
929d4cb @cruppstahl added env test (broken!)
authored
406 }
407
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
408 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
409 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
929d4cb @cruppstahl added env test (broken!)
authored
410 }
411
b1b5aed @cruppstahl recno unittests
authored
412 void insertBadKeyTest(void)
413 {
414 ham_key_t key;
415 ham_record_t rec;
416 ham_u64_t recno;
417
418 memset(&key, 0, sizeof(key));
419 memset(&rec, 0, sizeof(rec));
420
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
421 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
422 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
b1b5aed @cruppstahl recno unittests
authored
423
424 key.flags=0;
425 key.data=&recno;
426 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
427 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
b1b5aed @cruppstahl recno unittests
authored
428 ham_insert(m_db, 0, &key, &rec, 0));
429
430 key.data=0;
431 key.size=8;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
432 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
b1b5aed @cruppstahl recno unittests
authored
433 ham_insert(m_db, 0, &key, &rec, 0));
434
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
435 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
b1b5aed @cruppstahl recno unittests
authored
436 ham_insert(m_db, 0, 0, &rec, 0));
437
438 key.data=0;
439 key.size=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
440 BFC_ASSERT_EQUAL(0,
b1b5aed @cruppstahl recno unittests
authored
441 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
442 BFC_ASSERT_EQUAL((ham_u64_t)1ull, *(ham_u64_t *)key.data);
b1b5aed @cruppstahl recno unittests
authored
443
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
444 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
445 }
446
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
447 void insertBadKeyCursorTest(void)
448 {
449 ham_key_t key;
450 ham_record_t rec;
451 ham_cursor_t *cursor;
452 ham_u64_t recno;
453
454 memset(&key, 0, sizeof(key));
455 memset(&rec, 0, sizeof(rec));
456
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
457 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
458 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
459 BFC_ASSERT_EQUAL(0,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
460 ham_cursor_create(m_db, 0, 0, &cursor));
461
462 key.flags=0;
463 key.data=&recno;
464 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
465 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
466 ham_cursor_insert(cursor, &key, &rec, 0));
467
468 key.data=0;
469 key.size=8;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
470 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
471 ham_cursor_insert(cursor, &key, &rec, 0));
472
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
473 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
474 ham_cursor_insert(cursor, 0, &rec, 0));
475
476 key.data=0;
477 key.size=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
478 BFC_ASSERT_EQUAL(0,
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
479 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
480 BFC_ASSERT_EQUAL((ham_u64_t)1ull, *(ham_u64_t *)key.data);
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
481
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
482 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
483 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
4a394b0 @cruppstahl new unittests for recno w/ cursors
authored
484 }
485
b1b5aed @cruppstahl recno unittests
authored
486 void createBadKeysizeTest(void)
487 {
488 ham_parameter_t p[]={
489 {HAM_PARAM_KEYSIZE, 7},
490 {0, 0}
491 };
492
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
493 BFC_ASSERT_EQUAL(HAM_INV_KEYSIZE,
78e61dc @cruppstahl fixed all valgrind warnings about uninitialized memory accesses
authored
494 ham_create_ex(m_db, BFC_OPATH(".test"),
495 m_flags|HAM_RECORD_NUMBER, 0664, &p[0]));
b1b5aed @cruppstahl recno unittests
authored
496
497 p[0].value=9;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
498 BFC_ASSERT_EQUAL(0,
78e61dc @cruppstahl fixed all valgrind warnings about uninitialized memory accesses
authored
499 ham_create_ex(m_db, BFC_OPATH(".test"),
500 m_flags|HAM_RECORD_NUMBER, 0664, &p[0]));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
501 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
b1b5aed @cruppstahl recno unittests
authored
502 }
929d4cb @cruppstahl added env test (broken!)
authored
503
504 void envTest(void)
505 {
506 ham_env_t *env;
507 ham_key_t key;
508 ham_record_t rec;
c95f9ce @cruppstahl new recno tests
authored
509 ham_u64_t recno;
929d4cb @cruppstahl added env test (broken!)
authored
510
511 memset(&key, 0, sizeof(key));
512 memset(&rec, 0, sizeof(rec));
c95f9ce @cruppstahl new recno tests
authored
513 key.data=&recno;
514 key.size=sizeof(recno);
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
515 key.flags=HAM_KEY_USER_ALLOC;
929d4cb @cruppstahl added env test (broken!)
authored
516
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
517 BFC_ASSERT_EQUAL(0, ham_env_new(&env));
518 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
519 ham_env_create(env, BFC_OPATH(".test"), m_flags, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
520 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
521 ham_env_create_db(env, m_db, 333, HAM_RECORD_NUMBER, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
522 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
523 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
524 BFC_ASSERT_EQUAL((ham_u64_t)1ull, *(ham_u64_t *)key.data);
525 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
526 BFC_ASSERT_EQUAL(0, ham_env_close(env, 0));
929d4cb @cruppstahl added env test (broken!)
authored
527
528 if (!(m_flags&HAM_IN_MEMORY_DB)) {
2319df2 @cruppstahl all tests are working now
authored
529 BFC_ASSERT_EQUAL(0, ham_env_open(env, BFC_OPATH(".test"), 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
530 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
531 ham_env_open_db(env, m_db, 333, HAM_RECORD_NUMBER, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
532 BFC_ASSERT_EQUAL(0,
929d4cb @cruppstahl added env test (broken!)
authored
533 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
534 BFC_ASSERT_EQUAL((ham_u64_t)2ull, *(ham_u64_t *)key.data);
535 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
536 BFC_ASSERT_EQUAL(0, ham_env_close(env, 0));
929d4cb @cruppstahl added env test (broken!)
authored
537 }
538
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
539 BFC_ASSERT_EQUAL(0, ham_env_delete(env));
929d4cb @cruppstahl added env test (broken!)
authored
540 }
663313f @cruppstahl new unittest: endian-converted recno's
authored
541
542 void endianTestOpenDatabase(void)
543 {
75392bf @cruppstahl legacy format of hamsterdb 1.0.9 and older is no longer supported
authored
544 // i currently don't have access to a big-endian machine, and the existing
545 // files were created with a database < 1.0.9 and are no longer supported
546 #if 0
663313f @cruppstahl new unittest: endian-converted recno's
authored
547 ham_key_t key;
548 ham_record_t rec;
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
549 ham_offset_t recno=100;
3779106 @cruppstahl enhanced recno-unittests
authored
550 ham_cursor_t *cursor;
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
551
1eb7909 @cruppstahl unit tests no longer modify big/little endian samples
authored
552 /* generated with `cat ../COPYING.GPL2 | ./db4`; has 2973 entries */
c72c72c @cruppstahl using different fixture as base class
authored
553 #if defined(HAM_LITTLE_ENDIAN)
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
554 BFC_ASSERT_EQUAL(true,
75392bf @cruppstahl legacy format of hamsterdb 1.0.9 and older is no longer supported
authored
555 os::copy("data/recno-endian-test-open-database-be.hdb",
556 BFC_OPATH(".test")));
663313f @cruppstahl new unittest: endian-converted recno's
authored
557 #else
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
558 BFC_ASSERT_EQUAL(true,
75392bf @cruppstahl legacy format of hamsterdb 1.0.9 and older is no longer supported
authored
559 os::copy("data/recno-endian-test-open-database-le.hdb",
560 BFC_OPATH(".test")));
663313f @cruppstahl new unittest: endian-converted recno's
authored
561 #endif
2319df2 @cruppstahl all tests are working now
authored
562 BFC_ASSERT_EQUAL(0, ham_open(m_db, BFC_OPATH(".test"), 0));
663313f @cruppstahl new unittest: endian-converted recno's
authored
563
75392bf @cruppstahl legacy format of hamsterdb 1.0.9 and older is no longer supported
authored
564 BFC_ASSERT_EQUAL(0, ham_cursor_create(m_db, 0, 0, &cursor));
3779106 @cruppstahl enhanced recno-unittests
authored
565
663313f @cruppstahl new unittest: endian-converted recno's
authored
566 ::memset(&key, 0, sizeof(key));
567 ::memset(&rec, 0, sizeof(rec));
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
568 key.data=(void *)&recno;
569 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
570 BFC_ASSERT_EQUAL(0,
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
571 ham_find(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
572 BFC_ASSERT_EQUAL(0, strcmp("the", (char *)rec.data));
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
573
3779106 @cruppstahl enhanced recno-unittests
authored
574 ::memset(&rec, 0, sizeof(rec));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
575 BFC_ASSERT_EQUAL(0,
3779106 @cruppstahl enhanced recno-unittests
authored
576 ham_cursor_find(cursor, &key, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
577 BFC_ASSERT_EQUAL(0,
3779106 @cruppstahl enhanced recno-unittests
authored
578 ham_cursor_move(cursor, 0, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
579 BFC_ASSERT_EQUAL(0, strcmp("the", (char *)rec.data));
3779106 @cruppstahl enhanced recno-unittests
authored
580
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
581 BFC_ASSERT_EQUAL(0, ham_cursor_erase(cursor, 0));
582 BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
3779106 @cruppstahl enhanced recno-unittests
authored
583 ham_find(m_db, 0, &key, &rec, 0));
584
5aa72a7 @cruppstahl fixed big endian-issues in recno databases
authored
585 ::memset(&key, 0, sizeof(key));
586 ::memset(&rec, 0, sizeof(rec));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
587 BFC_ASSERT_EQUAL(0,
663313f @cruppstahl new unittest: endian-converted recno's
authored
588 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
589 BFC_ASSERT_EQUAL((ham_u64_t)2974ull, *(ham_u64_t *)key.data);
2f6692a @cruppstahl git-svn-id: svn+ssh://hamsterdb.com/home/chris/repos/hamsterdb/trunk@543...
authored
590
3779106 @cruppstahl enhanced recno-unittests
authored
591 ::memset(&key, 0, sizeof(key));
592 ::memset(&rec, 0, sizeof(rec));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
593 BFC_ASSERT_EQUAL(0,
3779106 @cruppstahl enhanced recno-unittests
authored
594 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
595 BFC_ASSERT_EQUAL((ham_u64_t)2975ull, *(ham_u64_t *)key.data);
3779106 @cruppstahl enhanced recno-unittests
authored
596
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
597 BFC_ASSERT_EQUAL(0,
2f6692a @cruppstahl git-svn-id: svn+ssh://hamsterdb.com/home/chris/repos/hamsterdb/trunk@543...
authored
598 ham_erase(m_db, 0, &key, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
599 BFC_ASSERT_EQUAL(HAM_KEY_NOT_FOUND,
3779106 @cruppstahl enhanced recno-unittests
authored
600 ham_find(m_db, 0, &key, &rec, 0));
663313f @cruppstahl new unittest: endian-converted recno's
authored
601
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
602 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
603 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
75392bf @cruppstahl legacy format of hamsterdb 1.0.9 and older is no longer supported
authored
604 #endif
663313f @cruppstahl new unittest: endian-converted recno's
authored
605 }
e6f9580 @cruppstahl added test for overwriting recno keys
authored
606
607 void overwriteTest(void)
608 {
609 ham_key_t key;
610 ham_record_t rec;
efd3115 @cruppstahl fixed recno issues on big endian
authored
611 ham_u64_t recno, value;
e6f9580 @cruppstahl added test for overwriting recno keys
authored
612
613 memset(&key, 0, sizeof(key));
614 memset(&rec, 0, sizeof(rec));
615
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
616 BFC_ASSERT_EQUAL(0,
90bfd4f @cruppstahl many refactorings and beautifications; unittests are broken - progress i...
authored
617 ham_create(m_db, BFC_OPATH(".test"),
618 m_flags|HAM_RECORD_NUMBER, 0664));
e6f9580 @cruppstahl added test for overwriting recno keys
authored
619
620 key.data=&recno;
621 key.flags=HAM_KEY_USER_ALLOC;
622 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
623 BFC_ASSERT_EQUAL(0, ham_insert(m_db, 0, &key, &rec, 0));
e6f9580 @cruppstahl added test for overwriting recno keys
authored
624
efd3115 @cruppstahl fixed recno issues on big endian
authored
625 value=0x13ull;
e6f9580 @cruppstahl added test for overwriting recno keys
authored
626 memset(&rec, 0, sizeof(rec));
efd3115 @cruppstahl fixed recno issues on big endian
authored
627 rec.data=&value;
628 rec.size=sizeof(value);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
629 BFC_ASSERT_EQUAL(0, ham_insert(m_db, 0, &key, &rec, HAM_OVERWRITE));
e6f9580 @cruppstahl added test for overwriting recno keys
authored
630
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
631 key.size=4;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
632 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
633 ham_insert(m_db, 0, &key, &rec, HAM_OVERWRITE));
634 key.size=8;
635 key.data=0;
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
636 BFC_ASSERT_EQUAL(HAM_INV_PARAMETER,
8ae279a @cruppstahl more unittests, mainly for routines in hamsterdb.c
authored
637 ham_insert(m_db, 0, &key, &rec, HAM_OVERWRITE));
638 key.data=&recno;
639
e6f9580 @cruppstahl added test for overwriting recno keys
authored
640 memset(&rec, 0, sizeof(rec));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
641 BFC_ASSERT_EQUAL(0, ham_find(m_db, 0, &key, &rec, 0));
e6f9580 @cruppstahl added test for overwriting recno keys
authored
642
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
643 BFC_ASSERT_EQUAL(value, *(ham_u64_t *)rec.data);
e6f9580 @cruppstahl added test for overwriting recno keys
authored
644
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
645 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
e6f9580 @cruppstahl added test for overwriting recno keys
authored
646 }
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
647
648 void overwriteCursorTest(void)
649 {
650 ham_key_t key;
651 ham_record_t rec;
bebd4aa @cruppstahl fixed bigendian issues
authored
652 ham_u64_t recno, value;
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
653 ham_cursor_t *cursor;
654
655 memset(&key, 0, sizeof(key));
656 memset(&rec, 0, sizeof(rec));
657
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
658 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
659 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
660 BFC_ASSERT_EQUAL(0,
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
661 ham_cursor_create(m_db, 0, 0, &cursor));
662
663 key.data=&recno;
664 key.flags=HAM_KEY_USER_ALLOC;
665 key.size=sizeof(recno);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
666 BFC_ASSERT_EQUAL(0, ham_cursor_insert(cursor, &key, &rec, 0));
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
667
bebd4aa @cruppstahl fixed bigendian issues
authored
668 value=0x13ull;
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
669 memset(&rec, 0, sizeof(rec));
bebd4aa @cruppstahl fixed bigendian issues
authored
670 rec.data=&value;
671 rec.size=sizeof(value);
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
672 BFC_ASSERT_EQUAL(0,
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
673 ham_cursor_insert(cursor, &key, &rec, HAM_OVERWRITE));
674
675 memset(&rec, 0, sizeof(rec));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
676 BFC_ASSERT_EQUAL(0, ham_find(m_db, 0, &key, &rec, 0));
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
677
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
678 BFC_ASSERT_EQUAL(value, *(ham_u64_t *)rec.data);
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
679
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
680 BFC_ASSERT_EQUAL(0, ham_cursor_close(cursor));
681 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
f846603 @cruppstahl duplicate cursors are implemented; some functions are not yet tested
authored
682 }
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
683
684 void eraseLastReopenTest(void)
685 {
686 ham_key_t key;
687 ham_record_t rec;
688 ham_u64_t recno;
689
690 memset(&key, 0, sizeof(key));
691 memset(&rec, 0, sizeof(rec));
692
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
693 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
694 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
695
696 key.data=&recno;
697 key.flags=HAM_KEY_USER_ALLOC;
698 key.size=sizeof(recno);
699
700 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
701 BFC_ASSERT_EQUAL(0,
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
702 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
703 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
704 }
705
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
706 BFC_ASSERT_EQUAL(0, ham_erase(m_db, 0, &key, 0));
707 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
2319df2 @cruppstahl all tests are working now
authored
708 BFC_ASSERT_EQUAL(0, ham_open(m_db, BFC_OPATH(".test"), m_flags));
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
709
710 for (int i=5; i<10; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
711 BFC_ASSERT_EQUAL(0,
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
712 ham_insert(m_db, 0, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
713 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
714 }
715
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
716 BFC_ASSERT_EQUAL(0, ham_close(m_db, 0));
80d034f @cruppstahl don't reuse deleted recnos after a reopen
authored
717 }
9309ce3 @cruppstahl refactoring/review of util.c
authored
718
719 void uncoupleTest(void)
720 {
721 ham_key_t key;
722 ham_record_t rec;
723 ham_u64_t recno;
724 ham_cursor_t *cursor, *c2;
725
726 memset(&key, 0, sizeof(key));
727 memset(&rec, 0, sizeof(rec));
728
43f98e3 @cruppstahl most of Ger's stuff is now merged
authored
729 key.flags=HAM_KEY_USER_ALLOC;
9309ce3 @cruppstahl refactoring/review of util.c
authored
730 key.data=&recno;
731 key.size=sizeof(recno);
732
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
733 BFC_ASSERT_EQUAL(0,
2319df2 @cruppstahl all tests are working now
authored
734 ham_create(m_db, BFC_OPATH(".test"), m_flags|HAM_RECORD_NUMBER, 0664));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
735 BFC_ASSERT_EQUAL(0,
9309ce3 @cruppstahl refactoring/review of util.c
authored
736 ham_cursor_create(m_db, 0, 0, &cursor));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
737 BFC_ASSERT_EQUAL(0,
9309ce3 @cruppstahl refactoring/review of util.c
authored
738 ham_cursor_create(m_db, 0, 0, &c2));
739
740 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
741 BFC_ASSERT_EQUAL(0,
9309ce3 @cruppstahl refactoring/review of util.c
authored
742 ham_cursor_insert(cursor, &key, &rec, 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
743 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
9309ce3 @cruppstahl refactoring/review of util.c
authored
744 }
745
c3d8264 @cruppstahl Backend is now C++-ified
authored
746 BtreeBackend *be=(BtreeBackend *)((Database *)m_db)->get_backend();
42568a2 @cruppstahl ham_page_t is now c++-ified (WIP)
authored
747 Page *page;
dbd7802 @cruppstahl ham_db_t is now C++-ified (WIP)
authored
748 BFC_ASSERT_EQUAL(0, db_fetch_page(&page, (Database *)m_db,
c3d8264 @cruppstahl Backend is now C++-ified
authored
749 be->get_rootpage(), 0));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
750 BFC_ASSERT(page!=0);
6bed4c8 @cruppstahl the Page class is now fully C++-ified
authored
751 BFC_ASSERT_EQUAL(0, page->uncouple_all_cursors());
9309ce3 @cruppstahl refactoring/review of util.c
authored
752
753 for (int i=0; i<5; i++) {
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
754 BFC_ASSERT_EQUAL(0,
9309ce3 @cruppstahl refactoring/review of util.c
authored
755 ham_cursor_move(c2, &key, &rec, HAM_CURSOR_NEXT));
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
756 BFC_ASSERT_EQUAL((ham_u64_t)i+1, recno);
9309ce3 @cruppstahl refactoring/review of util.c
authored
757 }
758
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
759 BFC_ASSERT_EQUAL(0, ham_close(m_db, HAM_AUTO_CLEANUP));
9309ce3 @cruppstahl refactoring/review of util.c
authored
760 }
b1b5aed @cruppstahl recno unittests
authored
761 };
762
763 class InMemoryRecNoTest : public RecNoTest
764 {
765 public:
766 InMemoryRecNoTest()
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
767 : RecNoTest(HAM_IN_MEMORY_DB, "InMemoryRecNoTest")
b1b5aed @cruppstahl recno unittests
authored
768 {
c72c72c @cruppstahl using different fixture as base class
authored
769 clear_tests(); // don't inherit tests
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
770 testrunner::get_instance()->register_fixture(this);
771 BFC_REGISTER_TEST(InMemoryRecNoTest, createCloseTest);
772 BFC_REGISTER_TEST(InMemoryRecNoTest, createInsertCloseTest);
773 BFC_REGISTER_TEST(InMemoryRecNoTest, createInsertManyCloseTest);
774 BFC_REGISTER_TEST(InMemoryRecNoTest, createInsertCloseCursorTest);
775 BFC_REGISTER_TEST(InMemoryRecNoTest, insertBadKeyTest);
776 BFC_REGISTER_TEST(InMemoryRecNoTest, insertBadKeyCursorTest);
777 BFC_REGISTER_TEST(InMemoryRecNoTest, createBadKeysizeTest);
778 BFC_REGISTER_TEST(InMemoryRecNoTest, envTest);
779 BFC_REGISTER_TEST(InMemoryRecNoTest, overwriteTest);
780 BFC_REGISTER_TEST(InMemoryRecNoTest, overwriteCursorTest);
781 BFC_REGISTER_TEST(InMemoryRecNoTest, uncoupleTest);
b1b5aed @cruppstahl recno unittests
authored
782 }
783
784 };
785
a149d67 @cruppstahl first half of the tests is converted to bfc
authored
786 BFC_REGISTER_FIXTURE(RecNoTest);
787 BFC_REGISTER_FIXTURE(InMemoryRecNoTest);
Something went wrong with that request. Please try again.