push e7552b73e75828caa36d732caa646c0c70d8de9d
[wine/hacks.git] / dlls / oleaut32 / tests / olefont.c
blob8e26a0ff505026d0e2a9f2442ee81649ddff5b10
1 /*
2 * OLEFONT test program
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <math.h>
26 #include <float.h>
28 #define COBJMACROS
30 #include <wine/test.h>
31 #include <windef.h>
32 #include <winbase.h>
33 #include <winuser.h>
34 #include <wingdi.h>
35 #include <winnls.h>
36 #include <winerror.h>
37 #include <winnt.h>
38 #include <initguid.h>
39 #include <wtypes.h>
40 #include <olectl.h>
41 #include <ocidl.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 };
49 static HMODULE hOleaut32;
51 static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
53 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
55 /* Create a font with cySize given by lo_size, hi_size, */
56 /* SetRatio to ratio_logical, ratio_himetric, */
57 /* check that resulting hfont has height hfont_height. */
58 /* Various checks along the way. */
60 static void test_ifont_sizes(long lo_size, long hi_size,
61 long ratio_logical, long ratio_himetric,
62 long hfont_height, const char * test_name)
64 FONTDESC fd;
65 LPVOID pvObj = NULL;
66 IFont* ifnt = NULL;
67 HFONT hfont;
68 LOGFONT lf;
69 CY psize;
70 HRESULT hres;
72 fd.cbSizeofstruct = sizeof(FONTDESC);
73 fd.lpstrName = system_font;
74 S(fd.cySize).Lo = lo_size;
75 S(fd.cySize).Hi = hi_size;
76 fd.sWeight = 0;
77 fd.sCharset = 0;
78 fd.fItalic = 0;
79 fd.fUnderline = 0;
80 fd.fStrikethrough = 0;
82 /* Create font, test that it worked. */
83 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
84 ifnt = pvObj;
85 ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
86 test_name, hres);
87 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
89 /* Read back size. Hi part was ignored. */
90 hres = IFont_get_Size(ifnt, &psize);
91 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
92 test_name, hres);
93 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
94 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
95 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
97 /* Change ratio, check size unchanged. Standard is 72, 2540. */
98 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
99 ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
100 test_name, hres);
101 hres = IFont_get_Size(ifnt, &psize);
102 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
103 test_name, hres);
104 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
105 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
106 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
108 /* Check hFont size with this ratio. This tests an important */
109 /* conversion for which MSDN is very wrong. */
110 hres = IFont_get_hFont (ifnt, &hfont);
111 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
112 test_name, hres);
113 hres = GetObject (hfont, sizeof(LOGFONT), &lf);
114 ok(lf.lfHeight == hfont_height,
115 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
116 test_name, lf.lfHeight, hfont_height);
118 /* Free IFont. */
119 IFont_Release(ifnt);
122 static void test_QueryInterface(void)
124 LPVOID pvObj = NULL;
125 HRESULT hres;
126 IFont* font = NULL;
127 LONG ret;
129 hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
130 font = pvObj;
132 ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
133 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
135 pvObj = NULL;
136 hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);
138 /* Test if QueryInterface increments ref counter for IFONTs */
139 ret = IFont_AddRef(font);
140 ok(ret == 3 ||
141 broken(ret == 1), /* win95 */
142 "IFont_QI expected ref value 3 but instead got %d\n",ret);
143 IFont_Release(font);
145 ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
146 ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
148 /* Original ref and QueryInterface ref both have to be released */
149 IFont_Release(font);
150 IFont_Release(font);
153 static void test_type_info(void)
155 LPVOID pvObj = NULL;
156 HRESULT hres;
157 IFontDisp* fontdisp = NULL;
158 ITypeInfo* pTInfo;
159 WCHAR name_Name[] = {'N','a','m','e',0};
160 BSTR names[3];
161 UINT n;
162 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
163 SORT_DEFAULT);
164 DISPPARAMS dispparams;
165 VARIANT varresult;
167 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
168 fontdisp = pvObj;
170 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
171 ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
172 ok(pTInfo != NULL, "GTI returned NULL.\n");
174 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
175 ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
176 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
177 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
178 SysFreeString(names[0]);
180 ITypeInfo_Release(pTInfo);
182 dispparams.cNamedArgs = 0;
183 dispparams.rgdispidNamedArgs = NULL;
184 dispparams.cArgs = 0;
185 dispparams.rgvarg = NULL;
186 VariantInit(&varresult);
187 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
188 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
189 NULL, NULL);
190 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
191 VariantClear(&varresult);
193 IFontDisp_Release(fontdisp);
196 static HRESULT WINAPI FontEventsDisp_QueryInterface(
197 IFontEventsDisp *iface,
198 /* [in] */ REFIID riid,
199 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
201 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
203 IUnknown_AddRef(iface);
204 *ppvObject = iface;
205 return S_OK;
207 else
209 *ppvObject = NULL;
210 return E_NOINTERFACE;
214 static ULONG WINAPI FontEventsDisp_AddRef(
215 IFontEventsDisp *iface)
217 return 2;
220 static ULONG WINAPI FontEventsDisp_Release(
221 IFontEventsDisp *iface)
223 return 1;
226 static int fonteventsdisp_invoke_called = 0;
228 static HRESULT WINAPI FontEventsDisp_Invoke(
229 IFontEventsDisp __RPC_FAR * iface,
230 /* [in] */ DISPID dispIdMember,
231 /* [in] */ REFIID riid,
232 /* [in] */ LCID lcid,
233 /* [in] */ WORD wFlags,
234 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
235 /* [out] */ VARIANT __RPC_FAR *pVarResult,
236 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
237 /* [out] */ UINT __RPC_FAR *puArgErr)
239 static const WCHAR wszBold[] = {'B','o','l','d',0};
240 ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
241 ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
242 ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
243 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]));
244 ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
246 fonteventsdisp_invoke_called++;
247 return S_OK;
250 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
252 FontEventsDisp_QueryInterface,
253 FontEventsDisp_AddRef,
254 FontEventsDisp_Release,
255 NULL,
256 NULL,
257 NULL,
258 FontEventsDisp_Invoke
261 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
263 static void test_font_events_disp(void)
265 IFont *pFont;
266 IFont *pFont2;
267 IConnectionPointContainer *pCPC;
268 IConnectionPoint *pCP;
269 FONTDESC fontdesc;
270 HRESULT hr;
271 DWORD dwCookie;
272 IFontDisp *pFontDisp;
273 DISPPARAMS dispparams;
274 VARIANTARG vararg;
276 fontdesc.cbSizeofstruct = sizeof(fontdesc);
277 fontdesc.lpstrName = MSSansSerif_font;
278 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
279 fontdesc.sWeight = FW_NORMAL;
280 fontdesc.sCharset = 0;
281 fontdesc.fItalic = FALSE;
282 fontdesc.fUnderline = FALSE;
283 fontdesc.fStrikethrough = FALSE;
285 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
286 ok_ole_success(hr, "OleCreateFontIndirect");
288 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
289 ok_ole_success(hr, "IFont_QueryInterface");
291 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
292 ok_ole_success(hr, "IConnectionPointContainer_FindConnectionPoint");
293 IConnectionPointContainer_Release(pCPC);
295 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
296 ok_ole_success(hr, "IConnectionPoint_Advise");
297 IConnectionPoint_Release(pCP);
299 hr = IFont_put_Bold(pFont, TRUE);
300 ok_ole_success(hr, "IFont_put_Bold");
302 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
304 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
305 ok_ole_success(hr, "IFont_QueryInterface");
307 V_VT(&vararg) = VT_BOOL;
308 V_BOOL(&vararg) = VARIANT_FALSE;
309 dispparams.cNamedArgs = 0;
310 dispparams.rgdispidNamedArgs = NULL;
311 dispparams.cArgs = 1;
312 dispparams.rgvarg = &vararg;
313 hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
315 IFontDisp_Release(pFontDisp);
317 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
318 fonteventsdisp_invoke_called);
320 hr = IFont_Clone(pFont, &pFont2);
321 ok_ole_success(hr, "IFont_Clone");
322 IFont_Release(pFont);
324 hr = IFont_put_Bold(pFont2, FALSE);
325 ok_ole_success(hr, "IFont_put_Bold");
327 /* this test shows that the notification routine isn't called again */
328 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
329 fonteventsdisp_invoke_called);
331 IFont_Release(pFont2);
334 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
335 WCHAR* w_name_2, const char* a_name_2,
336 LCID lcid, DISPID id_1, DISPID id_2,
337 HRESULT hres_expect, int numnames)
339 LPVOID pvObj = NULL;
340 IFontDisp *fontdisp = NULL;
341 HRESULT hres;
342 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
343 LPOLESTR names[2] = {w_name_1, w_name_2};
345 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
346 fontdisp = pvObj;
348 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
349 lcid, rgDispId);
351 /* test hres */
352 ok(hres == hres_expect,
353 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
354 a_name_1, a_name_2, hres, hres_expect);
356 /* test first DISPID */
357 ok(rgDispId[0]==id_1,
358 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
359 a_name_1, rgDispId[0], id_1);
361 /* test second DISPID is present */
362 if (numnames == 2)
364 ok(rgDispId[1]==id_2,
365 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
366 a_name_2, rgDispId[1], id_2);
369 IFontDisp_Release(fontdisp);
372 static void test_GetIDsOfNames(void)
374 WCHAR name_Name[] = {'N','a','m','e',0};
375 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
376 WCHAR name_Size[] = {'S','i','z','e',0};
377 WCHAR name_Bold[] = {'B','o','l','d',0};
378 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
379 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
380 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
381 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
382 WCHAR name_Foo[] = {'F','o','o',0};
383 WCHAR name_nAmE[] = {'n','A','m','E',0};
384 WCHAR name_Nom[] = {'N','o','m',0};
386 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
387 SORT_DEFAULT);
388 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
389 SORT_DEFAULT);
391 /* Test DISPID_FONTs for the various properties. */
392 test_names_ids(name_Name, "Name", NULL, "", en_us,
393 DISPID_FONT_NAME, 0, S_OK,1);
394 test_names_ids(name_Size, "Size", NULL, "", en_us,
395 DISPID_FONT_SIZE, 0, S_OK,1);
396 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
397 DISPID_FONT_BOLD, 0, S_OK,1);
398 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
399 DISPID_FONT_ITALIC, 0, S_OK,1);
400 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
401 DISPID_FONT_UNDER, 0, S_OK,1);
402 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
403 DISPID_FONT_STRIKE, 0, S_OK,1);
404 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
405 DISPID_FONT_WEIGHT, 0, S_OK,1);
406 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
407 DISPID_FONT_CHARSET, 0, S_OK,1);
409 /* Capitalization doesn't matter. */
410 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
411 DISPID_FONT_NAME, 0, S_OK,1);
413 /* Unknown name. */
414 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
415 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
417 /* Pass several names: first is processed, */
418 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
419 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
420 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
421 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
422 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
424 /* Locale ID has no effect. */
425 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
426 DISPID_FONT_NAME, 0, S_OK,1);
427 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
428 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
430 /* One of the arguments are invalid */
431 test_names_ids(name_Name, "Name", NULL, "", en_us,
432 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
433 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
434 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
435 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
436 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
438 /* Crazy locale ID? */
439 test_names_ids(name_Name, "Name", NULL, "", -1,
440 DISPID_FONT_NAME, 0, S_OK,1);
443 static void test_Invoke(void)
445 IFontDisp *fontdisp;
446 HRESULT hr;
447 VARIANTARG vararg;
448 DISPPARAMS dispparams;
449 VARIANT varresult;
451 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
452 ok_ole_success(hr, "OleCreateFontIndirect");
454 V_VT(&vararg) = VT_BOOL;
455 V_BOOL(&vararg) = VARIANT_FALSE;
456 dispparams.cNamedArgs = 0;
457 dispparams.rgdispidNamedArgs = NULL;
458 dispparams.cArgs = 1;
459 dispparams.rgvarg = &vararg;
460 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
461 ok(hr == DISP_E_UNKNOWNINTERFACE, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr);
463 dispparams.cArgs = 0;
464 dispparams.rgvarg = NULL;
465 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
466 ok(hr == DISP_E_BADPARAMCOUNT, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
468 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
469 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
471 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
472 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
474 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
475 ok_ole_success(hr, "IFontDisp_Invoke");
477 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
478 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
480 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
481 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
483 dispparams.cArgs = 1;
484 dispparams.rgvarg = &vararg;
485 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
486 ok_ole_success(hr, "IFontDisp_Invoke");
488 IFontDisp_Release(fontdisp);
491 static void test_IsEqual(void)
493 FONTDESC fd;
494 LPVOID pvObj = NULL;
495 LPVOID pvObj2 = NULL;
496 IFont* ifnt = NULL;
497 IFont* ifnt2 = NULL;
498 HRESULT hres;
500 /* Basic font description */
501 fd.cbSizeofstruct = sizeof(FONTDESC);
502 fd.lpstrName = system_font;
503 S(fd.cySize).Lo = 100;
504 S(fd.cySize).Hi = 100;
505 fd.sWeight = 0;
506 fd.sCharset = 0;
507 fd.fItalic = 0;
508 fd.fUnderline = 0;
509 fd.fStrikethrough = 0;
511 /* Create font */
512 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
513 ifnt = pvObj;
515 /* Test equal fonts */
516 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
517 ifnt2 = pvObj2;
518 hres = IFont_IsEqual(ifnt,ifnt2);
519 ok(hres == S_OK,
520 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
521 IFont_Release(ifnt2);
523 /* Check for bad pointer */
524 hres = IFont_IsEqual(ifnt,NULL);
525 ok(hres == E_POINTER,
526 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
528 /* Test strName */
529 fd.lpstrName = arial_font;
530 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
531 hres = IFont_IsEqual(ifnt,ifnt2);
532 ok(hres == S_FALSE,
533 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
534 fd.lpstrName = system_font;
535 IFont_Release(ifnt2);
537 /* Test lo font size */
538 S(fd.cySize).Lo = 10000;
539 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
540 ifnt2 = pvObj2;
541 hres = IFont_IsEqual(ifnt,ifnt2);
542 ok(hres == S_FALSE,
543 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
544 S(fd.cySize).Lo = 100;
545 IFont_Release(ifnt2);
547 /* Test hi font size */
548 S(fd.cySize).Hi = 10000;
549 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
550 ifnt2 = pvObj2;
551 hres = IFont_IsEqual(ifnt,ifnt2);
552 ok(hres == S_FALSE,
553 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
554 S(fd.cySize).Hi = 100;
555 IFont_Release(ifnt2);
557 /* Test font weight */
558 fd.sWeight = 100;
559 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
560 ifnt2 = pvObj2;
561 hres = IFont_IsEqual(ifnt,ifnt2);
562 ok(hres == S_FALSE,
563 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
564 fd.sWeight = 0;
565 IFont_Release(ifnt2);
567 /* Test charset */
568 fd.sCharset = 1;
569 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
570 hres = IFont_IsEqual(ifnt,ifnt2);
571 ok(hres == S_FALSE,
572 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
573 fd.sCharset = 0;
574 IFont_Release(ifnt2);
576 /* Test italic setting */
577 fd.fItalic = 1;
578 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
579 hres = IFont_IsEqual(ifnt,ifnt2);
580 ok(hres == S_FALSE,
581 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
582 fd.fItalic = 0;
583 IFont_Release(ifnt2);
585 /* Test underline setting */
586 fd.fUnderline = 1;
587 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
588 hres = IFont_IsEqual(ifnt,ifnt2);
589 ok(hres == S_FALSE,
590 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
591 fd.fUnderline = 0;
592 IFont_Release(ifnt2);
594 /* Test strikethrough setting */
595 fd.fStrikethrough = 1;
596 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
597 hres = IFont_IsEqual(ifnt,ifnt2);
598 ok(hres == S_FALSE,
599 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
600 fd.fStrikethrough = 0;
601 IFont_Release(ifnt2);
603 /* Free IFont. */
604 IFont_Release(ifnt);
607 static void test_ReleaseHfont(void)
609 FONTDESC fd;
610 LPVOID pvObj1 = NULL;
611 LPVOID pvObj2 = NULL;
612 IFont* ifnt1 = NULL;
613 IFont* ifnt2 = NULL;
614 HFONT hfnt1 = 0;
615 HFONT hfnt2 = 0;
616 HRESULT hres;
618 /* Basic font description */
619 fd.cbSizeofstruct = sizeof(FONTDESC);
620 fd.lpstrName = system_font;
621 S(fd.cySize).Lo = 100;
622 S(fd.cySize).Hi = 100;
623 fd.sWeight = 0;
624 fd.sCharset = 0;
625 fd.fItalic = 0;
626 fd.fUnderline = 0;
627 fd.fStrikethrough = 0;
629 /* Create HFONTs and IFONTs */
630 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
631 ifnt1 = pvObj1;
632 IFont_get_hFont(ifnt1,&hfnt1);
633 fd.lpstrName = arial_font;
634 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
635 ifnt2 = pvObj2;
636 IFont_get_hFont(ifnt2,&hfnt2);
638 /* Try invalid HFONT */
639 hres = IFont_ReleaseHfont(ifnt1,NULL);
640 ok(hres == E_INVALIDARG,
641 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
642 hres);
644 /* Try to add a bad HFONT */
645 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
646 ok(hres == S_FALSE,
647 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
648 hres);
650 /* Release all refs */
651 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
652 ok(hres == S_OK,
653 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
654 hres);
656 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
657 ok(hres == S_OK,
658 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
659 hres);
661 /* Check that both lists are empty */
662 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
663 ok(hres == S_FALSE,
664 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
665 hres);
667 /* The list should be empty */
668 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
669 ok(hres == S_FALSE,
670 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
671 hres);
673 IFont_Release(ifnt1);
674 IFont_Release(ifnt2);
677 static void test_AddRefHfont(void)
679 FONTDESC fd;
680 IFont* ifnt1 = NULL;
681 IFont* ifnt2 = NULL;
682 IFont* ifnt3 = NULL;
683 HFONT hfnt1 = 0;
684 HFONT hfnt2 = 0;
685 HFONT hfnt3 = 0;
686 HRESULT hres;
688 /* Basic font description */
689 fd.cbSizeofstruct = sizeof(FONTDESC);
690 fd.lpstrName = system_font;
691 S(fd.cySize).Lo = 100;
692 S(fd.cySize).Hi = 100;
693 fd.sWeight = 0;
694 fd.sCharset = 0;
695 fd.fItalic = 0;
696 fd.fUnderline = 0;
697 fd.fStrikethrough = 0;
699 /* Create HFONTs and IFONTs */
700 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
701 IFont_get_hFont(ifnt1,&hfnt1);
702 fd.lpstrName = arial_font;
703 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
704 IFont_get_hFont(ifnt2,&hfnt2);
706 /* Try invalid HFONT */
707 hres = IFont_AddRefHfont(ifnt1,NULL);
708 ok(hres == E_INVALIDARG,
709 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
710 hres);
712 /* Try to add a bad HFONT */
713 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
714 ok(hres == S_FALSE,
715 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
716 hres);
718 /* Add simple IFONT HFONT pair */
719 hres = IFont_AddRefHfont(ifnt1,hfnt1);
720 ok(hres == S_OK,
721 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
722 hres);
724 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
725 hres = IFont_AddRefHfont(ifnt2,hfnt1);
726 ok(hres == S_OK,
727 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
728 hres);
730 /* Release all hfnt1 refs */
731 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
732 ok(hres == S_OK,
733 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
734 hres);
736 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
737 ok(hres == S_OK,
738 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
739 hres);
741 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
742 ok(hres == S_OK,
743 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
744 hres);
746 /* Check if hfnt1 is empty */
747 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
748 ok(hres == S_FALSE,
749 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
750 hres);
752 /* Release all hfnt2 refs */
753 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
754 ok(hres == S_OK,
755 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
756 hres);
758 /* Check if hfnt2 is empty */
759 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
760 ok(hres == S_FALSE,
761 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
762 hres);
764 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
766 IFont_Release(ifnt1);
768 /* Add a reference for destroyed hfnt1 */
769 hres = IFont_AddRefHfont(ifnt2,hfnt1);
770 ok(hres == S_OK,
771 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
772 hres);
774 /* Decrement reference for destroyed hfnt1 */
775 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
776 ok(hres == S_OK ||
777 hres == S_FALSE, /* <= win2k */
778 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
779 hres);
781 /* Shows that releasing all IFONT's does clear the HFONT cache. */
783 IFont_Release(ifnt2);
785 /* Need to make a new IFONT for testing */
786 fd.fUnderline = 1;
787 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
788 IFont_get_hFont(ifnt3,&hfnt3);
790 /* Add a reference for destroyed hfnt1 */
791 hres = IFont_AddRefHfont(ifnt3,hfnt1);
792 ok(hres == S_FALSE,
793 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
794 hres);
796 /* Decrement reference for destroyed hfnt1 */
797 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
798 ok(hres == S_FALSE,
799 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
800 hres);
802 IFont_Release(ifnt3);
805 START_TEST(olefont)
807 hOleaut32 = GetModuleHandleA("oleaut32.dll");
808 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
809 if (!pOleCreateFontIndirect)
811 win_skip("OleCreateFontIndirect not available\n");
812 return;
815 test_QueryInterface();
816 test_type_info();
818 /* Test various size operations and conversions. */
819 /* Add more as needed. */
820 if (0) /* FIXME: failing tests */
822 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
823 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
824 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
826 /* These depend on details of how IFont rounds sizes internally. */
827 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
828 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
831 test_font_events_disp();
832 test_GetIDsOfNames();
833 test_Invoke();
834 test_IsEqual();
835 test_ReleaseHfont();
836 test_AddRefHfont();