ReactOS  0.4.14-dev-608-gd495a4f
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 }

Referenced by test_pRtlTimeToTimeFields().

◆ 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 }
static void test_NtGetTickCount(void)
Definition: time.c:234
static void test_NtQueryPerformanceCounter(void)
Definition: time.c:178
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:821
static void test_pRtlTimeToTimeFields(void)
Definition: time.c:125
static void test_RtlQueryTimeZoneInformation(void)
Definition: time.c:198
#define GetProcAddress(x, y)
Definition: compat.h:418
#define win_skip
Definition: test.h:150
static int mod
Definition: i386-dis.c:1273

◆ 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 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
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
#define ok(value,...)
Definition: atltest.h:57
#define win_skip
Definition: test.h:150

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
smooth NULL
Definition: ftsmooth.c:416
GLuint counter
Definition: glext.h:11116
static LARGE_INTEGER * frequency
Definition: time.c:106
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define ok(value,...)
Definition: atltest.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
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 }
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
#define TICKSPERSEC
Definition: time.c:100
int64_t LONGLONG
Definition: typedefs.h:66
uint64_t ULONGLONG
Definition: typedefs.h:65
static const int MonthLengths[2][12]
Definition: time.c:111
#define SECSPERDAY
Definition: time.c:102
static BOOL IsLeapYear(int Year)
Definition: time.c:117
static TIME_FIELDS tftest
Definition: time.c:123
#define ok(value,...)
Definition: atltest.h:57
LONGLONG QuadPart
Definition: typedefs.h:112

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",
217  wine_dbgstr_w(tzinfo.StandardName));
218  todo_wine ok(tzinfo.DaylightName[0] == '@',
219  "daylight time zone name isn't an indirect string, got %s\n",
220  wine_dbgstr_w(tzinfo.DaylightName));
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",
228  wine_dbgstr_w(tzinfo.StandardName));
229  todo_wine ok(tzinfo.DaylightName[0] == '@',
230  "daylight time zone name isn't an indirect string, got %s\n",
231  wine_dbgstr_w(tzinfo.DaylightName));
232 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
LONG NTSTATUS
Definition: precomp.h:26
#define todo_wine
Definition: test.h:163
#define ok(value,...)
Definition: atltest.h:57
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
static SERVICE_STATUS status
Definition: service.c:31
#define win_skip
Definition: test.h:150
Definition: ps.c:97

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 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(), CKsClockForwarder_ThreadStartup(), 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(), KeUpdateSystemTime(), 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(), SetLocalSystemTime(), SetScreenSaver(), SignalObjectAndWait(), SleepConditionVariableCS(), SleepConditionVariableSRW(), SleepEx(), START_TEST(), TdiDisconnect(), Time2Str(), TimeToMsString(), USBPORT_StartTimer(), WaitForMultipleObjectsEx(), WaitForSingleObjectEx(), WdmAudGetWavePositionByLegacy(), and xclip_handle_SelectionNotify().

◆ TimeFields