4 * Copyright 2003 Marcus Meissner
5 * Copyright 2006 (Google) Benjamin Arai
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include <wine/test.h>
43 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
45 static WCHAR MSSansSerif_font[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
46 static WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
47 static WCHAR arial_font[] = { 'A','r','i','a','l',0 };
48 static WCHAR marlett_font[] = { 'M','a','r','l','e','t','t',0 };
50 static HMODULE hOleaut32;
52 static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
54 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
56 /* Create a font with cySize given by lo_size, hi_size, */
57 /* SetRatio to ratio_logical, ratio_himetric, */
58 /* check that resulting hfont has height hfont_height. */
59 /* Various checks along the way. */
60 static void test_ifont_size(LONG lo_size, LONG hi_size,
61 LONG ratio_logical, LONG ratio_himetric,
62 LONG hfont_height, const char * test_name)
73 fd.cbSizeofstruct = sizeof(FONTDESC);
74 fd.lpstrName = arial_font; /* using scaleable instead of bitmap font reduces errors due to font realization */
75 S(fd.cySize).Lo = lo_size;
76 S(fd.cySize).Hi = hi_size;
81 fd.fStrikethrough = 0;
83 /* Create font, test that it worked. */
84 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
86 ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
88 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
90 /* If scaling ration specified, change ratio. */
91 if(ratio_logical && ratio_himetric)
93 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
94 ok(hres == S_OK,"%s: IFont_SetRatio returns 0x%08x instead of S_OK.\n",
99 hres = IFont_get_Size(ifnt, &psize);
100 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
103 /* Check returned size - allow for errors due to rouding & font realization. */
104 ok((abs(S(psize).Lo - lo_size) < 10000) && S(psize).Hi == hi_size,
105 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
106 test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);
108 /* Check hFont size. */
109 hres = IFont_get_hFont (ifnt, &hfont);
110 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
112 rtnval = GetObject (hfont, sizeof(LOGFONT), &lf);
113 ok(rtnval > 0, "GetObject(hfont) failed\n");
115 /* Since font scaling may encounter rouding errors, allow 1 pixel deviation. */
116 ok(abs(lf.lfHeight - hfont_height) <= 1,
117 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
118 test_name, lf.lfHeight, hfont_height);
124 static void test_ifont_sizes(void)
126 /* Test various size operations and conversions. */
127 /* Add more as needed. */
129 /* Results of first 2 tests depend on display resolution. */
131 LONG dpi = GetDeviceCaps(hdc, LOGPIXELSY); /* expected results depend on display DPI */
133 if(dpi == 96) /* normal resolution display */
135 test_ifont_size(180000, 0, 0, 0, -24, "default"); /* normal font */
136 test_ifont_size(186000, 0, 0, 0, -25, "rounding"); /* test rounding */
137 } else if(dpi == 72) /* low resolution display */
139 test_ifont_size(180000, 0, 0, 0, -18, "default"); /* normal font */
140 test_ifont_size(186000, 0, 0, 0, -19, "rounding"); /* test rounding */
141 } else if(dpi == 120) /* high resolution display */
143 test_ifont_size(180000, 0, 0, 0, -30, "default"); /* normal font */
144 test_ifont_size(186000, 0, 0, 0, -31, "rounding"); /* test rounding */
146 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi);
148 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
149 test_ifont_size(180000, 0, 72, 2540, -18, "ratio1"); /* change ratio */
150 test_ifont_size(180000, 0, 144, 2540, -36, "ratio2"); /* another ratio */
151 test_ifont_size(180000, 0, 72, 1270, -36, "ratio3"); /* yet another ratio */
152 test_ifont_size(186000, 0, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
155 static void test_QueryInterface(void)
162 hres = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
163 ok(hres == E_POINTER, "got 0x%08x\n", hres);
165 hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
168 ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
169 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
172 hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);
174 /* Test if QueryInterface increments ref counter for IFONTs */
175 ret = IFont_AddRef(font);
177 broken(ret == 1), /* win95 */
178 "IFont_QI expected ref value 3 but instead got %d\n",ret);
181 ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
182 ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
184 /* Original ref and QueryInterface ref both have to be released */
189 static void test_type_info(void)
193 IFontDisp* fontdisp = NULL;
195 WCHAR name_Name[] = {'N','a','m','e',0};
198 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
200 DISPPARAMS dispparams;
203 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
206 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
207 ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
208 ok(pTInfo != NULL, "GTI returned NULL.\n");
210 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
211 ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
212 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
213 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
214 SysFreeString(names[0]);
216 ITypeInfo_Release(pTInfo);
218 dispparams.cNamedArgs = 0;
219 dispparams.rgdispidNamedArgs = NULL;
220 dispparams.cArgs = 0;
221 dispparams.rgvarg = NULL;
222 VariantInit(&varresult);
223 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
224 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
226 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
227 VariantClear(&varresult);
229 IFontDisp_Release(fontdisp);
232 static HRESULT WINAPI FontEventsDisp_QueryInterface(
233 IFontEventsDisp *iface,
234 /* [in] */ REFIID riid,
235 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
237 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
239 IUnknown_AddRef(iface);
246 return E_NOINTERFACE;
250 static ULONG WINAPI FontEventsDisp_AddRef(
251 IFontEventsDisp *iface)
256 static ULONG WINAPI FontEventsDisp_Release(
257 IFontEventsDisp *iface)
262 static int fonteventsdisp_invoke_called = 0;
264 static HRESULT WINAPI FontEventsDisp_Invoke(
265 IFontEventsDisp __RPC_FAR * iface,
266 /* [in] */ DISPID dispIdMember,
267 /* [in] */ REFIID riid,
268 /* [in] */ LCID lcid,
269 /* [in] */ WORD wFlags,
270 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
271 /* [out] */ VARIANT __RPC_FAR *pVarResult,
272 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
273 /* [out] */ UINT __RPC_FAR *puArgErr)
275 static const WCHAR wszBold[] = {'B','o','l','d',0};
276 ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
277 ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
278 ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
279 ok(V_VT(&pDispParams->rgvarg[0]) == VT_BSTR, "VT of first param should have been VT_BSTR instead of %d\n", V_VT(&pDispParams->rgvarg[0]));
280 ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
282 fonteventsdisp_invoke_called++;
286 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
288 FontEventsDisp_QueryInterface,
289 FontEventsDisp_AddRef,
290 FontEventsDisp_Release,
294 FontEventsDisp_Invoke
297 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
299 static void test_font_events_disp(void)
303 IConnectionPointContainer *pCPC;
304 IConnectionPoint *pCP;
308 IFontDisp *pFontDisp;
309 DISPPARAMS dispparams;
312 fontdesc.cbSizeofstruct = sizeof(fontdesc);
313 fontdesc.lpstrName = MSSansSerif_font;
314 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
315 fontdesc.sWeight = FW_NORMAL;
316 fontdesc.sCharset = 0;
317 fontdesc.fItalic = FALSE;
318 fontdesc.fUnderline = FALSE;
319 fontdesc.fStrikethrough = FALSE;
321 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
322 ok_ole_success(hr, "OleCreateFontIndirect");
324 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
325 ok_ole_success(hr, "IFont_QueryInterface");
327 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
328 ok_ole_success(hr, "IConnectionPointContainer_FindConnectionPoint");
329 IConnectionPointContainer_Release(pCPC);
331 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
332 ok_ole_success(hr, "IConnectionPoint_Advise");
333 IConnectionPoint_Release(pCP);
335 hr = IFont_put_Bold(pFont, TRUE);
336 ok_ole_success(hr, "IFont_put_Bold");
338 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
340 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
341 ok_ole_success(hr, "IFont_QueryInterface");
343 V_VT(&vararg) = VT_BOOL;
344 V_BOOL(&vararg) = VARIANT_FALSE;
345 dispparams.cNamedArgs = 0;
346 dispparams.rgdispidNamedArgs = NULL;
347 dispparams.cArgs = 1;
348 dispparams.rgvarg = &vararg;
349 hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
350 ok(hr == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hr);
352 IFontDisp_Release(pFontDisp);
354 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
355 fonteventsdisp_invoke_called);
357 hr = IFont_Clone(pFont, &pFont2);
358 ok_ole_success(hr, "IFont_Clone");
359 IFont_Release(pFont);
361 hr = IFont_put_Bold(pFont2, FALSE);
362 ok_ole_success(hr, "IFont_put_Bold");
364 /* this test shows that the notification routine isn't called again */
365 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
366 fonteventsdisp_invoke_called);
368 IFont_Release(pFont2);
371 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
372 WCHAR* w_name_2, const char* a_name_2,
373 LCID lcid, DISPID id_1, DISPID id_2,
374 HRESULT hres_expect, int numnames)
377 IFontDisp *fontdisp = NULL;
379 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
380 LPOLESTR names[2] = {w_name_1, w_name_2};
382 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
385 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
389 ok(hres == hres_expect,
390 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
391 a_name_1, a_name_2, hres, hres_expect);
393 /* test first DISPID */
394 ok(rgDispId[0]==id_1,
395 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
396 a_name_1, rgDispId[0], id_1);
398 /* test second DISPID is present */
401 ok(rgDispId[1]==id_2,
402 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
403 a_name_2, rgDispId[1], id_2);
406 IFontDisp_Release(fontdisp);
409 static void test_GetIDsOfNames(void)
411 WCHAR name_Name[] = {'N','a','m','e',0};
412 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
413 WCHAR name_Size[] = {'S','i','z','e',0};
414 WCHAR name_Bold[] = {'B','o','l','d',0};
415 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
416 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
417 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
418 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
419 WCHAR name_Foo[] = {'F','o','o',0};
420 WCHAR name_nAmE[] = {'n','A','m','E',0};
421 WCHAR name_Nom[] = {'N','o','m',0};
423 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
425 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
428 /* Test DISPID_FONTs for the various properties. */
429 test_names_ids(name_Name, "Name", NULL, "", en_us,
430 DISPID_FONT_NAME, 0, S_OK,1);
431 test_names_ids(name_Size, "Size", NULL, "", en_us,
432 DISPID_FONT_SIZE, 0, S_OK,1);
433 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
434 DISPID_FONT_BOLD, 0, S_OK,1);
435 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
436 DISPID_FONT_ITALIC, 0, S_OK,1);
437 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
438 DISPID_FONT_UNDER, 0, S_OK,1);
439 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
440 DISPID_FONT_STRIKE, 0, S_OK,1);
441 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
442 DISPID_FONT_WEIGHT, 0, S_OK,1);
443 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
444 DISPID_FONT_CHARSET, 0, S_OK,1);
446 /* Capitalization doesn't matter. */
447 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
448 DISPID_FONT_NAME, 0, S_OK,1);
451 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
452 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
454 /* Pass several names: first is processed, */
455 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
456 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
457 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
458 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
459 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
461 /* Locale ID has no effect. */
462 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
463 DISPID_FONT_NAME, 0, S_OK,1);
464 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
465 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
467 /* One of the arguments are invalid */
468 test_names_ids(name_Name, "Name", NULL, "", en_us,
469 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
470 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
471 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
472 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
473 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
475 /* Crazy locale ID? */
476 test_names_ids(name_Name, "Name", NULL, "", -1,
477 DISPID_FONT_NAME, 0, S_OK,1);
480 static void test_Invoke(void)
485 DISPPARAMS dispparams;
488 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
489 ok_ole_success(hr, "OleCreateFontIndirect");
491 V_VT(&vararg) = VT_BOOL;
492 V_BOOL(&vararg) = VARIANT_FALSE;
493 dispparams.cNamedArgs = 0;
494 dispparams.rgdispidNamedArgs = NULL;
495 dispparams.cArgs = 1;
496 dispparams.rgvarg = &vararg;
497 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
498 ok(hr == DISP_E_UNKNOWNINTERFACE, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr);
500 dispparams.cArgs = 0;
501 dispparams.rgvarg = NULL;
502 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
503 ok(hr == DISP_E_BADPARAMCOUNT, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
505 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
506 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
508 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
509 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
511 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
512 ok_ole_success(hr, "IFontDisp_Invoke");
514 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
515 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
517 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
518 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
520 dispparams.cArgs = 1;
521 dispparams.rgvarg = &vararg;
522 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
523 ok_ole_success(hr, "IFontDisp_Invoke");
525 IFontDisp_Release(fontdisp);
528 static void test_IsEqual(void)
535 /* Basic font description */
536 fd.cbSizeofstruct = sizeof(FONTDESC);
537 fd.lpstrName = system_font;
538 S(fd.cySize).Lo = 100;
539 S(fd.cySize).Hi = 100;
544 fd.fStrikethrough = 0;
547 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);
549 /* Test equal fonts */
550 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
551 hres = IFont_IsEqual(ifnt,ifnt2);
553 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
554 IFont_Release(ifnt2);
556 /* Check for bad pointer */
557 hres = IFont_IsEqual(ifnt,NULL);
558 ok(hres == E_POINTER,
559 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
562 fd.lpstrName = arial_font;
563 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
564 hres = IFont_IsEqual(ifnt,ifnt2);
566 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
567 fd.lpstrName = system_font;
568 IFont_Release(ifnt2);
570 /* Test lo font size */
571 S(fd.cySize).Lo = 10000;
572 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
573 hres = IFont_IsEqual(ifnt,ifnt2);
575 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
576 S(fd.cySize).Lo = 100;
577 IFont_Release(ifnt2);
579 /* Test hi font size */
580 S(fd.cySize).Hi = 10000;
581 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
582 hres = IFont_IsEqual(ifnt,ifnt2);
584 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
585 S(fd.cySize).Hi = 100;
586 IFont_Release(ifnt2);
588 /* Test font weight */
590 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
591 hres = IFont_IsEqual(ifnt,ifnt2);
593 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
595 IFont_Release(ifnt2);
599 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
600 hres = IFont_IsEqual(ifnt,ifnt2);
602 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
604 IFont_Release(ifnt2);
606 /* Test italic setting */
608 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
609 hres = IFont_IsEqual(ifnt,ifnt2);
611 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
613 IFont_Release(ifnt2);
615 /* Test underline setting */
617 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
618 hres = IFont_IsEqual(ifnt,ifnt2);
620 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
622 IFont_Release(ifnt2);
624 /* Test strikethrough setting */
625 fd.fStrikethrough = 1;
626 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
627 hres = IFont_IsEqual(ifnt,ifnt2);
629 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
630 fd.fStrikethrough = 0;
631 IFont_Release(ifnt2);
637 static void test_ReleaseHfont(void)
640 LPVOID pvObj1 = NULL;
641 LPVOID pvObj2 = NULL;
648 /* Basic font description */
649 fd.cbSizeofstruct = sizeof(FONTDESC);
650 fd.lpstrName = system_font;
651 S(fd.cySize).Lo = 100;
652 S(fd.cySize).Hi = 100;
657 fd.fStrikethrough = 0;
659 /* Create HFONTs and IFONTs */
660 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
662 IFont_get_hFont(ifnt1,&hfnt1);
663 fd.lpstrName = arial_font;
664 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
666 IFont_get_hFont(ifnt2,&hfnt2);
668 /* Try invalid HFONT */
669 hres = IFont_ReleaseHfont(ifnt1,NULL);
670 ok(hres == E_INVALIDARG,
671 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
674 /* Try to add a bad HFONT */
675 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
677 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
680 /* Release all refs */
681 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
683 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
686 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
688 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
691 /* Check that both lists are empty */
692 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
694 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
697 /* The list should be empty */
698 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
700 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
703 IFont_Release(ifnt1);
704 IFont_Release(ifnt2);
707 static void test_AddRefHfont(void)
718 /* Basic font description */
719 fd.cbSizeofstruct = sizeof(FONTDESC);
720 fd.lpstrName = system_font;
721 S(fd.cySize).Lo = 100;
722 S(fd.cySize).Hi = 100;
727 fd.fStrikethrough = 0;
729 /* Create HFONTs and IFONTs */
730 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
731 IFont_get_hFont(ifnt1,&hfnt1);
732 fd.lpstrName = arial_font;
733 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
734 IFont_get_hFont(ifnt2,&hfnt2);
736 /* Try invalid HFONT */
737 hres = IFont_AddRefHfont(ifnt1,NULL);
738 ok(hres == E_INVALIDARG,
739 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
742 /* Try to add a bad HFONT */
743 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
745 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
748 /* Add simple IFONT HFONT pair */
749 hres = IFont_AddRefHfont(ifnt1,hfnt1);
751 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
754 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
755 hres = IFont_AddRefHfont(ifnt2,hfnt1);
757 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
760 /* Release all hfnt1 refs */
761 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
763 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
766 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
768 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
771 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
773 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
776 /* Check if hfnt1 is empty */
777 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
779 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
782 /* Release all hfnt2 refs */
783 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
785 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
788 /* Check if hfnt2 is empty */
789 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
791 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
794 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
796 IFont_Release(ifnt1);
798 /* Add a reference for destroyed hfnt1 */
799 hres = IFont_AddRefHfont(ifnt2,hfnt1);
801 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
804 /* Decrement reference for destroyed hfnt1 */
805 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
807 hres == S_FALSE, /* <= win2k */
808 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
811 /* Shows that releasing all IFONT's does clear the HFONT cache. */
813 IFont_Release(ifnt2);
815 /* Need to make a new IFONT for testing */
817 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
818 IFont_get_hFont(ifnt3,&hfnt3);
820 /* Add a reference for destroyed hfnt1 */
821 hres = IFont_AddRefHfont(ifnt3,hfnt1);
823 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
826 /* Decrement reference for destroyed hfnt1 */
827 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
829 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
832 IFont_Release(ifnt3);
835 static void test_returns(void)
841 fontdesc.cbSizeofstruct = sizeof(fontdesc);
842 fontdesc.lpstrName = MSSansSerif_font;
843 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
844 fontdesc.sWeight = FW_NORMAL;
845 fontdesc.sCharset = 0;
846 fontdesc.fItalic = FALSE;
847 fontdesc.fUnderline = FALSE;
848 fontdesc.fStrikethrough = FALSE;
850 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
851 ok_ole_success(hr, "OleCreateFontIndirect");
853 hr = IFont_put_Name(pFont, NULL);
854 ok(hr == CTL_E_INVALIDPROPERTYVALUE,
855 "IFont::put_Name: Expected CTL_E_INVALIDPROPERTYVALUE got 0x%08x\n",
858 hr = IFont_get_Name(pFont, NULL);
860 "IFont::get_Name: Expected E_POINTER got 0x%08x\n",
863 hr = IFont_get_Size(pFont, NULL);
865 "IFont::get_Size: Expected E_POINTER got 0x%08x\n",
868 hr = IFont_get_Bold(pFont, NULL);
870 "IFont::get_Bold: Expected E_POINTER got 0x%08x\n",
873 IFont_Release(pFont);
876 static void test_hfont_lifetime(void)
881 HFONT hfont, first_hfont = NULL;
886 fontdesc.cbSizeofstruct = sizeof(fontdesc);
887 fontdesc.lpstrName = arial_font;
888 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
889 fontdesc.sWeight = FW_NORMAL;
890 fontdesc.sCharset = ANSI_CHARSET;
891 fontdesc.fItalic = FALSE;
892 fontdesc.fUnderline = FALSE;
893 fontdesc.fStrikethrough = FALSE;
895 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
896 ok_ole_success(hr, "OleCreateFontIndirect");
898 hr = IFont_get_hFont(font, &hfont);
899 ok_ole_success(hr, "get_hFont");
901 /* show that if the font is updated the old hfont is deleted when the
902 new font is realized */
903 for(i = 0; i < 100; i++)
905 HFONT last_hfont = hfont;
907 size.int64 = (i + 10) * 20000;
909 obj_type = GetObjectType(hfont);
910 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
912 hr = IFont_put_Size(font, size);
913 ok_ole_success(hr, "put_Size");
915 /* put_Size doesn't cause the new font to be realized */
916 obj_type = GetObjectType(last_hfont);
917 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
919 hr = IFont_get_hFont(font, &hfont);
920 ok_ole_success(hr, "get_hFont");
922 obj_type = GetObjectType(last_hfont);
923 ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
926 /* now show that if we take a reference on the hfont, it persists
927 until the font object is released */
928 for(i = 0; i < 100; i++)
931 size.int64 = (i + 10) * 20000;
933 obj_type = GetObjectType(hfont);
934 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
936 hr = IFont_put_Size(font, size);
937 ok_ole_success(hr, "put_Size");
939 hr = IFont_get_hFont(font, &hfont);
940 ok_ole_success(hr, "get_hFont");
942 hr = IFont_AddRefHfont(font, hfont);
943 ok_ole_success(hr, "AddRefHfont");
945 if(i == 0) first_hfont = hfont;
946 obj_type = GetObjectType(first_hfont);
947 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
952 obj_type = GetObjectType(first_hfont);
953 ok(obj_type == 0, "got obj type %d\n", obj_type);
955 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
956 through re-realization */
958 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
959 ok_ole_success(hr, "OleCreateFontIndirect");
961 hr = IFont_get_hFont(font, &hfont);
962 ok_ole_success(hr, "get_hFont");
964 for(i = 0; i < 100; i++)
966 HFONT last_hfont = hfont;
968 size.int64 = (i + 10) * 20000;
970 obj_type = GetObjectType(hfont);
971 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
973 hr = IFont_put_Size(font, size);
974 ok_ole_success(hr, "put_Size");
976 /* put_Size doesn't cause the new font to be realized */
977 obj_type = GetObjectType(last_hfont);
978 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
980 hr = IFont_get_hFont(font, &hfont);
981 ok_ole_success(hr, "get_hFont");
983 hr = IFont_AddRefHfont(font, hfont);
984 ok_ole_success(hr, "AddRefHfont");
986 hr = IFont_ReleaseHfont(font, hfont);
987 ok_ole_success(hr, "ReleaseHfont");
989 obj_type = GetObjectType(last_hfont);
990 ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
993 /* Interestingly if we release a nonexistent reference on the hfont,
994 * it persists until the font object is released
996 for(i = 0; i < 100; i++)
998 size.int64 = (i + 10) * 20000;
1000 obj_type = GetObjectType(hfont);
1001 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1003 hr = IFont_put_Size(font, size);
1004 ok_ole_success(hr, "put_Size");
1006 hr = IFont_get_hFont(font, &hfont);
1007 ok_ole_success(hr, "get_hFont");
1009 hr = IFont_ReleaseHfont(font, hfont);
1010 ok_ole_success(hr, "ReleaseHfont");
1012 if(i == 0) first_hfont = hfont;
1013 obj_type = GetObjectType(first_hfont);
1014 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1017 IFont_Release(font);
1019 obj_type = GetObjectType(first_hfont);
1020 ok(obj_type == 0, "got obj type %d\n", obj_type);
1022 /* If we take two internal references on a hfont then we can release
1023 it twice. So it looks like there's a total reference count
1024 that includes internal and external references */
1026 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1027 ok_ole_success(hr, "OleCreateFontIndirect");
1028 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
1029 ok_ole_success(hr, "OleCreateFontIndirect");
1031 hr = IFont_get_hFont(font, &hfont);
1032 ok_ole_success(hr, "get_hFont");
1033 hr = IFont_get_hFont(font2, &first_hfont);
1034 ok_ole_success(hr, "get_hFont");
1036 ok(hfont == first_hfont, "fonts differ\n");
1037 hr = IFont_ReleaseHfont(font, hfont);
1038 ok(hr == S_OK, "got %08x\n", hr);
1039 hr = IFont_ReleaseHfont(font, hfont);
1041 ok(hr == S_OK, "got %08x\n", hr);
1042 hr = IFont_ReleaseHfont(font, hfont);
1043 ok(hr == S_FALSE, "got %08x\n", hr);
1045 obj_type = GetObjectType(hfont);
1046 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1048 IFont_Release(font);
1050 obj_type = GetObjectType(hfont);
1051 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1053 IFont_Release(font2);
1055 obj_type = GetObjectType(hfont);
1056 ok(obj_type == 0, "got obj type %d\n", obj_type);
1059 static void test_realization(void)
1067 /* Try to create a symbol only font (marlett) with charset
1068 set to ANSI. This will result in another, ANSI, font
1070 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1071 fontdesc.lpstrName = marlett_font;
1072 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1073 fontdesc.sWeight = FW_NORMAL;
1074 fontdesc.sCharset = ANSI_CHARSET;
1075 fontdesc.fItalic = FALSE;
1076 fontdesc.fUnderline = FALSE;
1077 fontdesc.fStrikethrough = FALSE;
1079 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1080 ok_ole_success(hr, "OleCreateFontIndirect");
1082 hr = IFont_get_Charset(font, &cs);
1083 ok_ole_success(hr, "get_Charset");
1084 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1086 IFont_Release(font);
1088 /* Now create an ANSI font and change the name to marlett */
1090 fontdesc.lpstrName = arial_font;
1092 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1093 ok_ole_success(hr, "OleCreateFontIndirect");
1095 hr = IFont_get_Charset(font, &cs);
1096 ok_ole_success(hr, "get_Charset");
1097 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1099 name = SysAllocString(marlett_font);
1100 hr = IFont_put_Name(font, name);
1101 ok_ole_success(hr, "put_Name");
1102 SysFreeString(name);
1104 hr = IFont_get_Name(font, &name);
1105 ok_ole_success(hr, "get_Name");
1106 ok(!lstrcmpiW(name, marlett_font), "got name %s\n", wine_dbgstr_w(name));
1107 SysFreeString(name);
1109 hr = IFont_get_Charset(font, &cs);
1110 ok_ole_success(hr, "get_Charset");
1111 ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);
1113 IFont_Release(font);
1118 hOleaut32 = GetModuleHandleA("oleaut32.dll");
1119 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
1120 if (!pOleCreateFontIndirect)
1122 win_skip("OleCreateFontIndirect not available\n");
1126 test_QueryInterface();
1129 test_font_events_disp();
1130 test_GetIDsOfNames();
1133 test_ReleaseHfont();
1136 test_hfont_lifetime();