diff options
Diffstat (limited to 'tests/aplwc_errstr.c')
| -rw-r--r-- | tests/aplwc_errstr.c | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/tests/aplwc_errstr.c b/tests/aplwc_errstr.c index 8014c1e..fe9fa0e 100644 --- a/tests/aplwc_errstr.c +++ b/tests/aplwc_errstr.c @@ -1,47 +1,75 @@ -#include <aplwc.h> +#include <stdlib.h> #include <string.h> +#include <aplwc.h> + +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[APLWC_MIN_MEM]; + enum aplwc_rc ret; + struct aplwc_fns fns; struct aplwc *aplwc; - int ret; + int success; const char *err; - ret = aplwc_new(&aplwc, data, sizeof(data)); + success = 0; + + memset(&fns, 0, sizeof(fns)); + fns.alloc = my_alloc; + fns.dealloc = my_dealloc; + + aplwc = aplwc_new(fns, &ret); 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); - ret = aplwc_new(&aplwc, data, 0); + fns.alloc = NULL; + aplwc = aplwc_new(fns, &ret); 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; } |