From 79e85313aa611b599f19fea61c38ff3928e1fd59 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 18 Sep 2014 14:03:49 -0400 Subject: Write the outlines of a WritingTests.txt document Also, add some sample tests to be examples. --- src/test/test_util.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/test/test_util.c') 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 }; -- cgit v1.2.3-54-g00ecf