summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/SetFileTime
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/file_io/SetFileTime')
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/CMakeLists.txt7
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c129
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test1/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c101
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test2/testinfo.dat15
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c66
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test3/testinfo.dat14
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c108
-rw-r--r--src/pal/tests/palsuite/file_io/SetFileTime/test4/testinfo.dat14
13 files changed, 545 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/CMakeLists.txt
new file mode 100644
index 0000000000..a3847f8ca9
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+add_subdirectory(test4)
+
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt
new file mode 100644
index 0000000000..4c4b5d7611
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ SetFileTime.c
+)
+
+add_executable(paltest_setfiletime_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfiletime_test1 coreclrpal)
+
+target_link_libraries(paltest_setfiletime_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c
new file mode 100644
index 0000000000..4711aeba89
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test1/SetFileTime.c
@@ -0,0 +1,129 @@
+// 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: SetFileTime.c
+**
+** Purpose: Tests the PAL implementation of the SetFileTime function.
+** This test first sets a valid file time on the file which is opened.
+** Then it calls GetFileTime, and compares the values. They should
+** be the same. Note: Access time isn't checked in this test. It will
+** be dealt with seperatly due to odd behaviour.
+**
+** Depends:
+** CreateFile
+** GetFileTime
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+int __cdecl main(int argc, char **argv)
+{
+
+#if WIN32
+ FILETIME Creation;
+ FILETIME SetCreation;
+#endif
+ FILETIME LastWrite;
+ FILETIME SetLastWrite;
+ HANDLE TheFileHandle;
+ BOOL result;
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* Populate some FILETIME structures with values
+ These values are valid Creation, Access and Write times
+ which I generated, and should work properly.
+ */
+#if WIN32
+ SetCreation.dwLowDateTime = 458108416;
+ SetCreation.dwHighDateTime = 29436904;
+#endif
+
+ SetLastWrite.dwLowDateTime = -1995099136;
+ SetLastWrite.dwHighDateTime = 29436915;
+
+
+ /* Open the file to get a HANDLE */
+ TheFileHandle = CreateFile("the_file",
+ GENERIC_READ|GENERIC_WRITE,
+ 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.\n",GetLastError());
+ }
+
+ /* Set the new file time */
+#if WIN32
+ result = SetFileTime(TheFileHandle,
+ &SetCreation, NULL, &SetLastWrite);
+#else
+ result = SetFileTime(TheFileHandle,
+ NULL, NULL, &SetLastWrite);
+#endif
+ if(result == 0)
+ {
+ Fail("ERROR: SetFileTime failed when trying to set the "
+ "new file time. The GetLastError was %d.\n",GetLastError());
+ }
+
+
+ /* Then get the file time of the file */
+#if WIN32
+ result = GetFileTime(TheFileHandle, &Creation, NULL, &LastWrite);
+#else
+ result = GetFileTime(TheFileHandle, NULL, NULL, &LastWrite);
+#endif
+
+ if(result == 0)
+ {
+ Fail("ERROR: GetFileTime failed, and this tests depends "
+ "upon it working properly, in order to ensure that the "
+ "file time was set with SetFileTime. GetLastError() "
+ "returned %d.\n",GetLastError());
+ }
+
+ /* Compare the write time we Set to the write time aquired with
+ Get. They should be the same.
+ */
+
+ if(LastWrite.dwLowDateTime != SetLastWrite.dwLowDateTime ||
+ LastWrite.dwHighDateTime != SetLastWrite.dwHighDateTime)
+ {
+ Fail("ERROR: After setting the write time, it is not "
+ "equal to what it was set to. Either Set of GetFileTime are "
+ "broken.\n");
+ }
+
+ /* Within FreeBSD, the Creation time is ignored when SetFileTime
+ is called. Since FreeBSD has no equivalent. For that reason,
+ it is not checked with the following test.
+ */
+
+#if WIN32
+ if(Creation.dwHighDateTime != SetCreation.dwHighDateTime ||
+ Creation.dwLowDateTime != SetCreation.dwLowDateTime)
+ {
+ Fail("ERROR: After setting the file time, the Creation "
+ "time is not what it should be. Either Set or GetFileTime "
+ "are broken.");
+ }
+#endif
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileTime/test1/testinfo.dat
new file mode 100644
index 0000000000..09dfa0b623
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test1/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = file_io
+Function = SetFileTime
+Name = Positive Test for SetFileTime
+TYPE = DEFAULT
+EXE1 = setfiletime
+Description
+= Test the SetFileTime function.
+= This test calls SetFileTime and sets a file to a given time. It then
+= calls GetFileTime, and compares the values of the two, which should be
+= equal
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt
new file mode 100644
index 0000000000..35c18c8d8d
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ SetFileTime.c
+)
+
+add_executable(paltest_setfiletime_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfiletime_test2 coreclrpal)
+
+target_link_libraries(paltest_setfiletime_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c
new file mode 100644
index 0000000000..e950153bb0
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test2/SetFileTime.c
@@ -0,0 +1,101 @@
+// 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: SetFileTime.c
+**
+** Purpose: Tests the PAL implementation of the SetFileTime
+** This test first tries to SetFileTime on a HANDLE which doesn't have
+** GENERIC_WRITE set, which should fail.
+**
+**
+** Depends:
+** CreateFile
+** CloseHandle
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILETIME SetCreation,SetLastAccess,SetLastWrite;
+ HANDLE TheFileHandle;
+ BOOL result;
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* Populate some FILETIME structures with values
+ These values are valid Creation, Access and Write times
+ which I generated, and should work properly.
+
+ The access times are not seperated into WIN32 and FreeBSD here,
+ but it should be fine, as no comparisons are being done in this
+ test.
+ */
+
+ SetCreation.dwLowDateTime = 458108416;
+ SetCreation.dwHighDateTime = 29436904;
+
+ SetLastAccess.dwLowDateTime = 341368832;
+ SetLastAccess.dwHighDateTime = 29436808;
+
+ SetLastWrite.dwLowDateTime = -1995099136;
+ SetLastWrite.dwHighDateTime = 29436915;
+
+
+/* Open the file to get a HANDLE, without GENERIC WRITE */
+
+ 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());
+ }
+
+ /* This SetFileTime should fail, because the HANDLE isn't set with
+ GENERIC_WRITE
+ */
+ result = SetFileTime(TheFileHandle,
+ &SetCreation,&SetLastAccess,&SetLastWrite);
+
+ if(result != 0)
+ {
+ Fail("ERROR: SetFileTime should have failed, but returned a "
+ "non-zero result. The File HANDLE passed was no set Writable "
+ "which should cause failure.");
+ }
+
+ result = CloseHandle(TheFileHandle);
+
+ if(result == 0)
+ {
+ Fail("ERROR: CloseHandle failed. This test depends upon "
+ "it working.");
+ }
+
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test2/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileTime/test2/testinfo.dat
new file mode 100644
index 0000000000..f1699facaf
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test2/testinfo.dat
@@ -0,0 +1,15 @@
+# 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.
+
+Version = 1.0
+Section = file_io
+Function = SetFileTime
+Name = Negative Test for SetFileTime
+TYPE = DEFAULT
+EXE1 = setfiletime
+Description
+= Test the SetFileTime function.
+= This test first tries to SetFileTime on a HANDLE which doesn't have
+= GENERIC_WRITE set, which should fail. Then it attempts to set the file
+= time with bad FILETIME structures, which should also fail
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt
new file mode 100644
index 0000000000..0a85d30c51
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ SetFileTime.c
+)
+
+add_executable(paltest_setfiletime_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfiletime_test3 coreclrpal)
+
+target_link_libraries(paltest_setfiletime_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c
new file mode 100644
index 0000000000..97f49495d7
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test3/SetFileTime.c
@@ -0,0 +1,66 @@
+// 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: SetFileTime.c
+**
+** Purpose: Tests the PAL implementation of the SetFileTime function.
+** This test checks to ensure that the function fails when passed an
+** invalid file HANDLE
+**
+**
+**===================================================================*/
+
+
+
+#include <palsuite.h>
+
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+
+ FILETIME SetCreation, SetLastWrite, SetLastAccess;
+ HANDLE TheFileHandle = NULL;
+ BOOL result;
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* Populate some FILETIME structures with values
+ These values are valid Creation, Access and Write times
+ which I generated, and should work properly.
+ */
+
+ SetCreation.dwLowDateTime = 458108416;
+ SetCreation.dwHighDateTime = 29436904;
+
+ SetLastAccess.dwLowDateTime = 341368832;
+ SetLastAccess.dwHighDateTime = 29436808;
+
+ SetLastWrite.dwLowDateTime = -1995099136;
+ SetLastWrite.dwHighDateTime = 29436915;
+
+
+ /* Pass this function an invalid file HANDLE and it should
+ fail.
+ */
+
+ result = SetFileTime(TheFileHandle,
+ &SetCreation,&SetLastAccess,&SetLastWrite);
+
+ if(result != 0)
+ {
+ Fail("ERROR: Passed an invalid file HANDLE to SetFileTime, but it "
+ "returned non-zero. This should return zero for failure.");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test3/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileTime/test3/testinfo.dat
new file mode 100644
index 0000000000..e27280469e
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test3/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = file_io
+Function = SetFileTime
+Name = Negative Test for SetFileTime
+TYPE = DEFAULT
+EXE1 = setfiletime
+Description
+= Test the SetFileTime function.
+= This test checks to ensure that the function fails when passed an
+= invalid file HANDLE
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt b/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt
new file mode 100644
index 0000000000..086e35e535
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test4/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ SetFileTime.c
+)
+
+add_executable(paltest_setfiletime_test4
+ ${SOURCES}
+)
+
+add_dependencies(paltest_setfiletime_test4 coreclrpal)
+
+target_link_libraries(paltest_setfiletime_test4
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c b/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c
new file mode 100644
index 0000000000..3edd2403c4
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test4/SetFileTime.c
@@ -0,0 +1,108 @@
+// 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: SetFileTime.c
+**
+** Purpose: Tests the PAL implementation of the SetFileTime function
+** This passes a variety of NULL values as parameters to the function.
+** It should still succeed.
+**
+** Depends:
+** CreateFile
+**
+
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+#if WIN32
+ FILETIME Creation;
+#endif
+ FILETIME LastWrite,LastAccess;
+ HANDLE TheFileHandle;
+
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ /* Populate some FILETIME structures with values
+ These values are valid Creation, Access and Write times
+ which I generated, and should work properly.
+
+ These values aren't being used for comparison, so they should
+ work ok, even though they weren't generated specifically for
+ FreeBSD or WIN32 ...
+ */
+#if WIN32
+ Creation.dwLowDateTime = 458108416;
+ Creation.dwHighDateTime = 29436904;
+#endif
+ LastAccess.dwLowDateTime = 341368832;
+ LastAccess.dwHighDateTime = 29436808;
+
+ LastWrite.dwLowDateTime = -1995099136;
+ LastWrite.dwHighDateTime = 29436915;
+
+ /* Open the file to get a HANDLE */
+ TheFileHandle =
+ CreateFile(
+ "the_file",
+ GENERIC_READ|GENERIC_WRITE,
+ 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());
+ }
+
+ /* Pass all NULLs, this is useless but should still work. */
+ if(SetFileTime(TheFileHandle,NULL,NULL,NULL)==0)
+ {
+ Fail("ERROR: SetFileTime returned 0, indicating failure. "
+ "Three of the params were NULL in this case, did they "
+ "cause the problem?");
+ }
+
+#if WIN32
+ /* Set the Creation time of the File */
+ if(SetFileTime(TheFileHandle,&Creation,NULL,NULL)==0)
+ {
+ Fail("ERROR: SetFileTime returned 0, indicating failure. "
+ "Two of the params were NULL in this case, did they "
+ "cause the problem?");
+ }
+#endif
+
+#if WIN32
+ /* Set the Creation, LastWrite time of the File */
+ if(SetFileTime(TheFileHandle,&Creation,&LastWrite,NULL)==0)
+#else
+ /* Set the LastWrite time of the File */
+ if(SetFileTime(TheFileHandle,NULL,&LastWrite,NULL)==0)
+#endif
+ {
+ Fail("ERROR: SetFileTime returned 0, indicating failure. "
+ "One of the params were NULL in this case, did it "
+ "cause the problem?");
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/SetFileTime/test4/testinfo.dat b/src/pal/tests/palsuite/file_io/SetFileTime/test4/testinfo.dat
new file mode 100644
index 0000000000..a3dfdd02f0
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/SetFileTime/test4/testinfo.dat
@@ -0,0 +1,14 @@
+# 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.
+
+Version = 1.0
+Section = file_io
+Function = SetFileTime
+Name = Positive Test for SetFileTime
+TYPE = DEFAULT
+EXE1 = setfiletime
+Description
+= Test the SetFileTime function.
+= This passes a variety of NULL values as parameters to the function.
+= It should still succeed