Release 0.9.39.
[wine/gsoc-2012-control.git] / dlls / oleaut32 / tests / olefont.c
blob69621cf965ad9ad68fe0c5ddfe738470ca621614
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 <wtypes.h>
40 #include <olectl.h>
41 #include <ocidl.h>
43 static WCHAR MSSansSerif_font[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
44 static WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
45 static WCHAR arial_font[] = { 'A','r','i','a','l',0 };
47 static HMODULE hOleaut32;
49 static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
51 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
53 /* Create a font with cySize given by lo_size, hi_size, */
54 /* SetRatio to ratio_logical, ratio_himetric, */
55 /* check that resulting hfont has height hfont_height. */
56 /* Various checks along the way. */
58 static void test_ifont_sizes(long lo_size, long hi_size,
59 long ratio_logical, long ratio_himetric,
60 long hfont_height, const char * test_name)
62 FONTDESC fd;
63 LPVOID pvObj = NULL;
64 IFont* ifnt = NULL;
65 HFONT hfont;
66 LOGFONT lf;
67 CY psize;
68 HRESULT hres;
70 fd.cbSizeofstruct = sizeof(FONTDESC);
71 fd.lpstrName = system_font;
72 S(fd.cySize).Lo = lo_size;
73 S(fd.cySize).Hi = hi_size;
74 fd.sWeight = 0;
75 fd.sCharset = 0;
76 fd.fItalic = 0;
77 fd.fUnderline = 0;
78 fd.fStrikethrough = 0;
80 /* Create font, test that it worked. */
81 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
82 ifnt = pvObj;
83 ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
84 test_name, hres);
85 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
87 /* Read back size. Hi part was ignored. */
88 hres = IFont_get_Size(ifnt, &psize);
89 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
90 test_name, hres);
91 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
92 "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
93 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
95 /* Change ratio, check size unchanged. Standard is 72, 2540. */
96 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
97 ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
98 test_name, hres);
99 hres = IFont_get_Size(ifnt, &psize);
100 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
101 test_name, hres);
102 ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
103 "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%ld, Hi=%ld.\n",
104 test_name, S(psize).Lo, S(psize).Hi, lo_size, 0L);
106 /* Check hFont size with this ratio. This tests an important */
107 /* conversion for which MSDN is very wrong. */
108 hres = IFont_get_hFont (ifnt, &hfont);
109 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
110 test_name, hres);
111 hres = GetObject (hfont, sizeof(LOGFONT), &lf);
112 ok(lf.lfHeight == hfont_height,
113 "%s: hFont has lf.lfHeight=%d, expected %ld.\n",
114 test_name, lf.lfHeight, hfont_height);
116 /* Free IFont. */
117 IFont_Release(ifnt);
120 static void test_QueryInterface(void)
122 LPVOID pvObj = NULL;
123 HRESULT hres;
124 IFont* font = NULL;
125 LONG ret;
127 hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
128 font = pvObj;
130 ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
131 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
133 pvObj = NULL;
134 hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);
136 /* Test if QueryInterface increments ref counter for IFONTs */
137 ret = IFont_AddRef(font);
138 ok(ret == 3, "IFont_QI expected ref value 3 but instead got %12u\n",ret);
139 IFont_Release(font);
141 ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
142 ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
144 /* Orignial ref and QueryInterface ref both have to be released */
145 IFont_Release(font);
146 IFont_Release(font);
149 static void test_type_info(void)
151 LPVOID pvObj = NULL;
152 HRESULT hres;
153 IFontDisp* fontdisp = NULL;
154 ITypeInfo* pTInfo;
155 WCHAR name_Name[] = {'N','a','m','e',0};
156 BSTR names[3];
157 UINT n;
158 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
159 SORT_DEFAULT);
160 DISPPARAMS dispparams;
161 VARIANT varresult;
163 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
164 fontdisp = pvObj;
166 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
167 ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
168 ok(pTInfo != NULL, "GTI returned NULL.\n");
170 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
171 ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
172 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
173 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
175 ITypeInfo_Release(pTInfo);
177 dispparams.cNamedArgs = 0;
178 dispparams.rgdispidNamedArgs = NULL;
179 dispparams.cArgs = 0;
180 dispparams.rgvarg = NULL;
181 VariantInit(&varresult);
182 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
183 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
184 NULL, NULL);
185 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
186 VariantClear(&varresult);
188 IFontDisp_Release(fontdisp);
191 static HRESULT WINAPI FontEventsDisp_QueryInterface(
192 IFontEventsDisp *iface,
193 /* [in] */ REFIID riid,
194 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
196 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
198 IUnknown_AddRef(iface);
199 *ppvObject = iface;
200 return S_OK;
202 else
204 *ppvObject = NULL;
205 return E_NOINTERFACE;
209 static ULONG WINAPI FontEventsDisp_AddRef(
210 IFontEventsDisp *iface)
212 return 2;
215 static ULONG WINAPI FontEventsDisp_Release(
216 IFontEventsDisp *iface)
218 return 1;
221 static int fonteventsdisp_invoke_called = 0;
223 static HRESULT WINAPI FontEventsDisp_Invoke(
224 IFontEventsDisp __RPC_FAR * iface,
225 /* [in] */ DISPID dispIdMember,
226 /* [in] */ REFIID riid,
227 /* [in] */ LCID lcid,
228 /* [in] */ WORD wFlags,
229 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
230 /* [out] */ VARIANT __RPC_FAR *pVarResult,
231 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
232 /* [out] */ UINT __RPC_FAR *puArgErr)
234 static const WCHAR wszBold[] = {'B','o','l','d',0};
235 ok(wFlags == INVOKE_FUNC, "invoke flags should have been INVOKE_FUNC instead of 0x%x\n", wFlags);
236 ok(dispIdMember == DISPID_FONT_CHANGED, "dispIdMember should have been DISPID_FONT_CHANGED instead of 0x%x\n", dispIdMember);
237 ok(pDispParams->cArgs == 1, "pDispParams->cArgs should have been 1 instead of %d\n", pDispParams->cArgs);
238 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]));
239 ok(!lstrcmpW(V_BSTR(&pDispParams->rgvarg[0]), wszBold), "String in first param should have been \"Bold\"\n");
241 fonteventsdisp_invoke_called++;
242 return S_OK;
245 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
247 FontEventsDisp_QueryInterface,
248 FontEventsDisp_AddRef,
249 FontEventsDisp_Release,
250 NULL,
251 NULL,
252 NULL,
253 FontEventsDisp_Invoke
256 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
258 static void test_font_events_disp(void)
260 IFont *pFont;
261 IFont *pFont2;
262 IConnectionPointContainer *pCPC;
263 IConnectionPoint *pCP;
264 FONTDESC fontdesc;
265 HRESULT hr;
266 DWORD dwCookie;
267 IFontDisp *pFontDisp;
268 DISPPARAMS dispparams;
269 VARIANTARG vararg;
271 fontdesc.cbSizeofstruct = sizeof(fontdesc);
272 fontdesc.lpstrName = MSSansSerif_font;
273 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
274 fontdesc.sWeight = FW_NORMAL;
275 fontdesc.sCharset = 0;
276 fontdesc.fItalic = FALSE;
277 fontdesc.fUnderline = FALSE;
278 fontdesc.fStrikethrough = FALSE;
280 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
281 ok_ole_success(hr, "OleCreateFontIndirect");
283 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
284 ok_ole_success(hr, "IFont_QueryInterface");
286 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
287 ok_ole_success(hr, "IConnectionPointContainer_FindConnectionPoint");
288 IConnectionPointContainer_Release(pCPC);
290 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
291 ok_ole_success(hr, "IConnectionPoint_Advise");
292 IConnectionPoint_Release(pCP);
294 hr = IFont_put_Bold(pFont, TRUE);
295 ok_ole_success(hr, "IFont_put_Bold");
297 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
299 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
300 ok_ole_success(hr, "IFont_QueryInterface");
302 V_VT(&vararg) = VT_BOOL;
303 V_BOOL(&vararg) = VARIANT_FALSE;
304 dispparams.cNamedArgs = 0;
305 dispparams.rgdispidNamedArgs = NULL;
306 dispparams.cArgs = 1;
307 dispparams.rgvarg = &vararg;
308 hr = IFontDisp_Invoke(pFontDisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
310 IFontDisp_Release(pFontDisp);
312 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
313 fonteventsdisp_invoke_called);
315 hr = IFont_Clone(pFont, &pFont2);
316 ok_ole_success(hr, "IFont_Clone");
317 IFont_Release(pFont);
319 hr = IFont_put_Bold(pFont2, FALSE);
320 ok_ole_success(hr, "IFont_put_Bold");
322 /* this test shows that the notification routine isn't called again */
323 ok(fonteventsdisp_invoke_called == 2, "IFontEventDisp::Invoke was called %d times instead of twice\n",
324 fonteventsdisp_invoke_called);
326 IFont_Release(pFont2);
329 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
330 WCHAR* w_name_2, const char* a_name_2,
331 LCID lcid, DISPID id_1, DISPID id_2,
332 HRESULT hres_expect, int numnames)
334 LPVOID pvObj = NULL;
335 IFontDisp *fontdisp = NULL;
336 HRESULT hres;
337 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
338 LPOLESTR names[2] = {w_name_1, w_name_2};
340 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
341 fontdisp = pvObj;
343 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
344 lcid, rgDispId);
346 /* test hres */
347 ok(hres == hres_expect,
348 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
349 a_name_1, a_name_2, hres, hres_expect);
351 /* test first DISPID */
352 ok(rgDispId[0]==id_1,
353 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
354 a_name_1, rgDispId[0], id_1);
356 /* test second DISPID is present */
357 if (numnames == 2)
359 ok(rgDispId[1]==id_2,
360 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
361 a_name_2, rgDispId[1], id_2);
364 IFontDisp_Release(fontdisp);
367 static void test_GetIDsOfNames(void)
369 WCHAR name_Name[] = {'N','a','m','e',0};
370 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
371 WCHAR name_Size[] = {'S','i','z','e',0};
372 WCHAR name_Bold[] = {'B','o','l','d',0};
373 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
374 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
375 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
376 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
377 WCHAR name_Foo[] = {'F','o','o',0};
378 WCHAR name_nAmE[] = {'n','A','m','E',0};
379 WCHAR name_Nom[] = {'N','o','m',0};
381 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
382 SORT_DEFAULT);
383 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
384 SORT_DEFAULT);
386 /* Test DISPID_FONTs for the various properties. */
387 test_names_ids(name_Name, "Name", NULL, "", en_us,
388 DISPID_FONT_NAME, 0, S_OK,1);
389 test_names_ids(name_Size, "Size", NULL, "", en_us,
390 DISPID_FONT_SIZE, 0, S_OK,1);
391 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
392 DISPID_FONT_BOLD, 0, S_OK,1);
393 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
394 DISPID_FONT_ITALIC, 0, S_OK,1);
395 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
396 DISPID_FONT_UNDER, 0, S_OK,1);
397 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
398 DISPID_FONT_STRIKE, 0, S_OK,1);
399 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
400 DISPID_FONT_WEIGHT, 0, S_OK,1);
401 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
402 DISPID_FONT_CHARSET, 0, S_OK,1);
404 /* Capitalization doesn't matter. */
405 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
406 DISPID_FONT_NAME, 0, S_OK,1);
408 /* Unknown name. */
409 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
410 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
412 /* Pass several names: first is processed, */
413 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
414 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
415 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
416 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
417 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
419 /* Locale ID has no effect. */
420 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
421 DISPID_FONT_NAME, 0, S_OK,1);
422 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
423 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
425 /* One of the arguments are invalid */
426 test_names_ids(name_Name, "Name", NULL, "", en_us,
427 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
428 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
429 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
430 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
431 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
433 /* Crazy locale ID? */
434 test_names_ids(name_Name, "Name", NULL, "", -1,
435 DISPID_FONT_NAME, 0, S_OK,1);
438 static void test_Invoke(void)
440 IFontDisp *fontdisp;
441 HRESULT hr;
442 VARIANTARG vararg;
443 DISPPARAMS dispparams;
444 VARIANT varresult;
446 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
447 ok_ole_success(hr, "OleCreateFontIndirect");
449 V_VT(&vararg) = VT_BOOL;
450 V_BOOL(&vararg) = VARIANT_FALSE;
451 dispparams.cNamedArgs = 0;
452 dispparams.rgdispidNamedArgs = NULL;
453 dispparams.cArgs = 1;
454 dispparams.rgvarg = &vararg;
455 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
456 ok(hr == DISP_E_UNKNOWNINTERFACE, "IFontDisp_Invoke should have returned DISP_E_UNKNOWNINTERFACE instead of 0x%08x\n", hr);
458 dispparams.cArgs = 0;
459 dispparams.rgvarg = NULL;
460 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
461 ok(hr == DISP_E_BADPARAMCOUNT, "IFontDisp_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
463 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
464 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
466 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
467 ok(hr == DISP_E_PARAMNOTOPTIONAL, "IFontDisp_Invoke should have returned DISP_E_PARAMNOTOPTIONAL instead of 0x%08x\n", hr);
469 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
470 ok_ole_success(hr, "IFontDisp_Invoke");
472 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
473 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
475 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
476 ok(hr == DISP_E_MEMBERNOTFOUND, "IFontDisp_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
478 dispparams.cArgs = 1;
479 dispparams.rgvarg = &vararg;
480 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
481 ok_ole_success(hr, "IFontDisp_Invoke");
483 IFontDisp_Release(fontdisp);
486 static void test_IsEqual(void)
488 FONTDESC fd;
489 LPVOID pvObj = NULL;
490 LPVOID pvObj2 = NULL;
491 IFont* ifnt = NULL;
492 IFont* ifnt2 = NULL;
493 HRESULT hres;
495 /* Basic font description */
496 fd.cbSizeofstruct = sizeof(FONTDESC);
497 fd.lpstrName = system_font;
498 S(fd.cySize).Lo = 100;
499 S(fd.cySize).Hi = 100;
500 fd.sWeight = 0;
501 fd.sCharset = 0;
502 fd.fItalic = 0;
503 fd.fUnderline = 0;
504 fd.fStrikethrough = 0;
506 /* Create font */
507 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
508 ifnt = pvObj;
510 /* Test equal fonts */
511 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
512 ifnt2 = pvObj2;
513 hres = IFont_IsEqual(ifnt,ifnt2);
514 ok(hres == S_OK,
515 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
516 IFont_Release(ifnt2);
518 /* Check for bad pointer */
519 hres = IFont_IsEqual(ifnt,NULL);
520 ok(hres == E_POINTER,
521 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
523 /* Test strName */
524 fd.lpstrName = arial_font;
525 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
526 hres = IFont_IsEqual(ifnt,ifnt2);
527 ok(hres == S_FALSE,
528 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
529 fd.lpstrName = system_font;
530 IFont_Release(ifnt2);
532 /* Test lo font size */
533 S(fd.cySize).Lo = 10000;
534 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
535 ifnt2 = pvObj2;
536 hres = IFont_IsEqual(ifnt,ifnt2);
537 ok(hres == S_FALSE,
538 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
539 S(fd.cySize).Lo = 100;
540 IFont_Release(ifnt2);
542 /* Test hi font size */
543 S(fd.cySize).Hi = 10000;
544 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
545 ifnt2 = pvObj2;
546 hres = IFont_IsEqual(ifnt,ifnt2);
547 ok(hres == S_FALSE,
548 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
549 S(fd.cySize).Hi = 100;
550 IFont_Release(ifnt2);
552 /* Test font weight */
553 fd.sWeight = 100;
554 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
555 ifnt2 = pvObj2;
556 hres = IFont_IsEqual(ifnt,ifnt2);
557 ok(hres == S_FALSE,
558 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
559 fd.sWeight = 0;
560 IFont_Release(ifnt2);
562 /* Test charset */
563 fd.sCharset = 1;
564 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
565 hres = IFont_IsEqual(ifnt,ifnt2);
566 ok(hres == S_FALSE,
567 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
568 fd.sCharset = 0;
569 IFont_Release(ifnt2);
571 /* Test italic setting */
572 fd.fItalic = 1;
573 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
574 hres = IFont_IsEqual(ifnt,ifnt2);
575 ok(hres == S_FALSE,
576 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
577 fd.fItalic = 0;
578 IFont_Release(ifnt2);
580 /* Test underline setting */
581 fd.fUnderline = 1;
582 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
583 hres = IFont_IsEqual(ifnt,ifnt2);
584 ok(hres == S_FALSE,
585 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
586 fd.fUnderline = 0;
587 IFont_Release(ifnt2);
589 /* Test strikethrough setting */
590 fd.fStrikethrough = 1;
591 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
592 hres = IFont_IsEqual(ifnt,ifnt2);
593 ok(hres == S_FALSE,
594 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
595 fd.fStrikethrough = 0;
596 IFont_Release(ifnt2);
598 /* Free IFont. */
599 IFont_Release(ifnt);
602 static void test_ReleaseHfont(void)
604 FONTDESC fd;
605 LPVOID pvObj1 = NULL;
606 LPVOID pvObj2 = NULL;
607 IFont* ifnt1 = NULL;
608 IFont* ifnt2 = NULL;
609 HFONT hfnt1 = 0;
610 HFONT hfnt2 = 0;
611 HRESULT hres;
613 /* Basic font description */
614 fd.cbSizeofstruct = sizeof(FONTDESC);
615 fd.lpstrName = system_font;
616 S(fd.cySize).Lo = 100;
617 S(fd.cySize).Hi = 100;
618 fd.sWeight = 0;
619 fd.sCharset = 0;
620 fd.fItalic = 0;
621 fd.fUnderline = 0;
622 fd.fStrikethrough = 0;
624 /* Create HFONTs and IFONTs */
625 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
626 ifnt1 = pvObj1;
627 IFont_get_hFont(ifnt1,&hfnt1);
628 fd.lpstrName = arial_font;
629 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
630 ifnt2 = pvObj2;
631 IFont_get_hFont(ifnt2,&hfnt2);
633 /* Try invalid HFONT */
634 hres = IFont_ReleaseHfont(ifnt1,NULL);
635 ok(hres == E_INVALIDARG,
636 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
637 hres);
639 /* Try to add a bad HFONT */
640 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
641 ok(hres == S_FALSE,
642 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
643 hres);
645 /* Release all refs */
646 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
647 ok(hres == S_OK,
648 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
649 hres);
651 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
652 ok(hres == S_OK,
653 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
654 hres);
656 /* Check that both lists are empty */
657 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
658 ok(hres == S_FALSE,
659 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
660 hres);
662 /* The list should be empty */
663 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
664 ok(hres == S_FALSE,
665 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
666 hres);
668 IFont_Release(ifnt1);
669 IFont_Release(ifnt2);
672 static void test_AddRefHfont(void)
674 FONTDESC fd;
675 IFont* ifnt1 = NULL;
676 IFont* ifnt2 = NULL;
677 IFont* ifnt3 = NULL;
678 HFONT hfnt1 = 0;
679 HFONT hfnt2 = 0;
680 HFONT hfnt3 = 0;
681 HRESULT hres;
683 /* Basic font description */
684 fd.cbSizeofstruct = sizeof(FONTDESC);
685 fd.lpstrName = system_font;
686 S(fd.cySize).Lo = 100;
687 S(fd.cySize).Hi = 100;
688 fd.sWeight = 0;
689 fd.sCharset = 0;
690 fd.fItalic = 0;
691 fd.fUnderline = 0;
692 fd.fStrikethrough = 0;
694 /* Create HFONTs and IFONTs */
695 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
696 IFont_get_hFont(ifnt1,&hfnt1);
697 fd.lpstrName = arial_font;
698 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
699 IFont_get_hFont(ifnt2,&hfnt2);
701 /* Try invalid HFONT */
702 hres = IFont_AddRefHfont(ifnt1,NULL);
703 ok(hres == E_INVALIDARG,
704 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
705 hres);
707 /* Try to add a bad HFONT */
708 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
709 ok(hres == S_FALSE,
710 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
711 hres);
713 /* Add simple IFONT HFONT pair */
714 hres = IFont_AddRefHfont(ifnt1,hfnt1);
715 ok(hres == S_OK,
716 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
717 hres);
719 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
720 hres = IFont_AddRefHfont(ifnt2,hfnt1);
721 ok(hres == S_OK,
722 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
723 hres);
725 /* Release all hfnt1 refs */
726 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
727 ok(hres == S_OK,
728 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
729 hres);
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 /* Check if hfnt1 is empty */
742 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
743 ok(hres == S_FALSE,
744 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
745 hres);
747 /* Release all hfnt2 refs */
748 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
749 ok(hres == S_OK,
750 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
751 hres);
753 /* Check if hfnt2 is empty */
754 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
755 ok(hres == S_FALSE,
756 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
757 hres);
759 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
761 IFont_Release(ifnt1);
763 /* Add a reference for destroyed hfnt1 */
764 hres = IFont_AddRefHfont(ifnt2,hfnt1);
765 ok(hres == S_OK,
766 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
767 hres);
769 /* Decrement reference for destroyed hfnt1 */
770 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
771 ok(hres == S_OK,
772 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
773 hres);
775 /* Shows that releasing all IFONT's does clear the HFONT cache. */
777 IFont_Release(ifnt2);
779 /* Need to make a new IFONT for testing */
780 fd.fUnderline = 1;
781 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
782 IFont_get_hFont(ifnt3,&hfnt3);
784 /* Add a reference for destroyed hfnt1 */
785 hres = IFont_AddRefHfont(ifnt3,hfnt1);
786 ok(hres == S_FALSE,
787 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
788 hres);
790 /* Decrement reference for destroyed hfnt1 */
791 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
792 ok(hres == S_FALSE,
793 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
794 hres);
796 IFont_Release(ifnt3);
799 START_TEST(olefont)
801 hOleaut32 = LoadLibraryA("oleaut32.dll");
802 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
803 if (!pOleCreateFontIndirect)
804 return;
806 test_QueryInterface();
807 test_type_info();
809 /* Test various size operations and conversions. */
810 /* Add more as needed. */
811 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
812 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
813 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
815 /* These depend on details of how IFont rounds sizes internally. */
816 test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); /* zero size */
817 test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); /* test rounding */
819 test_font_events_disp();
820 test_GetIDsOfNames();
821 test_Invoke();
822 test_IsEqual();
823 test_ReleaseHfont();
824 test_AddRefHfont();