From 729964bea692f9683860978b89848784a7fc2f46 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 30 Aug 2026 20:52:43 +0000 Subject: Still a lot to be done, but I'm going to bed. Two remaining big issues: * aplwc (the parameter passed "everywhere") - should it move or not? * values returned from the public API should not move. FossilOrigin-Name: 31ab3154b8f3d5ac167218496e9e204324bf0ac9d36b7bada8fe2a6c8f93d51c --- tests/aplwc_errstr.c | 59 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'tests/aplwc_errstr.c') diff --git a/tests/aplwc_errstr.c b/tests/aplwc_errstr.c index 2ca14ab..1a5ebc4 100644 --- a/tests/aplwc_errstr.c +++ b/tests/aplwc_errstr.c @@ -1,47 +1,76 @@ -#include +#include #include +#include + +static void * +my_alloc(size_t min, size_t max, size_t *actual) +{ + (void)max; + + *actual = min; + return malloc(min); +} + +static void +my_dealloc(void *p) +{ + free(p); +} int main(void) { - uint8_t data[20000]; + struct aplwc_fns fns; struct aplwc *aplwc; - int ret; + int ret, success; const char *err; - ret = aplwc_new(&aplwc, data, sizeof(data)); + success = 0; + aplwc = NULL; + + memset(&fns, 0, sizeof(fns)); + fns.alloc = my_alloc; + fns.dealloc = my_dealloc; + + ret = aplwc_new(&aplwc, fns); if(ret) - return 1; + goto end; err = aplwc_errstr(aplwc); if(err == NULL) - return 1; + goto end; if(strlen(err) != 0) - return 1; + goto end; err = aplwc_errstr(NULL); if(err == NULL) - return 1; + goto end; if(strcmp(err, "(unable to produce error string)") != 0) - return 1; + goto end; aplwc_destroy(aplwc); + aplwc = NULL; - ret = aplwc_new(&aplwc, data, 0); + fns.alloc = NULL; + ret = aplwc_new(&aplwc, fns); if(ret == 0) - return 1; + goto end; err = aplwc_errstr_rc(ret); if(err == NULL) - return 1; + goto end; for(ret = 0; ret <= APLWC_RC_LAST; ret++){ err = aplwc_errstr_rc(ret); if(err == NULL) - return 1; + goto end; if(strcmp(err, "(unable to produce error string)") == 0) - return 1; + goto end; } - return 0; + success = 1; +end: + if(aplwc) + aplwc_destroy(aplwc); + return !success; } -- cgit v1.2.3