Sort entry points alphabetically.
[wine] / dlls / ntdll / tests / info.c
1 /* Unit test suite for *Information* Registry API functions
2  *
3  * Copyright 2005 Paul Vriens
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include "ntdll_test.h"
22
23 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
24 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
25
26 static HMODULE hntdll = 0;
27
28 /* one_before_last_pid is used to be able to compare values of a still running process
29    with the output of the test_query_process_times and test_query_process_handlecount tests.
30 */
31 static DWORD one_before_last_pid = 0;
32
33 #define NTDLL_GET_PROC(func) \
34     p ## func = (void*)GetProcAddress(hntdll, #func); \
35     if(!p ## func) { \
36       trace("GetProcAddress(%s) failed\n", #func); \
37       FreeLibrary(hntdll); \
38       return FALSE; \
39     }
40
41 static BOOL InitFunctionPtrs(void)
42 {
43     hntdll = LoadLibraryA("ntdll.dll");
44     if(!hntdll) {
45       trace("Could not load ntdll.dll\n");
46       return FALSE;
47     }
48     if (hntdll)
49     {
50       NTDLL_GET_PROC(NtQuerySystemInformation)
51       NTDLL_GET_PROC(NtQueryInformationProcess)
52     }
53     return TRUE;
54 }
55
56 static void test_query_basic(void)
57 {
58     DWORD status;
59     ULONG ReturnLength;
60     SYSTEM_BASIC_INFORMATION sbi;
61
62     /* This test also covers some basic parameter testing that should be the same for 
63      * every information class
64     */
65
66     /* Use a nonexistent info class */
67     trace("Check nonexistent info class\n");
68     status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
69     ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status);
70
71     /* Use an existing class but with a zero-length buffer */
72     trace("Check zero-length buffer\n");
73     status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
74     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
75
76     /* Use an existing class, correct length but no SystemInformation buffer */
77     trace("Check no SystemInformation buffer\n");
78     status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
79     ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
80
81     /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
82     trace("Check no ReturnLength pointer\n");
83     status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
84     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
85
86     /* Check a too large buffer size */
87     trace("Check a too large buffer size\n");
88     status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi) * 2, &ReturnLength);
89     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
90
91     /* Finally some correct calls */
92     trace("Check with correct parameters\n");
93     status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
94     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
95     ok( sizeof(sbi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sbi), ReturnLength);
96
97     /* Check if we have some return values */
98     trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
99     ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
100 }
101
102 static void test_query_cpu(void)
103 {
104     DWORD status;
105     ULONG ReturnLength;
106     SYSTEM_CPU_INFORMATION sci;
107
108     status = pNtQuerySystemInformation(SystemCpuInformation, &sci, sizeof(sci), &ReturnLength);
109     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
110     ok( sizeof(sci) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sci), ReturnLength);
111                                                                                                                        
112     /* Check if we have some return values */
113     trace("Processor FeatureSet : %08lx\n", sci.FeatureSet);
114     ok( sci.FeatureSet != 0, "Expected some features for this processor, got %08lx\n", sci.FeatureSet);
115 }
116
117 static void test_query_timeofday(void)
118 {
119     DWORD status;
120     ULONG ReturnLength;
121
122     /* Copy of our winternl.h structure turned into a private one */
123     typedef struct _SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE {
124         LARGE_INTEGER liKeBootTime;
125         LARGE_INTEGER liKeSystemTime;
126         LARGE_INTEGER liExpTimeZoneBias;
127         ULONG uCurrentTimeZoneId;
128         DWORD dwUnknown1[5];
129     } SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE, *PSYSTEM_TIMEOFDAY_INFORMATION_PRIVATE;
130
131     SYSTEM_TIMEOFDAY_INFORMATION_PRIVATE sti;
132   
133     /*  The struct size for NT (32 bytes) and Win2K/XP (48 bytes) differ.
134      *
135      *  Windows 2000 and XP return STATUS_INFO_LENGTH_MISMATCH if the given buffer size is greater
136      *  then 48 and 0 otherwise
137      *  Windows NT returns STATUS_INFO_LENGTH_MISMATCH when the given buffer size is not correct
138      *  and 0 otherwise
139      *
140      *  Windows 2000 and XP copy the given buffer size into the provided buffer, if the return code is STATUS_SUCCESS
141      *  NT only fills the buffer if the return code is STATUS_SUCCESS
142      *
143     */
144
145     status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
146
147     if (status == STATUS_INFO_LENGTH_MISMATCH)
148     {
149         trace("Windows version is NT, we have to cater for differences with W2K/WinXP\n");
150  
151         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
152         ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
153         ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
154
155         sti.uCurrentTimeZoneId = 0xdeadbeef;
156         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 28, &ReturnLength);
157         ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
158
159         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
160         ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
161         ok( 32 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
162     }
163     else
164     {
165         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 0, &ReturnLength);
166         ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
167         ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
168
169         sti.uCurrentTimeZoneId = 0xdeadbeef;
170         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 24, &ReturnLength);
171         ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
172         ok( 24 == ReturnLength, "ReturnLength should be 24, it is (%ld)\n", ReturnLength);
173         ok( 0xdeadbeef == sti.uCurrentTimeZoneId, "This part of the buffer should not have been filled\n");
174     
175         sti.uCurrentTimeZoneId = 0xdeadbeef;
176         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 32, &ReturnLength);
177         ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
178         ok( 32 == ReturnLength, "ReturnLength should be 32, it is (%ld)\n", ReturnLength);
179         ok( 0xdeadbeef != sti.uCurrentTimeZoneId, "Buffer should have been partially filled\n");
180     
181         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, 49, &ReturnLength);
182         ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
183         ok( 0 == ReturnLength, "ReturnLength should be 0, it is (%ld)\n", ReturnLength);
184     
185         status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &sti, sizeof(sti), &ReturnLength);
186         ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
187         ok( sizeof(sti) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(sti), ReturnLength);
188     }
189
190     /* Check if we have some return values */
191     trace("uCurrentTimeZoneId : (%ld)\n", sti.uCurrentTimeZoneId);
192 }
193
194 static void test_query_process(void)
195 {
196     DWORD status;
197     DWORD last_pid;
198     ULONG ReturnLength;
199     int i = 0, j = 0, k = 0;
200     int is_nt = 0;
201     SYSTEM_BASIC_INFORMATION sbi;
202
203     /* Copy of our winternl.h structure turned into a private one */
204     typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
205         DWORD dwOffset;
206         DWORD dwThreadCount;
207         DWORD dwUnknown1[6];
208         FILETIME ftCreationTime;
209         FILETIME ftUserTime;
210         FILETIME ftKernelTime;
211         UNICODE_STRING ProcessName;
212         DWORD dwBasePriority;
213         DWORD dwProcessID;
214         DWORD dwParentProcessID;
215         DWORD dwHandleCount;
216         DWORD dwUnknown3;
217         DWORD dwUnknown4;
218         VM_COUNTERS vmCounters;
219         IO_COUNTERS ioCounters;
220         SYSTEM_THREAD_INFORMATION ti[1];
221     } SYSTEM_PROCESS_INFORMATION_PRIVATE, *PSYSTEM_PROCESS_INFORMATION_PRIVATE;
222
223     ULONG SystemInformationLength = sizeof(SYSTEM_PROCESS_INFORMATION_PRIVATE);
224     SYSTEM_PROCESS_INFORMATION_PRIVATE* spi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
225
226     /* Only W2K3 returns the needed length, the rest returns 0, so we have to loop */
227
228     for (;;)
229     {
230         status = pNtQuerySystemInformation(SystemProcessInformation, spi, SystemInformationLength, &ReturnLength);
231
232         if (status != STATUS_INFO_LENGTH_MISMATCH) break;
233         
234         spi = HeapReAlloc(GetProcessHeap(), 0, spi , SystemInformationLength *= 2);
235     }
236
237     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
238
239     /* Get the first dwOffset, from this we can deduce the OS version we're running
240      *
241      * W2K/WinXP/W2K3:
242      *   dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
243      * NT:
244      *   dwOffset for a process is 136 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION)
245      * Wine (with every windows version):
246      *   dwOffset for a process is 0 if just this test is running
247      *   dwOffset for a process is 184 + (no. of threads) * sizeof(SYSTEM_THREAD_INFORMATION) +
248      *                             ProcessName.MaximumLength
249      *     if more wine processes are running
250      *
251      * Note : On windows the first process is in fact the Idle 'process' with a thread for every processor
252     */
253
254     pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
255
256     is_nt = ( spi->dwOffset - (sbi.NumberOfProcessors * sizeof(SYSTEM_THREAD_INFORMATION)) == 136);
257
258     if (is_nt) trace("Windows version is NT, we will skip thread tests\n");
259
260     /* Check if we have some return values
261      * 
262      * On windows there will be several processes running (Including the always present Idle and System)
263      * On wine we only have one (if this test is the only wine process running)
264     */
265     
266     /* Loop through the processes */
267
268     for (;;)
269     {
270         i++;
271
272         last_pid = spi->dwProcessID;
273
274         ok( spi->dwThreadCount > 0, "Expected some threads for this process, got 0\"");
275
276         /* Loop through the threads, skip NT4 for now */
277         
278         if (!is_nt)
279         {
280             for ( j = 0; j < spi->dwThreadCount; j++) 
281             {
282                 k++;
283                 ok ( spi->ti[j].dwOwningPID == spi->dwProcessID, 
284                      "The owning pid of the thread (%ld) doesn't equal the pid (%ld) of the process\n",
285                      spi->ti[j].dwOwningPID, spi->dwProcessID);
286             }
287         }
288
289         if (!spi->dwOffset) break;
290
291         one_before_last_pid = last_pid;
292                                                                                                                               
293         spi = (SYSTEM_PROCESS_INFORMATION_PRIVATE*)((char*)spi + spi->dwOffset);
294     }
295     trace("Total number of running processes : %d\n", i);
296     if (!is_nt) trace("Total number of running threads   : %d\n", k);
297
298     if (one_before_last_pid == 0) one_before_last_pid = last_pid;
299
300     HeapFree( GetProcessHeap(), 0, spi);
301 }
302
303 static void test_query_handle(void)
304 {
305     DWORD status;
306     ULONG ReturnLength;
307     ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
308     SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
309
310     /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
311     status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
312
313     /* The following check assumes more than one handle on any given system */
314     todo_wine
315     {
316         ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
317     }
318     ok( ReturnLength > 0, "Expected ReturnLength to be > 0, it was %ld\n", ReturnLength);
319
320     SystemInformationLength = ReturnLength;
321     shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
322     status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
323     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
324
325     /* Check if we have some return values */
326     trace("Number of Handles : %ld\n", shi->Count);
327     todo_wine
328     {
329         /* our implementation is a stub for now */
330         ok( shi->Count > 1, "Expected more than 1 handles, got (%ld)\n", shi->Count);
331     }
332
333     HeapFree( GetProcessHeap(), 0, shi);
334 }
335
336 static void test_query_process_basic(void)
337 {
338     DWORD status;
339     ULONG ReturnLength;
340
341     typedef struct _PROCESS_BASIC_INFORMATION_PRIVATE {
342         DWORD ExitStatus;
343         DWORD PebBaseAddress;
344         DWORD AffinityMask;
345         DWORD BasePriority;
346         ULONG UniqueProcessId;
347         ULONG InheritedFromUniqueProcessId;
348     } PROCESS_BASIC_INFORMATION_PRIVATE, *PPROCESS_BASIC_INFORMATION_PRIVATE;
349
350     PROCESS_BASIC_INFORMATION_PRIVATE pbi;
351
352     /* This test also covers some basic parameter testing that should be the same for
353      * every information class
354     */
355
356     /* Use a nonexistent info class */
357     trace("Check nonexistent info class\n");
358     status = pNtQueryInformationProcess(NULL, -1, NULL, 0, NULL);
359     ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status);
360
361     /* Do not give a handle and buffer */
362     trace("Check NULL handle and buffer and zero-length buffersize\n");
363     status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL);
364     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
365
366     /* Use a correct info class and buffer size, but still no handle and buffer */
367     trace("Check NULL handle and buffer\n");
368     status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(pbi), NULL);
369     ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
370         "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status);
371
372     /* Use a correct info class and buffer size, but still no handle */
373     trace("Check NULL handle\n");
374     status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
375     ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
376
377     /* Use a greater buffer size */
378     trace("Check NULL handle and too large buffersize\n");
379     status = pNtQueryInformationProcess(NULL, ProcessBasicInformation, &pbi, sizeof(pbi) * 2, NULL);
380     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
381
382     /* Use no ReturnLength */
383     trace("Check NULL ReturnLength\n");
384     status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
385     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
386
387     /* Finally some correct calls */
388     trace("Check with correct parameters\n");
389     status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &ReturnLength);
390     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
391     ok( sizeof(pbi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi), ReturnLength);
392
393     /* Everything is correct except a too large buffersize */
394     trace("Too large buffersize\n");
395     status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi) * 2, &ReturnLength);
396     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
397     ok( sizeof(pbi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pbi), ReturnLength);
398                                                                                                                                                
399     /* Check if we have some return values */
400     trace("ProcessID : %ld\n", pbi.UniqueProcessId);
401     ok( pbi.UniqueProcessId > 0, "Expected a ProcessID > 0, got 0\n");
402 }
403
404 static void test_query_process_vm(void)
405 {
406     DWORD status;
407     ULONG ReturnLength;
408     VM_COUNTERS pvi;
409
410     status = pNtQueryInformationProcess(NULL, ProcessVmCounters, NULL, sizeof(pvi), NULL);
411     ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
412         "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status);
413
414     status = pNtQueryInformationProcess(NULL, ProcessVmCounters, &pvi, sizeof(pvi), NULL);
415     ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
416
417     /* Windows XP and W2K3 will report success for a size of 44 AND 48 !
418        Windows W2K will only report success for 44.
419        For now we only care for 44, which is sizeof(VM_COUNTERS)
420        If an app depends on it, we have to implement this in ntdll/process.c
421     */
422
423     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 24, &ReturnLength);
424     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
425
426     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, sizeof(pvi), &ReturnLength);
427     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
428     ok( sizeof(pvi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pvi), ReturnLength);
429
430     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessVmCounters, &pvi, 46, &ReturnLength);
431     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
432     ok( sizeof(pvi) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pvi), ReturnLength);
433
434     /* Check if we have some return values */
435     trace("WorkingSetSize : %ld\n", pvi.WorkingSetSize);
436     todo_wine
437     {
438         ok( pvi.WorkingSetSize > 0, "Expected a WorkingSetSize > 0\n");
439     }
440 }
441
442 static void test_query_process_io(void)
443 {
444     DWORD status;
445     ULONG ReturnLength;
446     IO_COUNTERS pii;
447
448     status = pNtQueryInformationProcess(NULL, ProcessIoCounters, NULL, sizeof(pii), NULL);
449     ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
450         "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status);
451
452     status = pNtQueryInformationProcess(NULL, ProcessIoCounters, &pii, sizeof(pii), NULL);
453     ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
454
455     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, 24, &ReturnLength);
456     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
457
458     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii), &ReturnLength);
459     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
460     ok( sizeof(pii) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pii), ReturnLength);
461
462     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessIoCounters, &pii, sizeof(pii) * 2, &ReturnLength);
463     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
464     ok( sizeof(pii) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(pii), ReturnLength);
465
466     /* Check if we have some return values */
467     trace("OtherOperationCount : %lld\n", pii.OtherOperationCount);
468     todo_wine
469     {
470         ok( pii.OtherOperationCount > 0, "Expected an OtherOperationCount > 0\n");
471     }
472 }
473
474 static void test_query_process_times(void)
475 {
476     DWORD status;
477     ULONG ReturnLength;
478     HANDLE process;
479     SYSTEMTIME UTC, Local;
480     KERNEL_USER_TIMES spti;
481
482     status = pNtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(spti), NULL);
483     ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
484         "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status);
485
486     status = pNtQueryInformationProcess(NULL, ProcessTimes, &spti, sizeof(spti), NULL);
487     ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
488
489     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, 24, &ReturnLength);
490     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
491
492     process = OpenProcess (PROCESS_QUERY_INFORMATION, TRUE, one_before_last_pid);
493     trace("ProcessTimes for process with ID : %ld\n", one_before_last_pid);
494     status = pNtQueryInformationProcess( process, ProcessTimes, &spti, sizeof(spti), &ReturnLength);
495     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
496     ok( sizeof(spti) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spti), ReturnLength);
497     CloseHandle(process);
498
499     FileTimeToSystemTime((const FILETIME *)&spti.CreateTime, &UTC);
500     SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
501     trace("CreateTime : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
502            Local.wHour, Local.wMinute, Local.wSecond);
503
504     FileTimeToSystemTime((const FILETIME *)&spti.ExitTime, &UTC);
505     SystemTimeToTzSpecificLocalTime(NULL, &UTC, &Local);
506     trace("ExitTime   : %02d/%02d/%04d %02d:%02d:%02d\n", Local.wMonth, Local.wDay, Local.wYear,
507            Local.wHour, Local.wMinute, Local.wSecond);
508
509     FileTimeToSystemTime((const FILETIME *)&spti.KernelTime, &Local);
510     trace("KernelTime : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
511
512     FileTimeToSystemTime((const FILETIME *)&spti.UserTime, &Local);
513     trace("UserTime   : %02d:%02d:%02d.%03d\n", Local.wHour, Local.wMinute, Local.wSecond, Local.wMilliseconds);
514
515     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessTimes, &spti, sizeof(spti) * 2, &ReturnLength);
516     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
517     ok( sizeof(spti) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(spti), ReturnLength);
518 }
519
520 static void test_query_process_handlecount(void)
521 {
522     DWORD status;
523     ULONG ReturnLength;
524     DWORD handlecount;
525     HANDLE process;
526
527     status = pNtQueryInformationProcess(NULL, ProcessHandleCount, NULL, sizeof(handlecount), NULL);
528     ok( status == STATUS_ACCESS_VIOLATION || status == STATUS_INVALID_HANDLE,
529         "Expected STATUS_ACCESS_VIOLATION or STATUS_INVALID_HANDLE(W2K3), got %08lx\n", status);
530
531     status = pNtQueryInformationProcess(NULL, ProcessHandleCount, &handlecount, sizeof(handlecount), NULL);
532     ok( status == STATUS_INVALID_HANDLE, "Expected STATUS_INVALID_HANDLE, got %08lx\n", status);
533
534     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, 2, &ReturnLength);
535     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
536
537     process = OpenProcess (PROCESS_QUERY_INFORMATION, TRUE, one_before_last_pid);
538     trace("Handlecount for process with ID : %ld\n", one_before_last_pid);
539     status = pNtQueryInformationProcess( process, ProcessHandleCount, &handlecount, sizeof(handlecount), &ReturnLength);
540     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
541     ok( sizeof(handlecount) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(handlecount), ReturnLength);
542     CloseHandle(process);
543
544     status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessHandleCount, &handlecount, sizeof(handlecount) * 2, &ReturnLength);
545     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
546     ok( sizeof(handlecount) == ReturnLength, "Inconsistent length (%d) <-> (%ld)\n", sizeof(handlecount), ReturnLength);
547
548     /* Check if we have some return values */
549     trace("HandleCount : %ld\n", handlecount);
550     todo_wine
551     {
552         ok( handlecount > 0, "Expected some handles, got 0\n");
553     }
554 }
555
556 START_TEST(info)
557 {
558     if(!InitFunctionPtrs())
559         return;
560
561     /* NtQuerySystemInformation */
562
563     /* 0x0 SystemBasicInformation */
564     trace("Starting test_query_basic()\n");
565     test_query_basic();
566
567     /* 0x1 SystemCpuInformation */
568     trace("Starting test_query_cpu()\n");
569     test_query_cpu();
570
571     /* 0x3 SystemCpuInformation */
572     trace("Starting test_query_timeofday()\n");
573     test_query_timeofday();
574
575     /* 0x5 SystemProcessInformation */
576     trace("Starting test_query_process()\n");
577     test_query_process();
578
579     /* 0x10 SystemHandleInformation */
580     trace("Starting test_query_handle()\n");
581     test_query_handle();
582
583     /* NtQueryInformationProcess */
584
585     /* 0x0 ProcessBasicInformation */
586     trace("Starting test_query_process_basic()\n");
587     test_query_process_basic();
588
589     /* 0x2 ProcessIoCounters */
590     trace("Starting test_query_process_io()\n");
591     test_query_process_io();
592
593     /* 0x3 ProcessVmCounters */
594     trace("Starting test_query_process_vm()\n");
595     test_query_process_vm();
596
597     /* 0x4 ProcessTimes */
598     trace("Starting test_query_process_times()\n");
599     test_query_process_times();
600
601     /* 0x14 ProcessHandleCount */
602     trace("Starting test_query_process_handlecount()\n");
603     test_query_process_handlecount();
604
605     FreeLibrary(hntdll);
606 }