Fix segmentation fault caused by incorrect referencing of client audio
[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
25 static HMODULE hntdll = 0;
26
27 #define NTDLL_GET_PROC(func) \
28     p ## func = (void*)GetProcAddress(hntdll, #func); \
29     if(!p ## func) { \
30       trace("GetProcAddress(%s) failed\n", #func); \
31       FreeLibrary(hntdll); \
32       return FALSE; \
33     }
34
35 static BOOL InitFunctionPtrs(void)
36 {
37     hntdll = LoadLibraryA("ntdll.dll");
38     if(!hntdll) {
39       trace("Could not load ntdll.dll\n");
40       return FALSE;
41     }
42     if (hntdll)
43     {
44       NTDLL_GET_PROC(NtQuerySystemInformation)
45     }
46     return TRUE;
47 }
48
49 static void test_basic()
50 {
51     DWORD status;
52     ULONG ReturnLength;
53
54     SYSTEM_BASIC_INFORMATION* sbi = HeapAlloc(GetProcessHeap(), 0, sizeof(*sbi));
55
56     /* This test also covers some basic parameter testing that should be the same for 
57      * every information class
58     */
59
60     /* Use a nonexistent info class */
61     trace("Check nonexistent info class\n");
62     status = pNtQuerySystemInformation(-1, NULL, 0, NULL);
63     ok( status == STATUS_INVALID_INFO_CLASS, "Expected STATUS_INVALID_INFO_CLASS, got %08lx\n", status);
64
65     /* Use an existing class but with a zero-length buffer */
66     trace("Check zero-length buffer\n");
67     status = pNtQuerySystemInformation(SystemBasicInformation, NULL, 0, NULL);
68     ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08lx\n", status);
69
70     /* Use an existing class, correct length but no SystemInformation buffer */
71     trace("Check no SystemInformation buffer\n");
72     status = pNtQuerySystemInformation(SystemBasicInformation, NULL, sizeof(*sbi), NULL);
73     ok( status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %08lx\n", status);
74
75     /* Use a existing class, correct length, a pointer to a buffer but no ReturnLength pointer */
76     trace("Check no ReturnLength pointer\n");
77     status = pNtQuerySystemInformation(SystemBasicInformation, sbi, sizeof(*sbi), NULL);
78     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
79
80     /* Finally some correct calls */
81     trace("Check with correct parameters\n");
82     status = pNtQuerySystemInformation(SystemBasicInformation, sbi, sizeof(*sbi), &ReturnLength);
83     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08lx\n", status);
84     ok( sizeof(*sbi) == ReturnLength, "Inconsistent length (%08x) <-> (%ld)\n", sizeof(*sbi), ReturnLength);
85
86     /* Check if we have some return values */
87     trace("Number of Processors : %d\n", sbi->NumberOfProcessors);
88     ok( sbi->NumberOfProcessors > 0, "Expected more than 0 processors, got %d\n", sbi->NumberOfProcessors);
89
90     HeapFree(GetProcessHeap(), 0, sbi);
91 }
92
93 START_TEST(info)
94 {
95     if(!InitFunctionPtrs())
96         return;
97
98     /* 0 SystemBasicInformation */
99     trace("Starting test_basic()\n");
100     test_basic();
101
102     FreeLibrary(hntdll);
103 }