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 EXPECT_HR(hr,hr_exp) \
55 ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
57 /* Create a font with cySize given by lo_size, hi_size, */
58 /* SetRatio to ratio_logical, ratio_himetric, */
59 /* check that resulting hfont has height hfont_height. */
60 /* Various checks along the way. */
61 static void test_ifont_size(LONGLONG size
, LONG ratio_logical
, LONG ratio_himetric
,
62 LONG hfont_height
, const char * test_name
)
73 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
74 fd
.lpstrName
= arial_font
; /* using scalable instead of bitmap font reduces errors due to font realization */
75 fd
.cySize
.int64
= size
;
79 fd
.fUnderline
= FALSE
;
80 fd
.fStrikethrough
= FALSE
;
82 /* Create font, test that it worked. */
83 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
85 ok(hres
== S_OK
,"%s: OCFI returns 0x%08x instead of S_OK.\n",
87 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
89 /* Change the scaling ratio */
90 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
91 ok((ratio_logical
&& ratio_himetric
) ? hres
== S_OK
: hres
== E_FAIL
,
92 "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name
, hres
);
95 hres
= IFont_get_Size(ifnt
, &psize
);
96 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
99 /* Check returned size - allow for errors due to rounding & font realization. */
100 ok((psize
.int64
- size
) < 10000 && (psize
.int64
- size
) > -10000,
101 "%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
102 test_name
, S(psize
).Lo
, S(psize
).Hi
, fd
.cySize
.Lo
, fd
.cySize
.Hi
);
104 /* Check hFont size. */
105 hres
= IFont_get_hFont (ifnt
, &hfont
);
106 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
108 rtnval
= GetObjectA(hfont
, sizeof(LOGFONTA
), &lf
);
109 ok(rtnval
> 0, "GetObject(hfont) failed\n");
111 /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
112 ok(abs(lf
.lfHeight
- hfont_height
) <= 1,
113 "%s: hFont has lf.lfHeight=%d, expected %d.\n",
114 test_name
, lf
.lfHeight
, hfont_height
);
120 static void test_ifont_sizes(void)
122 /* Test various size operations and conversions. */
123 /* Add more as needed. */
125 /* Results of first 2 tests depend on display resolution. */
127 LONG dpi
= GetDeviceCaps(hdc
, LOGPIXELSY
); /* expected results depend on display DPI */
129 if(dpi
== 96) /* normal resolution display */
131 test_ifont_size(180000, 0, 0, -24, "default"); /* normal font */
132 test_ifont_size(186000, 0, 0, -25, "rounding"); /* test rounding */
133 } else if(dpi
== 72) /* low resolution display */
135 test_ifont_size(180000, 0, 0, -18, "default"); /* normal font */
136 test_ifont_size(186000, 0, 0, -19, "rounding"); /* test rounding */
137 } else if(dpi
== 120) /* high resolution display */
139 test_ifont_size(180000, 0, 0, -30, "default"); /* normal font */
140 test_ifont_size(186000, 0, 0, -31, "rounding"); /* test rounding */
142 skip("Skipping resolution dependent font size tests - display resolution is %d\n", dpi
);
144 /* Next 4 tests specify a scaling ratio, so display resolution is not a factor. */
145 test_ifont_size(180000, 72, 2540, -18, "ratio1"); /* change ratio */
146 test_ifont_size(180000, 144, 2540, -36, "ratio2"); /* another ratio */
147 test_ifont_size(180000, 72, 1270, -36, "ratio3"); /* yet another ratio */
148 test_ifont_size(186000, 72, 2540, -19, "rounding+ratio"); /* test rounding with ratio */
150 /* test various combinations of logical == himetric */
151 test_ifont_size(180000, 10, 10, -635, "identical ratio 1");
152 test_ifont_size(240000, 10, 10, -848, "identical ratio 2");
153 test_ifont_size(300000, 10, 10, -1058, "identical ratio 3");
155 /* test various combinations of logical and himetric both set to 1 */
156 test_ifont_size(180000, 1, 1, -24, "1:1 ratio 1");
157 test_ifont_size(240000, 1, 1, -32, "1:1 ratio 2");
158 test_ifont_size(300000, 1, 1, -40, "1:1 ratio 3");
160 /* test various combinations of logical set to 1 */
161 test_ifont_size(180000, 1, 0, -24, "1:0 ratio 1");
162 test_ifont_size(240000, 1, 0, -32, "1:0 ratio 2");
163 test_ifont_size(300000, 1, 0, -40, "1:0 ratio 3");
165 /* test various combinations of himetric set to 1 */
166 test_ifont_size(180000, 0, 1, -24, "0:1 ratio 1");
167 test_ifont_size(240000, 0, 1, -32, "0:1 ratio 2");
168 test_ifont_size(300000, 0, 1, -40, "0:1 ratio 3");
170 /* test various combinations of 2:1 logical:himetric */
171 test_ifont_size(180000, 2, 1, -1270, "2:1 ratio 1");
172 test_ifont_size(240000, 2, 1, -1694, "2:1 ratio 2");
173 test_ifont_size(300000, 2, 1, -2117, "2:1 ratio 3");
175 /* test various combinations of 1:2 logical:himetric */
176 test_ifont_size(180000, 1, 2, -318, "1:2 ratio 1");
177 test_ifont_size(240000, 1, 2, -424, "1:2 ratio 2");
178 test_ifont_size(300000, 1, 2, -529, "1:2 ratio 3");
180 /* test various combinations of logical and himetric both set to 2 */
181 test_ifont_size(180000, 2, 2, -635, "2:2 ratio 1");
182 test_ifont_size(240000, 2, 2, -848, "2:2 ratio 2");
183 test_ifont_size(300000, 2, 2, -1058, "2:2 ratio 3");
186 static void test_QueryInterface(void)
193 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, NULL
);
194 EXPECT_HR(hr
, E_POINTER
);
196 hr
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
200 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
203 hr
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
206 /* Test if QueryInterface increments ref counter for IFONTs */
207 ref
= IFont_AddRef(font
);
209 broken(ref
== 1), /* win95 */
210 "IFont_QI expected ref value 3 but instead got %d\n", ref
);
213 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
219 static void test_type_info(void)
223 IFontDisp
* fontdisp
= NULL
;
225 WCHAR name_Name
[] = {'N','a','m','e',0};
228 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
230 DISPPARAMS dispparams
;
233 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
236 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
237 ok(hres
== S_OK
, "GTI returned 0x%08x instead of S_OK.\n", hres
);
238 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
240 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
241 ok(hres
== S_OK
, "GetNames returned 0x%08x instead of S_OK.\n", hres
);
242 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
243 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
244 SysFreeString(names
[0]);
246 ITypeInfo_Release(pTInfo
);
248 dispparams
.cNamedArgs
= 0;
249 dispparams
.rgdispidNamedArgs
= NULL
;
250 dispparams
.cArgs
= 0;
251 dispparams
.rgvarg
= NULL
;
252 VariantInit(&varresult
);
253 hres
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_NAME
, &IID_NULL
,
254 LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
,
256 ok(hres
== S_OK
, "IFontDisp_Invoke return 0x%08x instead of S_OK.\n", hres
);
257 VariantClear(&varresult
);
259 IFontDisp_Release(fontdisp
);
262 static HRESULT WINAPI
FontEventsDisp_QueryInterface(IFontEventsDisp
*iface
, REFIID riid
, void **ppvObject
)
264 if (IsEqualIID(riid
, &IID_IFontEventsDisp
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
266 IFontEventsDisp_AddRef(iface
);
273 return E_NOINTERFACE
;
277 static ULONG WINAPI
FontEventsDisp_AddRef(
278 IFontEventsDisp
*iface
)
283 static ULONG WINAPI
FontEventsDisp_Release(
284 IFontEventsDisp
*iface
)
289 static HRESULT WINAPI
FontEventsDisp_GetTypeInfoCount(IFontEventsDisp
*iface
, UINT
*pctinfo
)
291 ok(0, "unexpected call\n");
295 static HRESULT WINAPI
FontEventsDisp_GetTypeInfo(IFontEventsDisp
*iface
, UINT itinfo
, LCID lcid
, ITypeInfo
**pptinfo
)
297 ok(0, "unexpected call\n");
301 static HRESULT WINAPI
FontEventsDisp_GetIDsOfNames(IFontEventsDisp
*iface
, REFIID riid
, LPOLESTR
*names
, UINT cNames
, LCID lcid
,
304 ok(0, "unexpected call\n");
308 static int fonteventsdisp_invoke_called
;
309 static BSTR fonteventsdisp_invoke_arg0
;
311 static HRESULT WINAPI
FontEventsDisp_Invoke(
312 IFontEventsDisp
*iface
,
317 DISPPARAMS
*pDispParams
,
319 EXCEPINFO
*pExcepInfo
,
322 VARIANTARG
*arg0
= &pDispParams
->rgvarg
[0];
324 ok(dispid
== DISPID_FONT_CHANGED
, "expected DISPID_FONT_CHANGED instead of 0x%x\n", dispid
);
325 ok(IsEqualGUID(riid
, &GUID_NULL
), "got riid %s\n", wine_dbgstr_guid(riid
));
326 ok(wFlags
== INVOKE_FUNC
, "expected INVOKE_FUNC instead of 0x%x\n", wFlags
);
327 ok(pDispParams
->cArgs
== 1, "expected arg count 1, got %d\n", pDispParams
->cArgs
);
328 ok(V_VT(arg0
) == VT_BSTR
, "expected VT_BSTR, got %d\n", V_VT(arg0
));
330 fonteventsdisp_invoke_arg0
= SysAllocString(V_BSTR(arg0
));
331 fonteventsdisp_invoke_called
++;
335 static IFontEventsDispVtbl FontEventsDisp_Vtbl
=
337 FontEventsDisp_QueryInterface
,
338 FontEventsDisp_AddRef
,
339 FontEventsDisp_Release
,
340 FontEventsDisp_GetTypeInfoCount
,
341 FontEventsDisp_GetTypeInfo
,
342 FontEventsDisp_GetIDsOfNames
,
343 FontEventsDisp_Invoke
346 static IFontEventsDisp FontEventsDisp
= { &FontEventsDisp_Vtbl
};
354 static void test_font_events_disp(void)
356 static const WCHAR nameW
[] = {'N','a','m','e',0};
357 static const WCHAR sizeW
[] = {'S','i','z','e',0};
358 static const WCHAR boldW
[] = {'B','o','l','d',0};
359 static const WCHAR italicW
[] = {'I','t','a','l','i','c',0};
360 static const WCHAR underlineW
[] = {'U','n','d','e','r','l','i','n','e',0};
361 static const WCHAR strikeW
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
362 static const WCHAR weightW
[] = {'W','e','i','g','h','t',0};
363 static const WCHAR charsetW
[] = {'C','h','a','r','s','e','t',0};
365 static const struct font_dispid font_dispids
[] =
367 { DISPID_FONT_NAME
, nameW
},
368 { DISPID_FONT_SIZE
, sizeW
},
369 { DISPID_FONT_BOLD
, boldW
},
370 { DISPID_FONT_ITALIC
, italicW
},
371 { DISPID_FONT_UNDER
, underlineW
},
372 { DISPID_FONT_STRIKE
, strikeW
},
373 { DISPID_FONT_WEIGHT
, weightW
},
374 { DISPID_FONT_CHARSET
, charsetW
}
379 IConnectionPointContainer
*pCPC
;
380 IConnectionPoint
*pCP
;
384 IFontDisp
*pFontDisp
;
385 DISPPARAMS dispparams
;
389 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
390 fontdesc
.lpstrName
= MSSansSerif_font
;
391 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
392 fontdesc
.sWeight
= FW_NORMAL
;
393 fontdesc
.sCharset
= 0;
394 fontdesc
.fItalic
= FALSE
;
395 fontdesc
.fUnderline
= FALSE
;
396 fontdesc
.fStrikethrough
= FALSE
;
398 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
401 hr
= IFont_QueryInterface(pFont
, &IID_IConnectionPointContainer
, (void **)&pCPC
);
404 hr
= IConnectionPointContainer_FindConnectionPoint(pCPC
, &IID_IFontEventsDisp
, &pCP
);
406 IConnectionPointContainer_Release(pCPC
);
408 hr
= IConnectionPoint_Advise(pCP
, (IUnknown
*)&FontEventsDisp
, &dwCookie
);
410 IConnectionPoint_Release(pCP
);
412 fonteventsdisp_invoke_called
= 0;
413 fonteventsdisp_invoke_arg0
= NULL
;
414 hr
= IFont_put_Bold(pFont
, TRUE
);
417 ok(fonteventsdisp_invoke_called
== 1, "IFontEventDisp::Invoke wasn't called once\n");
418 SysFreeString(fonteventsdisp_invoke_arg0
);
420 hr
= IFont_QueryInterface(pFont
, &IID_IFontDisp
, (void **)&pFontDisp
);
423 for (i
= 0; i
< sizeof(font_dispids
)/sizeof(font_dispids
[0]); i
++)
425 switch (font_dispids
[i
].dispid
)
427 case DISPID_FONT_NAME
:
429 static const WCHAR arialW
[] = {'A','r','i','a','l',0};
430 V_VT(&vararg
) = VT_BSTR
;
431 V_BSTR(&vararg
) = SysAllocString(arialW
);
434 case DISPID_FONT_SIZE
:
435 V_VT(&vararg
) = VT_CY
;
436 S(V_CY(&vararg
)).Lo
= 25;
437 S(V_CY(&vararg
)).Hi
= 0;
439 case DISPID_FONT_BOLD
:
440 V_VT(&vararg
) = VT_BOOL
;
441 V_BOOL(&vararg
) = VARIANT_FALSE
;
443 case DISPID_FONT_ITALIC
:
444 case DISPID_FONT_UNDER
:
445 case DISPID_FONT_STRIKE
:
446 V_VT(&vararg
) = VT_BOOL
;
447 V_BOOL(&vararg
) = VARIANT_TRUE
;
449 case DISPID_FONT_WEIGHT
:
450 V_VT(&vararg
) = VT_I2
;
451 V_I2(&vararg
) = FW_BLACK
;
453 case DISPID_FONT_CHARSET
:
454 V_VT(&vararg
) = VT_I2
;
461 dispparams
.cNamedArgs
= 0;
462 dispparams
.rgdispidNamedArgs
= NULL
;
463 dispparams
.cArgs
= 1;
464 dispparams
.rgvarg
= &vararg
;
465 fonteventsdisp_invoke_called
= 0;
466 hr
= IFontDisp_Invoke(pFontDisp
, font_dispids
[i
].dispid
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
467 ok(hr
== S_OK
, "dispid=%d, got 0x%08x\n", font_dispids
[i
].dispid
, hr
);
468 ok(fonteventsdisp_invoke_called
== 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids
[i
].dispid
,
469 fonteventsdisp_invoke_called
);
472 ok(!lstrcmpW(font_dispids
[i
].name
, fonteventsdisp_invoke_arg0
), "dispid=%d, got %s, expected %s\n",
473 font_dispids
[i
].dispid
, wine_dbgstr_w(fonteventsdisp_invoke_arg0
), wine_dbgstr_w(font_dispids
[i
].name
));
474 SysFreeString(fonteventsdisp_invoke_arg0
);
476 VariantClear(&vararg
);
479 IFontDisp_Release(pFontDisp
);
481 hr
= IFont_Clone(pFont
, &pFont2
);
483 IFont_Release(pFont
);
485 /* this test shows that the notification routine isn't called again */
486 fonteventsdisp_invoke_called
= 0;
487 hr
= IFont_put_Bold(pFont2
, FALSE
);
489 ok(fonteventsdisp_invoke_called
== 0, "got %d\n", fonteventsdisp_invoke_called
);
491 IFont_Release(pFont2
);
494 static void test_names_ids(WCHAR
* w_name_1
, const char* a_name_1
,
495 WCHAR
* w_name_2
, const char* a_name_2
,
496 LCID lcid
, DISPID id_1
, DISPID id_2
,
497 HRESULT hres_expect
, int numnames
)
500 IFontDisp
*fontdisp
= NULL
;
502 DISPID rgDispId
[2] = {0xdeadbeef, 0xdeadbeef};
503 LPOLESTR names
[2] = {w_name_1
, w_name_2
};
505 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
508 hres
= IFontDisp_GetIDsOfNames(fontdisp
, &IID_NULL
, names
, numnames
,
512 ok(hres
== hres_expect
,
513 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08x, expected 0x%08x.\n",
514 a_name_1
, a_name_2
, hres
, hres_expect
);
516 /* test first DISPID */
517 ok(rgDispId
[0]==id_1
,
518 "GetIDsOfNames: \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
519 a_name_1
, rgDispId
[0], id_1
);
521 /* test second DISPID is present */
524 ok(rgDispId
[1]==id_2
,
525 "GetIDsOfNames: ..., \"%s\" gets DISPID 0x%08x, expected 0x%08x.\n",
526 a_name_2
, rgDispId
[1], id_2
);
529 IFontDisp_Release(fontdisp
);
532 static void test_GetIDsOfNames(void)
534 WCHAR name_Name
[] = {'N','a','m','e',0};
535 WCHAR name_Italic
[] = {'I','t','a','l','i','c',0};
536 WCHAR name_Size
[] = {'S','i','z','e',0};
537 WCHAR name_Bold
[] = {'B','o','l','d',0};
538 WCHAR name_Underline
[] = {'U','n','d','e','r','l','i','n','e',0};
539 WCHAR name_Strikethrough
[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
540 WCHAR name_Weight
[] = {'W','e','i','g','h','t',0};
541 WCHAR name_Charset
[] = {'C','h','a','r','s','e','t',0};
542 WCHAR name_Foo
[] = {'F','o','o',0};
543 WCHAR name_nAmE
[] = {'n','A','m','E',0};
544 WCHAR name_Nom
[] = {'N','o','m',0};
546 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
548 LCID fr_fr
= MAKELCID(MAKELANGID(LANG_FRENCH
,SUBLANG_FRENCH
),
551 /* Test DISPID_FONTs for the various properties. */
552 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
553 DISPID_FONT_NAME
, 0, S_OK
,1);
554 test_names_ids(name_Size
, "Size", NULL
, "", en_us
,
555 DISPID_FONT_SIZE
, 0, S_OK
,1);
556 test_names_ids(name_Bold
, "Bold", NULL
, "", en_us
,
557 DISPID_FONT_BOLD
, 0, S_OK
,1);
558 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
559 DISPID_FONT_ITALIC
, 0, S_OK
,1);
560 test_names_ids(name_Underline
, "Underline", NULL
, "", en_us
,
561 DISPID_FONT_UNDER
, 0, S_OK
,1);
562 test_names_ids(name_Strikethrough
, "Strikethrough", NULL
, "", en_us
,
563 DISPID_FONT_STRIKE
, 0, S_OK
,1);
564 test_names_ids(name_Weight
, "Weight", NULL
, "", en_us
,
565 DISPID_FONT_WEIGHT
, 0, S_OK
,1);
566 test_names_ids(name_Charset
, "Charset", NULL
, "", en_us
,
567 DISPID_FONT_CHARSET
, 0, S_OK
,1);
569 /* Capitalization doesn't matter. */
570 test_names_ids(name_nAmE
, "nAmE", NULL
, "", en_us
,
571 DISPID_FONT_NAME
, 0, S_OK
,1);
574 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
575 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
577 /* Pass several names: first is processed, */
578 /* second gets DISPID_UNKNOWN and doesn't affect retval. */
579 test_names_ids(name_Italic
, "Italic", name_Name
, "Name", en_us
,
580 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
581 test_names_ids(name_Italic
, "Italic", name_Foo
, "Foo", en_us
,
582 DISPID_FONT_ITALIC
, DISPID_UNKNOWN
, S_OK
,2);
584 /* Locale ID has no effect. */
585 test_names_ids(name_Name
, "Name", NULL
, "", fr_fr
,
586 DISPID_FONT_NAME
, 0, S_OK
,1);
587 test_names_ids(name_Nom
, "This is not a font", NULL
, "", fr_fr
,
588 DISPID_UNKNOWN
, 0, DISP_E_UNKNOWNNAME
,1);
590 /* One of the arguments are invalid */
591 test_names_ids(name_Name
, "Name", NULL
, "", en_us
,
592 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
593 test_names_ids(name_Italic
, "Italic", NULL
, "", en_us
,
594 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
595 test_names_ids(name_Foo
, "Foo", NULL
, "", en_us
,
596 0xdeadbeef, 0xdeadbeef, E_INVALIDARG
,0);
598 /* Crazy locale ID? */
599 test_names_ids(name_Name
, "Name", NULL
, "", -1,
600 DISPID_FONT_NAME
, 0, S_OK
,1);
603 static void test_Invoke(void)
608 DISPPARAMS dispparams
;
611 hr
= pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, (void **)&fontdisp
);
614 V_VT(&vararg
) = VT_BOOL
;
615 V_BOOL(&vararg
) = VARIANT_FALSE
;
616 dispparams
.cNamedArgs
= 0;
617 dispparams
.rgdispidNamedArgs
= NULL
;
618 dispparams
.cArgs
= 1;
619 dispparams
.rgvarg
= &vararg
;
620 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_IFontDisp
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
621 EXPECT_HR(hr
, DISP_E_UNKNOWNINTERFACE
);
623 dispparams
.cArgs
= 0;
624 dispparams
.rgvarg
= NULL
;
625 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, &dispparams
, NULL
, NULL
, NULL
);
626 EXPECT_HR(hr
, DISP_E_BADPARAMCOUNT
);
628 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYPUT
, NULL
, NULL
, NULL
, NULL
);
629 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
631 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, NULL
, NULL
, NULL
);
632 EXPECT_HR(hr
, DISP_E_PARAMNOTOPTIONAL
);
634 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
637 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_METHOD
, NULL
, &varresult
, NULL
, NULL
);
638 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
640 hr
= IFontDisp_Invoke(fontdisp
, 0xdeadbeef, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, NULL
, &varresult
, NULL
, NULL
);
641 EXPECT_HR(hr
, DISP_E_MEMBERNOTFOUND
);
643 dispparams
.cArgs
= 1;
644 dispparams
.rgvarg
= &vararg
;
645 hr
= IFontDisp_Invoke(fontdisp
, DISPID_FONT_BOLD
, &IID_NULL
, 0, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, NULL
, NULL
);
648 IFontDisp_Release(fontdisp
);
651 static void test_IsEqual(void)
658 /* Basic font description */
659 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
660 fd
.lpstrName
= system_font
;
661 S(fd
.cySize
).Lo
= 100;
662 S(fd
.cySize
).Hi
= 100;
666 fd
.fUnderline
= FALSE
;
667 fd
.fStrikethrough
= FALSE
;
670 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt
);
672 /* Test equal fonts */
673 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
674 hres
= IFont_IsEqual(ifnt
,ifnt2
);
676 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres
);
677 IFont_Release(ifnt2
);
679 /* Check for bad pointer */
680 hres
= IFont_IsEqual(ifnt
,NULL
);
681 ok(hres
== E_POINTER
,
682 "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres
);
685 fd
.lpstrName
= arial_font
;
686 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
687 hres
= IFont_IsEqual(ifnt
,ifnt2
);
689 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres
);
690 fd
.lpstrName
= system_font
;
691 IFont_Release(ifnt2
);
693 /* Test lo font size */
694 S(fd
.cySize
).Lo
= 10000;
695 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
696 hres
= IFont_IsEqual(ifnt
,ifnt2
);
698 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres
);
699 S(fd
.cySize
).Lo
= 100;
700 IFont_Release(ifnt2
);
702 /* Test hi font size */
703 S(fd
.cySize
).Hi
= 10000;
704 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
705 hres
= IFont_IsEqual(ifnt
,ifnt2
);
707 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres
);
708 S(fd
.cySize
).Hi
= 100;
709 IFont_Release(ifnt2
);
711 /* Test font weight */
713 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
714 hres
= IFont_IsEqual(ifnt
,ifnt2
);
716 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres
);
718 IFont_Release(ifnt2
);
722 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
723 hres
= IFont_IsEqual(ifnt
,ifnt2
);
725 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres
);
727 IFont_Release(ifnt2
);
729 /* Test italic setting */
731 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
732 hres
= IFont_IsEqual(ifnt
,ifnt2
);
734 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres
);
736 IFont_Release(ifnt2
);
738 /* Test underline setting */
739 fd
.fUnderline
= TRUE
;
740 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
741 hres
= IFont_IsEqual(ifnt
,ifnt2
);
743 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres
);
744 fd
.fUnderline
= FALSE
;
745 IFont_Release(ifnt2
);
747 /* Test strikethrough setting */
748 fd
.fStrikethrough
= TRUE
;
749 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
750 hres
= IFont_IsEqual(ifnt
,ifnt2
);
752 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres
);
753 fd
.fStrikethrough
= FALSE
;
754 IFont_Release(ifnt2
);
760 static void test_ReleaseHfont(void)
763 LPVOID pvObj1
= NULL
;
764 LPVOID pvObj2
= NULL
;
771 /* Basic font description */
772 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
773 fd
.lpstrName
= system_font
;
774 S(fd
.cySize
).Lo
= 100;
775 S(fd
.cySize
).Hi
= 100;
779 fd
.fUnderline
= FALSE
;
780 fd
.fStrikethrough
= FALSE
;
782 /* Create HFONTs and IFONTs */
783 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj1
);
785 IFont_get_hFont(ifnt1
,&hfnt1
);
786 fd
.lpstrName
= arial_font
;
787 pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj2
);
789 IFont_get_hFont(ifnt2
,&hfnt2
);
791 /* Try invalid HFONT */
792 hres
= IFont_ReleaseHfont(ifnt1
,NULL
);
793 ok(hres
== E_INVALIDARG
,
794 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
797 /* Try to add a bad HFONT */
798 hres
= IFont_ReleaseHfont(ifnt1
,(HFONT
)32);
800 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
803 /* Release all refs */
804 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
806 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
809 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
811 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
814 /* Check that both lists are empty */
815 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
817 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
820 /* The list should be empty */
821 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
823 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
826 IFont_Release(ifnt1
);
827 IFont_Release(ifnt2
);
830 static void test_AddRefHfont(void)
841 /* Basic font description */
842 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
843 fd
.lpstrName
= system_font
;
844 S(fd
.cySize
).Lo
= 100;
845 S(fd
.cySize
).Hi
= 100;
849 fd
.fUnderline
= FALSE
;
850 fd
.fStrikethrough
= FALSE
;
852 /* Create HFONTs and IFONTs */
853 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt1
);
854 IFont_get_hFont(ifnt1
,&hfnt1
);
855 fd
.lpstrName
= arial_font
;
856 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt2
);
857 IFont_get_hFont(ifnt2
,&hfnt2
);
859 /* Try invalid HFONT */
860 hres
= IFont_AddRefHfont(ifnt1
,NULL
);
861 ok(hres
== E_INVALIDARG
,
862 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
865 /* Try to add a bad HFONT */
866 hres
= IFont_AddRefHfont(ifnt1
,(HFONT
)32);
868 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
871 /* Add simple IFONT HFONT pair */
872 hres
= IFont_AddRefHfont(ifnt1
,hfnt1
);
874 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
877 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
878 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
880 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
883 /* Release all hfnt1 refs */
884 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
886 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
889 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
891 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
894 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
896 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
899 /* Check if hfnt1 is empty */
900 hres
= IFont_ReleaseHfont(ifnt1
,hfnt1
);
902 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
905 /* Release all hfnt2 refs */
906 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
908 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
911 /* Check if hfnt2 is empty */
912 hres
= IFont_ReleaseHfont(ifnt2
,hfnt2
);
914 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
917 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
919 IFont_Release(ifnt1
);
921 /* Add a reference for destroyed hfnt1 */
922 hres
= IFont_AddRefHfont(ifnt2
,hfnt1
);
924 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
927 /* Decrement reference for destroyed hfnt1 */
928 hres
= IFont_ReleaseHfont(ifnt2
,hfnt1
);
930 hres
== S_FALSE
, /* <= win2k */
931 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
934 /* Shows that releasing all IFONT's does clear the HFONT cache. */
936 IFont_Release(ifnt2
);
938 /* Need to make a new IFONT for testing */
939 fd
.fUnderline
= TRUE
;
940 pOleCreateFontIndirect(&fd
, &IID_IFont
, (void **)&ifnt3
);
941 IFont_get_hFont(ifnt3
,&hfnt3
);
943 /* Add a reference for destroyed hfnt1 */
944 hres
= IFont_AddRefHfont(ifnt3
,hfnt1
);
946 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
949 /* Decrement reference for destroyed hfnt1 */
950 hres
= IFont_ReleaseHfont(ifnt3
,hfnt1
);
952 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
955 IFont_Release(ifnt3
);
958 static void test_returns(void)
964 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
965 fontdesc
.lpstrName
= MSSansSerif_font
;
966 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
967 fontdesc
.sWeight
= FW_NORMAL
;
968 fontdesc
.sCharset
= 0;
969 fontdesc
.fItalic
= FALSE
;
970 fontdesc
.fUnderline
= FALSE
;
971 fontdesc
.fStrikethrough
= FALSE
;
973 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&pFont
);
976 hr
= IFont_put_Name(pFont
, NULL
);
977 EXPECT_HR(hr
, CTL_E_INVALIDPROPERTYVALUE
);
979 hr
= IFont_get_Name(pFont
, NULL
);
980 EXPECT_HR(hr
, E_POINTER
);
982 hr
= IFont_get_Size(pFont
, NULL
);
983 EXPECT_HR(hr
, E_POINTER
);
985 hr
= IFont_get_Bold(pFont
, NULL
);
986 EXPECT_HR(hr
, E_POINTER
);
988 IFont_Release(pFont
);
991 static void test_hfont_lifetime(void)
996 HFONT hfont
, first_hfont
= NULL
;
1001 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1002 fontdesc
.lpstrName
= arial_font
;
1003 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1004 fontdesc
.sWeight
= FW_NORMAL
;
1005 fontdesc
.sCharset
= ANSI_CHARSET
;
1006 fontdesc
.fItalic
= FALSE
;
1007 fontdesc
.fUnderline
= FALSE
;
1008 fontdesc
.fStrikethrough
= FALSE
;
1010 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1011 EXPECT_HR(hr
, S_OK
);
1013 hr
= IFont_get_hFont(font
, &hfont
);
1014 EXPECT_HR(hr
, S_OK
);
1016 /* show that if the font is updated the old hfont is deleted when the
1017 new font is realized */
1018 for(i
= 0; i
< 100; i
++)
1020 HFONT last_hfont
= hfont
;
1022 size
.int64
= (i
+ 10) * 20000;
1024 obj_type
= GetObjectType(hfont
);
1025 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1027 hr
= IFont_put_Size(font
, size
);
1028 EXPECT_HR(hr
, S_OK
);
1030 /* put_Size doesn't cause the new font to be realized */
1031 obj_type
= GetObjectType(last_hfont
);
1032 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1034 hr
= IFont_get_hFont(font
, &hfont
);
1035 EXPECT_HR(hr
, S_OK
);
1037 obj_type
= GetObjectType(last_hfont
);
1038 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1041 /* now show that if we take a reference on the hfont, it persists
1042 until the font object is released */
1043 for(i
= 0; i
< 100; i
++)
1045 size
.int64
= (i
+ 10) * 20000;
1047 obj_type
= GetObjectType(hfont
);
1048 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1050 hr
= IFont_put_Size(font
, size
);
1051 EXPECT_HR(hr
, S_OK
);
1053 hr
= IFont_get_hFont(font
, &hfont
);
1054 EXPECT_HR(hr
, S_OK
);
1056 hr
= IFont_AddRefHfont(font
, hfont
);
1057 EXPECT_HR(hr
, S_OK
);
1059 if(i
== 0) first_hfont
= hfont
;
1060 obj_type
= GetObjectType(first_hfont
);
1061 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1064 IFont_Release(font
);
1066 obj_type
= GetObjectType(first_hfont
);
1067 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
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 %d\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 %d\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
);
1103 obj_type
= GetObjectType(last_hfont
);
1104 ok(obj_type
== 0, "%d: got obj type %d\n", i
, obj_type
);
1107 /* Interestingly if we release a nonexistent reference on the hfont,
1108 * it persists until the font object is released
1110 for(i
= 0; i
< 100; i
++)
1112 size
.int64
= (i
+ 10) * 20000;
1114 obj_type
= GetObjectType(hfont
);
1115 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1117 hr
= IFont_put_Size(font
, size
);
1118 EXPECT_HR(hr
, S_OK
);
1120 hr
= IFont_get_hFont(font
, &hfont
);
1121 EXPECT_HR(hr
, S_OK
);
1123 hr
= IFont_ReleaseHfont(font
, hfont
);
1124 EXPECT_HR(hr
, S_OK
);
1126 if(i
== 0) first_hfont
= hfont
;
1127 obj_type
= GetObjectType(first_hfont
);
1128 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1131 IFont_Release(font
);
1133 obj_type
= GetObjectType(first_hfont
);
1134 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1136 /* If we take two internal references on a hfont then we can release
1137 it twice. So it looks like there's a total reference count
1138 that includes internal and external references */
1140 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1141 EXPECT_HR(hr
, S_OK
);
1142 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font2
);
1143 EXPECT_HR(hr
, S_OK
);
1145 hr
= IFont_get_hFont(font
, &hfont
);
1146 EXPECT_HR(hr
, S_OK
);
1147 hr
= IFont_get_hFont(font2
, &first_hfont
);
1148 EXPECT_HR(hr
, S_OK
);
1150 ok(hfont
== first_hfont
, "fonts differ\n");
1151 hr
= IFont_ReleaseHfont(font
, hfont
);
1152 EXPECT_HR(hr
, S_OK
);
1153 hr
= IFont_ReleaseHfont(font
, hfont
);
1155 EXPECT_HR(hr
, S_OK
);
1156 hr
= IFont_ReleaseHfont(font
, hfont
);
1157 EXPECT_HR(hr
, S_FALSE
);
1159 obj_type
= GetObjectType(hfont
);
1160 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1162 IFont_Release(font
);
1164 obj_type
= GetObjectType(hfont
);
1165 ok(obj_type
== OBJ_FONT
, "got obj type %d\n", obj_type
);
1167 IFont_Release(font2
);
1169 obj_type
= GetObjectType(hfont
);
1170 ok(obj_type
== 0, "got obj type %d\n", obj_type
);
1173 static void test_realization(void)
1181 /* Try to create a symbol only font (marlett) with charset
1182 set to ANSI. This will result in another, ANSI, font
1184 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1185 fontdesc
.lpstrName
= marlett_font
;
1186 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1187 fontdesc
.sWeight
= FW_NORMAL
;
1188 fontdesc
.sCharset
= ANSI_CHARSET
;
1189 fontdesc
.fItalic
= FALSE
;
1190 fontdesc
.fUnderline
= FALSE
;
1191 fontdesc
.fStrikethrough
= FALSE
;
1193 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1194 EXPECT_HR(hr
, S_OK
);
1196 hr
= IFont_get_Charset(font
, &cs
);
1197 EXPECT_HR(hr
, S_OK
);
1198 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1200 IFont_Release(font
);
1202 /* Now create an ANSI font and change the name to marlett */
1204 fontdesc
.lpstrName
= arial_font
;
1206 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void **)&font
);
1207 EXPECT_HR(hr
, S_OK
);
1209 hr
= IFont_get_Charset(font
, &cs
);
1210 EXPECT_HR(hr
, S_OK
);
1211 ok(cs
== ANSI_CHARSET
, "got charset %d\n", cs
);
1213 name
= SysAllocString(marlett_font
);
1214 hr
= IFont_put_Name(font
, name
);
1215 EXPECT_HR(hr
, S_OK
);
1216 SysFreeString(name
);
1218 hr
= IFont_get_Name(font
, &name
);
1219 EXPECT_HR(hr
, S_OK
);
1220 ok(!lstrcmpiW(name
, marlett_font
), "got name %s\n", wine_dbgstr_w(name
));
1221 SysFreeString(name
);
1223 hr
= IFont_get_Charset(font
, &cs
);
1224 EXPECT_HR(hr
, S_OK
);
1225 ok(cs
== SYMBOL_CHARSET
, "got charset %d\n", cs
);
1227 IFont_Release(font
);
1230 static void test_OleCreateFontIndirect(void)
1233 IUnknown
*unk
, *unk2
;
1237 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
);
1238 fontdesc
.lpstrName
= arial_font
;
1239 fontdesc
.cySize
.int64
= 12 * 10000; /* 12 pt */
1240 fontdesc
.sWeight
= FW_NORMAL
;
1241 fontdesc
.sCharset
= ANSI_CHARSET
;
1242 fontdesc
.fItalic
= FALSE
;
1243 fontdesc
.fUnderline
= FALSE
;
1244 fontdesc
.fStrikethrough
= FALSE
;
1246 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1247 EXPECT_HR(hr
, S_OK
);
1248 IFont_Release(font
);
1250 /* play with cbSizeofstruct value */
1251 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)-1;
1252 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1253 EXPECT_HR(hr
, S_OK
);
1254 IFont_Release(font
);
1256 fontdesc
.cbSizeofstruct
= sizeof(fontdesc
)+1;
1257 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1258 EXPECT_HR(hr
, S_OK
);
1259 IFont_Release(font
);
1261 fontdesc
.cbSizeofstruct
= 0;
1262 hr
= pOleCreateFontIndirect(&fontdesc
, &IID_IFont
, (void**)&font
);
1263 EXPECT_HR(hr
, S_OK
);
1264 IFont_Release(font
);
1266 hr
= OleInitialize(NULL
);
1267 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1269 hr
= CoGetClassObject(&CLSID_StdFont
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&unk
);
1270 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1272 hr
= IUnknown_QueryInterface(unk
, &IID_IUnknown
, (void**)&unk2
);
1273 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1275 IUnknown_Release(unk
);
1276 IUnknown_Release(unk2
);
1283 hOleaut32
= GetModuleHandleA("oleaut32.dll");
1284 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
1285 if (!pOleCreateFontIndirect
)
1287 win_skip("OleCreateFontIndirect not available\n");
1291 test_QueryInterface();
1294 test_font_events_disp();
1295 test_GetIDsOfNames();
1298 test_ReleaseHfont();
1301 test_hfont_lifetime();
1303 test_OleCreateFontIndirect();