aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorEsteban Manchado Velázquez <emanchado@demiurgo.org>2012-02-10 00:21:00 +0100
committerNick Mathewson <nickm@torproject.org>2012-03-08 20:49:24 -0500
commit667f30e4652601cde39b3ec79d68e0f3caa64800 (patch)
tree45f77e823398238b2181acf1f0d2f58edcff5a13 /src/test/test_util.c
parent781c6676ca413421204136e9086ca15a9d74ac26 (diff)
downloadtor-667f30e4652601cde39b3ec79d68e0f3caa64800.tar
tor-667f30e4652601cde39b3ec79d68e0f3caa64800.tar.gz
Improve a bit asprintf unit tests
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index ec4405f59..de570ac33 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1549,36 +1549,47 @@ test_util_asprintf(void *ptr)
int r;
(void)ptr;
- /* empty string. */
+ /* simple string */
+ r = tor_asprintf(&cp, "simple string 100%% safe");
+ test_assert(cp);
+ test_streq("simple string 100% safe", cp);
+ test_eq(strlen(cp), r);
+
+ /* empty string */
r = tor_asprintf(&cp, "%s", "");
- tt_assert(cp);
- tt_int_op(r, ==, strlen(cp));
- tt_str_op(cp, ==, "");
+ test_assert(cp);
+ test_streq("", cp);
+ test_eq(strlen(cp), r);
+
+ /* numbers (%i) */
+ r = tor_asprintf(&cp, "I like numbers-%2i, %i, etc.", -1, 2);
+ test_assert(cp);
+ test_streq("I like numbers--1, 2, etc.", cp);
+ test_eq(strlen(cp), r);
- /* Short string with some printing in it. */
+ /* numbers (%d) */
r = tor_asprintf(&cp2, "First=%d, Second=%d", 101, 202);
- tt_assert(cp2);
- tt_int_op(r, ==, strlen(cp2));
- tt_str_op(cp2, ==, "First=101, Second=202");
- tt_assert(cp != cp2);
+ test_assert(cp2);
+ test_eq(strlen(cp2), r);
+ test_streq("First=101, Second=202", cp2);
+ test_assert(cp != cp2);
tor_free(cp);
tor_free(cp2);
/* Glass-box test: a string exactly 128 characters long. */
r = tor_asprintf(&cp, "Lorem1: %sLorem2: %s", LOREMIPSUM, LOREMIPSUM);
- tt_assert(cp);
- tt_int_op(r, ==, 128);
- tt_assert(cp[128] == '\0');
- tt_str_op(cp, ==,
- "Lorem1: "LOREMIPSUM"Lorem2: "LOREMIPSUM);
+ test_assert(cp);
+ test_eq(128, r);
+ test_assert(cp[128] == '\0');
+ test_streq("Lorem1: "LOREMIPSUM"Lorem2: "LOREMIPSUM, cp);
tor_free(cp);
/* String longer than 128 characters */
r = tor_asprintf(&cp, "1: %s 2: %s 3: %s",
LOREMIPSUM, LOREMIPSUM, LOREMIPSUM);
- tt_assert(cp);
- tt_int_op(r, ==, strlen(cp));
- tt_str_op(cp, ==, "1: "LOREMIPSUM" 2: "LOREMIPSUM" 3: "LOREMIPSUM);
+ test_assert(cp);
+ test_eq(strlen(cp), r);
+ test_streq("1: "LOREMIPSUM" 2: "LOREMIPSUM" 3: "LOREMIPSUM, cp);
done:
tor_free(cp);