2 * Copyright (C) 2003, 2004 Stefan Leichter
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
29 static char env_x86[] = "Windows NT x86";
30 static char env_win9x_case[] = "windowS 4.0";
33 static void test_default_printer(void)
35 #define DEFAULT_PRINTER_SIZE 1000
37 DWORD exact = DEFAULT_PRINTER_SIZE;
41 char buffer[DEFAULT_PRINTER_SIZE];
43 lib = GetModuleHandleA("winspool.drv");
45 ok( 0, "GetModuleHandleA(\"winspool.drv\") failed\n");
49 func = GetProcAddress( lib, "GetDefaultPrinterA");
51 /* only supported on NT like OSes starting with win2k */
54 SetLastError(ERROR_SUCCESS);
55 retval = func( buffer, &exact);
56 if (!retval || !exact || !strlen(buffer) ||
57 (ERROR_SUCCESS != GetLastError())) {
58 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
59 (ERROR_INVALID_NAME == GetLastError()))
60 trace("this test requires a default printer to be set\n");
62 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
63 "function returned %s\n"
64 "last error 0x%08lx\n"
65 "returned buffer size 0x%08lx\n"
66 "returned buffer content %s\n",
67 retval ? "true" : "false", GetLastError(), exact, buffer);
71 SetLastError(ERROR_SUCCESS);
72 retval = func( NULL, NULL);
73 ok( !retval, "function result wrong! False expected\n");
74 ok( ERROR_INVALID_PARAMETER == GetLastError(),
75 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
78 SetLastError(ERROR_SUCCESS);
79 retval = func( buffer, NULL);
80 ok( !retval, "function result wrong! False expected\n");
81 ok( ERROR_INVALID_PARAMETER == GetLastError(),
82 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
85 SetLastError(ERROR_SUCCESS);
87 retval = func( NULL, &size);
88 ok( !retval, "function result wrong! False expected\n");
89 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
90 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
92 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
95 SetLastError(ERROR_SUCCESS);
96 size = DEFAULT_PRINTER_SIZE;
97 retval = func( NULL, &size);
98 ok( !retval, "function result wrong! False expected\n");
99 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
100 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
102 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
106 retval = func( buffer, &size);
107 ok( !retval, "function result wrong! False expected\n");
108 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
109 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
111 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
115 retval = func( buffer, &size);
116 ok( retval, "function result wrong! True expected\n");
117 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
121 static void test_printer_directory(void)
122 { LPBYTE buffer = NULL;
123 DWORD cbBuf = 0, pcbNeeded = 0;
126 SetLastError(0x00dead00);
127 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
128 trace("GetPrinterDriverDirectoryA: first call returned 0x%04x, "
129 "buffer size 0x%08lx\n", res, cbBuf);
131 if((res == 0) && (GetLastError() == RPC_S_SERVER_UNAVAILABLE))
133 trace("The Service 'Spooler' is required for this test\n");
136 ok((res == 0) && (GetLastError() == ERROR_INSUFFICIENT_BUFFER),
137 "returned %d with lasterror=%ld (expected '0' with " \
138 "ERROR_INSUFFICIENT_BUFFER)\n", res, GetLastError());
141 trace("no valid buffer size returned, skipping tests\n");
145 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
146 if (buffer == NULL) return ;
148 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
149 ok( res, "expected result != 0, got %d\n", res);
150 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
153 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
154 ok( res, "expected result != 0, got %d\n", res);
155 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
158 SetLastError(0x00dead00);
159 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
160 ok( !res , "expected result == 0, got %d\n", res);
161 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
164 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
165 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
169 SetLastError(0x00dead00);
170 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
171 ok( (!res && ERROR_INVALID_USER_BUFFER == GetLastError()) ||
172 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
173 "expected either result == 0 and "
174 "last error == ERROR_INVALID_USER_BUFFER "
175 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
176 "got result %d and last error == %ld\n", res, GetLastError());
178 SetLastError(0x00dead00);
179 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
180 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
181 "expected either result == 0 and "
182 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
183 "got result %d and last error == %ld\n", res, GetLastError());
185 SetLastError(0x00dead00);
186 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
187 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) ||
188 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
189 "expected either result == 0 and "
190 "last error == RPC_X_NULL_REF_POINTER "
191 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
192 "got result %d and last error == %ld\n", res, GetLastError());
194 /* with a valid buffer, but level is to large */
196 SetLastError(0x00dead00);
197 res = GetPrinterDriverDirectoryA(NULL, NULL, 2, buffer, cbBuf, &pcbNeeded);
199 /* Level not checked in win9x and wine:*/
200 if((res != FALSE) && buffer[0])
202 trace("invalid Level '2' not checked (valid Level is '1') => '%s'\n",
207 ok( !res && (GetLastError() == ERROR_INVALID_LEVEL),
208 "returned %d with lasterror=%ld (expected '0' with " \
209 "ERROR_INVALID_LEVEL)\n", res, GetLastError());
212 /* printing environments are case insensitive */
213 /* "Windows 4.0" is valid for win9x and NT */
215 SetLastError(0x00dead00);
216 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
217 buffer, cbBuf*2, &pcbNeeded);
219 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
221 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
222 if (buffer == NULL) return ;
224 SetLastError(0x00dead00);
225 res = GetPrinterDriverDirectoryA(NULL, env_win9x_case, 1,
226 buffer, cbBuf*2, &pcbNeeded);
230 ok(res && buffer[0], "returned %d with " \
231 "lasterror=%ld and len=%d (expected '0' with 'len > 0')\n",
232 res, GetLastError(), lstrlenA((char *)buffer));
236 SetLastError(0x00dead00);
237 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
238 buffer, cbBuf*2, &pcbNeeded);
240 if(!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
242 buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, cbBuf*2);
243 if (buffer == NULL) return ;
246 SetLastError(0x00dead00);
247 res = GetPrinterDriverDirectoryA(NULL, env_x86, 1,
248 buffer, cbBuf*2, &pcbNeeded);
251 /* "Windows NT x86" is invalid for win9x */
252 ok( (res && buffer[0]) ||
253 (!res && (GetLastError() == ERROR_INVALID_ENVIRONMENT)),
254 "returned %d with lasterror=%ld and len=%d (expected '!= 0' with " \
255 "'len > 0' or '0' with ERROR_INVALID_ENVIRONMENT)\n",
256 res, GetLastError(), lstrlenA((char *)buffer));
258 HeapFree( GetProcessHeap(), 0, buffer);
263 test_default_printer();
264 test_printer_directory();