push 319afc849e77c7d120112c7718dd0b4fc9a636fe
[wine/hacks.git] / dlls / oleaut32 / tests / olefont.c
blob0e5f55f3cf2cbc7ff69e004efb85a046a0085d18
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>
27 #include <time.h>
29 #define COBJMACROS
31 #include <wine/test.h>
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winuser.h>
35 #include <wingdi.h>
36 #include <winnls.h>
37 #include <winerror.h>
38 #include <winnt.h>
39 #include <initguid.h>
40 #include <wtypes.h>
41 #include <olectl.h>
42 #include <ocidl.h>
44 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
46 static WCHAR MSSansSerif_font[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
47 static WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
48 static WCHAR arial_font[] = { 'A','r','i','a','l',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. */
61 static void test_ifont_sizes(long lo_size, long hi_size,
62 long ratio_logical, long ratio_himetric,
63 long hfont_height, const char * test_name)
65 FONTDESC fd;
66 LPVOID pvObj = NULL;
67 IFont* ifnt = NULL;
68 HFONT hfont;
69 LOGFONT lf;
70 CY psize;
71 HRESULT hres;
73 fd.cbSizeofstruct = sizeof(FONTDESC);
74 fd.lpstrName = system_font;
75 S(fd.cySize).Lo = lo_size;
76 S(fd.cySize).Hi = hi_size;
77 fd.sWeight = 0;
78 fd.sCharset = 0;
79 fd.fItalic = 0;
80 fd.fUnderline = 0;
81 fd.fStrikethrough = 0;
83 /* Create font, test that it worked. */
84 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
85 ifnt = pvObj;
86 ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
87 test_name, hres);
88 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
90 /* Read back size. Hi part was ignored. */
91 hres = IFont_get_Size(ifnt, &psize);
92 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
93 test_name, hres);
94 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
95 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
96 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
98 /* Change ratio, check size unchanged. Standard is 72, 2540. */
99 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
100 ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
101 test_name, hres);
102 hres = IFont_get_Size(ifnt, &psize);
103 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
104 test_name, hres);
105 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
106 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
107 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
109 /* Check hFont size with this ratio. This tests an important */
110 /* conversion for which MSDN is very wrong. */
111 hres = IFont_get_hFont (ifnt, &hfont);
112 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
113 test_name, hres);
114 hres = GetObject (hfont, sizeof(LOGFONT), &lf);
115 ok(lf.lfHeight == hfont_height,
116 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
117 test_name, lf.lfHeight, hfont_height);
119 /* Free IFont. */
120 IFont_Release(ifnt);
123 static void test_QueryInterface(void)
125 LPVOID pvObj = NULL;
126 HRESULT hres;
127 IFont* font = NULL;
128 LONG ret;
130 hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
131 font = pvObj;
133 ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
134 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
136 pvObj = NULL;
137 hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);
139 /* Test if QueryInterface increments ref counter for IFONTs */
140 ret = IFont_AddRef(font);
141 ok(ret == 3, "IFont_QI expected ref value 3 but instead got %12u\n",ret);
142 IFont_Release(font);
144 ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
145 ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
147 /* Original ref and QueryInterface ref both have to be released */
148 IFont_Release(font);
149 IFont_Release(font);
152 static void test_type_info(void)
154 LPVOID pvObj = NULL;
155 HRESULT hres;
156 IFontDisp* fontdisp = NULL;
157 ITypeInfo* pTInfo;
158 WCHAR name_Name[] = {'N','a','m','e',0};
159 BSTR names[3];
160 UINT n;
161 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
162 SORT_DEFAULT);
163 DISPPARAMS dispparams;
164 VARIANT varresult;
166 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
167 fontdisp = pvObj;
169 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
170 ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
171 ok(pTInfo != NULL, "GTI returned NULL.\n");
173 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
174 ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
175 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
176 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
177 SysFreeString(names[0]);
179 ITypeInfo_Release(pTInfo);
181 dispparams.cNamedArgs = 0;
182 dispparams.rgdispidNamedArgs = NULL;
183 dispparams.cArgs = 0;
184 dispparams.rgvarg = NULL;
185 VariantInit(&varresult);
186 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
187 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
188 NULL, NULL);
189 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
190 VariantClear(&varresult);
192 IFontDisp_Release(fontdisp);
195 static HRESULT WINAPI FontEventsDisp_QueryInterface(
196 IFontEventsDisp *iface,
197 /* [in] */ REFIID riid,
198 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
200 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
202 IUnknown_AddRef(iface);
203 *ppvObject = iface;
204 return S_OK;
206 else
208 *ppvObject = NULL;
209 return E_NOINTERFACE;
213 static ULONG WINAPI FontEventsDisp_AddRef(
214 IFontEventsDisp *iface)
216 return 2;
219 static ULONG WINAPI FontEventsDisp_Release(
220 IFontEventsDisp *iface)
222 return 1;
225 static int fonteventsdisp_invoke_called = 0;
227 static HRESULT WINAPI FontEventsDisp_Invoke(
228 IFontEventsDisp __RPC_FAR * iface,
229 /* [in] */ DISPID dispIdMember,
230 /* [in] */ REFIID riid,
231 /* [in] */ LCID lcid,
232 /* [in] */ WORD wFlags,
233 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
234 /* [out] */ VARIANT __RPC_FAR *pVarResult,
235 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
236 /* [out] */ UINT __RPC_FAR *puArgErr)
238 static const WCHAR wszBold[] = {'B','o','l','d',0};
239 ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
240 ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
241 ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
242 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]));
243 ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
245 fonteventsdisp_invoke_called++;
246 return S_OK;
249 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
251 FontEventsDisp_QueryInterface,
252 FontEventsDisp_AddRef,
253 FontEventsDisp_Release,
254 NULL,
255 NULL,
256 NULL,
257 FontEventsDisp_Invoke
260 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
262 static void test_font_events_disp(void)
264 IFont *pFont;
265 IFont *pFont2;
266 IConnectionPointContainer *pCPC;
267 IConnectionPoint *pCP;
268 FONTDESC fontdesc;
269 HRESULT hr;
270 DWORD dwCookie;
271 IFontDisp *pFontDisp;
272 DISPPARAMS dispparams;
273 VARIANTARG vararg;
275 fontdesc.cbSizeofstruct = sizeof(fontdesc);
276 fontdesc.lpstrName = MSSansSerif_font;
277 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
278 fontdesc.sWeight = FW_NORMAL;
279 fontdesc.sCharset = 0;
280 fontdesc.fItalic = FALSE;
281 fontdesc.fUnderline = FALSE;
282 fontdesc.fStrikethrough = FALSE;
284 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
285 ok_ole_success(hr, "OleCreateFontIndirect");
287 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
288 ok_ole_success(hr, "IFont_QueryInterface");
290 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
291 ok_ole_success(hr, "IConnectionPointContainer_FindConnectionPoint");
292 IConnectionPointContainer_Release(pCPC);
294 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
295 ok_ole_success(hr, "IConnectionPoint_Advise");
296 IConnectionPoint_Release(pCP);
298 hr = IFont_put_Bold(pFont, TRUE);
299 ok_ole_success(hr, "IFont_put_Bold");
301 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
303 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
304 ok_ole_success(hr, "IFont_QueryInterface");
306 V_VT(&vararg) = VT_BOOL;
307 V_BOOL(&vararg) = VARIANT_FALSE;
308 dispparams.cNamedArgs = 0;
309 dispparams.rgdispidNamedArgs = NULL;
310 dispparams.cArgs = 1;
311 dispparams.rgvarg = &vararg;
312 hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
314 IFontDisp_Release(pFontDisp);
316 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
317 fonteventsdisp_invoke_called);
319 hr = IFont_Clone(pFont, &pFont2);
320 ok_ole_success(hr, "IFont_Clone");
321 IFont_Release(pFont);
323 hr = IFont_put_Bold(pFont2, FALSE);
324 ok_ole_success(hr, "IFont_put_Bold");
326 /* this test shows that the notification routine isn't called again */
327 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
328 fonteventsdisp_invoke_called);
330 IFont_Release(pFont2);
333 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
334 WCHAR* w_name_2, const char* a_name_2,
335 LCID lcid, DISPID id_1, DISPID id_2,
336 HRESULT hres_expect, int numnames)
338 LPVOID pvObj = NULL;
339 IFontDisp *fontdisp = NULL;
340 HRESULT hres;
341 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
342 LPOLESTR names[2] = {w_name_1, w_name_2};
344 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
345 fontdisp = pvObj;
347 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
348 lcid, rgDispId);
350 /* test hres */
351 ok(hres == hres_expect,
352 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
353 a_name_1, a_name_2, hres, hres_expect);
355 /* test first DISPID */
356 ok(rgDispId[0]==id_1,
357 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
358 a_name_1, rgDispId[0], id_1);
360 /* test second DISPID is present */
361 if (numnames == 2)
363 ok(rgDispId[1]==id_2,
364 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
365 a_name_2, rgDispId[1], id_2);
368 IFontDisp_Release(fontdisp);
371 static void test_GetIDsOfNames(void)
373 WCHAR name_Name[] = {'N','a','m','e',0};
374 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
375 WCHAR name_Size[] = {'S','i','z','e',0};
376 WCHAR name_Bold[] = {'B','o','l','d',0};
377 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
378 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
379 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
380 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
381 WCHAR name_Foo[] = {'F','o','o',0};
382 WCHAR name_nAmE[] = {'n','A','m','E',0};
383 WCHAR name_Nom[] = {'N','o','m',0};
385 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
386 SORT_DEFAULT);
387 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
388 SORT_DEFAULT);
390 /* Test DISPID_FONTs for the various properties. */
391 test_names_ids(name_Name, "Name", NULL, "", en_us,
392 DISPID_FONT_NAME, 0, S_OK,1);
393 test_names_ids(name_Size, "Size", NULL, "", en_us,
394 DISPID_FONT_SIZE, 0, S_OK,1);
395 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
396 DISPID_FONT_BOLD, 0, S_OK,1);
397 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
398 DISPID_FONT_ITALIC, 0, S_OK,1);
399 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
400 DISPID_FONT_UNDER, 0, S_OK,1);
401 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
402 DISPID_FONT_STRIKE, 0, S_OK,1);
403 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
404 DISPID_FONT_WEIGHT, 0, S_OK,1);
405 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
406 DISPID_FONT_CHARSET, 0, S_OK,1);
408 /* Capitalization doesn't matter. */
409 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
410 DISPID_FONT_NAME, 0, S_OK,1);
412 /* Unknown name. */
413 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
414 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
416 /* Pass several names: first is processed, */
417 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
418 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
419 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
420 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
421 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
423 /* Locale ID has no effect. */
424 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
425 DISPID_FONT_NAME, 0, S_OK,1);
426 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
427 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
429 /* One of the arguments are invalid */
430 test_names_ids(name_Name, "Name", NULL, "", en_us,
431 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
432 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
433 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
434 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
435 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
437 /* Crazy locale ID? */
438 test_names_ids(name_Name, "Name", NULL, "", -1,
439 DISPID_FONT_NAME, 0, S_OK,1);
442 static void test_Invoke(void)
444 IFontDisp *fontdisp;
445 HRESULT hr;
446 VARIANTARG vararg;
447 DISPPARAMS dispparams;
448 VARIANT varresult;
450 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
451 ok_ole_success(hr, "OleCreateFontIndirect");
453 V_VT(&vararg) = VT_BOOL;
454 V_BOOL(&vararg) = VARIANT_FALSE;
455 dispparams.cNamedArgs = 0;
456 dispparams.rgdispidNamedArgs = NULL;
457 dispparams.cArgs = 1;
458 dispparams.rgvarg = &vararg;
459 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
460 ok(hr == DISP_E_UNKNOWNINTERFACE, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr);
462 dispparams.cArgs = 0;
463 dispparams.rgvarg = NULL;
464 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
465 ok(hr == DISP_E_BADPARAMCOUNT, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
467 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
468 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
470 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
471 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
473 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
474 ok_ole_success(hr, "IFontDisp_Invoke");
476 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
477 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
479 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
480 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
482 dispparams.cArgs = 1;
483 dispparams.rgvarg = &vararg;
484 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
485 ok_ole_success(hr, "IFontDisp_Invoke");
487 IFontDisp_Release(fontdisp);
490 static void test_IsEqual(void)
492 FONTDESC fd;
493 LPVOID pvObj = NULL;
494 LPVOID pvObj2 = NULL;
495 IFont* ifnt = NULL;
496 IFont* ifnt2 = NULL;
497 HRESULT hres;
499 /* Basic font description */
500 fd.cbSizeofstruct = sizeof(FONTDESC);
501 fd.lpstrName = system_font;
502 S(fd.cySize).Lo = 100;
503 S(fd.cySize).Hi = 100;
504 fd.sWeight = 0;
505 fd.sCharset = 0;
506 fd.fItalic = 0;
507 fd.fUnderline = 0;
508 fd.fStrikethrough = 0;
510 /* Create font */
511 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
512 ifnt = pvObj;
514 /* Test equal fonts */
515 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
516 ifnt2 = pvObj2;
517 hres = IFont_IsEqual(ifnt,ifnt2);
518 ok(hres == S_OK,
519 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
520 IFont_Release(ifnt2);
522 /* Check for bad pointer */
523 hres = IFont_IsEqual(ifnt,NULL);
524 ok(hres == E_POINTER,
525 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
527 /* Test strName */
528 fd.lpstrName = arial_font;
529 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
530 hres = IFont_IsEqual(ifnt,ifnt2);
531 ok(hres == S_FALSE,
532 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
533 fd.lpstrName = system_font;
534 IFont_Release(ifnt2);
536 /* Test lo font size */
537 S(fd.cySize).Lo = 10000;
538 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
539 ifnt2 = pvObj2;
540 hres = IFont_IsEqual(ifnt,ifnt2);
541 ok(hres == S_FALSE,
542 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
543 S(fd.cySize).Lo = 100;
544 IFont_Release(ifnt2);
546 /* Test hi font size */
547 S(fd.cySize).Hi = 10000;
548 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
549 ifnt2 = pvObj2;
550 hres = IFont_IsEqual(ifnt,ifnt2);
551 ok(hres == S_FALSE,
552 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
553 S(fd.cySize).Hi = 100;
554 IFont_Release(ifnt2);
556 /* Test font weight */
557 fd.sWeight = 100;
558 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
559 ifnt2 = pvObj2;
560 hres = IFont_IsEqual(ifnt,ifnt2);
561 ok(hres == S_FALSE,
562 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
563 fd.sWeight = 0;
564 IFont_Release(ifnt2);
566 /* Test charset */
567 fd.sCharset = 1;
568 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
569 hres = IFont_IsEqual(ifnt,ifnt2);
570 ok(hres == S_FALSE,
571 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
572 fd.sCharset = 0;
573 IFont_Release(ifnt2);
575 /* Test italic setting */
576 fd.fItalic = 1;
577 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
578 hres = IFont_IsEqual(ifnt,ifnt2);
579 ok(hres == S_FALSE,
580 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
581 fd.fItalic = 0;
582 IFont_Release(ifnt2);
584 /* Test underline setting */
585 fd.fUnderline = 1;
586 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
587 hres = IFont_IsEqual(ifnt,ifnt2);
588 ok(hres == S_FALSE,
589 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
590 fd.fUnderline = 0;
591 IFont_Release(ifnt2);
593 /* Test strikethrough setting */
594 fd.fStrikethrough = 1;
595 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
596 hres = IFont_IsEqual(ifnt,ifnt2);
597 ok(hres == S_FALSE,
598 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
599 fd.fStrikethrough = 0;
600 IFont_Release(ifnt2);
602 /* Free IFont. */
603 IFont_Release(ifnt);
606 static void test_ReleaseHfont(void)
608 FONTDESC fd;
609 LPVOID pvObj1 = NULL;
610 LPVOID pvObj2 = NULL;
611 IFont* ifnt1 = NULL;
612 IFont* ifnt2 = NULL;
613 HFONT hfnt1 = 0;
614 HFONT hfnt2 = 0;
615 HRESULT hres;
617 /* Basic font description */
618 fd.cbSizeofstruct = sizeof(FONTDESC);
619 fd.lpstrName = system_font;
620 S(fd.cySize).Lo = 100;
621 S(fd.cySize).Hi = 100;
622 fd.sWeight = 0;
623 fd.sCharset = 0;
624 fd.fItalic = 0;
625 fd.fUnderline = 0;
626 fd.fStrikethrough = 0;
628 /* Create HFONTs and IFONTs */
629 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
630 ifnt1 = pvObj1;
631 IFont_get_hFont(ifnt1,&hfnt1);
632 fd.lpstrName = arial_font;
633 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
634 ifnt2 = pvObj2;
635 IFont_get_hFont(ifnt2,&hfnt2);
637 /* Try invalid HFONT */
638 hres = IFont_ReleaseHfont(ifnt1,NULL);
639 ok(hres == E_INVALIDARG,
640 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
641 hres);
643 /* Try to add a bad HFONT */
644 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
645 ok(hres == S_FALSE,
646 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
647 hres);
649 /* Release all refs */
650 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
651 ok(hres == S_OK,
652 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
653 hres);
655 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
656 ok(hres == S_OK,
657 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
658 hres);
660 /* Check that both lists are empty */
661 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
662 ok(hres == S_FALSE,
663 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
664 hres);
666 /* The list should be empty */
667 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
668 ok(hres == S_FALSE,
669 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
670 hres);
672 IFont_Release(ifnt1);
673 IFont_Release(ifnt2);
676 static void test_AddRefHfont(void)
678 FONTDESC fd;
679 IFont* ifnt1 = NULL;
680 IFont* ifnt2 = NULL;
681 IFont* ifnt3 = NULL;
682 HFONT hfnt1 = 0;
683 HFONT hfnt2 = 0;
684 HFONT hfnt3 = 0;
685 HRESULT hres;
687 /* Basic font description */
688 fd.cbSizeofstruct = sizeof(FONTDESC);
689 fd.lpstrName = system_font;
690 S(fd.cySize).Lo = 100;
691 S(fd.cySize).Hi = 100;
692 fd.sWeight = 0;
693 fd.sCharset = 0;
694 fd.fItalic = 0;
695 fd.fUnderline = 0;
696 fd.fStrikethrough = 0;
698 /* Create HFONTs and IFONTs */
699 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
700 IFont_get_hFont(ifnt1,&hfnt1);
701 fd.lpstrName = arial_font;
702 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
703 IFont_get_hFont(ifnt2,&hfnt2);
705 /* Try invalid HFONT */
706 hres = IFont_AddRefHfont(ifnt1,NULL);
707 ok(hres == E_INVALIDARG,
708 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
709 hres);
711 /* Try to add a bad HFONT */
712 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
713 ok(hres == S_FALSE,
714 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
715 hres);
717 /* Add simple IFONT HFONT pair */
718 hres = IFont_AddRefHfont(ifnt1,hfnt1);
719 ok(hres == S_OK,
720 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
721 hres);
723 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
724 hres = IFont_AddRefHfont(ifnt2,hfnt1);
725 ok(hres == S_OK,
726 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
727 hres);
729 /* Release all hfnt1 refs */
730 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
731 ok(hres == S_OK,
732 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
733 hres);
735 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
736 ok(hres == S_OK,
737 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
738 hres);
740 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
741 ok(hres == S_OK,
742 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
743 hres);
745 /* Check if hfnt1 is empty */
746 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
747 ok(hres == S_FALSE,
748 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
749 hres);
751 /* Release all hfnt2 refs */
752 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
753 ok(hres == S_OK,
754 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
755 hres);
757 /* Check if hfnt2 is empty */
758 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
759 ok(hres == S_FALSE,
760 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
761 hres);
763 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
765 IFont_Release(ifnt1);
767 /* Add a reference for destroyed hfnt1 */
768 hres = IFont_AddRefHfont(ifnt2,hfnt1);
769 ok(hres == S_OK,
770 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
771 hres);
773 /* Decrement reference for destroyed hfnt1 */
774 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
775 ok(hres == S_OK ||
776 hres == S_FALSE, /* <= win2k */
777 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
778 hres);
780 /* Shows that releasing all IFONT's does clear the HFONT cache. */
782 IFont_Release(ifnt2);
784 /* Need to make a new IFONT for testing */
785 fd.fUnderline = 1;
786 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
787 IFont_get_hFont(ifnt3,&hfnt3);
789 /* Add a reference for destroyed hfnt1 */
790 hres = IFont_AddRefHfont(ifnt3,hfnt1);
791 ok(hres == S_FALSE,
792 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
793 hres);
795 /* Decrement reference for destroyed hfnt1 */
796 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
797 ok(hres == S_FALSE,
798 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
799 hres);
801 IFont_Release(ifnt3);
804 START_TEST(olefont)
806 hOleaut32 = GetModuleHandleA("oleaut32.dll");
807 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
808 if (!pOleCreateFontIndirect)
810 skip("OleCreateFontIndirect not available\n");
811 return;
814 test_QueryInterface();
815 test_type_info();
817 /* Test various size operations and conversions. */
818 /* Add more as needed. */
819 if (0) /* FIXME: failing tests */
821 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
822 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
823 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
825 /* These depend on details of how IFont rounds sizes internally. */
826 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
827 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
830 test_font_events_disp();
831 test_GetIDsOfNames();
832 test_Invoke();
833 test_IsEqual();
834 test_ReleaseHfont();
835 test_AddRefHfont();