summaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-08-09 17:27:35 -0700
committerNick Mathewson <nickm@torproject.org>2009-08-09 17:30:15 -0700
commit3886467f386732598647a2d3209777ba8d8d7baa (patch)
treecc240f735afa1073dbdc0bb442f015d358ff7a0c /src/or/test.c
parent6423091f071dc7c843d0fd02ac32b880b7754b24 (diff)
downloadtor-3886467f386732598647a2d3209777ba8d8d7baa.tar.gz
tor-3886467f386732598647a2d3209777ba8d8d7baa.zip
Add a new tor_strtok_r for platforms that don't have one, plus tests.
I don't think we actually use (or plan to use) strtok_r in a reentrant way anywhere in our code, but would be nice not to have to think about whether we're doing it.
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 3103eed828..67a9c381fe 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -4284,6 +4284,39 @@ test_util_datadir(void)
tor_free(f);
}
+static void
+test_util_strtok(void)
+{
+ char buf[128];
+ char buf2[128];
+ char *cp1, *cp2;
+ strlcpy(buf, "Graved on the dark in gestures of descent", sizeof(buf));
+ strlcpy(buf2, "they.seemed;their!own;most.perfect;monument", sizeof(buf2));
+ /* -- "Year's End", Richard Wilbur */
+
+ test_streq("Graved", tor_strtok_r_impl(buf, " ", &cp1));
+ test_streq("they", tor_strtok_r_impl(buf2, ".!..;!", &cp2));
+#define S1() tor_strtok_r_impl(NULL, " ", &cp1)
+#define S2() tor_strtok_r_impl(NULL, ".!..;!", &cp2)
+ test_streq("on", S1());
+ test_streq("the", S1());
+ test_streq("dark", S1());
+ test_streq("seemed", S2());
+ test_streq("their", S2());
+ test_streq("own", S2());
+ test_streq("in", S1());
+ test_streq("gestures", S1());
+ test_streq("of", S1());
+ test_streq("most", S2());
+ test_streq("perfect", S2());
+ test_streq("descent", S1());
+ test_streq("monument", S2());
+ test_assert(NULL == S1());
+ test_assert(NULL == S2());
+ done:
+ ;
+}
+
/** Test AES-CTR encryption and decryption with IV. */
static void
test_crypto_aes_iv(void)
@@ -4692,6 +4725,7 @@ static struct {
SUBENT(util, threads),
SUBENT(util, order_functions),
SUBENT(util, sscanf),
+ SUBENT(util, strtok),
ENT(onion_handshake),
ENT(dir_format),
ENT(dirutil),