aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util_format.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-10-06 11:20:33 -0400
committerNick Mathewson <nickm@torproject.org>2015-10-06 11:20:33 -0400
commit2592d537f95173083e397d19e182346955741221 (patch)
tree408fe3e21b23225da01e1316e4239ed590a64c36 /src/test/test_util_format.c
parentaaa27b995c03f6fe07849021e0302ecd9b720551 (diff)
parentb54133fbd9b1c7e08024b3987ff17ca3ef5666a9 (diff)
downloadtor-2592d537f95173083e397d19e182346955741221.tar.gz
tor-2592d537f95173083e397d19e182346955741221.zip
Merge remote-tracking branch 'twstrike/util_format_tests'
Conflicts: src/test/test_util_format.c
Diffstat (limited to 'src/test/test_util_format.c')
-rw-r--r--src/test/test_util_format.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c
index af4997de97..705dfcf605 100644
--- a/src/test/test_util_format.c
+++ b/src/test/test_util_format.c
@@ -112,10 +112,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;
@@ -137,9 +140,14 @@ test_util_format_base64_decode_nopad(void *ignored)
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);
+ tor_free(real_dst);
}
static void
@@ -149,10 +157,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;
@@ -179,9 +190,14 @@ test_util_format_base64_decode(void *ignored)
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);
+ tor_free(real_dst);
}
static void
@@ -191,10 +207,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;
@@ -222,9 +241,14 @@ test_util_format_base16_decode(void *ignored)
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);
+ tor_free(real_dst);
}
struct testcase_t util_format_tests[] = {