1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================ |
6 | ** |
7 | ** Source: test.c |
8 | ** |
9 | ** Purpose: Test for GetSystemTime() function |
10 | ** |
11 | ** |
12 | **=========================================================*/ |
13 | |
14 | /* Note: Some of the range comparisons only check |
15 | * the high end of the range. Since the structure |
16 | * contains WORDs, negative values can never be included, |
17 | * so there is no reason to check and see if the lower |
18 | * end of the spectrum is <0 |
19 | */ |
20 | |
21 | #include <palsuite.h> |
22 | |
23 | |
24 | int __cdecl main(int argc, char *argv[]) |
25 | { |
26 | SYSTEMTIME TheTime; |
27 | SYSTEMTIME firstTime; |
28 | SYSTEMTIME secondTime; |
29 | |
30 | WORD avgDeltaFileTime = 0; |
31 | |
32 | int i=0; |
33 | |
34 | |
35 | if (0 != PAL_Initialize(argc,argv)) |
36 | { |
37 | return FAIL; |
38 | } |
39 | |
40 | GetSystemTime(&TheTime); |
41 | |
42 | /* Go through each item in the structure and ensure it is a valid value. |
43 | We can't ensure they have the exact values of the current time, but |
44 | at least that they have been set to a valid range of values for that |
45 | item. |
46 | */ |
47 | |
48 | /* Year */ |
49 | if(TheTime.wYear < (WORD)2001) |
50 | { |
51 | Fail("ERROR: The year is %d, when it should be at least 2001." , |
52 | TheTime.wYear); |
53 | } |
54 | |
55 | /* Month */ |
56 | if(TheTime.wMonth > (WORD)12 || TheTime.wMonth < (WORD)1) |
57 | { |
58 | Fail("ERROR: The month should be between 1 and 12, and it is " |
59 | "showing up as %d." ,TheTime.wMonth); |
60 | } |
61 | |
62 | /* Weekday */ |
63 | if(TheTime.wDayOfWeek > 6) |
64 | { |
65 | Fail("ERROR: The day of the week should be between 0 and 6, " |
66 | "and it is showing up as %d." ,TheTime.wDayOfWeek); |
67 | } |
68 | |
69 | /* Day of the Month */ |
70 | if(TheTime.wDay > 31 || TheTime.wDay < 1) |
71 | { |
72 | Fail("ERROR: The day of the month should be between 1 and " |
73 | "31, and it is showing up as %d." ,TheTime.wDay); |
74 | } |
75 | |
76 | /* Hour */ |
77 | if(TheTime.wHour > 23) |
78 | { |
79 | Fail("ERROR: The hour should be between 0 and 23, and it is " |
80 | "showing up as %d." ,TheTime.wHour); |
81 | } |
82 | |
83 | /* Minute */ |
84 | if(TheTime.wMinute > 59) |
85 | { |
86 | Fail("ERROR: The minute should be between 0 and 59 and it is " |
87 | "showing up as %d." ,TheTime.wMinute); |
88 | } |
89 | |
90 | /* Second */ |
91 | if(TheTime.wSecond > 59) |
92 | { |
93 | Fail("ERROR: The second should be between 0 and 59 and it is" |
94 | " showing up as %d." ,TheTime.wSecond); |
95 | } |
96 | |
97 | /* Millisecond */ |
98 | if(TheTime.wMilliseconds > 999) |
99 | { |
100 | Fail("ERROR: The milliseconds should be between 0 and 999 " |
101 | "and it is currently showing %d." ,TheTime.wMilliseconds); |
102 | } |
103 | |
104 | /* check if two consecutive calls to system time return */ |
105 | /* correct time in ms after sleep() call. */ |
106 | for (i = 0; i<5 ;i++) |
107 | { |
108 | GetSystemTime(&firstTime); |
109 | Sleep(1000); |
110 | GetSystemTime(&secondTime); |
111 | avgDeltaFileTime += abs(firstTime.wSecond - secondTime.wSecond ); |
112 | |
113 | } |
114 | |
115 | if( (avgDeltaFileTime/5) < 1.0) |
116 | { |
117 | Fail("ERROR: 2 calls for GetSystemTime interrupted" |
118 | " by a 1000 ms sleep failed Value[%f]" , avgDeltaFileTime/5 ); |
119 | } |
120 | |
121 | PAL_Terminate(); |
122 | return PASS; |
123 | } |
124 | |
125 | |