diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-10-02 12:52:35 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-10-02 12:52:35 +0200 |
commit | 39eb075c20991e10df394e8f40ef56d16b9935c0 (patch) | |
tree | 40fb6dfe0f045656850f59153fb05e7679b66d54 /src/test/test_util_format.c | |
parent | 144a0cb70452fd934a3f9ec6533c829d9379e0f1 (diff) | |
download | tor-39eb075c20991e10df394e8f40ef56d16b9935c0.tar.gz tor-39eb075c20991e10df394e8f40ef56d16b9935c0.zip |
Give test_util_format some succeeding test cases
Diffstat (limited to 'src/test/test_util_format.c')
-rw-r--r-- | src/test/test_util_format.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c index c7d1047933..af4997de97 100644 --- a/src/test/test_util_format.c +++ b/src/test/test_util_format.c @@ -121,14 +121,22 @@ test_util_format_base64_decode_nopad(void *ignored) src[i] = (char)i; } - /* XXXX Needs to test the success case */ - res = base64_decode_nopad(dst, 1, src, SIZE_T_CEILING); tt_int_op(res, OP_EQ, -1); res = base64_decode_nopad(dst, 1, src, 5); tt_int_op(res, OP_EQ, -1); + const char *s = "SGVsbG8gd29ybGQ"; + res = base64_decode_nopad(dst, 1000, s, strlen(s)); + tt_int_op(res, OP_EQ, 11); + tt_mem_op(dst, OP_EQ, "Hello world", 11); + + s = "T3BhIG11bmRv"; + res = base64_decode_nopad(dst, 9, s, strlen(s)); + tt_int_op(res, OP_EQ, 9); + tt_mem_op(dst, OP_EQ, "Opa mundo", 9); + done: tor_free(src); tor_free(dst); @@ -150,14 +158,27 @@ test_util_format_base64_decode(void *ignored) src[i] = (char)i; } - /* XXXX Needs to test the success case */ - res = base64_decode(dst, 1, src, SIZE_T_CEILING); tt_int_op(res, OP_EQ, -1); res = base64_decode(dst, SIZE_T_CEILING+1, src, 10); tt_int_op(res, OP_EQ, -1); + const char *s = "T3BhIG11bmRv"; + res = base64_decode(dst, 9, s, strlen(s)); + tt_int_op(res, OP_EQ, 9); + tt_mem_op(dst, OP_EQ, "Opa mundo", 9); + + memset(dst, 0, 1000); + res = base64_decode(dst, 100, s, strlen(s)); + tt_int_op(res, OP_EQ, 9); + tt_mem_op(dst, OP_EQ, "Opa mundo", 9); + + s = "SGVsbG8gd29ybGQ="; + res = base64_decode(dst, 100, s, strlen(s)); + tt_int_op(res, OP_EQ, 11); + tt_mem_op(dst, OP_EQ, "Hello world", 11); + done: tor_free(src); tor_free(dst); @@ -179,8 +200,6 @@ test_util_format_base16_decode(void *ignored) src[i] = (char)i; } - /* XXXX Needs to test the success case */ - res = base16_decode(dst, 3, src, 3); tt_int_op(res, OP_EQ, -1); @@ -190,6 +209,19 @@ 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(dst, 1000, "", 0); + tt_int_op(res, OP_EQ, 0); + + res = base16_decode(dst, 1000, "aabc", 4); + tt_int_op(res, OP_EQ, 0); + tt_mem_op(dst, OP_EQ, "\xaa\xbc", 2); + + res = base16_decode(dst, 1000, "aabcd", 6); + tt_int_op(res, OP_EQ, -1); + + res = base16_decode(dst, 1000, "axxx", 4); + tt_int_op(res, OP_EQ, -1); + done: tor_free(src); tor_free(dst); |