shell32: Update for simplified Chinese translation.
[wine] / dlls / ntprint / tests / ntprint.c
1 /*
2  * Unit test suite for the Spooler Setup API (Printing)
3  *
4  * Copyright 2007 Detlef Riekenberg
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "wingdi.h"
29 #include "wine/test.h"
30
31
32 /* ##### */
33
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);
38
39 /* ########################### */
40
41 static LPCSTR load_functions(void)
42 {
43     LPCSTR  ptr;
44
45     ptr = "ntprint.dll";
46     hdll = LoadLibraryA(ptr);
47     if (!hdll) return ptr;
48
49     ptr = "PSetupCreateMonitorInfo";
50     pPSetupCreateMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
51     if (!pPSetupCreateMonitorInfo) return ptr;
52
53     ptr = "PSetupDestroyMonitorInfo";
54     pPSetupDestroyMonitorInfo = (VOID *) GetProcAddress(hdll, ptr);
55     if (!pPSetupDestroyMonitorInfo) return ptr;
56
57     ptr = "PSetupEnumMonitor";
58     pPSetupEnumMonitor = (VOID *) GetProcAddress(hdll, ptr);
59     if (!pPSetupEnumMonitor) return ptr;
60
61     return NULL;
62 }
63
64 /* ########################### */
65
66 static void test_PSetupCreateMonitorInfo(VOID)
67 {
68     HANDLE  mi;
69     BYTE    buffer[1024] ;
70
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);
75
76
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);
82
83 }
84
85 /* ########################### */
86
87 static void test_PSetupDestroyMonitorInfo(VOID)
88 {
89     HANDLE  mi;
90
91
92     SetLastError(0xdeadbeef);
93     pPSetupDestroyMonitorInfo(NULL);
94     /* lasterror is returned */
95     trace("returned with %u\n", GetLastError());
96
97     SetLastError(0xdeadbeef);
98     mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
99     ok( mi != NULL, "got %p with %u (expected '!= NULL')\n", mi, GetLastError());
100
101     if (!mi) return;
102
103     SetLastError(0xdeadbeef);
104     pPSetupDestroyMonitorInfo(mi);
105     /* lasterror is returned */
106     trace("returned with %u\n", GetLastError());
107
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());
113     }
114
115 }
116
117 /* ########################### */
118
119 static void test_PSetupEnumMonitor(VOID)
120 {
121     HANDLE  mi;
122     WCHAR   buffer[MAX_PATH+2];
123     DWORD   minsize = 0;
124     DWORD   size;
125     DWORD   res;
126     DWORD   index=0;
127
128     SetLastError(0xdeadbeef);
129     mi = pPSetupCreateMonitorInfo(NULL, NULL, NULL);
130     if (!mi) {
131         skip("PSetupCreateMonitorInfo\n");
132         return;
133     }
134
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);
141
142
143     size = sizeof(buffer) / sizeof(buffer[0]);
144     if ((minsize + 1) > size) {
145         skip("overflow: %u\n", minsize);
146         pPSetupDestroyMonitorInfo(mi);
147         return;
148     }
149
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());
158     }
159
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);
166     }
167
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());
175     }
176
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);
183
184
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);
190
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);
196
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);
206
207         if (res) index++;
208     }
209     pPSetupDestroyMonitorInfo(mi);
210
211 }
212
213 /* ########################### */
214
215 START_TEST(ntprint)
216 {
217     LPCSTR ptr;
218
219     /* ntprint.dll does not exist on win9x */
220     ptr = load_functions();
221     if (ptr) {
222         skip("%s not found\n", ptr);
223         return;
224     }
225
226     test_PSetupCreateMonitorInfo();
227     test_PSetupDestroyMonitorInfo();
228     test_PSetupEnumMonitor();
229
230 }