aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_pt.c2
-rw-r--r--src/test/test_util.c33
2 files changed, 28 insertions, 7 deletions
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index 9d6aa09f0..201f78ea5 100644
--- a/src/test/test_pt.c
+++ b/src/test/test_pt.c
@@ -94,6 +94,8 @@ test_pt_protocol(void)
managed_proxy_t *mp = tor_malloc_zero(sizeof(managed_proxy_t));
mp->conf_state = PT_PROTO_LAUNCHED;
mp->transports = smartlist_new();
+ mp->argv = tor_malloc_zero(sizeof(char*)*2);
+ mp->argv[0] = tor_strdup("<testcase>");
/* various wrong protocol runs: */
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 3cbc5bf89..365b5ac77 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -540,7 +540,7 @@ test_util_config_line_escaped_content(void)
tor_free(v);
}
-#ifndef MS_WINDOWS
+#ifndef _WIN32
static void
test_util_expand_filename(void)
{
@@ -755,6 +755,21 @@ test_util_strmisc(void)
test_eq(-10.0, d);
}
+ {
+ /* Test tor_parse_* where we overflow/underflow the underlying type. */
+ /* This string should overflow 64-bit ints. */
+#define TOOBIG "100000000000000000000000000"
+ test_eq(0L, tor_parse_long(TOOBIG, 10, LONG_MIN, LONG_MAX, &i, NULL));
+ test_eq(i, 0);
+ test_eq(0L, tor_parse_long("-"TOOBIG, 10, LONG_MIN, LONG_MAX, &i, NULL));
+ test_eq(i, 0);
+ test_eq(0UL, tor_parse_ulong(TOOBIG, 10, 0, ULONG_MAX, &i, NULL));
+ test_eq(i, 0);
+ test_eq(U64_LITERAL(0), tor_parse_uint64(TOOBIG, 10,
+ 0, UINT64_MAX, &i, NULL));
+ test_eq(i, 0);
+ }
+
/* Test snprintf */
/* Returning -1 when there's not enough room in the output buffer */
test_eq(-1, tor_snprintf(buf, 0, "Foo"));
@@ -1384,7 +1399,6 @@ test_util_sscanf(void)
test_eq(-1, tor_sscanf("wrong", "%5c", s1)); /* %c cannot have a number. */
test_eq(-1, tor_sscanf("hello", "%s", s1)); /* %s needs a number. */
test_eq(-1, tor_sscanf("prettylongstring", "%999999s", s1));
- test_eq(-1, tor_sscanf("We're the 99 monkeys", "We're the 99%%"));
#if 0
/* GCC thinks these two are illegal. */
test_eq(-1, tor_sscanf("prettylongstring", "%0s", s1));
@@ -1468,6 +1482,11 @@ test_util_sscanf(void)
/* Literal '%' (ie. '%%') */
test_eq(1, tor_sscanf("99% fresh", "%3u%% fresh", &u1));
test_eq(99, u1);
+ test_eq(0, tor_sscanf("99 fresh", "%% %3u %s", &u1, s1));
+ test_eq(1, tor_sscanf("99 fresh", "%3u%% %s", &u1, s1));
+ test_eq(2, tor_sscanf("99 fresh", "%3u %5s %%", &u1, s1));
+ test_eq(99, u1);
+ test_streq(s1, "fresh");
test_eq(1, tor_sscanf("% boo", "%% %3s", s1));
test_streq("boo", s1);
@@ -1521,21 +1540,19 @@ test_util_path_is_relative(void)
test_eq(0, path_is_relative("/dir/"));
/* Windows */
-#ifdef MS_WINDOWS
+#ifdef _WIN32
/* I don't have Windows so I can't test this, hence the "#ifdef
0". These are tests that look useful, so please try to get them
running and uncomment if it all works as it should */
-#ifdef 0
test_eq(1, path_is_relative("dir"));
test_eq(1, path_is_relative("dir\\"));
test_eq(1, path_is_relative("dir\\a:"));
test_eq(1, path_is_relative("dir\\a:\\"));
+ test_eq(1, path_is_relative("http:\\dir"));
test_eq(0, path_is_relative("\\dir"));
test_eq(0, path_is_relative("a:\\dir"));
test_eq(0, path_is_relative("z:\\dir"));
- test_eq(0, path_is_relative("http:\\dir"));
-#endif
#endif
done:
@@ -1944,7 +1961,7 @@ test_util_listdir(void *ptr)
test_eq(0, write_str_to_file(fname1, "X\n", 0));
test_eq(0, write_str_to_file(fname2, "Y\n", 0));
test_eq(0, write_str_to_file(fname3, "Z\n", 0));
-#ifdef MS_WINDOWS
+#ifdef _WIN32
r = mkdir(dir1);
#else
r = mkdir(dir1, 0700);
@@ -2905,7 +2922,9 @@ struct testcase_t util_tests[] = {
UTIL_LEGACY(config_line_quotes),
UTIL_LEGACY(config_line_comment_character),
UTIL_LEGACY(config_line_escaped_content),
+#ifndef _WIN32
UTIL_LEGACY(expand_filename),
+#endif
UTIL_LEGACY(strmisc),
UTIL_LEGACY(pow2),
UTIL_LEGACY(gzip),