diff options
author | Ola Bini <ola@olabini.se> | 2015-10-03 18:37:29 -0500 |
---|---|---|
committer | Ola Bini <ola@olabini.se> | 2015-10-03 18:37:29 -0500 |
commit | d0abf16119cf57e47044e171bc310773b45686f6 (patch) | |
tree | 212b949e2e568f6a381c13d63490c91f746587ca /src/test/test_util_format.c | |
parent | 28370fe77fcb8aae275883280679d0f7bc030496 (diff) | |
download | tor-d0abf16119cf57e47044e171bc310773b45686f6.tar.gz tor-d0abf16119cf57e47044e171bc310773b45686f6.zip |
Actually test success cases as well
Diffstat (limited to 'src/test/test_util_format.c')
-rw-r--r-- | src/test/test_util_format.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c index 8ffc2de63c..e35632f7e8 100644 --- a/src/test/test_util_format.c +++ b/src/test/test_util_format.c @@ -107,10 +107,13 @@ test_util_format_base64_decode_nopad(void *ignored) int res; int i; char *src; - uint8_t *dst; + uint8_t *dst, *real_dst; + uint8_t expected[] = {0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65}; + char real_src[] = "ZXhhbXBsZQ"; src = tor_malloc_zero(256); dst = tor_malloc_zero(1000); + real_dst = tor_malloc_zero(10); for(i=0;i<256;i++) { src[i] = (char)i; @@ -122,9 +125,14 @@ test_util_format_base64_decode_nopad(void *ignored) res = base64_decode_nopad(dst, 1, src, 5); tt_int_op(res, OP_EQ, -1); + res = base64_decode_nopad(real_dst, 10, real_src, 10); + tt_int_op(res, OP_EQ, 7); + tt_mem_op(real_dst, OP_EQ, expected, 7); + done: tor_free(src); tor_free(dst); + tor_free(real_dst); } @@ -135,10 +143,13 @@ test_util_format_base64_decode(void *ignored) int res; int i; char *src; - char *dst; + char *dst, *real_dst; + uint8_t expected[] = {0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65}; + char real_src[] = "ZXhhbXBsZQ=="; src = tor_malloc_zero(256); dst = tor_malloc_zero(1000); + real_dst = tor_malloc_zero(10); for(i=0;i<256;i++) { src[i] = (char)i; @@ -150,9 +161,14 @@ test_util_format_base64_decode(void *ignored) res = base64_decode(dst, SIZE_T_CEILING+1, src, 10); tt_int_op(res, OP_EQ, -1); + res = base64_decode(real_dst, 10, real_src, 10); + tt_int_op(res, OP_EQ, 7); + tt_mem_op(real_dst, OP_EQ, expected, 7); + done: tor_free(src); tor_free(dst); + tor_free(real_dst); } @@ -164,10 +180,13 @@ test_util_format_base16_decode(void *ignored) int res; int i; char *src; - char *dst; + char *dst, *real_dst; + char expected[] = {0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65}; + char real_src[] = "6578616D706C65"; src = tor_malloc_zero(256); dst = tor_malloc_zero(1000); + real_dst = tor_malloc_zero(10); for(i=0;i<256;i++) { src[i] = (char)i; @@ -182,9 +201,14 @@ test_util_format_base16_decode(void *ignored) res = base16_decode(dst, SIZE_T_CEILING+2, src, 10); tt_int_op(res, OP_EQ, -1); + res = base16_decode(real_dst, 10, real_src, 14); + tt_int_op(res, OP_EQ, 0); + tt_mem_op(real_dst, OP_EQ, expected, 7); + done: tor_free(src); tor_free(dst); + tor_free(real_dst); } |