aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c73
1 files changed, 54 insertions, 19 deletions
diff --git a/test.c b/test.c
index 96a4527..f7e821a 100644
--- a/test.c
+++ b/test.c
@@ -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;
}