1 /*
2 * Unit test suite for pens
3 *
4 * Copyright 2006 Dmitry Timoshkov
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 #include <stdarg.h>
22 #include <assert.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28
29 #include "wine/test.h"
30
31 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
32
33 static void test_logpen(void)
34 {
35 static const struct
36 {
37 UINT style;
38 INT width;
39 COLORREF color;
40 UINT ret_style;
41 INT ret_width;
42 COLORREF ret_color;
43 } pen[] = {
44 { PS_SOLID, -123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
45 { PS_SOLID, 0, RGB(0x12,0x34,0x56), PS_SOLID, 0, RGB(0x12,0x34,0x56) },
46 { PS_SOLID, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
47 { PS_DASH, 123, RGB(0x12,0x34,0x56), PS_DASH, 123, RGB(0x12,0x34,0x56) },
48 { PS_DOT, 123, RGB(0x12,0x34,0x56), PS_DOT, 123, RGB(0x12,0x34,0x56) },
49 { PS_DASHDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOT, 123, RGB(0x12,0x34,0x56) },
50 { PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56) },
51 { PS_NULL, -123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 },
52 { PS_NULL, 123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 },
53 { PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56), PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56) },
54 { PS_USERSTYLE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
55 { PS_ALTERNATE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }
56 };
57 INT i, size;
58 HPEN hpen;
59 LOGPEN lp;
60 EXTLOGPEN elp;
61 LOGBRUSH lb;
62 DWORD obj_type, user_style[2] = { 0xabc, 0xdef };
63 struct
64 {
65 EXTLOGPEN elp;
66 DWORD style_data[10];
67 } ext_pen;
68
69 for (i = 0; i < sizeof(pen)/sizeof(pen[0]); i++)
70 {
71 trace("testing style %u\n", pen[i].style);
72
73 /********************** cosmetic pens **********************/
74 /* CreatePenIndirect behaviour */
75 lp.lopnStyle = pen[i].style,
76 lp.lopnWidth.x = pen[i].width;
77 lp.lopnWidth.y = 11; /* just in case */
78 lp.lopnColor = pen[i].color;
79 SetLastError(0xdeadbeef);
80 hpen = CreatePenIndirect(&lp);
81 ok(hpen != 0, "CreatePen error %d\n", GetLastError());
82
83 obj_type = GetObjectType(hpen);
84 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
85
86 memset(&lp, 0xb0, sizeof(lp));
87 SetLastError(0xdeadbeef);
88 size = GetObject(hpen, sizeof(lp), &lp);
89 ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError());
90
91 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
92 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
93 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
94 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
95
96 DeleteObject(hpen);
97
98 /* CreatePen behaviour */
99 SetLastError(0xdeadbeef);
100 hpen = CreatePen(pen[i].style, pen[i].width, pen[i].color);
101 ok(hpen != 0, "CreatePen error %d\n", GetLastError());
102
103 obj_type = GetObjectType(hpen);
104 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
105
106 /* check what's the real size of the object */
107 size = GetObject(hpen, 0, NULL);
108 ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError());
109
110 /* ask for truncated data */
111 memset(&lp, 0xb0, sizeof(lp));
112 SetLastError(0xdeadbeef);
113 size = GetObject(hpen, sizeof(lp.lopnStyle), &lp);
114 ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError());
115
116 /* see how larger buffer sizes are handled */
117 memset(&lp, 0xb0, sizeof(lp));
118 SetLastError(0xdeadbeef);
119 size = GetObject(hpen, sizeof(lp) * 2, &lp);
120 ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError());
121
122 /* see how larger buffer sizes are handled */
123 memset(&elp, 0xb0, sizeof(elp));
124 SetLastError(0xdeadbeef);
125 size = GetObject(hpen, sizeof(elp) * 2, &elp);
126 ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError());
127
128 memset(&lp, 0xb0, sizeof(lp));
129 SetLastError(0xdeadbeef);
130 size = GetObject(hpen, sizeof(lp), &lp);
131 ok(size == sizeof(lp), "GetObject returned %d, error %d\n", size, GetLastError());
132
133 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
134 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
135 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
136 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
137
138 memset(&elp, 0xb0, sizeof(elp));
139 SetLastError(0xdeadbeef);
140 size = GetObject(hpen, sizeof(elp), &elp);
141
142 /* for some reason XP differentiates PS_NULL here */
143 if (pen[i].style == PS_NULL)
144 {
145 ok(size == sizeof(EXTLOGPEN), "GetObject returned %d, error %d\n", size, GetLastError());
146 ok(elp.elpPenStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, elp.elpPenStyle);
147 ok(elp.elpWidth == 0, "expected 0, got %u\n", elp.elpWidth);
148 ok(elp.elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, elp.elpColor);
149 ok(elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %u\n", elp.elpBrushStyle);
150 ok(elp.elpHatch == 0, "expected 0, got %p\n", (void *)elp.elpHatch);
151 ok(elp.elpNumEntries == 0, "expected 0, got %x\n", elp.elpNumEntries);
152 }
153 else
154 {
155 ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError());
156 memcpy(&lp, &elp, sizeof(lp));
157 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
158 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
159 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
160 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
161 }
162
163 DeleteObject(hpen);
164
165 /********** cosmetic pens created by ExtCreatePen ***********/
166 lb.lbStyle = BS_SOLID;
167 lb.lbColor = pen[i].color;
168 lb.lbHatch = HS_CROSS; /* just in case */
169 SetLastError(0xdeadbeef);
170 hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 2, user_style);
171 if (pen[i].style != PS_USERSTYLE)
172 {
173 ok(hpen == 0, "ExtCreatePen should fail\n");
174 ok(GetLastError() == ERROR_INVALID_PARAMETER,
175 "wrong last error value %d\n", GetLastError());
176 SetLastError(0xdeadbeef);
177 hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 0, NULL);
178 if (pen[i].style != PS_NULL)
179 {
180 ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n");
181 ok(GetLastError() == ERROR_INVALID_PARAMETER,
182 "wrong last error value %d\n", GetLastError());
183
184 SetLastError(0xdeadbeef);
185 hpen = ExtCreatePen(pen[i].style, 1, &lb, 0, NULL);
186 }
187 }
188 else
189 {
190 ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n");
191 ok(GetLastError() == ERROR_INVALID_PARAMETER,
192 "wrong last error value %d\n", GetLastError());
193 SetLastError(0xdeadbeef);
194 hpen = ExtCreatePen(pen[i].style, 1, &lb, 2, user_style);
195 }
196 if (pen[i].style == PS_INSIDEFRAME)
197 {
198 /* This style is applicable only for geometric pens */
199 ok(hpen == 0, "ExtCreatePen should fail\n");
200 goto test_geometric_pens;
201 }
202 ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError());
203
204 obj_type = GetObjectType(hpen);
205 /* for some reason XP differentiates PS_NULL here */
206 if (pen[i].style == PS_NULL)
207 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
208 else
209 ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type);
210
211 /* check what's the real size of the object */
212 SetLastError(0xdeadbeef);
213 size = GetObject(hpen, 0, NULL);
214 switch (pen[i].style)
215 {
216 case PS_NULL:
217 ok(size == sizeof(LOGPEN),
218 "GetObject returned %d, error %d\n", size, GetLastError());
219 break;
220
221 case PS_USERSTYLE:
222 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
223 "GetObject returned %d, error %d\n", size, GetLastError());
224 break;
225
226 default:
227 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
228 "GetObject returned %d, error %d\n", size, GetLastError());
229 break;
230 }
231
232 /* ask for truncated data */
233 memset(&elp, 0xb0, sizeof(elp));
234 SetLastError(0xdeadbeef);
235 size = GetObject(hpen, sizeof(elp.elpPenStyle), &elp);
236 ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError());
237
238 /* see how larger buffer sizes are handled */
239 memset(&ext_pen, 0xb0, sizeof(ext_pen));
240 SetLastError(0xdeadbeef);
241 size = GetObject(hpen, sizeof(ext_pen), &ext_pen.elp);
242 switch (pen[i].style)
243 {
244 case PS_NULL:
245 ok(size == sizeof(LOGPEN),
246 "GetObject returned %d, error %d\n", size, GetLastError());
247 memcpy(&lp, &ext_pen.elp, sizeof(lp));
248 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
249 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
250 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
251 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
252
253 /* for PS_NULL it also works this way */
254 memset(&elp, 0xb0, sizeof(elp));
255 SetLastError(0xdeadbeef);
256 size = GetObject(hpen, sizeof(elp), &elp);
257 ok(size == sizeof(EXTLOGPEN),
258 "GetObject returned %d, error %d\n", size, GetLastError());
259 ok(ext_pen.elp.elpHatch == 0xb0b0b0b0, "expected 0xb0b0b0b0, got %p\n", (void *)ext_pen.elp.elpHatch);
260 ok(ext_pen.elp.elpNumEntries == 0xb0b0b0b0, "expected 0xb0b0b0b0, got %x\n", ext_pen.elp.elpNumEntries);
261 break;
262
263 case PS_USERSTYLE:
264 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
265 "GetObject returned %d, error %d\n", size, GetLastError());
266 ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
267 ok(ext_pen.elp.elpNumEntries == 2, "expected 0, got %x\n", ext_pen.elp.elpNumEntries);
268 ok(ext_pen.elp.elpStyleEntry[0] == 0xabc, "expected 0xabc, got %x\n", ext_pen.elp.elpStyleEntry[0]);
269 ok(ext_pen.elp.elpStyleEntry[1] == 0xdef, "expected 0xabc, got %x\n", ext_pen.elp.elpStyleEntry[1]);
270 break;
271
272 default:
273 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
274 "GetObject returned %d, error %d\n", size, GetLastError());
275 ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
276 ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %x\n", ext_pen.elp.elpNumEntries);
277 break;
278 }
279
280 if (pen[i].style == PS_USERSTYLE)
281 {
282 todo_wine
283 ok(ext_pen.elp.elpPenStyle == pen[i].style, "expected %x, got %x\n", pen[i].style, ext_pen.elp.elpPenStyle);
284 }
285 else
286 ok(ext_pen.elp.elpPenStyle == pen[i].style, "expected %x, got %x\n", pen[i].style, ext_pen.elp.elpPenStyle);
287 ok(ext_pen.elp.elpWidth == 1, "expected 1, got %x\n", ext_pen.elp.elpWidth);
288 ok(ext_pen.elp.elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, ext_pen.elp.elpColor);
289 ok(ext_pen.elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen.elp.elpBrushStyle);
290
291 DeleteObject(hpen);
292
293 test_geometric_pens:
294 /********************** geometric pens **********************/
295 lb.lbStyle = BS_SOLID;
296 lb.lbColor = pen[i].color;
297 lb.lbHatch = HS_CROSS; /* just in case */
298 SetLastError(0xdeadbeef);
299 hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 2, user_style);
300 if (pen[i].style != PS_USERSTYLE)
301 {
302 ok(hpen == 0, "ExtCreatePen should fail\n");
303 SetLastError(0xdeadbeef);
304 hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 0, NULL);
305 }
306 if (pen[i].style == PS_ALTERNATE)
307 {
308 /* This style is applicable only for cosmetic pens */
309 ok(hpen == 0, "ExtCreatePen should fail\n");
310 continue;
311 }
312 ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError());
313
314 obj_type = GetObjectType(hpen);
315 /* for some reason XP differentiates PS_NULL here */
316 if (pen[i].style == PS_NULL)
317 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
318 else
319 ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type);
320
321 /* check what's the real size of the object */
322 size = GetObject(hpen, 0, NULL);
323 switch (pen[i].style)
324 {
325 case PS_NULL:
326 ok(size == sizeof(LOGPEN),
327 "GetObject returned %d, error %d\n", size, GetLastError());
328 break;
329
330 case PS_USERSTYLE:
331 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
332 "GetObject returned %d, error %d\n", size, GetLastError());
333 break;
334
335 default:
336 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
337 "GetObject returned %d, error %d\n", size, GetLastError());
338 break;
339 }
340
341 /* ask for truncated data */
342 memset(&lp, 0xb0, sizeof(lp));
343 SetLastError(0xdeadbeef);
344 size = GetObject(hpen, sizeof(lp.lopnStyle), &lp);
345 ok(!size, "GetObject should fail: size %d, error %d\n", size, GetLastError());
346
347 memset(&lp, 0xb0, sizeof(lp));
348 SetLastError(0xdeadbeef);
349 size = GetObject(hpen, sizeof(lp), &lp);
350 /* for some reason XP differentiates PS_NULL here */
351 if (pen[i].style == PS_NULL)
352 {
353 ok(size == sizeof(LOGPEN), "GetObject returned %d, error %d\n", size, GetLastError());
354 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
355 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
356 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
357 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
358 }
359 else
360 /* XP doesn't set last error here */
361 ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/,
362 "GetObject should fail: size %d, error %d\n", size, GetLastError());
363
364 memset(&ext_pen, 0xb0, sizeof(ext_pen));
365 SetLastError(0xdeadbeef);
366 /* buffer is too small for user styles */
367 size = GetObject(hpen, sizeof(elp), &ext_pen.elp);
368 switch (pen[i].style)
369 {
370 case PS_NULL:
371 ok(size == sizeof(EXTLOGPEN),
372 "GetObject returned %d, error %d\n", size, GetLastError());
373 ok(ext_pen.elp.elpHatch == 0, "expected 0, got %p\n", (void *)ext_pen.elp.elpHatch);
374 ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %x\n", ext_pen.elp.elpNumEntries);
375
376 /* for PS_NULL it also works this way */
377 SetLastError(0xdeadbeef);
378 size = GetObject(hpen, sizeof(ext_pen), &lp);
379 ok(size == sizeof(LOGPEN),
380 "GetObject returned %d, error %d\n", size, GetLastError());
381 ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
382 ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %d\n", pen[i].ret_width, lp.lopnWidth.x);
383 ok(lp.lopnWidth.y == 0, "expected 0, got %d\n", lp.lopnWidth.y);
384 ok(lp.lopnColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, lp.lopnColor);
385 break;
386
387 case PS_USERSTYLE:
388 ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/,
389 "GetObject should fail: size %d, error %d\n", size, GetLastError());
390 size = GetObject(hpen, sizeof(ext_pen), &ext_pen.elp);
391 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
392 "GetObject returned %d, error %d\n", size, GetLastError());
393 ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
394 ok(ext_pen.elp.elpNumEntries == 2, "expected 0, got %x\n", ext_pen.elp.elpNumEntries);
395 ok(ext_pen.elp.elpStyleEntry[0] == 0xabc, "expected 0xabc, got %x\n", ext_pen.elp.elpStyleEntry[0]);
396 ok(ext_pen.elp.elpStyleEntry[1] == 0xdef, "expected 0xabc, got %x\n", ext_pen.elp.elpStyleEntry[1]);
397 break;
398
399 default:
400 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
401 "GetObject returned %d, error %d\n", size, GetLastError());
402 ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
403 ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %x\n", ext_pen.elp.elpNumEntries);
404 break;
405 }
406
407 /* for some reason XP differentiates PS_NULL here */
408 if (pen[i].style == PS_NULL)
409 ok(ext_pen.elp.elpPenStyle == pen[i].ret_style, "expected %x, got %x\n", pen[i].ret_style, ext_pen.elp.elpPenStyle);
410 else
411 {
412 ok(ext_pen.elp.elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %x\n", PS_GEOMETRIC | pen[i].style, ext_pen.elp.elpPenStyle);
413 }
414
415 if (pen[i].style == PS_NULL)
416 ok(ext_pen.elp.elpWidth == 0, "expected 0, got %x\n", ext_pen.elp.elpWidth);
417 else
418 ok(ext_pen.elp.elpWidth == pen[i].ret_width, "expected %u, got %x\n", pen[i].ret_width, ext_pen.elp.elpWidth);
419 ok(ext_pen.elp.elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, ext_pen.elp.elpColor);
420 ok(ext_pen.elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen.elp.elpBrushStyle);
421
422 DeleteObject(hpen);
423 }
424 }
425
426 static unsigned int atoi2(const char *s)
427 {
428 unsigned int ret = 0;
429 while(*s) ret = (ret << 1) | (*s++ == '1');
430 return ret;
431 }
432
433 #define TEST_LINE(x1, x2, z) \
434 { int buf = 0; \
435 SetBitmapBits(bmp, sizeof(buf), &buf); \
436 MoveToEx(hdc, x1, 0, NULL); \
437 LineTo(hdc, x2, 0); \
438 GetBitmapBits(bmp, sizeof(buf), &buf); \
439 expect(atoi2(z), buf); }
440
441 static void test_ps_alternate(void)
442 {
443 HDC hdc;
444 HBITMAP bmp;
445 HPEN pen;
446 LOGBRUSH lb;
447
448 lb.lbStyle = BS_SOLID;
449 lb.lbColor = RGB(0xff,0xff,0xff);
450
451 SetLastError(0xdeadbeef);
452 pen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL);
453 if(pen == NULL && GetLastError() == 0xdeadbeef) {
454 skip("looks like 9x, skipping PS_ALTERNATE tests\n");
455 return;
456 }
457 ok(pen != NULL, "gle=%d\n", GetLastError());
458 hdc = CreateCompatibleDC(NULL);
459 ok(hdc != NULL, "gle=%d\n", GetLastError());
460 bmp = CreateBitmap(8, 1, 1, 1, NULL);
461 ok(bmp != NULL, "gle=%d\n", GetLastError());
462 ok(SelectObject(hdc, bmp) != NULL, "gle=%d\n", GetLastError());
463 ok(SelectObject(hdc, pen) != NULL, "gle=%d\n", GetLastError());
464 ok(SetBkMode(hdc, TRANSPARENT), "gle=%d\n", GetLastError());
465
466 TEST_LINE(0, 1, "10000000")
467 TEST_LINE(0, 2, "10000000")
468 TEST_LINE(0, 3, "10100000")
469 TEST_LINE(0, 4, "10100000")
470 TEST_LINE(1, 4, "01010000")
471 TEST_LINE(1, 5, "01010000")
472 TEST_LINE(4, 8, "00001010")
473
474 DeleteObject(pen);
475 DeleteObject(bmp);
476 DeleteDC(hdc);
477 }
478
479 static void test_ps_userstyle(void)
480 {
481 static DWORD style[17] = {0, 2, 0, 4, 5, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 17};
482 static DWORD bad_style[5] = {0, 0, 0, 0, 0};
483 static DWORD bad_style2[5] = {4, 7, 8, 3, -1};
484
485 LOGBRUSH lb;
486 HPEN pen;
487 INT size, i;
488
489 struct
490 {
491 EXTLOGPEN elp;
492 DWORD style_data[15];
493 } ext_pen;
494
495 lb.lbColor = 0x00ff0000;
496 lb.lbStyle = BS_SOLID;
497 lb.lbHatch = 0;
498
499 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 3, NULL);
500 ok(pen == 0, "ExtCreatePen should fail\n");
501 expect(ERROR_INVALID_PARAMETER, GetLastError());
502 DeleteObject(pen);
503 SetLastError(0xdeadbeef);
504
505 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 0, style);
506 ok(pen == 0, "ExtCreatePen should fail\n");
507 expect(0xdeadbeef, GetLastError());
508 DeleteObject(pen);
509 SetLastError(0xdeadbeef);
510
511 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 17, style);
512 ok(pen == 0, "ExtCreatePen should fail\n");
513 expect(ERROR_INVALID_PARAMETER, GetLastError());
514 DeleteObject(pen);
515 SetLastError(0xdeadbeef);
516
517 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, -1, style);
518 ok(pen == 0, "ExtCreatePen should fail\n");
519 expect(0xdeadbeef, GetLastError());
520 DeleteObject(pen);
521 SetLastError(0xdeadbeef);
522
523 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style);
524 ok(pen == 0, "ExtCreatePen should fail\n");
525 expect(ERROR_INVALID_PARAMETER, GetLastError());
526 DeleteObject(pen);
527 SetLastError(0xdeadbeef);
528
529 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 5, bad_style2);
530 ok(pen == 0, "ExtCreatePen should fail\n");
531 expect(ERROR_INVALID_PARAMETER, GetLastError());
532 DeleteObject(pen);
533 SetLastError(0xdeadbeef);
534
535 pen = ExtCreatePen(PS_GEOMETRIC | PS_USERSTYLE, 50, &lb, 16, style);
536 ok(pen != 0, "ExtCreatePen should not fail\n");
537
538 size = GetObject(pen, sizeof(ext_pen), &ext_pen);
539 expect(88, size);
540
541 for(i = 0; i < 16; i++)
542 expect(style[i], ext_pen.elp.elpStyleEntry[i]);
543
544 DeleteObject(pen);
545 }
546
547 START_TEST(pen)
548 {
549 test_logpen();
550 test_ps_alternate();
551 test_ps_userstyle();
552 }
553
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.