1 /* Unit test suite for *Information* Registry API functions
3 * Copyright 2005 Paul Vriens
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.
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.
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
21 #include "ntdll_test.h"
23 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
25 static HMODULE hntdll = 0;
27 #define NTDLL_GET_PROC(func) \
28 p ## func = (void*)GetProcAddress(hntdll, #func); \
30 trace("GetProcAddress(%s) failed\n", #func); \
31 FreeLibrary(hntdll); \
35 static BOOL InitFunctionPtrs(void)
37 hntdll = LoadLibraryA("ntdll.dll");
39 trace("Could not load ntdll.dll\n");
44 NTDLL_GET_PROC(NtQuerySystemInformation)
49 static void test_query_basic()
53 SYSTEM_BASIC_INFORMATION sbi;
55 /* This test also covers some basic parameter testing that should be the same for
56 * every information class
59 /* Use a nonexistent info class */
60 trace("Check nonexistent info class\n");
61 status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
62 ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status);
64 /* Use an existing class but with a zero-length buffer */
65 trace("Check zero-length buffer\n");
66 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
67 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
69 /* Use an existing class, correct length but no SystemInformation buffer */
70 trace("Check no SystemInformation buffer\n");
71 status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(sbi), NULL);
72 ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
74 /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
75 trace("Check no ReturnLength pointer\n");
76 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), NULL);
77 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
79 /* Finally some correct calls */
80 trace("Check with correct parameters\n");
81 status = pNtQuerySystemInformation(SystemBasicInformation, &sbi, sizeof(sbi), &ReturnLength);
82 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
83 ok( sizeof(sbi) == ReturnLength, "Inconsistent length (%08x) <-> (%ld)\n", sizeof(sbi), ReturnLength);
85 /* Check if we have some return values */
86 trace("Number of Processors : %d\n", sbi.NumberOfProcessors);
87 ok( sbi.NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi.NumberOfProcessors);
90 static void test_query_handle()
94 ULONG SystemInformationLength = sizeof(SYSTEM_HANDLE_INFORMATION);
95 SYSTEM_HANDLE_INFORMATION* shi = HeapAlloc(GetProcessHeap(), 0, SystemInformationLength);
97 /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
98 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
100 /* The following check assumes more than one handle on any given system */
103 ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
105 ok( ReturnLength > 0, "Expected ReturnLength to be > 0, it was %ld\n", ReturnLength);
107 SystemInformationLength = ReturnLength;
108 shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
109 status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
110 ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
112 /* Check if we have some return values */
113 trace("Number of Handles : %ld\n", shi->Count);
116 /* our implementation is a stub for now */
117 ok( shi->Count > 1, "Expected more than 1 handles, got (%ld)\n", shi->Count);
120 HeapFree( GetProcessHeap(), 0, shi);
126 if(!InitFunctionPtrs())
129 /* 0 SystemBasicInformation */
130 trace("Starting test_query_basic()\n");
133 /* 0x10 SystemHandleInformation */
134 trace("Starting test_query_handle()\n");