[tor-commits] [tor/master] Give test_util_format some succeeding test cases
nickm at torproject.org
nickm at torproject.org
Fri Oct 2 10:52:40 UTC 2015
commit 39eb075c20991e10df394e8f40ef56d16b9935c0
Author: Nick Mathewson <nickm at torproject.org>
Date: Fri Oct 2 12:52:35 2015 +0200
Give test_util_format some succeeding test cases
---
src/test/test_util_format.c | 44 +++++++++++++++++++++++++++++++++++++------
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c
index c7d1047..af4997d 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);
More information about the tor-commits
mailing list