You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

11 years ago
#include "../src/common.h"
11 years ago
#include "../src/database.h"
int main() {
simdb_t *db;
simdb_rec_t rec[2];
simdb_block_t blk;
11 years ago
char *path = "test.db";
8 years ago
int mode = 0, err = 0, num;
bool ret;
11 years ago
unlink(path);
8 years ago
db = simdb_open(path, mode, &err);
8 years ago
assert(db == NULL);
assert(err == -1); /* no such file */
ret = simdb_create(path);
8 years ago
assert(ret == true);
db = simdb_open(path, mode, &err);
8 years ago
assert(db != NULL);
11 years ago
rec[0].num = 1;
err = simdb_read_rec(db, rec);
assert(err == SIMDB_ERR_NXRECORD);
11 years ago
memset(rec[0].data, 0xAA, SIMDB_REC_LEN);
8 years ago
memset(rec[0].data, 0xFF, 1); /* record is used */
num = simdb_write_rec(db, rec);
assert(num == SIMDB_ERR_READONLY); /* database open in read-only mode */
8 years ago
simdb_close(db);
8 years ago
mode |= SIMDB_FLAG_WRITE;
db = simdb_open(path, mode, &err);
8 years ago
assert(db != NULL);
num = simdb_write_rec(db, rec);
8 years ago
assert(num == 1); /* success */
11 years ago
num = simdb_read_rec(db, rec);
8 years ago
assert(num == 1);
11 years ago
11 years ago
blk.start = 1;
blk.records = 2;
blk.data = NULL;
num = simdb_read_blk(db, &blk);
8 years ago
assert(num == 1);
11 years ago
assert(blk.records == 1);
assert(blk.data != NULL);
11 years ago
rec[0].num = 1;
rec[1].num = 3;
simdb_close(db);
11 years ago
return 0;
}