4 * Copyright 2003 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <wine/test.h>
41 static HMODULE hOleaut32
;
43 static HRESULT (WINAPI
*pOleCreateFontIndirect
)(LPFONTDESC
,REFIID
,LPVOID
*);
45 /* Create a font with cySize given by lo_size, hi_size, */
46 /* SetRatio to ratio_logical, ratio_himetric, */
47 /* check that resulting hfont has height hfont_height. */
48 /* Various checks along the way. */
50 static void test_ifont_sizes(long lo_size
, long hi_size
,
51 long ratio_logical
, long ratio_himetric
,
52 long hfont_height
, const char * test_name
)
55 static const WCHAR fname
[] = { 'S','y','s','t','e','m',0 };
63 fd
.cbSizeofstruct
= sizeof(FONTDESC
);
64 fd
.lpstrName
= (WCHAR
*)fname
;
65 S(fd
.cySize
).Lo
= lo_size
;
66 S(fd
.cySize
).Hi
= hi_size
;
71 fd
.fStrikethrough
= 0;
73 /* Create font, test that it worked. */
74 hres
= pOleCreateFontIndirect(&fd
, &IID_IFont
, &pvObj
);
76 ok(hres
== S_OK
,"%s: OCFI returns 0x%08lx instead of S_OK.\n",
78 ok(pvObj
!= NULL
,"%s: OCFI returns NULL.\n", test_name
);
80 /* Read back size. Hi part was ignored. */
81 hres
= IFont_get_Size(ifnt
, &psize
);
82 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08lx instead of S_OK.\n",
84 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
85 "%s: get_Size: Lo=%ld, Hi=%ld; expected Lo=%ld, Hi=%ld.\n",
86 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
88 /* Change ratio, check size unchanged. Standard is 72, 2540. */
89 hres
= IFont_SetRatio(ifnt
, ratio_logical
, ratio_himetric
);
90 ok(hres
== S_OK
,"%s: IFont_SR returns 0x%08lx instead of S_OK.\n",
92 hres
= IFont_get_Size(ifnt
, &psize
);
93 ok(hres
== S_OK
,"%s: IFont_get_size returns 0x%08lx instead of S_OK.\n",
95 ok(S(psize
).Lo
== lo_size
&& S(psize
).Hi
== 0,
96 "%s: gS after SR: Lo=%ld, Hi=%ld; expected Lo=%ld, Hi=%ld.\n",
97 test_name
, S(psize
).Lo
, S(psize
).Hi
, lo_size
, 0L);
99 /* Check hFont size with this ratio. This tests an important */
100 /* conversion for which MSDN is very wrong. */
101 hres
= IFont_get_hFont (ifnt
, &hfont
);
102 ok(hres
== S_OK
, "%s: IFont_get_hFont returns 0x%08lx instead of S_OK.\n",
104 hres
= GetObject (hfont
, sizeof(LOGFONT
), &lf
);
105 ok(lf
.lfHeight
== hfont_height
,
106 "%s: hFont has lf.lfHeight=%ld, expected %ld.\n",
107 test_name
, lf
.lfHeight
, hfont_height
);
113 void test_QueryInterface(void)
119 hres
= pOleCreateFontIndirect(NULL
, &IID_IFont
, &pvObj
);
122 ok(hres
== S_OK
,"OCFI (NULL,..) does not return 0, but 0x%08lx\n",hres
);
123 ok(font
!= NULL
,"OCFI (NULL,..) returns NULL, instead of !NULL\n");
126 hres
= IFont_QueryInterface( font
, &IID_IFont
, &pvObj
);
128 ok(hres
== S_OK
,"IFont_QI does not return S_OK, but 0x%08lx\n", hres
);
129 ok(pvObj
!= NULL
,"IFont_QI does return NULL, instead of a ptr\n");
134 void test_type_info(void)
138 IFontDisp
* fontdisp
= NULL
;
140 WCHAR name_Name
[] = {'N','a','m','e',0};
143 LCID en_us
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),
146 pOleCreateFontIndirect(NULL
, &IID_IFontDisp
, &pvObj
);
149 hres
= IFontDisp_GetTypeInfo(fontdisp
, 0, en_us
, &pTInfo
);
150 ok(hres
== S_OK
, "GTI returned 0x%08lx instead of S_OK.\n", hres
);
151 ok(pTInfo
!= NULL
, "GTI returned NULL.\n");
153 hres
= ITypeInfo_GetNames(pTInfo
, DISPID_FONT_NAME
, names
, 3, &n
);
154 ok(hres
== S_OK
, "GetNames returned 0x%08lx instead of S_OK.\n", hres
);
155 ok(n
== 1, "GetNames returned %d names instead of 1.\n", n
);
156 ok(!lstrcmpiW(names
[0],name_Name
), "DISPID_FONT_NAME doesn't get 'Names'.\n");
158 ITypeInfo_Release(pTInfo
);
159 IFontDisp_Release(fontdisp
);
164 hOleaut32
= LoadLibraryA("oleaut32.dll");
165 pOleCreateFontIndirect
= (void*)GetProcAddress(hOleaut32
, "OleCreateFontIndirect");
166 if (!pOleCreateFontIndirect
)
169 test_QueryInterface();
172 /* Test various size operations and conversions. */
173 /* Add more as needed. */
174 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
175 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
176 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
178 /* These depend on details of how IFont rounds sizes internally. */
179 /* test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); */ /* zero size */
180 /* test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); */ /* test rounding */