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.

62 lines
1.1 KiB

11 years ago
#include "../src/common.h"
11 years ago
#include "../src/database.h"
9 years ago
int main()
11 years ago
{
8 years ago
imdb_db_t *db;
imdb_rec_t rec[2];
9 years ago
imdb_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 = imdb_open(path, mode, &err);
assert(db == NULL);
assert(err == -1); /* no such file */
ret = imdb_create(path);
assert(ret == true);
db = imdb_open(path, mode, &err);
assert(db != NULL);
11 years ago
rec[0].num = 1;
8 years ago
err = imdb_read_rec(db, rec);
assert(err == 0); /* no such record */
11 years ago
10 years ago
memset(rec[0].data, 0xAA, IMDB_REC_LEN);
8 years ago
memset(rec[0].data, 0xFF, 1); /* record is used */
num = imdb_write_rec(db, rec);
assert(num != 1); /* database open in read-only mode */
imdb_close(db);
mode |= IMDB_FLAG_WRITE;
db = imdb_open(path, mode, &err);
assert(db != NULL);
num = imdb_write_rec(db, rec);
assert(num == 1); /* success */
11 years ago
8 years ago
num = imdb_read_rec(db, rec);
assert(num == 1);
11 years ago
11 years ago
blk.start = 1;
blk.records = 2;
blk.data = NULL;
8 years ago
num = imdb_read_blk(db, &blk);
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;
8 years ago
imdb_close(db);
11 years ago
return 0;
}