X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Falloc%2Ftest%2Frun-tiny-encode.c;h=8f548622fdc5bae8c7ab8b2d3b329b8d2c68c6f0;hp=fac83f00a55ef8f65afc4bc080355788c456a0eb;hb=bd294f1df2a9a2a97bf32336ddd22e53e0e0b8f7;hpb=7f9d956574d30f70d2260f4b7694f481e3765173 diff --git a/ccan/alloc/test/run-tiny-encode.c b/ccan/alloc/test/run-tiny-encode.c index fac83f00..8f548622 100644 --- a/ccan/alloc/test/run-tiny-encode.c +++ b/ccan/alloc/test/run-tiny-encode.c @@ -13,7 +13,7 @@ int main(void) unsigned char array[ARR_SIZE]; unsigned int i, prev; - plan_tests(567); + plan_tests(405); prev = 0; /* Test encode_length */ @@ -27,11 +27,11 @@ int main(void) /* Test it against actual encoding return val. */ for (i = 1; i < 0x8000000; i *= 2) { ok1(encode_length(i-1) == encode(i - 1 + MIN_BLOCK_SIZE, - false, array, ARR_SIZE)); + false, array)); ok1(encode_length(i) == encode(i + MIN_BLOCK_SIZE, - false, array, ARR_SIZE)); + false, array)); ok1(encode_length(i+1) == encode(i + 1 + MIN_BLOCK_SIZE, - false, array, ARR_SIZE)); + false, array)); } /* Test encoder vs. decoder. */ @@ -39,50 +39,21 @@ int main(void) unsigned long hdrlen, len; bool free; - hdrlen = encode(i - 1 + MIN_BLOCK_SIZE, false, array, ARR_SIZE); + hdrlen = encode(i - 1 + MIN_BLOCK_SIZE, false, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i - 1 + MIN_BLOCK_SIZE); ok1(free == false); - hdrlen = encode(i + MIN_BLOCK_SIZE, true, array, ARR_SIZE); + hdrlen = encode(i + MIN_BLOCK_SIZE, true, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i + MIN_BLOCK_SIZE); ok1(free == true); - hdrlen = encode(i + 1 + MIN_BLOCK_SIZE, true, array, ARR_SIZE); + hdrlen = encode(i + 1 + MIN_BLOCK_SIZE, true, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i + 1 + MIN_BLOCK_SIZE); ok1(free == true); } - /* Test encoder limit enforcement. */ - for (i = 1; i < 0x8000000; i *= 2) { - unsigned char *arr; - unsigned int len; - - /* These should fit. */ - ok1(encode(i-1 + MIN_BLOCK_SIZE, false, array, - encode_length(i-1)) == encode_length(i-1)); - ok1(encode(i + MIN_BLOCK_SIZE, false, array, - encode_length(i)) == encode_length(i)); - ok1(encode(i+1 + MIN_BLOCK_SIZE, false, array, - encode_length(i+1)) == encode_length(i+1)); - - /* These should not: malloc so valgrind finds overruns. */ - len = encode_length(i-1) - 1; - arr = malloc(len); - ok1(encode(i-1 + MIN_BLOCK_SIZE, true, arr, len) == 0); - free(arr); - - len = encode_length(i-1) - 1; - arr = malloc(len); - ok1(encode(i + MIN_BLOCK_SIZE, false, arr, len) == 0); - free(arr); - - len = encode_length(i+1) - 1; - arr = malloc(len); - ok1(encode(i+1 + MIN_BLOCK_SIZE, false, arr, len) == 0); - free(arr); - } return exit_status(); }