kernel32: FindFirstChangeNotification needs a static IO_STATUS_BLOCK.
[wine] / dlls / gdi / tests / gdiobj.c
1 /*
2  * Unit test suite for GDI objects
3  *
4  * Copyright 2002 Mike McCormack
5  * Copyright 2004 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23 #include <assert.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29
30 #include "wine/test.h"
31
32
33 static void check_font(const char* test, const LOGFONTA* lf, HFONT hfont)
34 {
35     LOGFONTA getobj_lf;
36     int ret, minlen = 0;
37
38     if (!hfont)
39         return;
40
41     ret = GetObject(hfont, sizeof(getobj_lf), &getobj_lf);
42     /* NT4 tries to be clever and only returns the minimum length */
43     while (lf->lfFaceName[minlen] && minlen < LF_FACESIZE-1)
44         minlen++;
45     minlen += FIELD_OFFSET(LOGFONTA, lfFaceName) + 1;
46     ok(ret == sizeof(LOGFONTA) || ret == minlen,
47        "%s: GetObject returned %d expected %d or %d\n", test, ret, sizeof(LOGFONTA), minlen);
48     ok(!memcmp(&lf, &lf, FIELD_OFFSET(LOGFONTA, lfFaceName)), "%s: fonts don't match\n", test);
49     ok(!lstrcmpA(lf->lfFaceName, getobj_lf.lfFaceName),
50        "%s: font names don't match: %s != %s\n", test, lf->lfFaceName, getobj_lf.lfFaceName);
51 }
52
53 static HFONT create_font(const char* test, const LOGFONTA* lf)
54 {
55     HFONT hfont = CreateFontIndirectA(lf);
56     ok(hfont != 0, "%s: CreateFontIndirect failed\n", test);
57     if (hfont)
58         check_font(test, lf, hfont);
59     return hfont;
60 }
61
62 static void test_logfont(void)
63 {
64     LOGFONTA lf;
65     HFONT hfont;
66
67     memset(&lf, 0, sizeof lf);
68
69     lf.lfCharSet = ANSI_CHARSET;
70     lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
71     lf.lfWeight = FW_DONTCARE;
72     lf.lfHeight = 16;
73     lf.lfWidth = 16;
74     lf.lfQuality = DEFAULT_QUALITY;
75
76     lstrcpyA(lf.lfFaceName, "Arial");
77     hfont = create_font("Arial", &lf);
78     DeleteObject(hfont);
79
80     memset(&lf, 'A', sizeof(lf));
81     hfont = CreateFontIndirectA(&lf);
82     ok(hfont != 0, "CreateFontIndirectA with strange LOGFONT failed\n");
83     
84     lf.lfFaceName[LF_FACESIZE - 1] = 0;
85     check_font("AAA...", &lf, hfont);
86     DeleteObject(hfont);
87 }
88
89 static INT CALLBACK font_enum_proc(const LOGFONT *elf, const TEXTMETRIC *ntm, DWORD type, LPARAM lParam)
90 {
91     if (type & RASTER_FONTTYPE)
92     {
93         LOGFONT *lf = (LOGFONT *)lParam;
94         *lf = *elf;
95         return 0; /* stop enumeration */
96     }
97
98     return 1; /* continue enumeration */
99 }
100
101 static void test_font_metrics(HDC hdc, HFONT hfont, const char *test_str,
102                               INT test_str_len, const TEXTMETRICA *tm_orig,
103                               const SIZE *size_orig, INT width_orig,
104                               INT scale_x, INT scale_y)
105 {
106     HFONT old_hfont;
107     TEXTMETRICA tm;
108     SIZE size;
109     INT width;
110
111     if (!hfont)
112         return;
113
114     old_hfont = SelectObject(hdc, hfont);
115
116     GetTextMetricsA(hdc, &tm);
117
118     ok(tm.tmHeight == tm_orig->tmHeight * scale_y, "%ld != %ld\n", tm.tmHeight, tm_orig->tmHeight * scale_y);
119     ok(tm.tmAscent == tm_orig->tmAscent * scale_y, "%ld != %ld\n", tm.tmAscent, tm_orig->tmAscent * scale_y);
120     ok(tm.tmDescent == tm_orig->tmDescent * scale_y, "%ld != %ld\n", tm.tmDescent, tm_orig->tmDescent * scale_y);
121     ok(tm.tmAveCharWidth == tm_orig->tmAveCharWidth * scale_x, "%ld != %ld\n", tm.tmAveCharWidth, tm_orig->tmAveCharWidth * scale_x);
122
123     GetTextExtentPoint32A(hdc, test_str, test_str_len, &size);
124
125     ok(size.cx == size_orig->cx * scale_x, "%ld != %ld\n", size.cx, size_orig->cx * scale_x);
126     ok(size.cy == size_orig->cy * scale_y, "%ld != %ld\n", size.cy, size_orig->cy * scale_y);
127
128     GetCharWidthA(hdc, 'A', 'A', &width);
129
130     ok(width == width_orig * scale_x, "%d != %d\n", width, width_orig * scale_x);
131
132     SelectObject(hdc, old_hfont);
133 }
134
135 /* see whether GDI scales bitmap font metrics */
136 static void test_bitmap_font(void)
137 {
138     static const char test_str[11] = "Test String";
139     HDC hdc;
140     LOGFONTA bitmap_lf;
141     HFONT hfont, old_hfont;
142     TEXTMETRICA tm_orig;
143     SIZE size_orig;
144     INT ret, i, width_orig, height_orig;
145
146     hdc = GetDC(0);
147
148     /* "System" has only 1 pixel size defined, otherwise the test breaks */
149     ret = EnumFontFamiliesA(hdc, "System", font_enum_proc, (LPARAM)&bitmap_lf);
150     if (ret)
151     {
152         ReleaseDC(0, hdc);
153         trace("no bitmap fonts were found, skipping the test\n");
154         return;
155     }
156
157     trace("found bitmap font %s, height %ld\n", bitmap_lf.lfFaceName, bitmap_lf.lfHeight);
158
159     height_orig = bitmap_lf.lfHeight;
160     hfont = create_font("bitmap", &bitmap_lf);
161
162     old_hfont = SelectObject(hdc, hfont);
163     ok(GetTextMetricsA(hdc, &tm_orig), "GetTextMetricsA failed\n");
164     ok(GetTextExtentPoint32A(hdc, test_str, sizeof(test_str), &size_orig), "GetTextExtentPoint32A failed\n");
165     ok(GetCharWidthA(hdc, 'A', 'A', &width_orig), "GetCharWidthA failed\n");
166     SelectObject(hdc, old_hfont);
167     DeleteObject(hfont);
168
169     /* test fractional scaling */
170     for (i = 1; i < height_orig; i++)
171     {
172         hfont = create_font("fractional", &bitmap_lf);
173         test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 1, 1);
174         DeleteObject(hfont);
175     }
176
177     /* test integer scaling 3x2 */
178     bitmap_lf.lfHeight = height_orig * 2;
179     bitmap_lf.lfWidth *= 3;
180     hfont = create_font("3x2", &bitmap_lf);
181 todo_wine
182 {
183     test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 2);
184 }
185     DeleteObject(hfont);
186
187     /* test integer scaling 3x3 */
188     bitmap_lf.lfHeight = height_orig * 3;
189     bitmap_lf.lfWidth = 0;
190     hfont = create_font("3x3", &bitmap_lf);
191
192 todo_wine
193 {
194     test_font_metrics(hdc, hfont, test_str, sizeof(test_str), &tm_orig, &size_orig, width_orig, 3, 3);
195 }
196     DeleteObject(hfont);
197
198     ReleaseDC(0, hdc);
199 }
200
201 static void test_gdi_objects(void)
202 {
203     BYTE buff[256];
204     HDC hdc = GetDC(NULL);
205     HPEN hp;
206     int i;
207     BOOL ret;
208
209     /* SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE.
210      * Note: Under XP at least invalid ptrs can also be passed, not just NULL;
211      *       Don't test that here in case it crashes earlier win versions.
212      */
213     SetLastError(0);
214     hp = SelectObject(NULL, GetStockObject(BLACK_PEN));
215     ok(!hp && GetLastError() == ERROR_INVALID_HANDLE,
216        "SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, 0x%08lx\n",
217        hp, GetLastError());
218
219     /* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */
220     SetLastError(0);
221     hp = SelectObject(hdc, NULL);
222     ok(!hp && !GetLastError(),
223        "SelectObject(NULL obj) expected 0, NO_ERROR, got %p, 0x%08lx\n",
224        hp, GetLastError());
225
226     /* The DC is unaffected by the NULL SelectObject */
227     SetLastError(0);
228     hp = SelectObject(hdc, GetStockObject(BLACK_PEN));
229     ok(hp && !GetLastError(),
230        "SelectObject(post NULL) expected non-null, NO_ERROR, got %p, 0x%08lx\n",
231        hp, GetLastError());
232
233     /* GetCurrentObject does not SetLastError() on a null object */
234     SetLastError(0);
235     hp = GetCurrentObject(NULL, OBJ_PEN);
236     ok(!hp && !GetLastError(),
237        "GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, 0x%08lx\n",
238        hp, GetLastError());
239
240     /* DeleteObject does not SetLastError() on a null object */
241     ret = DeleteObject(NULL);
242     ok( !ret && !GetLastError(),
243        "DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
244        ret, GetLastError());
245
246     /* GetObject does not SetLastError() on a null object */
247     SetLastError(0);
248     i = GetObjectA(NULL, sizeof(buff), buff);
249     ok (!i && !GetLastError(),
250         "GetObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
251         i, GetLastError());
252
253     /* GetObjectType does SetLastError() on a null object */
254     SetLastError(0);
255     i = GetObjectType(NULL);
256     ok (!i && GetLastError() == ERROR_INVALID_HANDLE,
257         "GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, 0x%08lx\n",
258         i, GetLastError());
259
260     /* UnrealizeObject does not SetLastError() on a null object */
261     SetLastError(0);
262     i = UnrealizeObject(NULL);
263     ok (!i && !GetLastError(),
264         "UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, 0x%08lx\n",
265         i, GetLastError());
266
267     ReleaseDC(NULL, hdc);
268 }
269
270 static void test_GdiGetCharDimensions(void)
271 {
272     HDC hdc;
273     TEXTMETRICW tm;
274     LONG ret;
275     SIZE size;
276     LONG avgwidth, height;
277     static const char szAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
278     typedef LONG (WINAPI *fnGdiGetCharDimensions)(HDC hdc, LPTEXTMETRICW lptm, LONG *height);
279     fnGdiGetCharDimensions GdiGetCharDimensions = (fnGdiGetCharDimensions)GetProcAddress(LoadLibrary("gdi32"), "GdiGetCharDimensions");
280     if (!GdiGetCharDimensions) return;
281
282     hdc = CreateCompatibleDC(NULL);
283
284     GetTextExtentPoint(hdc, szAlphabet, strlen(szAlphabet), &size);
285     avgwidth = ((size.cx / 26) + 1) / 2;
286
287     ret = GdiGetCharDimensions(hdc, &tm, &height);
288     ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
289     ok(height == tm.tmHeight, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", tm.tmHeight, height);
290
291     ret = GdiGetCharDimensions(hdc, &tm, NULL);
292     ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
293
294     ret = GdiGetCharDimensions(hdc, NULL, NULL);
295     ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
296
297     height = 0;
298     ret = GdiGetCharDimensions(hdc, NULL, &height);
299     ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
300     ok(height == size.cy, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", size.cy, height);
301
302     DeleteDC(hdc);
303 }
304
305 static void test_text_extents(void)
306 {
307     LOGFONTA lf;
308     TEXTMETRICA tm;
309     HDC hdc;
310     HFONT hfont;
311     SIZE sz;
312
313     memset(&lf, 0, sizeof(lf));
314     strcpy(lf.lfFaceName, "Arial");
315     lf.lfHeight = 20;
316
317     hfont = CreateFontIndirectA(&lf);
318     hdc = GetDC(0);
319     hfont = SelectObject(hdc, hfont);
320     GetTextMetricsA(hdc, &tm);
321     GetTextExtentPointA(hdc, "o", 1, &sz);
322     ok(sz.cy == tm.tmHeight, "cy %ld tmHeight %ld\n", sz.cy, tm.tmHeight);
323
324     SelectObject(hdc, hfont);
325     DeleteObject(hfont);
326     ReleaseDC(NULL, hdc);
327 }
328
329 struct hgdiobj_event
330 {
331     HDC hdc;
332     HGDIOBJ hgdiobj1;
333     HGDIOBJ hgdiobj2;
334     HANDLE stop_event;
335     HANDLE ready_event;
336 };
337
338 static DWORD WINAPI thread_proc(void *param)
339 {
340     LOGPEN lp;
341     struct hgdiobj_event *hgdiobj_event = (struct hgdiobj_event *)param;
342
343     hgdiobj_event->hdc = CreateDC("display", NULL, NULL, NULL);
344     ok(hgdiobj_event->hdc != NULL, "CreateDC error %ld\n", GetLastError());
345
346     hgdiobj_event->hgdiobj1 = CreatePen(PS_DASHDOTDOT, 17, RGB(1, 2, 3));
347     ok(hgdiobj_event->hgdiobj1 != 0, "Failed to create pen\n");
348
349     hgdiobj_event->hgdiobj2 = CreateRectRgn(0, 1, 12, 17);
350     ok(hgdiobj_event->hgdiobj2 != 0, "Failed to create pen\n");
351
352     SetEvent(hgdiobj_event->ready_event);
353     ok(WaitForSingleObject(hgdiobj_event->stop_event, INFINITE) == WAIT_OBJECT_0,
354        "WaitForSingleObject error %ld\n", GetLastError());
355
356     ok(!GetObject(hgdiobj_event->hgdiobj1, sizeof(lp), &lp), "GetObject should fail\n");
357
358     ok(!GetDeviceCaps(hgdiobj_event->hdc, TECHNOLOGY), "GetDeviceCaps(TECHNOLOGY) should fail\n");
359
360     return 0;
361 }
362
363 static void test_thread_objects(void)
364 {
365     LOGPEN lp;
366     DWORD tid, type;
367     HANDLE hthread;
368     struct hgdiobj_event hgdiobj_event;
369     INT ret;
370
371     hgdiobj_event.stop_event = CreateEvent(NULL, 0, 0, NULL);
372     ok(hgdiobj_event.stop_event != NULL, "CreateEvent error %ld\n", GetLastError());
373     hgdiobj_event.ready_event = CreateEvent(NULL, 0, 0, NULL);
374     ok(hgdiobj_event.ready_event != NULL, "CreateEvent error %ld\n", GetLastError());
375
376     hthread = CreateThread(NULL, 0, thread_proc, &hgdiobj_event, 0, &tid);
377     ok(hthread != NULL, "CreateThread error %ld\n", GetLastError());
378
379     ok(WaitForSingleObject(hgdiobj_event.ready_event, INFINITE) == WAIT_OBJECT_0,
380        "WaitForSingleObject error %ld\n", GetLastError());
381
382     ok(GetObject(hgdiobj_event.hgdiobj1, sizeof(lp), &lp) == sizeof(lp),
383        "GetObject error %ld\n", GetLastError());
384     ok(lp.lopnStyle == PS_DASHDOTDOT, "wrong pen style %d\n", lp.lopnStyle);
385     ok(lp.lopnWidth.x == 17, "wrong pen width.y %ld\n", lp.lopnWidth.x);
386     ok(lp.lopnWidth.y == 0, "wrong pen width.y %ld\n", lp.lopnWidth.y);
387     ok(lp.lopnColor == RGB(1, 2, 3), "wrong pen width.y %08lx\n", lp.lopnColor);
388
389     ret = GetDeviceCaps(hgdiobj_event.hdc, TECHNOLOGY);
390     ok(ret == DT_RASDISPLAY, "GetDeviceCaps(TECHNOLOGY) should return DT_RASDISPLAY not %d\n", ret);
391
392     ok(DeleteObject(hgdiobj_event.hgdiobj1), "DeleteObject error %ld\n", GetLastError());
393     ok(DeleteDC(hgdiobj_event.hdc), "DeleteDC error %ld\n", GetLastError());
394
395     type = GetObjectType(hgdiobj_event.hgdiobj2);
396     ok(type == OBJ_REGION, "GetObjectType returned %lu\n", type);
397
398     SetEvent(hgdiobj_event.stop_event);
399     ok(WaitForSingleObject(hthread, INFINITE) == WAIT_OBJECT_0,
400        "WaitForSingleObject error %ld\n", GetLastError());
401     CloseHandle(hthread);
402
403     type = GetObjectType(hgdiobj_event.hgdiobj2);
404     ok(type == OBJ_REGION, "GetObjectType returned %lu\n", type);
405     ok(DeleteObject(hgdiobj_event.hgdiobj2), "DeleteObject error %ld\n", GetLastError());
406
407     CloseHandle(hgdiobj_event.stop_event);
408     CloseHandle(hgdiobj_event.ready_event);
409 }
410
411 static void test_GetCurrentObject(void)
412 {
413     DWORD type;
414     HPEN hpen;
415     HBRUSH hbrush;
416     HPALETTE hpal;
417     HFONT hfont;
418     HBITMAP hbmp;
419     HRGN hrgn;
420     HDC hdc;
421     HCOLORSPACE hcs;
422     HGDIOBJ hobj;
423     LOGBRUSH lb;
424     LOGCOLORSPACEA lcs;
425
426     hdc = CreateCompatibleDC(0);
427     assert(hdc != 0);
428
429     type = GetObjectType(hdc);
430     ok(type == OBJ_MEMDC, "GetObjectType returned %lu\n", type);
431
432     hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30));
433     assert(hpen != 0);
434     SelectObject(hdc, hpen);
435     hobj = GetCurrentObject(hdc, OBJ_PEN);
436     ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
437     hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
438     ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
439
440     hbrush = CreateSolidBrush(RGB(10, 20, 30));
441     assert(hbrush != 0);
442     SelectObject(hdc, hbrush);
443     hobj = GetCurrentObject(hdc, OBJ_BRUSH);
444     ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj);
445
446     hpal = CreateHalftonePalette(hdc);
447     assert(hpal != 0);
448     SelectPalette(hdc, hpal, FALSE);
449     hobj = GetCurrentObject(hdc, OBJ_PAL);
450     ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj);
451
452     hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET,
453                         OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
454                         DEFAULT_PITCH, "MS Sans Serif");
455     assert(hfont != 0);
456     SelectObject(hdc, hfont);
457     hobj = GetCurrentObject(hdc, OBJ_FONT);
458     ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj);
459
460     hbmp = CreateBitmap(100, 100, 1, 1, NULL);
461     assert(hbmp != 0);
462     SelectObject(hdc, hbmp);
463     hobj = GetCurrentObject(hdc, OBJ_BITMAP);
464     ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj);
465
466     assert(GetObject(hbrush, sizeof(lb), &lb) == sizeof(lb));
467     hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE | PS_JOIN_BEVEL,
468                         10, &lb, 0, NULL);
469     assert(hpen != 0);
470     SelectObject(hdc, hpen);
471     hobj = GetCurrentObject(hdc, OBJ_PEN);
472     ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
473     hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
474     ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);
475
476     hcs = GetColorSpace(hdc);
477     if (hcs)
478     {
479         trace("current color space is not NULL\n");
480         ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n");
481         hcs = CreateColorSpaceA(&lcs);
482         ok(hcs != 0, "CreateColorSpace failed\n");
483         SelectObject(hdc, hcs);
484         hobj = GetCurrentObject(hdc, OBJ_COLORSPACE);
485         ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj);
486     }
487
488     hrgn = CreateRectRgn(1, 1, 100, 100);
489     assert(hrgn != 0);
490     SelectObject(hdc, hrgn);
491     hobj = GetCurrentObject(hdc, OBJ_REGION);
492     ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj);
493
494     DeleteDC(hdc);
495 }
496
497 static void test_logpen(void)
498 {
499     static const struct
500     {
501         UINT style;
502         INT width;
503         COLORREF color;
504         UINT ret_style;
505         INT ret_width;
506         COLORREF ret_color;
507     } pen[] = {
508         { PS_SOLID, -123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
509         { PS_SOLID, 0, RGB(0x12,0x34,0x56), PS_SOLID, 0, RGB(0x12,0x34,0x56) },
510         { PS_SOLID, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
511         { PS_DASH, 123, RGB(0x12,0x34,0x56), PS_DASH, 123, RGB(0x12,0x34,0x56) },
512         { PS_DOT, 123, RGB(0x12,0x34,0x56), PS_DOT, 123, RGB(0x12,0x34,0x56) },
513         { PS_DASHDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOT, 123, RGB(0x12,0x34,0x56) },
514         { PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56), PS_DASHDOTDOT, 123, RGB(0x12,0x34,0x56) },
515         { PS_NULL, -123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 },
516         { PS_NULL, 123, RGB(0x12,0x34,0x56), PS_NULL, 1, 0 },
517         { PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56), PS_INSIDEFRAME, 123, RGB(0x12,0x34,0x56) },
518         { PS_USERSTYLE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) },
519         { PS_ALTERNATE, 123, RGB(0x12,0x34,0x56), PS_SOLID, 123, RGB(0x12,0x34,0x56) }
520     };
521     INT i, size;
522     HPEN hpen;
523     LOGPEN lp;
524     EXTLOGPEN elp;
525     LOGBRUSH lb;
526     DWORD obj_type, user_style[2] = { 0xabc, 0xdef };
527     struct
528     {
529         EXTLOGPEN elp;
530         DWORD style_data[10];
531     } ext_pen;
532
533     for (i = 0; i < sizeof(pen)/sizeof(pen[0]); i++)
534     {
535         trace("testing style %u\n", pen[i].style);
536
537         /********************** cosmetic pens **********************/
538         /* CreatePenIndirect behaviour */
539         lp.lopnStyle = pen[i].style,
540         lp.lopnWidth.x = pen[i].width;
541         lp.lopnWidth.y = 11; /* just in case */
542         lp.lopnColor = pen[i].color;
543         SetLastError(0xdeadbeef);
544         hpen = CreatePenIndirect(&lp);
545         ok(hpen != 0, "CreatePen error %ld\n", GetLastError());
546
547         obj_type = GetObjectType(hpen);
548         ok(obj_type == OBJ_PEN, "wrong object type %lu\n", obj_type);
549
550         memset(&lp, 0xb0, sizeof(lp));
551         SetLastError(0xdeadbeef);
552         size = GetObject(hpen, sizeof(lp), &lp);
553         ok(size == sizeof(lp), "GetObject returned %d, error %ld\n", size, GetLastError());
554
555         ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
556         ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
557         ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
558         ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
559
560         DeleteObject(hpen);
561
562         /* CreatePen behaviour */
563         SetLastError(0xdeadbeef);
564         hpen = CreatePen(pen[i].style, pen[i].width, pen[i].color);
565         ok(hpen != 0, "CreatePen error %ld\n", GetLastError());
566
567         obj_type = GetObjectType(hpen);
568         ok(obj_type == OBJ_PEN, "wrong object type %lu\n", obj_type);
569
570         /* check what's the real size of the object */
571         size = GetObject(hpen, 0, NULL);
572         ok(size == sizeof(lp), "GetObject returned %d, error %ld\n", size, GetLastError());
573
574         /* ask for truncated data */
575         memset(&lp, 0xb0, sizeof(lp));
576         SetLastError(0xdeadbeef);
577         size = GetObject(hpen, sizeof(lp.lopnStyle), &lp);
578         ok(!size, "GetObject should fail: size %d, error %ld\n", size, GetLastError());
579
580         /* see how larger buffer sizes are handled */
581         memset(&lp, 0xb0, sizeof(lp));
582         SetLastError(0xdeadbeef);
583         size = GetObject(hpen, sizeof(lp) * 2, &lp);
584         ok(size == sizeof(lp), "GetObject returned %d, error %ld\n", size, GetLastError());
585
586         /* see how larger buffer sizes are handled */
587         memset(&elp, 0xb0, sizeof(elp));
588         SetLastError(0xdeadbeef);
589         size = GetObject(hpen, sizeof(elp) * 2, &elp);
590         ok(size == sizeof(lp), "GetObject returned %d, error %ld\n", size, GetLastError());
591
592         memset(&lp, 0xb0, sizeof(lp));
593         SetLastError(0xdeadbeef);
594         size = GetObject(hpen, sizeof(lp), &lp);
595         ok(size == sizeof(lp), "GetObject returned %d, error %ld\n", size, GetLastError());
596
597         ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
598         ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
599         ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
600         ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
601
602         memset(&elp, 0xb0, sizeof(elp));
603         SetLastError(0xdeadbeef);
604         size = GetObject(hpen, sizeof(elp), &elp);
605
606         /* for some reason XP differentiates PS_NULL here */
607         if (pen[i].style == PS_NULL)
608         {
609             ok(size == sizeof(EXTLOGPEN), "GetObject returned %d, error %ld\n", size, GetLastError());
610             ok(elp.elpPenStyle == pen[i].ret_style, "expected %u, got %lu\n", pen[i].ret_style, elp.elpPenStyle);
611             ok(elp.elpWidth == 0, "expected 0, got %lu\n", elp.elpWidth);
612             ok(elp.elpColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, elp.elpColor);
613             ok(elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %u\n", elp.elpBrushStyle);
614             ok(elp.elpHatch == 0, "expected 0, got %p\n", (void *)elp.elpHatch);
615             ok(elp.elpNumEntries == 0, "expected 0, got %lx\n", elp.elpNumEntries);
616         }
617         else
618         {
619             ok(size == sizeof(LOGPEN), "GetObject returned %d, error %ld\n", size, GetLastError());
620             memcpy(&lp, &elp, sizeof(lp));
621             ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
622             ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
623             ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
624             ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
625         }
626
627         DeleteObject(hpen);
628
629         /********** cosmetic pens created by ExtCreatePen ***********/
630         lb.lbStyle = BS_SOLID;
631         lb.lbColor = pen[i].color;
632         lb.lbHatch = HS_CROSS; /* just in case */
633         SetLastError(0xdeadbeef);
634         hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 2, user_style);
635         if (pen[i].style != PS_USERSTYLE)
636         {
637             ok(hpen == 0, "ExtCreatePen should fail\n");
638             ok(GetLastError() == ERROR_INVALID_PARAMETER,
639                "wrong last error value %ld\n", GetLastError());
640             SetLastError(0xdeadbeef);
641             hpen = ExtCreatePen(pen[i].style, pen[i].width, &lb, 0, NULL);
642             if (pen[i].style != PS_NULL)
643             {
644                 ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n");
645                 ok(GetLastError() == ERROR_INVALID_PARAMETER,
646                    "wrong last error value %ld\n", GetLastError());
647
648                 SetLastError(0xdeadbeef);
649                 hpen = ExtCreatePen(pen[i].style, 1, &lb, 0, NULL);
650             }
651         }
652         else
653         {
654             ok(hpen == 0, "ExtCreatePen with width != 1 should fail\n");
655             ok(GetLastError() == ERROR_INVALID_PARAMETER,
656                "wrong last error value %ld\n", GetLastError());
657             SetLastError(0xdeadbeef);
658             hpen = ExtCreatePen(pen[i].style, 1, &lb, 2, user_style);
659         }
660         if (pen[i].style == PS_INSIDEFRAME)
661         {
662             /* This style is applicable only for gemetric pens */
663             ok(hpen == 0, "ExtCreatePen should fail\n");
664             goto test_geometric_pens;
665         }
666         ok(hpen != 0, "ExtCreatePen error %ld\n", GetLastError());
667
668         obj_type = GetObjectType(hpen);
669         /* for some reason XP differentiates PS_NULL here */
670         if (pen[i].style == PS_NULL)
671             ok(obj_type == OBJ_PEN, "wrong object type %lu\n", obj_type);
672         else
673             ok(obj_type == OBJ_EXTPEN, "wrong object type %lu\n", obj_type);
674
675         /* check what's the real size of the object */
676         SetLastError(0xdeadbeef);
677         size = GetObject(hpen, 0, NULL);
678         switch (pen[i].style)
679         {
680         case PS_NULL:
681             ok(size == sizeof(LOGPEN),
682                "GetObject returned %d, error %ld\n", size, GetLastError());
683             break;
684
685         case PS_USERSTYLE:
686             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
687                "GetObject returned %d, error %ld\n", size, GetLastError());
688             break;
689
690         default:
691             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
692                "GetObject returned %d, error %ld\n", size, GetLastError());
693             break;
694         }
695
696         /* ask for truncated data */
697         memset(&elp, 0xb0, sizeof(elp));
698         SetLastError(0xdeadbeef);
699         size = GetObject(hpen, sizeof(elp.elpPenStyle), &elp);
700         ok(!size, "GetObject should fail: size %d, error %ld\n", size, GetLastError());
701
702         /* see how larger buffer sizes are handled */
703         memset(&ext_pen, 0xb0, sizeof(ext_pen));
704         SetLastError(0xdeadbeef);
705         size = GetObject(hpen, sizeof(ext_pen), &ext_pen.elp);
706         switch (pen[i].style)
707         {
708         case PS_NULL:
709             ok(size == sizeof(LOGPEN),
710                "GetObject returned %d, error %ld\n", size, GetLastError());
711             memcpy(&lp, &ext_pen.elp, sizeof(lp));
712             ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
713             ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
714             ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
715             ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
716
717             /* for PS_NULL it also works this way */
718             memset(&elp, 0xb0, sizeof(elp));
719             SetLastError(0xdeadbeef);
720             size = GetObject(hpen, sizeof(elp), &elp);
721             ok(size == sizeof(EXTLOGPEN),
722                 "GetObject returned %d, error %ld\n", size, GetLastError());
723             ok(ext_pen.elp.elpHatch == 0xb0b0b0b0, "expected 0xb0b0b0b0, got %p\n", (void *)ext_pen.elp.elpHatch);
724             ok(ext_pen.elp.elpNumEntries == 0xb0b0b0b0, "expected 0xb0b0b0b0, got %lx\n", ext_pen.elp.elpNumEntries);
725             break;
726
727         case PS_USERSTYLE:
728             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
729                "GetObject returned %d, error %ld\n", size, GetLastError());
730             ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
731             ok(ext_pen.elp.elpNumEntries == 2, "expected 0, got %lx\n", ext_pen.elp.elpNumEntries);
732             ok(ext_pen.elp.elpStyleEntry[0] == 0xabc, "expected 0xabc, got %lx\n", ext_pen.elp.elpStyleEntry[0]);
733             ok(ext_pen.elp.elpStyleEntry[1] == 0xdef, "expected 0xabc, got %lx\n", ext_pen.elp.elpStyleEntry[1]);
734             break;
735
736         default:
737             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
738                "GetObject returned %d, error %ld\n", size, GetLastError());
739             ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
740             ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %lx\n", ext_pen.elp.elpNumEntries);
741             break;
742         }
743
744 if (pen[i].style == PS_USERSTYLE)
745 {
746     todo_wine
747         ok(ext_pen.elp.elpPenStyle == pen[i].style, "expected %x, got %lx\n", pen[i].style, ext_pen.elp.elpPenStyle);
748 }
749 else
750         ok(ext_pen.elp.elpPenStyle == pen[i].style, "expected %x, got %lx\n", pen[i].style, ext_pen.elp.elpPenStyle);
751         ok(ext_pen.elp.elpWidth == 1, "expected 1, got %lx\n", ext_pen.elp.elpWidth);
752         ok(ext_pen.elp.elpColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, ext_pen.elp.elpColor);
753         ok(ext_pen.elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen.elp.elpBrushStyle);
754
755         DeleteObject(hpen);
756
757 test_geometric_pens:
758         /********************** geometric pens **********************/
759         lb.lbStyle = BS_SOLID;
760         lb.lbColor = pen[i].color;
761         lb.lbHatch = HS_CROSS; /* just in case */
762         SetLastError(0xdeadbeef);
763         hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 2, user_style);
764         if (pen[i].style != PS_USERSTYLE)
765         {
766             ok(hpen == 0, "ExtCreatePen should fail\n");
767             SetLastError(0xdeadbeef);
768             hpen = ExtCreatePen(PS_GEOMETRIC | pen[i].style, pen[i].width, &lb, 0, NULL);
769         }
770         if (pen[i].style == PS_ALTERNATE)
771         {
772             /* This style is applicable only for cosmetic pens */
773             ok(hpen == 0, "ExtCreatePen should fail\n");
774             continue;
775         }
776         ok(hpen != 0, "ExtCreatePen error %ld\n", GetLastError());
777
778         obj_type = GetObjectType(hpen);
779         /* for some reason XP differentiates PS_NULL here */
780         if (pen[i].style == PS_NULL)
781             ok(obj_type == OBJ_PEN, "wrong object type %lu\n", obj_type);
782         else
783             ok(obj_type == OBJ_EXTPEN, "wrong object type %lu\n", obj_type);
784
785         /* check what's the real size of the object */
786         size = GetObject(hpen, 0, NULL);
787         switch (pen[i].style)
788         {
789         case PS_NULL:
790             ok(size == sizeof(LOGPEN),
791                "GetObject returned %d, error %ld\n", size, GetLastError());
792             break;
793
794         case PS_USERSTYLE:
795             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
796                "GetObject returned %d, error %ld\n", size, GetLastError());
797             break;
798
799         default:
800             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
801                "GetObject returned %d, error %ld\n", size, GetLastError());
802             break;
803         }
804
805         /* ask for truncated data */
806         memset(&lp, 0xb0, sizeof(lp));
807         SetLastError(0xdeadbeef);
808         size = GetObject(hpen, sizeof(lp.lopnStyle), &lp);
809         ok(!size, "GetObject should fail: size %d, error %ld\n", size, GetLastError());
810
811         memset(&lp, 0xb0, sizeof(lp));
812         SetLastError(0xdeadbeef);
813         size = GetObject(hpen, sizeof(lp), &lp);
814         /* for some reason XP differenciates PS_NULL here */
815         if (pen[i].style == PS_NULL)
816         {
817             ok(size == sizeof(LOGPEN), "GetObject returned %d, error %ld\n", size, GetLastError());
818             ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
819             ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
820             ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
821             ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
822         }
823         else
824             /* XP doesn't set last error here */
825             ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/,
826                "GetObject should fail: size %d, error %ld\n", size, GetLastError());
827
828         memset(&ext_pen, 0xb0, sizeof(ext_pen));
829         SetLastError(0xdeadbeef);
830         /* buffer is too small for user styles */
831         size = GetObject(hpen, sizeof(elp), &ext_pen.elp);
832         switch (pen[i].style)
833         {
834         case PS_NULL:
835             ok(size == sizeof(EXTLOGPEN),
836                 "GetObject returned %d, error %ld\n", size, GetLastError());
837             ok(ext_pen.elp.elpHatch == 0, "expected 0, got %p\n", (void *)ext_pen.elp.elpHatch);
838             ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %lx\n", ext_pen.elp.elpNumEntries);
839
840             /* for PS_NULL it also works this way */
841             SetLastError(0xdeadbeef);
842             size = GetObject(hpen, sizeof(ext_pen), &lp);
843             ok(size == sizeof(LOGPEN),
844                 "GetObject returned %d, error %ld\n", size, GetLastError());
845             ok(lp.lopnStyle == pen[i].ret_style, "expected %u, got %u\n", pen[i].ret_style, lp.lopnStyle);
846             ok(lp.lopnWidth.x == pen[i].ret_width, "expected %u, got %ld\n", pen[i].ret_width, lp.lopnWidth.x);
847             ok(lp.lopnWidth.y == 0, "expected 0, got %ld\n", lp.lopnWidth.y);
848             ok(lp.lopnColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, lp.lopnColor);
849             break;
850
851         case PS_USERSTYLE:
852             ok(!size /*&& GetLastError() == ERROR_INVALID_PARAMETER*/,
853                "GetObject should fail: size %d, error %ld\n", size, GetLastError());
854             size = GetObject(hpen, sizeof(ext_pen), &ext_pen.elp);
855             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry) + sizeof(user_style),
856                "GetObject returned %d, error %ld\n", size, GetLastError());
857             ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
858             ok(ext_pen.elp.elpNumEntries == 2, "expected 0, got %lx\n", ext_pen.elp.elpNumEntries);
859             ok(ext_pen.elp.elpStyleEntry[0] == 0xabc, "expected 0xabc, got %lx\n", ext_pen.elp.elpStyleEntry[0]);
860             ok(ext_pen.elp.elpStyleEntry[1] == 0xdef, "expected 0xabc, got %lx\n", ext_pen.elp.elpStyleEntry[1]);
861             break;
862
863         default:
864             ok(size == sizeof(EXTLOGPEN) - sizeof(elp.elpStyleEntry),
865                "GetObject returned %d, error %ld\n", size, GetLastError());
866             ok(ext_pen.elp.elpHatch == HS_CROSS, "expected HS_CROSS, got %p\n", (void *)ext_pen.elp.elpHatch);
867             ok(ext_pen.elp.elpNumEntries == 0, "expected 0, got %lx\n", ext_pen.elp.elpNumEntries);
868             break;
869         }
870
871         /* for some reason XP differenciates PS_NULL here */
872         if (pen[i].style == PS_NULL)
873             ok(ext_pen.elp.elpPenStyle == pen[i].ret_style, "expected %x, got %lx\n", pen[i].ret_style, ext_pen.elp.elpPenStyle);
874         else
875         {
876 if (pen[i].style == PS_USERSTYLE)
877 {
878     todo_wine
879             ok(ext_pen.elp.elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %lx\n", PS_GEOMETRIC | pen[i].style, ext_pen.elp.elpPenStyle);
880 }
881 else
882             ok(ext_pen.elp.elpPenStyle == (PS_GEOMETRIC | pen[i].style), "expected %x, got %lx\n", PS_GEOMETRIC | pen[i].style, ext_pen.elp.elpPenStyle);
883         }
884
885         if (pen[i].style == PS_NULL)
886             ok(ext_pen.elp.elpWidth == 0, "expected 0, got %lx\n", ext_pen.elp.elpWidth);
887         else
888             ok(ext_pen.elp.elpWidth == pen[i].ret_width, "expected %u, got %lx\n", pen[i].ret_width, ext_pen.elp.elpWidth);
889         ok(ext_pen.elp.elpColor == pen[i].ret_color, "expected %08lx, got %08lx\n", pen[i].ret_color, ext_pen.elp.elpColor);
890         ok(ext_pen.elp.elpBrushStyle == BS_SOLID, "expected BS_SOLID, got %x\n", ext_pen.elp.elpBrushStyle);
891
892         DeleteObject(hpen);
893     }
894 }
895
896 START_TEST(gdiobj)
897 {
898     test_logfont();
899     test_logpen();
900     test_bitmap_font();
901     test_gdi_objects();
902     test_GdiGetCharDimensions();
903     test_text_extents();
904     test_thread_objects();
905     test_GetCurrentObject();
906 }