aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-09-18 14:03:49 -0400
committerNick Mathewson <nickm@torproject.org>2015-05-07 15:29:16 -0400
commit79e85313aa611b599f19fea61c38ff3928e1fd59 (patch)
treed6c25dae4999d42a33810134f49d7d650a25b2dc /src/test/test_util.c
parent3668a4126e0c2502a77c2ba5d7885add489a964a (diff)
downloadtor-79e85313aa611b599f19fea61c38ff3928e1fd59.tar.gz
tor-79e85313aa611b599f19fea61c38ff3928e1fd59.zip
Write the outlines of a WritingTests.txt document
Also, add some sample tests to be examples.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 15470e8efa..3bebe60490 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4905,6 +4905,35 @@ test_util_ipv4_validation(void *arg)
return;
}
+static void
+test_util_writepid(void *arg)
+{
+ (void) arg;
+
+ char *contents = NULL;
+ const char *fname = get_fname("tmp_pid");
+ unsigned long pid;
+ char c;
+
+ write_pidfile(fname);
+
+ contents = read_file_to_str(fname, 0, NULL);
+ tt_assert(contents);
+
+ int n = sscanf(contents, "%lu\n%c", &pid, &c);
+ tt_int_op(n, OP_EQ, 1);
+ tt_uint_op(pid, OP_EQ,
+#ifdef _WIN32
+ _getpid()
+#else
+ getpid()
+#endif
+ );
+
+ done:
+ tor_free(contents);
+}
+
struct testcase_t util_tests[] = {
UTIL_LEGACY(time),
UTIL_TEST(parse_http_time, 0),
@@ -4981,6 +5010,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(max_mem, 0),
UTIL_TEST(hostname_validation, 0),
UTIL_TEST(ipv4_validation, 0),
+ UTIL_TEST(writepid, 0),
END_OF_TESTCASES
};