d3d9/tests: Accept AMD GPU sysmem sample failure in test_mipmap_upload.
[wine.git] / dlls / oleaut32 / tests / olefont.c
blobcf5b9ab34af50695756daeff9aa0c4a45837bbbb
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 check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
55 static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
57 IUnknown *iface = iface_ptr;
58 HRESULT hr, expected_hr;
59 IUnknown *unk;
61 expected_hr = supported ? S_OK : E_NOINTERFACE;
63 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
64 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
65 if (SUCCEEDED(hr))
66 IUnknown_Release(unk);
69 #define EXPECT_HR(hr,hr_exp) \
70 ok(hr == hr_exp, "got 0x%08lx, expected 0x%08lx\n", hr, hr_exp)
72 /* Create a font with cySize given by lo_size, hi_size, */
73 /* SetRatio to ratio_logical, ratio_himetric, */
74 /* check that resulting hfont has height hfont_height. */
75 /* Various checks along the way. */
76 static void test_ifont_size(LONGLONG size, LONG ratio_logical, LONG ratio_himetric,
77 LONG hfont_height, const char * test_name)
79 FONTDESC fd;
80 LPVOID pvObj = NULL;
81 IFont* ifnt = NULL;
82 HFONT hfont;
83 LOGFONTA lf;
84 CY psize;
85 HRESULT hres;
86 DWORD rtnval;
88 fd.cbSizeofstruct = sizeof(FONTDESC);
89 fd.lpstrName = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
90 fd.cySize.int64 = size;
91 fd.sWeight = 0;
92 fd.sCharset = 0;
93 fd.fItalic = FALSE;
94 fd.fUnderline = FALSE;
95 fd.fStrikethrough = FALSE;
97 /* Create font, test that it worked. */
98 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
99 ifnt = pvObj;
100 ok(hres == S_OK,"%s: OCFI returns 0x%08lx instead of S_OK.\n",
101 test_name, hres);
102 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
104 /* Change the scaling ratio */
105 hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
106 ok((ratio_logical && ratio_himetric) ? hres == S_OK : hres == E_FAIL,
107 "%s: IFont_SetRatio unexpectedly returned 0x%08lx.\n", test_name, hres);
109 /* Read back size. */
110 hres = IFont_get_Size(ifnt, &psize);
111 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08lx instead of S_OK.\n",
112 test_name, hres);
114 /* Check returned size - allow for errors due to rounding & font realization. */
115 ok((psize.int64 - size) < 10000 && (psize.int64 - size) > -10000,
116 "%s: IFont_get_Size: Lo=%ld, Hi=%ld; expected Lo=%ld, Hi=%ld.\n",
117 test_name, S(psize).Lo, S(psize).Hi, fd.cySize.Lo, fd.cySize.Hi);
119 /* Check hFont size. */
120 hres = IFont_get_hFont (ifnt, &hfont);
121 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08lx instead of S_OK.\n",
122 test_name, hres);
123 rtnval = GetObjectA(hfont, sizeof(LOGFONTA), &lf);
124 ok(rtnval > 0, "GetObject(hfont) failed\n");
126 /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
127 ok(abs(lf.lfHeight - hfont_height) <= 1,
128 "%s: hFont has lf.lfHeight=%ld, expected %ld.\n",
129 test_name, lf.lfHeight, hfont_height);
131 /* Free IFont. */
132 IFont_Release(ifnt);
135 static void test_ifont_sizes(void)
137 /* Test various size operations and conversions. */
138 /* Add more as needed. */
140 /* Results of first 2 tests depend on display resolution. */
141 HDC hdc = GetDC(0);
142 LONG dpi = GetDeviceCaps(hdc, LOGPIXELSY); /* expected results depend on display DPI */
143 ReleaseDC(0, hdc);
144 if(dpi == 96) /* normal resolution display */
146 test_ifont_size(180000, 0, 0, -24, "default"); /* normal font */
147 test_ifont_size(186000, 0, 0, -25, "rounding"); /* test rounding */
148 } else if(dpi == 72) /* low resolution display */
150 test_ifont_size(180000, 0, 0, -18, "default"); /* normal font */
151 test_ifont_size(186000, 0, 0, -19, "rounding"); /* test rounding */
152 } else if(dpi == 120) /* high resolution display */
154 test_ifont_size(180000, 0, 0, -30, "default"); /* normal font */
155 test_ifont_size(186000, 0, 0, -31, "rounding"); /* test rounding */
156 } else
157 skip("Skipping resolution dependent font size tests - display resolution is %ld\n", dpi);
159 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
160 test_ifont_size(180000, 72, 2540, -18, "ratio1"); /* change ratio */
161 test_ifont_size(180000, 144, 2540, -36, "ratio2"); /* another ratio */
162 test_ifont_size(180000, 72, 1270, -36, "ratio3"); /* yet another ratio */
163 test_ifont_size(186000, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
165 /* test various combinations of logical == himetric */
166 test_ifont_size(180000, 10, 10, -635, "identical ratio 1");
167 test_ifont_size(240000, 10, 10, -848, "identical ratio 2");
168 test_ifont_size(300000, 10, 10, -1058, "identical ratio 3");
170 /* test various combinations of logical and himetric both set to 1 */
171 test_ifont_size(180000, 1, 1, -24, "1:1 ratio 1");
172 test_ifont_size(240000, 1, 1, -32, "1:1 ratio 2");
173 test_ifont_size(300000, 1, 1, -40, "1:1 ratio 3");
175 /* test various combinations of logical set to 1 */
176 test_ifont_size(180000, 1, 0, -24, "1:0 ratio 1");
177 test_ifont_size(240000, 1, 0, -32, "1:0 ratio 2");
178 test_ifont_size(300000, 1, 0, -40, "1:0 ratio 3");
180 /* test various combinations of himetric set to 1 */
181 test_ifont_size(180000, 0, 1, -24, "0:1 ratio 1");
182 test_ifont_size(240000, 0, 1, -32, "0:1 ratio 2");
183 test_ifont_size(300000, 0, 1, -40, "0:1 ratio 3");
185 /* test various combinations of 2:1 logical:himetric */
186 test_ifont_size(180000, 2, 1, -1270, "2:1 ratio 1");
187 test_ifont_size(240000, 2, 1, -1694, "2:1 ratio 2");
188 test_ifont_size(300000, 2, 1, -2117, "2:1 ratio 3");
190 /* test various combinations of 1:2 logical:himetric */
191 test_ifont_size(180000, 1, 2, -318, "1:2 ratio 1");
192 test_ifont_size(240000, 1, 2, -424, "1:2 ratio 2");
193 test_ifont_size(300000, 1, 2, -529, "1:2 ratio 3");
195 /* test various combinations of logical and himetric both set to 2 */
196 test_ifont_size(180000, 2, 2, -635, "2:2 ratio 1");
197 test_ifont_size(240000, 2, 2, -848, "2:2 ratio 2");
198 test_ifont_size(300000, 2, 2, -1058, "2:2 ratio 3");
201 static void test_interfaces(void)
203 HRESULT hr;
204 IFont *font = NULL;
206 hr = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
207 EXPECT_HR(hr, E_POINTER);
209 hr = pOleCreateFontIndirect(NULL, &IID_IFont, (void **)&font);
210 EXPECT_HR(hr, S_OK);
211 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
213 check_interface(font, &IID_IFont, TRUE);
214 check_interface(font, &IID_IFontDisp, TRUE);
215 check_interface(font, &IID_IDispatch, TRUE);
216 check_interface(font, &IID_IPersist, TRUE);
217 check_interface(font, &IID_IPersistStream, TRUE);
218 check_interface(font, &IID_IConnectionPointContainer, TRUE);
219 check_interface(font, &IID_IPersistPropertyBag, TRUE);
220 check_interface(font, &IID_IPersistStreamInit, FALSE);
222 IFont_Release(font);
225 static void test_type_info(void)
227 LPVOID pvObj = NULL;
228 HRESULT hres;
229 IFontDisp* fontdisp = NULL;
230 ITypeInfo* pTInfo;
231 WCHAR name_Name[] = {'N','a','m','e',0};
232 BSTR names[3];
233 UINT n;
234 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
235 SORT_DEFAULT);
236 DISPPARAMS dispparams;
237 VARIANT varresult;
239 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
240 fontdisp = pvObj;
242 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
243 ok(hres == S_OK, "GTI returned 0x%08lx instead of S_OK.\n", hres);
244 ok(pTInfo != NULL, "GTI returned NULL.\n");
246 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
247 ok(hres == S_OK, "GetNames returned 0x%08lx instead of S_OK.\n", hres);
248 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
249 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
250 SysFreeString(names[0]);
252 ITypeInfo_Release(pTInfo);
254 dispparams.cNamedArgs = 0;
255 dispparams.rgdispidNamedArgs = NULL;
256 dispparams.cArgs = 0;
257 dispparams.rgvarg = NULL;
258 VariantInit(&varresult);
259 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
260 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
261 NULL, NULL);
262 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08lx instead of S_OK.\n", hres);
263 VariantClear(&varresult);
265 IFontDisp_Release(fontdisp);
268 static HRESULT WINAPI FontEventsDisp_QueryInterface(IFontEventsDisp *iface, REFIID riid, void **ppvObject)
270 if (IsEqualIID(riid, &IID_IFontEventsDisp) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
272 IFontEventsDisp_AddRef(iface);
273 *ppvObject = iface;
274 return S_OK;
276 else
278 *ppvObject = NULL;
279 return E_NOINTERFACE;
283 static ULONG WINAPI FontEventsDisp_AddRef(
284 IFontEventsDisp *iface)
286 return 2;
289 static ULONG WINAPI FontEventsDisp_Release(
290 IFontEventsDisp *iface)
292 return 1;
295 static HRESULT WINAPI FontEventsDisp_GetTypeInfoCount(IFontEventsDisp *iface, UINT *pctinfo)
297 ok(0, "unexpected call\n");
298 return E_NOTIMPL;
301 static HRESULT WINAPI FontEventsDisp_GetTypeInfo(IFontEventsDisp *iface, UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
303 ok(0, "unexpected call\n");
304 return E_NOTIMPL;
307 static HRESULT WINAPI FontEventsDisp_GetIDsOfNames(IFontEventsDisp *iface, REFIID riid, LPOLESTR *names, UINT cNames, LCID lcid,
308 DISPID *dispid)
310 ok(0, "unexpected call\n");
311 return E_NOTIMPL;
314 static int fonteventsdisp_invoke_called;
315 static BSTR fonteventsdisp_invoke_arg0;
317 static HRESULT WINAPI FontEventsDisp_Invoke(
318 IFontEventsDisp *iface,
319 DISPID dispid,
320 REFIID riid,
321 LCID lcid,
322 WORD wFlags,
323 DISPPARAMS *pDispParams,
324 VARIANT *pVarResult,
325 EXCEPINFO *pExcepInfo,
326 UINT *puArgErr)
328 VARIANTARG *arg0 = &pDispParams->rgvarg[0];
330 ok(dispid == DISPID_FONT_CHANGED, "expected DISPID_FONT_CHANGED instead of 0x%lx\n", dispid);
331 ok(IsEqualGUID(riid, &GUID_NULL), "got riid %s\n", wine_dbgstr_guid(riid));
332 ok(wFlags == INVOKE_FUNC, "expected INVOKE_FUNC instead of 0x%x\n", wFlags);
333 ok(pDispParams->cArgs == 1, "expected arg count 1, got %d\n", pDispParams->cArgs);
334 ok(V_VT(arg0) == VT_BSTR, "expected VT_BSTR, got %d\n", V_VT(arg0));
336 fonteventsdisp_invoke_arg0 = SysAllocString(V_BSTR(arg0));
337 fonteventsdisp_invoke_called++;
338 return S_OK;
341 static IFontEventsDispVtbl FontEventsDisp_Vtbl =
343 FontEventsDisp_QueryInterface,
344 FontEventsDisp_AddRef,
345 FontEventsDisp_Release,
346 FontEventsDisp_GetTypeInfoCount,
347 FontEventsDisp_GetTypeInfo,
348 FontEventsDisp_GetIDsOfNames,
349 FontEventsDisp_Invoke
352 static IFontEventsDisp FontEventsDisp = { &FontEventsDisp_Vtbl };
354 struct font_dispid
356 DISPID dispid;
357 const WCHAR *name;
360 static void test_font_events_disp(void)
362 static const WCHAR nameW[] = {'N','a','m','e',0};
363 static const WCHAR sizeW[] = {'S','i','z','e',0};
364 static const WCHAR boldW[] = {'B','o','l','d',0};
365 static const WCHAR italicW[] = {'I','t','a','l','i','c',0};
366 static const WCHAR underlineW[] = {'U','n','d','e','r','l','i','n','e',0};
367 static const WCHAR strikeW[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
368 static const WCHAR weightW[] = {'W','e','i','g','h','t',0};
369 static const WCHAR charsetW[] = {'C','h','a','r','s','e','t',0};
371 static const struct font_dispid font_dispids[] =
373 { DISPID_FONT_NAME, nameW },
374 { DISPID_FONT_SIZE, sizeW },
375 { DISPID_FONT_BOLD, boldW },
376 { DISPID_FONT_ITALIC, italicW },
377 { DISPID_FONT_UNDER, underlineW },
378 { DISPID_FONT_STRIKE, strikeW },
379 { DISPID_FONT_WEIGHT, weightW },
380 { DISPID_FONT_CHARSET, charsetW }
383 IFont *pFont;
384 IFont *pFont2;
385 IConnectionPointContainer *pCPC;
386 IConnectionPoint *pCP;
387 FONTDESC fontdesc;
388 HRESULT hr;
389 DWORD dwCookie;
390 IFontDisp *pFontDisp;
391 DISPPARAMS dispparams;
392 VARIANTARG vararg;
393 INT i;
395 fontdesc.cbSizeofstruct = sizeof(fontdesc);
396 fontdesc.lpstrName = MSSansSerif_font;
397 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
398 fontdesc.sWeight = FW_NORMAL;
399 fontdesc.sCharset = 0;
400 fontdesc.fItalic = FALSE;
401 fontdesc.fUnderline = FALSE;
402 fontdesc.fStrikethrough = FALSE;
404 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
405 EXPECT_HR(hr, S_OK);
407 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
408 EXPECT_HR(hr, S_OK);
410 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
411 EXPECT_HR(hr, S_OK);
412 IConnectionPointContainer_Release(pCPC);
414 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
415 EXPECT_HR(hr, S_OK);
416 IConnectionPoint_Release(pCP);
418 fonteventsdisp_invoke_called = 0;
419 fonteventsdisp_invoke_arg0 = NULL;
420 hr = IFont_put_Bold(pFont, TRUE);
421 EXPECT_HR(hr, S_OK);
423 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
424 SysFreeString(fonteventsdisp_invoke_arg0);
426 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
427 EXPECT_HR(hr, S_OK);
429 for (i = 0; i < ARRAY_SIZE(font_dispids); i++)
431 switch (font_dispids[i].dispid)
433 case DISPID_FONT_NAME:
435 static const WCHAR arialW[] = {'A','r','i','a','l',0};
436 V_VT(&vararg) = VT_BSTR;
437 V_BSTR(&vararg) = SysAllocString(arialW);
438 break;
440 case DISPID_FONT_SIZE:
441 V_VT(&vararg) = VT_CY;
442 S(V_CY(&vararg)).Lo = 25;
443 S(V_CY(&vararg)).Hi = 0;
444 break;
445 case DISPID_FONT_BOLD:
446 V_VT(&vararg) = VT_BOOL;
447 V_BOOL(&vararg) = VARIANT_FALSE;
448 break;
449 case DISPID_FONT_ITALIC:
450 case DISPID_FONT_UNDER:
451 case DISPID_FONT_STRIKE:
452 V_VT(&vararg) = VT_BOOL;
453 V_BOOL(&vararg) = VARIANT_TRUE;
454 break;
455 case DISPID_FONT_WEIGHT:
456 V_VT(&vararg) = VT_I2;
457 V_I2(&vararg) = FW_BLACK;
458 break;
459 case DISPID_FONT_CHARSET:
460 V_VT(&vararg) = VT_I2;
461 V_I2(&vararg) = 1;
462 break;
463 default:
467 dispparams.cNamedArgs = 0;
468 dispparams.rgdispidNamedArgs = NULL;
469 dispparams.cArgs = 1;
470 dispparams.rgvarg = &vararg;
471 fonteventsdisp_invoke_called = 0;
472 hr = IFontDisp_Invoke(pFontDisp, font_dispids[i].dispid, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
473 ok(hr == S_OK, "dispid=%ld, got 0x%08lx\n", font_dispids[i].dispid, hr);
474 ok(fonteventsdisp_invoke_called == 1, "dispid=%ld, DISPID_FONT_CHANGED not called, got %d\n", font_dispids[i].dispid,
475 fonteventsdisp_invoke_called);
476 if (hr == S_OK)
478 ok(!lstrcmpW(font_dispids[i].name, fonteventsdisp_invoke_arg0), "dispid=%ld, got %s, expected %s\n",
479 font_dispids[i].dispid, wine_dbgstr_w(fonteventsdisp_invoke_arg0), wine_dbgstr_w(font_dispids[i].name));
480 SysFreeString(fonteventsdisp_invoke_arg0);
482 VariantClear(&vararg);
485 IFontDisp_Release(pFontDisp);
487 hr = IFont_Clone(pFont, &pFont2);
488 EXPECT_HR(hr, S_OK);
489 IFont_Release(pFont);
491 /* this test shows that the notification routine isn't called again */
492 fonteventsdisp_invoke_called = 0;
493 hr = IFont_put_Bold(pFont2, FALSE);
494 EXPECT_HR(hr, S_OK);
495 ok(fonteventsdisp_invoke_called == 0, "got %d\n", fonteventsdisp_invoke_called);
497 IFont_Release(pFont2);
500 static void test_names_ids(WCHAR* w_name_1, const char* a_name_1,
501 WCHAR* w_name_2, const char* a_name_2,
502 LCID lcid, DISPID id_1, DISPID id_2,
503 HRESULT hres_expect, int numnames)
505 LPVOID pvObj = NULL;
506 IFontDisp *fontdisp = NULL;
507 HRESULT hres;
508 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
509 LPOLESTR names[2] = {w_name_1, w_name_2};
511 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
512 fontdisp = pvObj;
514 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
515 lcid, rgDispId);
517 /* test hres */
518 ok(hres == hres_expect,
519 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08lx, expected 0x%08lx.\n",
520 a_name_1, a_name_2, hres, hres_expect);
522 /* test first DISPID */
523 ok(rgDispId[0]==id_1,
524 "GetIDsOfNames: \"%s\" gets DISPID 0x%08lx, expected 0x%08lx.\n",
525 a_name_1, rgDispId[0], id_1);
527 /* test second DISPID is present */
528 if (numnames == 2)
530 ok(rgDispId[1]==id_2,
531 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08lx, expected 0x%08lx.\n",
532 a_name_2, rgDispId[1], id_2);
535 IFontDisp_Release(fontdisp);
538 static void test_GetIDsOfNames(void)
540 WCHAR name_Name[] = {'N','a','m','e',0};
541 WCHAR name_Italic[] = {'I','t','a','l','i','c',0};
542 WCHAR name_Size[] = {'S','i','z','e',0};
543 WCHAR name_Bold[] = {'B','o','l','d',0};
544 WCHAR name_Underline[] = {'U','n','d','e','r','l','i','n','e',0};
545 WCHAR name_Strikethrough[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
546 WCHAR name_Weight[] = {'W','e','i','g','h','t',0};
547 WCHAR name_Charset[] = {'C','h','a','r','s','e','t',0};
548 WCHAR name_Foo[] = {'F','o','o',0};
549 WCHAR name_nAmE[] = {'n','A','m','E',0};
550 WCHAR name_Nom[] = {'N','o','m',0};
552 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
553 SORT_DEFAULT);
554 LCID fr_fr = MAKELCID(MAKELANGID(LANG_FRENCH,SUBLANG_FRENCH),
555 SORT_DEFAULT);
557 /* Test DISPID_FONTs for the various properties. */
558 test_names_ids(name_Name, "Name", NULL, "", en_us,
559 DISPID_FONT_NAME, 0, S_OK,1);
560 test_names_ids(name_Size, "Size", NULL, "", en_us,
561 DISPID_FONT_SIZE, 0, S_OK,1);
562 test_names_ids(name_Bold, "Bold", NULL, "", en_us,
563 DISPID_FONT_BOLD, 0, S_OK,1);
564 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
565 DISPID_FONT_ITALIC, 0, S_OK,1);
566 test_names_ids(name_Underline, "Underline", NULL, "", en_us,
567 DISPID_FONT_UNDER, 0, S_OK,1);
568 test_names_ids(name_Strikethrough, "Strikethrough", NULL, "", en_us,
569 DISPID_FONT_STRIKE, 0, S_OK,1);
570 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
571 DISPID_FONT_WEIGHT, 0, S_OK,1);
572 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
573 DISPID_FONT_CHARSET, 0, S_OK,1);
575 /* Capitalization doesn't matter. */
576 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
577 DISPID_FONT_NAME, 0, S_OK,1);
579 /* Unknown name. */
580 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
581 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
583 /* Pass several names: first is processed, */
584 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
585 test_names_ids(name_Italic, "Italic", name_Name, "Name", en_us,
586 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
587 test_names_ids(name_Italic, "Italic", name_Foo, "Foo", en_us,
588 DISPID_FONT_ITALIC, DISPID_UNKNOWN, S_OK,2);
590 /* Locale ID has no effect. */
591 test_names_ids(name_Name, "Name", NULL, "", fr_fr,
592 DISPID_FONT_NAME, 0, S_OK,1);
593 test_names_ids(name_Nom, "This is not a font", NULL, "", fr_fr,
594 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
596 /* One of the arguments are invalid */
597 test_names_ids(name_Name, "Name", NULL, "", en_us,
598 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
599 test_names_ids(name_Italic, "Italic", NULL, "", en_us,
600 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
601 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
602 0xdeadbeef, 0xdeadbeef, E_INVALIDARG,0);
604 /* Crazy locale ID? */
605 test_names_ids(name_Name, "Name", NULL, "", -1,
606 DISPID_FONT_NAME, 0, S_OK,1);
609 static void test_Invoke(void)
611 IFontDisp *fontdisp;
612 HRESULT hr;
613 VARIANTARG vararg;
614 DISPPARAMS dispparams;
615 VARIANT varresult;
617 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
618 EXPECT_HR(hr, S_OK);
620 V_VT(&vararg) = VT_BOOL;
621 V_BOOL(&vararg) = VARIANT_FALSE;
622 dispparams.cNamedArgs = 0;
623 dispparams.rgdispidNamedArgs = NULL;
624 dispparams.cArgs = 1;
625 dispparams.rgvarg = &vararg;
626 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_IFontDisp, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
627 EXPECT_HR(hr, DISP_E_UNKNOWNINTERFACE);
629 dispparams.cArgs = 0;
630 dispparams.rgvarg = NULL;
631 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
632 EXPECT_HR(hr, DISP_E_BADPARAMCOUNT);
634 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
635 EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
637 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
638 EXPECT_HR(hr, DISP_E_PARAMNOTOPTIONAL);
640 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
641 EXPECT_HR(hr, S_OK);
643 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
644 EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
646 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
647 EXPECT_HR(hr, DISP_E_MEMBERNOTFOUND);
649 dispparams.cArgs = 1;
650 dispparams.rgvarg = &vararg;
651 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
652 EXPECT_HR(hr, S_OK);
654 IFontDisp_Release(fontdisp);
657 static void test_IsEqual(void)
659 FONTDESC fd;
660 IFont* ifnt = NULL;
661 IFont* ifnt2 = NULL;
662 HRESULT hres;
664 /* Basic font description */
665 fd.cbSizeofstruct = sizeof(FONTDESC);
666 fd.lpstrName = system_font;
667 S(fd.cySize).Lo = 100;
668 S(fd.cySize).Hi = 100;
669 fd.sWeight = 0;
670 fd.sCharset = 0;
671 fd.fItalic = FALSE;
672 fd.fUnderline = FALSE;
673 fd.fStrikethrough = FALSE;
675 /* Create font */
676 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);
678 /* Test equal fonts */
679 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
680 hres = IFont_IsEqual(ifnt,ifnt2);
681 ok(hres == S_OK,
682 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08lx\n",hres);
683 IFont_Release(ifnt2);
685 /* Check for bad pointer */
686 hres = IFont_IsEqual(ifnt,NULL);
687 ok(hres == E_POINTER,
688 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08lx\n",hres);
690 /* Test strName */
691 fd.lpstrName = arial_font;
692 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
693 hres = IFont_IsEqual(ifnt,ifnt2);
694 ok(hres == S_FALSE,
695 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08lx\n",hres);
696 fd.lpstrName = system_font;
697 IFont_Release(ifnt2);
699 /* Test lo font size */
700 S(fd.cySize).Lo = 10000;
701 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
702 hres = IFont_IsEqual(ifnt,ifnt2);
703 ok(hres == S_FALSE,
704 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08lx\n",hres);
705 S(fd.cySize).Lo = 100;
706 IFont_Release(ifnt2);
708 /* Test hi font size */
709 S(fd.cySize).Hi = 10000;
710 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
711 hres = IFont_IsEqual(ifnt,ifnt2);
712 ok(hres == S_FALSE,
713 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08lx\n",hres);
714 S(fd.cySize).Hi = 100;
715 IFont_Release(ifnt2);
717 /* Test font weight */
718 fd.sWeight = 100;
719 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
720 hres = IFont_IsEqual(ifnt,ifnt2);
721 ok(hres == S_FALSE,
722 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08lx\n",hres);
723 fd.sWeight = 0;
724 IFont_Release(ifnt2);
726 /* Test charset */
727 fd.sCharset = 1;
728 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
729 hres = IFont_IsEqual(ifnt,ifnt2);
730 ok(hres == S_FALSE,
731 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08lx\n",hres);
732 fd.sCharset = 0;
733 IFont_Release(ifnt2);
735 /* Test italic setting */
736 fd.fItalic = TRUE;
737 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
738 hres = IFont_IsEqual(ifnt,ifnt2);
739 ok(hres == S_FALSE,
740 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08lx\n",hres);
741 fd.fItalic = FALSE;
742 IFont_Release(ifnt2);
744 /* Test underline setting */
745 fd.fUnderline = TRUE;
746 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
747 hres = IFont_IsEqual(ifnt,ifnt2);
748 ok(hres == S_FALSE,
749 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08lx\n",hres);
750 fd.fUnderline = FALSE;
751 IFont_Release(ifnt2);
753 /* Test strikethrough setting */
754 fd.fStrikethrough = TRUE;
755 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
756 hres = IFont_IsEqual(ifnt,ifnt2);
757 ok(hres == S_FALSE,
758 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08lx\n",hres);
759 fd.fStrikethrough = FALSE;
760 IFont_Release(ifnt2);
762 /* Free IFont. */
763 IFont_Release(ifnt);
766 static void test_ReleaseHfont(void)
768 FONTDESC fd;
769 LPVOID pvObj1 = NULL;
770 LPVOID pvObj2 = NULL;
771 IFont* ifnt1 = NULL;
772 IFont* ifnt2 = NULL;
773 HFONT hfnt1 = 0;
774 HFONT hfnt2 = 0;
775 HRESULT hres;
777 /* Basic font description */
778 fd.cbSizeofstruct = sizeof(FONTDESC);
779 fd.lpstrName = system_font;
780 S(fd.cySize).Lo = 100;
781 S(fd.cySize).Hi = 100;
782 fd.sWeight = 0;
783 fd.sCharset = 0;
784 fd.fItalic = FALSE;
785 fd.fUnderline = FALSE;
786 fd.fStrikethrough = FALSE;
788 /* Create HFONTs and IFONTs */
789 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
790 ifnt1 = pvObj1;
791 IFont_get_hFont(ifnt1,&hfnt1);
792 fd.lpstrName = arial_font;
793 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
794 ifnt2 = pvObj2;
795 IFont_get_hFont(ifnt2,&hfnt2);
797 /* Try invalid HFONT */
798 hres = IFont_ReleaseHfont(ifnt1,NULL);
799 ok(hres == E_INVALIDARG,
800 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08lx\n",
801 hres);
803 /* Try to add a bad HFONT */
804 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
805 ok(hres == S_FALSE,
806 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
807 hres);
809 /* Release all refs */
810 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
811 ok(hres == S_OK,
812 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
813 hres);
815 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
816 ok(hres == S_OK,
817 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
818 hres);
820 /* Check that both lists are empty */
821 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
822 ok(hres == S_FALSE,
823 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
824 hres);
826 /* The list should be empty */
827 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
828 ok(hres == S_FALSE,
829 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
830 hres);
832 IFont_Release(ifnt1);
833 IFont_Release(ifnt2);
836 static void test_AddRefHfont(void)
838 FONTDESC fd;
839 IFont* ifnt1 = NULL;
840 IFont* ifnt2 = NULL;
841 IFont* ifnt3 = NULL;
842 HFONT hfnt1 = 0;
843 HFONT hfnt2 = 0;
844 HFONT hfnt3 = 0;
845 HRESULT hres;
847 /* Basic font description */
848 fd.cbSizeofstruct = sizeof(FONTDESC);
849 fd.lpstrName = system_font;
850 S(fd.cySize).Lo = 100;
851 S(fd.cySize).Hi = 100;
852 fd.sWeight = 0;
853 fd.sCharset = 0;
854 fd.fItalic = FALSE;
855 fd.fUnderline = FALSE;
856 fd.fStrikethrough = FALSE;
858 /* Create HFONTs and IFONTs */
859 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
860 IFont_get_hFont(ifnt1,&hfnt1);
861 fd.lpstrName = arial_font;
862 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
863 IFont_get_hFont(ifnt2,&hfnt2);
865 /* Try invalid HFONT */
866 hres = IFont_AddRefHfont(ifnt1,NULL);
867 ok(hres == E_INVALIDARG,
868 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08lx\n",
869 hres);
871 /* Try to add a bad HFONT */
872 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
873 ok(hres == S_FALSE,
874 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
875 hres);
877 /* Add simple IFONT HFONT pair */
878 hres = IFont_AddRefHfont(ifnt1,hfnt1);
879 ok(hres == S_OK,
880 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
881 hres);
883 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
884 hres = IFont_AddRefHfont(ifnt2,hfnt1);
885 ok(hres == S_OK,
886 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
887 hres);
889 /* Release all hfnt1 refs */
890 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
891 ok(hres == S_OK,
892 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
893 hres);
895 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
896 ok(hres == S_OK,
897 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
898 hres);
900 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
901 ok(hres == S_OK,
902 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
903 hres);
905 /* Check if hfnt1 is empty */
906 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
907 ok(hres == S_FALSE,
908 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
909 hres);
911 /* Release all hfnt2 refs */
912 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
913 ok(hres == S_OK,
914 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
915 hres);
917 /* Check if hfnt2 is empty */
918 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
919 ok(hres == S_FALSE,
920 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
921 hres);
923 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
925 IFont_Release(ifnt1);
927 /* Add a reference for destroyed hfnt1 */
928 hres = IFont_AddRefHfont(ifnt2,hfnt1);
929 ok(hres == S_OK,
930 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
931 hres);
933 /* Decrement reference for destroyed hfnt1 */
934 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
935 ok(hres == S_OK ||
936 hres == S_FALSE, /* <= win2k */
937 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08lx\n",
938 hres);
940 /* Shows that releasing all IFONT's does clear the HFONT cache. */
942 IFont_Release(ifnt2);
944 /* Need to make a new IFONT for testing */
945 fd.fUnderline = TRUE;
946 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
947 IFont_get_hFont(ifnt3,&hfnt3);
949 /* Add a reference for destroyed hfnt1 */
950 hres = IFont_AddRefHfont(ifnt3,hfnt1);
951 ok(hres == S_FALSE,
952 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
953 hres);
955 /* Decrement reference for destroyed hfnt1 */
956 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
957 ok(hres == S_FALSE,
958 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
959 hres);
961 IFont_Release(ifnt3);
964 static void test_returns(void)
966 IFont *pFont;
967 FONTDESC fontdesc;
968 HRESULT hr;
970 fontdesc.cbSizeofstruct = sizeof(fontdesc);
971 fontdesc.lpstrName = MSSansSerif_font;
972 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
973 fontdesc.sWeight = FW_NORMAL;
974 fontdesc.sCharset = 0;
975 fontdesc.fItalic = FALSE;
976 fontdesc.fUnderline = FALSE;
977 fontdesc.fStrikethrough = FALSE;
979 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
980 EXPECT_HR(hr, S_OK);
982 hr = IFont_put_Name(pFont, NULL);
983 EXPECT_HR(hr, CTL_E_INVALIDPROPERTYVALUE);
985 hr = IFont_get_Name(pFont, NULL);
986 EXPECT_HR(hr, E_POINTER);
988 hr = IFont_get_Size(pFont, NULL);
989 EXPECT_HR(hr, E_POINTER);
991 hr = IFont_get_Bold(pFont, NULL);
992 EXPECT_HR(hr, E_POINTER);
994 IFont_Release(pFont);
997 static void test_hfont_lifetime(void)
999 IFont *font, *font2;
1000 FONTDESC fontdesc;
1001 HRESULT hr;
1002 HFONT hfont, first_hfont = NULL;
1003 CY size;
1004 DWORD obj_type;
1005 int i;
1007 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1008 fontdesc.lpstrName = arial_font;
1009 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1010 fontdesc.sWeight = FW_NORMAL;
1011 fontdesc.sCharset = ANSI_CHARSET;
1012 fontdesc.fItalic = FALSE;
1013 fontdesc.fUnderline = FALSE;
1014 fontdesc.fStrikethrough = FALSE;
1016 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1017 EXPECT_HR(hr, S_OK);
1019 hr = IFont_get_hFont(font, &hfont);
1020 EXPECT_HR(hr, S_OK);
1022 /* show that if the font is updated the old hfont is deleted when the
1023 new font is realized */
1024 for(i = 0; i < 100; i++)
1026 HFONT last_hfont = hfont;
1028 size.int64 = (i + 10) * 20000;
1030 obj_type = GetObjectType(hfont);
1031 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1033 hr = IFont_put_Size(font, size);
1034 EXPECT_HR(hr, S_OK);
1036 /* put_Size doesn't cause the new font to be realized */
1037 obj_type = GetObjectType(last_hfont);
1038 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1040 hr = IFont_get_hFont(font, &hfont);
1041 EXPECT_HR(hr, S_OK);
1044 /* now show that if we take a reference on the hfont, it persists
1045 until the font object is released */
1046 for(i = 0; i < 100; i++)
1048 size.int64 = (i + 10) * 20000;
1050 obj_type = GetObjectType(hfont);
1051 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1053 hr = IFont_put_Size(font, size);
1054 EXPECT_HR(hr, S_OK);
1056 hr = IFont_get_hFont(font, &hfont);
1057 EXPECT_HR(hr, S_OK);
1059 hr = IFont_AddRefHfont(font, hfont);
1060 EXPECT_HR(hr, S_OK);
1062 if(i == 0) first_hfont = hfont;
1063 obj_type = GetObjectType(first_hfont);
1064 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1067 IFont_Release(font);
1069 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
1070 through re-realization */
1072 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1073 EXPECT_HR(hr, S_OK);
1075 hr = IFont_get_hFont(font, &hfont);
1076 EXPECT_HR(hr, S_OK);
1078 for(i = 0; i < 100; i++)
1080 HFONT last_hfont = hfont;
1082 size.int64 = (i + 10) * 20000;
1084 obj_type = GetObjectType(hfont);
1085 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1087 hr = IFont_put_Size(font, size);
1088 EXPECT_HR(hr, S_OK);
1090 /* put_Size doesn't cause the new font to be realized */
1091 obj_type = GetObjectType(last_hfont);
1092 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1094 hr = IFont_get_hFont(font, &hfont);
1095 EXPECT_HR(hr, S_OK);
1097 hr = IFont_AddRefHfont(font, hfont);
1098 EXPECT_HR(hr, S_OK);
1100 hr = IFont_ReleaseHfont(font, hfont);
1101 EXPECT_HR(hr, S_OK);
1104 /* Interestingly if we release a nonexistent reference on the hfont,
1105 * it persists until the font object is released
1107 for(i = 0; i < 100; i++)
1109 size.int64 = (i + 10) * 20000;
1111 obj_type = GetObjectType(hfont);
1112 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1114 hr = IFont_put_Size(font, size);
1115 EXPECT_HR(hr, S_OK);
1117 hr = IFont_get_hFont(font, &hfont);
1118 EXPECT_HR(hr, S_OK);
1120 hr = IFont_ReleaseHfont(font, hfont);
1121 EXPECT_HR(hr, S_OK);
1123 if(i == 0) first_hfont = hfont;
1124 obj_type = GetObjectType(first_hfont);
1125 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1128 IFont_Release(font);
1130 /* If we take two internal references on a hfont then we can release
1131 it twice. So it looks like there's a total reference count
1132 that includes internal and external references */
1134 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1135 EXPECT_HR(hr, S_OK);
1136 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
1137 EXPECT_HR(hr, S_OK);
1139 hr = IFont_get_hFont(font, &hfont);
1140 EXPECT_HR(hr, S_OK);
1141 hr = IFont_get_hFont(font2, &first_hfont);
1142 EXPECT_HR(hr, S_OK);
1143 todo_wine
1144 ok(hfont == first_hfont, "fonts differ\n");
1145 hr = IFont_ReleaseHfont(font, hfont);
1146 EXPECT_HR(hr, S_OK);
1147 hr = IFont_ReleaseHfont(font, hfont);
1148 todo_wine
1149 EXPECT_HR(hr, S_OK);
1150 hr = IFont_ReleaseHfont(font, hfont);
1151 EXPECT_HR(hr, S_FALSE);
1153 obj_type = GetObjectType(hfont);
1154 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1156 IFont_Release(font);
1158 obj_type = GetObjectType(hfont);
1159 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1161 IFont_Release(font2);
1164 static void test_realization(void)
1166 IFont *font;
1167 FONTDESC fontdesc;
1168 HRESULT hr;
1169 BSTR name;
1170 SHORT cs;
1172 /* Try to create a symbol only font (marlett) with charset
1173 set to ANSI. This will result in another, ANSI, font
1174 being selected */
1175 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1176 fontdesc.lpstrName = marlett_font;
1177 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1178 fontdesc.sWeight = FW_NORMAL;
1179 fontdesc.sCharset = ANSI_CHARSET;
1180 fontdesc.fItalic = FALSE;
1181 fontdesc.fUnderline = FALSE;
1182 fontdesc.fStrikethrough = FALSE;
1184 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1185 EXPECT_HR(hr, S_OK);
1187 hr = IFont_get_Charset(font, &cs);
1188 EXPECT_HR(hr, S_OK);
1189 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1191 IFont_Release(font);
1193 /* Now create an ANSI font and change the name to marlett */
1195 fontdesc.lpstrName = arial_font;
1197 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1198 EXPECT_HR(hr, S_OK);
1200 hr = IFont_get_Charset(font, &cs);
1201 EXPECT_HR(hr, S_OK);
1202 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1204 name = SysAllocString(marlett_font);
1205 hr = IFont_put_Name(font, name);
1206 EXPECT_HR(hr, S_OK);
1207 SysFreeString(name);
1209 hr = IFont_get_Name(font, &name);
1210 EXPECT_HR(hr, S_OK);
1211 ok(!lstrcmpiW(name, marlett_font), "got name %s\n", wine_dbgstr_w(name));
1212 SysFreeString(name);
1214 hr = IFont_get_Charset(font, &cs);
1215 EXPECT_HR(hr, S_OK);
1216 ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);
1218 IFont_Release(font);
1221 static void test_OleCreateFontIndirect(void)
1223 FONTDESC fontdesc;
1224 IUnknown *unk, *unk2;
1225 IFont *font;
1226 HRESULT hr;
1228 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1229 fontdesc.lpstrName = arial_font;
1230 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1231 fontdesc.sWeight = FW_NORMAL;
1232 fontdesc.sCharset = ANSI_CHARSET;
1233 fontdesc.fItalic = FALSE;
1234 fontdesc.fUnderline = FALSE;
1235 fontdesc.fStrikethrough = FALSE;
1237 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1238 EXPECT_HR(hr, S_OK);
1239 IFont_Release(font);
1241 /* play with cbSizeofstruct value */
1242 fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
1243 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1244 EXPECT_HR(hr, S_OK);
1245 IFont_Release(font);
1247 fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
1248 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1249 EXPECT_HR(hr, S_OK);
1250 IFont_Release(font);
1252 fontdesc.cbSizeofstruct = 0;
1253 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1254 EXPECT_HR(hr, S_OK);
1255 IFont_Release(font);
1257 hr = OleInitialize(NULL);
1258 ok(hr == S_OK, "got 0x%08lx\n", hr);
1260 hr = CoGetClassObject(&CLSID_StdFont, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&unk);
1261 ok(hr == S_OK, "got 0x%08lx\n", hr);
1263 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void**)&unk2);
1264 ok(hr == S_OK, "got 0x%08lx\n", hr);
1266 IUnknown_Release(unk);
1267 IUnknown_Release(unk2);
1269 OleUninitialize();
1272 START_TEST(olefont)
1274 hOleaut32 = GetModuleHandleA("oleaut32.dll");
1275 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
1276 if (!pOleCreateFontIndirect)
1278 win_skip("OleCreateFontIndirect not available\n");
1279 return;
1282 test_interfaces();
1283 test_type_info();
1284 test_ifont_sizes();
1285 test_font_events_disp();
1286 test_GetIDsOfNames();
1287 test_Invoke();
1288 test_IsEqual();
1289 test_ReleaseHfont();
1290 test_AddRefHfont();
1291 test_returns();
1292 test_hfont_lifetime();
1293 test_realization();
1294 test_OleCreateFontIndirect();