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. */
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
;
90 static inline ITextHostTestImpl
*impl_from_ITextHost(ITextHost
*iface
)
92 return CONTAINING_RECORD(iface
, ITextHostTestImpl
, ITextHost_iface
);
95 static HRESULT WINAPI
ITextHostImpl_QueryInterface(ITextHost
*iface
,
99 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
101 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, pIID_ITextHost
)) {
103 ITextHost_AddRef((ITextHost
*)*ppvObject
);
107 return E_NOINTERFACE
;
110 static ULONG WINAPI
ITextHostImpl_AddRef(ITextHost
*iface
)
112 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
113 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
117 static ULONG WINAPI
ITextHostImpl_Release(ITextHost
*iface
)
119 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
120 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
131 static HDC WINAPI
ITextHostImpl_TxGetDC(ITextHost
*iface
)
133 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
134 TRACECALL("Call to TxGetDC(%p)\n", This
);
138 static INT WINAPI
ITextHostImpl_TxReleaseDC(ITextHost
*iface
,
141 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
142 TRACECALL("Call to TxReleaseDC(%p)\n", This
);
146 static BOOL WINAPI
ITextHostImpl_TxShowScrollBar(ITextHost
*iface
,
150 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
151 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
156 static BOOL WINAPI
ITextHostImpl_TxEnableScrollBar(ITextHost
*iface
,
160 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
161 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
162 This
, fuSBFlags
, fuArrowflags
);
166 static BOOL WINAPI
ITextHostImpl_TxSetScrollRange(ITextHost
*iface
,
172 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
173 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
174 This
, fnBar
, nMinPos
, nMaxPos
, fRedraw
);
178 static BOOL WINAPI
ITextHostImpl_TxSetScrollPos(ITextHost
*iface
,
183 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
184 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
185 This
, fnBar
, nPos
, fRedraw
);
189 static void WINAPI
ITextHostImpl_TxInvalidateRect(ITextHost
*iface
,
193 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
194 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
198 static void WINAPI
ITextHostImpl_TxViewChange(ITextHost
*iface
, BOOL fUpdate
)
200 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
201 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
205 static BOOL WINAPI
ITextHostImpl_TxCreateCaret(ITextHost
*iface
,
207 INT xWidth
, INT yHeight
)
209 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
210 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
211 This
, hbmp
, xWidth
, yHeight
);
215 static BOOL WINAPI
ITextHostImpl_TxShowCaret(ITextHost
*iface
, BOOL fShow
)
217 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
218 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
223 static BOOL WINAPI
ITextHostImpl_TxSetCaretPos(ITextHost
*iface
,
226 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
227 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This
, x
, y
);
231 static BOOL WINAPI
ITextHostImpl_TxSetTimer(ITextHost
*iface
,
232 UINT idTimer
, UINT uTimeout
)
234 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
235 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
236 This
, idTimer
, uTimeout
);
240 static void WINAPI
ITextHostImpl_TxKillTimer(ITextHost
*iface
, UINT idTimer
)
242 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
243 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This
, idTimer
);
246 static void WINAPI
ITextHostImpl_TxScrollWindowEx(ITextHost
*iface
,
254 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
255 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
256 This
, dx
, dy
, lprcScroll
, lprcClip
, hRgnUpdate
, lprcUpdate
, fuScroll
);
259 static void WINAPI
ITextHostImpl_TxSetCapture(ITextHost
*iface
, BOOL fCapture
)
261 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
262 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This
, fCapture
);
265 static void WINAPI
ITextHostImpl_TxSetFocus(ITextHost
*iface
)
267 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
268 TRACECALL("Call to TxSetFocus(%p)\n", This
);
271 static void WINAPI
ITextHostImpl_TxSetCursor(ITextHost
*iface
,
275 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
276 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
280 static BOOL WINAPI
ITextHostImpl_TxScreenToClient(ITextHost
*iface
,
283 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
284 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This
, lppt
);
288 static BOOL WINAPI
ITextHostImpl_TxClientToScreen(ITextHost
*iface
,
291 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
292 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This
, lppt
);
296 static HRESULT WINAPI
ITextHostImpl_TxActivate(ITextHost
*iface
,
299 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
300 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This
, plOldState
);
304 static HRESULT WINAPI
ITextHostImpl_TxDeactivate(ITextHost
*iface
,
307 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
308 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This
, lNewState
);
312 static HRESULT WINAPI
ITextHostImpl_TxGetClientRect(ITextHost
*iface
,
315 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
316 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This
, prc
);
320 static HRESULT WINAPI
ITextHostImpl_TxGetViewInset(ITextHost
*iface
,
323 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
324 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This
, prc
);
328 static HRESULT WINAPI
ITextHostImpl_TxGetCharFormat(ITextHost
*iface
,
329 const CHARFORMATW
**ppCF
)
331 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
332 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This
, ppCF
);
336 static HRESULT WINAPI
ITextHostImpl_TxGetParaFormat(ITextHost
*iface
,
337 const PARAFORMAT
**ppPF
)
339 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
340 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This
, ppPF
);
344 static COLORREF WINAPI
ITextHostImpl_TxGetSysColor(ITextHost
*iface
,
347 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
348 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This
, nIndex
);
352 static HRESULT WINAPI
ITextHostImpl_TxGetBackStyle(ITextHost
*iface
,
353 TXTBACKSTYLE
*pStyle
)
355 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
356 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This
, pStyle
);
360 static HRESULT WINAPI
ITextHostImpl_TxGetMaxLength(ITextHost
*iface
,
363 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
364 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This
, pLength
);
368 static HRESULT WINAPI
ITextHostImpl_TxGetScrollBars(ITextHost
*iface
,
371 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
372 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
377 static HRESULT WINAPI
ITextHostImpl_TxGetPasswordChar(ITextHost
*iface
,
380 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
381 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This
, pch
);
385 static HRESULT WINAPI
ITextHostImpl_TxGetAcceleratorPos(ITextHost
*iface
,
388 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
389 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This
, pch
);
393 static HRESULT WINAPI
ITextHostImpl_TxGetExtent(ITextHost
*iface
,
396 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
397 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This
, lpExtent
);
401 static HRESULT WINAPI
ITextHostImpl_OnTxCharFormatChange(ITextHost
*iface
,
402 const CHARFORMATW
*pcf
)
404 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
405 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This
, pcf
);
409 static HRESULT WINAPI
ITextHostImpl_OnTxParaFormatChange(ITextHost
*iface
,
410 const PARAFORMAT
*ppf
)
412 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
413 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This
, ppf
);
417 /* This must return S_OK for the native ITextServices object to
419 static HRESULT WINAPI
ITextHostImpl_TxGetPropertyBits(ITextHost
*iface
,
423 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
424 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
425 This
, dwMask
, pdwBits
);
430 static HRESULT WINAPI
ITextHostImpl_TxNotify(ITextHost
*iface
, DWORD iNotify
,
433 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
434 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This
, iNotify
, pv
);
438 static HIMC WINAPI
ITextHostImpl_TxImmGetContext(ITextHost
*iface
)
440 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
441 TRACECALL("Call to TxImmGetContext(%p)\n", This
);
445 static void WINAPI
ITextHostImpl_TxImmReleaseContext(ITextHost
*iface
, HIMC himc
)
447 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
448 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This
, himc
);
451 /* This function must set the variable pointed to by *lSelBarWidth.
452 Otherwise an uninitialized value will be used to calculate
453 positions and sizes even if E_NOTIMPL is returned. */
454 static HRESULT WINAPI
ITextHostImpl_TxGetSelectionBarWidth(ITextHost
*iface
,
457 ITextHostTestImpl
*This
= impl_from_ITextHost(iface
);
458 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
464 static ITextHostVtbl itextHostVtbl
= {
465 ITextHostImpl_QueryInterface
,
466 ITextHostImpl_AddRef
,
467 ITextHostImpl_Release
,
468 ITextHostImpl_TxGetDC
,
469 ITextHostImpl_TxReleaseDC
,
470 ITextHostImpl_TxShowScrollBar
,
471 ITextHostImpl_TxEnableScrollBar
,
472 ITextHostImpl_TxSetScrollRange
,
473 ITextHostImpl_TxSetScrollPos
,
474 ITextHostImpl_TxInvalidateRect
,
475 ITextHostImpl_TxViewChange
,
476 ITextHostImpl_TxCreateCaret
,
477 ITextHostImpl_TxShowCaret
,
478 ITextHostImpl_TxSetCaretPos
,
479 ITextHostImpl_TxSetTimer
,
480 ITextHostImpl_TxKillTimer
,
481 ITextHostImpl_TxScrollWindowEx
,
482 ITextHostImpl_TxSetCapture
,
483 ITextHostImpl_TxSetFocus
,
484 ITextHostImpl_TxSetCursor
,
485 ITextHostImpl_TxScreenToClient
,
486 ITextHostImpl_TxClientToScreen
,
487 ITextHostImpl_TxActivate
,
488 ITextHostImpl_TxDeactivate
,
489 ITextHostImpl_TxGetClientRect
,
490 ITextHostImpl_TxGetViewInset
,
491 ITextHostImpl_TxGetCharFormat
,
492 ITextHostImpl_TxGetParaFormat
,
493 ITextHostImpl_TxGetSysColor
,
494 ITextHostImpl_TxGetBackStyle
,
495 ITextHostImpl_TxGetMaxLength
,
496 ITextHostImpl_TxGetScrollBars
,
497 ITextHostImpl_TxGetPasswordChar
,
498 ITextHostImpl_TxGetAcceleratorPos
,
499 ITextHostImpl_TxGetExtent
,
500 ITextHostImpl_OnTxCharFormatChange
,
501 ITextHostImpl_OnTxParaFormatChange
,
502 ITextHostImpl_TxGetPropertyBits
,
503 ITextHostImpl_TxNotify
,
504 ITextHostImpl_TxImmGetContext
,
505 ITextHostImpl_TxImmReleaseContext
,
506 ITextHostImpl_TxGetSelectionBarWidth
509 static void *wrapperCodeMem
= NULL
;
511 #include "pshpack1.h"
513 /* Code structure for x86 byte code */
516 BYTE pop_eax
; /* popl %eax */
517 BYTE push_ecx
; /* pushl %ecx */
518 BYTE push_eax
; /* pushl %eax */
519 BYTE jmp_func
; /* jmp $func */
521 } THISCALL_TO_STDCALL_THUNK
;
525 BYTE pop_eax
; /* popl %eax */
526 BYTE pop_ecx
; /* popl %ecx */
527 BYTE push_eax
; /* pushl %eax */
528 BYTE mov_vtable_eax
[2]; /* movl (%ecx), %eax */
529 BYTE jmp_eax
[2]; /* jmp *$vtablefunc_offset(%eax) */
530 int vtablefunc_offset
;
531 } STDCALL_TO_THISCALL_THUNK
;
535 static void setup_thiscall_wrappers(void)
540 THISCALL_TO_STDCALL_THUNK
*thunk
;
541 STDCALL_TO_THISCALL_THUNK
*thunk2
;
543 wrapperCodeMem
= VirtualAlloc(NULL
,
544 (sizeof(ITextHostVtbl
)/sizeof(void*) - 3)
545 * sizeof(THISCALL_TO_STDCALL_THUNK
)
546 +(sizeof(ITextServicesVtbl
)/sizeof(void*) - 3)
547 * sizeof(STDCALL_TO_THISCALL_THUNK
),
548 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
549 thunk
= wrapperCodeMem
;
551 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
552 * stdcall conversion. The thiscall calling convention places the This
553 * pointer in ecx on the x86 platform, and the stdcall calling convention
554 * pushes the This pointer on the stack as the first argument.
556 * The byte code does the conversion then jumps to the real function.
558 * Each wrapper needs to be modified so that the function to jump to is
559 * modified in the byte code. */
561 /* Skip QueryInterface, AddRef, and Release native actually
562 * defined them with the stdcall calling convention. */
563 pVtable
= (void**)&itextHostVtbl
+ 3;
564 pVtableEnd
= (void**)(&itextHostVtbl
+ 1);
565 while (pVtable
!= pVtableEnd
) {
566 /* write byte code to executable memory */
567 thunk
->pop_eax
= 0x58; /* popl %eax */
568 thunk
->push_ecx
= 0x51; /* pushl %ecx */
569 thunk
->push_eax
= 0x50; /* pushl %eax */
570 thunk
->jmp_func
= 0xe9; /* jmp $func */
571 /* The address needs to be relative to the end of the jump instructions. */
572 thunk
->func
= (char*)*pVtable
- (char*)(&thunk
->func
+ 1);
578 /* Setup an ITextServices standard call vtable that will call the
579 * native thiscall vtable when the methods are called. */
581 /* QueryInterface, AddRef, and Release should be called directly on the
582 * real vtable since they use the stdcall calling convention. */
583 thunk2
= (STDCALL_TO_THISCALL_THUNK
*)thunk
;
584 pVtable
= (void**)&itextServicesStdcallVtbl
+ 3;
585 pVtableEnd
= (void**)(&itextServicesStdcallVtbl
+ 1);
586 while (pVtable
!= pVtableEnd
) {
587 /* write byte code to executable memory */
588 thunk2
->pop_eax
= 0x58; /* popl %eax */
589 thunk2
->pop_ecx
= 0x59; /* popl %ecx */
590 thunk2
->push_eax
= 0x50; /* pushl %eax */
591 thunk2
->mov_vtable_eax
[0] = 0x8b; /* movl (%ecx), %eax */
592 thunk2
->mov_vtable_eax
[1] = 0x01;
593 thunk2
->jmp_eax
[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
594 thunk2
->jmp_eax
[1] = 0xa0;
595 thunk2
->vtablefunc_offset
= (char*)pVtable
- (char*)&itextServicesStdcallVtbl
;
600 #endif /* __i386__ */
603 /*************************************************************************/
604 /* Conformance test functions. */
606 /* Initialize the test texthost structure */
607 static BOOL
init_texthost(ITextServices
**txtserv
, ITextHost
**ret
)
609 ITextHostTestImpl
*dummyTextHost
;
613 dummyTextHost
= CoTaskMemAlloc(sizeof(*dummyTextHost
));
614 if (dummyTextHost
== NULL
) {
615 win_skip("Insufficient memory to create ITextHost interface\n");
618 dummyTextHost
->ITextHost_iface
.lpVtbl
= &itextHostVtbl
;
619 dummyTextHost
->refCount
= 1;
621 /* MSDN states that an IUnknown object is returned by
622 CreateTextServices which is then queried to obtain a
623 ITextServices object. */
624 result
= pCreateTextServices(NULL
, &dummyTextHost
->ITextHost_iface
, &init
);
625 ok(result
== S_OK
, "Did not return S_OK when created (result = %x)\n", result
);
626 if (result
!= S_OK
) {
627 CoTaskMemFree(dummyTextHost
);
628 win_skip("CreateTextServices failed.\n");
632 result
= IUnknown_QueryInterface(init
, pIID_ITextServices
, (void**)txtserv
);
633 ok((result
== S_OK
) && (*txtserv
!= NULL
), "Querying interface failed (result = %x, txtserv = %p)\n", result
, *txtserv
);
634 IUnknown_Release(init
);
635 if (!((result
== S_OK
) && (*txtserv
!= NULL
))) {
636 CoTaskMemFree(dummyTextHost
);
637 win_skip("Could not retrieve ITextServices interface\n");
641 *ret
= &dummyTextHost
->ITextHost_iface
;
645 static void test_TxGetText(void)
647 ITextServices
*txtserv
;
652 if (!init_texthost(&txtserv
, &host
))
655 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
656 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
658 ITextServices_Release(txtserv
);
659 ITextHost_Release(host
);
662 static void test_TxSetText(void)
664 ITextServices
*txtserv
;
668 WCHAR settext
[] = {'T','e','s','t',0};
670 if (!init_texthost(&txtserv
, &host
))
673 hres
= ITextServices_TxSetText(txtserv
, settext
);
674 ok(hres
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", hres
);
676 hres
= ITextServices_TxGetText(txtserv
, &rettext
);
677 ok(hres
== S_OK
, "ITextServices_TxGetText failed (result = %x)\n", hres
);
679 ok(SysStringLen(rettext
) == 4,
680 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext
));
681 ok(memcmp(rettext
,settext
,SysStringByteLen(rettext
)) == 0,
682 "String returned differs\n");
684 SysFreeString(rettext
);
685 ITextServices_Release(txtserv
);
686 ITextHost_Release(host
);
689 static void test_TxGetNaturalSize(void)
691 ITextServices
*txtserv
;
696 /* This value is used when calling TxGetNaturalSize. MSDN says
697 that this is not supported however a null pointer cannot be
698 used as it will cause a segmentation violation. The values in
699 the structure being pointed to are required to be INT_MAX
700 otherwise calculations can give wrong values. */
701 const SIZEL psizelExtent
= {INT_MAX
,INT_MAX
};
703 static const WCHAR oneA
[] = {'A',0};
705 /* Results of measurements */
708 /* The device context to do the tests in */
711 /* Variables with the text metric information */
712 INT charwidth_caps_text
[26];
713 TEXTMETRICA tmInfo_text
;
715 if (!init_texthost(&txtserv
, &host
))
718 hdcDraw
= GetDC(NULL
);
721 /* Populate the metric strucs */
722 SetMapMode(hdcDraw
,MM_TEXT
);
723 GetTextMetricsA(hdcDraw
, &tmInfo_text
);
724 SetLastError(0xdeadbeef);
725 ret
= GetCharWidth32A(hdcDraw
,'A','Z',charwidth_caps_text
);
726 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
727 win_skip("GetCharWidth32 is not available\n");
731 /* Make measurements in MM_TEXT */
732 SetMapMode(hdcDraw
,MM_TEXT
);
735 result
= ITextServices_TxSetText(txtserv
, oneA
);
736 ok(result
== S_OK
, "ITextServices_TxSetText failed (result = %x)\n", result
);
737 if (result
!= S_OK
) {
738 skip("Could not set text\n");
742 SetLastError(0xdeadbeef);
743 result
= ITextServices_TxGetNaturalSize(txtserv
, DVASPECT_CONTENT
,
745 TXTNS_FITTOCONTENT
, &psizelExtent
,
747 todo_wine
ok(result
== S_OK
|| broken(result
== E_FAIL
), /* WINXP Arabic Language */
748 "TxGetNaturalSize gave unexpected return value (result = %x)\n", result
);
749 if (result
== S_OK
) {
750 todo_wine
ok(ydim
== tmInfo_text
.tmHeight
,
751 "Height calculated incorrectly (expected %d, got %d)\n",
752 tmInfo_text
.tmHeight
, ydim
);
753 /* The native DLL adds one pixel extra when calculating widths. */
754 todo_wine
ok(xdim
>= charwidth_caps_text
[0] && xdim
<= charwidth_caps_text
[0] + 1,
755 "Width calculated incorrectly (expected %d {+1}, got %d)\n",
756 charwidth_caps_text
[0], xdim
);
758 skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n",
759 xdim
, ydim
, result
, GetLastError());
762 RestoreDC(hdcDraw
,1);
763 ReleaseDC(NULL
,hdcDraw
);
764 ITextServices_Release(txtserv
);
765 ITextHost_Release(host
);
768 static void test_TxDraw(void)
770 ITextServices
*txtserv
;
772 HDC tmphdc
= GetDC(NULL
);
773 DWORD dwAspect
= DVASPECT_CONTENT
;
774 HDC hicTargetDev
= NULL
; /* Means "default" device */
775 DVTARGETDEVICE
*ptd
= NULL
;
776 void *pvAspect
= NULL
;
778 RECTL client
= {0,0,100,100};
781 if (!init_texthost(&txtserv
, &host
))
785 result
= ITextServices_TxDraw(txtserv
, dwAspect
, 0, pvAspect
, ptd
,
786 tmphdc
, hicTargetDev
, &client
, NULL
,
788 ok(result
== S_OK
, "TxDraw failed (result = %x)\n", result
);
791 ITextServices_Release(txtserv
);
792 ITextHost_Release(host
);
795 DEFINE_GUID(expected_iid_itextservices
, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
796 DEFINE_GUID(expected_iid_itexthost
, 0x13e670f4,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
797 DEFINE_GUID(expected_iid_itexthost2
, 0x13e670f5,0x1a5a,0x11cf,0xab,0xeb,0x00,0xaa,0x00,0xb6,0x5e,0xa1);
799 static void test_IIDs(void)
801 ok(IsEqualIID(pIID_ITextServices
, &expected_iid_itextservices
),
802 "unexpected value for IID_ITextServices: %s\n", wine_dbgstr_guid(pIID_ITextServices
));
803 ok(IsEqualIID(pIID_ITextHost
, &expected_iid_itexthost
),
804 "unexpected value for IID_ITextHost: %s\n", wine_dbgstr_guid(pIID_ITextHost
));
805 ok(IsEqualIID(pIID_ITextHost2
, &expected_iid_itexthost2
),
806 "unexpected value for IID_ITextHost2: %s\n", wine_dbgstr_guid(pIID_ITextHost2
));
809 /* Outer IUnknown for COM aggregation tests */
811 IUnknown IUnknown_iface
;
816 static inline struct unk_impl
*impl_from_IUnknown(IUnknown
*iface
)
818 return CONTAINING_RECORD(iface
, struct unk_impl
, IUnknown_iface
);
821 static HRESULT WINAPI
unk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
823 struct unk_impl
*This
= impl_from_IUnknown(iface
);
825 return IUnknown_QueryInterface(This
->inner_unk
, riid
, ppv
);
828 static ULONG WINAPI
unk_AddRef(IUnknown
*iface
)
830 struct unk_impl
*This
= impl_from_IUnknown(iface
);
832 return InterlockedIncrement(&This
->ref
);
835 static ULONG WINAPI
unk_Release(IUnknown
*iface
)
837 struct unk_impl
*This
= impl_from_IUnknown(iface
);
839 return InterlockedDecrement(&This
->ref
);
842 static const IUnknownVtbl unk_vtbl
=
849 static void test_COM(void)
851 struct unk_impl unk_obj
= {{&unk_vtbl
}, 19, NULL
};
852 struct ITextHostTestImpl texthost
= {{&itextHostVtbl
}, 1};
853 ITextServices
*textsrv
;
857 /* COM aggregation */
858 hr
= pCreateTextServices(&unk_obj
.IUnknown_iface
, &texthost
.ITextHost_iface
,
860 ok(hr
== S_OK
, "CreateTextServices failed: %08x\n", hr
);
861 hr
= IUnknown_QueryInterface(unk_obj
.inner_unk
, pIID_ITextServices
, (void**)&textsrv
);
862 ok(hr
== S_OK
, "QueryInterface for IID_ITextServices failed: %08x\n", hr
);
863 refcount
= ITextServices_AddRef(textsrv
);
864 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
865 refcount
= ITextServices_Release(textsrv
);
866 ok(refcount
== unk_obj
.ref
, "CreateTextServices just pretends to support COM aggregation\n");
867 refcount
= ITextServices_Release(textsrv
);
868 ok(refcount
== 19, "Refcount should be back at 19 but is %u\n", refcount
);
870 IUnknown_Release(unk_obj
.inner_unk
);
873 static ULONG
get_refcount(IUnknown
*iface
)
875 IUnknown_AddRef(iface
);
876 return IUnknown_Release(iface
);
879 static void test_QueryInterface(void)
881 ITextServices
*txtserv
;
884 IRichEditOle
*reole
, *txtsrv_reole
;
885 ITextDocument
*txtdoc
, *txtsrv_txtdoc
;
888 if(!init_texthost(&txtserv
, &host
))
891 refcount
= get_refcount((IUnknown
*)txtserv
);
892 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
894 /* IID_IRichEditOle */
895 hres
= ITextServices_QueryInterface(txtserv
, &IID_IRichEditOle
, (void **)&txtsrv_reole
);
896 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08x\n", hres
);
897 refcount
= get_refcount((IUnknown
*)txtserv
);
898 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
899 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
900 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
902 hres
= IRichEditOle_QueryInterface(txtsrv_reole
, &IID_ITextDocument
, (void **)&txtdoc
);
903 ok(hres
== S_OK
, "IRichEditOle_QueryInterface: 0x%08x\n", hres
);
904 refcount
= get_refcount((IUnknown
*)txtserv
);
905 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
906 refcount
= get_refcount((IUnknown
*)txtsrv_reole
);
907 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
909 ITextDocument_Release(txtdoc
);
910 refcount
= get_refcount((IUnknown
*)txtserv
);
911 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
912 IRichEditOle_Release(txtsrv_reole
);
913 refcount
= get_refcount((IUnknown
*)txtserv
);
914 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
916 /* IID_ITextDocument */
917 hres
= ITextServices_QueryInterface(txtserv
, &IID_ITextDocument
, (void **)&txtsrv_txtdoc
);
918 ok(hres
== S_OK
, "ITextServices_QueryInterface: 0x%08x\n", hres
);
919 refcount
= get_refcount((IUnknown
*)txtserv
);
920 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
921 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
922 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
924 hres
= ITextDocument_QueryInterface(txtsrv_txtdoc
, &IID_IRichEditOle
, (void **)&reole
);
925 ok(hres
== S_OK
, "ITextDocument_QueryInterface: 0x%08x\n", hres
);
926 refcount
= get_refcount((IUnknown
*)txtserv
);
927 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
928 refcount
= get_refcount((IUnknown
*)txtsrv_txtdoc
);
929 ok(refcount
== 3, "got wrong ref count: %d\n", refcount
);
931 IRichEditOle_Release(reole
);
932 refcount
= get_refcount((IUnknown
*)txtserv
);
933 ok(refcount
== 2, "got wrong ref count: %d\n", refcount
);
934 ITextDocument_Release(txtsrv_txtdoc
);
935 refcount
= get_refcount((IUnknown
*)txtserv
);
936 ok(refcount
== 1, "got wrong ref count: %d\n", refcount
);
938 ITextServices_Release(txtserv
);
939 ITextHost_Release(host
);
944 ITextServices
*txtserv
;
947 setup_thiscall_wrappers();
949 /* Must explicitly LoadLibrary(). The test has no references to functions in
950 * RICHED20.DLL, so the linker doesn't actually link to it. */
951 hmoduleRichEdit
= LoadLibraryA("riched20.dll");
952 ok(hmoduleRichEdit
!= NULL
, "error: %d\n", (int) GetLastError());
954 pIID_ITextServices
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextServices");
955 pIID_ITextHost
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost");
956 pIID_ITextHost2
= (IID
*)GetProcAddress(hmoduleRichEdit
, "IID_ITextHost2");
957 pCreateTextServices
= (void*)GetProcAddress(hmoduleRichEdit
, "CreateTextServices");
962 if (init_texthost(&txtserv
, &host
))
964 ITextServices_Release(txtserv
);
965 ITextHost_Release(host
);
969 test_TxGetNaturalSize();
971 test_QueryInterface();
973 if (wrapperCodeMem
) VirtualFree(wrapperCodeMem
, 0, MEM_RELEASE
);