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
25 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
27 static WCHAR MSSansSerif_font
[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
28 static WCHAR system_font
[] = { 'S','y','s','t','e','m',0 };
29 static WCHAR arial_font
[] = { 'A','r','i','a','l',0 };
30 static WCHAR marlett_font
[] = { 'M','a','r','l','e','t','t',0 };
32 static HMODULE hOleaut32
;
34 static HRESULT (WINAPI
*pOleCreateFontIndirect
)(LPFONTDESC
,REFIID
,LPVOID
*);
36 #define EXPECT_HR(hr,hr_exp) \
37 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
39 /* Create a font with cySize given by lo_size, hi_size, */
40 /* SetRatio to ratio_logical, ratio_himetric, */
41 /* check that resulting hfont has height hfont_height. */
42 /* Various checks along the way. */
43 static void test_ifont_size(LONGLONG size
, LONG ratio_logical
, LONG ratio_himetric
,
44 LONG hfont_height
, const char * test_name
)
55 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
56 fd
.lpstrName
= arial_font
; /* using scalable instead of bitmap font reduces errors due to font realization */
57 fd
.cySize
.int64
= size
;
61 fd
.fUnderline
= FALSE
;
62 fd
.fStrikethrough
= FALSE
;
64 /* Create font, test that it worked. */
65 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
67 ok(hres
== S_OK
,"%s: OCFI returns 0x%08x instead of S_OK.\n",
69 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
71 /* Change the scaling ratio */
72 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
73 ok((ratio_logical
&& ratio_himetric
) ? hres
== S_OK
: hres
== E_FAIL
,
74 "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name
, hres
);
77 hres
= IFont_get_Size(ifnt
, &psize
);
78 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
81 /* Check returned size - allow for errors due to rounding & font realization. */
82 ok((psize
.int64
- size
) < 10000 && (psize
.int64
- size
) > -10000,
83 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
84 test_name
, S(psize
).Lo
, S(psize
).Hi
, fd
.cySize
.Lo
, fd
.cySize
.Hi
);
86 /* Check hFont size. */
87 hres
= IFont_get_hFont (ifnt
, &hfont
);
88 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
90 rtnval
= GetObjectA(hfont
, sizeof(LOGFONTA
), &lf
);
91 ok(rtnval
> 0, "GetObject(hfont) failed\n");
93 /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
94 ok(abs(lf
.lfHeight
- hfont_height
) <= 1,
95 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
96 test_name
, lf
.lfHeight
, hfont_height
);
102 static void test_ifont_sizes(void)
104 /* Test various size operations and conversions. */
105 /* Add more as needed. */
107 /* Results of first 2 tests depend on display resolution. */
109 LONG dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
); /* expected results depend on display DPI */
111 if(dpi
== 96) /* normal resolution display */
113 test_ifont_size(180000, 0, 0, -24, "default"); /* normal font */
114 test_ifont_size(186000, 0, 0, -25, "rounding"); /* test rounding */
115 } else if(dpi
== 72) /* low resolution display */
117 test_ifont_size(180000, 0, 0, -18, "default"); /* normal font */
118 test_ifont_size(186000, 0, 0, -19, "rounding"); /* test rounding */
119 } else if(dpi
== 120) /* high resolution display */
121 test_ifont_size(180000, 0, 0, -30, "default"); /* normal font */
122 test_ifont_size(186000, 0, 0, -31, "rounding"); /* test rounding */
124 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi
);
126 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
127 test_ifont_size(180000, 72, 2540, -18, "ratio1"); /* change ratio */
128 test_ifont_size(180000, 144, 2540, -36, "ratio2"); /* another ratio */
129 test_ifont_size(180000, 72, 1270, -36, "ratio3"); /* yet another ratio */
130 test_ifont_size(186000, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
132 /* test various combinations of logical == himetric */
133 test_ifont_size(180000, 10, 10, -635, "identical ratio 1");
134 test_ifont_size(240000, 10, 10, -848, "identical ratio 2");
135 test_ifont_size(300000, 10, 10, -1058, "identical ratio 3");
137 /* test various combinations of logical and himetric both set to 1 */
138 test_ifont_size(180000, 1, 1, -24, "1:1 ratio 1");
139 test_ifont_size(240000, 1, 1, -32, "1:1 ratio 2");
140 test_ifont_size(300000, 1, 1, -40, "1:1 ratio 3");
142 /* test various combinations of logical set to 1 */
143 test_ifont_size(180000, 1, 0, -24, "1:0 ratio 1");
144 test_ifont_size(240000, 1, 0, -32, "1:0 ratio 2");
145 test_ifont_size(300000, 1, 0, -40, "1:0 ratio 3");
147 /* test various combinations of himetric set to 1 */
148 test_ifont_size(180000, 0, 1, -24, "0:1 ratio 1");
149 test_ifont_size(240000, 0, 1, -32, "0:1 ratio 2");
150 test_ifont_size(300000, 0, 1, -40, "0:1 ratio 3");
152 /* test various combinations of 2:1 logical:himetric */
153 test_ifont_size(180000, 2, 1, -1270, "2:1 ratio 1");
154 test_ifont_size(240000, 2, 1, -1694, "2:1 ratio 2");
155 test_ifont_size(300000, 2, 1, -2117, "2:1 ratio 3");
157 /* test various combinations of 1:2 logical:himetric */
158 test_ifont_size(180000, 1, 2, -318, "1:2 ratio 1");
159 test_ifont_size(240000, 1, 2, -424, "1:2 ratio 2");
160 test_ifont_size(300000, 1, 2, -529, "1:2 ratio 3");
162 /* test various combinations of logical and himetric both set to 2 */
163 test_ifont_size(180000, 2, 2, -635, "2:2 ratio 1");
164 test_ifont_size(240000, 2, 2, -848, "2:2 ratio 2");
165 test_ifont_size(300000, 2, 2, -1058, "2:2 ratio 3");
168 static void test_QueryInterface(void)
175 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
176 EXPECT_HR(hr
, E_POINTER
);
178 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
182 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
185 hr
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
188 /* Test if QueryInterface increments ref counter for IFONTs */
189 ref
= IFont_AddRef(font
);
191 broken(ref
== 1), /* win95 */
192 "IFont_QI expected ref value 3 but instead got %d\n", ref
);
195 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
201 static void test_type_info(void)
205 IFontDisp
* fontdisp
= NULL
;
207 WCHAR name_Name
[] = {'N','a','m','e',0};
210 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
212 DISPPARAMS dispparams
;
215 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
218 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
219 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
220 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
222 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
223 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
224 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
225 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
226 SysFreeString(names
[0]);
228 ITypeInfo_Release(pTInfo
);
230 dispparams
.cNamedArgs
= 0;
231 dispparams
.rgdispidNamedArgs
= NULL
;
232 dispparams
.cArgs
= 0;
233 dispparams
.rgvarg
= NULL
;
234 VariantInit(&varresult
);
235 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
236 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
238 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
239 VariantClear(&varresult
);
241 IFontDisp_Release(fontdisp
);
244 static HRESULT WINAPI
FontEventsDisp_QueryInterface(IFontEventsDisp
*iface
, REFIID riid
, void **ppvObject
)
246 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
248 IFontEventsDisp_AddRef(iface
);
255 return E_NOINTERFACE
;
259 static ULONG WINAPI
FontEventsDisp_AddRef(
260 IFontEventsDisp
*iface
)
265 static ULONG WINAPI
FontEventsDisp_Release(
266 IFontEventsDisp
*iface
)
271 static HRESULT WINAPI
FontEventsDisp_GetTypeInfoCount(IFontEventsDisp
*iface
, UINT
*pctinfo
)
273 ok(0, "unexpected call\n");
277 static HRESULT WINAPI
FontEventsDisp_GetTypeInfo(IFontEventsDisp
*iface
, UINT itinfo
, LCID lcid
, ITypeInfo
**pptinfo
)
279 ok(0, "unexpected call\n");
283 static HRESULT WINAPI
FontEventsDisp_GetIDsOfNames(IFontEventsDisp
*iface
, REFIID riid
, LPOLESTR
*names
, UINT cNames
, LCID lcid
,
286 ok(0, "unexpected call\n");
290 static int fonteventsdisp_invoke_called
;
291 static BSTR fonteventsdisp_invoke_arg0
;
293 static HRESULT WINAPI
FontEventsDisp_Invoke(
294 IFontEventsDisp
*iface
,
299 DISPPARAMS
*pDispParams
,
301 EXCEPINFO
*pExcepInfo
,
304 VARIANTARG
*arg0
= &pDispParams
->rgvarg
[0];
306 ok(dispid
== DISPID_FONT_CHANGED
, "expected DISPID_FONT_CHANGED instead of 0x%x\n", dispid
);
307 ok(IsEqualGUID(riid
, &GUID_NULL
), "got riid %s\n", wine_dbgstr_guid(riid
));
308 ok(wFlags
== INVOKE_FUNC
, "expected INVOKE_FUNC instead of 0x%x\n", wFlags
);
309 ok(pDispParams
->cArgs
== 1, "expected arg count 1, got %d\n", pDispParams
->cArgs
);
310 ok(V_VT(arg0
) == VT_BSTR
, "expected VT_BSTR, got %d\n", V_VT(arg0
));
312 fonteventsdisp_invoke_arg0
= SysAllocString(V_BSTR(arg0
));
313 fonteventsdisp_invoke_called
++;
317 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
319 FontEventsDisp_QueryInterface
,
320 FontEventsDisp_AddRef
,
321 FontEventsDisp_Release
,
322 FontEventsDisp_GetTypeInfoCount
,
323 FontEventsDisp_GetTypeInfo
,
324 FontEventsDisp_GetIDsOfNames
,
325 FontEventsDisp_Invoke
328 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
336 static void test_font_events_disp(void)
338 static const WCHAR nameW
[] = {'N','a','m','e',0};
339 static const WCHAR sizeW
[] = {'S','i','z','e',0};
340 static const WCHAR boldW
[] = {'B','o','l','d',0};
341 static const WCHAR italicW
[] = {'I','t','a','l','i','c',0};
342 static const WCHAR underlineW
[] = {'U','n','d','e','r','l','i','n','e',0};
343 static const WCHAR strikeW
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
344 static const WCHAR weightW
[] = {'W','e','i','g','h','t',0};
345 static const WCHAR charsetW
[] = {'C','h','a','r','s','e','t',0};
347 static const struct font_dispid font_dispids
[] =
349 { DISPID_FONT_NAME
, nameW
},
350 { DISPID_FONT_SIZE
, sizeW
},
351 { DISPID_FONT_BOLD
, boldW
},
352 { DISPID_FONT_ITALIC
, italicW
},
353 { DISPID_FONT_UNDER
, underlineW
},
354 { DISPID_FONT_STRIKE
, strikeW
},
355 { DISPID_FONT_WEIGHT
, weightW
},
356 { DISPID_FONT_CHARSET
, charsetW
}
361 IConnectionPointContainer
*pCPC
;
362 IConnectionPoint
*pCP
;
366 IFontDisp
*pFontDisp
;
367 DISPPARAMS dispparams
;
371 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
372 fontdesc
.lpstrName
= MSSansSerif_font
;
373 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
374 fontdesc
.sWeight
= FW_NORMAL
;
375 fontdesc
.sCharset
= 0;
376 fontdesc
.fItalic
= FALSE
;
377 fontdesc
.fUnderline
= FALSE
;
378 fontdesc
.fStrikethrough
= FALSE
;
380 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
383 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
386 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
388 IConnectionPointContainer_Release(pCPC
);
390 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
392 IConnectionPoint_Release(pCP
);
394 fonteventsdisp_invoke_called
= 0;
395 fonteventsdisp_invoke_arg0
= NULL
;
396 hr
= IFont_put_Bold(pFont
, TRUE
);
399 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
400 SysFreeString(fonteventsdisp_invoke_arg0
);
402 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
405 for (i
= 0; i
< sizeof(font_dispids
)/sizeof(font_dispids
[0]); i
++)
407 switch (font_dispids
[i
].dispid
)
409 case DISPID_FONT_NAME
:
411 static const WCHAR arialW
[] = {'A','r','i','a','l',0};
412 V_VT(&vararg
) = VT_BSTR
;
413 V_BSTR(&vararg
) = SysAllocString(arialW
);
416 case DISPID_FONT_SIZE
:
417 V_VT(&vararg
) = VT_CY
;
418 S(V_CY(&vararg
)).Lo
= 25;
419 S(V_CY(&vararg
)).Hi
= 0;
421 case DISPID_FONT_BOLD
:
422 V_VT(&vararg
) = VT_BOOL
;
423 V_BOOL(&vararg
) = VARIANT_FALSE
;
425 case DISPID_FONT_ITALIC
:
426 case DISPID_FONT_UNDER
:
427 case DISPID_FONT_STRIKE
:
428 V_VT(&vararg
) = VT_BOOL
;
429 V_BOOL(&vararg
) = VARIANT_TRUE
;
431 case DISPID_FONT_WEIGHT
:
432 V_VT(&vararg
) = VT_I2
;
433 V_I2(&vararg
) = FW_BLACK
;
435 case DISPID_FONT_CHARSET
:
436 V_VT(&vararg
) = VT_I2
;
443 dispparams
.cNamedArgs
= 0;
444 dispparams
.rgdispidNamedArgs
= NULL
;
445 dispparams
.cArgs
= 1;
446 dispparams
.rgvarg
= &vararg
;
447 fonteventsdisp_invoke_called
= 0;
448 hr
= IFontDisp_Invoke(pFontDisp
, font_dispids
[i
].dispid
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
449 ok(hr
== S_OK
, "dispid=%d, got 0x%08x\n", font_dispids
[i
].dispid
, hr
);
450 ok(fonteventsdisp_invoke_called
== 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids
[i
].dispid
,
451 fonteventsdisp_invoke_called
);
454 ok(!lstrcmpW(font_dispids
[i
].name
, fonteventsdisp_invoke_arg0
), "dispid=%d, got %s, expected %s\n",
455 font_dispids
[i
].dispid
, wine_dbgstr_w(fonteventsdisp_invoke_arg0
), wine_dbgstr_w(font_dispids
[i
].name
));
456 SysFreeString(fonteventsdisp_invoke_arg0
);
458 VariantClear(&vararg
);
461 IFontDisp_Release(pFontDisp
);
463 hr
= IFont_Clone(pFont
, &pFont2
);
465 IFont_Release(pFont
);
467 /* this test shows that the notification routine isn't called again */
468 fonteventsdisp_invoke_called
= 0;
469 hr
= IFont_put_Bold(pFont2
, FALSE
);
471 ok(fonteventsdisp_invoke_called
== 0, "got %d\n", fonteventsdisp_invoke_called
);
473 IFont_Release(pFont2
);
476 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
477 WCHAR
* w_name_2
, const char* a_name_2
,
478 LCID lcid
, DISPID id_1
, DISPID id_2
,
479 HRESULT hres_expect
, int numnames
)
482 IFontDisp
*fontdisp
= NULL
;
484 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
485 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
487 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
490 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
494 ok(hres
== hres_expect
,
495 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
496 a_name_1
, a_name_2
, hres
, hres_expect
);
498 /* test first DISPID */
499 ok(rgDispId
[0]==id_1
,
500 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
501 a_name_1
, rgDispId
[0], id_1
);
503 /* test second DISPID is present */
506 ok(rgDispId
[1]==id_2
,
507 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
508 a_name_2
, rgDispId
[1], id_2
);
511 IFontDisp_Release(fontdisp
);
514 static void test_GetIDsOfNames(void)
516 WCHAR name_Name
[] = {'N','a','m','e',0};
517 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
518 WCHAR name_Size
[] = {'S','i','z','e',0};
519 WCHAR name_Bold
[] = {'B','o','l','d',0};
520 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
521 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
522 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
523 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
524 WCHAR name_Foo
[] = {'F','o','o',0};
525 WCHAR name_nAmE
[] = {'n','A','m','E',0};
526 WCHAR name_Nom
[] = {'N','o','m',0};
528 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
530 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
533 /* Test DISPID_FONTs for the various properties. */
534 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
535 DISPID_FONT_NAME
, 0, S_OK
,1);
536 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
537 DISPID_FONT_SIZE
, 0, S_OK
,1);
538 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
539 DISPID_FONT_BOLD
, 0, S_OK
,1);
540 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
541 DISPID_FONT_ITALIC
, 0, S_OK
,1);
542 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
543 DISPID_FONT_UNDER
, 0, S_OK
,1);
544 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
545 DISPID_FONT_STRIKE
, 0, S_OK
,1);
546 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
547 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
548 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
549 DISPID_FONT_CHARSET
, 0, S_OK
,1);
551 /* Capitalization doesn't matter. */
552 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
553 DISPID_FONT_NAME
, 0, S_OK
,1);
556 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
557 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
559 /* Pass several names: first is processed, */
560 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
561 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
562 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
563 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
564 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
566 /* Locale ID has no effect. */
567 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
568 DISPID_FONT_NAME
, 0, S_OK
,1);
569 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
570 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
572 /* One of the arguments are invalid */
573 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
574 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
575 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
576 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
577 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
578 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
580 /* Crazy locale ID? */
581 test_names_ids(name_Name
, "Name", NULL
, "", -1,
582 DISPID_FONT_NAME
, 0, S_OK
,1);
585 static void test_Invoke(void)
590 DISPPARAMS dispparams
;
593 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
596 V_VT(&vararg
) = VT_BOOL
;
597 V_BOOL(&vararg
) = VARIANT_FALSE
;
598 dispparams
.cNamedArgs
= 0;
599 dispparams
.rgdispidNamedArgs
= NULL
;
600 dispparams
.cArgs
= 1;
601 dispparams
.rgvarg
= &vararg
;
602 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
603 EXPECT_HR(hr
, DISP_E_UNKNOWNINTERFACE
);
605 dispparams
.cArgs
= 0;
606 dispparams
.rgvarg
= NULL
;
607 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
608 EXPECT_HR(hr
, DISP_E_BADPARAMCOUNT
);
610 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
611 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
613 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
614 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
616 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
619 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
620 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
622 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
623 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
625 dispparams
.cArgs
= 1;
626 dispparams
.rgvarg
= &vararg
;
627 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
630 IFontDisp_Release(fontdisp
);
633 static void test_IsEqual(void)
640 /* Basic font description */
641 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
642 fd
.lpstrName
= system_font
;
643 S(fd
.cySize
).Lo
= 100;
644 S(fd
.cySize
).Hi
= 100;
648 fd
.fUnderline
= FALSE
;
649 fd
.fStrikethrough
= FALSE
;
652 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
654 /* Test equal fonts */
655 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
656 hres
= IFont_IsEqual(ifnt
,ifnt2
);
658 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
659 IFont_Release(ifnt2
);
661 /* Check for bad pointer */
662 hres
= IFont_IsEqual(ifnt
,NULL
);
663 ok(hres
== E_POINTER
,
664 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
667 fd
.lpstrName
= arial_font
;
668 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
669 hres
= IFont_IsEqual(ifnt
,ifnt2
);
671 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
672 fd
.lpstrName
= system_font
;
673 IFont_Release(ifnt2
);
675 /* Test lo font size */
676 S(fd
.cySize
).Lo
= 10000;
677 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
678 hres
= IFont_IsEqual(ifnt
,ifnt2
);
680 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
681 S(fd
.cySize
).Lo
= 100;
682 IFont_Release(ifnt2
);
684 /* Test hi font size */
685 S(fd
.cySize
).Hi
= 10000;
686 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
687 hres
= IFont_IsEqual(ifnt
,ifnt2
);
689 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
690 S(fd
.cySize
).Hi
= 100;
691 IFont_Release(ifnt2
);
693 /* Test font weight */
695 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
696 hres
= IFont_IsEqual(ifnt
,ifnt2
);
698 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
700 IFont_Release(ifnt2
);
704 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
705 hres
= IFont_IsEqual(ifnt
,ifnt2
);
707 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
709 IFont_Release(ifnt2
);
711 /* Test italic setting */
713 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
714 hres
= IFont_IsEqual(ifnt
,ifnt2
);
716 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
718 IFont_Release(ifnt2
);
720 /* Test underline setting */
721 fd
.fUnderline
= TRUE
;
722 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
723 hres
= IFont_IsEqual(ifnt
,ifnt2
);
725 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
726 fd
.fUnderline
= FALSE
;
727 IFont_Release(ifnt2
);
729 /* Test strikethrough setting */
730 fd
.fStrikethrough
= TRUE
;
731 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
732 hres
= IFont_IsEqual(ifnt
,ifnt2
);
734 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
735 fd
.fStrikethrough
= FALSE
;
736 IFont_Release(ifnt2
);
742 static void test_ReleaseHfont(void)
745 LPVOID pvObj1
= NULL
;
746 LPVOID pvObj2
= NULL
;
753 /* Basic font description */
754 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
755 fd
.lpstrName
= system_font
;
756 S(fd
.cySize
).Lo
= 100;
757 S(fd
.cySize
).Hi
= 100;
761 fd
.fUnderline
= FALSE
;
762 fd
.fStrikethrough
= FALSE
;
764 /* Create HFONTs and IFONTs */
765 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
767 IFont_get_hFont(ifnt1
,&hfnt1
);
768 fd
.lpstrName
= arial_font
;
769 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
771 IFont_get_hFont(ifnt2
,&hfnt2
);
773 /* Try invalid HFONT */
774 hres
= IFont_ReleaseHfont(ifnt1
,NULL
);
775 ok(hres
== E_INVALIDARG
,
776 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
779 /* Try to add a bad HFONT */
780 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
782 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
785 /* Release all refs */
786 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
788 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
791 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
793 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
796 /* Check that both lists are empty */
797 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
799 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
802 /* The list should be empty */
803 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
805 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
808 IFont_Release(ifnt1
);
809 IFont_Release(ifnt2
);
812 static void test_AddRefHfont(void)
823 /* Basic font description */
824 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
825 fd
.lpstrName
= system_font
;
826 S(fd
.cySize
).Lo
= 100;
827 S(fd
.cySize
).Hi
= 100;
831 fd
.fUnderline
= FALSE
;
832 fd
.fStrikethrough
= FALSE
;
834 /* Create HFONTs and IFONTs */
835 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt1
);
836 IFont_get_hFont(ifnt1
,&hfnt1
);
837 fd
.lpstrName
= arial_font
;
838 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
839 IFont_get_hFont(ifnt2
,&hfnt2
);
841 /* Try invalid HFONT */
842 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
843 ok(hres
== E_INVALIDARG
,
844 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
847 /* Try to add a bad HFONT */
848 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
850 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
853 /* Add simple IFONT HFONT pair */
854 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
856 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
859 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
860 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
862 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
865 /* Release all hfnt1 refs */
866 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
868 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
871 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
873 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
876 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
878 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
881 /* Check if hfnt1 is empty */
882 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
884 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
887 /* Release all hfnt2 refs */
888 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
890 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
893 /* Check if hfnt2 is empty */
894 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
896 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
899 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
901 IFont_Release(ifnt1
);
903 /* Add a reference for destroyed hfnt1 */
904 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
906 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
909 /* Decrement reference for destroyed hfnt1 */
910 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
912 hres
== S_FALSE
, /* <= win2k */
913 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
916 /* Shows that releasing all IFONT's does clear the HFONT cache. */
918 IFont_Release(ifnt2
);
920 /* Need to make a new IFONT for testing */
921 fd
.fUnderline
= TRUE
;
922 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
923 IFont_get_hFont(ifnt3
,&hfnt3
);
925 /* Add a reference for destroyed hfnt1 */
926 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
928 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
931 /* Decrement reference for destroyed hfnt1 */
932 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
934 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
937 IFont_Release(ifnt3
);
940 static void test_returns(void)
946 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
947 fontdesc
.lpstrName
= MSSansSerif_font
;
948 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
949 fontdesc
.sWeight
= FW_NORMAL
;
950 fontdesc
.sCharset
= 0;
951 fontdesc
.fItalic
= FALSE
;
952 fontdesc
.fUnderline
= FALSE
;
953 fontdesc
.fStrikethrough
= FALSE
;
955 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
958 hr
= IFont_put_Name(pFont
, NULL
);
959 EXPECT_HR(hr
, CTL_E_INVALIDPROPERTYVALUE
);
961 hr
= IFont_get_Name(pFont
, NULL
);
962 EXPECT_HR(hr
, E_POINTER
);
964 hr
= IFont_get_Size(pFont
, NULL
);
965 EXPECT_HR(hr
, E_POINTER
);
967 hr
= IFont_get_Bold(pFont
, NULL
);
968 EXPECT_HR(hr
, E_POINTER
);
970 IFont_Release(pFont
);
973 static void test_hfont_lifetime(void)
978 HFONT hfont
, first_hfont
= NULL
;
983 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
984 fontdesc
.lpstrName
= arial_font
;
985 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
986 fontdesc
.sWeight
= FW_NORMAL
;
987 fontdesc
.sCharset
= ANSI_CHARSET
;
988 fontdesc
.fItalic
= FALSE
;
989 fontdesc
.fUnderline
= FALSE
;
990 fontdesc
.fStrikethrough
= FALSE
;
992 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
995 hr
= IFont_get_hFont(font
, &hfont
);
998 /* show that if the font is updated the old hfont is deleted when the
999 new font is realized */
1000 for(i
= 0; i
< 100; i
++)
1002 HFONT last_hfont
= hfont
;
1004 size
.int64
= (i
+ 10) * 20000;
1006 obj_type
= GetObjectType(hfont
);
1007 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1009 hr
= IFont_put_Size(font
, size
);
1010 EXPECT_HR(hr
, S_OK
);
1012 /* put_Size doesn't cause the new font to be realized */
1013 obj_type
= GetObjectType(last_hfont
);
1014 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1016 hr
= IFont_get_hFont(font
, &hfont
);
1017 EXPECT_HR(hr
, S_OK
);
1019 obj_type
= GetObjectType(last_hfont
);
1020 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1023 /* now show that if we take a reference on the hfont, it persists
1024 until the font object is released */
1025 for(i
= 0; i
< 100; i
++)
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 hr
= IFont_get_hFont(font
, &hfont
);
1036 EXPECT_HR(hr
, S_OK
);
1038 hr
= IFont_AddRefHfont(font
, hfont
);
1039 EXPECT_HR(hr
, S_OK
);
1041 if(i
== 0) first_hfont
= hfont
;
1042 obj_type
= GetObjectType(first_hfont
);
1043 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1046 IFont_Release(font
);
1048 obj_type
= GetObjectType(first_hfont
);
1049 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1051 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
1052 through re-realization */
1054 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1055 EXPECT_HR(hr
, S_OK
);
1057 hr
= IFont_get_hFont(font
, &hfont
);
1058 EXPECT_HR(hr
, S_OK
);
1060 for(i
= 0; i
< 100; i
++)
1062 HFONT last_hfont
= hfont
;
1064 size
.int64
= (i
+ 10) * 20000;
1066 obj_type
= GetObjectType(hfont
);
1067 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1069 hr
= IFont_put_Size(font
, size
);
1070 EXPECT_HR(hr
, S_OK
);
1072 /* put_Size doesn't cause the new font to be realized */
1073 obj_type
= GetObjectType(last_hfont
);
1074 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1076 hr
= IFont_get_hFont(font
, &hfont
);
1077 EXPECT_HR(hr
, S_OK
);
1079 hr
= IFont_AddRefHfont(font
, hfont
);
1080 EXPECT_HR(hr
, S_OK
);
1082 hr
= IFont_ReleaseHfont(font
, hfont
);
1083 EXPECT_HR(hr
, S_OK
);
1085 obj_type
= GetObjectType(last_hfont
);
1086 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1089 /* Interestingly if we release a nonexistent reference on the hfont,
1090 * it persists until the font object is released
1092 for(i
= 0; i
< 100; i
++)
1094 size
.int64
= (i
+ 10) * 20000;
1096 obj_type
= GetObjectType(hfont
);
1097 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1099 hr
= IFont_put_Size(font
, size
);
1100 EXPECT_HR(hr
, S_OK
);
1102 hr
= IFont_get_hFont(font
, &hfont
);
1103 EXPECT_HR(hr
, S_OK
);
1105 hr
= IFont_ReleaseHfont(font
, hfont
);
1106 EXPECT_HR(hr
, S_OK
);
1108 if(i
== 0) first_hfont
= hfont
;
1109 obj_type
= GetObjectType(first_hfont
);
1110 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1113 IFont_Release(font
);
1115 obj_type
= GetObjectType(first_hfont
);
1116 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1118 /* If we take two internal references on a hfont then we can release
1119 it twice. So it looks like there's a total reference count
1120 that includes internal and external references */
1122 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1123 EXPECT_HR(hr
, S_OK
);
1124 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font2
);
1125 EXPECT_HR(hr
, S_OK
);
1127 hr
= IFont_get_hFont(font
, &hfont
);
1128 EXPECT_HR(hr
, S_OK
);
1129 hr
= IFont_get_hFont(font2
, &first_hfont
);
1130 EXPECT_HR(hr
, S_OK
);
1132 ok(hfont
== first_hfont
, "fonts differ\n");
1133 hr
= IFont_ReleaseHfont(font
, hfont
);
1134 EXPECT_HR(hr
, S_OK
);
1135 hr
= IFont_ReleaseHfont(font
, hfont
);
1137 EXPECT_HR(hr
, S_OK
);
1138 hr
= IFont_ReleaseHfont(font
, hfont
);
1139 EXPECT_HR(hr
, S_FALSE
);
1141 obj_type
= GetObjectType(hfont
);
1142 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1144 IFont_Release(font
);
1146 obj_type
= GetObjectType(hfont
);
1147 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1149 IFont_Release(font2
);
1151 obj_type
= GetObjectType(hfont
);
1152 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1155 static void test_realization(void)
1163 /* Try to create a symbol only font (marlett) with charset
1164 set to ANSI. This will result in another, ANSI, font
1166 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1167 fontdesc
.lpstrName
= marlett_font
;
1168 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1169 fontdesc
.sWeight
= FW_NORMAL
;
1170 fontdesc
.sCharset
= ANSI_CHARSET
;
1171 fontdesc
.fItalic
= FALSE
;
1172 fontdesc
.fUnderline
= FALSE
;
1173 fontdesc
.fStrikethrough
= FALSE
;
1175 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1176 EXPECT_HR(hr
, S_OK
);
1178 hr
= IFont_get_Charset(font
, &cs
);
1179 EXPECT_HR(hr
, S_OK
);
1180 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1182 IFont_Release(font
);
1184 /* Now create an ANSI font and change the name to marlett */
1186 fontdesc
.lpstrName
= arial_font
;
1188 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1189 EXPECT_HR(hr
, S_OK
);
1191 hr
= IFont_get_Charset(font
, &cs
);
1192 EXPECT_HR(hr
, S_OK
);
1193 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1195 name
= SysAllocString(marlett_font
);
1196 hr
= IFont_put_Name(font
, name
);
1197 EXPECT_HR(hr
, S_OK
);
1198 SysFreeString(name
);
1200 hr
= IFont_get_Name(font
, &name
);
1201 EXPECT_HR(hr
, S_OK
);
1202 ok(!lstrcmpiW(name
, marlett_font
), "got name %s\n", wine_dbgstr_w(name
));
1203 SysFreeString(name
);
1205 hr
= IFont_get_Charset(font
, &cs
);
1206 EXPECT_HR(hr
, S_OK
);
1207 ok(cs
== SYMBOL_CHARSET
, "got charset %d\n", cs
);
1209 IFont_Release(font
);
1212 static void test_OleCreateFontIndirect(void)
1215 IUnknown
*unk
, *unk2
;
1219 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1220 fontdesc
.lpstrName
= arial_font
;
1221 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1222 fontdesc
.sWeight
= FW_NORMAL
;
1223 fontdesc
.sCharset
= ANSI_CHARSET
;
1224 fontdesc
.fItalic
= FALSE
;
1225 fontdesc
.fUnderline
= FALSE
;
1226 fontdesc
.fStrikethrough
= FALSE
;
1228 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1229 EXPECT_HR(hr
, S_OK
);
1230 IFont_Release(font
);
1232 /* play with cbSizeofstruct value */
1233 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)-1;
1234 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1235 EXPECT_HR(hr
, S_OK
);
1236 IFont_Release(font
);
1238 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)+1;
1239 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1240 EXPECT_HR(hr
, S_OK
);
1241 IFont_Release(font
);
1243 fontdesc
.cbSizeofstruct
= 0;
1244 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1245 EXPECT_HR(hr
, S_OK
);
1246 IFont_Release(font
);
1248 hr
= OleInitialize(NULL
);
1249 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1251 hr
= CoGetClassObject(&CLSID_StdFont
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&unk
);
1252 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1254 hr
= IUnknown_QueryInterface(unk
, &IID_IUnknown
, (void**)&unk2
);
1255 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1257 IUnknown_Release(unk
);
1258 IUnknown_Release(unk2
);
1265 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1266 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1267 if (!pOleCreateFontIndirect
)
1269 win_skip("OleCreateFontIndirect not available\n");
1273 test_QueryInterface();
1276 test_font_events_disp();
1277 test_GetIDsOfNames();
1280 test_ReleaseHfont();
1283 test_hfont_lifetime();
1285 test_OleCreateFontIndirect();