summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-01-03 08:37:14 -0800
committerNick Mathewson <nickm@torproject.org>2016-01-03 08:37:14 -0800
commit8aa9ee73dabc8669de7744ddd19da87eef7778da (patch)
tree5364c4cf36065debaa9665064dd29c0bc4125015 /src/test
parentde8110fba2b177d0fcd0f1b92a42caae8cf7addf (diff)
downloadtor-8aa9ee73dabc8669de7744ddd19da87eef7778da.tar.gz
tor-8aa9ee73dabc8669de7744ddd19da87eef7778da.zip
Add a test for touch_file
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_util.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4cf2f9bda1..f88c2976bc 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -14,6 +14,12 @@
#include "memarea.h"
#include "util_process.h"
+#ifdef HAVE_SYS_UTIME_H
+#include <sys/utime.h>
+#endif
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#endif
#ifdef _WIN32
#include <tchar.h>
#endif
@@ -4599,6 +4605,33 @@ test_util_get_avail_disk_space(void *arg)
;
}
+static void
+test_util_touch_file(void *arg)
+{
+ (void) arg;
+ const char *fname = get_fname("touch");
+
+ const time_t now = time(NULL);
+ struct stat st;
+ write_bytes_to_file(fname, "abc", 3, 1);
+ tt_int_op(0, OP_EQ, stat(fname, &st));
+ tt_i64_op(st.st_mtime, OP_GE, now);
+
+ const time_t five_sec_ago = now - 5;
+ struct utimbuf u = { five_sec_ago, five_sec_ago };
+ tt_int_op(0, OP_EQ, utime(fname, &u));
+ tt_int_op(0, OP_EQ, stat(fname, &st));
+ tt_i64_op(st.st_mtime, OP_EQ, five_sec_ago);
+
+ /* Finally we can touch the file */
+ tt_int_op(0, OP_EQ, touch_file(fname));
+ tt_int_op(0, OP_EQ, stat(fname, &st));
+ tt_i64_op(st.st_mtime, OP_GE, now);
+
+ done:
+ ;
+}
+
struct testcase_t util_tests[] = {
UTIL_LEGACY(time),
UTIL_TEST(parse_http_time, 0),
@@ -4672,6 +4705,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(ipv4_validation, 0),
UTIL_TEST(writepid, 0),
UTIL_TEST(get_avail_disk_space, 0),
+ UTIL_TEST(touch_file, 0),
END_OF_TESTCASES
};