ReactOS 0.4.16-dev-329-g9223134
time.c File Reference
#include "ntdll_test.h"
#include "ddk/wdm.h"
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define NONAMELESSUNION
 
#define TICKSPERSEC   10000000
 
#define TICKSPERMSEC   10000
 
#define SECSPERDAY   86400
 

Functions

static VOID (WINAPI *pRtlTimeToTimeFields)(const LARGE_INTEGER *liTime
 
static NTSTATUS (WINAPI *pNtQueryPerformanceCounter)(LARGE_INTEGER *counter
 
static ULONG (WINAPI *pNtGetTickCount)(void)
 
static BOOL IsLeapYear (int Year)
 
static void test_pRtlTimeToTimeFields (void)
 
static void test_NtQueryPerformanceCounter (void)
 
static void test_RtlQueryTimeZoneInformation (void)
 
static void test_NtGetTickCount (void)
 
 START_TEST (time)
 

Variables

static PTIME_FIELDS TimeFields
 
static PLARGE_INTEGER Time
 
static LARGE_INTEGERfrequency
 
static const int MonthLengths [2][12]
 
static TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0}
 

Macro Definition Documentation

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 22 of file time.c.

◆ SECSPERDAY

#define SECSPERDAY   86400

Definition at line 102 of file time.c.

◆ TICKSPERMSEC

#define TICKSPERMSEC   10000

Definition at line 101 of file time.c.

◆ TICKSPERSEC

#define TICKSPERSEC   10000000

Definition at line 100 of file time.c.

Function Documentation

◆ IsLeapYear()

static BOOL IsLeapYear ( int  Year)
inlinestatic

Definition at line 117 of file time.c.

118{
119 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
120}

◆ NTSTATUS()

static NTSTATUS ( WINAPI pNtQueryPerformanceCounter)
static

◆ START_TEST()

START_TEST ( time  )

Definition at line 257 of file time.c.

258{
259 HMODULE mod = GetModuleHandleA("ntdll.dll");
260 pRtlTimeToTimeFields = (void *)GetProcAddress(mod,"RtlTimeToTimeFields");
261 pRtlTimeFieldsToTime = (void *)GetProcAddress(mod,"RtlTimeFieldsToTime");
262 pNtQueryPerformanceCounter = (void *)GetProcAddress(mod, "NtQueryPerformanceCounter");
263 pNtGetTickCount = (void *)GetProcAddress(mod,"NtGetTickCount");
264 pRtlQueryTimeZoneInformation =
265 (void *)GetProcAddress(mod, "RtlQueryTimeZoneInformation");
266 pRtlQueryDynamicTimeZoneInformation =
267 (void *)GetProcAddress(mod, "RtlQueryDynamicTimeZoneInformation");
268
269 if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
271 else
272 win_skip("Required time conversion functions are not available\n");
276}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void test_NtQueryPerformanceCounter(void)
Definition: time.c:178
static void test_pRtlTimeToTimeFields(void)
Definition: time.c:125
static void test_NtGetTickCount(void)
Definition: time.c:234
static void test_RtlQueryTimeZoneInformation(void)
Definition: time.c:198
#define win_skip
Definition: test.h:163

◆ test_NtGetTickCount()

static void test_NtGetTickCount ( void  )
static

Definition at line 234 of file time.c.

235{
236#ifndef _WIN64
237 KSHARED_USER_DATA *user_shared_data = (void *)0x7ffe0000;
238 LONG diff;
239 int i;
240
241 if (!pNtGetTickCount)
242 {
243 win_skip("NtGetTickCount is not available\n");
244 return;
245 }
246
247 for (i = 0; i < 5; ++i)
248 {
249 diff = (user_shared_data->TickCountQuad * user_shared_data->TickCountMultiplier) >> 24;
250 diff = pNtGetTickCount() - diff;
251 ok(diff < 32, "NtGetTickCount - TickCountQuad too high, expected < 32 got %d\n", diff);
252 Sleep(50);
253 }
254#endif
255}
#define ok(value,...)
Definition: atltest.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

Referenced by START_TEST().

◆ test_NtQueryPerformanceCounter()

static void test_NtQueryPerformanceCounter ( void  )
static

Definition at line 178 of file time.c.

179{
182
183 status = pNtQueryPerformanceCounter(NULL, NULL);
184 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
185 status = pNtQueryPerformanceCounter(NULL, &frequency);
186 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
187 status = pNtQueryPerformanceCounter(&counter, (void *)0xdeadbee0);
188 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
189 status = pNtQueryPerformanceCounter((void *)0xdeadbee0, &frequency);
190 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
191
192 status = pNtQueryPerformanceCounter(&counter, NULL);
193 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
194 status = pNtQueryPerformanceCounter(&counter, &frequency);
195 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
196}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
static LARGE_INTEGER * frequency
Definition: time.c:106
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ps.c:97

Referenced by START_TEST().

◆ test_pRtlTimeToTimeFields()

static void test_pRtlTimeToTimeFields ( void  )
static

Definition at line 125 of file time.c.

126{
127 LARGE_INTEGER litime , liresult;
128 TIME_FIELDS tfresult;
129 int i=0;
130 litime.QuadPart = ((ULONGLONG)0x0144017a << 32) | 0xf0b0a980;
131 while( tftest.Year < 2110 ) {
132 /* test at the last second of the month */
133 pRtlTimeToTimeFields( &litime, &tfresult);
134 ok( tfresult.Year == tftest.Year && tfresult.Month == tftest.Month &&
135 tfresult.Day == tftest.Day && tfresult.Hour == tftest.Hour &&
136 tfresult.Minute == tftest.Minute && tfresult.Second == tftest.Second,
137 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
140 tfresult.Year, tfresult.Month, tfresult.Day,
141 tfresult.Hour, tfresult.Minute, tfresult.Second);
142 /* test the inverse */
143 pRtlTimeFieldsToTime( &tfresult, &liresult);
144 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
145 tfresult.Year, tfresult.Month, tfresult.Day,
146 tfresult.Hour, tfresult.Minute, tfresult.Second,
147 (int) (liresult.QuadPart - litime.QuadPart) );
148 /* one second later is beginning of next month */
149 litime.QuadPart += TICKSPERSEC ;
150 pRtlTimeToTimeFields( &litime, &tfresult);
151 ok( tfresult.Year == tftest.Year + (tftest.Month ==12) &&
152 tfresult.Month == tftest.Month % 12 + 1 &&
153 tfresult.Day == 1 && tfresult.Hour == 0 &&
154 tfresult.Minute == 0 && tfresult.Second == 0,
155 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
156 tftest.Year + (tftest.Month ==12),
157 tftest.Month % 12 + 1, 1, 0, 0, 0,
158 tfresult.Year, tfresult.Month, tfresult.Day,
159 tfresult.Hour, tfresult.Minute, tfresult.Second);
160 /* test the inverse */
161 pRtlTimeFieldsToTime( &tfresult, &liresult);
162 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
163 tfresult.Year, tfresult.Month, tfresult.Day,
164 tfresult.Hour, tfresult.Minute, tfresult.Second,
165 (int) (liresult.QuadPart - litime.QuadPart) );
166 /* advance to the end of the month */
167 litime.QuadPart -= TICKSPERSEC ;
168 if( tftest.Month == 12) {
169 tftest.Month = 1;
170 tftest.Year += 1;
171 } else
172 tftest.Month += 1;
175 }
176}
#define TICKSPERSEC
Definition: time.c:40
#define SECSPERDAY
Definition: time.c:33
static TIME_FIELDS tftest
Definition: time.c:123
static const int MonthLengths[2][12]
Definition: time.c:111
int64_t LONGLONG
Definition: typedefs.h:68
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
#define IsLeapYear(y)
Definition: variant.c:1048

Referenced by START_TEST().

◆ test_RtlQueryTimeZoneInformation()

static void test_RtlQueryTimeZoneInformation ( void  )
static

Definition at line 198 of file time.c.

199{
202
203 /* test RtlQueryTimeZoneInformation returns an indirect string,
204 e.g. @tzres.dll,-32 (Vista or later) */
205 if (!pRtlQueryTimeZoneInformation || !pRtlQueryDynamicTimeZoneInformation)
206 {
207 win_skip("Time zone name tests requires Vista or later\n");
208 return;
209 }
210
211 memset(&tzinfo, 0, sizeof(tzinfo));
212 status = pRtlQueryDynamicTimeZoneInformation(&tzinfo);
214 "RtlQueryDynamicTimeZoneInformation failed, got %08x\n", status);
215 todo_wine ok(tzinfo.StandardName[0] == '@',
216 "standard time zone name isn't an indirect string, got %s\n",
218 todo_wine ok(tzinfo.DaylightName[0] == '@',
219 "daylight time zone name isn't an indirect string, got %s\n",
221
222 memset(&tzinfo, 0, sizeof(tzinfo));
223 status = pRtlQueryTimeZoneInformation((RTL_TIME_ZONE_INFORMATION *)&tzinfo);
225 "RtlQueryTimeZoneInformation failed, got %08x\n", status);
226 todo_wine ok(tzinfo.StandardName[0] == '@',
227 "standard time zone name isn't an indirect string, got %s\n",
229 todo_wine ok(tzinfo.DaylightName[0] == '@',
230 "daylight time zone name isn't an indirect string, got %s\n",
232}
#define wine_dbgstr_w
Definition: kernel32.h:34
#define todo_wine
Definition: custom.c:89
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ ULONG()

static ULONG ( WINAPI pNtGetTickCount)
static

◆ VOID()

static VOID ( WINAPI pRtlTimeToTimeFields) const
static

Variable Documentation

◆ frequency

◆ MonthLengths

const int MonthLengths[2][12]
static
Initial value:
=
{
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
}

Definition at line 111 of file time.c.

Referenced by RtlCutoverTimeToSystemTime(), RtlTimeFieldsToTime(), RtlTimeToTimeFields(), and test_pRtlTimeToTimeFields().

◆ tftest

TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0}
static

Definition at line 123 of file time.c.

Referenced by test_pRtlTimeToTimeFields().

◆ Time

Definition at line 105 of file time.c.

Referenced by _getsystime(), _setsystime(), clock(), ClockPropertyCorrelatedPhysicalTime(), ClockPropertyCorrelatedTime(), ClockPropertyPhysicalTime(), ClockPropertyTime(), CompBattQueryInformation(), CCabinet::ConvertDateAndTime(), ElfReportEventA(), ElfReportEventAndSourceW(), ElfReportEventW(), ElfrIntReportEventW(), ElfrReportEventA(), ElfrReportEventAndSourceW(), ElfrReportEventW(), ExpAllocateUuids(), ExpUuidGetValues(), ExUuidCreate(), FatConstructDirent(), FatFatDateToNtTime(), FatFatTimeToNtTime(), FatGetCurrentFatTime(), FatSwapDirEntry(), FatSwapFatXDirEntry(), FormatDateTime(), FrLdrHeapAllocateEx(), FrLdrHeapFreeEx(), GdiSAPCallback(), GetCurrentDayOfMonth(), GetCurrentTimeInSeconds(), GetLocalSystemTime(), GetNtTimeout(), GetQueuedCompletionStatus(), GetTimeAsJobTime(), GetTimeInSeconds(), HalQueryRealTimeClock(), HalSetRealTimeClock(), Host_Sleep(), IntDispatchMessage(), JobTimeToTimeString(), KiCheckForTimerExpiration(), KiTimerExpiration(), KsGetDefaultClockTime(), CKsProxy::KsGetPhysicalTime(), CKsProxy::KsGetTime(), KspBusWorkerRoutine(), KsServiceBusEnumCreateRequest(), KsServiceBusEnumPnpRequest(), KsSetDefaultClockTime(), CKsProxy::KsSetPhysicalTime(), CKsProxy::KsSetTime(), LogfAllocAndBuildNewRecord(), LogfReportEvent(), LsarCreateSecret(), LsarSetSecret(), LsarStorePrivateData(), MmeGetPosition(), MonthCalSetLocalTime(), NetrRemoteTOD(), NtAllocateUuids(), NtProcessStartup(), OnInitDialog(), ParseDate(), Ping(), PRINT_RECORD(), PrintDateTime(), PrintLocalTime(), ProcessPortMessage(), ProcessTest(), ProcessTimers(), QuerySystemTimeMs(), QueryTime(), ReportTimes(), RtlSecondsSince1970ToTime(), RtlSecondsSince1980ToTime(), RtlTimeFieldsToTime(), RtlTimeToElapsedTimeFields(), RtlTimeToSecondsSince1970(), RtlTimeToSecondsSince1980(), RtlTimeToTimeFields(), FxUsbDevice::SendSyncRequest(), FxUsbDevice::SendSyncUmUrb(), SetLocalSystemTime(), SetScreenSaver(), SignalObjectAndWait(), SleepConditionVariableCS(), SleepConditionVariableSRW(), SleepEx(), START_TEST(), TdiDisconnect(), Time2Str(), TimeToMsString(), USBPORT_StartTimer(), WaitForMultipleObjectsEx(), WaitForSingleObjectEx(), WDF_ABS_TIMEOUT_IN_MS(), WDF_ABS_TIMEOUT_IN_SEC(), WDF_ABS_TIMEOUT_IN_US(), WDF_REL_TIMEOUT_IN_MS(), WDF_REL_TIMEOUT_IN_SEC(), WDF_REL_TIMEOUT_IN_US(), WdmAudGetWavePositionByLegacy(), WdmAudGetWavePositionByMMixer(), and xclip_handle_SelectionNotify().

◆ TimeFields