2 * Unit test suite for pens
4 * Copyright 2006 Dmitry Timoshkov
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.
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.
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
29 #include "wine/test.h"
31 #define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
33 static void test_logpen(void)
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) }
62 DWORD obj_type, user_style[2] = { 0xabc, 0xdef };
69 for (i = 0; i < sizeof(pen)/sizeof(pen[0]); i++)
71 trace("testing style %u\n", pen[i].style);
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());
83 obj_type = GetObjectType(hpen);
84 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
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());
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);
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());
103 obj_type = GetObjectType(hpen);
104 ok(obj_type == OBJ_PEN, "wrong object type %u\n", obj_type);
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());
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());
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());
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());
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());
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);
138 memset(&elp, 0xb0, sizeof(elp));
139 SetLastError(0xdeadbeef);
140 size = GetObject(hpen, sizeof(elp), &elp);
142 /* for some reason XP differentiates PS_NULL here */
143 if (pen[i].style == PS_NULL)
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);
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);
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)
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)
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());
184 SetLastError(0xdeadbeef);
185 hpen = ExtCreatePen(pen[i].style, 1, &lb, 0, NULL);
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);
196 if (pen[i].style == PS_INSIDEFRAME)
198 /* This style is applicable only for gemetric pens */
199 ok(hpen == 0, "ExtCreatePen should fail\n");
200 goto test_geometric_pens;
202 ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError());
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);
209 ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type);
211 /* check what's the real size of the object */
212 SetLastError(0xdeadbeef);
213 size = GetObject(hpen, 0, NULL);
214 switch (pen[i].style)
217 ok(size == sizeof(LOGPEN),
218 "GetObject returned %d, error %d\n", size, GetLastError());
222 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
223 "GetObject returned %d, error %d\n", size, GetLastError());
227 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
228 "GetObject returned %d, error %d\n", size, GetLastError());
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());
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)
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);
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);
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]);
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);
280 if (pen[i].style == PS_USERSTYLE)
283 ok(ext_pen.elp.elpPenStyle == pen[i].style, "expected %x, got %x\n", pen[i].style, ext_pen.elp.elpPenStyle);
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);
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)
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);
306 if (pen[i].style == PS_ALTERNATE)
308 /* This style is applicable only for cosmetic pens */
309 ok(hpen == 0, "ExtCreatePen should fail\n");
312 ok(hpen != 0, "ExtCreatePen error %d\n", GetLastError());
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);
319 ok(obj_type == OBJ_EXTPEN, "wrong object type %u\n", obj_type);
321 /* check what's the real size of the object */
322 size = GetObject(hpen, 0, NULL);
323 switch (pen[i].style)
326 ok(size == sizeof(LOGPEN),
327 "GetObject returned %d, error %d\n", size, GetLastError());
331 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
332 "GetObject returned %d, error %d\n", size, GetLastError());
336 ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
337 "GetObject returned %d, error %d\n", size, GetLastError());
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());
347 memset(&lp, 0xb0, sizeof(lp));
348 SetLastError(0xdeadbeef);
349 size = GetObject(hpen, sizeof(lp), &lp);
350 /* for some reason XP differenciates PS_NULL here */
351 if (pen[i].style == PS_NULL)
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);
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());
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)
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);
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);
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]);
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);
407 /* for some reason XP differenciates 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);
412 if (pen[i].style == PS_USERSTYLE)
415 ok(ext_pen.elp.elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %x\n", PS_GEOMETRIC | pen[i].style, ext_pen.elp.elpPenStyle);
418 ok(ext_pen.elp.elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %x\n", PS_GEOMETRIC | pen[i].style, ext_pen.elp.elpPenStyle);
421 if (pen[i].style == PS_NULL)
422 ok(ext_pen.elp.elpWidth == 0, "expected 0, got %x\n", ext_pen.elp.elpWidth);
424 ok(ext_pen.elp.elpWidth == pen[i].ret_width, "expected %u, got %x\n", pen[i].ret_width, ext_pen.elp.elpWidth);
425 ok(ext_pen.elp.elpColor == pen[i].ret_color, "expected %08x, got %08x\n", pen[i].ret_color, ext_pen.elp.elpColor);
426 ok(ext_pen.elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen.elp.elpBrushStyle);
432 static unsigned int atoi2(const char *s)
434 unsigned int ret = 0;
435 while(*s) ret = (ret << 1) | (*s++ == '1');
439 #define TEST_LINE(x1, x2, z) \
441 SetBitmapBits(bmp, sizeof(buf), &buf); \
442 MoveToEx(hdc, x1, 0, NULL); \
443 LineTo(hdc, x2, 0); \
444 GetBitmapBits(bmp, sizeof(buf), &buf); \
445 expect(atoi2(z), buf); }
447 static void test_ps_alternate(void)
454 lb.lbStyle = BS_SOLID;
455 lb.lbColor = RGB(0xff,0xff,0xff);
457 SetLastError(0xdeadbeef);
458 pen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, NULL);
459 if(pen == NULL && GetLastError() == 0xdeadbeef) {
460 skip("looks like 9x, skipping PS_ALTERNATE tests\n");
463 ok(pen != NULL, "gle=%d\n", GetLastError());
464 hdc = CreateCompatibleDC(NULL);
465 ok(hdc != NULL, "gle=%d\n", GetLastError());
466 bmp = CreateBitmap(8, 1, 1, 1, NULL);
467 ok(bmp != NULL, "gle=%d\n", GetLastError());
468 ok(SelectObject(hdc, bmp) != NULL, "gle=%d\n", GetLastError());
469 ok(SelectObject(hdc, pen) != NULL, "gle=%d\n", GetLastError());
470 ok(SetBkMode(hdc, TRANSPARENT), "gle=%d\n", GetLastError());
472 TEST_LINE(0, 1, "10000000")
473 TEST_LINE(0, 2, "10000000")
474 TEST_LINE(0, 3, "10100000")
475 TEST_LINE(0, 4, "10100000")
476 TEST_LINE(1, 4, "01010000")
477 TEST_LINE(1, 5, "01010000")
478 TEST_LINE(4, 8, "00001010")