gdi32: Fix arguments for OSMesaMakeCurrent when using 16 bit formats.
[wine.git] / dlls / riched20 / tests / txtsrv.c
blobc154e2dee4a322025b9f7c0c0f7653bf76ed8dad
1 /*
2 * Unit test suite for windowless rich edit controls
4 * Copyright 2008 Maarten Lankhorst
5 * Copyright 2008 Austin Lund
6 * Copyright 2008 Dylan Smith
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
23 #define COBJMACROS
24 #define CONST_VTABLE
26 #include <stdio.h>
27 #include <stdarg.h>
28 #include <windef.h>
29 #include <winbase.h>
30 #include <objbase.h>
31 #include <richedit.h>
32 #include <tom.h>
33 #include <richole.h>
34 #include <initguid.h>
35 #include <imm.h>
36 #include <textserv.h>
37 #include <wine/test.h>
38 #include <oleauto.h>
39 #include <limits.h>
41 static HMODULE hmoduleRichEdit;
42 static IID *pIID_ITextServices;
43 static IID *pIID_ITextHost;
44 static IID *pIID_ITextHost2;
45 static PCreateTextServices pCreateTextServices;
47 /* Define C Macros for ITextServices calls. */
49 /* Use a special table for x86 machines to convert the thiscall
50 * calling convention. This isn't needed on other platforms. */
51 #ifdef __i386__
52 static ITextServicesVtbl itextServicesStdcallVtbl;
53 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
54 #else /* __i386__ */
55 #define TXTSERV_VTABLE(This) (This)->lpVtbl
56 #endif /* __i386__ */
58 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
59 #define ITextServices_TxDraw(This,a,b,c,d,e,f,g,h,i,j,k,l) TXTSERV_VTABLE(This)->TxDraw(This,a,b,c,d,e,f,g,h,i,j,k,l)
60 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
61 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
62 #define ITextServices_OnTxSetCursor(This,a,b,c,d,e,f,g,h,i) TXTSERV_VTABLE(This)->OnTxSetCursor(This,a,b,c,d,e,f,g,h,i)
63 #define ITextServices_TxQueryHitPoint(This,a,b,c,d,e,f,g,h,i,j) TXTSERV_VTABLE(This)->TxQueryHitPoint(This,a,b,c,d,e,f,g,h,i,j)
64 #define ITextServices_OnTxInplaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInplaceActivate(This,a)
65 #define ITextServices_OnTxInplaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInplaceDeactivate(This)
66 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
67 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
68 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
69 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
70 #define ITextServices_TxGetCurTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurTargetX(This,a)
71 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
72 #define ITextServices_TxGetNaturalSize(This,a,b,c,d,e,f,g,h) TXTSERV_VTABLE(This)->TxGetNaturalSize(This,a,b,c,d,e,f,g,h)
73 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
74 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
75 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
77 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
78 * function call traces of ITextHost. */
79 #define TRACECALL if(winetest_debug > 1) trace
81 /************************************************************************/
82 /* ITextHost implementation for conformance testing. */
84 typedef struct ITextHostTestImpl
86 ITextHost ITextHost_iface;
87 LONG refCount;
88 } ITextHostTestImpl;
90 static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface)
92 return CONTAINING_RECORD(iface, ITextHostTestImpl, ITextHost_iface);
95 static HRESULT WINAPI ITextHostImpl_QueryInterface(ITextHost *iface,
96 REFIID riid,
97 LPVOID *ppvObject)
99 ITextHostTestImpl *This = impl_from_ITextHost(iface);
101 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, pIID_ITextHost)) {
102 *ppvObject = This;
103 ITextHost_AddRef((ITextHost *)*ppvObject);
104 return S_OK;
107 return E_NOINTERFACE;
110 static ULONG WINAPI ITextHostImpl_AddRef(ITextHost *iface)
112 ITextHostTestImpl *This = impl_from_ITextHost(iface);
113 ULONG refCount = InterlockedIncrement(&This->refCount);
114 return refCount;
117 static ULONG WINAPI ITextHostImpl_Release(ITextHost *iface)
119 ITextHostTestImpl *This = impl_from_ITextHost(iface);
120 ULONG refCount = InterlockedDecrement(&This->refCount);
122 if (!refCount)
124 CoTaskMemFree(This);
125 return 0;
126 } else {
127 return refCount;
131 static HDC WINAPI ITextHostImpl_TxGetDC(ITextHost *iface)
133 ITextHostTestImpl *This = impl_from_ITextHost(iface);
134 TRACECALL("Call to TxGetDC(%p)\n", This);
135 return NULL;
138 static INT WINAPI ITextHostImpl_TxReleaseDC(ITextHost *iface,
139 HDC hdc)
141 ITextHostTestImpl *This = impl_from_ITextHost(iface);
142 TRACECALL("Call to TxReleaseDC(%p)\n", This);
143 return 0;
146 static BOOL WINAPI ITextHostImpl_TxShowScrollBar(ITextHost *iface,
147 INT fnBar,
148 BOOL fShow)
150 ITextHostTestImpl *This = impl_from_ITextHost(iface);
151 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
152 This, fnBar, fShow);
153 return FALSE;
156 static BOOL WINAPI ITextHostImpl_TxEnableScrollBar(ITextHost *iface,
157 INT fuSBFlags,
158 INT fuArrowflags)
160 ITextHostTestImpl *This = impl_from_ITextHost(iface);
161 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
162 This, fuSBFlags, fuArrowflags);
163 return FALSE;
166 static BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface,
167 INT fnBar,
168 LONG nMinPos,
169 INT nMaxPos,
170 BOOL fRedraw)
172 ITextHostTestImpl *This = impl_from_ITextHost(iface);
173 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
174 This, fnBar, nMinPos, nMaxPos, fRedraw);
175 return FALSE;
178 static BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface,
179 INT fnBar,
180 INT nPos,
181 BOOL fRedraw)
183 ITextHostTestImpl *This = impl_from_ITextHost(iface);
184 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
185 This, fnBar, nPos, fRedraw);
186 return FALSE;
189 static void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface,
190 LPCRECT prc,
191 BOOL fMode)
193 ITextHostTestImpl *This = impl_from_ITextHost(iface);
194 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
195 This, prc, fMode);
198 static void WINAPI ITextHostImpl_TxViewChange(ITextHost *iface, BOOL fUpdate)
200 ITextHostTestImpl *This = impl_from_ITextHost(iface);
201 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
202 This, fUpdate);
205 static BOOL WINAPI ITextHostImpl_TxCreateCaret(ITextHost *iface,
206 HBITMAP hbmp,
207 INT xWidth, INT yHeight)
209 ITextHostTestImpl *This = impl_from_ITextHost(iface);
210 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
211 This, hbmp, xWidth, yHeight);
212 return FALSE;
215 static BOOL WINAPI ITextHostImpl_TxShowCaret(ITextHost *iface, BOOL fShow)
217 ITextHostTestImpl *This = impl_from_ITextHost(iface);
218 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
219 This, fShow);
220 return FALSE;
223 static BOOL WINAPI ITextHostImpl_TxSetCaretPos(ITextHost *iface,
224 INT x, INT y)
226 ITextHostTestImpl *This = impl_from_ITextHost(iface);
227 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This, x, y);
228 return FALSE;
231 static BOOL WINAPI ITextHostImpl_TxSetTimer(ITextHost *iface,
232 UINT idTimer, UINT uTimeout)
234 ITextHostTestImpl *This = impl_from_ITextHost(iface);
235 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
236 This, idTimer, uTimeout);
237 return FALSE;
240 static void WINAPI ITextHostImpl_TxKillTimer(ITextHost *iface, UINT idTimer)
242 ITextHostTestImpl *This = impl_from_ITextHost(iface);
243 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This, idTimer);
246 static void WINAPI ITextHostImpl_TxScrollWindowEx(ITextHost *iface,
247 INT dx, INT dy,
248 LPCRECT lprcScroll,
249 LPCRECT lprcClip,
250 HRGN hRgnUpdate,
251 LPRECT lprcUpdate,
252 UINT fuScroll)
254 ITextHostTestImpl *This = impl_from_ITextHost(iface);
255 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
256 This, dx, dy, lprcScroll, lprcClip, hRgnUpdate, lprcUpdate, fuScroll);
259 static void WINAPI ITextHostImpl_TxSetCapture(ITextHost *iface, BOOL fCapture)
261 ITextHostTestImpl *This = impl_from_ITextHost(iface);
262 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This, fCapture);
265 static void WINAPI ITextHostImpl_TxSetFocus(ITextHost *iface)
267 ITextHostTestImpl *This = impl_from_ITextHost(iface);
268 TRACECALL("Call to TxSetFocus(%p)\n", This);
271 static void WINAPI ITextHostImpl_TxSetCursor(ITextHost *iface,
272 HCURSOR hcur,
273 BOOL fText)
275 ITextHostTestImpl *This = impl_from_ITextHost(iface);
276 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
277 This, hcur, fText);
280 static BOOL WINAPI ITextHostImpl_TxScreenToClient(ITextHost *iface,
281 LPPOINT lppt)
283 ITextHostTestImpl *This = impl_from_ITextHost(iface);
284 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This, lppt);
285 return FALSE;
288 static BOOL WINAPI ITextHostImpl_TxClientToScreen(ITextHost *iface,
289 LPPOINT lppt)
291 ITextHostTestImpl *This = impl_from_ITextHost(iface);
292 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This, lppt);
293 return FALSE;
296 static HRESULT WINAPI ITextHostImpl_TxActivate(ITextHost *iface,
297 LONG *plOldState)
299 ITextHostTestImpl *This = impl_from_ITextHost(iface);
300 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This, plOldState);
301 return E_NOTIMPL;
304 static HRESULT WINAPI ITextHostImpl_TxDeactivate(ITextHost *iface,
305 LONG lNewState)
307 ITextHostTestImpl *This = impl_from_ITextHost(iface);
308 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This, lNewState);
309 return E_NOTIMPL;
312 static HRESULT WINAPI ITextHostImpl_TxGetClientRect(ITextHost *iface,
313 LPRECT prc)
315 ITextHostTestImpl *This = impl_from_ITextHost(iface);
316 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This, prc);
317 return E_NOTIMPL;
320 static HRESULT WINAPI ITextHostImpl_TxGetViewInset(ITextHost *iface,
321 LPRECT prc)
323 ITextHostTestImpl *This = impl_from_ITextHost(iface);
324 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This, prc);
325 return E_NOTIMPL;
328 static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
329 const CHARFORMATW **ppCF)
331 ITextHostTestImpl *This = impl_from_ITextHost(iface);
332 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
333 return E_NOTIMPL;
336 static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
337 const PARAFORMAT **ppPF)
339 ITextHostTestImpl *This = impl_from_ITextHost(iface);
340 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This, ppPF);
341 return E_NOTIMPL;
344 static COLORREF WINAPI ITextHostImpl_TxGetSysColor(ITextHost *iface,
345 int nIndex)
347 ITextHostTestImpl *This = impl_from_ITextHost(iface);
348 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This, nIndex);
349 return E_NOTIMPL;
352 static HRESULT WINAPI ITextHostImpl_TxGetBackStyle(ITextHost *iface,
353 TXTBACKSTYLE *pStyle)
355 ITextHostTestImpl *This = impl_from_ITextHost(iface);
356 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This, pStyle);
357 return E_NOTIMPL;
360 static HRESULT WINAPI ITextHostImpl_TxGetMaxLength(ITextHost *iface,
361 DWORD *pLength)
363 ITextHostTestImpl *This = impl_from_ITextHost(iface);
364 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This, pLength);
365 return E_NOTIMPL;
368 static HRESULT WINAPI ITextHostImpl_TxGetScrollBars(ITextHost *iface,
369 DWORD *pdwScrollBar)
371 ITextHostTestImpl *This = impl_from_ITextHost(iface);
372 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
373 This, pdwScrollBar);
374 return E_NOTIMPL;
377 static HRESULT WINAPI ITextHostImpl_TxGetPasswordChar(ITextHost *iface,
378 WCHAR *pch)
380 ITextHostTestImpl *This = impl_from_ITextHost(iface);
381 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This, pch);
382 return E_NOTIMPL;
385 static HRESULT WINAPI ITextHostImpl_TxGetAcceleratorPos(ITextHost *iface,
386 LONG *pch)
388 ITextHostTestImpl *This = impl_from_ITextHost(iface);
389 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This, pch);
390 return E_NOTIMPL;
393 static HRESULT WINAPI ITextHostImpl_TxGetExtent(ITextHost *iface,
394 LPSIZEL lpExtent)
396 ITextHostTestImpl *This = impl_from_ITextHost(iface);
397 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This, lpExtent);
398 return E_NOTIMPL;
401 static HRESULT WINAPI ITextHostImpl_OnTxCharFormatChange(ITextHost *iface,
402 const CHARFORMATW *pcf)
404 ITextHostTestImpl *This = impl_from_ITextHost(iface);
405 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This, pcf);
406 return E_NOTIMPL;
409 static HRESULT WINAPI ITextHostImpl_OnTxParaFormatChange(ITextHost *iface,
410 const PARAFORMAT *ppf)
412 ITextHostTestImpl *This = impl_from_ITextHost(iface);
413 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This, ppf);
414 return E_NOTIMPL;
417 /* This must return S_OK for the native ITextServices object to
418 initialize. */
419 static HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
420 DWORD dwMask,
421 DWORD *pdwBits)
423 ITextHostTestImpl *This = impl_from_ITextHost(iface);
424 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
425 This, dwMask, pdwBits);
426 *pdwBits = 0;
427 return S_OK;
430 static HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface, DWORD iNotify,
431 void *pv)
433 ITextHostTestImpl *This = impl_from_ITextHost(iface);
434 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This, iNotify, pv);
435 return E_NOTIMPL;
438 static HIMC WINAPI ITextHostImpl_TxImmGetContext(ITextHost *iface)
440 ITextHostTestImpl *This = impl_from_ITextHost(iface);
441 TRACECALL("Call to TxImmGetContext(%p)\n", This);
442 return 0;
445 static void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface, HIMC himc)
447 ITextHostTestImpl *This = impl_from_ITextHost(iface);
448 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This, himc);
451 /* This function must set the variable pointed to by *lSelBarWidth.
452 Otherwise an uninitialized value will be used to calculate
453 positions and sizes even if E_NOTIMPL is returned. */
454 static HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
455 LONG *lSelBarWidth)
457 ITextHostTestImpl *This = impl_from_ITextHost(iface);
458 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
459 This, lSelBarWidth);
460 *lSelBarWidth = 0;
461 return E_NOTIMPL;
464 static ITextHostVtbl itextHostVtbl = {
465 ITextHostImpl_QueryInterface,
466 ITextHostImpl_AddRef,
467 ITextHostImpl_Release,
468 ITextHostImpl_TxGetDC,
469 ITextHostImpl_TxReleaseDC,
470 ITextHostImpl_TxShowScrollBar,
471 ITextHostImpl_TxEnableScrollBar,
472 ITextHostImpl_TxSetScrollRange,
473 ITextHostImpl_TxSetScrollPos,
474 ITextHostImpl_TxInvalidateRect,
475 ITextHostImpl_TxViewChange,
476 ITextHostImpl_TxCreateCaret,
477 ITextHostImpl_TxShowCaret,
478 ITextHostImpl_TxSetCaretPos,
479 ITextHostImpl_TxSetTimer,
480 ITextHostImpl_TxKillTimer,
481 ITextHostImpl_TxScrollWindowEx,
482 ITextHostImpl_TxSetCapture,
483 ITextHostImpl_TxSetFocus,
484 ITextHostImpl_TxSetCursor,
485 ITextHostImpl_TxScreenToClient,
486 ITextHostImpl_TxClientToScreen,
487 ITextHostImpl_TxActivate,
488 ITextHostImpl_TxDeactivate,
489 ITextHostImpl_TxGetClientRect,
490 ITextHostImpl_TxGetViewInset,
491 ITextHostImpl_TxGetCharFormat,
492 ITextHostImpl_TxGetParaFormat,
493 ITextHostImpl_TxGetSysColor,
494 ITextHostImpl_TxGetBackStyle,
495 ITextHostImpl_TxGetMaxLength,
496 ITextHostImpl_TxGetScrollBars,
497 ITextHostImpl_TxGetPasswordChar,
498 ITextHostImpl_TxGetAcceleratorPos,
499 ITextHostImpl_TxGetExtent,
500 ITextHostImpl_OnTxCharFormatChange,
501 ITextHostImpl_OnTxParaFormatChange,
502 ITextHostImpl_TxGetPropertyBits,
503 ITextHostImpl_TxNotify,
504 ITextHostImpl_TxImmGetContext,
505 ITextHostImpl_TxImmReleaseContext,
506 ITextHostImpl_TxGetSelectionBarWidth
509 static ITextServices *txtserv = NULL;
510 static ITextHostTestImpl *dummyTextHost;
511 static void *wrapperCodeMem = NULL;
513 #include "pshpack1.h"
515 /* Code structure for x86 byte code */
516 typedef struct
518 BYTE pop_eax; /* popl %eax */
519 BYTE push_ecx; /* pushl %ecx */
520 BYTE push_eax; /* pushl %eax */
521 BYTE jmp_func; /* jmp $func */
522 DWORD func;
523 } THISCALL_TO_STDCALL_THUNK;
525 typedef struct
527 BYTE pop_eax; /* popl %eax */
528 BYTE pop_ecx; /* popl %ecx */
529 BYTE push_eax; /* pushl %eax */
530 BYTE mov_vtable_eax[2]; /* movl (%ecx), %eax */
531 BYTE jmp_eax[2]; /* jmp *$vtablefunc_offset(%eax) */
532 int vtablefunc_offset;
533 } STDCALL_TO_THISCALL_THUNK;
535 #include "poppack.h"
537 static void setup_thiscall_wrappers(void)
539 #ifdef __i386__
540 void** pVtable;
541 void** pVtableEnd;
542 THISCALL_TO_STDCALL_THUNK *thunk;
543 STDCALL_TO_THISCALL_THUNK *thunk2;
545 wrapperCodeMem = VirtualAlloc(NULL,
546 (sizeof(ITextHostVtbl)/sizeof(void*) - 3)
547 * sizeof(THISCALL_TO_STDCALL_THUNK)
548 +(sizeof(ITextServicesVtbl)/sizeof(void*) - 3)
549 * sizeof(STDCALL_TO_THISCALL_THUNK),
550 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
551 thunk = wrapperCodeMem;
553 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
554 * stdcall conversion. The thiscall calling convention places the This
555 * pointer in ecx on the x86 platform, and the stdcall calling convention
556 * pushes the This pointer on the stack as the first argument.
558 * The byte code does the conversion then jumps to the real function.
560 * Each wrapper needs to be modified so that the function to jump to is
561 * modified in the byte code. */
563 /* Skip QueryInterface, AddRef, and Release native actually
564 * defined them with the stdcall calling convention. */
565 pVtable = (void**)&itextHostVtbl + 3;
566 pVtableEnd = (void**)(&itextHostVtbl + 1);
567 while (pVtable != pVtableEnd) {
568 /* write byte code to executable memory */
569 thunk->pop_eax = 0x58; /* popl %eax */
570 thunk->push_ecx = 0x51; /* pushl %ecx */
571 thunk->push_eax = 0x50; /* pushl %eax */
572 thunk->jmp_func = 0xe9; /* jmp $func */
573 /* The address needs to be relative to the end of the jump instructions. */
574 thunk->func = (char*)*pVtable - (char*)(&thunk->func + 1);
575 *pVtable = thunk;
576 pVtable++;
577 thunk++;
580 /* Setup an ITextServices standard call vtable that will call the
581 * native thiscall vtable when the methods are called. */
583 /* QueryInterface, AddRef, and Release should be called directly on the
584 * real vtable since they use the stdcall calling convention. */
585 thunk2 = (STDCALL_TO_THISCALL_THUNK *)thunk;
586 pVtable = (void**)&itextServicesStdcallVtbl + 3;
587 pVtableEnd = (void**)(&itextServicesStdcallVtbl + 1);
588 while (pVtable != pVtableEnd) {
589 /* write byte code to executable memory */
590 thunk2->pop_eax = 0x58; /* popl %eax */
591 thunk2->pop_ecx = 0x59; /* popl %ecx */
592 thunk2->push_eax = 0x50; /* pushl %eax */
593 thunk2->mov_vtable_eax[0] = 0x8b; /* movl (%ecx), %eax */
594 thunk2->mov_vtable_eax[1] = 0x01;
595 thunk2->jmp_eax[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
596 thunk2->jmp_eax[1] = 0xa0;
597 thunk2->vtablefunc_offset = (char*)pVtable - (char*)&itextServicesStdcallVtbl;
598 *pVtable = thunk2;
599 pVtable++;
600 thunk2++;
602 #endif /* __i386__ */
605 /*************************************************************************/
606 /* Conformance test functions. */
608 /* Initialize the test texthost structure */
609 static BOOL init_texthost(void)
611 IUnknown *init;
612 HRESULT result;
614 dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
615 if (dummyTextHost == NULL) {
616 skip("Insufficient memory to create ITextHost interface\n");
617 return FALSE;
619 dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl;
620 dummyTextHost->refCount = 1;
622 /* MSDN states that an IUnknown object is returned by
623 CreateTextServices which is then queried to obtain a
624 ITextServices object. */
625 result = (*pCreateTextServices)(NULL, &dummyTextHost->ITextHost_iface, &init);
626 ok(result == S_OK, "Did not return S_OK when created (result = %x)\n", result);
627 if (result != S_OK) {
628 CoTaskMemFree(dummyTextHost);
629 skip("CreateTextServices failed.\n");
630 return FALSE;
633 result = IUnknown_QueryInterface(init, pIID_ITextServices,
634 (void **)&txtserv);
635 ok((result == S_OK) && (txtserv != NULL), "Querying interface failed (result = %x, txtserv = %p)\n", result, txtserv);
636 IUnknown_Release(init);
637 if (!((result == S_OK) && (txtserv != NULL))) {
638 CoTaskMemFree(dummyTextHost);
639 skip("Could not retrieve ITextServices interface\n");
640 return FALSE;
643 return TRUE;
646 static void free_texthost(void)
648 ITextServices_Release(txtserv);
649 CoTaskMemFree(dummyTextHost);
652 static void test_TxGetText(void)
654 HRESULT hres;
655 BSTR rettext;
657 if (!init_texthost())
658 return;
660 hres = ITextServices_TxGetText(txtserv, &rettext);
661 ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres);
663 free_texthost();
666 static void test_TxSetText(void)
668 HRESULT hres;
669 BSTR rettext;
670 WCHAR settext[] = {'T','e','s','t',0};
672 if (!init_texthost())
673 return;
675 hres = ITextServices_TxSetText(txtserv, settext);
676 ok(hres == S_OK, "ITextServices_TxSetText failed (result = %x)\n", hres);
678 hres = ITextServices_TxGetText(txtserv, &rettext);
679 ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres);
681 ok(SysStringLen(rettext) == 4,
682 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext));
683 ok(memcmp(rettext,settext,SysStringByteLen(rettext)) == 0,
684 "String returned differs\n");
686 SysFreeString(rettext);
687 free_texthost();
690 static void test_TxGetNaturalSize(void) {
691 HRESULT result;
692 BOOL ret;
694 /* This value is used when calling TxGetNaturalSize. MSDN says
695 that this is not supported however a null pointer cannot be
696 used as it will cause a segmentation violation. The values in
697 the structure being pointed to are required to be INT_MAX
698 otherwise calculations can give wrong values. */
699 const SIZEL psizelExtent = {INT_MAX,INT_MAX};
701 static const WCHAR oneA[] = {'A',0};
703 /* Results of measurements */
704 LONG xdim, ydim;
706 /* The device context to do the tests in */
707 HDC hdcDraw;
709 /* Variables with the text metric information */
710 INT charwidth_caps_text[26];
711 TEXTMETRICA tmInfo_text;
713 if (!init_texthost())
714 return;
716 hdcDraw = GetDC(NULL);
717 SaveDC(hdcDraw);
719 /* Populate the metric strucs */
720 SetMapMode(hdcDraw,MM_TEXT);
721 GetTextMetricsA(hdcDraw, &tmInfo_text);
722 SetLastError(0xdeadbeef);
723 ret = GetCharWidth32A(hdcDraw,'A','Z',charwidth_caps_text);
724 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
725 win_skip("GetCharWidth32 is not available\n");
726 goto cleanup;
729 /* Make measurements in MM_TEXT */
730 SetMapMode(hdcDraw,MM_TEXT);
731 xdim = 0; ydim = 0;
733 result = ITextServices_TxSetText(txtserv, oneA);
734 ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result);
735 if (result != S_OK) {
736 skip("Could not set text\n");
737 goto cleanup;
740 SetLastError(0xdeadbeef);
741 result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
742 hdcDraw, NULL, NULL,
743 TXTNS_FITTOCONTENT, &psizelExtent,
744 &xdim, &ydim);
745 todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */
746 "TxGetNaturalSize gave unexpected return value (result = %x)\n", result);
747 if (result == S_OK) {
748 todo_wine ok(ydim == tmInfo_text.tmHeight,
749 "Height calculated incorrectly (expected %d, got %d)\n",
750 tmInfo_text.tmHeight, ydim);
751 /* The native DLL adds one pixel extra when calculating widths. */
752 todo_wine ok(xdim >= charwidth_caps_text[0] && xdim <= charwidth_caps_text[0] + 1,
753 "Width calculated incorrectly (expected %d {+1}, got %d)\n",
754 charwidth_caps_text[0], xdim);
755 } else
756 skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n",
757 xdim, ydim, result, GetLastError());
759 cleanup:
760 RestoreDC(hdcDraw,1);
761 ReleaseDC(NULL,hdcDraw);
762 free_texthost();
765 static void test_TxDraw(void)
767 HDC tmphdc = GetDC(NULL);
768 DWORD dwAspect = DVASPECT_CONTENT;
769 HDC hicTargetDev = NULL; /* Means "default" device */
770 DVTARGETDEVICE *ptd = NULL;
771 void *pvAspect = NULL;
772 HRESULT result;
773 RECTL client = {0,0,100,100};
775 if (!init_texthost())
776 return;
778 todo_wine {
779 result = ITextServices_TxDraw(txtserv, dwAspect, 0, pvAspect, ptd,
780 tmphdc, hicTargetDev, &client, NULL,
781 NULL, NULL, 0, 0);
782 ok(result == S_OK, "TxDraw failed (result = %x)\n", result);
785 free_texthost();
789 DEFINE_GUID(expected_iid_itextservices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
790 DEFINE_GUID(expected_iid_itexthost, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
791 DEFINE_GUID(expected_iid_itexthost2, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
793 static void test_IIDs(void)
795 ok(IsEqualIID(pIID_ITextServices, &expected_iid_itextservices),
796 "unexpected value for IID_ITextServices: %s\n", wine_dbgstr_guid(pIID_ITextServices));
797 ok(IsEqualIID(pIID_ITextHost, &expected_iid_itexthost),
798 "unexpected value for IID_ITextHost: %s\n", wine_dbgstr_guid(pIID_ITextHost));
799 ok(IsEqualIID(pIID_ITextHost2, &expected_iid_itexthost2),
800 "unexpected value for IID_ITextHost2: %s\n", wine_dbgstr_guid(pIID_ITextHost2));
803 /* Outer IUnknown for COM aggregation tests */
804 struct unk_impl {
805 IUnknown IUnknown_iface;
806 LONG ref;
807 IUnknown *inner_unk;
810 static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface)
812 return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface);
815 static HRESULT WINAPI unk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
817 struct unk_impl *This = impl_from_IUnknown(iface);
819 return IUnknown_QueryInterface(This->inner_unk, riid, ppv);
822 static ULONG WINAPI unk_AddRef(IUnknown *iface)
824 struct unk_impl *This = impl_from_IUnknown(iface);
826 return InterlockedIncrement(&This->ref);
829 static ULONG WINAPI unk_Release(IUnknown *iface)
831 struct unk_impl *This = impl_from_IUnknown(iface);
833 return InterlockedDecrement(&This->ref);
836 static const IUnknownVtbl unk_vtbl =
838 unk_QueryInterface,
839 unk_AddRef,
840 unk_Release
843 static void test_COM(void)
845 struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
846 struct ITextHostTestImpl texthost = {{&itextHostVtbl}, 1};
847 ITextServices *textsrv;
848 ULONG refcount;
849 HRESULT hr;
851 /* COM aggregation */
852 hr = pCreateTextServices(&unk_obj.IUnknown_iface, &texthost.ITextHost_iface,
853 &unk_obj.inner_unk);
854 ok(hr == S_OK, "CreateTextServices failed: %08x\n", hr);
855 hr = IUnknown_QueryInterface(unk_obj.inner_unk, pIID_ITextServices, (void**)&textsrv);
856 ok(hr == S_OK, "QueryInterface for IID_ITextServices failed: %08x\n", hr);
857 refcount = ITextServices_AddRef(textsrv);
858 ok(refcount == unk_obj.ref, "CreateTextServices just pretends to support COM aggregation\n");
859 refcount = ITextServices_Release(textsrv);
860 ok(refcount == unk_obj.ref, "CreateTextServices just pretends to support COM aggregation\n");
861 refcount = ITextServices_Release(textsrv);
862 ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount);
864 IUnknown_Release(unk_obj.inner_unk);
867 static ULONG get_refcount(IUnknown *iface)
869 IUnknown_AddRef(iface);
870 return IUnknown_Release(iface);
873 static void test_QueryInterface(void)
875 HRESULT hres;
876 IRichEditOle *reole, *txtsrv_reole;
877 ITextDocument *txtdoc, *txtsrv_txtdoc;
878 ULONG refcount;
880 if(!init_texthost())
881 return;
883 refcount = get_refcount((IUnknown *)txtserv);
884 ok(refcount == 1, "got wrong ref count: %d\n", refcount);
886 /* IID_IRichEditOle */
887 hres = ITextServices_QueryInterface(txtserv, &IID_IRichEditOle, (void **)&txtsrv_reole);
888 ok(hres == S_OK, "ITextServices_QueryInterface: 0x%08x\n", hres);
889 refcount = get_refcount((IUnknown *)txtserv);
890 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
891 refcount = get_refcount((IUnknown *)txtsrv_reole);
892 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
894 hres = IRichEditOle_QueryInterface(txtsrv_reole, &IID_ITextDocument, (void **)&txtdoc);
895 ok(hres == S_OK, "IRichEditOle_QueryInterface: 0x%08x\n", hres);
896 refcount = get_refcount((IUnknown *)txtserv);
897 ok(refcount == 3, "got wrong ref count: %d\n", refcount);
898 refcount = get_refcount((IUnknown *)txtsrv_reole);
899 ok(refcount == 3, "got wrong ref count: %d\n", refcount);
901 ITextDocument_Release(txtdoc);
902 refcount = get_refcount((IUnknown *)txtserv);
903 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
904 IRichEditOle_Release(txtsrv_reole);
905 refcount = get_refcount((IUnknown *)txtserv);
906 ok(refcount == 1, "got wrong ref count: %d\n", refcount);
908 /* IID_ITextDocument */
909 hres = ITextServices_QueryInterface(txtserv, &IID_ITextDocument, (void **)&txtsrv_txtdoc);
910 ok(hres == S_OK, "ITextServices_QueryInterface: 0x%08x\n", hres);
911 refcount = get_refcount((IUnknown *)txtserv);
912 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
913 refcount = get_refcount((IUnknown *)txtsrv_txtdoc);
914 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
916 hres = ITextDocument_QueryInterface(txtsrv_txtdoc, &IID_IRichEditOle, (void **)&reole);
917 ok(hres == S_OK, "ITextDocument_QueryInterface: 0x%08x\n", hres);
918 refcount = get_refcount((IUnknown *)txtserv);
919 ok(refcount == 3, "got wrong ref count: %d\n", refcount);
920 refcount = get_refcount((IUnknown *)txtsrv_txtdoc);
921 ok(refcount == 3, "got wrong ref count: %d\n", refcount);
923 IRichEditOle_Release(reole);
924 refcount = get_refcount((IUnknown *)txtserv);
925 ok(refcount == 2, "got wrong ref count: %d\n", refcount);
926 ITextDocument_Release(txtsrv_txtdoc);
927 refcount = get_refcount((IUnknown *)txtserv);
928 ok(refcount == 1, "got wrong ref count: %d\n", refcount);
930 free_texthost();
933 START_TEST( txtsrv )
935 setup_thiscall_wrappers();
937 /* Must explicitly LoadLibrary(). The test has no references to functions in
938 * RICHED20.DLL, so the linker doesn't actually link to it. */
939 hmoduleRichEdit = LoadLibraryA("riched20.dll");
940 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
942 pIID_ITextServices = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextServices");
943 pIID_ITextHost = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextHost");
944 pIID_ITextHost2 = (IID*)GetProcAddress(hmoduleRichEdit, "IID_ITextHost2");
945 pCreateTextServices = (void*)GetProcAddress(hmoduleRichEdit, "CreateTextServices");
947 test_IIDs();
948 test_COM();
950 if (init_texthost())
952 free_texthost();
954 test_TxGetText();
955 test_TxSetText();
956 test_TxGetNaturalSize();
957 test_TxDraw();
958 test_QueryInterface();
960 if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);