ReactOS 0.4.17-dev-357-ga8f14ff
olefont.c
Go to the documentation of this file.
1/*
2 * OLEFONT test program
3 *
4 * Copyright 2003 Marcus Meissner
5 * Copyright 2006 (Google) Benjamin Arai
6 *
7 *
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.
12 *
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.
17 *
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
21 */
22
23#include <stdarg.h>
24#include <stdio.h>
25#include <math.h>
26#include <float.h>
27
28#define COBJMACROS
29
30#include <wine/test.h>
31#include <windef.h>
32#include <winbase.h>
33#include <winuser.h>
34#include <wingdi.h>
35#include <winnls.h>
36#include <winerror.h>
37#include <winnt.h>
38#include <initguid.h>
39#include <wtypes.h>
40#include <olectl.h>
41#include <ocidl.h>
42
43DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
44
45static WCHAR MSSansSerif_font[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f',0};
46static WCHAR system_font[] = { 'S','y','s','t','e','m',0 };
47static WCHAR arial_font[] = { 'A','r','i','a','l',0 };
48static WCHAR marlett_font[] = { 'M','a','r','l','e','t','t',0 };
49
51
52static HRESULT (WINAPI *pOleCreateFontIndirect)(LPFONTDESC,REFIID,LPVOID*);
53
54#define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
55static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
56{
57 IUnknown *iface = iface_ptr;
58 HRESULT hr, expected_hr;
59 IUnknown *unk;
60
61 expected_hr = supported ? S_OK : E_NOINTERFACE;
62
63 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
64 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
65 if (SUCCEEDED(hr))
66 IUnknown_Release(unk);
67}
68
69#define EXPECT_HR(hr,hr_exp) \
70 ok(hr == hr_exp, "got 0x%08lx, expected 0x%08lx\n", hr, hr_exp)
71
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. */
76static void test_ifont_size(LONGLONG size, LONG ratio_logical, LONG ratio_himetric,
77 LONG hfont_height, const char * test_name)
78{
80 LPVOID pvObj = NULL;
81 IFont* ifnt = NULL;
82 HFONT hfont;
83 LOGFONTA lf;
84 CY psize;
86 DWORD rtnval;
87
88 fd.cbSizeofstruct = sizeof(FONTDESC);
89 fd.lpstrName = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
90 fd.cySize.int64 = size;
91 fd.sWeight = 0;
92 fd.sCharset = 0;
93 fd.fItalic = FALSE;
94 fd.fUnderline = FALSE;
95 fd.fStrikethrough = FALSE;
96
97 /* Create font, test that it worked. */
98 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
99 ifnt = pvObj;
100 ok(hres == S_OK,"%s: OCFI returns 0x%08lx instead of S_OK.\n",
101 test_name, hres);
102 ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);
103
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);
108
109 /* Read back size. */
110 hres = IFont_get_Size(ifnt, &psize);
111 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08lx instead of S_OK.\n",
112 test_name, hres);
113
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, psize.Lo, psize.Hi, fd.cySize.Lo, fd.cySize.Hi);
118
119 /* Check hFont size. */
120 hres = IFont_get_hFont (ifnt, &hfont);
121 ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08lx instead of S_OK.\n",
122 test_name, hres);
123 rtnval = GetObjectA(hfont, sizeof(LOGFONTA), &lf);
124 ok(rtnval > 0, "GetObject(hfont) failed\n");
125
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);
130
131 /* Free IFont. */
132 IFont_Release(ifnt);
133}
134
135static void test_ifont_sizes(void)
136{
137 /* Test various size operations and conversions. */
138 /* Add more as needed. */
139
140 /* Results of first 2 tests depend on display resolution. */
141 HDC hdc = GetDC(0);
142 LONG dpi = GetDeviceCaps(hdc, LOGPIXELSY); /* expected results depend on display DPI */
143 ReleaseDC(0, hdc);
144 if(dpi == 96) /* normal resolution display */
145 {
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 */
149 {
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 */
153 {
154 test_ifont_size(180000, 0, 0, -30, "default"); /* normal font */
155 test_ifont_size(186000, 0, 0, -31, "rounding"); /* test rounding */
156 } else
157 skip("Skipping resolution dependent font size tests - display resolution is %ld\n", dpi);
158
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 */
164
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");
169
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");
174
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");
179
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");
184
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");
189
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");
194
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");
199}
200
201static void test_interfaces(void)
202{
203 HRESULT hr;
204 IFont *font = NULL;
205
206 hr = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
208
209 hr = pOleCreateFontIndirect(NULL, &IID_IFont, (void **)&font);
210 EXPECT_HR(hr, S_OK);
211 ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
212
221
222 IFont_Release(font);
223}
224
225static void test_type_info(void)
226{
227 LPVOID pvObj = NULL;
229 IFontDisp* fontdisp = NULL;
230 ITypeInfo* pTInfo;
231 WCHAR name_Name[] = {'N','a','m','e',0};
232 BSTR names[3];
233 UINT n;
236 DISPPARAMS dispparams;
237 VARIANT varresult;
238
239 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
240 fontdisp = pvObj;
241
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");
245
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");
251
252 ITypeInfo_Release(pTInfo);
253
254 dispparams.cNamedArgs = 0;
255 dispparams.rgdispidNamedArgs = NULL;
256 dispparams.cArgs = 0;
257 dispparams.rgvarg = NULL;
258 VariantInit(&varresult);
259 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
260 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
261 NULL, NULL);
262 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08lx instead of S_OK.\n", hres);
263 VariantClear(&varresult);
264
265 IFontDisp_Release(fontdisp);
266}
267
269{
271 {
272 IFontEventsDisp_AddRef(iface);
273 *ppvObject = iface;
274 return S_OK;
275 }
276 else
277 {
278 *ppvObject = NULL;
279 return E_NOINTERFACE;
280 }
281}
282
284 IFontEventsDisp *iface)
285{
286 return 2;
287}
288
290 IFontEventsDisp *iface)
291{
292 return 1;
293}
294
296{
297 ok(0, "unexpected call\n");
298 return E_NOTIMPL;
299}
300
302{
303 ok(0, "unexpected call\n");
304 return E_NOTIMPL;
305}
306
308 DISPID *dispid)
309{
310 ok(0, "unexpected call\n");
311 return E_NOTIMPL;
312}
313
316
318 IFontEventsDisp *iface,
319 DISPID dispid,
320 REFIID riid,
321 LCID lcid,
322 WORD wFlags,
323 DISPPARAMS *pDispParams,
324 VARIANT *pVarResult,
325 EXCEPINFO *pExcepInfo,
326 UINT *puArgErr)
327{
328 VARIANTARG *arg0 = &pDispParams->rgvarg[0];
329
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));
335
338 return S_OK;
339}
340
341static IFontEventsDispVtbl FontEventsDisp_Vtbl =
342{
350};
351
353
355 {
357 const WCHAR *name;
358 };
359
360static void test_font_events_disp(void)
361{
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};
370
371 static const struct font_dispid font_dispids[] =
372 {
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 },
381 };
382
383 IFont *pFont;
384 IFont *pFont2;
386 IConnectionPoint *pCP;
387 FONTDESC fontdesc;
388 HRESULT hr;
389 DWORD dwCookie;
390 IFontDisp *pFontDisp;
391 DISPPARAMS dispparams;
392 VARIANTARG vararg;
393 INT i;
394
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;
403
404 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
405 EXPECT_HR(hr, S_OK);
406
407 hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
408 EXPECT_HR(hr, S_OK);
409
410 hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
411 EXPECT_HR(hr, S_OK);
412 IConnectionPointContainer_Release(pCPC);
413
414 hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
415 EXPECT_HR(hr, S_OK);
416 IConnectionPoint_Release(pCP);
417
420 hr = IFont_put_Bold(pFont, TRUE);
421 EXPECT_HR(hr, S_OK);
422
423 ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
425
426 hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
427 EXPECT_HR(hr, S_OK);
428
429 for (i = 0; i < ARRAY_SIZE(font_dispids); i++)
430 {
431 switch (font_dispids[i].dispid)
432 {
433 case DISPID_FONT_NAME:
434 {
435 static const WCHAR arialW[] = {'A','r','i','a','l',0};
436 V_VT(&vararg) = VT_BSTR;
437 V_BSTR(&vararg) = SysAllocString(arialW);
438 break;
439 }
440 case DISPID_FONT_SIZE:
441 V_VT(&vararg) = VT_CY;
442 V_CY(&vararg).Lo = 25;
443 V_CY(&vararg).Hi = 0;
444 break;
445 case DISPID_FONT_BOLD:
446 V_VT(&vararg) = VT_BOOL;
447 V_BOOL(&vararg) = VARIANT_FALSE;
448 break;
452 V_VT(&vararg) = VT_BOOL;
453 V_BOOL(&vararg) = VARIANT_TRUE;
454 break;
456 V_VT(&vararg) = VT_I2;
457 V_I2(&vararg) = FW_BLACK;
458 break;
460 V_VT(&vararg) = VT_I2;
461 V_I2(&vararg) = 1;
462 break;
463 default:
464 ;
465 }
466
467 dispparams.cNamedArgs = 0;
468 dispparams.rgdispidNamedArgs = NULL;
469 dispparams.cArgs = 1;
470 dispparams.rgvarg = &vararg;
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,
476 if (hr == S_OK)
477 {
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));
481 }
482 VariantClear(&vararg);
483 }
484
485 IFontDisp_Release(pFontDisp);
486
487 hr = IFont_Clone(pFont, &pFont2);
488 EXPECT_HR(hr, S_OK);
489 IFont_Release(pFont);
490
491 /* this test shows that the notification routine isn't called again */
493 hr = IFont_put_Bold(pFont2, FALSE);
494 EXPECT_HR(hr, S_OK);
496
497 IFont_Release(pFont2);
498}
499
500static 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)
504{
505 LPVOID pvObj = NULL;
506 IFontDisp *fontdisp = NULL;
508 DISPID rgDispId[2] = {0xdeadbeef, 0xdeadbeef};
509 LPOLESTR names[2] = {w_name_1, w_name_2};
510
511 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
512 fontdisp = pvObj;
513
514 hres = IFontDisp_GetIDsOfNames(fontdisp, &IID_NULL, names, numnames,
515 lcid, rgDispId);
516
517 /* test hres */
518 ok(hres == hres_expect,
519 "GetIDsOfNames: \"%s\", \"%s\" returns 0x%08lx, expected 0x%08lx.\n",
520 a_name_1, a_name_2, hres, hres_expect);
521
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);
526
527 /* test second DISPID is present */
528 if (numnames == 2)
529 {
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);
533 }
534
535 IFontDisp_Release(fontdisp);
536}
537
538static void test_GetIDsOfNames(void)
539{
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};
551
556
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,
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,
570 test_names_ids(name_Weight, "Weight", NULL, "", en_us,
572 test_names_ids(name_Charset, "Charset", NULL, "", en_us,
574
575 /* Capitalization doesn't matter. */
576 test_names_ids(name_nAmE, "nAmE", NULL, "", en_us,
577 DISPID_FONT_NAME, 0, S_OK,1);
578
579 /* Unknown name. */
580 test_names_ids(name_Foo, "Foo", NULL, "", en_us,
581 DISPID_UNKNOWN, 0, DISP_E_UNKNOWNNAME,1);
582
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);
589
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);
595
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);
603
604 /* Crazy locale ID? */
605 test_names_ids(name_Name, "Name", NULL, "", -1,
606 DISPID_FONT_NAME, 0, S_OK,1);
607}
608
609static void test_Invoke(void)
610{
611 IFontDisp *fontdisp;
612 HRESULT hr;
613 VARIANTARG vararg;
614 DISPPARAMS dispparams;
615 VARIANT varresult;
616
617 hr = pOleCreateFontIndirect(NULL, &IID_IFontDisp, (void **)&fontdisp);
618 EXPECT_HR(hr, S_OK);
619
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);
628
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);
633
634 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYPUT, NULL, NULL, NULL, NULL);
636
637 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
639
640 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
641 EXPECT_HR(hr, S_OK);
642
643 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_METHOD, NULL, &varresult, NULL, NULL);
645
646 hr = IFontDisp_Invoke(fontdisp, 0xdeadbeef, &IID_NULL, 0, DISPATCH_PROPERTYGET, NULL, &varresult, NULL, NULL);
648
649 dispparams.cArgs = 1;
650 dispparams.rgvarg = &vararg;
651 hr = IFontDisp_Invoke(fontdisp, DISPID_FONT_BOLD, &IID_NULL, 0, DISPATCH_PROPERTYGET, &dispparams, &varresult, NULL, NULL);
652 EXPECT_HR(hr, S_OK);
653
654 IFontDisp_Release(fontdisp);
655}
656
657static void test_IsEqual(void)
658{
659 FONTDESC fd;
660 IFont* ifnt = NULL;
661 IFont* ifnt2 = NULL;
663
664 /* Basic font description */
665 fd.cbSizeofstruct = sizeof(FONTDESC);
666 fd.lpstrName = system_font;
667 fd.cySize.Lo = 100;
668 fd.cySize.Hi = 100;
669 fd.sWeight = 0;
670 fd.sCharset = 0;
671 fd.fItalic = FALSE;
672 fd.fUnderline = FALSE;
673 fd.fStrikethrough = FALSE;
674
675 /* Create font */
676 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);
677
678 /* Test equal fonts */
679 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
680 hres = IFont_IsEqual(ifnt,ifnt2);
681 ok(hres == S_OK,
682 "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08lx\n",hres);
683 IFont_Release(ifnt2);
684
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);
689
690 /* Test strName */
691 fd.lpstrName = arial_font;
692 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
693 hres = IFont_IsEqual(ifnt,ifnt2);
694 ok(hres == S_FALSE,
695 "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08lx\n",hres);
696 fd.lpstrName = system_font;
697 IFont_Release(ifnt2);
698
699 /* Test lo font size */
700 fd.cySize.Lo = 10000;
701 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
702 hres = IFont_IsEqual(ifnt,ifnt2);
703 ok(hres == S_FALSE,
704 "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08lx\n",hres);
705 fd.cySize.Lo = 100;
706 IFont_Release(ifnt2);
707
708 /* Test hi font size */
709 fd.cySize.Hi = 10000;
710 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
711 hres = IFont_IsEqual(ifnt,ifnt2);
712 ok(hres == S_FALSE,
713 "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08lx\n",hres);
714 fd.cySize.Hi = 100;
715 IFont_Release(ifnt2);
716
717 /* Test font weight */
718 fd.sWeight = 100;
719 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
720 hres = IFont_IsEqual(ifnt,ifnt2);
721 ok(hres == S_FALSE,
722 "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08lx\n",hres);
723 fd.sWeight = 0;
724 IFont_Release(ifnt2);
725
726 /* Test charset */
727 fd.sCharset = 1;
728 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
729 hres = IFont_IsEqual(ifnt,ifnt2);
730 ok(hres == S_FALSE,
731 "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08lx\n",hres);
732 fd.sCharset = 0;
733 IFont_Release(ifnt2);
734
735 /* Test italic setting */
736 fd.fItalic = TRUE;
737 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
738 hres = IFont_IsEqual(ifnt,ifnt2);
739 ok(hres == S_FALSE,
740 "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08lx\n",hres);
741 fd.fItalic = FALSE;
742 IFont_Release(ifnt2);
743
744 /* Test underline setting */
745 fd.fUnderline = TRUE;
746 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
747 hres = IFont_IsEqual(ifnt,ifnt2);
748 ok(hres == S_FALSE,
749 "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08lx\n",hres);
750 fd.fUnderline = FALSE;
751 IFont_Release(ifnt2);
752
753 /* Test strikethrough setting */
754 fd.fStrikethrough = TRUE;
755 pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
756 hres = IFont_IsEqual(ifnt,ifnt2);
757 ok(hres == S_FALSE,
758 "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08lx\n",hres);
759 fd.fStrikethrough = FALSE;
760 IFont_Release(ifnt2);
761
762 /* Free IFont. */
763 IFont_Release(ifnt);
764}
765
766static void test_ReleaseHfont(void)
767{
768 FONTDESC fd;
769 LPVOID pvObj1 = NULL;
770 LPVOID pvObj2 = NULL;
771 IFont* ifnt1 = NULL;
772 IFont* ifnt2 = NULL;
773 HFONT hfnt1 = 0;
774 HFONT hfnt2 = 0;
776
777 /* Basic font description */
778 fd.cbSizeofstruct = sizeof(FONTDESC);
779 fd.lpstrName = system_font;
780 fd.cySize.Lo = 100;
781 fd.cySize.Hi = 100;
782 fd.sWeight = 0;
783 fd.sCharset = 0;
784 fd.fItalic = FALSE;
785 fd.fUnderline = FALSE;
786 fd.fStrikethrough = FALSE;
787
788 /* Create HFONTs and IFONTs */
789 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
790 ifnt1 = pvObj1;
791 IFont_get_hFont(ifnt1,&hfnt1);
792 fd.lpstrName = arial_font;
793 pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
794 ifnt2 = pvObj2;
795 IFont_get_hFont(ifnt2,&hfnt2);
796
797 /* Try invalid HFONT */
798 hres = IFont_ReleaseHfont(ifnt1,NULL);
800 "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08lx\n",
801 hres);
802
803 /* Try to add a bad HFONT */
804 hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
805 ok(hres == S_FALSE,
806 "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
807 hres);
808
809 /* Release all refs */
810 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
811 ok(hres == S_OK,
812 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
813 hres);
814
815 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
816 ok(hres == S_OK,
817 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
818 hres);
819
820 /* Check that both lists are empty */
821 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
822 ok(hres == S_FALSE,
823 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
824 hres);
825
826 /* The list should be empty */
827 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
828 ok(hres == S_FALSE,
829 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
830 hres);
831
832 IFont_Release(ifnt1);
833 IFont_Release(ifnt2);
834}
835
836static void test_AddRefHfont(void)
837{
838 FONTDESC fd;
839 IFont* ifnt1 = NULL;
840 IFont* ifnt2 = NULL;
841 IFont* ifnt3 = NULL;
842 HFONT hfnt1 = 0;
843 HFONT hfnt2 = 0;
844 HFONT hfnt3 = 0;
846
847 /* Basic font description */
848 fd.cbSizeofstruct = sizeof(FONTDESC);
849 fd.lpstrName = system_font;
850 fd.cySize.Lo = 100;
851 fd.cySize.Hi = 100;
852 fd.sWeight = 0;
853 fd.sCharset = 0;
854 fd.fItalic = FALSE;
855 fd.fUnderline = FALSE;
856 fd.fStrikethrough = FALSE;
857
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);
864
865 /* Try invalid HFONT */
866 hres = IFont_AddRefHfont(ifnt1,NULL);
868 "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08lx\n",
869 hres);
870
871 /* Try to add a bad HFONT */
872 hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
873 ok(hres == S_FALSE,
874 "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08lx\n",
875 hres);
876
877 /* Add simple IFONT HFONT pair */
878 hres = IFont_AddRefHfont(ifnt1,hfnt1);
879 ok(hres == S_OK,
880 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
881 hres);
882
883 /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
884 hres = IFont_AddRefHfont(ifnt2,hfnt1);
885 ok(hres == S_OK,
886 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
887 hres);
888
889 /* Release all hfnt1 refs */
890 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
891 ok(hres == S_OK,
892 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
893 hres);
894
895 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
896 ok(hres == S_OK,
897 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
898 hres);
899
900 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
901 ok(hres == S_OK,
902 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
903 hres);
904
905 /* Check if hfnt1 is empty */
906 hres = IFont_ReleaseHfont(ifnt1,hfnt1);
907 ok(hres == S_FALSE,
908 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
909 hres);
910
911 /* Release all hfnt2 refs */
912 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
913 ok(hres == S_OK,
914 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
915 hres);
916
917 /* Check if hfnt2 is empty */
918 hres = IFont_ReleaseHfont(ifnt2,hfnt2);
919 ok(hres == S_FALSE,
920 "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08lx\n",
921 hres);
922
923 /* Show that releasing an IFONT does not always release it from the HFONT cache. */
924
925 IFont_Release(ifnt1);
926
927 /* Add a reference for destroyed hfnt1 */
928 hres = IFont_AddRefHfont(ifnt2,hfnt1);
929 ok(hres == S_OK,
930 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
931 hres);
932
933 /* Decrement reference for destroyed hfnt1 */
934 hres = IFont_ReleaseHfont(ifnt2,hfnt1);
935 ok(hres == S_OK ||
936 hres == S_FALSE, /* <= win2k */
937 "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08lx\n",
938 hres);
939
940 /* Shows that releasing all IFONT's does clear the HFONT cache. */
941
942 IFont_Release(ifnt2);
943
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);
948
949 /* Add a reference for destroyed hfnt1 */
950 hres = IFont_AddRefHfont(ifnt3,hfnt1);
951 ok(hres == S_FALSE,
952 "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08lx\n",
953 hres);
954
955 /* Decrement reference for destroyed hfnt1 */
956 hres = IFont_ReleaseHfont(ifnt3,hfnt1);
957 ok(hres == S_FALSE,
958 "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08lx\n",
959 hres);
960
961 IFont_Release(ifnt3);
962}
963
964static void test_returns(void)
965{
966 IFont *pFont;
967 FONTDESC fontdesc;
968 HRESULT hr;
969
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;
978
979 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
980 EXPECT_HR(hr, S_OK);
981
982 hr = IFont_put_Name(pFont, NULL);
984
985 hr = IFont_get_Name(pFont, NULL);
987
988 hr = IFont_get_Size(pFont, NULL);
990
991 hr = IFont_get_Bold(pFont, NULL);
993
994 IFont_Release(pFont);
995}
996
997static void test_hfont_lifetime(void)
998{
999 IFont *font, *font2;
1000 FONTDESC fontdesc;
1001 HRESULT hr;
1002 HFONT hfont, first_hfont = NULL;
1003 CY size;
1004 DWORD obj_type;
1005 int i;
1006
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;
1015
1016 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1017 EXPECT_HR(hr, S_OK);
1018
1019 hr = IFont_get_hFont(font, &hfont);
1020 EXPECT_HR(hr, S_OK);
1021
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++)
1025 {
1026 HFONT last_hfont = hfont;
1027
1028 size.int64 = (i + 10) * 20000;
1029
1030 obj_type = GetObjectType(hfont);
1031 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1032
1033 hr = IFont_put_Size(font, size);
1034 EXPECT_HR(hr, S_OK);
1035
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);
1039
1040 hr = IFont_get_hFont(font, &hfont);
1041 EXPECT_HR(hr, S_OK);
1042 }
1043
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++)
1047 {
1048 size.int64 = (i + 10) * 20000;
1049
1050 obj_type = GetObjectType(hfont);
1051 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1052
1053 hr = IFont_put_Size(font, size);
1054 EXPECT_HR(hr, S_OK);
1055
1056 hr = IFont_get_hFont(font, &hfont);
1057 EXPECT_HR(hr, S_OK);
1058
1059 hr = IFont_AddRefHfont(font, hfont);
1060 EXPECT_HR(hr, S_OK);
1061
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);
1065 }
1066
1067 IFont_Release(font);
1068
1069 /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
1070 through re-realization */
1071
1072 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1073 EXPECT_HR(hr, S_OK);
1074
1075 hr = IFont_get_hFont(font, &hfont);
1076 EXPECT_HR(hr, S_OK);
1077
1078 for(i = 0; i < 100; i++)
1079 {
1080 HFONT last_hfont = hfont;
1081
1082 size.int64 = (i + 10) * 20000;
1083
1084 obj_type = GetObjectType(hfont);
1085 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1086
1087 hr = IFont_put_Size(font, size);
1088 EXPECT_HR(hr, S_OK);
1089
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);
1093
1094 hr = IFont_get_hFont(font, &hfont);
1095 EXPECT_HR(hr, S_OK);
1096
1097 hr = IFont_AddRefHfont(font, hfont);
1098 EXPECT_HR(hr, S_OK);
1099
1100 hr = IFont_ReleaseHfont(font, hfont);
1101 EXPECT_HR(hr, S_OK);
1102 }
1103
1104 /* Interestingly if we release a nonexistent reference on the hfont,
1105 * it persists until the font object is released
1106 */
1107 for(i = 0; i < 100; i++)
1108 {
1109 size.int64 = (i + 10) * 20000;
1110
1111 obj_type = GetObjectType(hfont);
1112 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1113
1114 hr = IFont_put_Size(font, size);
1115 EXPECT_HR(hr, S_OK);
1116
1117 hr = IFont_get_hFont(font, &hfont);
1118 EXPECT_HR(hr, S_OK);
1119
1120 hr = IFont_ReleaseHfont(font, hfont);
1121 EXPECT_HR(hr, S_OK);
1122
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);
1126 }
1127
1128 IFont_Release(font);
1129
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 */
1133
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);
1138
1139 hr = IFont_get_hFont(font, &hfont);
1140 EXPECT_HR(hr, S_OK);
1141 hr = IFont_get_hFont(font2, &first_hfont);
1142 EXPECT_HR(hr, S_OK);
1143 todo_wine
1144 ok(hfont == first_hfont, "fonts differ\n");
1145 hr = IFont_ReleaseHfont(font, hfont);
1146 EXPECT_HR(hr, S_OK);
1147 hr = IFont_ReleaseHfont(font, hfont);
1148 todo_wine
1149 EXPECT_HR(hr, S_OK);
1150 hr = IFont_ReleaseHfont(font, hfont);
1152
1153 obj_type = GetObjectType(hfont);
1154 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1155
1156 IFont_Release(font);
1157
1158 obj_type = GetObjectType(hfont);
1159 ok(obj_type == OBJ_FONT, "got obj type %ld\n", obj_type);
1160
1161 IFont_Release(font2);
1162}
1163
1164static void test_realization(void)
1165{
1166 IFont *font;
1167 FONTDESC fontdesc;
1168 HRESULT hr;
1169 BSTR name;
1170 SHORT cs;
1171
1172 /* Try to create a symbol only font (marlett) with charset
1173 set to ANSI. This will result in another, ANSI, font
1174 being selected */
1175 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1176 fontdesc.lpstrName = marlett_font;
1177 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1178 fontdesc.sWeight = FW_NORMAL;
1179 fontdesc.sCharset = ANSI_CHARSET;
1180 fontdesc.fItalic = FALSE;
1181 fontdesc.fUnderline = FALSE;
1182 fontdesc.fStrikethrough = FALSE;
1183
1184 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1185 EXPECT_HR(hr, S_OK);
1186
1187 hr = IFont_get_Charset(font, &cs);
1188 EXPECT_HR(hr, S_OK);
1189 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1190
1191 IFont_Release(font);
1192
1193 /* Now create an ANSI font and change the name to marlett */
1194
1195 fontdesc.lpstrName = arial_font;
1196
1197 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
1198 EXPECT_HR(hr, S_OK);
1199
1200 hr = IFont_get_Charset(font, &cs);
1201 EXPECT_HR(hr, S_OK);
1202 ok(cs == ANSI_CHARSET, "got charset %d\n", cs);
1203
1205 hr = IFont_put_Name(font, name);
1206 EXPECT_HR(hr, S_OK);
1208
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));
1213
1214 hr = IFont_get_Charset(font, &cs);
1215 EXPECT_HR(hr, S_OK);
1216 ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);
1217
1218 IFont_Release(font);
1219}
1220
1222{
1223 FONTDESC fontdesc;
1224 IUnknown *unk, *unk2;
1225 IFont *font;
1226 HRESULT hr;
1227 WCHAR str_empty[] = {0};
1228
1229 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1230 fontdesc.lpstrName = arial_font;
1231 fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
1232 fontdesc.sWeight = FW_NORMAL;
1233 fontdesc.sCharset = ANSI_CHARSET;
1234 fontdesc.fItalic = FALSE;
1235 fontdesc.fUnderline = FALSE;
1236 fontdesc.fStrikethrough = FALSE;
1237
1238 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1239 EXPECT_HR(hr, S_OK);
1240 IFont_Release(font);
1241
1242 /* play with cbSizeofstruct value */
1243 fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
1244 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1245 EXPECT_HR(hr, S_OK);
1246 IFont_Release(font);
1247
1248 fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
1249 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1250 EXPECT_HR(hr, S_OK);
1251 IFont_Release(font);
1252
1253 fontdesc.cbSizeofstruct = 0;
1254 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1255 EXPECT_HR(hr, S_OK);
1256 IFont_Release(font);
1257
1258 /* Test NULL name */
1259 fontdesc.cbSizeofstruct = sizeof(fontdesc);
1260 fontdesc.lpstrName = NULL;
1261 font = (IFont*)0xdeadbeef;
1262 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1264 ok(font == 0, "Got %p\n", font);
1265
1266 /* Test empty Name */
1267 fontdesc.lpstrName = str_empty;
1268 font = NULL;
1269 hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
1270 EXPECT_HR(hr, S_OK);
1271 ok(font != 0, "Got NULL font\n");
1272 IFont_Release(font);
1273
1275 ok(hr == S_OK, "got 0x%08lx\n", hr);
1276
1277 hr = CoGetClassObject(&CLSID_StdFont, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&unk);
1278 ok(hr == S_OK, "got 0x%08lx\n", hr);
1279
1280 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void**)&unk2);
1281 ok(hr == S_OK, "got 0x%08lx\n", hr);
1282
1283 IUnknown_Release(unk);
1284 IUnknown_Release(unk2);
1285
1287}
1288
1290{
1291 hOleaut32 = GetModuleHandleA("oleaut32.dll");
1292 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
1293 if (!pOleCreateFontIndirect)
1294 {
1295 win_skip("OleCreateFontIndirect not available\n");
1296 return;
1297 }
1298
1304 test_Invoke();
1305 test_IsEqual();
1308 test_returns();
1312}
static HFONT hfont
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
static const WCHAR nameW[]
Definition: main.c:49
#define ARRAY_SIZE(A)
Definition: main.h:20
const GUID IID_IUnknown
const GUID IID_IClassFactory
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscontext, COSERVERINFO *server_info, REFIID riid, void **obj)
Definition: combase.c:1925
#define GetProcAddress(x, y)
Definition: compat.h:753
OLECHAR * BSTR
Definition: compat.h:2293
@ VT_BSTR
Definition: compat.h:2303
@ VT_CY
Definition: compat.h:2301
@ VT_BOOL
Definition: compat.h:2306
@ VT_I2
Definition: compat.h:2297
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
LCID lcid
Definition: locale.c:5660
static const WCHAR sizeW[]
Definition: editor.c:79
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:162
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:218
#define abs(i)
Definition: fconv.c:206
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble n
Definition: glext.h:7729
GLuint GLuint * names
Definition: glext.h:11545
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static const WCHAR charsetW[]
Definition: htmlmeta.c:149
#define cs
Definition: i386-dis.c:442
REFIID riid
Definition: atlbase.h:39
Definition: ocidl.idl:76
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
#define GUID_NULL
Definition: ks.h:106
#define win_skip
Definition: minitest.h:67
#define todo_wine
Definition: minitest.h:80
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
HRESULT hres
Definition: protocol.c:465
static const char * test_name
Definition: run.c:194
static const CLSID CLSID_StdFont
Definition: compobj.c:92
static WCHAR MSSansSerif_font[]
Definition: olefont.c:45
static void test_font_events_disp(void)
Definition: olefont.c:360
static void test_returns(void)
Definition: olefont.c:964
static HRESULT WINAPI FontEventsDisp_GetIDsOfNames(IFontEventsDisp *iface, REFIID riid, LPOLESTR *names, UINT cNames, LCID lcid, DISPID *dispid)
Definition: olefont.c:307
static ULONG WINAPI FontEventsDisp_AddRef(IFontEventsDisp *iface)
Definition: olefont.c:283
static void test_names_ids(WCHAR *w_name_1, const char *a_name_1, WCHAR *w_name_2, const char *a_name_2, LCID lcid, DISPID id_1, DISPID id_2, HRESULT hres_expect, int numnames)
Definition: olefont.c:500
static BSTR fonteventsdisp_invoke_arg0
Definition: olefont.c:315
static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
Definition: olefont.c:55
#define EXPECT_HR(hr, hr_exp)
Definition: olefont.c:69
static HMODULE hOleaut32
Definition: olefont.c:50
static void test_IsEqual(void)
Definition: olefont.c:657
static HRESULT WINAPI FontEventsDisp_QueryInterface(IFontEventsDisp *iface, REFIID riid, void **ppvObject)
Definition: olefont.c:268
static WCHAR marlett_font[]
Definition: olefont.c:48
static void test_realization(void)
Definition: olefont.c:1164
static IFontEventsDisp FontEventsDisp
Definition: olefont.c:352
static ULONG WINAPI FontEventsDisp_Release(IFontEventsDisp *iface)
Definition: olefont.c:289
static void test_hfont_lifetime(void)
Definition: olefont.c:997
static void test_interfaces(void)
Definition: olefont.c:201
static void test_Invoke(void)
Definition: olefont.c:609
static void test_type_info(void)
Definition: olefont.c:225
static WCHAR system_font[]
Definition: olefont.c:46
static HRESULT WINAPI FontEventsDisp_GetTypeInfoCount(IFontEventsDisp *iface, UINT *pctinfo)
Definition: olefont.c:295
static IFontEventsDispVtbl FontEventsDisp_Vtbl
Definition: olefont.c:341
static HRESULT WINAPI FontEventsDisp_Invoke(IFontEventsDisp *iface, DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
Definition: olefont.c:317
static void test_ifont_sizes(void)
Definition: olefont.c:135
#define check_interface(a, b, c)
Definition: olefont.c:54
static void test_ifont_size(LONGLONG size, LONG ratio_logical, LONG ratio_himetric, LONG hfont_height, const char *test_name)
Definition: olefont.c:76
static void test_AddRefHfont(void)
Definition: olefont.c:836
static void test_GetIDsOfNames(void)
Definition: olefont.c:538
static void test_OleCreateFontIndirect(void)
Definition: olefont.c:1221
static int fonteventsdisp_invoke_called
Definition: olefont.c:314
static WCHAR arial_font[]
Definition: olefont.c:47
static void test_ReleaseHfont(void)
Definition: olefont.c:766
static HRESULT WINAPI FontEventsDisp_GetTypeInfo(IFontEventsDisp *iface, UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
Definition: olefont.c:301
static VARIANTARG static DISPID
Definition: ordinal.c:49
Definition: mk_font.cpp:20
unsigned int UINT
Definition: ndis.h:50
#define LOCALE_NEUTRAL
#define SORT_DEFAULT
#define MAKELCID(lgid, srtid)
#define OBJ_FONT
Definition: objidl.idl:1019
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
#define V_BOOL(A)
Definition: oleauto.h:224
#define DISPATCH_PROPERTYPUT
Definition: oleauto.h:1008
#define DISPATCH_METHOD
Definition: oleauto.h:1006
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
#define V_CY(A)
Definition: oleauto.h:229
#define DISPATCH_PROPERTYGET
Definition: oleauto.h:1007
#define V_I2(A)
Definition: oleauto.h:245
struct tagFONTDESC FONTDESC
#define DISPID_FONT_SIZE
Definition: olectl.h:428
#define DISPID_FONT_NAME
Definition: olectl.h:427
struct tagFONTDESC * LPFONTDESC
#define DISPID_FONT_BOLD
Definition: olectl.h:429
#define DISPID_FONT_STRIKE
Definition: olectl.h:432
#define DISPID_FONT_ITALIC
Definition: olectl.h:430
#define CTL_E_INVALIDPROPERTYVALUE
Definition: olectl.h:292
#define DISPID_FONT_CHARSET
Definition: olectl.h:434
#define DISPID_FONT_WEIGHT
Definition: olectl.h:433
#define DISPID_FONT_CHANGED
Definition: olectl.h:435
#define DISPID_FONT_UNDER
Definition: olectl.h:431
const GUID IID_IConnectionPointContainer
const GUID IID_IFontEventsDisp
const GUID IID_IDispatch
const GUID IID_IFont
const GUID IID_IFontDisp
const GUID IID_IPersistStreamInit
short WCHAR
Definition: pedump.c:58
short SHORT
Definition: pedump.c:59
long LONG
Definition: pedump.c:60
const GUID IID_IPersist
Definition: proxy.cpp:14
const GUID IID_IPersistStream
Definition: proxy.cpp:13
const GUID IID_IPersistPropertyBag
Definition: proxy.cpp:11
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
#define IID_NULL
Definition: guiddef.h:98
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_FRENCH
Definition: nls.h:242
#define LANG_ENGLISH
Definition: nls.h:52
DWORD LCID
Definition: nls.h:13
#define LANG_FRENCH
Definition: nls.h:58
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:171
static int fd
Definition: io.c:51
LONG lfHeight
Definition: dimm.idl:42
DISPID dispid
Definition: olefont.c:356
const WCHAR * name
Definition: olefont.c:357
Definition: parser.c:49
Definition: name.c:39
UINT cbSizeofstruct
Definition: olectl.h:119
SHORT sWeight
Definition: olectl.h:122
BOOL fItalic
Definition: olectl.h:124
BOOL fUnderline
Definition: olectl.h:125
BOOL fStrikethrough
Definition: olectl.h:126
SHORT sCharset
Definition: olectl.h:123
CY cySize
Definition: olectl.h:121
LPOLESTR lpstrName
Definition: olectl.h:120
int64_t LONGLONG
Definition: typedefs.h:68
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
Definition: compat.h:2255
LONGLONG int64
Definition: compat.h:2265
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
#define dpi
Definition: sysparams.c:23
WINBASEAPI _In_ DWORD _Out_ _In_ WORD wFlags
Definition: wincon_undoc.h:337
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
#define E_NOINTERFACE
Definition: winerror.h:3479
#define DISP_E_UNKNOWNINTERFACE
Definition: winerror.h:3614
#define DISP_E_BADPARAMCOUNT
Definition: winerror.h:3626
#define DISP_E_MEMBERNOTFOUND
Definition: winerror.h:3615
#define E_POINTER
Definition: winerror.h:3480
#define DISP_E_PARAMNOTOPTIONAL
Definition: winerror.h:3627
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
int WINAPI GetObjectA(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define LOGPIXELSY
Definition: wingdi.h:719
#define FW_BLACK
Definition: wingdi.h:382
#define ANSI_CHARSET
Definition: wingdi.h:383
#define FW_NORMAL
Definition: wingdi.h:373
#define SYMBOL_CHARSET
Definition: wingdi.h:385
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)