Add a test for Invoking an OleFont function.
[wine/multimedia.git] / dlls / oleaut32 / tests / olefont.c
blobfb24207683be9552e5211a35f2c540a69a54ecf9
1 /*
2 * OLEFONT test program
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
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <math.h>
25 #include <float.h>
26 #include <time.h>
28 #define COBJMACROS
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 <wtypes.h>
39 #include <olectl.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)
54 FONTDESC fd;
55 static const WCHAR fname[] = { 'S','y','s','t','e','m',0 };
56 LPVOID pvObj = NULL;
57 IFont* ifnt = NULL;
58 HFONT hfont;
59 LOGFONT lf;
60 CY psize;
61 HRESULT hres;
63 fd.cbSizeofstruct = sizeof(FONTDESC);
64 fd.lpstrName = (WCHAR*)fname;
65 S(fd.cySize).Lo = lo_size;
66 S(fd.cySize).Hi = hi_size;
67 fd.sWeight = 0;
68 fd.sCharset = 0;
69 fd.fItalic = 0;
70 fd.fUnderline = 0;
71 fd.fStrikethrough = 0;
73 /* Create font, test that it worked. */
74 hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
75 ifnt = pvObj;
76 ok(hres == S_OK,"%s: OCFI returns 0x%08lx instead of S_OK.\n",
77 test_name, hres);
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",
83 test_name, hres);
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",
91 test_name, hres);
92 hres = IFont_get_Size(ifnt, &psize);
93 ok(hres == S_OK,"%s: IFont_get_size returns 0x%08lx instead of S_OK.\n",
94 test_name, hres);
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",
103 test_name, hres);
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);
109 /* Free IFont. */
110 IFont_Release(ifnt);
113 void test_QueryInterface(void)
115 LPVOID pvObj = NULL;
116 HRESULT hres;
117 IFont* font = NULL;
119 hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
120 font = 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");
125 pvObj = NULL;
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");
131 IFont_Release(font);
134 void test_type_info(void)
136 LPVOID pvObj = NULL;
137 HRESULT hres;
138 IFontDisp* fontdisp = NULL;
139 ITypeInfo* pTInfo;
140 WCHAR name_Name[] = {'N','a','m','e',0};
141 BSTR names[3];
142 UINT n;
143 LCID en_us = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
144 SORT_DEFAULT);
145 DISPPARAMS dispparams;
146 VARIANT varresult;
148 pOleCreateFontIndirect(NULL, &IID_IFontDisp, &pvObj);
149 fontdisp = pvObj;
151 hres = IFontDisp_GetTypeInfo(fontdisp, 0, en_us, &pTInfo);
152 ok(hres == S_OK, "GTI returned 0x%08lx instead of S_OK.\n", hres);
153 ok(pTInfo != NULL, "GTI returned NULL.\n");
155 hres = ITypeInfo_GetNames(pTInfo, DISPID_FONT_NAME, names, 3, &n);
156 ok(hres == S_OK, "GetNames returned 0x%08lx instead of S_OK.\n", hres);
157 ok(n == 1, "GetNames returned %d names instead of 1.\n", n);
158 ok(!lstrcmpiW(names[0],name_Name), "DISPID_FONT_NAME doesn't get 'Names'.\n");
160 ITypeInfo_Release(pTInfo);
162 dispparams.cNamedArgs = 0;
163 dispparams.rgdispidNamedArgs = NULL;
164 dispparams.cArgs = 0;
165 dispparams.rgvarg = NULL;
166 VariantInit(&varresult);
167 hres = IFontDisp_Invoke(fontdisp, DISPID_FONT_NAME, &IID_NULL,
168 LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult,
169 NULL, NULL);
170 ok(hres == S_OK, "IFontDisp_Invoke return 0x%08lx instead of S_OK.\n", hres);
171 VariantClear(&varresult);
173 IFontDisp_Release(fontdisp);
176 START_TEST(olefont)
178 hOleaut32 = LoadLibraryA("oleaut32.dll");
179 pOleCreateFontIndirect = (void*)GetProcAddress(hOleaut32, "OleCreateFontIndirect");
180 if (!pOleCreateFontIndirect)
181 return;
183 test_QueryInterface();
184 test_type_info();
186 /* Test various size operations and conversions. */
187 /* Add more as needed. */
188 test_ifont_sizes(180000, 0, 72, 2540, -18, "default");
189 test_ifont_sizes(180000, 0, 144, 2540, -36, "ratio1"); /* change ratio */
190 test_ifont_sizes(180000, 0, 72, 1270, -36, "ratio2"); /* 2nd part of ratio */
192 /* These depend on details of how IFont rounds sizes internally. */
193 /* test_ifont_sizes(0, 0, 72, 2540, 0, "zero size"); */ /* zero size */
194 /* test_ifont_sizes(186000, 0, 72, 2540, -19, "rounding"); */ /* test rounding */