/* * vplist_test.c * * Copyright (c) 2014-2018 * * Source code released under the GPL version 2 * * * test vplist functions */ #include #include #include #include #include #include "vplist.h" /* * typedef struct vplist { * vplist_index n, max; * void **data; * } vplist; */ const char progname[] = "vplist_test"; const char version[] = "0.1"; #define report_memerr( a ) { \ fprintf( stderr, "Failed: %s() line %d: %s() did not return VPLIST_OK, memory error\n", __FUNCTION__, __LINE__, a ); \ return 1; \ } #define check_len( a, b ) if ( !_check_len( a, b, __FUNCTION__, __LINE__ ) ) return 1; int _check_len( vplist *a, int expected, const char *fn, int line ) { if ( a->n == expected ) return 1; fprintf( stderr, "Failed: %s() line %d: Expected list length of %d, found %d\n", fn, line, expected, a->n ); return 0; } #define check_entry( a, b, c ) if ( !_check_entry( a, b, c, __FUNCTION__, __LINE__ ) ) return 1; int _check_entry( vplist *a, int n, const void *expected, const char *fn, int line ) { void *v; v = vplist_get( a, n ); if ( v==NULL && expected==NULL ) return 1; if ( v!=NULL && expected==NULL ) { fprintf( stderr, "Failed: %s() line %d: Expected list element %d to be NULL, found %p '%s'\n", fn, line, n, v, (char*)v ); return 0; } if ( v==NULL && expected!=NULL ) { fprintf( stderr, "Failed: %s() line %d: Expected list element %d to be %p '%s', found NULL\n", fn, line, n, expected, (char*)expected ); return 0; } if ( v == expected ) return 1; fprintf( stderr, "Failed: %s() line %d: Expected list element %d to be %p '%s', found %p '%s'\n", fn, line, n, expected, (char*)expected, v, (char*)v ); return 0; } #define check_isempty( a ) { \ check_len( a, 0 ); \ check_entry( a, -1, NULL ); \ check_entry( a, 0, NULL ); \ check_entry( a, 1, NULL ); \ } /* vplist 'a' will hold strings "0", "1", "2" .... */ static int build_vplist_a( vplist *a, char *s[], int lens ) { vplist_index i, j; char buf[256]; int status; for ( i=0; i