From 113911921e555aa839c7bd71998c5e9d43cf4d87 Mon Sep 17 00:00:00 2001 From: Louis Lenders Date: Fri, 29 Apr 2011 09:58:04 +0200 Subject: msvcrt: Add tests to show that utime() can take a NULL-pointer for the utimbuf structure field --- dlls/msvcrt/tests/file.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index 0231f72..60c76f9 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -24,8 +24,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -38,6 +40,7 @@ static HANDLE proc_handles[2]; static int (__cdecl *p_fopen_s)(FILE**, const char*, const char*); static int (__cdecl *p__wfopen_s)(FILE**, const wchar_t*, const wchar_t*); +static int (__cdecl *p_utime)(const char*, const struct utimbuf*); static void init(void) { @@ -45,6 +48,7 @@ static void init(void) p_fopen_s = (void*)GetProcAddress(hmod, "fopen_s"); p__wfopen_s = (void*)GetProcAddress(hmod, "_wfopen_s"); + p_utime = (void*)GetProcAddress(hmod, "_utime"); } static void test_filbuf( void ) @@ -1522,6 +1526,53 @@ static void test_dup2(void) ok(-1 == _dup2(0, -1), "expected _dup2 to fail when second arg is negative\n" ); } +static void test_utime(void) +{ + int fd; + struct utimbuf ubuf; + struct stat info; + struct tm access_time = {0} , modification_time = {0}; + + fd = open("fd.tst", O_CREAT | O_RDWR | O_BINARY, _S_IREAD |_S_IWRITE); + ok(fd != -1, "Couldn't create test file\n"); + + /* set access date to Wed Nov 15 00:00:00 2000 */ + access_time.tm_mon = 10; + access_time.tm_mday = 15; + access_time.tm_year = 100; + + /* set modification date to Tue Feb 22 08:00:00 2005 */ + modification_time.tm_hour = 8; + modification_time.tm_mday = 22; + modification_time.tm_mon = 1; + modification_time.tm_year = 105; + + ubuf.actime = mktime(&access_time); + ubuf.modtime = mktime(&modification_time); + + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace("testfile modification time is %s\n", ctime(&info.st_mtime)); + trace("testfile access time is %s\n", ctime(&info.st_atime)); + + ok(p_utime("fd.tst", &ubuf) == 0, "utime failed\n"); + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace("changed the modification time to %s\n", ctime(&info.st_mtime)); + trace("changed the access time to %s\n", ctime(&info.st_atime)); + +#if(0) /* FIXME: this test crashes wine, remove this line when wine is fixed */ + /* test with NULL pointer */ + ok(p_utime("fd.tst", NULL) == 0, "utime failed\n"); + ok(stat("fd.tst", &info) == 0, "file-status information could not be obtained\n"); + + trace(" changed the modification time back to %s\n", ctime(&info.st_mtime)); + trace(" changed the access time back to %s\n", ctime(&info.st_atime)); +#endif + ok(close(fd) == 0, "Couldn't close testfile\n"); + ok(unlink("fd.tst") == 0, "Couldn't unlink\n"); +} + START_TEST(file) { int arg_c; @@ -1573,6 +1624,7 @@ START_TEST(file) test_get_osfhandle(); test_setmaxstdio(); test_pipes(arg_v[0]); + test_utime(); /* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report * file contains lines in the correct order -- 1.7.4.1