aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-05-11 11:45:40 -0400
committerNick Mathewson <nickm@torproject.org>2012-05-11 11:45:40 -0400
commit84ddc4b6aad392dd9a735580caf6fb68e3694d42 (patch)
tree7fec188bfa660448fc8a2722f3c8e224ad4085c6 /src/test/test_util.c
parent648db9a4b7101d54f38aee60f42546e9a172e17e (diff)
parentefb8a09f41fcd4c48bffdc98ae8d5e0002a0bb88 (diff)
downloadtor-84ddc4b6aad392dd9a735580caf6fb68e3694d42.tar
tor-84ddc4b6aad392dd9a735580caf6fb68e3694d42.tar.gz
Merge remote-tracking branch 'public/bug5091'
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index e8f043a2c..365b5ac77 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1752,32 +1752,56 @@ test_util_strtok(void)
{
char buf[128];
char buf2[128];
+ int i;
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));
+ for (i = 0; i < 3; i++) {
+ const char *pad1, *pad2;
+ switch (i) {
+ case 0:
+ pad1 = pad2 = "";
+ break;
+ case 1:
+ pad1 = " ";
+ pad2 = "!";
+ break;
+ case 2:
+ pad1 = " ";
+ pad2 = ";!";
+ break;
+ }
+ tor_snprintf(buf, sizeof(buf), "%s", pad1);
+ tor_snprintf(buf2, sizeof(buf2), "%s", pad2);
+ test_assert(NULL == tor_strtok_r_impl(buf, " ", &cp1));
+ test_assert(NULL == tor_strtok_r_impl(buf2, ".!..;!", &cp2));
+
+ tor_snprintf(buf, sizeof(buf),
+ "%sGraved on the dark in gestures of descent%s", pad1, pad1);
+ tor_snprintf(buf2, sizeof(buf2),
+ "%sthey.seemed;;their!.own;most.perfect;monument%s",pad2,pad2);
+ /* -- "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_eq_ptr(NULL, S1());
- test_eq_ptr(NULL, S2());
+ 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_eq_ptr(NULL, S1());
+ test_eq_ptr(NULL, S2());
+ }
-#if 0
buf[0] = 0;
test_eq_ptr(NULL, tor_strtok_r_impl(buf, " ", &cp1));
test_eq_ptr(NULL, tor_strtok_r_impl(buf, "!", &cp1));
@@ -1790,12 +1814,10 @@ test_util_strtok(void)
test_eq_ptr(NULL, tor_strtok_r_impl(buf, " ", &cp1));
strlcpy(buf, " ", sizeof(buf));
test_eq_ptr(NULL, tor_strtok_r_impl(buf, " ", &cp1));
-#endif
strlcpy(buf, "something ", sizeof(buf));
test_streq("something", tor_strtok_r_impl(buf, " ", &cp1));
- test_streq(" ", tor_strtok_r_impl(NULL, ";", &cp1));
- test_eq_ptr(NULL, tor_strtok_r_impl(NULL, " ", &cp1));
+ test_eq_ptr(NULL, tor_strtok_r_impl(NULL, ";", &cp1));
done:
;
}