diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-04-10 21:23:08 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-04-10 21:23:08 +0300 |
commit | e60275a234a625b3982b9744b5e9aefa2c1f7211 (patch) | |
tree | fad0c1492c8bec4e13506edf9f47301152de0822 /test.c | |
parent | 844b90ec6b79be309d0bd3d08df36b78d48eee90 (diff) |
testing changes
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 73 |
1 files changed, 54 insertions, 19 deletions
@@ -46,6 +46,7 @@ static int passed_test_counter; static int failed_test_counter; static int failed_asserts; +int test_internal(); int test_bool(); int test_int(); @@ -62,6 +63,7 @@ int test_int(); int main(void) { + TEST(test_internal()); TEST(test_bool()); TEST(test_int()); @@ -74,11 +76,23 @@ int main(void) return 0; } -#define BODY_SUCCESS_1(type) \ +int test_internal() +{ + return 0; +} + +#define BODY_SUCCESS_1(t, type) \ { \ assert(t == type, \ logvar(t, msgpack_type_string[t], "%s")); \ } + +#define BODY_SUCCESS_2(t, a, type, subtype) \ + { \ + BODY_SUCCESS_1(t, type); \ + assert(a == subtype, \ + logvar(a, msgpack_type_string[a], "%s")); \ + } #define BODY_FAILED_1(t, e, a) \ { \ @@ -94,24 +108,24 @@ int main(void) void bool_1(uint8_t *buf, size_t size, bool value) { - uint8_t b[1]; + uint8_t b[1] = {0}; bool v; MSGPACK_CHECK2(msgpack_read_bool(&msgpack_init(buf, size, NULL), &v), - (t, e, a), BODY_SUCCESS_1(MSGPACK_BOOL), BODY_FAILED_1(t, e, a)); + (t, e, a), BODY_SUCCESS_1(t, MSGPACK_BOOL), BODY_FAILED_1(t, e, a)); assert(v == value, logvar(v, "%d")); - + MSGPACK_CHECK2(msgpack_write_bool(&msgpack_init(b, size, NULL), &value), - (t, e, a), BODY_SUCCESS_1(MSGPACK_BOOL), BODY_FAILED_1(t, e, a)); + (t, e, a), BODY_SUCCESS_1(t, MSGPACK_BOOL), BODY_FAILED_1(t, e, a)); assert(memcmp(buf, b, size) == 0, logbytes(b, size)); } -#define bool_template(n, _buf, _value) \ - make_template(bool_##n(_buf, sizeof(_buf), _value), { \ - logbytes(buf, _buf, sizeof(_buf)); \ - logvar(value, _value, "%d"); \ - printf("\n"); \ - }); \ +#define bool_template(n, _buf, _value) \ + make_template(bool_##n((_buf), sizeof(_buf), (_value)), { \ + logbytes(buf, (_buf), sizeof(_buf)); \ + logvar(value, (_value), "%d"); \ + printf("\n"); \ + }); \ int test_bool() { @@ -123,19 +137,40 @@ int test_bool() return failed_asserts; } -#define int_template(n, _buf, _value) \ - make_template(bool_##n(_buf, sizeof(_buf), _value), { \ - logbytes(buf, _buf, sizeof(_buf)); \ - logvar(value, _value, "%d"); \ - printf("\n"); \ - }); \ +void int_1(uint8_t *buf, size_t size, union mp_int value, enum msgpack_type subtype) +{ + uint8_t b[9] = {0}; + union mp_int v; + + MSGPACK_CHECK2(msgpack_read_int(&msgpack_init(buf, size, NULL), &v), + (t, e, a), BODY_SUCCESS_2(t, a, MSGPACK_INT, subtype), + BODY_FAILED_1(t, e, a)); + assert(v.i == value.i, logvar(v.u, "%lld")); + + MSGPACK_CHECK2(msgpack_write_int(&msgpack_init(b, size, NULL), &value, subtype), + (t, e, a), BODY_SUCCESS_2(t, a, MSGPACK_INT, subtype), + BODY_FAILED_1(t, e, a)); + assert(memcmp(buf, b, size) == 0, logbytes(b, size)); +} + +#define int_template(n, _buf, _value, _subtype) \ + make_template(int_##n((_buf), sizeof(_buf), (_value), (_subtype)), { \ + logbytes(buf, (_buf), sizeof(_buf)); \ + if((_subtype) == MSGPACK_INT_SIGNED) \ + logvar(value.i, (_value).i, "%lld"); \ + else logvar(value.u, (_value).u, "%lld"); \ + logvar(subtype, msgpack_type_string[(_subtype)], "%s"); \ + printf("\n"); \ + }); \ int test_int() { failed_asserts = 0; - // char buf[] = {0xD3, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01}; - // char buf[] = {0xCC, 0xFF}; + int_template(1, ((uint8_t []){0xD3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01}), + ((union mp_int){.i=0x0100000000000201}), MSGPACK_INT_SIGNED); + int_template(1, ((uint8_t []){0xFF}), + ((union mp_int){.i=-1}), MSGPACK_INT_SIGNED); return failed_asserts; } |