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
37 #include <wine/test.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 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
52 static ITextServicesVtbl itextServicesStdcallVtbl
;
53 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
55 #define TXTSERV_VTABLE(This) (This)->lpVtbl
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
;
88 CHARFORMAT2W char_format
;
91 static inline ITextHostTestImpl
*impl_from_ITextHost(ITextHost
*iface
)
93 return CONTAINING_RECORD(iface
, ITextHostTestImpl
, ITextHost_iface
);
96 static HRESULT WINAPI
ITextHostImpl_QueryInterface(ITextHost
*iface
,
100 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
102 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, pIID_ITextHost
)) {
103 *ppvObject
= &This
->ITextHost_iface
;
104 ITextHost_AddRef((ITextHost
*)*ppvObject
);
108 return E_NOINTERFACE
;
111 static ULONG WINAPI
ITextHostImpl_AddRef(ITextHost
*iface
)
113 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
114 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
118 static ULONG WINAPI
ITextHostImpl_Release(ITextHost
*iface
)
120 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
121 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
132 static HDC __thiscall
ITextHostImpl_TxGetDC(ITextHost
*iface
)
134 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
135 TRACECALL("Call to TxGetDC(%p)\n", This
);
139 static INT __thiscall
ITextHostImpl_TxReleaseDC(ITextHost
*iface
, HDC hdc
)
141 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
142 TRACECALL("Call to TxReleaseDC(%p)\n", This
);
146 static BOOL __thiscall
ITextHostImpl_TxShowScrollBar(ITextHost
*iface
, INT fnBar
, BOOL fShow
)
148 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
149 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
154 static BOOL __thiscall
ITextHostImpl_TxEnableScrollBar(ITextHost
*iface
, INT fuSBFlags
, INT fuArrowflags
)
156 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
157 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
158 This
, fuSBFlags
, fuArrowflags
);
162 static BOOL __thiscall
ITextHostImpl_TxSetScrollRange(ITextHost
*iface
, INT fnBar
, LONG nMinPos
,
163 INT nMaxPos
, BOOL fRedraw
)
165 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
166 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
167 This
, fnBar
, nMinPos
, nMaxPos
, fRedraw
);
171 static BOOL __thiscall
ITextHostImpl_TxSetScrollPos(ITextHost
*iface
, INT fnBar
, INT nPos
, BOOL fRedraw
)
173 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
174 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
175 This
, fnBar
, nPos
, fRedraw
);
179 static void __thiscall
ITextHostImpl_TxInvalidateRect(ITextHost
*iface
, LPCRECT prc
, BOOL fMode
)
181 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
182 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
186 static void __thiscall
ITextHostImpl_TxViewChange(ITextHost
*iface
, BOOL fUpdate
)
188 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
189 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
193 static BOOL __thiscall
ITextHostImpl_TxCreateCaret(ITextHost
*iface
, HBITMAP hbmp
, INT xWidth
, INT yHeight
)
195 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
196 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
197 This
, hbmp
, xWidth
, yHeight
);
201 static BOOL __thiscall
ITextHostImpl_TxShowCaret(ITextHost
*iface
, BOOL fShow
)
203 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
204 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
209 static BOOL __thiscall
ITextHostImpl_TxSetCaretPos(ITextHost
*iface
, INT x
, INT y
)
211 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
212 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This
, x
, y
);
216 static BOOL __thiscall
ITextHostImpl_TxSetTimer(ITextHost
*iface
, UINT idTimer
, UINT uTimeout
)
218 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
219 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
220 This
, idTimer
, uTimeout
);
224 static void __thiscall
ITextHostImpl_TxKillTimer(ITextHost
*iface
, UINT idTimer
)
226 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
227 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This
, idTimer
);
230 static void __thiscall
ITextHostImpl_TxScrollWindowEx(ITextHost
*iface
, INT dx
, INT dy
, LPCRECT lprcScroll
,
231 LPCRECT lprcClip
, HRGN hRgnUpdate
, LPRECT lprcUpdate
,
234 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
235 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
236 This
, dx
, dy
, lprcScroll
, lprcClip
, hRgnUpdate
, lprcUpdate
, fuScroll
);
239 static void __thiscall
ITextHostImpl_TxSetCapture(ITextHost
*iface
, BOOL fCapture
)
241 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
242 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This
, fCapture
);
245 static void __thiscall
ITextHostImpl_TxSetFocus(ITextHost
*iface
)
247 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
248 TRACECALL("Call to TxSetFocus(%p)\n", This
);
251 static void __thiscall
ITextHostImpl_TxSetCursor(ITextHost
*iface
, HCURSOR hcur
, BOOL fText
)
253 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
254 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
258 static BOOL __thiscall
ITextHostImpl_TxScreenToClient(ITextHost
*iface
, LPPOINT lppt
)
260 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
261 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This
, lppt
);
265 static BOOL __thiscall
ITextHostImpl_TxClientToScreen(ITextHost
*iface
, LPPOINT lppt
)
267 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
268 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This
, lppt
);
272 static HRESULT __thiscall
ITextHostImpl_TxActivate(ITextHost
*iface
, LONG
*plOldState
)
274 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
275 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This
, plOldState
);
279 static HRESULT __thiscall
ITextHostImpl_TxDeactivate(ITextHost
*iface
, LONG lNewState
)
281 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
282 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This
, lNewState
);
286 static HRESULT __thiscall
ITextHostImpl_TxGetClientRect(ITextHost
*iface
, LPRECT prc
)
288 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
289 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This
, prc
);
293 static HRESULT __thiscall
ITextHostImpl_TxGetViewInset(ITextHost
*iface
, LPRECT prc
)
295 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
296 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This
, prc
);
300 static HRESULT __thiscall
ITextHostImpl_TxGetCharFormat(ITextHost
*iface
, const CHARFORMATW
**ppCF
)
302 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
303 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This
, ppCF
);
304 *ppCF
= (CHARFORMATW
*)&This
->char_format
;
308 static HRESULT __thiscall
ITextHostImpl_TxGetParaFormat(ITextHost
*iface
, const PARAFORMAT
**ppPF
)
310 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
311 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This
, ppPF
);
315 static COLORREF __thiscall
ITextHostImpl_TxGetSysColor(ITextHost
*iface
, int nIndex
)
317 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
318 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This
, nIndex
);
322 static HRESULT __thiscall
ITextHostImpl_TxGetBackStyle(ITextHost
*iface
, TXTBACKSTYLE
*pStyle
)
324 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
325 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This
, pStyle
);
329 static HRESULT __thiscall
ITextHostImpl_TxGetMaxLength(ITextHost
*iface
, DWORD
*pLength
)
331 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
332 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This
, pLength
);
336 static HRESULT __thiscall
ITextHostImpl_TxGetScrollBars(ITextHost
*iface
, DWORD
*pdwScrollBar
)
338 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
339 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
344 static HRESULT __thiscall
ITextHostImpl_TxGetPasswordChar(ITextHost
*iface
, WCHAR
*pch
)
346 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
347 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This
, pch
);
351 static HRESULT __thiscall
ITextHostImpl_TxGetAcceleratorPos(ITextHost
*iface
, LONG
*pch
)
353 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
354 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This
, pch
);
358 static HRESULT __thiscall
ITextHostImpl_TxGetExtent(ITextHost
*iface
, LPSIZEL lpExtent
)
360 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
361 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This
, lpExtent
);
365 static HRESULT __thiscall
ITextHostImpl_OnTxCharFormatChange(ITextHost
*iface
, const CHARFORMATW
*pcf
)
367 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
368 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This
, pcf
);
372 static HRESULT __thiscall
ITextHostImpl_OnTxParaFormatChange(ITextHost
*iface
, const PARAFORMAT
*ppf
)
374 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
375 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This
, ppf
);
379 /* This must return S_OK for the native ITextServices object to
381 static HRESULT __thiscall
ITextHostImpl_TxGetPropertyBits(ITextHost
*iface
, DWORD dwMask
, DWORD
*pdwBits
)
383 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
384 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
385 This
, dwMask
, pdwBits
);
390 static HRESULT __thiscall
ITextHostImpl_TxNotify(ITextHost
*iface
, DWORD iNotify
, void *pv
)
392 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
393 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This
, iNotify
, pv
);
397 static HIMC __thiscall
ITextHostImpl_TxImmGetContext(ITextHost
*iface
)
399 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
400 TRACECALL("Call to TxImmGetContext(%p)\n", This
);
404 static void __thiscall
ITextHostImpl_TxImmReleaseContext(ITextHost
*iface
, HIMC himc
)
406 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
407 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This
, himc
);
410 /* This function must set the variable pointed to by *lSelBarWidth.
411 Otherwise an uninitialized value will be used to calculate
412 positions and sizes even if E_NOTIMPL is returned. */
413 static HRESULT __thiscall
ITextHostImpl_TxGetSelectionBarWidth(ITextHost
*iface
, LONG
*lSelBarWidth
)
415 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
416 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
422 static ITextHostVtbl itextHostVtbl
= {
423 ITextHostImpl_QueryInterface
,
424 ITextHostImpl_AddRef
,
425 ITextHostImpl_Release
,
426 ITextHostImpl_TxGetDC
,
427 ITextHostImpl_TxReleaseDC
,
428 ITextHostImpl_TxShowScrollBar
,
429 ITextHostImpl_TxEnableScrollBar
,
430 ITextHostImpl_TxSetScrollRange
,
431 ITextHostImpl_TxSetScrollPos
,
432 ITextHostImpl_TxInvalidateRect
,
433 ITextHostImpl_TxViewChange
,
434 ITextHostImpl_TxCreateCaret
,
435 ITextHostImpl_TxShowCaret
,
436 ITextHostImpl_TxSetCaretPos
,
437 ITextHostImpl_TxSetTimer
,
438 ITextHostImpl_TxKillTimer
,
439 ITextHostImpl_TxScrollWindowEx
,
440 ITextHostImpl_TxSetCapture
,
441 ITextHostImpl_TxSetFocus
,
442 ITextHostImpl_TxSetCursor
,
443 ITextHostImpl_TxScreenToClient
,
444 ITextHostImpl_TxClientToScreen
,
445 ITextHostImpl_TxActivate
,
446 ITextHostImpl_TxDeactivate
,
447 ITextHostImpl_TxGetClientRect
,
448 ITextHostImpl_TxGetViewInset
,
449 ITextHostImpl_TxGetCharFormat
,
450 ITextHostImpl_TxGetParaFormat
,
451 ITextHostImpl_TxGetSysColor
,
452 ITextHostImpl_TxGetBackStyle
,
453 ITextHostImpl_TxGetMaxLength
,
454 ITextHostImpl_TxGetScrollBars
,
455 ITextHostImpl_TxGetPasswordChar
,
456 ITextHostImpl_TxGetAcceleratorPos
,
457 ITextHostImpl_TxGetExtent
,
458 ITextHostImpl_OnTxCharFormatChange
,
459 ITextHostImpl_OnTxParaFormatChange
,
460 ITextHostImpl_TxGetPropertyBits
,
461 ITextHostImpl_TxNotify
,
462 ITextHostImpl_TxImmGetContext
,
463 ITextHostImpl_TxImmReleaseContext
,
464 ITextHostImpl_TxGetSelectionBarWidth
467 static void *wrapperCodeMem
= NULL
;
469 #include "pshpack1.h"
471 /* Code structure for x86 byte code */
474 BYTE pop_eax
; /* popl %eax */
475 BYTE push_ecx
; /* pushl %ecx */
476 BYTE push_eax
; /* pushl %eax */
477 BYTE jmp_func
; /* jmp $func */
479 } THISCALL_TO_STDCALL_THUNK
;
483 BYTE pop_eax
; /* popl %eax */
484 BYTE pop_ecx
; /* popl %ecx */
485 BYTE push_eax
; /* pushl %eax */
486 BYTE mov_vtable_eax
[2]; /* movl (%ecx), %eax */
487 BYTE jmp_eax
[2]; /* jmp *$vtablefunc_offset(%eax) */
488 int vtablefunc_offset
;
489 } STDCALL_TO_THISCALL_THUNK
;
493 static void setup_thiscall_wrappers(void)
495 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
498 THISCALL_TO_STDCALL_THUNK
*thunk
;
499 STDCALL_TO_THISCALL_THUNK
*thunk2
;
501 wrapperCodeMem
= VirtualAlloc(NULL
,
502 (sizeof(ITextHostVtbl
)/sizeof(void*) - 3)
503 * sizeof(THISCALL_TO_STDCALL_THUNK
)
504 +(sizeof(ITextServicesVtbl
)/sizeof(void*) - 3)
505 * sizeof(STDCALL_TO_THISCALL_THUNK
),
506 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
507 thunk
= wrapperCodeMem
;
509 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
510 * stdcall conversion. The thiscall calling convention places the This
511 * pointer in ecx on the x86 platform, and the stdcall calling convention
512 * pushes the This pointer on the stack as the first argument.
514 * The byte code does the conversion then jumps to the real function.
516 * Each wrapper needs to be modified so that the function to jump to is
517 * modified in the byte code. */
519 /* Skip QueryInterface, AddRef, and Release native actually
520 * defined them with the stdcall calling convention. */
521 pVtable
= (void**)&itextHostVtbl
+ 3;
522 pVtableEnd
= (void**)(&itextHostVtbl
+ 1);
523 while (pVtable
!= pVtableEnd
) {
524 /* write byte code to executable memory */
525 thunk
->pop_eax
= 0x58; /* popl %eax */
526 thunk
->push_ecx
= 0x51; /* pushl %ecx */
527 thunk
->push_eax
= 0x50; /* pushl %eax */
528 thunk
->jmp_func
= 0xe9; /* jmp $func */
529 /* The address needs to be relative to the end of the jump instructions. */
530 thunk
->func
= (char*)*pVtable
- (char*)(&thunk
->func
+ 1);
536 /* Setup an ITextServices standard call vtable that will call the
537 * native thiscall vtable when the methods are called. */
539 /* QueryInterface, AddRef, and Release should be called directly on the
540 * real vtable since they use the stdcall calling convention. */
541 thunk2
= (STDCALL_TO_THISCALL_THUNK
*)thunk
;
542 pVtable
= (void**)&itextServicesStdcallVtbl
+ 3;
543 pVtableEnd
= (void**)(&itextServicesStdcallVtbl
+ 1);
544 while (pVtable
!= pVtableEnd
) {
545 /* write byte code to executable memory */
546 thunk2
->pop_eax
= 0x58; /* popl %eax */
547 thunk2
->pop_ecx
= 0x59; /* popl %ecx */
548 thunk2
->push_eax
= 0x50; /* pushl %eax */
549 thunk2
->mov_vtable_eax
[0] = 0x8b; /* movl (%ecx), %eax */
550 thunk2
->mov_vtable_eax
[1] = 0x01;
551 thunk2
->jmp_eax
[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
552 thunk2
->jmp_eax
[1] = 0xa0;
553 thunk2
->vtablefunc_offset
= (char*)pVtable
- (char*)&itextServicesStdcallVtbl
;
558 #endif /* __i386__ */
561 static void hf_to_cf(HFONT hf
, CHARFORMAT2W
*cf
)
565 GetObjectW(hf
, sizeof(lf
), &lf
);
566 lstrcpyW(cf
->szFaceName
, lf
.lfFaceName
);
567 cf
->yHeight
= MulDiv(abs(lf
.lfHeight
), 1440, GetDeviceCaps(GetDC(NULL
), LOGPIXELSY
));
568 if (lf
.lfWeight
> FW_NORMAL
) cf
->dwEffects
|= CFE_BOLD
;
569 if (lf
.lfItalic
) cf
->dwEffects
|= CFE_ITALIC
;
570 if (lf
.lfUnderline
) cf
->dwEffects
|= CFE_UNDERLINE
;
571 if (lf
.lfStrikeOut
) cf
->dwEffects
|= CFE_SUBSCRIPT
;
572 cf
->bPitchAndFamily
= lf
.lfPitchAndFamily
;
573 cf
->bCharSet
= lf
.lfCharSet
;
576 /*************************************************************************/
577 /* Conformance test functions. */
579 /* Initialize the test texthost structure */
580 static BOOL
init_texthost(ITextServices
**txtserv
, ITextHost
**ret
)
582 ITextHostTestImpl
*dummyTextHost
;
587 dummyTextHost
= CoTaskMemAlloc(sizeof(*dummyTextHost
));
588 if (dummyTextHost
== NULL
) {
589 win_skip("Insufficient memory to create ITextHost interface\n");
592 dummyTextHost
->ITextHost_iface
.lpVtbl
= &itextHostVtbl
;
593 dummyTextHost
->refCount
= 1;
594 memset(&dummyTextHost
->char_format
, 0, sizeof(dummyTextHost
->char_format
));
595 dummyTextHost
->char_format
.cbSize
= sizeof(dummyTextHost
->char_format
);
596 dummyTextHost
->char_format
.dwMask
= CFM_ALL2
;
597 hf
= GetStockObject(DEFAULT_GUI_FONT
);
598 hf_to_cf(hf
, &dummyTextHost
->char_format
);
600 /* MSDN states that an IUnknown object is returned by
601 CreateTextServices which is then queried to obtain a
602 ITextServices object. */
603 result
= pCreateTextServices(NULL
, &dummyTextHost
->ITextHost_iface
, &init
);
604 ok(result
== S_OK
, "Did not return S_OK when created (result = %x)\n", result
);
605 if (result
!= S_OK
) {
606 CoTaskMemFree(dummyTextHost
);
607 win_skip("CreateTextServices failed.\n");
611 result
= IUnknown_QueryInterface(init
, pIID_ITextServices
, (void**)txtserv
);
612 ok((result
== S_OK
) && (*txtserv
!= NULL
), "Querying interface failed (result = %x, txtserv = %p)\n", result
, *txtserv
);
613 IUnknown_Release(init
);
614 if (!((result
== S_OK
) && (*txtserv
!= NULL
))) {
615 CoTaskMemFree(dummyTextHost
);
616 win_skip("Could not retrieve ITextServices interface\n");
620 *ret
= &dummyTextHost
->ITextHost_iface
;
624 static void test_TxGetText(void)
626 ITextServices
*txtserv
;
631 if (!init_texthost(&txtserv
, &host
))
634 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
635 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
636 SysFreeString(rettext
);
638 ITextServices_Release(txtserv
);
639 ITextHost_Release(host
);
642 static void test_TxSetText(void)
644 ITextServices
*txtserv
;
648 WCHAR settext
[] = {'T','e','s','t',0};
650 if (!init_texthost(&txtserv
, &host
))
653 hres
= ITextServices_TxSetText(txtserv
, settext
);
654 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", hres
);
656 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
657 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
659 ok(SysStringLen(rettext
) == 4,
660 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext
));
661 ok(memcmp(rettext
,settext
,SysStringByteLen(rettext
)) == 0,
662 "String returned differs\n");
664 SysFreeString(rettext
);
666 /* Null-pointer should behave the same as empty-string */
668 hres
= ITextServices_TxSetText(txtserv
, 0);
669 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", hres
);
671 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
672 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
673 ok(SysStringLen(rettext
) == 0,
674 "String returned of wrong length (expected 0, got %d)\n", SysStringLen(rettext
));
676 SysFreeString(rettext
);
677 ITextServices_Release(txtserv
);
678 ITextHost_Release(host
);
681 #define CHECK_TXGETNATURALSIZE(res,width,height,hdc,rect,string) \
682 _check_txgetnaturalsize(res, width, height, hdc, rect, string, __LINE__)
683 static void _check_txgetnaturalsize(HRESULT res
, LONG width
, LONG height
, HDC hdc
, RECT rect
, LPCWSTR string
, int line
)
685 RECT expected_rect
= rect
;
686 LONG expected_width
, expected_height
;
688 DrawTextW(hdc
, string
, -1, &expected_rect
, DT_LEFT
| DT_CALCRECT
| DT_NOCLIP
| DT_EDITCONTROL
| DT_WORDBREAK
);
689 expected_width
= expected_rect
.right
- expected_rect
.left
;
690 expected_height
= expected_rect
.bottom
- expected_rect
.top
;
691 ok_(__FILE__
,line
)(res
== S_OK
, "ITextServices_TxGetNaturalSize failed: 0x%08x.\n", res
);
692 ok_(__FILE__
,line
)(width
>= expected_width
&& width
<= expected_width
+ 1,
693 "got wrong width: %d, expected: %d {+1}.\n", width
, expected_width
);
694 ok_(__FILE__
,line
)(height
== expected_height
, "got wrong height: %d, expected: %d.\n",
695 height
, expected_height
);
698 static void test_TxGetNaturalSize(void)
700 ITextServices
*txtserv
;
704 static const WCHAR test_text
[] = {'T','e','s','t','S','o','m','e','T','e','x','t',0};
713 if (!init_texthost(&txtserv
, &host
))
716 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
| WS_VISIBLE
,
717 0, 0, 100, 100, 0, 0, 0, NULL
);
718 hdcDraw
= GetDC(hwnd
);
719 SetMapMode(hdcDraw
,MM_TEXT
);
720 GetClientRect(hwnd
, &rect
);
722 memset(&cf
, 0, sizeof(cf
));
723 cf
.cbSize
= sizeof(cf
);
724 cf
.dwMask
= CFM_ALL2
;
725 hf
= GetStockObject(DEFAULT_GUI_FONT
);
727 result
= ITextServices_TxSendMessage(txtserv
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&cf
, &lresult
);
728 ok(result
== S_OK
, "ITextServices_TxSendMessage failed: 0x%08x.\n", result
);
729 SelectObject(hdcDraw
, hf
);
731 result
= ITextServices_TxSetText(txtserv
, test_text
);
732 ok(result
== S_OK
, "ITextServices_TxSetText failed: 0x%08x.\n", result
);
734 extent
.cx
= -1; extent
.cy
= -1;
735 width
= rect
.right
- rect
.left
;
737 result
= ITextServices_TxGetNaturalSize(txtserv
, DVASPECT_CONTENT
, hdcDraw
, NULL
, NULL
,
738 TXTNS_FITTOCONTENT
, &extent
, &width
, &height
);
739 todo_wine
CHECK_TXGETNATURALSIZE(result
, width
, height
, hdcDraw
, rect
, test_text
);
741 ReleaseDC(hwnd
, hdcDraw
);
743 ITextServices_Release(txtserv
);
744 ITextHost_Release(host
);
747 static void test_TxDraw(void)
749 ITextServices
*txtserv
;
751 HDC tmphdc
= GetDC(NULL
);
752 DWORD dwAspect
= DVASPECT_CONTENT
;
753 HDC hicTargetDev
= NULL
; /* Means "default" device */
754 DVTARGETDEVICE
*ptd
= NULL
;
755 void *pvAspect
= NULL
;
757 RECTL client
= {0,0,100,100};
760 if (!init_texthost(&txtserv
, &host
))
764 result
= ITextServices_TxDraw(txtserv
, dwAspect
, 0, pvAspect
, ptd
,
765 tmphdc
, hicTargetDev
, &client
, NULL
,
767 ok(result
== S_OK
, "TxDraw failed (result = %x)\n", result
);
770 ITextServices_Release(txtserv
);
771 ITextHost_Release(host
);
774 DEFINE_GUID(expected_iid_itextservices
, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
775 DEFINE_GUID(expected_iid_itexthost
, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
776 DEFINE_GUID(expected_iid_itexthost2
, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
778 static void test_IIDs(void)
780 ok(IsEqualIID(pIID_ITextServices
, &expected_iid_itextservices
),
781 "unexpected value for IID_ITextServices: %s\n", wine_dbgstr_guid(pIID_ITextServices
));
782 ok(IsEqualIID(pIID_ITextHost
, &expected_iid_itexthost
),
783 "unexpected value for IID_ITextHost: %s\n", wine_dbgstr_guid(pIID_ITextHost
));
784 ok(IsEqualIID(pIID_ITextHost2
, &expected_iid_itexthost2
),
785 "unexpected value for IID_ITextHost2: %s\n", wine_dbgstr_guid(pIID_ITextHost2
));
788 /* Outer IUnknown for COM aggregation tests */
790 IUnknown IUnknown_iface
;
795 static inline struct unk_impl
*impl_from_IUnknown(IUnknown
*iface
)
797 return CONTAINING_RECORD(iface
, struct unk_impl
, IUnknown_iface
);
800 static HRESULT WINAPI
unk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
802 struct unk_impl
*This
= impl_from_IUnknown(iface
);
804 return IUnknown_QueryInterface(This
->inner_unk
, riid
, ppv
);
807 static ULONG WINAPI
unk_AddRef(IUnknown
*iface
)
809 struct unk_impl
*This
= impl_from_IUnknown(iface
);
811 return InterlockedIncrement(&This
->ref
);
814 static ULONG WINAPI
unk_Release(IUnknown
*iface
)
816 struct unk_impl
*This
= impl_from_IUnknown(iface
);
818 return InterlockedDecrement(&This
->ref
);
821 static const IUnknownVtbl unk_vtbl
=
828 static void test_COM(void)
830 struct unk_impl unk_obj
= {{&unk_vtbl
}, 19, NULL
};
831 struct ITextHostTestImpl texthost
= {{&itextHostVtbl
}, 1};
832 ITextServices
*textsrv
;
836 /* COM aggregation */
837 hr
= pCreateTextServices(&unk_obj
.IUnknown_iface
, &texthost
.ITextHost_iface
,
839 ok(hr
== S_OK
, "CreateTextServices failed: %08x\n", hr
);
840 hr
= IUnknown_QueryInterface(unk_obj
.inner_unk
, pIID_ITextServices
, (void**)&textsrv
);
841 ok(hr
== S_OK
, "QueryInterface for IID_ITextServices failed: %08x\n", hr
);
842 refcount
= ITextServices_AddRef(textsrv
);
843 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
844 refcount
= ITextServices_Release(textsrv
);
845 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
846 refcount
= ITextServices_Release(textsrv
);
847 ok(refcount
== 19, "Refcount should be back at 19 but is %u\n", refcount
);
849 IUnknown_Release(unk_obj
.inner_unk
);
852 static ULONG
get_refcount(IUnknown
*iface
)
854 IUnknown_AddRef(iface
);
855 return IUnknown_Release(iface
);
858 static void test_QueryInterface(void)
860 ITextServices
*txtserv
;
863 IRichEditOle
*reole
, *txtsrv_reole
;
864 ITextDocument
*txtdoc
, *txtsrv_txtdoc
;
865 ITextDocument2Old
*txtdoc2old
, *txtsrv_txtdoc2old
;
868 if(!init_texthost(&txtserv
, &host
))
871 refcount
= get_refcount((IUnknown
*)txtserv
);
872 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
874 /* IID_IRichEditOle */
875 hres
= ITextServices_QueryInterface(txtserv
, &IID_IRichEditOle
, (void **)&txtsrv_reole
);
876 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08x\n", hres
);
877 refcount
= get_refcount((IUnknown
*)txtserv
);
878 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
879 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
880 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
882 hres
= IRichEditOle_QueryInterface(txtsrv_reole
, &IID_ITextDocument
, (void **)&txtdoc
);
883 ok(hres
== S_OK
, "IRichEditOle_QueryInterface: 0x%08x\n", hres
);
884 refcount
= get_refcount((IUnknown
*)txtserv
);
885 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
886 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
887 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
889 ITextDocument_Release(txtdoc
);
890 refcount
= get_refcount((IUnknown
*)txtserv
);
891 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
893 hres
= IRichEditOle_QueryInterface(txtsrv_reole
, &IID_ITextDocument2Old
, (void **)&txtdoc2old
);
894 ok(hres
== S_OK
, "IRichEditOle_QueryInterface: 0x%08x\n", hres
);
895 refcount
= get_refcount((IUnknown
*)txtserv
);
896 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
897 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
898 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
900 ITextDocument2Old_Release(txtdoc2old
);
901 refcount
= get_refcount((IUnknown
*)txtserv
);
902 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
903 IRichEditOle_Release(txtsrv_reole
);
904 refcount
= get_refcount((IUnknown
*)txtserv
);
905 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
907 /* IID_ITextDocument */
908 hres
= ITextServices_QueryInterface(txtserv
, &IID_ITextDocument
, (void **)&txtsrv_txtdoc
);
909 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08x\n", hres
);
910 refcount
= get_refcount((IUnknown
*)txtserv
);
911 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
912 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
913 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
915 hres
= ITextDocument_QueryInterface(txtsrv_txtdoc
, &IID_IRichEditOle
, (void **)&reole
);
916 ok(hres
== S_OK
, "ITextDocument_QueryInterface: 0x%08x\n", hres
);
917 refcount
= get_refcount((IUnknown
*)txtserv
);
918 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
919 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
920 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
922 IRichEditOle_Release(reole
);
923 refcount
= get_refcount((IUnknown
*)txtserv
);
924 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
925 ITextDocument_Release(txtsrv_txtdoc
);
926 refcount
= get_refcount((IUnknown
*)txtserv
);
927 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
929 /* ITextDocument2Old */
930 hres
= ITextServices_QueryInterface(txtserv
, &IID_ITextDocument2Old
, (void **)&txtsrv_txtdoc2old
);
931 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08x\n", hres
);
932 refcount
= get_refcount((IUnknown
*)txtserv
);
933 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
934 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc2old
);
935 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
937 hres
= ITextDocument2Old_QueryInterface(txtsrv_txtdoc2old
, &IID_IRichEditOle
, (void **)&reole
);
938 ok(hres
== S_OK
, "ITextDocument2Old_QueryInterface: 0x%08x\n", hres
);
939 refcount
= get_refcount((IUnknown
*)txtserv
);
940 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
941 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc2old
);
942 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
944 IRichEditOle_Release(reole
);
945 refcount
= get_refcount((IUnknown
*)txtserv
);
946 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
947 ITextDocument2Old_Release(txtsrv_txtdoc2old
);
948 refcount
= get_refcount((IUnknown
*)txtserv
);
949 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
951 ITextServices_Release(txtserv
);
952 ITextHost_Release(host
);
955 static void test_default_format(void)
957 ITextServices
*txtserv
;
962 const CHARFORMATW
*host_cf
;
963 DWORD expected_effects
;
965 if (!init_texthost(&txtserv
, &host
))
968 cf2
.cbSize
= sizeof(CHARFORMAT2W
);
969 result
= ITextServices_TxSendMessage(txtserv
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&cf2
, &lresult
);
970 ok(result
== S_OK
, "ITextServices_TxSendMessage failed: 0x%08x.\n", result
);
972 ITextHostImpl_TxGetCharFormat(host
, &host_cf
);
973 ok(!lstrcmpW(host_cf
->szFaceName
, cf2
.szFaceName
), "got wrong font name: %s.\n", wine_dbgstr_w(cf2
.szFaceName
));
974 ok(cf2
.yHeight
== host_cf
->yHeight
, "got wrong yHeight: %d, expected %d.\n", cf2
.yHeight
, host_cf
->yHeight
);
975 expected_effects
= (cf2
.dwEffects
& ~(CFE_AUTOCOLOR
| CFE_AUTOBACKCOLOR
));
976 ok(host_cf
->dwEffects
== expected_effects
, "got wrong dwEffects: %x, expected %x.\n", cf2
.dwEffects
, expected_effects
);
977 ok(cf2
.bPitchAndFamily
== host_cf
->bPitchAndFamily
, "got wrong bPitchAndFamily: %x, expected %x.\n",
978 cf2
.bPitchAndFamily
, host_cf
->bPitchAndFamily
);
979 ok(cf2
.bCharSet
== host_cf
->bCharSet
, "got wrong bCharSet: %x, expected %x.\n", cf2
.bCharSet
, host_cf
->bCharSet
);
981 ITextServices_Release(txtserv
);
982 ITextHost_Release(host
);
985 static void test_TxGetScroll(void)
987 ITextServices
*txtserv
;
991 if (!init_texthost(&txtserv
, &host
))
994 ret
= ITextServices_TxGetHScroll(txtserv
, NULL
, NULL
, NULL
, NULL
, NULL
);
995 ok(ret
== S_OK
, "ITextServices_TxGetHScroll failed: 0x%08x.\n", ret
);
997 ret
= ITextServices_TxGetVScroll(txtserv
, NULL
, NULL
, NULL
, NULL
, NULL
);
998 ok(ret
== S_OK
, "ITextServices_TxGetVScroll failed: 0x%08x.\n", ret
);
1000 ITextServices_Release(txtserv
);
1001 ITextHost_Release(host
);
1004 START_TEST( txtsrv
)
1006 ITextServices
*txtserv
;
1009 setup_thiscall_wrappers();
1011 /* Must explicitly LoadLibrary(). The test has no references to functions in
1012 * RICHED20.DLL, so the linker doesn't actually link to it. */
1013 hmoduleRichEdit
= LoadLibraryA("riched20.dll");
1014 ok(hmoduleRichEdit
!= NULL
, "error: %d\n", (int) GetLastError());
1016 pIID_ITextServices
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextServices");
1017 pIID_ITextHost
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost");
1018 pIID_ITextHost2
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost2");
1019 pCreateTextServices
= (void*)GetProcAddress(hmoduleRichEdit
, "CreateTextServices");
1024 if (init_texthost(&txtserv
, &host
))
1026 ITextServices_Release(txtserv
);
1027 ITextHost_Release(host
);
1031 test_TxGetNaturalSize();
1033 test_QueryInterface();
1034 test_default_format();
1037 if (wrapperCodeMem
) VirtualFree(wrapperCodeMem
, 0, MEM_RELEASE
);