Skip to content
Snippets Groups Projects
Commit 7b13a828 authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

add __m variants to some check macros

parent db4fd66e
No related branches found
No related tags found
No related merge requests found
...@@ -78,14 +78,14 @@ ...@@ -78,14 +78,14 @@
} while(0) } while(0)
#define g_check_parse_failed(parser, backend, input, inp_len) do { \ #define g_check_parse_failed__m(mm__, parser, backend, input, inp_len) do { \
int skip = h_compile((HParser *)(parser), (HParserBackend)backend, NULL); \ int skip = h_compile__m(mm__, (HParser *)(parser), (HParserBackend)backend, NULL); \
if(skip != 0) { \ if(skip != 0) { \
g_test_message("Compile failed"); \ g_test_message("Compile failed"); \
g_test_fail(); \ g_test_fail(); \
break; \ break; \
} \ } \
HParseResult *result = h_parse(parser, (const uint8_t*)input, inp_len); \ HParseResult *result = h_parse__m(mm__, parser, (const uint8_t*)input, inp_len); \
if (NULL != result) { \ if (NULL != result) { \
h_parse_result_free(result); \ h_parse_result_free(result); \
g_test_message("Check failed: shouldn't have succeeded, but did"); \ g_test_message("Check failed: shouldn't have succeeded, but did"); \
...@@ -93,6 +93,9 @@ ...@@ -93,6 +93,9 @@
} \ } \
} while(0) } while(0)
#define g_check_parse_failed(p, be, input, len) \
g_check_parse_failed__m(&system_allocator, p, be, input, len)
#define g_check_parse_ok(parser, backend, input, inp_len) do { \ #define g_check_parse_ok(parser, backend, input, inp_len) do { \
int skip = h_compile((HParser *)(parser), (HParserBackend) backend, NULL); \ int skip = h_compile((HParser *)(parser), (HParserBackend) backend, NULL); \
if(skip) { \ if(skip) { \
...@@ -140,18 +143,18 @@ ...@@ -140,18 +143,18 @@
} \ } \
} while(0) } while(0)
#define g_check_parse_chunks_failed(parser, backend, chunk1, c1_len, chunk2, c2_len) do { \ #define g_check_parse_chunks_failed__m(mm__, parser, backend, chunk1, c1_len, chunk2, c2_len) do { \
int skip = h_compile((HParser *)(parser), (HParserBackend)backend, NULL); \ int skip = h_compile__m(mm__, (HParser *)(parser), (HParserBackend)backend, NULL); \
if(skip) { \ if(skip) { \
g_test_message("Compile failed"); \ g_test_message("Compile failed"); \
g_test_fail(); \ g_test_fail(); \
break; \ break; \
} \ } \
g_check_parse_chunks_failed_(parser, chunk1, c1_len, chunk2, c2_len); \ g_check_parse_chunks_failed___m(mm__, parser, chunk1, c1_len, chunk2, c2_len); \
} while(0) } while(0)
#define g_check_parse_chunks_failed_(parser, chunk1, c1_len, chunk2, c2_len) do { \ #define g_check_parse_chunks_failed___m(mm__, parser, chunk1, c1_len, chunk2, c2_len) do { \
HSuspendedParser *s = h_parse_start(parser); \ HSuspendedParser *s = h_parse_start__m(mm__, parser); \
if(!s) { \ if(!s) { \
g_test_message("Chunk-wise parsing not available"); \ g_test_message("Chunk-wise parsing not available"); \
g_test_fail(); \ g_test_fail(); \
...@@ -167,6 +170,46 @@ ...@@ -167,6 +170,46 @@
} \ } \
} while(0) } while(0)
#define g_check_parse_chunks_failed(p, be, c1, c1_len, c2, c2_len) \
g_check_parse_chunks_failed__m(&system_allocator, p, be, c1, c1_len, c2, c2_len)
#define g_check_parse_chunks_failed_(p, c1, c1_len, c2, c2_len) \
g_check_parse_chunks_failed___m(&system_allocator, p, c1, c1_len, c2, c2_len)
#define g_check_parse_chunks_ok(parser, backend, chunk1, c1_len, chunk2, c2_len) do { \
int skip = h_compile((HParser *)(parser), (HParserBackend)backend, NULL); \
if(skip) { \
g_test_message("Compile failed"); \
g_test_fail(); \
break; \
} \
g_check_parse_chunks_ok_(parser, chunk1, c1_len, chunk2, c2_len); \
} while(0)
#define g_check_parse_chunks_ok_(parser, chunk1, c1_len, chunk2, c2_len) do { \
HSuspendedParser *s = h_parse_start(parser); \
if(!s) { \
g_test_message("Chunk-wise parsing not available"); \
g_test_fail(); \
break; \
} \
h_parse_chunk(s, (const uint8_t*)chunk1, c1_len); \
h_parse_chunk(s, (const uint8_t*)chunk2, c2_len); \
HParseResult *res = h_parse_finish(s); \
if (!res) { \
g_test_message("Parse failed on line %d", __LINE__); \
g_test_fail(); \
} else { \
HArenaStats stats; \
h_allocator_stats(res->arena, &stats); \
g_test_message("Parse used %zd bytes, wasted %zd bytes. " \
"Inefficiency: %5f%%", \
stats.used, stats.wasted, \
stats.wasted * 100. / (stats.used+stats.wasted)); \
h_parse_result_free(res); \
} \
} while(0)
#define g_check_parse_chunks_match(parser, backend, chunk1, c1_len, chunk2, c2_len, result) do { \ #define g_check_parse_chunks_match(parser, backend, chunk1, c1_len, chunk2, c2_len, result) do { \
int skip = h_compile((HParser *)(parser), (HParserBackend) backend, NULL); \ int skip = h_compile((HParser *)(parser), (HParserBackend) backend, NULL); \
if(skip) { \ if(skip) { \
......
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