diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c')
-rw-r--r-- | src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c b/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c new file mode 100644 index 0000000000..a3f46c2bf8 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/GetFileTime/test3/GetFileTime.c @@ -0,0 +1,142 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: GetFileTime.c +** +** Purpose: Tests the PAL implementation of the GetFileTime function +** Test to see that creation time is changed when two different files +** are created. +** +** Depends: +** CreateFile +** ReadFile +** CloseHandle +** +** +**===================================================================*/ + + +#include <palsuite.h> + + +int __cdecl main(int argc, char **argv) +{ + + FILETIME Creation; + HANDLE TheFileHandle, SecondFileHandle; + ULONG64 FirstCreationTime, SecondCreationTime; + BOOL result; + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + /* Open the file to get a HANDLE */ + TheFileHandle = + CreateFile( + "the_file", + GENERIC_READ, + 0, + NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + + + if(TheFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Get the Creation time of the File */ + if(GetFileTime(TheFileHandle,&Creation,NULL,NULL)==0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Two of the params were NULL in this case, did they " + "cause the probleM?"); + } + + /* Convert the structure to an ULONG64 */ + + FirstCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + + /* Close the File, so the changes are recorded */ + result = CloseHandle(TheFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Sleep for 3 seconds, this will ensure the time changes */ + Sleep(3000); + + + + /* Open another file */ + SecondFileHandle = + CreateFile("the_other_file", /* file name */ + GENERIC_READ, /* access mode */ + 0, /* share mode */ + NULL, /* SD */ + CREATE_ALWAYS, /* how to create */ + FILE_ATTRIBUTE_NORMAL, /* file attributes */ + NULL /* handle to template file */ + ); + + if(SecondFileHandle == INVALID_HANDLE_VALUE) + { + Fail("ERROR: Failed to open the second file. The error number " + "returned was %d.",GetLastError()); + } + + + /* Call GetFileTime again */ + if(GetFileTime(SecondFileHandle,&Creation,NULL,NULL) == 0) + { + Fail("ERROR: GetFileTime returned 0, indicating failure. " + "Perhaps the NULLs in the function broke it?"); + } + + /* Close the File*/ + result = CloseHandle(SecondFileHandle); + + if(result == 0) + { + Fail("ERROR: Failed to close the file handle."); + } + + + /* Store the results in a ULONG64 */ + + SecondCreationTime = ( (((ULONG64)Creation.dwHighDateTime)<<32) | + ((ULONG64)Creation.dwLowDateTime)); + + + + /* Now -- to test. We ensure that the FirstCreationTime is + less than the SecondCreationTime + */ + + + if(FirstCreationTime >= SecondCreationTime) + { + Fail("ERROR: The creation time of the two files should be " + "different. The first file should have a creation " + "time less than the second."); + } + + + + PAL_Terminate(); + return PASS; +} |