wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / oleaut32 / tests / olefont.c
blob5137d807e78cc49323ccdc03651b74a8f33af85d
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 };
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 EXPECT_HR(hr,hr_exp) \
55 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
57 /* Create a font with cySize given by lo_size, hi_size, */
58 /* SetRatio to ratio_logical, ratio_himetric, */
59 /* check that resulting hfont has height hfont_height. */
60 /* Various checks along the way. */
61 static void test_ifont_size(LONGLONG size, 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 LOGFONTA lf;
69 CY psize;
70 HRESULT hres;
71 DWORD rtnval;
73 fd.cbSizeofstruct = sizeof(FONTDESC);
74 fd.lpstrName = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
75 fd.cySize.int64 = size;
76 fd.sWeight = 0;
77 fd.sCharset = 0;
78 fd.fItalic = FALSE;
79 fd.fUnderline = FALSE;
80 fd.fStrikethrough = FALSE;
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 /* Change the scaling ratio */
90 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
91 ok((ratio_logical && ratio_himetric) ? hres == S_OK : hres == E_FAIL,
92 "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name, hres);
94 /* Read back size. */
95 hres = IFont_get_Size(ifnt, &psize);
96 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
97 test_name, hres);
99 /* Check returned size - allow for errors due to rounding & font realization. */
100 ok((psize.int64 - size) < 10000 && (psize.int64 - size) > -10000,
101 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
102 test_name, S(psize).Lo, S(psize).Hi, fd.cySize.Lo, fd.cySize.Hi);
104 /* Check hFont size. */
105 hres = IFont_get_hFont (ifnt, &hfont);
106 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
107 test_name, hres);
108 rtnval = GetObjectA(hfont, sizeof(LOGFONTA), &lf);
109 ok(rtnval > 0, "GetObject(hfont) failed\n");
111 /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
112 ok(abs(lf.lfHeight - hfont_height) <= 1,
113 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
114 test_name, lf.lfHeight, hfont_height);
116 /* Free IFont. */
117 IFont_Release(ifnt);
120 static void test_ifont_sizes(void)
122 /* Test various size operations and conversions. */
123 /* Add more as needed. */
125 /* Results of first 2 tests depend on display resolution. */
126 HDC hdc = GetDC(0);
127 LONG dpi = GetDeviceCaps(hdc, LOGPIXELSY); /* expected results depend on display DPI */
128 ReleaseDC(0, hdc);
129 if(dpi == 96) /* normal resolution display */
131 test_ifont_size(180000, 0, 0, -24, "default"); /* normal font */
132 test_ifont_size(186000, 0, 0, -25, "rounding"); /* test rounding */
133 } else if(dpi == 72) /* low resolution display */
135 test_ifont_size(180000, 0, 0, -18, "default"); /* normal font */
136 test_ifont_size(186000, 0, 0, -19, "rounding"); /* test rounding */
137 } else if(dpi == 120) /* high resolution display */
139 test_ifont_size(180000, 0, 0, -30, "default"); /* normal font */
140 test_ifont_size(186000, 0, 0, -31, "rounding"); /* test rounding */
141 } else
142 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi);
144 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
145 test_ifont_size(180000, 72, 2540, -18, "ratio1"); /* change ratio */
146 test_ifont_size(180000, 144, 2540, -36, "ratio2"); /* another ratio */
147 test_ifont_size(180000, 72, 1270, -36, "ratio3"); /* yet another ratio */
148 test_ifont_size(186000, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
150 /* test various combinations of logical == himetric */
151 test_ifont_size(180000, 10, 10, -635, "identical ratio 1");
152 test_ifont_size(240000, 10, 10, -848, "identical ratio 2");
153 test_ifont_size(300000, 10, 10, -1058, "identical ratio 3");
155 /* test various combinations of logical and himetric both set to 1 */
156 test_ifont_size(180000, 1, 1, -24, "1:1 ratio 1");
157 test_ifont_size(240000, 1, 1, -32, "1:1 ratio 2");
158 test_ifont_size(300000, 1, 1, -40, "1:1 ratio 3");
160 /* test various combinations of logical set to 1 */
161 test_ifont_size(180000, 1, 0, -24, "1:0 ratio 1");
162 test_ifont_size(240000, 1, 0, -32, "1:0 ratio 2");
163 test_ifont_size(300000, 1, 0, -40, "1:0 ratio 3");
165 /* test various combinations of himetric set to 1 */
166 test_ifont_size(180000, 0, 1, -24, "0:1 ratio 1");
167 test_ifont_size(240000, 0, 1, -32, "0:1 ratio 2");
168 test_ifont_size(300000, 0, 1, -40, "0:1 ratio 3");
170 /* test various combinations of 2:1 logical:himetric */
171 test_ifont_size(180000, 2, 1, -1270, "2:1 ratio 1");
172 test_ifont_size(240000, 2, 1, -1694, "2:1 ratio 2");
173 test_ifont_size(300000, 2, 1, -2117, "2:1 ratio 3");
175 /* test various combinations of 1:2 logical:himetric */
176 test_ifont_size(180000, 1, 2, -318, "1:2 ratio 1");
177 test_ifont_size(240000, 1, 2, -424, "1:2 ratio 2");
178 test_ifont_size(300000, 1, 2, -529, "1:2 ratio 3");
180 /* test various combinations of logical and himetric both set to 2 */
181 test_ifont_size(180000, 2, 2, -635, "2:2 ratio 1");
182 test_ifont_size(240000, 2, 2, -848, "2:2 ratio 2");
183 test_ifont_size(300000, 2, 2, -1058, "2:2 ratio 3");
186 static void test_QueryInterface(void)
188 LPVOID pvObj = NULL;
189 HRESULT hr;
190 IFont* font = NULL;
191 IPersistStreamInit *persistStreamInit = NULL;
192 LONG ref;
194 hr = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
195 EXPECT_HR(hr, E_POINTER);
197 hr = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
198 font = pvObj;
200 EXPECT_HR(hr, S_OK);
201 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
203 pvObj = NULL;
204 hr = IFont_QueryInterface( font, &IID_IFont, &pvObj);
205 EXPECT_HR(hr, S_OK);
207 /* Test if QueryInterface increments ref counter for IFONTs */
208 ref = IFont_AddRef(font);
209 ok(ref == 3 ||
210 broken(ref == 1), /* win95 */
211 "IFont_QI expected ref value 3 but instead got %d\n", ref);
212 IFont_Release(font);
214 ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");
216 /* IFont never had IPersistStreamInit */
217 hr = IFont_QueryInterface(font, &IID_IPersistStreamInit, (void**)&persistStreamInit);
218 EXPECT_HR(hr, E_NOINTERFACE);
220 IFont_Release(font);
221 IFont_Release(font);
224 static void test_type_info(void)
226 LPVOID pvObj = NULL;
227 HRESULT hres;
228 IFontDisp* fontdisp = NULL;
229 ITypeInfo* pTInfo;
230 WCHAR name_Name[] = {'N','a','m','e',0};
231 BSTR names[3];
232 UINT n;
233 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
234 SORT_DEFAULT);
235 DISPPARAMS dispparams;
236 VARIANT varresult;
238 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
239 fontdisp = pvObj;
241 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
242 ok(hres == S_OK, "GTI returned 0x%08x instead of S_OK.\n", hres);
243 ok(pTInfo != NULL, "GTI returned NULL.\n");
245 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
246 ok(hres == S_OK, "GetNames returned 0x%08x instead of S_OK.\n", hres);
247 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
248 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
249 SysFreeString(names[0]);
251 ITypeInfo_Release(pTInfo);
253 dispparams.cNamedArgs = 0;
254 dispparams.rgdispidNamedArgs = NULL;
255 dispparams.cArgs = 0;
256 dispparams.rgvarg = NULL;
257 VariantInit(&varresult);
258 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
259 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
260 NULL, NULL);
261 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres);
262 VariantClear(&varresult);
264 IFontDisp_Release(fontdisp);
267 static HRESULT WINAPI FontEventsDisp_QueryInterface(IFontEventsDisp *iface, REFIID riid, void **ppvObject)
269 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
271 IFontEventsDisp_AddRef(iface);
272 *ppvObject = iface;
273 return S_OK;
275 else
277 *ppvObject = NULL;
278 return E_NOINTERFACE;
282 static ULONG WINAPI FontEventsDisp_AddRef(
283 IFontEventsDisp *iface)
285 return 2;
288 static ULONG WINAPI FontEventsDisp_Release(
289 IFontEventsDisp *iface)
291 return 1;
294 static HRESULT WINAPI FontEventsDisp_GetTypeInfoCount(IFontEventsDisp *iface, UINT *pctinfo)
296 ok(0, "unexpected call\n");
297 return E_NOTIMPL;
300 static HRESULT WINAPI FontEventsDisp_GetTypeInfo(IFontEventsDisp *iface, UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
302 ok(0, "unexpected call\n");
303 return E_NOTIMPL;
306 static HRESULT WINAPI FontEventsDisp_GetIDsOfNames(IFontEventsDisp *iface, REFIID riid, LPOLESTR *names, UINT cNames, LCID lcid,
307 DISPID *dispid)
309 ok(0, "unexpected call\n");
310 return E_NOTIMPL;
313 static int fonteventsdisp_invoke_called;
314 static BSTR fonteventsdisp_invoke_arg0;
316 static HRESULT WINAPI FontEventsDisp_Invoke(
317 IFontEventsDisp *iface,
318 DISPID dispid,
319 REFIID riid,
320 LCID lcid,
321 WORD wFlags,
322 DISPPARAMS *pDispParams,
323 VARIANT *pVarResult,
324 EXCEPINFO *pExcepInfo,
325 UINT *puArgErr)
327 VARIANTARG *arg0 = &pDispParams->rgvarg[0];
329 ok(dispid == DISPID_FONT_CHANGED, "expected DISPID_FONT_CHANGED instead of 0x%x\n", dispid);
330 ok(IsEqualGUID(riid, &GUID_NULL), "got riid %s\n", wine_dbgstr_guid(riid));
331 ok(wFlags == INVOKE_FUNC, "expected INVOKE_FUNC instead of 0x%x\n", wFlags);
332 ok(pDispParams->cArgs == 1, "expected arg count 1, got %d\n", pDispParams->cArgs);
333 ok(V_VT(arg0) == VT_BSTR, "expected VT_BSTR, got %d\n", V_VT(arg0));
335 fonteventsdisp_invoke_arg0 = SysAllocString(V_BSTR(arg0));
336 fonteventsdisp_invoke_called++;
337 return S_OK;
340 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
342 FontEventsDisp_QueryInterface,
343 FontEventsDisp_AddRef,
344 FontEventsDisp_Release,
345 FontEventsDisp_GetTypeInfoCount,
346 FontEventsDisp_GetTypeInfo,
347 FontEventsDisp_GetIDsOfNames,
348 FontEventsDisp_Invoke
351 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
353 struct font_dispid
355 DISPID dispid;
356 const WCHAR *name;
359 static void test_font_events_disp(void)
361 static const WCHAR nameW[] = {'N','a','m','e',0};
362 static const WCHAR sizeW[] = {'S','i','z','e',0};
363 static const WCHAR boldW[] = {'B','o','l','d',0};
364 static const WCHAR italicW[] = {'I','t','a','l','i','c',0};
365 static const WCHAR underlineW[] = {'U','n','d','e','r','l','i','n','e',0};
366 static const WCHAR strikeW[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
367 static const WCHAR weightW[] = {'W','e','i','g','h','t',0};
368 static const WCHAR charsetW[] = {'C','h','a','r','s','e','t',0};
370 static const struct font_dispid font_dispids[] =
372 { DISPID_FONT_NAME, nameW },
373 { DISPID_FONT_SIZE, sizeW },
374 { DISPID_FONT_BOLD, boldW },
375 { DISPID_FONT_ITALIC, italicW },
376 { DISPID_FONT_UNDER, underlineW },
377 { DISPID_FONT_STRIKE, strikeW },
378 { DISPID_FONT_WEIGHT, weightW },
379 { DISPID_FONT_CHARSET, charsetW }
382 IFont *pFont;
383 IFont *pFont2;
384 IConnectionPointContainer *pCPC;
385 IConnectionPoint *pCP;
386 FONTDESC fontdesc;
387 HRESULT hr;
388 DWORD dwCookie;
389 IFontDisp *pFontDisp;
390 DISPPARAMS dispparams;
391 VARIANTARG vararg;
392 INT i;
394 fontdesc.cbSizeofstruct = sizeof(fontdesc);
395 fontdesc.lpstrName = MSSansSerif_font;
396 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
397 fontdesc.sWeight = FW_NORMAL;
398 fontdesc.sCharset = 0;
399 fontdesc.fItalic = FALSE;
400 fontdesc.fUnderline = FALSE;
401 fontdesc.fStrikethrough = FALSE;
403 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
404 EXPECT_HR(hr, S_OK);
406 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
407 EXPECT_HR(hr, S_OK);
409 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
410 EXPECT_HR(hr, S_OK);
411 IConnectionPointContainer_Release(pCPC);
413 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
414 EXPECT_HR(hr, S_OK);
415 IConnectionPoint_Release(pCP);
417 fonteventsdisp_invoke_called = 0;
418 fonteventsdisp_invoke_arg0 = NULL;
419 hr = IFont_put_Bold(pFont, TRUE);
420 EXPECT_HR(hr, S_OK);
422 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
423 SysFreeString(fonteventsdisp_invoke_arg0);
425 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
426 EXPECT_HR(hr, S_OK);
428 for (i = 0; i < ARRAY_SIZE(font_dispids); i++)
430 switch (font_dispids[i].dispid)
432 case DISPID_FONT_NAME:
434 static const WCHAR arialW[] = {'A','r','i','a','l',0};
435 V_VT(&vararg) = VT_BSTR;
436 V_BSTR(&vararg) = SysAllocString(arialW);
437 break;
439 case DISPID_FONT_SIZE:
440 V_VT(&vararg) = VT_CY;
441 S(V_CY(&vararg)).Lo = 25;
442 S(V_CY(&vararg)).Hi = 0;
443 break;
444 case DISPID_FONT_BOLD:
445 V_VT(&vararg) = VT_BOOL;
446 V_BOOL(&vararg) = VARIANT_FALSE;
447 break;
448 case DISPID_FONT_ITALIC:
449 case DISPID_FONT_UNDER:
450 case DISPID_FONT_STRIKE:
451 V_VT(&vararg) = VT_BOOL;
452 V_BOOL(&vararg) = VARIANT_TRUE;
453 break;
454 case DISPID_FONT_WEIGHT:
455 V_VT(&vararg) = VT_I2;
456 V_I2(&vararg) = FW_BLACK;
457 break;
458 case DISPID_FONT_CHARSET:
459 V_VT(&vararg) = VT_I2;
460 V_I2(&vararg) = 1;
461 break;
462 default:
466 dispparams.cNamedArgs = 0;
467 dispparams.rgdispidNamedArgs = NULL;
468 dispparams.cArgs = 1;
469 dispparams.rgvarg = &vararg;
470 fonteventsdisp_invoke_called = 0;
471 hr = IFontDisp_Invoke(pFontDisp, font_dispids[i].dispid, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
472 ok(hr == S_OK, "dispid=%d, got 0x%08x\n", font_dispids[i].dispid, hr);
473 ok(fonteventsdisp_invoke_called == 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids[i].dispid,
474 fonteventsdisp_invoke_called);
475 if (hr == S_OK)
477 ok(!lstrcmpW(font_dispids[i].name, fonteventsdisp_invoke_arg0), "dispid=%d, got %s, expected %s\n",
478 font_dispids[i].dispid, wine_dbgstr_w(fonteventsdisp_invoke_arg0), wine_dbgstr_w(font_dispids[i].name));
479 SysFreeString(fonteventsdisp_invoke_arg0);
481 VariantClear(&vararg);
484 IFontDisp_Release(pFontDisp);
486 hr = IFont_Clone(pFont, &pFont2);
487 EXPECT_HR(hr, S_OK);
488 IFont_Release(pFont);
490 /* this test shows that the notification routine isn't called again */
491 fonteventsdisp_invoke_called = 0;
492 hr = IFont_put_Bold(pFont2, FALSE);
493 EXPECT_HR(hr, S_OK);
494 ok(fonteventsdisp_invoke_called == 0, "got %d\n", fonteventsdisp_invoke_called);
496 IFont_Release(pFont2);
499 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
500 WCHAR* w_name_2, const char* a_name_2,
501 LCID lcid, DISPID id_1, DISPID id_2,
502 HRESULT hres_expect, int numnames)
504 LPVOID pvObj = NULL;
505 IFontDisp *fontdisp = NULL;
506 HRESULT hres;
507 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
508 LPOLESTR names[2] = {w_name_1, w_name_2};
510 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
511 fontdisp = pvObj;
513 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
514 lcid, rgDispId);
516 /* test hres */
517 ok(hres == hres_expect,
518 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
519 a_name_1, a_name_2, hres, hres_expect);
521 /* test first DISPID */
522 ok(rgDispId[0]==id_1,
523 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
524 a_name_1, rgDispId[0], id_1);
526 /* test second DISPID is present */
527 if (numnames == 2)
529 ok(rgDispId[1]==id_2,
530 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
531 a_name_2, rgDispId[1], id_2);
534 IFontDisp_Release(fontdisp);
537 static void test_GetIDsOfNames(void)
539 WCHAR name_Name[] = {'N','a','m','e',0};
540 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
541 WCHAR name_Size[] = {'S','i','z','e',0};
542 WCHAR name_Bold[] = {'B','o','l','d',0};
543 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
544 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
545 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
546 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
547 WCHAR name_Foo[] = {'F','o','o',0};
548 WCHAR name_nAmE[] = {'n','A','m','E',0};
549 WCHAR name_Nom[] = {'N','o','m',0};
551 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
552 SORT_DEFAULT);
553 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
554 SORT_DEFAULT);
556 /* Test DISPID_FONTs for the various properties. */
557 test_names_ids(name_Name, "Name", NULL, "", en_us,
558 DISPID_FONT_NAME, 0, S_OK,1);
559 test_names_ids(name_Size, "Size", NULL, "", en_us,
560 DISPID_FONT_SIZE, 0, S_OK,1);
561 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
562 DISPID_FONT_BOLD, 0, S_OK,1);
563 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
564 DISPID_FONT_ITALIC, 0, S_OK,1);
565 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
566 DISPID_FONT_UNDER, 0, S_OK,1);
567 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
568 DISPID_FONT_STRIKE, 0, S_OK,1);
569 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
570 DISPID_FONT_WEIGHT, 0, S_OK,1);
571 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
572 DISPID_FONT_CHARSET, 0, S_OK,1);
574 /* Capitalization doesn't matter. */
575 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
576 DISPID_FONT_NAME, 0, S_OK,1);
578 /* Unknown name. */
579 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
580 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
582 /* Pass several names: first is processed, */
583 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
584 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
585 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
586 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
587 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
589 /* Locale ID has no effect. */
590 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
591 DISPID_FONT_NAME, 0, S_OK,1);
592 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
593 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
595 /* One of the arguments are invalid */
596 test_names_ids(name_Name, "Name", NULL, "", en_us,
597 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
598 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
599 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
600 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
601 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
603 /* Crazy locale ID? */
604 test_names_ids(name_Name, "Name", NULL, "", -1,
605 DISPID_FONT_NAME, 0, S_OK,1);
608 static void test_Invoke(void)
610 IFontDisp *fontdisp;
611 HRESULT hr;
612 VARIANTARG vararg;
613 DISPPARAMS dispparams;
614 VARIANT varresult;
616 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
617 EXPECT_HR(hr, S_OK);
619 V_VT(&vararg) = VT_BOOL;
620 V_BOOL(&vararg) = VARIANT_FALSE;
621 dispparams.cNamedArgs = 0;
622 dispparams.rgdispidNamedArgs = NULL;
623 dispparams.cArgs = 1;
624 dispparams.rgvarg = &vararg;
625 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
626 EXPECT_HR(hr, DISP_E_UNKNOWNINTERFACE);
628 dispparams.cArgs = 0;
629 dispparams.rgvarg = NULL;
630 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
631 EXPECT_HR(hr, DISP_E_BADPARAMCOUNT);
633 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
634 EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
636 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
637 EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
639 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
640 EXPECT_HR(hr, S_OK);
642 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
643 EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
645 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
646 EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
648 dispparams.cArgs = 1;
649 dispparams.rgvarg = &vararg;
650 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
651 EXPECT_HR(hr, S_OK);
653 IFontDisp_Release(fontdisp);
656 static void test_IsEqual(void)
658 FONTDESC fd;
659 IFont* ifnt = NULL;
660 IFont* ifnt2 = NULL;
661 HRESULT hres;
663 /* Basic font description */
664 fd.cbSizeofstruct = sizeof(FONTDESC);
665 fd.lpstrName = system_font;
666 S(fd.cySize).Lo = 100;
667 S(fd.cySize).Hi = 100;
668 fd.sWeight = 0;
669 fd.sCharset = 0;
670 fd.fItalic = FALSE;
671 fd.fUnderline = FALSE;
672 fd.fStrikethrough = FALSE;
674 /* Create font */
675 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);
677 /* Test equal fonts */
678 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
679 hres = IFont_IsEqual(ifnt,ifnt2);
680 ok(hres == S_OK,
681 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
682 IFont_Release(ifnt2);
684 /* Check for bad pointer */
685 hres = IFont_IsEqual(ifnt,NULL);
686 ok(hres == E_POINTER,
687 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);
689 /* Test strName */
690 fd.lpstrName = arial_font;
691 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
692 hres = IFont_IsEqual(ifnt,ifnt2);
693 ok(hres == S_FALSE,
694 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
695 fd.lpstrName = system_font;
696 IFont_Release(ifnt2);
698 /* Test lo font size */
699 S(fd.cySize).Lo = 10000;
700 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
701 hres = IFont_IsEqual(ifnt,ifnt2);
702 ok(hres == S_FALSE,
703 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
704 S(fd.cySize).Lo = 100;
705 IFont_Release(ifnt2);
707 /* Test hi font size */
708 S(fd.cySize).Hi = 10000;
709 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
710 hres = IFont_IsEqual(ifnt,ifnt2);
711 ok(hres == S_FALSE,
712 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
713 S(fd.cySize).Hi = 100;
714 IFont_Release(ifnt2);
716 /* Test font weight */
717 fd.sWeight = 100;
718 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
719 hres = IFont_IsEqual(ifnt,ifnt2);
720 ok(hres == S_FALSE,
721 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
722 fd.sWeight = 0;
723 IFont_Release(ifnt2);
725 /* Test charset */
726 fd.sCharset = 1;
727 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
728 hres = IFont_IsEqual(ifnt,ifnt2);
729 ok(hres == S_FALSE,
730 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
731 fd.sCharset = 0;
732 IFont_Release(ifnt2);
734 /* Test italic setting */
735 fd.fItalic = TRUE;
736 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
737 hres = IFont_IsEqual(ifnt,ifnt2);
738 ok(hres == S_FALSE,
739 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
740 fd.fItalic = FALSE;
741 IFont_Release(ifnt2);
743 /* Test underline setting */
744 fd.fUnderline = TRUE;
745 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
746 hres = IFont_IsEqual(ifnt,ifnt2);
747 ok(hres == S_FALSE,
748 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
749 fd.fUnderline = FALSE;
750 IFont_Release(ifnt2);
752 /* Test strikethrough setting */
753 fd.fStrikethrough = TRUE;
754 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
755 hres = IFont_IsEqual(ifnt,ifnt2);
756 ok(hres == S_FALSE,
757 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
758 fd.fStrikethrough = FALSE;
759 IFont_Release(ifnt2);
761 /* Free IFont. */
762 IFont_Release(ifnt);
765 static void test_ReleaseHfont(void)
767 FONTDESC fd;
768 LPVOID pvObj1 = NULL;
769 LPVOID pvObj2 = NULL;
770 IFont* ifnt1 = NULL;
771 IFont* ifnt2 = NULL;
772 HFONT hfnt1 = 0;
773 HFONT hfnt2 = 0;
774 HRESULT hres;
776 /* Basic font description */
777 fd.cbSizeofstruct = sizeof(FONTDESC);
778 fd.lpstrName = system_font;
779 S(fd.cySize).Lo = 100;
780 S(fd.cySize).Hi = 100;
781 fd.sWeight = 0;
782 fd.sCharset = 0;
783 fd.fItalic = FALSE;
784 fd.fUnderline = FALSE;
785 fd.fStrikethrough = FALSE;
787 /* Create HFONTs and IFONTs */
788 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
789 ifnt1 = pvObj1;
790 IFont_get_hFont(ifnt1,&hfnt1);
791 fd.lpstrName = arial_font;
792 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
793 ifnt2 = pvObj2;
794 IFont_get_hFont(ifnt2,&hfnt2);
796 /* Try invalid HFONT */
797 hres = IFont_ReleaseHfont(ifnt1,NULL);
798 ok(hres == E_INVALIDARG,
799 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
800 hres);
802 /* Try to add a bad HFONT */
803 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
804 ok(hres == S_FALSE,
805 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
806 hres);
808 /* Release all refs */
809 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
810 ok(hres == S_OK,
811 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
812 hres);
814 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
815 ok(hres == S_OK,
816 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
817 hres);
819 /* Check that both lists are empty */
820 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
821 ok(hres == S_FALSE,
822 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
823 hres);
825 /* The list should be empty */
826 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
827 ok(hres == S_FALSE,
828 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
829 hres);
831 IFont_Release(ifnt1);
832 IFont_Release(ifnt2);
835 static void test_AddRefHfont(void)
837 FONTDESC fd;
838 IFont* ifnt1 = NULL;
839 IFont* ifnt2 = NULL;
840 IFont* ifnt3 = NULL;
841 HFONT hfnt1 = 0;
842 HFONT hfnt2 = 0;
843 HFONT hfnt3 = 0;
844 HRESULT hres;
846 /* Basic font description */
847 fd.cbSizeofstruct = sizeof(FONTDESC);
848 fd.lpstrName = system_font;
849 S(fd.cySize).Lo = 100;
850 S(fd.cySize).Hi = 100;
851 fd.sWeight = 0;
852 fd.sCharset = 0;
853 fd.fItalic = FALSE;
854 fd.fUnderline = FALSE;
855 fd.fStrikethrough = FALSE;
857 /* Create HFONTs and IFONTs */
858 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
859 IFont_get_hFont(ifnt1,&hfnt1);
860 fd.lpstrName = arial_font;
861 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
862 IFont_get_hFont(ifnt2,&hfnt2);
864 /* Try invalid HFONT */
865 hres = IFont_AddRefHfont(ifnt1,NULL);
866 ok(hres == E_INVALIDARG,
867 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
868 hres);
870 /* Try to add a bad HFONT */
871 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
872 ok(hres == S_FALSE,
873 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
874 hres);
876 /* Add simple IFONT HFONT pair */
877 hres = IFont_AddRefHfont(ifnt1,hfnt1);
878 ok(hres == S_OK,
879 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
880 hres);
882 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
883 hres = IFont_AddRefHfont(ifnt2,hfnt1);
884 ok(hres == S_OK,
885 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
886 hres);
888 /* Release all hfnt1 refs */
889 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
890 ok(hres == S_OK,
891 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
892 hres);
894 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
895 ok(hres == S_OK,
896 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
897 hres);
899 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
900 ok(hres == S_OK,
901 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
902 hres);
904 /* Check if hfnt1 is empty */
905 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
906 ok(hres == S_FALSE,
907 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
908 hres);
910 /* Release all hfnt2 refs */
911 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
912 ok(hres == S_OK,
913 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
914 hres);
916 /* Check if hfnt2 is empty */
917 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
918 ok(hres == S_FALSE,
919 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
920 hres);
922 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
924 IFont_Release(ifnt1);
926 /* Add a reference for destroyed hfnt1 */
927 hres = IFont_AddRefHfont(ifnt2,hfnt1);
928 ok(hres == S_OK,
929 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
930 hres);
932 /* Decrement reference for destroyed hfnt1 */
933 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
934 ok(hres == S_OK ||
935 hres == S_FALSE, /* <= win2k */
936 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
937 hres);
939 /* Shows that releasing all IFONT's does clear the HFONT cache. */
941 IFont_Release(ifnt2);
943 /* Need to make a new IFONT for testing */
944 fd.fUnderline = TRUE;
945 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
946 IFont_get_hFont(ifnt3,&hfnt3);
948 /* Add a reference for destroyed hfnt1 */
949 hres = IFont_AddRefHfont(ifnt3,hfnt1);
950 ok(hres == S_FALSE,
951 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
952 hres);
954 /* Decrement reference for destroyed hfnt1 */
955 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
956 ok(hres == S_FALSE,
957 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
958 hres);
960 IFont_Release(ifnt3);
963 static void test_returns(void)
965 IFont *pFont;
966 FONTDESC fontdesc;
967 HRESULT hr;
969 fontdesc.cbSizeofstruct = sizeof(fontdesc);
970 fontdesc.lpstrName = MSSansSerif_font;
971 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
972 fontdesc.sWeight = FW_NORMAL;
973 fontdesc.sCharset = 0;
974 fontdesc.fItalic = FALSE;
975 fontdesc.fUnderline = FALSE;
976 fontdesc.fStrikethrough = FALSE;
978 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
979 EXPECT_HR(hr, S_OK);
981 hr = IFont_put_Name(pFont, NULL);
982 EXPECT_HR(hr, CTL_E_INVALIDPROPERTYVALUE);
984 hr = IFont_get_Name(pFont, NULL);
985 EXPECT_HR(hr, E_POINTER);
987 hr = IFont_get_Size(pFont, NULL);
988 EXPECT_HR(hr, E_POINTER);
990 hr = IFont_get_Bold(pFont, NULL);
991 EXPECT_HR(hr, E_POINTER);
993 IFont_Release(pFont);
996 static void test_hfont_lifetime(void)
998 IFont *font, *font2;
999 FONTDESC fontdesc;
1000 HRESULT hr;
1001 HFONT hfont, first_hfont = NULL;
1002 CY size;
1003 DWORD obj_type;
1004 int i;
1006 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1007 fontdesc.lpstrName = arial_font;
1008 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1009 fontdesc.sWeight = FW_NORMAL;
1010 fontdesc.sCharset = ANSI_CHARSET;
1011 fontdesc.fItalic = FALSE;
1012 fontdesc.fUnderline = FALSE;
1013 fontdesc.fStrikethrough = FALSE;
1015 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1016 EXPECT_HR(hr, S_OK);
1018 hr = IFont_get_hFont(font, &hfont);
1019 EXPECT_HR(hr, S_OK);
1021 /* show that if the font is updated the old hfont is deleted when the
1022 new font is realized */
1023 for(i = 0; i < 100; i++)
1025 HFONT last_hfont = hfont;
1027 size.int64 = (i + 10) * 20000;
1029 obj_type = GetObjectType(hfont);
1030 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1032 hr = IFont_put_Size(font, size);
1033 EXPECT_HR(hr, S_OK);
1035 /* put_Size doesn't cause the new font to be realized */
1036 obj_type = GetObjectType(last_hfont);
1037 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1039 hr = IFont_get_hFont(font, &hfont);
1040 EXPECT_HR(hr, S_OK);
1043 /* now show that if we take a reference on the hfont, it persists
1044 until the font object is released */
1045 for(i = 0; i < 100; i++)
1047 size.int64 = (i + 10) * 20000;
1049 obj_type = GetObjectType(hfont);
1050 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1052 hr = IFont_put_Size(font, size);
1053 EXPECT_HR(hr, S_OK);
1055 hr = IFont_get_hFont(font, &hfont);
1056 EXPECT_HR(hr, S_OK);
1058 hr = IFont_AddRefHfont(font, hfont);
1059 EXPECT_HR(hr, S_OK);
1061 if(i == 0) first_hfont = hfont;
1062 obj_type = GetObjectType(first_hfont);
1063 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1066 IFont_Release(font);
1068 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
1069 through re-realization */
1071 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1072 EXPECT_HR(hr, S_OK);
1074 hr = IFont_get_hFont(font, &hfont);
1075 EXPECT_HR(hr, S_OK);
1077 for(i = 0; i < 100; i++)
1079 HFONT last_hfont = hfont;
1081 size.int64 = (i + 10) * 20000;
1083 obj_type = GetObjectType(hfont);
1084 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1086 hr = IFont_put_Size(font, size);
1087 EXPECT_HR(hr, S_OK);
1089 /* put_Size doesn't cause the new font to be realized */
1090 obj_type = GetObjectType(last_hfont);
1091 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1093 hr = IFont_get_hFont(font, &hfont);
1094 EXPECT_HR(hr, S_OK);
1096 hr = IFont_AddRefHfont(font, hfont);
1097 EXPECT_HR(hr, S_OK);
1099 hr = IFont_ReleaseHfont(font, hfont);
1100 EXPECT_HR(hr, S_OK);
1103 /* Interestingly if we release a nonexistent reference on the hfont,
1104 * it persists until the font object is released
1106 for(i = 0; i < 100; i++)
1108 size.int64 = (i + 10) * 20000;
1110 obj_type = GetObjectType(hfont);
1111 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1113 hr = IFont_put_Size(font, size);
1114 EXPECT_HR(hr, S_OK);
1116 hr = IFont_get_hFont(font, &hfont);
1117 EXPECT_HR(hr, S_OK);
1119 hr = IFont_ReleaseHfont(font, hfont);
1120 EXPECT_HR(hr, S_OK);
1122 if(i == 0) first_hfont = hfont;
1123 obj_type = GetObjectType(first_hfont);
1124 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1127 IFont_Release(font);
1129 /* If we take two internal references on a hfont then we can release
1130 it twice. So it looks like there's a total reference count
1131 that includes internal and external references */
1133 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1134 EXPECT_HR(hr, S_OK);
1135 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
1136 EXPECT_HR(hr, S_OK);
1138 hr = IFont_get_hFont(font, &hfont);
1139 EXPECT_HR(hr, S_OK);
1140 hr = IFont_get_hFont(font2, &first_hfont);
1141 EXPECT_HR(hr, S_OK);
1142 todo_wine
1143 ok(hfont == first_hfont, "fonts differ\n");
1144 hr = IFont_ReleaseHfont(font, hfont);
1145 EXPECT_HR(hr, S_OK);
1146 hr = IFont_ReleaseHfont(font, hfont);
1147 todo_wine
1148 EXPECT_HR(hr, S_OK);
1149 hr = IFont_ReleaseHfont(font, hfont);
1150 EXPECT_HR(hr, S_FALSE);
1152 obj_type = GetObjectType(hfont);
1153 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1155 IFont_Release(font);
1157 obj_type = GetObjectType(hfont);
1158 ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
1160 IFont_Release(font2);
1163 static void test_realization(void)
1165 IFont *font;
1166 FONTDESC fontdesc;
1167 HRESULT hr;
1168 BSTR name;
1169 SHORT cs;
1171 /* Try to create a symbol only font (marlett) with charset
1172 set to ANSI. This will result in another, ANSI, font
1173 being selected */
1174 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1175 fontdesc.lpstrName = marlett_font;
1176 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1177 fontdesc.sWeight = FW_NORMAL;
1178 fontdesc.sCharset = ANSI_CHARSET;
1179 fontdesc.fItalic = FALSE;
1180 fontdesc.fUnderline = FALSE;
1181 fontdesc.fStrikethrough = FALSE;
1183 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1184 EXPECT_HR(hr, S_OK);
1186 hr = IFont_get_Charset(font, &cs);
1187 EXPECT_HR(hr, S_OK);
1188 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1190 IFont_Release(font);
1192 /* Now create an ANSI font and change the name to marlett */
1194 fontdesc.lpstrName = arial_font;
1196 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1197 EXPECT_HR(hr, S_OK);
1199 hr = IFont_get_Charset(font, &cs);
1200 EXPECT_HR(hr, S_OK);
1201 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1203 name = SysAllocString(marlett_font);
1204 hr = IFont_put_Name(font, name);
1205 EXPECT_HR(hr, S_OK);
1206 SysFreeString(name);
1208 hr = IFont_get_Name(font, &name);
1209 EXPECT_HR(hr, S_OK);
1210 ok(!lstrcmpiW(name, marlett_font), "got name %s\n", wine_dbgstr_w(name));
1211 SysFreeString(name);
1213 hr = IFont_get_Charset(font, &cs);
1214 EXPECT_HR(hr, S_OK);
1215 ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);
1217 IFont_Release(font);
1220 static void test_OleCreateFontIndirect(void)
1222 FONTDESC fontdesc;
1223 IUnknown *unk, *unk2;
1224 IFont *font;
1225 HRESULT hr;
1227 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1228 fontdesc.lpstrName = arial_font;
1229 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1230 fontdesc.sWeight = FW_NORMAL;
1231 fontdesc.sCharset = ANSI_CHARSET;
1232 fontdesc.fItalic = FALSE;
1233 fontdesc.fUnderline = FALSE;
1234 fontdesc.fStrikethrough = FALSE;
1236 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1237 EXPECT_HR(hr, S_OK);
1238 IFont_Release(font);
1240 /* play with cbSizeofstruct value */
1241 fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
1242 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1243 EXPECT_HR(hr, S_OK);
1244 IFont_Release(font);
1246 fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
1247 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1248 EXPECT_HR(hr, S_OK);
1249 IFont_Release(font);
1251 fontdesc.cbSizeofstruct = 0;
1252 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1253 EXPECT_HR(hr, S_OK);
1254 IFont_Release(font);
1256 hr = OleInitialize(NULL);
1257 ok(hr == S_OK, "got 0x%08x\n", hr);
1259 hr = CoGetClassObject(&CLSID_StdFont, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&unk);
1260 ok(hr == S_OK, "got 0x%08x\n", hr);
1262 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void**)&unk2);
1263 ok(hr == S_OK, "got 0x%08x\n", hr);
1265 IUnknown_Release(unk);
1266 IUnknown_Release(unk2);
1268 OleUninitialize();
1271 START_TEST(olefont)
1273 hOleaut32 = GetModuleHandleA("oleaut32.dll");
1274 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
1275 if (!pOleCreateFontIndirect)
1277 win_skip("OleCreateFontIndirect not available\n");
1278 return;
1281 test_QueryInterface();
1282 test_type_info();
1283 test_ifont_sizes();
1284 test_font_events_disp();
1285 test_GetIDsOfNames();
1286 test_Invoke();
1287 test_IsEqual();
1288 test_ReleaseHfont();
1289 test_AddRefHfont();
1290 test_returns();
1291 test_hfont_lifetime();
1292 test_realization();
1293 test_OleCreateFontIndirect();