summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/file_io/FileTimeToDosDateTime')
-rw-r--r--src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c116
-rw-r--r--src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/testinfo.dat15
4 files changed, 154 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt
new file mode 100644
index 0000000000..131054266b
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_filetimetodosdatetime_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_filetimetodosdatetime_test1 coreclrpal)
+
+target_link_libraries(paltest_filetimetodosdatetime_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c
new file mode 100644
index 0000000000..5f2c81ff98
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/test1.c
@@ -0,0 +1,116 @@
+// 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: test1.c
+**
+** Purpose: Tests that FileTimeToDosDateTime successfully converts values.
+** Makes sure values are rounded up, and the limits of the function
+** pass. Also tests that values outside the valid range fail.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+typedef struct
+{
+ DWORD FileTimeLow;
+ DWORD FileTimeHigh;
+ WORD FatDate;
+ WORD FatTime;
+} testCase;
+
+int __cdecl main(int argc, char **argv)
+{
+ FILETIME FileTime;
+ WORD ResultDate;
+ WORD ResultTime;
+ BOOL ret;
+ int i;
+
+ testCase testCases[] =
+ {
+ /* Test a normal time */
+ {0x9BE00100, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/
+ /* Test that 12/15/2000, 10:45:29 Gets rounded up */
+ {0x9B476A80, 0x1B4A02C, 0x14CF, 0x55AF}, /* 12/15/2000, 10:45:30 AM*/
+ /* Test that 12/15/2000, 10:45:31 Gets rounded up */
+ {0x9C789780, 0x1B4A02C, 0x14CF, 0x55B0}, /* 12/15/2000, 10:45:32 AM*/
+
+ /* Test the upper and lower limits of the function */
+ {0xE1D58000, 0x1A8E79F, 0x0021, 0x0000}, /* 1/1/1980, 12:00:00 AM*/
+ {0xb9de1300, 0x1e9eede, 0x739f, 0xbf7d}, /* 12/31/2037, 11:59:58 PM*/
+
+ /* Tests that should fail */
+ {0, 0, 0, 0},
+ {0xE0A45300, 0x1A8E79F, 0, 0},
+ {0x66D29301, 0x23868B8, 0, 0}
+
+ /* All this accomplishes is for the date to overflow.
+ Likely the only reason it fails in Windows is bacause the
+ resulting date falls outside of the legal range. Under BSD,
+ it falls into a legal range. This being that BSD calculates time
+ from 1900 to 2037, not 1980 to 2107.
+ {0xFFFFFFFF, 0xFFFFFFF, 0, 0}
+ */
+ };
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ for (i=0; i<sizeof(testCases) / sizeof(testCase); i++)
+ {
+ ResultDate = 0xFFFF;
+ ResultTime = 0xFFFF;
+
+ FileTime.dwLowDateTime = testCases[i].FileTimeLow;
+ FileTime.dwHighDateTime = testCases[i].FileTimeHigh;
+
+
+ ret = FileTimeToDosDateTime(&FileTime, &ResultDate, &ResultTime);
+ if (testCases[i].FatDate != 0 || testCases[i].FatTime != 0)
+ {
+ /* Expected it to pass */
+ if (!ret)
+ {
+ Fail("FileTimeToDosDateTime failed for %X,%X!\n",
+ testCases[i].FileTimeLow, testCases[i].FileTimeHigh);
+ }
+
+ if (ResultDate != testCases[i].FatDate ||
+ ResultTime != testCases[i].FatTime)
+ {
+ Fail("FileTimeToDosDateTime did not convert %X,%X "
+ "successfully:\nExpected date to be %hX, time %hx.\n"
+ "Got %hX, %hX\n", testCases[i].FileTimeLow,
+ testCases[i].FileTimeHigh, testCases[i].FatDate,
+ testCases[i].FatTime, ResultDate, ResultTime);
+ }
+ }
+ else
+ {
+ /* Expected it to fail. */
+ if (ret)
+ {
+ Fail("FileTimeToDosDateTime passed for %X,%X!\n",
+ testCases[i].FileTimeLow, testCases[i].FileTimeHigh);
+ }
+
+ if (ResultDate != 0xFFFF || ResultTime != 0xFFFF)
+ {
+ Fail("FileTimeToDosDateTime failed, but modified output "
+ "parameters: %X %X\n", ResultDate, ResultTime);
+ }
+ }
+
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+
diff --git a/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/test1/testinfo.dat
new file mode 100644
index 0000000000..b5c7e1ae52
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/FileTimeToDosDateTime/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 = FileTimeToDosDateTime
+Name = Positive Test #1 for FileTimeToDosDateTime
+TYPE = DEFAULT
+EXE1 = test1
+Description
+=Tests that FileTimeToDosDateTime successfully converts values.
+=Makes sure values are rounded up, and the limits of the function
+=pass. Also tests that values outside the valid range fail.
+