Added some logging to the GetPrinterDriverDirectoryA tests.
[wine/multimedia.git] / dlls / winspool / tests / info.c
blobfc9cf7e8efcdf1717d5069bfcae530b13e65cde5
1 /*
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
19 #include <stdarg.h>
21 #include "wine/test.h"
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winerror.h"
25 #include "wingdi.h"
26 #include "winspool.h"
28 static void test_default_printer(void)
30 #define DEFAULT_PRINTER_SIZE 1000
31 BOOL retval;
32 DWORD exact = DEFAULT_PRINTER_SIZE;
33 DWORD size;
34 FARPROC func = NULL;
35 HMODULE lib = NULL;
36 char buffer[DEFAULT_PRINTER_SIZE];
38 lib = GetModuleHandleA("winspool.drv");
39 if (!lib) {
40 ok( 0, "GetModuleHandleA(\"winspool.drv\") failed\n");
41 return;
44 func = GetProcAddress( lib, "GetDefaultPrinterA");
45 if (!func)
46 /* only supported on NT like OSes starting with win2k */
47 return;
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");
56 else {
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);
64 return;
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",
71 GetLastError());
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",
78 GetLastError());
80 SetLastError(ERROR_SUCCESS);
81 size = 0;
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",
86 GetLastError());
87 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
88 exact, size);
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",
96 GetLastError());
97 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
98 exact, size);
100 size = 0;
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",
105 GetLastError());
106 ok( size == exact, "Parameter size wrong! %ld expected got %ld\n",
107 exact, size);
109 size = exact;
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",
113 exact, size);
116 static void test_printer_directory(void)
117 { LPBYTE buffer = NULL;
118 DWORD cbBuf = 0, pcbNeeded = 0;
119 BOOL res;
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);
125 buffer = HeapAlloc( GetProcessHeap(), 0, cbBuf*2);
127 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf, &pcbNeeded);
128 ok( res, "expected result != 0, got %d\n", res);
129 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
130 pcbNeeded, cbBuf);
132 res = GetPrinterDriverDirectoryA(NULL, NULL, 1, buffer, cbBuf*2, &pcbNeeded);
133 ok( res, "expected result != 0, got %d\n", res);
134 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
135 pcbNeeded, cbBuf);
137 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf-1, &pcbNeeded);
138 ok( !res , "expected result == 0, got %d\n", res);
139 ok( cbBuf == pcbNeeded, "pcbNeeded set to %ld instead of %ld\n",
140 pcbNeeded, cbBuf);
141 ok( ERROR_INSUFFICIENT_BUFFER == GetLastError(),
142 "last error set to %ld instead of ERROR_INSUFFICIENT_BUFFER\n",
143 GetLastError());
145 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, &pcbNeeded);
146 ok( (!res && ERROR_INVALID_USER_BUFFER == GetLastError()) ||
147 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
148 "expected either result == 0 and "
149 "last error == ERROR_INVALID_USER_BUFFER "
150 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
151 "got result %d and last error == %ld\n", res, GetLastError());
153 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, buffer, cbBuf, NULL);
154 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) || res,
155 "expected either result == 0 and "
156 "last error == RPC_X_NULL_REF_POINTER or result != 0 "
157 "got result %d and last error == %ld\n", res, GetLastError());
159 res = GetPrinterDriverDirectoryA( NULL, NULL, 1, NULL, cbBuf, NULL);
160 ok( (!res && RPC_X_NULL_REF_POINTER == GetLastError()) ||
161 ( res && ERROR_INVALID_PARAMETER == GetLastError()) ,
162 "expected either result == 0 and "
163 "last error == RPC_X_NULL_REF_POINTER "
164 "or result != 0 and last error == ERROR_INVALID_PARAMETER "
165 "got result %d and last error == %ld\n", res, GetLastError());
167 HeapFree( GetProcessHeap(), 0, buffer);
170 START_TEST(info)
172 test_default_printer();
173 test_printer_directory();