Browse Source

* add tests for record's packed struct

master
Alex 'AdUser' Z 8 years ago
parent
commit
b1c2f72242
  1. 3
      tests/CMakeLists.txt
  2. 38
      tests/record.c

3
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")

38
tests/record.c

@ -0,0 +1,38 @@
#include "../src/common.h"
#include "../src/simdb.h"
#include "../src/record.h"
#include <arpa/inet.h> /* 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;
}
Loading…
Cancel
Save