summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsussman <sussman@13f79535-47bb-0310-9956-ffa450edef68>2003-07-07 22:44:11 +0000
committersussman <sussman@13f79535-47bb-0310-9956-ffa450edef68>2003-07-07 22:44:11 +0000
commitdf9731f421df4af8b8d92c77099f07aa5d23e36f (patch)
tree0d3235b1a02a9f4302a6dadb0295b2fbad504658 /test
parent8a3a3508e97ae81cb07a9d8b943ca7aafedb5a85 (diff)
downloadlibapr-df9731f421df4af8b8d92c77099f07aa5d23e36f.tar.gz
New apr_file_mtime_set() API, implemented in unix and win32.
Patches from Branko Cibej (brane) and Matt Kraai <kraai@alumni.cmu.edu>. * include/apr_file_io.h (apr_file_mtime_set): declare. * include/arch/win32/apr_arch_file_io.h: expand apr_file_open internal flags; add new APR_WRITEATTRS value. * file_io/win32/open.c (apr_file_open): honor APR_WRITEATTRS flag. * file_io/win32/filestat.c (apr_file_mtime_set): implement in win32. * file_io/unix/filestat.c (apr_file_mtime_set): implement in unix. * test/testfileinfo.c (test_mtime_set): new API test. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64563 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/testfileinfo.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/testfileinfo.c b/test/testfileinfo.c
index a788193fb..3a7073b53 100644
--- a/test/testfileinfo.c
+++ b/test/testfileinfo.c
@@ -239,6 +239,53 @@ static void test_buffered_write_size(CuTest *tc)
apr_file_close(thefile);
}
+static void test_mtime_set(CuTest *tc)
+{
+ apr_file_t *thefile;
+ apr_finfo_t finfo;
+ apr_time_t epoch = 0;
+ apr_status_t rv;
+
+ /* This test sort of depends on the system clock being at least
+ * marginally ccorrect; We'll be setting the modification time to
+ * the epoch.
+ */
+ rv = apr_file_open(&thefile, NEWFILENAME,
+ APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE
+ | APR_BUFFERED | APR_DELONCLOSE,
+ APR_OS_DEFAULT, p);
+ apr_assert_success(tc, "open file", rv);
+
+ /* Check that the current mtime is not the epoch */
+ rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p);
+ if (rv == APR_INCOMPLETE) {
+ char *str;
+ int i;
+ str = apr_pstrdup(p, "APR_INCOMPLETE: Missing ");
+ for (i = 0; vfi[i].bits; ++i) {
+ if (vfi[i].bits & ~finfo.valid) {
+ str = apr_pstrcat(p, str, vfi[i].description, " ", NULL);
+ }
+ }
+ CuFail(tc, str);
+ }
+ apr_assert_success(tc, "get initial mtime", rv);
+ CuAssertTrue(tc, finfo.mtime != epoch);
+
+ /* Reset the mtime to the epoch and verify the result.
+ * Note: we blindly assume that if the first apr_stat succeeded,
+ * the second one will, too.
+ */
+ rv = apr_file_mtime_set(NEWFILENAME, epoch, p);
+ apr_assert_success(tc, "set mtime", rv);
+
+ rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p);
+ apr_assert_success(tc, "get modified mtime", rv);
+ CuAssertTrue(tc, finfo.mtime == epoch);
+
+ apr_file_close(thefile);
+}
+
CuSuite *testfileinfo(void)
{
CuSuite *suite = CuSuiteNew("File Info");
@@ -247,6 +294,7 @@ CuSuite *testfileinfo(void)
SUITE_ADD_TEST(suite, test_stat);
SUITE_ADD_TEST(suite, test_stat_eq_finfo);
SUITE_ADD_TEST(suite, test_buffered_write_size);
+ SUITE_ADD_TEST(suite, test_mtime_set);
return suite;
}