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"
28 static void test_default_printer(void)
30 #define DEFAULT_PRINTER_SIZE 1000
32 DWORD exact = DEFAULT_PRINTER_SIZE;
36 char buffer[DEFAULT_PRINTER_SIZE];
38 lib = GetModuleHandleA("winspool.drv");
40 ok( 0, "GetModuleHandleA(\"winspool.drv\") failed\n");
44 func = GetProcAddress( lib, "GetDefaultPrinterA");
46 /* only supported on NT like OSes starting with win2k */
49 SetLastError(ERROR_SUCCESS);
50 retval = func( buffer, &exact);
51 if (!retval || !exact || !strlen(buffer) ||
52 (ERROR_SUCCESS != GetLastError())) {
53 if ((ERROR_FILE_NOT_FOUND == GetLastError()) ||
54 (ERROR_INVALID_NAME == GetLastError()))
55 trace("this test requires a default printer to be set\n");
57 ok( 0, "function call GetDefaultPrinterA failed unexpected!\n"
58 "function returned %s\n"
59 "last error 0x%08lx\n"
60 "returned buffer size 0x%08lx\n"
61 "returned buffer content %s\n",
62 retval ? "true" : "false", GetLastError(), exact, buffer);
66 SetLastError(ERROR_SUCCESS);
67 retval = func( NULL, NULL);
68 ok( !retval, "function result wrong! False expected\n");
69 ok( ERROR_INVALID_PARAMETER == GetLastError(),
70 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
73 SetLastError(ERROR_SUCCESS);
74 retval = func( buffer, NULL);
75 ok( !retval, "function result wrong! False expected\n");
76 ok( ERROR_INVALID_PARAMETER == GetLastError(),
77 "Last error wrong! ERROR_INVALID_PARAMETER expected, got 0x%08lx\n",
80 SetLastError(ERROR_SUCCESS);
82 retval = func( NULL, &size);
83 ok( !retval, "function result wrong! False expected\n");
84 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
85 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
87 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
90 SetLastError(ERROR_SUCCESS);
91 size = DEFAULT_PRINTER_SIZE;
92 retval = func( NULL, &size);
93 ok( !retval, "function result wrong! False expected\n");
94 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
95 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
97 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
101 retval = func( buffer, &size);
102 ok( !retval, "function result wrong! False expected\n");
103 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
104 "Last error wrong! ERROR_INSUFFICIENT_BUFFER expected, got 0x%08lx\n",
106 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
110 retval = func( buffer, &size);
111 ok( retval, "function result wrong! True expected\n");
112 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
116 static void test_printer_directory(void)
117 { LPBYTE buffer = NULL;
118 DWORD cbBuf = 0, pcbNeeded = 0;
121 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, 0, &cbBuf);
122 trace("GetPrinterDriverDirectoryA: first call returned 0x%04x, "
123 "buffer size 0x%08lx\n", res, cbBuf);
126 trace("no valid buffer size returned, skipping tests\n");
130 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
132 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
133 ok( res, "expected result != 0, got %d\n", res);
134 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
137 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
138 ok( res, "expected result != 0, got %d\n", res);
139 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
142 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
143 ok( !res , "expected result == 0, got %d\n", res);
144 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
146 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
147 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
150 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
151 ok( (!res && ERROR_INVALID_USER_BUFFER == GetLastError()) ||
152 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
153 "expected either result == 0 and "
154 "last error == ERROR_INVALID_USER_BUFFER "
155 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
156 "got result %d and last error == %ld\n", res, GetLastError());
158 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
159 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
160 "expected either result == 0 and "
161 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
162 "got result %d and last error == %ld\n", res, GetLastError());
164 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
165 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) ||
166 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
167 "expected either result == 0 and "
168 "last error == RPC_X_NULL_REF_POINTER "
169 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
170 "got result %d and last error == %ld\n", res, GetLastError());
172 HeapFree( GetProcessHeap(), 0, buffer);
177 test_default_printer();
178 test_printer_directory();