push c6fcfc519a04d046be60ec60e33d075a2146cc03
[wine/hacks.git] / dlls / riched20 / tests / txtsrv.c
blob0714535768819f688541880671b2f8407b1d3900
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
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <objbase.h>
30 #include <richedit.h>
31 #include <initguid.h>
32 #include <textserv.h>
33 #include <wine/test.h>
34 #include <oleauto.h>
36 static HMODULE hmoduleRichEdit;
38 /* Define C Macros for ITextServices calls. */
40 /* Use a special table for x86 machines to convert the thiscall
41 * calling convention. This isn't needed on other platforms. */
42 #ifdef __i386__
43 static ITextServicesVtbl itextServicesStdcallVtbl;
44 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
45 #else /* __i386__ */
46 #define TXTSERV_VTABLE(This) (This)->lpVtbl
47 #endif /* __i386__ */
49 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
50 #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)
51 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
52 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
53 #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)
54 #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)
55 #define ITextServices_OnTxInplaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInplaceActivate(This,a)
56 #define ITextServices_OnTxInplaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInplaceDeactivate(This)
57 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
58 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
59 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
60 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
61 #define ITextServices_TxGetCurrentTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurrentTargetX(This,a)
62 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
63 #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)
64 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
65 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
66 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
68 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
69 * function call traces of ITextHost. */
70 #define TRACECALL if(winetest_debug > 1) trace
72 /************************************************************************/
73 /* ITextHost implementation for conformance testing. */
75 typedef struct ITextHostTestImpl
77 ITextHostVtbl *lpVtbl;
78 LONG refCount;
79 } ITextHostTestImpl;
81 static HRESULT WINAPI ITextHostImpl_QueryInterface(ITextHost *iface,
82 REFIID riid,
83 LPVOID *ppvObject)
85 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
87 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextHost)) {
88 *ppvObject = This;
89 ITextHost_AddRef((ITextHost *)*ppvObject);
90 return S_OK;
93 return E_NOINTERFACE;
96 static ULONG WINAPI ITextHostImpl_AddRef(ITextHost *iface)
98 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
99 ULONG refCount = InterlockedIncrement(&This->refCount);
100 return refCount;
103 static ULONG WINAPI ITextHostImpl_Release(ITextHost *iface)
105 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
106 ULONG refCount = InterlockedDecrement(&This->refCount);
108 if (!refCount)
110 CoTaskMemFree(This);
111 return 0;
112 } else {
113 return refCount;
117 static HDC WINAPI ITextHostImpl_TxGetDC(ITextHost *iface)
119 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
120 TRACECALL("Call to TxGetDC(%p)\n", This);
121 return NULL;
124 static INT WINAPI ITextHostImpl_TxReleaseDC(ITextHost *iface,
125 HDC hdc)
127 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
128 TRACECALL("Call to TxReleaseDC(%p)\n", This);
129 return 0;
132 static BOOL WINAPI ITextHostImpl_TxShowScrollBar(ITextHost *iface,
133 INT fnBar,
134 BOOL fShow)
136 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
137 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
138 This, fnBar, fShow);
139 return FALSE;
142 static BOOL WINAPI ITextHostImpl_TxEnableScrollBar(ITextHost *iface,
143 INT fuSBFlags,
144 INT fuArrowflags)
146 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
147 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
148 This, fuSBFlags, fuArrowflags);
149 return FALSE;
152 static BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface,
153 INT fnBar,
154 LONG nMinPos,
155 INT nMaxPos,
156 BOOL fRedraw)
158 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
159 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
160 This, fnBar, nMinPos, nMaxPos, fRedraw);
161 return FALSE;
164 static BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface,
165 INT fnBar,
166 INT nPos,
167 BOOL fRedraw)
169 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
170 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
171 This, fnBar, nPos, fRedraw);
172 return FALSE;
175 static void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface,
176 LPCRECT prc,
177 BOOL fMode)
179 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
180 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
181 This, prc, fMode);
184 static void WINAPI ITextHostImpl_TxViewChange(ITextHost *iface, BOOL fUpdate)
186 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
187 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
188 This, fUpdate);
191 static BOOL WINAPI ITextHostImpl_TxCreateCaret(ITextHost *iface,
192 HBITMAP hbmp,
193 INT xWidth, INT yHeight)
195 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
196 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
197 This, hbmp, xWidth, yHeight);
198 return FALSE;
201 static BOOL WINAPI ITextHostImpl_TxShowCaret(ITextHost *iface, BOOL fShow)
203 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
204 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
205 This, fShow);
206 return FALSE;
209 static BOOL WINAPI ITextHostImpl_TxSetCaretPos(ITextHost *iface,
210 INT x, INT y)
212 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
213 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This, x, y);
214 return FALSE;
217 static BOOL WINAPI ITextHostImpl_TxSetTimer(ITextHost *iface,
218 UINT idTimer, UINT uTimeout)
220 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
221 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
222 This, idTimer, uTimeout);
223 return FALSE;
226 static void WINAPI ITextHostImpl_TxKillTimer(ITextHost *iface, UINT idTimer)
228 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
229 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This, idTimer);
232 static void WINAPI ITextHostImpl_TxScrollWindowEx(ITextHost *iface,
233 INT dx, INT dy,
234 LPCRECT lprcScroll,
235 LPCRECT lprcClip,
236 HRGN hRgnUpdate,
237 LPRECT lprcUpdate,
238 UINT fuScroll)
240 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
241 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
242 This, dx, dy, lprcScroll, lprcClip, hRgnUpdate, lprcUpdate, fuScroll);
245 static void WINAPI ITextHostImpl_TxSetCapture(ITextHost *iface, BOOL fCapture)
247 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
248 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This, fCapture);
251 static void WINAPI ITextHostImpl_TxSetFocus(ITextHost *iface)
253 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
254 TRACECALL("Call to TxSetFocus(%p)\n", This);
257 static void WINAPI ITextHostImpl_TxSetCursor(ITextHost *iface,
258 HCURSOR hcur,
259 BOOL fText)
261 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
262 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
263 This, hcur, fText);
266 static BOOL WINAPI ITextHostImpl_TxScreenToClient(ITextHost *iface,
267 LPPOINT lppt)
269 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
270 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This, lppt);
271 return FALSE;
274 static BOOL WINAPI ITextHostImpl_TxClientToScreen(ITextHost *iface,
275 LPPOINT lppt)
277 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
278 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This, lppt);
279 return FALSE;
282 static HRESULT WINAPI ITextHostImpl_TxActivate(ITextHost *iface,
283 LONG *plOldState)
285 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
286 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This, plOldState);
287 return E_NOTIMPL;
290 static HRESULT WINAPI ITextHostImpl_TxDeactivate(ITextHost *iface,
291 LONG lNewState)
293 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
294 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This, lNewState);
295 return E_NOTIMPL;
298 static HRESULT WINAPI ITextHostImpl_TxGetClientRect(ITextHost *iface,
299 LPRECT prc)
301 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
302 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This, prc);
303 return E_NOTIMPL;
306 static HRESULT WINAPI ITextHostImpl_TxGetViewInset(ITextHost *iface,
307 LPRECT prc)
309 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
310 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This, prc);
311 return E_NOTIMPL;
314 static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
315 const CHARFORMATW **ppCF)
317 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
318 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
319 return E_NOTIMPL;
322 static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
323 const PARAFORMAT **ppPF)
325 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
326 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This, ppPF);
327 return E_NOTIMPL;
330 static COLORREF WINAPI ITextHostImpl_TxGetSysColor(ITextHost *iface,
331 int nIndex)
333 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
334 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This, nIndex);
335 return E_NOTIMPL;
338 static HRESULT WINAPI ITextHostImpl_TxGetBackStyle(ITextHost *iface,
339 TXTBACKSTYLE *pStyle)
341 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
342 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This, pStyle);
343 return E_NOTIMPL;
346 static HRESULT WINAPI ITextHostImpl_TxGetMaxLength(ITextHost *iface,
347 DWORD *pLength)
349 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
350 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This, pLength);
351 return E_NOTIMPL;
354 static HRESULT WINAPI ITextHostImpl_TxGetScrollBars(ITextHost *iface,
355 DWORD *pdwScrollBar)
357 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
358 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
359 This, pdwScrollBar);
360 return E_NOTIMPL;
363 static HRESULT WINAPI ITextHostImpl_TxGetPasswordChar(ITextHost *iface,
364 WCHAR *pch)
366 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
367 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This, pch);
368 return E_NOTIMPL;
371 static HRESULT WINAPI ITextHostImpl_TxGetAcceleratorPos(ITextHost *iface,
372 LONG *pch)
374 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
375 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This, pch);
376 return E_NOTIMPL;
379 static HRESULT WINAPI ITextHostImpl_TxGetExtent(ITextHost *iface,
380 LPSIZEL lpExtent)
382 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
383 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This, lpExtent);
384 return E_NOTIMPL;
387 static HRESULT WINAPI ITextHostImpl_OnTxCharFormatChange(ITextHost *iface,
388 const CHARFORMATW *pcf)
390 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
391 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This, pcf);
392 return E_NOTIMPL;
395 static HRESULT WINAPI ITextHostImpl_OnTxParaFormatChange(ITextHost *iface,
396 const PARAFORMAT *ppf)
398 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
399 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This, ppf);
400 return E_NOTIMPL;
403 /* This must return S_OK for the native ITextServices object to
404 initialize. */
405 static HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
406 DWORD dwMask,
407 DWORD *pdwBits)
409 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
410 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
411 This, dwMask, pdwBits);
412 *pdwBits = 0;
413 return S_OK;
416 static HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface, DWORD iNotify,
417 void *pv)
419 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
420 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This, iNotify, pv);
421 return E_NOTIMPL;
424 static HIMC WINAPI ITextHostImpl_TxImmGetContext(ITextHost *iface)
426 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
427 TRACECALL("Call to TxImmGetContext(%p)\n", This);
428 return 0;
431 static void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface, HIMC himc)
433 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
434 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This, himc);
437 static HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
438 LONG *lSelBarWidth)
440 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
441 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
442 This, lSelBarWidth);
443 return E_NOTIMPL;
446 static ITextHostVtbl itextHostVtbl = {
447 ITextHostImpl_QueryInterface,
448 ITextHostImpl_AddRef,
449 ITextHostImpl_Release,
450 ITextHostImpl_TxGetDC,
451 ITextHostImpl_TxReleaseDC,
452 ITextHostImpl_TxShowScrollBar,
453 ITextHostImpl_TxEnableScrollBar,
454 ITextHostImpl_TxSetScrollRange,
455 ITextHostImpl_TxSetScrollPos,
456 ITextHostImpl_TxInvalidateRect,
457 ITextHostImpl_TxViewChange,
458 ITextHostImpl_TxCreateCaret,
459 ITextHostImpl_TxShowCaret,
460 ITextHostImpl_TxSetCaretPos,
461 ITextHostImpl_TxSetTimer,
462 ITextHostImpl_TxKillTimer,
463 ITextHostImpl_TxScrollWindowEx,
464 ITextHostImpl_TxSetCapture,
465 ITextHostImpl_TxSetFocus,
466 ITextHostImpl_TxSetCursor,
467 ITextHostImpl_TxScreenToClient,
468 ITextHostImpl_TxClientToScreen,
469 ITextHostImpl_TxActivate,
470 ITextHostImpl_TxDeactivate,
471 ITextHostImpl_TxGetClientRect,
472 ITextHostImpl_TxGetViewInset,
473 ITextHostImpl_TxGetCharFormat,
474 ITextHostImpl_TxGetParaFormat,
475 ITextHostImpl_TxGetSysColor,
476 ITextHostImpl_TxGetBackStyle,
477 ITextHostImpl_TxGetMaxLength,
478 ITextHostImpl_TxGetScrollBars,
479 ITextHostImpl_TxGetPasswordChar,
480 ITextHostImpl_TxGetAcceleratorPos,
481 ITextHostImpl_TxGetExtent,
482 ITextHostImpl_OnTxCharFormatChange,
483 ITextHostImpl_OnTxParaFormatChange,
484 ITextHostImpl_TxGetPropertyBits,
485 ITextHostImpl_TxNotify,
486 ITextHostImpl_TxImmGetContext,
487 ITextHostImpl_TxImmReleaseContext,
488 ITextHostImpl_TxGetSelectionBarWidth
491 static ITextServices *txtserv = NULL;
492 static ITextHostTestImpl *dummyTextHost;
493 static void *wrapperCodeMem = NULL;
495 #include "pshpack1.h"
497 /* Code structure for x86 byte code */
498 typedef struct
500 BYTE pop_eax; /* popl %eax */
501 BYTE push_ecx; /* pushl %ecx */
502 BYTE push_eax; /* pushl %eax */
503 BYTE jmp_func; /* jmp $func */
504 DWORD func;
505 } THISCALL_TO_STDCALL_THUNK;
507 typedef struct
509 BYTE pop_eax; /* popl %eax */
510 BYTE pop_ecx; /* popl %ecx */
511 BYTE push_eax; /* pushl %eax */
512 BYTE mov_vtable_eax[2]; /* movl (%ecx), %eax */
513 BYTE jmp_eax[2]; /* jmp *$vtablefunc_offset(%eax) */
514 int vtablefunc_offset;
515 } STDCALL_TO_THISCALL_THUNK;
517 #include "poppack.h"
519 static void setup_thiscall_wrappers(void)
521 #ifdef __i386__
522 void** pVtable;
523 void** pVtableEnd;
524 THISCALL_TO_STDCALL_THUNK *thunk;
525 STDCALL_TO_THISCALL_THUNK *thunk2;
527 wrapperCodeMem = VirtualAlloc(NULL,
528 (sizeof(ITextHostVtbl)/sizeof(void*) - 3)
529 * sizeof(THISCALL_TO_STDCALL_THUNK)
530 +(sizeof(ITextServicesVtbl)/sizeof(void*) - 3)
531 * sizeof(STDCALL_TO_THISCALL_THUNK),
532 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
533 thunk = wrapperCodeMem;
535 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
536 * stdcall conversion. The thiscall calling convention places the This
537 * pointer in ecx on the x86 platform, and the stdcall calling convention
538 * pushes the This pointer on the stack as the first argument.
540 * The byte code does the conversion then jumps to the real function.
542 * Each wrapper needs to be modified so that the function to jump to is
543 * modified in the byte code. */
545 /* Skip QueryInterface, AddRef, and Release native actually
546 * defined them with the stdcall calling convention. */
547 pVtable = (void**)&itextHostVtbl + 3;
548 pVtableEnd = (void**)(&itextHostVtbl + 1);
549 while (pVtable != pVtableEnd) {
550 /* write byte code to executable memory */
551 thunk->pop_eax = 0x58; /* popl %eax */
552 thunk->push_ecx = 0x51; /* pushl %ecx */
553 thunk->push_eax = 0x50; /* pushl %eax */
554 thunk->jmp_func = 0xe9; /* jmp $func */
555 /* The address needs to be relative to the end of the jump instructions. */
556 thunk->func = (char*)*pVtable - (char*)(&thunk->func + 1);
557 *pVtable = thunk;
558 pVtable++;
559 thunk++;
562 /* Setup an ITextServices standard call vtable that will call the
563 * native thiscall vtable when the methods are called. */
565 /* QueryInterface, AddRef, and Release should be called directly on the
566 * real vtable since they use the stdcall calling convention. */
567 thunk2 = (STDCALL_TO_THISCALL_THUNK *)thunk;
568 pVtable = (void**)&itextServicesStdcallVtbl + 3;
569 pVtableEnd = (void**)(&itextServicesStdcallVtbl + 1);
570 while (pVtable != pVtableEnd) {
571 /* write byte code to executable memory */
572 thunk2->pop_eax = 0x58; /* popl %eax */
573 thunk2->pop_ecx = 0x59; /* popl %ecx */
574 thunk2->push_eax = 0x50; /* pushl %eax */
575 thunk2->mov_vtable_eax[0] = 0x8b; /* movl (%ecx), %eax */
576 thunk2->mov_vtable_eax[1] = 0x01;
577 thunk2->jmp_eax[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
578 thunk2->jmp_eax[1] = 0xa0;
579 thunk2->vtablefunc_offset = (char*)pVtable - (char*)&itextServicesStdcallVtbl;
580 *pVtable = thunk2;
581 pVtable++;
582 thunk2++;
584 #endif /* __i386__ */
587 /*************************************************************************/
588 /* Conformance test functions. */
590 /* Initialize the test texthost structure */
591 static BOOL init_texthost(void)
593 IUnknown *init;
594 HRESULT result;
595 PCreateTextServices pCreateTextServices;
597 dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
598 if (dummyTextHost == NULL) {
599 skip("Insufficient memory to create ITextHost interface\n");
600 return FALSE;
602 dummyTextHost->lpVtbl = &itextHostVtbl;
603 dummyTextHost->refCount = 1;
605 /* MSDN states that an IUnknown object is returned by
606 CreateTextServices which is then queried to obtain a
607 ITextServices object. */
608 pCreateTextServices = (void*)GetProcAddress(hmoduleRichEdit, "CreateTextServices");
609 result = (*pCreateTextServices)(NULL,(ITextHost*)dummyTextHost, &init);
610 ok(result == S_OK, "Did not return OK when created. Returned %x\n", result);
611 if (result != S_OK) {
612 CoTaskMemFree(dummyTextHost);
613 skip("CreateTextServices failed.\n");
614 return FALSE;
617 result = IUnknown_QueryInterface(init, &IID_ITextServices,
618 (void **)&txtserv);
619 ok((result == S_OK) && (txtserv != NULL), "Querying interface failed\n");
620 IUnknown_Release(init);
621 if (!((result == S_OK) && (txtserv != NULL))) {
622 CoTaskMemFree(dummyTextHost);
623 skip("Could not retrieve ITextServices interface\n");
624 return FALSE;
627 return TRUE;
630 static void test_TxGetText(void)
632 HRESULT hres;
633 BSTR rettext;
635 if (!init_texthost())
636 return;
638 hres = ITextServices_TxGetText(txtserv, &rettext);
639 todo_wine ok(hres == S_OK, "ITextServices_TxGetText failed\n");
641 IUnknown_Release(txtserv);
642 CoTaskMemFree(dummyTextHost);
645 static void test_TxSetText(void)
647 HRESULT hres;
648 BSTR rettext;
649 WCHAR settext[] = {'T','e','s','t',0};
651 if (!init_texthost())
652 return;
654 hres = ITextServices_TxSetText(txtserv, settext);
655 todo_wine ok(hres == S_OK, "ITextServices_TxSetText failed\n");
657 hres = ITextServices_TxGetText(txtserv, &rettext);
658 todo_wine ok(hres == S_OK, "ITextServices_TxGetText failed\n");
660 todo_wine ok(SysStringLen(rettext) == 4,
661 "String returned of wrong length\n");
662 todo_wine ok(memcmp(rettext,settext,SysStringByteLen(rettext)) == 0,
663 "String returned differs\n");
665 IUnknown_Release(txtserv);
666 CoTaskMemFree(dummyTextHost);
669 START_TEST( txtsrv )
671 setup_thiscall_wrappers();
673 /* Must explicitly LoadLibrary(). The test has no references to functions in
674 * RICHED20.DLL, so the linker doesn't actually link to it. */
675 hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
676 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
678 if (init_texthost())
680 IUnknown_Release(txtserv);
681 CoTaskMemFree(dummyTextHost);
683 test_TxGetText();
684 test_TxSetText();
686 if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);