rpcrt4: Store all active connections in RpcServerProtseq.
[wine.git] / dlls / ntdll / tests / time.c
blobb684bc1980d78731f84b129978af0bf2a6b621ec
1 /*
2 * Unit test suite for ntdll time functions
4 * Copyright 2004 Rein Klazes
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "ntdll_test.h"
23 #define TICKSPERSEC 10000000
24 #define TICKSPERMSEC 10000
25 #define SECSPERDAY 86400
27 static VOID (WINAPI *pRtlTimeToTimeFields)( const LARGE_INTEGER *liTime, PTIME_FIELDS TimeFields) ;
28 static VOID (WINAPI *pRtlTimeFieldsToTime)( PTIME_FIELDS TimeFields, PLARGE_INTEGER Time) ;
29 static NTSTATUS (WINAPI *pNtQueryPerformanceCounter)( LARGE_INTEGER *counter, LARGE_INTEGER *frequency );
31 static const int MonthLengths[2][12] =
33 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
34 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
37 static inline BOOL IsLeapYear(int Year)
39 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0);
42 /* start time of the tests */
43 static TIME_FIELDS tftest = {1889,12,31,23,59,59,0,0};
45 static void test_pRtlTimeToTimeFields(void)
47 LARGE_INTEGER litime , liresult;
48 TIME_FIELDS tfresult;
49 int i=0;
50 litime.QuadPart = ((ULONGLONG)0x0144017a << 32) | 0xf0b0a980;
51 while( tftest.Year < 2110 ) {
52 /* test at the last second of the month */
53 pRtlTimeToTimeFields( &litime, &tfresult);
54 ok( tfresult.Year == tftest.Year && tfresult.Month == tftest.Month &&
55 tfresult.Day == tftest.Day && tfresult.Hour == tftest.Hour &&
56 tfresult.Minute == tftest.Minute && tfresult.Second == tftest.Second,
57 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
58 tftest.Year, tftest.Month, tftest.Day,
59 tftest.Hour, tftest.Minute,tftest.Second,
60 tfresult.Year, tfresult.Month, tfresult.Day,
61 tfresult.Hour, tfresult.Minute, tfresult.Second);
62 /* test the inverse */
63 pRtlTimeFieldsToTime( &tfresult, &liresult);
64 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
65 tfresult.Year, tfresult.Month, tfresult.Day,
66 tfresult.Hour, tfresult.Minute, tfresult.Second,
67 (int) (liresult.QuadPart - litime.QuadPart) );
68 /* one second later is beginning of next month */
69 litime.QuadPart += TICKSPERSEC ;
70 pRtlTimeToTimeFields( &litime, &tfresult);
71 ok( tfresult.Year == tftest.Year + (tftest.Month ==12) &&
72 tfresult.Month == tftest.Month % 12 + 1 &&
73 tfresult.Day == 1 && tfresult.Hour == 0 &&
74 tfresult.Minute == 0 && tfresult.Second == 0,
75 "#%d expected: %d-%d-%d %d:%d:%d got: %d-%d-%d %d:%d:%d\n", ++i,
76 tftest.Year + (tftest.Month ==12),
77 tftest.Month % 12 + 1, 1, 0, 0, 0,
78 tfresult.Year, tfresult.Month, tfresult.Day,
79 tfresult.Hour, tfresult.Minute, tfresult.Second);
80 /* test the inverse */
81 pRtlTimeFieldsToTime( &tfresult, &liresult);
82 ok( liresult.QuadPart == litime.QuadPart," TimeFieldsToTime failed on %d-%d-%d %d:%d:%d. Error is %d ticks\n",
83 tfresult.Year, tfresult.Month, tfresult.Day,
84 tfresult.Hour, tfresult.Minute, tfresult.Second,
85 (int) (liresult.QuadPart - litime.QuadPart) );
86 /* advance to the end of the month */
87 litime.QuadPart -= TICKSPERSEC ;
88 if( tftest.Month == 12) {
89 tftest.Month = 1;
90 tftest.Year += 1;
91 } else
92 tftest.Month += 1;
93 tftest.Day = MonthLengths[IsLeapYear(tftest.Year)][tftest.Month - 1];
94 litime.QuadPart += (LONGLONG) tftest.Day * TICKSPERSEC * SECSPERDAY;
98 static void test_NtQueryPerformanceCounter(void)
100 LARGE_INTEGER counter, frequency;
101 NTSTATUS status;
103 status = pNtQueryPerformanceCounter(NULL, NULL);
104 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
105 status = pNtQueryPerformanceCounter(NULL, &frequency);
106 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
107 status = pNtQueryPerformanceCounter(&counter, (void *)0xdeadbee0);
108 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
109 status = pNtQueryPerformanceCounter((void *)0xdeadbee0, &frequency);
110 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %08x\n", status);
112 status = pNtQueryPerformanceCounter(&counter, NULL);
113 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
114 status = pNtQueryPerformanceCounter(&counter, &frequency);
115 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
118 START_TEST(time)
120 HMODULE mod = GetModuleHandleA("ntdll.dll");
121 pRtlTimeToTimeFields = (void *)GetProcAddress(mod,"RtlTimeToTimeFields");
122 pRtlTimeFieldsToTime = (void *)GetProcAddress(mod,"RtlTimeFieldsToTime");
123 pNtQueryPerformanceCounter = (void *)GetProcAddress(mod, "NtQueryPerformanceCounter");
124 if (pRtlTimeToTimeFields && pRtlTimeFieldsToTime)
125 test_pRtlTimeToTimeFields();
126 else
127 win_skip("Required time conversion functions are not available\n");
128 test_NtQueryPerformanceCounter();