From: Nick Mathewson Date: Tue, 6 Oct 2015 15:20:33 +0000 (-0400) Subject: Merge remote-tracking branch 'twstrike/util_format_tests' X-Git-Tag: tor-0.2.8.1-alpha~319 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2592d537f95173083e397d19e182346955741221;p=thirdparty%2Ftor.git Merge remote-tracking branch 'twstrike/util_format_tests' Conflicts: src/test/test_util_format.c --- 2592d537f95173083e397d19e182346955741221 diff --cc src/test/test_util_format.c index af4997de97,7be67438f5..705dfcf605 --- a/src/test/test_util_format.c +++ b/src/test/test_util_format.c @@@ -127,16 -137,10 +130,20 @@@ test_util_format_base64_decode_nopad(vo 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); + + 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); @@@ -164,21 -172,10 +175,25 @@@ test_util_format_base64_decode(void *ig 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); + + 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); @@@ -209,19 -210,10 +228,23 @@@ test_util_format_base16_decode(void *ig 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); + + 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);