diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 38aa62a..33ec4b3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,8 @@ add_executable("test-bitmap" "bitmap.c" "../src/bitmap.c") add_test("test/bitmap" "test-bitmap") +add_executable("test-record" "record.c") +add_test("test/record" "test-record") + add_executable("test-database" "database.c" "../src/database.c" "../src/bitmap.c") add_test("test/database" "test-database") diff --git a/tests/record.c b/tests/record.c new file mode 100644 index 0000000..ca2c3bf --- /dev/null +++ b/tests/record.c @@ -0,0 +1,38 @@ +#include "../src/common.h" +#include "../src/simdb.h" +#include "../src/record.h" + +#include /* htons */ + +int +main() { + simdb_urec_t r; + + memset(&r, 0x0, sizeof(r)); + + assert(sizeof(r) == SIMDB_REC_LEN); + + r.used = 0xFF; + r.clevel_r = 0x52; /* 'R' */ + r.clevel_g = 0x47; /* 'G' */ + r.clevel_b = 0x42; /* 'B' */ + r.image_w = htons(1024); + r.image_h = htons(768); + memset(r.bitmap, 0xA5, sizeof(r.bitmap)); + + /* note: htons() used here only for portability, * + * in real database it's not used */ + + unsigned char bytes[SIMDB_REC_LEN] = { + 0xFF, 0x52, 0x47, 0x42, 0x04, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, + 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, + 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, + 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, + }; + + assert(memcmp(&r, bytes, sizeof(r)) == 0); + + return 0; +}