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
30 #include <wine/test.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
;
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
);
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
)
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
;
94 fd
.fUnderline
= FALSE
;
95 fd
.fStrikethrough
= FALSE
;
97 /* Create font, test that it worked. */
98 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
100 ok(hres
== S_OK
,"%s: OCFI returns 0x%08lx instead of S_OK.\n",
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",
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",
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
);
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. */
142 LONG dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
); /* expected results depend on display DPI */
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 */
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)
206 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
207 EXPECT_HR(hr
, E_POINTER
);
209 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, (void **)&font
);
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
);
225 static void test_type_info(void)
229 IFontDisp
* fontdisp
= NULL
;
231 WCHAR name_Name
[] = {'N','a','m','e',0};
234 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
236 DISPPARAMS dispparams
;
239 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &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
,
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
);
279 return E_NOINTERFACE
;
283 static ULONG WINAPI
FontEventsDisp_AddRef(
284 IFontEventsDisp
*iface
)
289 static ULONG WINAPI
FontEventsDisp_Release(
290 IFontEventsDisp
*iface
)
295 static HRESULT WINAPI
FontEventsDisp_GetTypeInfoCount(IFontEventsDisp
*iface
, UINT
*pctinfo
)
297 ok(0, "unexpected call\n");
301 static HRESULT WINAPI
FontEventsDisp_GetTypeInfo(IFontEventsDisp
*iface
, UINT itinfo
, LCID lcid
, ITypeInfo
**pptinfo
)
303 ok(0, "unexpected call\n");
307 static HRESULT WINAPI
FontEventsDisp_GetIDsOfNames(IFontEventsDisp
*iface
, REFIID riid
, LPOLESTR
*names
, UINT cNames
, LCID lcid
,
310 ok(0, "unexpected call\n");
314 static int fonteventsdisp_invoke_called
;
315 static BSTR fonteventsdisp_invoke_arg0
;
317 static HRESULT WINAPI
FontEventsDisp_Invoke(
318 IFontEventsDisp
*iface
,
323 DISPPARAMS
*pDispParams
,
325 EXCEPINFO
*pExcepInfo
,
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
++;
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
};
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
}
385 IConnectionPointContainer
*pCPC
;
386 IConnectionPoint
*pCP
;
390 IFontDisp
*pFontDisp
;
391 DISPPARAMS dispparams
;
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
);
407 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
410 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
412 IConnectionPointContainer_Release(pCPC
);
414 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
416 IConnectionPoint_Release(pCP
);
418 fonteventsdisp_invoke_called
= 0;
419 fonteventsdisp_invoke_arg0
= NULL
;
420 hr
= IFont_put_Bold(pFont
, TRUE
);
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
);
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
);
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;
445 case DISPID_FONT_BOLD
:
446 V_VT(&vararg
) = VT_BOOL
;
447 V_BOOL(&vararg
) = VARIANT_FALSE
;
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
;
455 case DISPID_FONT_WEIGHT
:
456 V_VT(&vararg
) = VT_I2
;
457 V_I2(&vararg
) = FW_BLACK
;
459 case DISPID_FONT_CHARSET
:
460 V_VT(&vararg
) = VT_I2
;
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
);
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
);
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
);
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
)
506 IFontDisp
*fontdisp
= NULL
;
508 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
509 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
511 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
514 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
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 */
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
),
554 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
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);
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)
614 DISPPARAMS dispparams
;
617 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
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
);
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
);
654 IFontDisp_Release(fontdisp
);
657 static void test_IsEqual(void)
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;
672 fd
.fUnderline
= FALSE
;
673 fd
.fStrikethrough
= FALSE
;
676 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
678 /* Test equal fonts */
679 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
680 hres
= IFont_IsEqual(ifnt
,ifnt2
);
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
);
691 fd
.lpstrName
= arial_font
;
692 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
693 hres
= IFont_IsEqual(ifnt
,ifnt2
);
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
);
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
);
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 */
719 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
720 hres
= IFont_IsEqual(ifnt
,ifnt2
);
722 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08lx\n",hres
);
724 IFont_Release(ifnt2
);
728 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
729 hres
= IFont_IsEqual(ifnt
,ifnt2
);
731 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08lx\n",hres
);
733 IFont_Release(ifnt2
);
735 /* Test italic setting */
737 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
738 hres
= IFont_IsEqual(ifnt
,ifnt2
);
740 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08lx\n",hres
);
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
);
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
);
758 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08lx\n",hres
);
759 fd
.fStrikethrough
= FALSE
;
760 IFont_Release(ifnt2
);
766 static void test_ReleaseHfont(void)
769 LPVOID pvObj1
= NULL
;
770 LPVOID pvObj2
= NULL
;
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;
785 fd
.fUnderline
= FALSE
;
786 fd
.fStrikethrough
= FALSE
;
788 /* Create HFONTs and IFONTs */
789 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
791 IFont_get_hFont(ifnt1
,&hfnt1
);
792 fd
.lpstrName
= arial_font
;
793 pOleCreateFontIndirect(&fd
, &IID_IFont
, &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",
803 /* Try to add a bad HFONT */
804 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
806 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
809 /* Release all refs */
810 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
812 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
815 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
817 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
820 /* Check that both lists are empty */
821 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
823 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
826 /* The list should be empty */
827 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
829 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
832 IFont_Release(ifnt1
);
833 IFont_Release(ifnt2
);
836 static void test_AddRefHfont(void)
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;
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",
871 /* Try to add a bad HFONT */
872 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
874 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
877 /* Add simple IFONT HFONT pair */
878 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
880 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
883 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
884 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
886 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
889 /* Release all hfnt1 refs */
890 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
892 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
895 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
897 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
900 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
902 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
905 /* Check if hfnt1 is empty */
906 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
908 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
911 /* Release all hfnt2 refs */
912 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
914 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
917 /* Check if hfnt2 is empty */
918 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
920 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
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
);
930 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
933 /* Decrement reference for destroyed hfnt1 */
934 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
936 hres
== S_FALSE
, /* <= win2k */
937 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08lx\n",
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
);
952 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
955 /* Decrement reference for destroyed hfnt1 */
956 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
958 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
961 IFont_Release(ifnt3
);
964 static void test_returns(void)
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
);
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)
1002 HFONT hfont
, first_hfont
= NULL
;
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
);
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
);
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)
1172 /* Try to create a symbol only font (marlett) with charset
1173 set to ANSI. This will result in another, ANSI, font
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)
1224 IUnknown
*unk
, *unk2
;
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
);
1274 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1275 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1276 if (!pOleCreateFontIndirect
)
1278 win_skip("OleCreateFontIndirect not available\n");
1285 test_font_events_disp();
1286 test_GetIDsOfNames();
1289 test_ReleaseHfont();
1292 test_hfont_lifetime();
1294 test_OleCreateFontIndirect();