summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp')
-rw-r--r--src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp
new file mode 100644
index 0000000000..361dbef33d
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetSystemTime/test1/test.cpp
@@ -0,0 +1,124 @@
+// 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: test.c
+**
+** Purpose: Test for GetSystemTime() function
+**
+**
+**=========================================================*/
+
+/* Note: Some of the range comparisons only check
+ * the high end of the range. Since the structure
+ * contains WORDs, negative values can never be included,
+ * so there is no reason to check and see if the lower
+ * end of the spectrum is <0
+*/
+
+#include <palsuite.h>
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ SYSTEMTIME TheTime;
+ SYSTEMTIME firstTime;
+ SYSTEMTIME secondTime;
+
+ WORD avgDeltaFileTime = 0;
+
+ int i=0;
+
+
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ GetSystemTime(&TheTime);
+
+ /* Go through each item in the structure and ensure it is a valid value.
+ We can't ensure they have the exact values of the current time, but
+ at least that they have been set to a valid range of values for that
+ item.
+ */
+
+ /* Year */
+ if(TheTime.wYear < (WORD)2001)
+ {
+ Fail("ERROR: The year is %d, when it should be at least 2001.",
+ TheTime.wYear);
+ }
+
+ /* Month */
+ if(TheTime.wMonth > (WORD)12 || TheTime.wMonth < (WORD)1)
+ {
+ Fail("ERROR: The month should be between 1 and 12, and it is "
+ "showing up as %d.",TheTime.wMonth);
+ }
+
+ /* Weekday */
+ if(TheTime.wDayOfWeek > 6)
+ {
+ Fail("ERROR: The day of the week should be between 0 and 6, "
+ "and it is showing up as %d.",TheTime.wDayOfWeek);
+ }
+
+ /* Day of the Month */
+ if(TheTime.wDay > 31 || TheTime.wDay < 1)
+ {
+ Fail("ERROR: The day of the month should be between 1 and "
+ "31, and it is showing up as %d.",TheTime.wDay);
+ }
+
+ /* Hour */
+ if(TheTime.wHour > 23)
+ {
+ Fail("ERROR: The hour should be between 0 and 23, and it is "
+ "showing up as %d.",TheTime.wHour);
+ }
+
+ /* Minute */
+ if(TheTime.wMinute > 59)
+ {
+ Fail("ERROR: The minute should be between 0 and 59 and it is "
+ "showing up as %d.",TheTime.wMinute);
+ }
+
+ /* Second */
+ if(TheTime.wSecond > 59)
+ {
+ Fail("ERROR: The second should be between 0 and 59 and it is"
+ " showing up as %d.",TheTime.wSecond);
+ }
+
+ /* Millisecond */
+ if(TheTime.wMilliseconds > 999)
+ {
+ Fail("ERROR: The milliseconds should be between 0 and 999 "
+ "and it is currently showing %d.",TheTime.wMilliseconds);
+ }
+
+ /* check if two consecutive calls to system time return */
+ /* correct time in ms after sleep() call. */
+ for (i = 0; i<5 ;i++)
+ {
+ GetSystemTime(&firstTime);
+ Sleep(1000);
+ GetSystemTime(&secondTime);
+ avgDeltaFileTime += abs(firstTime.wSecond - secondTime.wSecond );
+
+ }
+
+ if( (avgDeltaFileTime/5) < 1.0)
+ {
+ Fail("ERROR: 2 calls for GetSystemTime interrupted"
+ " by a 1000 ms sleep failed Value[%f]", avgDeltaFileTime/5 );
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
+