aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2025-04-19 01:01:46 +0300
committerkartofen <mladenovnasko0@gmail.com>2025-04-19 01:01:46 +0300
commit81b8e14fd785141193c62bcd0023815b2a6cb810 (patch)
tree5872f8bb3688d1c0aeaef5856720bd1faeac92e1 /test.c
parent25792c81d9e4c1667ca6bcac28ae7b49afff90a1 (diff)
change unit conversions and writing as raw
Diffstat (limited to 'test.c')
-rw-r--r--test.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/test.c b/test.c
index 4ee5298..6b405dd 100644
--- a/test.c
+++ b/test.c
@@ -140,7 +140,7 @@ int main(void)
logvar(e, msgpack_error_string[e], "%s"); \
if(e == MSGPACK_ERROR_WRONG_TYPE) \
logvar(a, msgpack_type_string[a], "%s"); \
- else logvar(a, "%hhx"); \
+ else logvar(a, "0x%hhx"); \
return; \
}
@@ -303,18 +303,25 @@ int test_float()
return failed_asserts;
}
-void raw_1(uint8_t *bin, size_t size, struct mp_bin b)
+void raw_1(uint8_t *bin, size_t size, struct mp_bin r)
{
- msgpack_t pack = msgpack_init(bin, size, NULL);
+ uint8_t b[64] = {0};
struct mp_bin v = {0};
- MSGPACK_CHECK2(msgpack_read_raw(&pack, &v), (t, e, a),
+ MSGPACK_CHECK2(msgpack_read_raw(&msgpack_init(bin, size, NULL), &v),
+ (t, e, a),
BODY_SUCCESS_2(t, a, MSGPACK_RAW, MSGPACK_RAW_STRING),
BODY_FAILED_1(t, e, a));
- assert(v.size == b.size, logvar(v.size, "%z"));
- assert(memcmp(v.bin, b.bin, v.size) == 0, logbytes(v.bin, v.size));
+ assert(v.size == r.size, logvar(v.size, "%zu"));
+ assert(memcmp(v.bin, r.bin, v.size) == 0, logbytes(v.bin, v.size));
+ MSGPACK_CHECK2(msgpack_write_raw(&msgpack_init(b, sizeof(b), NULL), &r, MSGPACK_RAW_STRING),
+ (t, e, a),
+ BODY_SUCCESS_2(t, a, MSGPACK_RAW, MSGPACK_RAW_STRING),
+ BODY_FAILED_1(t, e, a));
+
+ assert(memcmp(b, bin, size) == 0, logbytes(b, size));
}
int test_raw()
@@ -322,8 +329,8 @@ int test_raw()
failed_asserts = 0;
check_condition(raw_1("\xa5hello", 6,
(struct mp_bin){.size = 5, .bin = "hello"}), );
- check_condition(raw_1("\xd9\x05hello", 7,
- (struct mp_bin){.size = 5, .bin = "hello"}), );
+ check_condition(raw_1("\xd9\x24hello_______________________________", 38,
+ (struct mp_bin){.size = 36, .bin = "hello_______________________________"}), );
return failed_asserts;
}