kernel32: Immediately return on failing to start wineboot
[wine/wine64.git] / dlls / ntprint / tests / ntprint.c
blobfca7b8d4848f7dcbad2d6ba0bfe8648cf0671657
1 /*
2 * Unit test suite for the Spooler Setup API (Printing)
4 * Copyright 2007 Detlef Riekenberg
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wingdi.h"
29 #include "wine/test.h"
32 /* ##### */
34 static HMODULE hdll;
35 static HANDLE (WINAPI *pPSetupCreateMonitorInfo)(LPVOID, LPVOID, LPVOID);
36 static VOID (WINAPI *pPSetupDestroyMonitorInfo)(HANDLE);
37 static BOOL (WINAPI *pPSetupEnumMonitor)(HANDLE, DWORD, LPWSTR, LPDWORD);
39 /* ########################### */
41 static LPCSTR load_functions(void)
43 LPCSTR ptr;
45 ptr = "ntprint.dll";
46 hdll = LoadLibraryA(ptr);
47 if (!hdll) return ptr;
49 ptr = "PSetupCreateMonitorInfo";
50 pPSetupCreateMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
51 if (!pPSetupCreateMonitorInfo) return ptr;
53 ptr = "PSetupDestroyMonitorInfo";
54 pPSetupDestroyMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
55 if (!pPSetupDestroyMonitorInfo) return ptr;
57 ptr = "PSetupEnumMonitor";
58 pPSetupEnumMonitor = (VOID *) GetProcAddress(hdll, ptr);
59 if (!pPSetupEnumMonitor) return ptr;
61 return NULL;
64 /* ########################### */
66 static void test_PSetupCreateMonitorInfo(VOID)
68 HANDLE mi;
69 BYTE buffer[1024] ;
71 SetLastError(0xdeadbeef);
72 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
73 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
74 if (mi) pPSetupDestroyMonitorInfo(mi);
77 memset(buffer, 0, sizeof(buffer));
78 SetLastError(0xdeadbeef);
79 mi = pPSetupCreateMonitorInfo(buffer, NULL, NULL);
80 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
81 if (mi) pPSetupDestroyMonitorInfo(mi);
85 /* ########################### */
87 static void test_PSetupDestroyMonitorInfo(VOID)
89 HANDLE mi;
92 SetLastError(0xdeadbeef);
93 pPSetupDestroyMonitorInfo(NULL);
94 /* lasterror is returned */
95 trace("returned with %u\n", GetLastError());
97 SetLastError(0xdeadbeef);
98 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
99 ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
101 if (!mi) return;
103 SetLastError(0xdeadbeef);
104 pPSetupDestroyMonitorInfo(mi);
105 /* lasterror is returned */
106 trace("returned with %u\n", GetLastError());
108 /* Try to destroy the handle twice crash with native ntprint.dll */
109 if (0) {
110 SetLastError(0xdeadbeef);
111 pPSetupDestroyMonitorInfo(mi);
112 trace(" with %u\n", GetLastError());
117 /* ########################### */
119 static void test_PSetupEnumMonitor(VOID)
121 HANDLE mi;
122 WCHAR buffer[MAX_PATH+2];
123 DWORD minsize = 0;
124 DWORD size;
125 DWORD res;
126 DWORD index=0;
128 SetLastError(0xdeadbeef);
129 mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
130 if (!mi) {
131 skip("PSetupCreateMonitorInfo\n");
132 return;
135 minsize = 0;
136 SetLastError(0xdeadbeef);
137 res = pPSetupEnumMonitor(mi, 0, NULL, &minsize);
138 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (minsize > 0),
139 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER "
140 "and '> 0')\n", res, GetLastError(), minsize);
143 size = sizeof(buffer) / sizeof(buffer[0]);
144 if ((minsize + 1) > size) {
145 skip("overflow: %u\n", minsize);
146 pPSetupDestroyMonitorInfo(mi);
147 return;
150 if (0) {
151 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
152 SetLastError(0xdeadbeef);
153 size = sizeof(buffer) / sizeof(buffer[0]);
154 res = pPSetupEnumMonitor(NULL, 0, buffer, &size);
155 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
156 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
157 res, GetLastError());
160 if (0) {
161 /* XP: Crash, w2k: Success (how can that work?) */
162 SetLastError(0xdeadbeef);
163 size = sizeof(buffer) / sizeof(buffer[0]);
164 res = pPSetupEnumMonitor(mi, 0, NULL, &size);
165 trace("got %u with %u and %u\n", res, GetLastError(), size);
168 if (0) {
169 /* XP: ERROR_INVALID_PARAMETER, w2k: Crash */
170 SetLastError(0xdeadbeef);
171 res = pPSetupEnumMonitor(mi, 0, buffer, NULL);
172 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
173 "got %u with %u (expected '0' with ERROR_INVALID_PARAMETER)\n",
174 res, GetLastError());
177 SetLastError(0xdeadbeef);
178 size = minsize - 1;
179 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
180 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
181 "got %u with %u and %u (expected '0' with ERROR_INSUFFICIENT_BUFFER)\n",
182 res, GetLastError(), size);
185 SetLastError(0xdeadbeef);
186 size = minsize;
187 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
188 ok( res, "got %u with %u and %u (expected '!= 0')\n",
189 res, GetLastError(), size);
191 SetLastError(0xdeadbeef);
192 size = minsize + 1;
193 res = pPSetupEnumMonitor(mi, 0, buffer, &size);
194 ok( res, "got %u with %u and %u (expected '!= 0')\n",
195 res, GetLastError(), size);
197 /* try max. 20 monitors */
198 while (res && (index < 20)) {
199 SetLastError(0xdeadbeef);
200 buffer[0] = '\0';
201 size = sizeof(buffer) / sizeof(buffer[0]);
202 res = pPSetupEnumMonitor(mi, index, buffer, &size);
203 ok( res || (GetLastError() == ERROR_NO_MORE_ITEMS),
204 "(%u) got %u with %u and %u (expected '!=0' or: '0' with "
205 "ERROR_NO_MORE_ITEMS)\n", index, res, GetLastError(), size);
207 if (res) index++;
209 pPSetupDestroyMonitorInfo(mi);
213 /* ########################### */
215 START_TEST(ntprint)
217 LPCSTR ptr;
219 /* ntprint.dll does not exist on win9x */
220 ptr = load_functions();
221 if (ptr) {
222 skip("%s not found\n", ptr);
223 return;
226 test_PSetupCreateMonitorInfo();
227 test_PSetupDestroyMonitorInfo();
228 test_PSetupEnumMonitor();