push 9eb9af089d68d39110a91889d3a673043db63c4b
[wine/hacks.git] / dlls / riched20 / tests / txtsrv.c
blob3d47490d975891dd5beb9890353c5f8a36e66e32
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>
35 static HMODULE hmoduleRichEdit;
37 /* Define C Macros for ITextServices calls. */
39 /* Use a special table for x86 machines to convert the thiscall
40 * calling convention. This isn't needed on other platforms. */
41 #ifdef __i386__
42 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
43 #else /* __i386__ */
44 #define TXTSERV_VTABLE(This) (This)->lpVtbl
45 #endif /* __i386__ */
47 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
48 #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)
49 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
50 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
51 #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)
52 #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)
53 #define ITextServices_OnTxInplaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInplaceActivate(This,a)
54 #define ITextServices_OnTxInplaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInplaceDeactivate(This)
55 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
56 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
57 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
58 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
59 #define ITextServices_TxGetCurrentTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurrentTargetX(This,a)
60 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
61 #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)
62 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
63 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
64 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
66 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
67 * function call traces of ITextHost. */
68 #define TRACECALL if(winetest_debug > 1) trace
70 /************************************************************************/
71 /* ITextHost implementation for conformance testing. */
73 typedef struct ITextHostTestImpl
75 ITextHostVtbl *lpVtbl;
76 LONG refCount;
77 } ITextHostTestImpl;
79 static HRESULT WINAPI ITextHostImpl_QueryInterface(ITextHost *iface,
80 REFIID riid,
81 LPVOID *ppvObject)
83 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
85 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextHost)) {
86 *ppvObject = This;
87 ITextHost_AddRef((ITextHost *)*ppvObject);
88 return S_OK;
91 return E_NOINTERFACE;
94 static ULONG WINAPI ITextHostImpl_AddRef(ITextHost *iface)
96 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
97 ULONG refCount = InterlockedIncrement(&This->refCount);
98 return refCount;
101 static ULONG WINAPI ITextHostImpl_Release(ITextHost *iface)
103 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
104 ULONG refCount = InterlockedDecrement(&This->refCount);
106 if (!refCount)
108 CoTaskMemFree(This);
109 return 0;
110 } else {
111 return refCount;
115 static HDC WINAPI ITextHostImpl_TxGetDC(ITextHost *iface)
117 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
118 TRACECALL("Call to TxGetDC(%p)\n", This);
119 return NULL;
122 static INT WINAPI ITextHostImpl_TxReleaseDC(ITextHost *iface,
123 HDC hdc)
125 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
126 TRACECALL("Call to TxReleaseDC(%p)\n", This);
127 return 0;
130 static BOOL WINAPI ITextHostImpl_TxShowScrollBar(ITextHost *iface,
131 INT fnBar,
132 BOOL fShow)
134 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
135 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
136 This, fnBar, fShow);
137 return E_NOTIMPL;
140 static BOOL WINAPI ITextHostImpl_TxEnableScrollBar(ITextHost *iface,
141 INT fuSBFlags,
142 INT fuArrowflags)
144 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
145 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
146 This, fuSBFlags, fuArrowflags);
147 return E_NOTIMPL;
150 static BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface,
151 INT fnBar,
152 LONG nMinPos,
153 INT nMaxPos,
154 BOOL fRedraw)
156 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
157 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
158 This, fnBar, nMinPos, nMaxPos, fRedraw);
159 return E_NOTIMPL;
162 static BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface,
163 INT fnBar,
164 INT nPos,
165 BOOL fRedraw)
167 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
168 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
169 This, fnBar, nPos, fRedraw);
170 return E_NOTIMPL;
173 static void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface,
174 LPCRECT prc,
175 BOOL fMode)
177 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
178 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
179 This, prc, fMode);
182 static void WINAPI ITextHostImpl_TxViewChange(ITextHost *iface, BOOL fUpdate)
184 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
185 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
186 This, fUpdate);
189 static BOOL WINAPI ITextHostImpl_TxCreateCaret(ITextHost *iface,
190 HBITMAP hbmp,
191 INT xWidth, INT yHeight)
193 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
194 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
195 This, hbmp, xWidth, yHeight);
196 return E_NOTIMPL;
199 static BOOL WINAPI ITextHostImpl_TxShowCaret(ITextHost *iface, BOOL fShow)
201 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
202 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
203 This, fShow);
204 return E_NOTIMPL;
207 static BOOL WINAPI ITextHostImpl_TxSetCaretPos(ITextHost *iface,
208 INT x, INT y)
210 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
211 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This, x, y);
212 return E_NOTIMPL;
215 static BOOL WINAPI ITextHostImpl_TxSetTimer(ITextHost *iface,
216 UINT idTimer, UINT uTimeout)
218 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
219 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
220 This, idTimer, uTimeout);
221 return E_NOTIMPL;
224 static void WINAPI ITextHostImpl_TxKillTimer(ITextHost *iface, UINT idTimer)
226 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
227 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This, idTimer);
230 static void WINAPI ITextHostImpl_TxScrollWindowEx(ITextHost *iface,
231 INT dx, INT dy,
232 LPCRECT lprcScroll,
233 LPCRECT lprcClip,
234 HRGN hRgnUpdate,
235 LPRECT lprcUpdate,
236 UINT fuScroll)
238 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
239 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
240 This, dx, dy, lprcScroll, lprcClip, hRgnUpdate, lprcUpdate, fuScroll);
243 static void WINAPI ITextHostImpl_TxSetCapture(ITextHost *iface, BOOL fCapture)
245 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
246 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This, fCapture);
249 static void WINAPI ITextHostImpl_TxSetFocus(ITextHost *iface)
251 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
252 TRACECALL("Call to TxSetFocus(%p)\n", This);
255 static void WINAPI ITextHostImpl_TxSetCursor(ITextHost *iface,
256 HCURSOR hcur,
257 BOOL fText)
259 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
260 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
261 This, hcur, fText);
264 static BOOL WINAPI ITextHostImpl_TxScreenToClient(ITextHost *iface,
265 LPPOINT lppt)
267 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
268 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This, lppt);
269 return E_NOTIMPL;
272 static BOOL WINAPI ITextHostImpl_TxClientToScreen(ITextHost *iface,
273 LPPOINT lppt)
275 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
276 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This, lppt);
277 return E_NOTIMPL;
280 static HRESULT WINAPI ITextHostImpl_TxActivate(ITextHost *iface,
281 LONG *plOldState)
283 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
284 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This, plOldState);
285 return E_NOTIMPL;
288 static HRESULT WINAPI ITextHostImpl_TxDeactivate(ITextHost *iface,
289 LONG lNewState)
291 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
292 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This, lNewState);
293 return E_NOTIMPL;
296 static HRESULT WINAPI ITextHostImpl_TxGetClientRect(ITextHost *iface,
297 LPRECT prc)
299 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
300 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This, prc);
301 return E_NOTIMPL;
304 static HRESULT WINAPI ITextHostImpl_TxGetViewInset(ITextHost *iface,
305 LPRECT prc)
307 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
308 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This, prc);
309 return E_NOTIMPL;
312 static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
313 const CHARFORMATW **ppCF)
315 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
316 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
317 return E_NOTIMPL;
320 static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
321 const PARAFORMAT **ppPF)
323 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
324 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This, ppPF);
325 return E_NOTIMPL;
328 static COLORREF WINAPI ITextHostImpl_TxGetSysColor(ITextHost *iface,
329 int nIndex)
331 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
332 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This, nIndex);
333 return E_NOTIMPL;
336 static HRESULT WINAPI ITextHostImpl_TxGetBackStyle(ITextHost *iface,
337 TXTBACKSTYLE *pStyle)
339 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
340 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This, pStyle);
341 return E_NOTIMPL;
344 static HRESULT WINAPI ITextHostImpl_TxGetMaxLength(ITextHost *iface,
345 DWORD *pLength)
347 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
348 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This, pLength);
349 return E_NOTIMPL;
352 static HRESULT WINAPI ITextHostImpl_TxGetScrollbars(ITextHost *iface,
353 DWORD *pdwScrollBar)
355 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
356 TRACECALL("Call to TxGetScrollbars(%p, pdwScrollBar=%p)\n",
357 This, pdwScrollBar);
358 return E_NOTIMPL;
361 static HRESULT WINAPI ITextHostImpl_TxGetPasswordChar(ITextHost *iface,
362 WCHAR *pch)
364 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
365 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This, pch);
366 return E_NOTIMPL;
369 static HRESULT WINAPI ITextHostImpl_TxGetAcceleratorPos(ITextHost *iface,
370 LONG *pch)
372 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
373 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This, pch);
374 return E_NOTIMPL;
377 static HRESULT WINAPI ITextHostImpl_TxGetExtent(ITextHost *iface,
378 LPSIZEL lpExtent)
380 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
381 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This, lpExtent);
382 return E_NOTIMPL;
385 static HRESULT WINAPI ITextHostImpl_OnTxCharFormatChange(ITextHost *iface,
386 const CHARFORMATW *pcf)
388 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
389 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This, pcf);
390 return E_NOTIMPL;
393 static HRESULT WINAPI ITextHostImpl_OnTxParaFormatChange(ITextHost *iface,
394 const PARAFORMAT *ppf)
396 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
397 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This, ppf);
398 return E_NOTIMPL;
401 /* This must return S_OK for the native ITextServices object to
402 initialize. */
403 static HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
404 DWORD dwMask,
405 DWORD *pdwBits)
407 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
408 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
409 This, dwMask, pdwBits);
410 *pdwBits = 0;
411 return S_OK;
414 static HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface, DWORD iNotify,
415 void *pv)
417 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
418 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This, iNotify, pv);
419 return E_NOTIMPL;
422 static HIMC WINAPI ITextHostImpl_TxImmGetContext(ITextHost *iface)
424 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
425 TRACECALL("Call to TxImmGetContext(%p)\n", This);
426 return 0;
429 static void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface, HIMC himc)
431 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
432 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This, himc);
435 static HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
436 LONG *lSelBarWidth)
438 ITextHostTestImpl *This = (ITextHostTestImpl *)iface;
439 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
440 This, lSelBarWidth);
441 return E_NOTIMPL;
444 static ITextServicesVtbl itextServicesStdcallVtbl;
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 START_TEST( txtsrv )
647 setup_thiscall_wrappers();
649 /* Must explicitly LoadLibrary(). The test has no references to functions in
650 * RICHED20.DLL, so the linker doesn't actually link to it. */
651 hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
652 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
654 if (init_texthost())
656 IUnknown_Release(txtserv);
657 CoTaskMemFree(dummyTextHost);
659 test_TxGetText();
661 if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);