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
33 #include <wine/test.h>
37 static HMODULE hmoduleRichEdit
;
38 static IID
*pIID_ITextServices
;
39 static IID
*pIID_ITextHost
;
40 static IID
*pIID_ITextHost2
;
41 static PCreateTextServices pCreateTextServices
;
43 static const char *debugstr_guid(REFIID riid
)
50 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
51 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
52 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
53 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
58 /* Define C Macros for ITextServices calls. */
60 /* Use a special table for x86 machines to convert the thiscall
61 * calling convention. This isn't needed on other platforms. */
63 static ITextServicesVtbl itextServicesStdcallVtbl
;
64 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
66 #define TXTSERV_VTABLE(This) (This)->lpVtbl
69 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
70 #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)
71 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
72 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
73 #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)
74 #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)
75 #define ITextServices_OnTxInplaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInplaceActivate(This,a)
76 #define ITextServices_OnTxInplaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInplaceDeactivate(This)
77 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
78 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
79 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
80 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
81 #define ITextServices_TxGetCurrentTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurrentTargetX(This,a)
82 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
83 #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)
84 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
85 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
86 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
88 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
89 * function call traces of ITextHost. */
90 #define TRACECALL if(winetest_debug > 1) trace
92 /************************************************************************/
93 /* ITextHost implementation for conformance testing. */
95 typedef struct ITextHostTestImpl
97 ITextHost ITextHost_iface
;
101 static inline ITextHostTestImpl
*impl_from_ITextHost(ITextHost
*iface
)
103 return CONTAINING_RECORD(iface
, ITextHostTestImpl
, ITextHost_iface
);
106 static HRESULT WINAPI
ITextHostImpl_QueryInterface(ITextHost
*iface
,
110 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
112 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, pIID_ITextHost
)) {
114 ITextHost_AddRef((ITextHost
*)*ppvObject
);
118 return E_NOINTERFACE
;
121 static ULONG WINAPI
ITextHostImpl_AddRef(ITextHost
*iface
)
123 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
124 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
128 static ULONG WINAPI
ITextHostImpl_Release(ITextHost
*iface
)
130 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
131 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
142 static HDC WINAPI
ITextHostImpl_TxGetDC(ITextHost
*iface
)
144 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
145 TRACECALL("Call to TxGetDC(%p)\n", This
);
149 static INT WINAPI
ITextHostImpl_TxReleaseDC(ITextHost
*iface
,
152 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
153 TRACECALL("Call to TxReleaseDC(%p)\n", This
);
157 static BOOL WINAPI
ITextHostImpl_TxShowScrollBar(ITextHost
*iface
,
161 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
162 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
167 static BOOL WINAPI
ITextHostImpl_TxEnableScrollBar(ITextHost
*iface
,
171 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
172 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
173 This
, fuSBFlags
, fuArrowflags
);
177 static BOOL WINAPI
ITextHostImpl_TxSetScrollRange(ITextHost
*iface
,
183 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
184 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
185 This
, fnBar
, nMinPos
, nMaxPos
, fRedraw
);
189 static BOOL WINAPI
ITextHostImpl_TxSetScrollPos(ITextHost
*iface
,
194 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
195 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
196 This
, fnBar
, nPos
, fRedraw
);
200 static void WINAPI
ITextHostImpl_TxInvalidateRect(ITextHost
*iface
,
204 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
205 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
209 static void WINAPI
ITextHostImpl_TxViewChange(ITextHost
*iface
, BOOL fUpdate
)
211 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
212 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
216 static BOOL WINAPI
ITextHostImpl_TxCreateCaret(ITextHost
*iface
,
218 INT xWidth
, INT yHeight
)
220 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
221 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
222 This
, hbmp
, xWidth
, yHeight
);
226 static BOOL WINAPI
ITextHostImpl_TxShowCaret(ITextHost
*iface
, BOOL fShow
)
228 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
229 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
234 static BOOL WINAPI
ITextHostImpl_TxSetCaretPos(ITextHost
*iface
,
237 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
238 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This
, x
, y
);
242 static BOOL WINAPI
ITextHostImpl_TxSetTimer(ITextHost
*iface
,
243 UINT idTimer
, UINT uTimeout
)
245 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
246 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
247 This
, idTimer
, uTimeout
);
251 static void WINAPI
ITextHostImpl_TxKillTimer(ITextHost
*iface
, UINT idTimer
)
253 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
254 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This
, idTimer
);
257 static void WINAPI
ITextHostImpl_TxScrollWindowEx(ITextHost
*iface
,
265 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
266 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
267 This
, dx
, dy
, lprcScroll
, lprcClip
, hRgnUpdate
, lprcUpdate
, fuScroll
);
270 static void WINAPI
ITextHostImpl_TxSetCapture(ITextHost
*iface
, BOOL fCapture
)
272 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
273 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This
, fCapture
);
276 static void WINAPI
ITextHostImpl_TxSetFocus(ITextHost
*iface
)
278 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
279 TRACECALL("Call to TxSetFocus(%p)\n", This
);
282 static void WINAPI
ITextHostImpl_TxSetCursor(ITextHost
*iface
,
286 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
287 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
291 static BOOL WINAPI
ITextHostImpl_TxScreenToClient(ITextHost
*iface
,
294 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
295 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This
, lppt
);
299 static BOOL WINAPI
ITextHostImpl_TxClientToScreen(ITextHost
*iface
,
302 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
303 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This
, lppt
);
307 static HRESULT WINAPI
ITextHostImpl_TxActivate(ITextHost
*iface
,
310 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
311 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This
, plOldState
);
315 static HRESULT WINAPI
ITextHostImpl_TxDeactivate(ITextHost
*iface
,
318 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
319 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This
, lNewState
);
323 static HRESULT WINAPI
ITextHostImpl_TxGetClientRect(ITextHost
*iface
,
326 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
327 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This
, prc
);
331 static HRESULT WINAPI
ITextHostImpl_TxGetViewInset(ITextHost
*iface
,
334 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
335 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This
, prc
);
339 static HRESULT WINAPI
ITextHostImpl_TxGetCharFormat(ITextHost
*iface
,
340 const CHARFORMATW
**ppCF
)
342 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
343 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This
, ppCF
);
347 static HRESULT WINAPI
ITextHostImpl_TxGetParaFormat(ITextHost
*iface
,
348 const PARAFORMAT
**ppPF
)
350 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
351 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This
, ppPF
);
355 static COLORREF WINAPI
ITextHostImpl_TxGetSysColor(ITextHost
*iface
,
358 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
359 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This
, nIndex
);
363 static HRESULT WINAPI
ITextHostImpl_TxGetBackStyle(ITextHost
*iface
,
364 TXTBACKSTYLE
*pStyle
)
366 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
367 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This
, pStyle
);
371 static HRESULT WINAPI
ITextHostImpl_TxGetMaxLength(ITextHost
*iface
,
374 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
375 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This
, pLength
);
379 static HRESULT WINAPI
ITextHostImpl_TxGetScrollBars(ITextHost
*iface
,
382 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
383 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
388 static HRESULT WINAPI
ITextHostImpl_TxGetPasswordChar(ITextHost
*iface
,
391 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
392 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This
, pch
);
396 static HRESULT WINAPI
ITextHostImpl_TxGetAcceleratorPos(ITextHost
*iface
,
399 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
400 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This
, pch
);
404 static HRESULT WINAPI
ITextHostImpl_TxGetExtent(ITextHost
*iface
,
407 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
408 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This
, lpExtent
);
412 static HRESULT WINAPI
ITextHostImpl_OnTxCharFormatChange(ITextHost
*iface
,
413 const CHARFORMATW
*pcf
)
415 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
416 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This
, pcf
);
420 static HRESULT WINAPI
ITextHostImpl_OnTxParaFormatChange(ITextHost
*iface
,
421 const PARAFORMAT
*ppf
)
423 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
424 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This
, ppf
);
428 /* This must return S_OK for the native ITextServices object to
430 static HRESULT WINAPI
ITextHostImpl_TxGetPropertyBits(ITextHost
*iface
,
434 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
435 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
436 This
, dwMask
, pdwBits
);
441 static HRESULT WINAPI
ITextHostImpl_TxNotify(ITextHost
*iface
, DWORD iNotify
,
444 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
445 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This
, iNotify
, pv
);
449 static HIMC WINAPI
ITextHostImpl_TxImmGetContext(ITextHost
*iface
)
451 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
452 TRACECALL("Call to TxImmGetContext(%p)\n", This
);
456 static void WINAPI
ITextHostImpl_TxImmReleaseContext(ITextHost
*iface
, HIMC himc
)
458 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
459 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This
, himc
);
462 /* This function must set the variable pointed to by *lSelBarWidth.
463 Otherwise an uninitialized value will be used to calculate
464 positions and sizes even if E_NOTIMPL is returned. */
465 static HRESULT WINAPI
ITextHostImpl_TxGetSelectionBarWidth(ITextHost
*iface
,
468 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
469 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
475 static ITextHostVtbl itextHostVtbl
= {
476 ITextHostImpl_QueryInterface
,
477 ITextHostImpl_AddRef
,
478 ITextHostImpl_Release
,
479 ITextHostImpl_TxGetDC
,
480 ITextHostImpl_TxReleaseDC
,
481 ITextHostImpl_TxShowScrollBar
,
482 ITextHostImpl_TxEnableScrollBar
,
483 ITextHostImpl_TxSetScrollRange
,
484 ITextHostImpl_TxSetScrollPos
,
485 ITextHostImpl_TxInvalidateRect
,
486 ITextHostImpl_TxViewChange
,
487 ITextHostImpl_TxCreateCaret
,
488 ITextHostImpl_TxShowCaret
,
489 ITextHostImpl_TxSetCaretPos
,
490 ITextHostImpl_TxSetTimer
,
491 ITextHostImpl_TxKillTimer
,
492 ITextHostImpl_TxScrollWindowEx
,
493 ITextHostImpl_TxSetCapture
,
494 ITextHostImpl_TxSetFocus
,
495 ITextHostImpl_TxSetCursor
,
496 ITextHostImpl_TxScreenToClient
,
497 ITextHostImpl_TxClientToScreen
,
498 ITextHostImpl_TxActivate
,
499 ITextHostImpl_TxDeactivate
,
500 ITextHostImpl_TxGetClientRect
,
501 ITextHostImpl_TxGetViewInset
,
502 ITextHostImpl_TxGetCharFormat
,
503 ITextHostImpl_TxGetParaFormat
,
504 ITextHostImpl_TxGetSysColor
,
505 ITextHostImpl_TxGetBackStyle
,
506 ITextHostImpl_TxGetMaxLength
,
507 ITextHostImpl_TxGetScrollBars
,
508 ITextHostImpl_TxGetPasswordChar
,
509 ITextHostImpl_TxGetAcceleratorPos
,
510 ITextHostImpl_TxGetExtent
,
511 ITextHostImpl_OnTxCharFormatChange
,
512 ITextHostImpl_OnTxParaFormatChange
,
513 ITextHostImpl_TxGetPropertyBits
,
514 ITextHostImpl_TxNotify
,
515 ITextHostImpl_TxImmGetContext
,
516 ITextHostImpl_TxImmReleaseContext
,
517 ITextHostImpl_TxGetSelectionBarWidth
520 static ITextServices
*txtserv
= NULL
;
521 static ITextHostTestImpl
*dummyTextHost
;
522 static void *wrapperCodeMem
= NULL
;
524 #include "pshpack1.h"
526 /* Code structure for x86 byte code */
529 BYTE pop_eax
; /* popl %eax */
530 BYTE push_ecx
; /* pushl %ecx */
531 BYTE push_eax
; /* pushl %eax */
532 BYTE jmp_func
; /* jmp $func */
534 } THISCALL_TO_STDCALL_THUNK
;
538 BYTE pop_eax
; /* popl %eax */
539 BYTE pop_ecx
; /* popl %ecx */
540 BYTE push_eax
; /* pushl %eax */
541 BYTE mov_vtable_eax
[2]; /* movl (%ecx), %eax */
542 BYTE jmp_eax
[2]; /* jmp *$vtablefunc_offset(%eax) */
543 int vtablefunc_offset
;
544 } STDCALL_TO_THISCALL_THUNK
;
548 static void setup_thiscall_wrappers(void)
553 THISCALL_TO_STDCALL_THUNK
*thunk
;
554 STDCALL_TO_THISCALL_THUNK
*thunk2
;
556 wrapperCodeMem
= VirtualAlloc(NULL
,
557 (sizeof(ITextHostVtbl
)/sizeof(void*) - 3)
558 * sizeof(THISCALL_TO_STDCALL_THUNK
)
559 +(sizeof(ITextServicesVtbl
)/sizeof(void*) - 3)
560 * sizeof(STDCALL_TO_THISCALL_THUNK
),
561 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
562 thunk
= wrapperCodeMem
;
564 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
565 * stdcall conversion. The thiscall calling convention places the This
566 * pointer in ecx on the x86 platform, and the stdcall calling convention
567 * pushes the This pointer on the stack as the first argument.
569 * The byte code does the conversion then jumps to the real function.
571 * Each wrapper needs to be modified so that the function to jump to is
572 * modified in the byte code. */
574 /* Skip QueryInterface, AddRef, and Release native actually
575 * defined them with the stdcall calling convention. */
576 pVtable
= (void**)&itextHostVtbl
+ 3;
577 pVtableEnd
= (void**)(&itextHostVtbl
+ 1);
578 while (pVtable
!= pVtableEnd
) {
579 /* write byte code to executable memory */
580 thunk
->pop_eax
= 0x58; /* popl %eax */
581 thunk
->push_ecx
= 0x51; /* pushl %ecx */
582 thunk
->push_eax
= 0x50; /* pushl %eax */
583 thunk
->jmp_func
= 0xe9; /* jmp $func */
584 /* The address needs to be relative to the end of the jump instructions. */
585 thunk
->func
= (char*)*pVtable
- (char*)(&thunk
->func
+ 1);
591 /* Setup an ITextServices standard call vtable that will call the
592 * native thiscall vtable when the methods are called. */
594 /* QueryInterface, AddRef, and Release should be called directly on the
595 * real vtable since they use the stdcall calling convention. */
596 thunk2
= (STDCALL_TO_THISCALL_THUNK
*)thunk
;
597 pVtable
= (void**)&itextServicesStdcallVtbl
+ 3;
598 pVtableEnd
= (void**)(&itextServicesStdcallVtbl
+ 1);
599 while (pVtable
!= pVtableEnd
) {
600 /* write byte code to executable memory */
601 thunk2
->pop_eax
= 0x58; /* popl %eax */
602 thunk2
->pop_ecx
= 0x59; /* popl %ecx */
603 thunk2
->push_eax
= 0x50; /* pushl %eax */
604 thunk2
->mov_vtable_eax
[0] = 0x8b; /* movl (%ecx), %eax */
605 thunk2
->mov_vtable_eax
[1] = 0x01;
606 thunk2
->jmp_eax
[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
607 thunk2
->jmp_eax
[1] = 0xa0;
608 thunk2
->vtablefunc_offset
= (char*)pVtable
- (char*)&itextServicesStdcallVtbl
;
613 #endif /* __i386__ */
616 /*************************************************************************/
617 /* Conformance test functions. */
619 /* Initialize the test texthost structure */
620 static BOOL
init_texthost(void)
625 dummyTextHost
= CoTaskMemAlloc(sizeof(*dummyTextHost
));
626 if (dummyTextHost
== NULL
) {
627 skip("Insufficient memory to create ITextHost interface\n");
630 dummyTextHost
->ITextHost_iface
.lpVtbl
= &itextHostVtbl
;
631 dummyTextHost
->refCount
= 1;
633 /* MSDN states that an IUnknown object is returned by
634 CreateTextServices which is then queried to obtain a
635 ITextServices object. */
636 result
= (*pCreateTextServices
)(NULL
, &dummyTextHost
->ITextHost_iface
, &init
);
637 ok(result
== S_OK
, "Did not return S_OK when created (result = %x)\n", result
);
638 if (result
!= S_OK
) {
639 CoTaskMemFree(dummyTextHost
);
640 skip("CreateTextServices failed.\n");
644 result
= IUnknown_QueryInterface(init
, pIID_ITextServices
,
646 ok((result
== S_OK
) && (txtserv
!= NULL
), "Querying interface failed (result = %x, txtserv = %p)\n", result
, txtserv
);
647 IUnknown_Release(init
);
648 if (!((result
== S_OK
) && (txtserv
!= NULL
))) {
649 CoTaskMemFree(dummyTextHost
);
650 skip("Could not retrieve ITextServices interface\n");
657 static void free_texthost(void)
659 IUnknown_Release(txtserv
);
660 CoTaskMemFree(dummyTextHost
);
663 static void test_TxGetText(void)
668 if (!init_texthost())
671 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
672 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
677 static void test_TxSetText(void)
681 WCHAR settext
[] = {'T','e','s','t',0};
683 if (!init_texthost())
686 hres
= ITextServices_TxSetText(txtserv
, settext
);
687 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", hres
);
689 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
690 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
692 ok(SysStringLen(rettext
) == 4,
693 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext
));
694 ok(memcmp(rettext
,settext
,SysStringByteLen(rettext
)) == 0,
695 "String returned differs\n");
697 SysFreeString(rettext
);
701 static void test_TxGetNaturalSize(void) {
705 /* This value is used when calling TxGetNaturalSize. MSDN says
706 that this is not supported however a null pointer cannot be
707 used as it will cause a segmentation violation. The values in
708 the structure being pointed to are required to be INT_MAX
709 otherwise calculations can give wrong values. */
710 const SIZEL psizelExtent
= {INT_MAX
,INT_MAX
};
712 static const WCHAR oneA
[] = {'A',0};
714 /* Results of measurements */
717 /* The device context to do the tests in */
720 /* Variables with the text metric information */
721 INT charwidth_caps_text
[26];
722 TEXTMETRIC tmInfo_text
;
724 if (!init_texthost())
727 hdcDraw
= GetDC(NULL
);
730 /* Populate the metric strucs */
731 SetMapMode(hdcDraw
,MM_TEXT
);
732 GetTextMetrics(hdcDraw
, &tmInfo_text
);
733 SetLastError(0xdeadbeef);
734 ret
= GetCharWidth32(hdcDraw
,'A','Z',charwidth_caps_text
);
735 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
736 win_skip("GetCharWidth32 is not available\n");
740 /* Make measurements in MM_TEXT */
741 SetMapMode(hdcDraw
,MM_TEXT
);
744 result
= ITextServices_TxSetText(txtserv
, oneA
);
745 ok(result
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", result
);
746 if (result
!= S_OK
) {
747 skip("Could not set text\n");
751 SetLastError(0xdeadbeef);
752 result
= ITextServices_TxGetNaturalSize(txtserv
, DVASPECT_CONTENT
,
754 TXTNS_FITTOCONTENT
, &psizelExtent
,
756 todo_wine
ok(result
== S_OK
|| broken(result
== E_FAIL
), /* WINXP Arabic Language */
757 "TxGetNaturalSize gave unexpected return value (result = %x)\n", result
);
758 if (result
== S_OK
) {
759 todo_wine
ok(ydim
== tmInfo_text
.tmHeight
,
760 "Height calculated incorrectly (expected %d, got %d)\n",
761 tmInfo_text
.tmHeight
, ydim
);
762 /* The native DLL adds one pixel extra when calculating widths. */
763 todo_wine
ok(xdim
>= charwidth_caps_text
[0] && xdim
<= charwidth_caps_text
[0] + 1,
764 "Width calculated incorrectly (expected %d {+1}, got %d)\n",
765 charwidth_caps_text
[0], xdim
);
767 skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n",
768 xdim
, ydim
, result
, GetLastError());
771 RestoreDC(hdcDraw
,1);
772 ReleaseDC(NULL
,hdcDraw
);
776 static void test_TxDraw(void)
778 HDC tmphdc
= GetDC(NULL
);
779 DWORD dwAspect
= DVASPECT_CONTENT
;
780 HDC hicTargetDev
= NULL
; /* Means "default" device */
781 DVTARGETDEVICE
*ptd
= NULL
;
782 void *pvAspect
= NULL
;
784 RECTL client
= {0,0,100,100};
786 if (!init_texthost())
790 result
= ITextServices_TxDraw(txtserv
, dwAspect
, 0, pvAspect
, ptd
,
791 tmphdc
, hicTargetDev
, &client
, NULL
,
793 ok(result
== S_OK
, "TxDraw failed (result = %x)\n", result
);
800 DEFINE_GUID(expected_iid_itextservices
, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
801 DEFINE_GUID(expected_iid_itexthost
, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
802 DEFINE_GUID(expected_iid_itexthost2
, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
804 static void test_IIDs(void)
806 ok(IsEqualIID(pIID_ITextServices
, &expected_iid_itextservices
),
807 "unexpected value for IID_ITextServices: %s\n", debugstr_guid(pIID_ITextServices
));
808 ok(IsEqualIID(pIID_ITextHost
, &expected_iid_itexthost
),
809 "unexpected value for IID_ITextHost: %s\n", debugstr_guid(pIID_ITextHost
));
810 ok(IsEqualIID(pIID_ITextHost2
, &expected_iid_itexthost2
),
811 "unexpected value for IID_ITextHost2: %s\n", debugstr_guid(pIID_ITextHost2
));
817 setup_thiscall_wrappers();
819 /* Must explicitly LoadLibrary(). The test has no references to functions in
820 * RICHED20.DLL, so the linker doesn't actually link to it. */
821 hmoduleRichEdit
= LoadLibrary("RICHED20.DLL");
822 ok(hmoduleRichEdit
!= NULL
, "error: %d\n", (int) GetLastError());
824 pIID_ITextServices
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextServices");
825 pIID_ITextHost
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost");
826 pIID_ITextHost2
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost2");
827 pCreateTextServices
= (void*)GetProcAddress(hmoduleRichEdit
, "CreateTextServices");
837 test_TxGetNaturalSize();
840 if (wrapperCodeMem
) VirtualFree(wrapperCodeMem
, 0, MEM_RELEASE
);