Skip to content
Snippets Groups Projects
Commit 6e087ac7 authored by Meredith L. Patterson's avatar Meredith L. Patterson
Browse files

Test harness macros extended. Need to implement bodies of primitive parsers.

parent 990a19e1
No related branches found
No related tags found
No related merge requests found
...@@ -441,10 +441,10 @@ parse_result_t* parse(const parser_t* parser, const uint8_t* input, size_t lengt ...@@ -441,10 +441,10 @@ parse_result_t* parse(const parser_t* parser, const uint8_t* input, size_t lengt
#include "test_suite.h" #include "test_suite.h"
static void test_token(void) { static void test_token(void) {
//uint8_t test[3] = { '9', '5', 0xa2 }; uint8_t test[3] = { '9', '5', 0xa2 };
//const parser_t *token_ = token(test , 3); const parser_t *token_ = token(test , 3);
//parse_result_t *ret = parse(token_, test, 3); parse_result_t *ret = parse(token_, test, 3);
// need a g_check_cmpstr function for this :P g_check_bytes((ret->ast)[0].bytes.len, (ret->ast)[0].bytes.token, ==, test);
} }
static void test_ch(void) { static void test_ch(void) {
...@@ -465,28 +465,28 @@ static void test_int64(void) { ...@@ -465,28 +465,28 @@ static void test_int64(void) {
uint8_t test[8] = { 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00 }; uint8_t test[8] = { 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00 };
const parser_t *int64_ = int64(); const parser_t *int64_ = int64();
parse_result_t *ret = parse(int64_, test, 8); parse_result_t *ret = parse(int64_, test, 8);
g_check_cmpint((long long int)(ret->ast)[0].sint, ==, -8589934592L); g_check_cmplong((ret->ast)[0].sint, ==, -8589934592L);
} }
static void test_int32(void) { static void test_int32(void) {
uint8_t test[4] = { 0xff, 0xfe, 0x00, 0x00 }; uint8_t test[4] = { 0xff, 0xfe, 0x00, 0x00 };
const parser_t *int32_ = int32(); const parser_t *int32_ = int32();
parse_result_t *ret = parse(int32_, test, 4); parse_result_t *ret = parse(int32_, test, 4);
g_check_cmpint((long long int)(ret->ast)[0].sint, ==, -131072); g_check_cmpint((ret->ast)[0].sint, ==, -131072);
} }
static void test_int16(void) { static void test_int16(void) {
uint8_t test[2] = { 0xfe, 0x00 }; uint8_t test[2] = { 0xfe, 0x00 };
const parser_t *int16_ = int16(); const parser_t *int16_ = int16();
parse_result_t *ret = parse(int16_, test, 2); parse_result_t *ret = parse(int16_, test, 2);
g_check_cmpint((long long int)(ret->ast)[0].sint, ==, -512); g_check_cmpint((ret->ast)[0].sint, ==, -512);
} }
static void test_int8(void) { static void test_int8(void) {
uint8_t test[1] = { 0x88 }; uint8_t test[1] = { 0x88 };
const parser_t *int8_ = int8(); const parser_t *int8_ = int8();
parse_result_t *ret = parse(int8_, test, 1); parse_result_t *ret = parse(int8_, test, 1);
g_check_cmpint((long long int)(ret->ast)[0].sint, ==, -120); g_check_cmpint((ret->ast)[0].sint, ==, -120);
} }
static void test_uint64(void) { static void test_uint64(void) {
......
...@@ -2,16 +2,33 @@ ...@@ -2,16 +2,33 @@
#define HAMMER_TEST_SUITE__H #define HAMMER_TEST_SUITE__H
// Equivalent to g_assert_*, but not using g_assert... // Equivalent to g_assert_*, but not using g_assert...
#define g_check_cmpint(n1, op, n2) { \ #define g_check_inttype(fmt, typ, n1, op, n2) { \
typeof (n1) _n1 = (n1); \ typ _n1 = (n1); \
typeof (n2) _n2 = (n2); \ typ _n2 = (n2); \
if (!(_n1 op _n2)) { \ if (!(_n1 op _n2)) { \
g_test_message("Check failed: (%s): (%lld %s %d)", \ g_test_message("Check failed: (%s): (" fmt " %s " fmt ")", \
#n1 " " #op " " #n2, \ #n1 " " #op " " #n2, \
_n1, #op, _n2); \ _n1, #op, _n2); \
g_test_fail(); \ g_test_fail(); \
} \ } \
} }
#define g_check_bytes(len, n1, op, n2) { \
const uint8_t *_n1 = (n1); \
uint8_t *_n2 = (n2); \
if (!(memcmp(_n1, _n2, len) op 0)) { \
g_test_message("Check failed: (%s)", \
#n1 " " #op " " #n2); \
g_test_fail(); \
} \
}
#define g_check_cmpint(n1, op, n2) g_check_inttype("%d", int, n1, op, n2)
#define g_check_cmplong(n1, op, n2) g_check_inttype("%ld", long, n1, op, n2)
#define g_check_cmplonglong(n1, op, n2) g_check_inttype("%lld", long long, n1, op, n2)
#define g_check_cmpuint(n1, op, n2) g_check_inttype("%u", unsigned int, n1, op, n2)
#define g_check_cmpulong(n1, op, n2) g_check_inttype("%lu", unsigned long, n1, op, n2)
#define g_check_cmpulonglong(n1, op, n2) g_check_inttype("%llu", unsigned long long, n1, op, n2)
#endif // #ifndef HAMMER_TEST_SUITE__H #endif // #ifndef HAMMER_TEST_SUITE__H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment