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;
39 /* Define C Macros for ITextServices calls. */
41 /* Use a special table for x86 machines to convert the thiscall
42 * calling convention. This isn't needed on other platforms. */
44 static ITextServicesVtbl itextServicesStdcallVtbl;
45 #define TXTSERV_VTABLE(This) (&itextServicesStdcallVtbl)
47 #define TXTSERV_VTABLE(This) (This)->lpVtbl
50 #define ITextServices_TxSendMessage(This,a,b,c,d) TXTSERV_VTABLE(This)->TxSendMessage(This,a,b,c,d)
51 #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)
52 #define ITextServices_TxGetHScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetHScroll(This,a,b,c,d,e)
53 #define ITextServices_TxGetVScroll(This,a,b,c,d,e) TXTSERV_VTABLE(This)->TxGetVScroll(This,a,b,c,d,e)
54 #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)
55 #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)
56 #define ITextServices_OnTxInplaceActivate(This,a) TXTSERV_VTABLE(This)->OnTxInplaceActivate(This,a)
57 #define ITextServices_OnTxInplaceDeactivate(This) TXTSERV_VTABLE(This)->OnTxInplaceDeactivate(This)
58 #define ITextServices_OnTxUIActivate(This) TXTSERV_VTABLE(This)->OnTxUIActivate(This)
59 #define ITextServices_OnTxUIDeactivate(This) TXTSERV_VTABLE(This)->OnTxUIDeactivate(This)
60 #define ITextServices_TxGetText(This,a) TXTSERV_VTABLE(This)->TxGetText(This,a)
61 #define ITextServices_TxSetText(This,a) TXTSERV_VTABLE(This)->TxSetText(This,a)
62 #define ITextServices_TxGetCurrentTargetX(This,a) TXTSERV_VTABLE(This)->TxGetCurrentTargetX(This,a)
63 #define ITextServices_TxGetBaseLinePos(This,a) TXTSERV_VTABLE(This)->TxGetBaseLinePos(This,a)
64 #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)
65 #define ITextServices_TxGetDropTarget(This,a) TXTSERV_VTABLE(This)->TxGetDropTarget(This,a)
66 #define ITextServices_OnTxPropertyBitsChange(This,a,b) TXTSERV_VTABLE(This)->OnTxPropertyBitsChange(This,a,b)
67 #define ITextServices_TxGetCachedSize(This,a,b) TXTSERV_VTABLE(This)->TxGetCachedSize(This,a,b)
69 /* Set the WINETEST_DEBUG environment variable to be greater than 1 for verbose
70 * function call traces of ITextHost. */
71 #define TRACECALL if(winetest_debug > 1) trace
73 /************************************************************************/
74 /* ITextHost implementation for conformance testing. */
76 typedef struct ITextHostTestImpl
78 ITextHost ITextHost_iface;
82 static inline ITextHostTestImpl *impl_from_ITextHost(ITextHost *iface)
84 return CONTAINING_RECORD(iface, ITextHostTestImpl, ITextHost_iface);
87 static HRESULT WINAPI ITextHostImpl_QueryInterface(ITextHost *iface,
91 ITextHostTestImpl *This = impl_from_ITextHost(iface);
93 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ITextHost)) {
95 ITextHost_AddRef((ITextHost *)*ppvObject);
102 static ULONG WINAPI ITextHostImpl_AddRef(ITextHost *iface)
104 ITextHostTestImpl *This = impl_from_ITextHost(iface);
105 ULONG refCount = InterlockedIncrement(&This->refCount);
109 static ULONG WINAPI ITextHostImpl_Release(ITextHost *iface)
111 ITextHostTestImpl *This = impl_from_ITextHost(iface);
112 ULONG refCount = InterlockedDecrement(&This->refCount);
123 static HDC WINAPI ITextHostImpl_TxGetDC(ITextHost *iface)
125 ITextHostTestImpl *This = impl_from_ITextHost(iface);
126 TRACECALL("Call to TxGetDC(%p)\n", This);
130 static INT WINAPI ITextHostImpl_TxReleaseDC(ITextHost *iface,
133 ITextHostTestImpl *This = impl_from_ITextHost(iface);
134 TRACECALL("Call to TxReleaseDC(%p)\n", This);
138 static BOOL WINAPI ITextHostImpl_TxShowScrollBar(ITextHost *iface,
142 ITextHostTestImpl *This = impl_from_ITextHost(iface);
143 TRACECALL("Call to TxShowScrollBar(%p, fnBar=%d, fShow=%d)\n",
148 static BOOL WINAPI ITextHostImpl_TxEnableScrollBar(ITextHost *iface,
152 ITextHostTestImpl *This = impl_from_ITextHost(iface);
153 TRACECALL("Call to TxEnableScrollBar(%p, fuSBFlags=%d, fuArrowflags=%d)\n",
154 This, fuSBFlags, fuArrowflags);
158 static BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface,
164 ITextHostTestImpl *This = impl_from_ITextHost(iface);
165 TRACECALL("Call to TxSetScrollRange(%p, fnBar=%d, nMinPos=%d, nMaxPos=%d, fRedraw=%d)\n",
166 This, fnBar, nMinPos, nMaxPos, fRedraw);
170 static BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface,
175 ITextHostTestImpl *This = impl_from_ITextHost(iface);
176 TRACECALL("Call to TxSetScrollPos(%p, fnBar=%d, nPos=%d, fRedraw=%d)\n",
177 This, fnBar, nPos, fRedraw);
181 static void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface,
185 ITextHostTestImpl *This = impl_from_ITextHost(iface);
186 TRACECALL("Call to TxInvalidateRect(%p, prc=%p, fMode=%d)\n",
190 static void WINAPI ITextHostImpl_TxViewChange(ITextHost *iface, BOOL fUpdate)
192 ITextHostTestImpl *This = impl_from_ITextHost(iface);
193 TRACECALL("Call to TxViewChange(%p, fUpdate=%d)\n",
197 static BOOL WINAPI ITextHostImpl_TxCreateCaret(ITextHost *iface,
199 INT xWidth, INT yHeight)
201 ITextHostTestImpl *This = impl_from_ITextHost(iface);
202 TRACECALL("Call to TxCreateCaret(%p, nbmp=%p, xWidth=%d, yHeight=%d)\n",
203 This, hbmp, xWidth, yHeight);
207 static BOOL WINAPI ITextHostImpl_TxShowCaret(ITextHost *iface, BOOL fShow)
209 ITextHostTestImpl *This = impl_from_ITextHost(iface);
210 TRACECALL("Call to TxShowCaret(%p, fShow=%d)\n",
215 static BOOL WINAPI ITextHostImpl_TxSetCaretPos(ITextHost *iface,
218 ITextHostTestImpl *This = impl_from_ITextHost(iface);
219 TRACECALL("Call to TxSetCaretPos(%p, x=%d, y=%d)\n", This, x, y);
223 static BOOL WINAPI ITextHostImpl_TxSetTimer(ITextHost *iface,
224 UINT idTimer, UINT uTimeout)
226 ITextHostTestImpl *This = impl_from_ITextHost(iface);
227 TRACECALL("Call to TxSetTimer(%p, idTimer=%u, uTimeout=%u)\n",
228 This, idTimer, uTimeout);
232 static void WINAPI ITextHostImpl_TxKillTimer(ITextHost *iface, UINT idTimer)
234 ITextHostTestImpl *This = impl_from_ITextHost(iface);
235 TRACECALL("Call to TxKillTimer(%p, idTimer=%u)\n", This, idTimer);
238 static void WINAPI ITextHostImpl_TxScrollWindowEx(ITextHost *iface,
246 ITextHostTestImpl *This = impl_from_ITextHost(iface);
247 TRACECALL("Call to TxScrollWindowEx(%p, %d, %d, %p, %p, %p, %p, %d)\n",
248 This, dx, dy, lprcScroll, lprcClip, hRgnUpdate, lprcUpdate, fuScroll);
251 static void WINAPI ITextHostImpl_TxSetCapture(ITextHost *iface, BOOL fCapture)
253 ITextHostTestImpl *This = impl_from_ITextHost(iface);
254 TRACECALL("Call to TxSetCapture(%p, fCapture=%d)\n", This, fCapture);
257 static void WINAPI ITextHostImpl_TxSetFocus(ITextHost *iface)
259 ITextHostTestImpl *This = impl_from_ITextHost(iface);
260 TRACECALL("Call to TxSetFocus(%p)\n", This);
263 static void WINAPI ITextHostImpl_TxSetCursor(ITextHost *iface,
267 ITextHostTestImpl *This = impl_from_ITextHost(iface);
268 TRACECALL("Call to TxSetCursor(%p, hcur=%p, fText=%d)\n",
272 static BOOL WINAPI ITextHostImpl_TxScreenToClient(ITextHost *iface,
275 ITextHostTestImpl *This = impl_from_ITextHost(iface);
276 TRACECALL("Call to TxScreenToClient(%p, lppt=%p)\n", This, lppt);
280 static BOOL WINAPI ITextHostImpl_TxClientToScreen(ITextHost *iface,
283 ITextHostTestImpl *This = impl_from_ITextHost(iface);
284 TRACECALL("Call to TxClientToScreen(%p, lppt=%p)\n", This, lppt);
288 static HRESULT WINAPI ITextHostImpl_TxActivate(ITextHost *iface,
291 ITextHostTestImpl *This = impl_from_ITextHost(iface);
292 TRACECALL("Call to TxActivate(%p, plOldState=%p)\n", This, plOldState);
296 static HRESULT WINAPI ITextHostImpl_TxDeactivate(ITextHost *iface,
299 ITextHostTestImpl *This = impl_from_ITextHost(iface);
300 TRACECALL("Call to TxDeactivate(%p, lNewState=%d)\n", This, lNewState);
304 static HRESULT WINAPI ITextHostImpl_TxGetClientRect(ITextHost *iface,
307 ITextHostTestImpl *This = impl_from_ITextHost(iface);
308 TRACECALL("Call to TxGetClientRect(%p, prc=%p)\n", This, prc);
312 static HRESULT WINAPI ITextHostImpl_TxGetViewInset(ITextHost *iface,
315 ITextHostTestImpl *This = impl_from_ITextHost(iface);
316 TRACECALL("Call to TxGetViewInset(%p, prc=%p)\n", This, prc);
320 static HRESULT WINAPI ITextHostImpl_TxGetCharFormat(ITextHost *iface,
321 const CHARFORMATW **ppCF)
323 ITextHostTestImpl *This = impl_from_ITextHost(iface);
324 TRACECALL("Call to TxGetCharFormat(%p, ppCF=%p)\n", This, ppCF);
328 static HRESULT WINAPI ITextHostImpl_TxGetParaFormat(ITextHost *iface,
329 const PARAFORMAT **ppPF)
331 ITextHostTestImpl *This = impl_from_ITextHost(iface);
332 TRACECALL("Call to TxGetParaFormat(%p, ppPF=%p)\n", This, ppPF);
336 static COLORREF WINAPI ITextHostImpl_TxGetSysColor(ITextHost *iface,
339 ITextHostTestImpl *This = impl_from_ITextHost(iface);
340 TRACECALL("Call to TxGetSysColor(%p, nIndex=%d)\n", This, nIndex);
344 static HRESULT WINAPI ITextHostImpl_TxGetBackStyle(ITextHost *iface,
345 TXTBACKSTYLE *pStyle)
347 ITextHostTestImpl *This = impl_from_ITextHost(iface);
348 TRACECALL("Call to TxGetBackStyle(%p, pStyle=%p)\n", This, pStyle);
352 static HRESULT WINAPI ITextHostImpl_TxGetMaxLength(ITextHost *iface,
355 ITextHostTestImpl *This = impl_from_ITextHost(iface);
356 TRACECALL("Call to TxGetMaxLength(%p, pLength=%p)\n", This, pLength);
360 static HRESULT WINAPI ITextHostImpl_TxGetScrollBars(ITextHost *iface,
363 ITextHostTestImpl *This = impl_from_ITextHost(iface);
364 TRACECALL("Call to TxGetScrollBars(%p, pdwScrollBar=%p)\n",
369 static HRESULT WINAPI ITextHostImpl_TxGetPasswordChar(ITextHost *iface,
372 ITextHostTestImpl *This = impl_from_ITextHost(iface);
373 TRACECALL("Call to TxGetPasswordChar(%p, pch=%p)\n", This, pch);
377 static HRESULT WINAPI ITextHostImpl_TxGetAcceleratorPos(ITextHost *iface,
380 ITextHostTestImpl *This = impl_from_ITextHost(iface);
381 TRACECALL("Call to TxGetAcceleratorPos(%p, pch=%p)\n", This, pch);
385 static HRESULT WINAPI ITextHostImpl_TxGetExtent(ITextHost *iface,
388 ITextHostTestImpl *This = impl_from_ITextHost(iface);
389 TRACECALL("Call to TxGetExtent(%p, lpExtent=%p)\n", This, lpExtent);
393 static HRESULT WINAPI ITextHostImpl_OnTxCharFormatChange(ITextHost *iface,
394 const CHARFORMATW *pcf)
396 ITextHostTestImpl *This = impl_from_ITextHost(iface);
397 TRACECALL("Call to OnTxCharFormatChange(%p, pcf=%p)\n", This, pcf);
401 static HRESULT WINAPI ITextHostImpl_OnTxParaFormatChange(ITextHost *iface,
402 const PARAFORMAT *ppf)
404 ITextHostTestImpl *This = impl_from_ITextHost(iface);
405 TRACECALL("Call to OnTxParaFormatChange(%p, ppf=%p)\n", This, ppf);
409 /* This must return S_OK for the native ITextServices object to
411 static HRESULT WINAPI ITextHostImpl_TxGetPropertyBits(ITextHost *iface,
415 ITextHostTestImpl *This = impl_from_ITextHost(iface);
416 TRACECALL("Call to TxGetPropertyBits(%p, dwMask=0x%08x, pdwBits=%p)\n",
417 This, dwMask, pdwBits);
422 static HRESULT WINAPI ITextHostImpl_TxNotify(ITextHost *iface, DWORD iNotify,
425 ITextHostTestImpl *This = impl_from_ITextHost(iface);
426 TRACECALL("Call to TxNotify(%p, iNotify=%d, pv=%p)\n", This, iNotify, pv);
430 static HIMC WINAPI ITextHostImpl_TxImmGetContext(ITextHost *iface)
432 ITextHostTestImpl *This = impl_from_ITextHost(iface);
433 TRACECALL("Call to TxImmGetContext(%p)\n", This);
437 static void WINAPI ITextHostImpl_TxImmReleaseContext(ITextHost *iface, HIMC himc)
439 ITextHostTestImpl *This = impl_from_ITextHost(iface);
440 TRACECALL("Call to TxImmReleaseContext(%p, himc=%p)\n", This, himc);
443 /* This function must set the variable pointed to by *lSelBarWidth.
444 Otherwise an uninitalized value will be used to calculate
445 positions and sizes even if E_NOTIMPL is returned. */
446 static HRESULT WINAPI ITextHostImpl_TxGetSelectionBarWidth(ITextHost *iface,
449 ITextHostTestImpl *This = impl_from_ITextHost(iface);
450 TRACECALL("Call to TxGetSelectionBarWidth(%p, lSelBarWidth=%p)\n",
456 static ITextHostVtbl itextHostVtbl = {
457 ITextHostImpl_QueryInterface,
458 ITextHostImpl_AddRef,
459 ITextHostImpl_Release,
460 ITextHostImpl_TxGetDC,
461 ITextHostImpl_TxReleaseDC,
462 ITextHostImpl_TxShowScrollBar,
463 ITextHostImpl_TxEnableScrollBar,
464 ITextHostImpl_TxSetScrollRange,
465 ITextHostImpl_TxSetScrollPos,
466 ITextHostImpl_TxInvalidateRect,
467 ITextHostImpl_TxViewChange,
468 ITextHostImpl_TxCreateCaret,
469 ITextHostImpl_TxShowCaret,
470 ITextHostImpl_TxSetCaretPos,
471 ITextHostImpl_TxSetTimer,
472 ITextHostImpl_TxKillTimer,
473 ITextHostImpl_TxScrollWindowEx,
474 ITextHostImpl_TxSetCapture,
475 ITextHostImpl_TxSetFocus,
476 ITextHostImpl_TxSetCursor,
477 ITextHostImpl_TxScreenToClient,
478 ITextHostImpl_TxClientToScreen,
479 ITextHostImpl_TxActivate,
480 ITextHostImpl_TxDeactivate,
481 ITextHostImpl_TxGetClientRect,
482 ITextHostImpl_TxGetViewInset,
483 ITextHostImpl_TxGetCharFormat,
484 ITextHostImpl_TxGetParaFormat,
485 ITextHostImpl_TxGetSysColor,
486 ITextHostImpl_TxGetBackStyle,
487 ITextHostImpl_TxGetMaxLength,
488 ITextHostImpl_TxGetScrollBars,
489 ITextHostImpl_TxGetPasswordChar,
490 ITextHostImpl_TxGetAcceleratorPos,
491 ITextHostImpl_TxGetExtent,
492 ITextHostImpl_OnTxCharFormatChange,
493 ITextHostImpl_OnTxParaFormatChange,
494 ITextHostImpl_TxGetPropertyBits,
495 ITextHostImpl_TxNotify,
496 ITextHostImpl_TxImmGetContext,
497 ITextHostImpl_TxImmReleaseContext,
498 ITextHostImpl_TxGetSelectionBarWidth
501 static ITextServices *txtserv = NULL;
502 static ITextHostTestImpl *dummyTextHost;
503 static void *wrapperCodeMem = NULL;
505 #include "pshpack1.h"
507 /* Code structure for x86 byte code */
510 BYTE pop_eax; /* popl %eax */
511 BYTE push_ecx; /* pushl %ecx */
512 BYTE push_eax; /* pushl %eax */
513 BYTE jmp_func; /* jmp $func */
515 } THISCALL_TO_STDCALL_THUNK;
519 BYTE pop_eax; /* popl %eax */
520 BYTE pop_ecx; /* popl %ecx */
521 BYTE push_eax; /* pushl %eax */
522 BYTE mov_vtable_eax[2]; /* movl (%ecx), %eax */
523 BYTE jmp_eax[2]; /* jmp *$vtablefunc_offset(%eax) */
524 int vtablefunc_offset;
525 } STDCALL_TO_THISCALL_THUNK;
529 static void setup_thiscall_wrappers(void)
534 THISCALL_TO_STDCALL_THUNK *thunk;
535 STDCALL_TO_THISCALL_THUNK *thunk2;
537 wrapperCodeMem = VirtualAlloc(NULL,
538 (sizeof(ITextHostVtbl)/sizeof(void*) - 3)
539 * sizeof(THISCALL_TO_STDCALL_THUNK)
540 +(sizeof(ITextServicesVtbl)/sizeof(void*) - 3)
541 * sizeof(STDCALL_TO_THISCALL_THUNK),
542 MEM_COMMIT, PAGE_EXECUTE_READWRITE);
543 thunk = wrapperCodeMem;
545 /* Wrap all ITextHostImpl methods with code to perform a thiscall to
546 * stdcall conversion. The thiscall calling convention places the This
547 * pointer in ecx on the x86 platform, and the stdcall calling convention
548 * pushes the This pointer on the stack as the first argument.
550 * The byte code does the conversion then jumps to the real function.
552 * Each wrapper needs to be modified so that the function to jump to is
553 * modified in the byte code. */
555 /* Skip QueryInterface, AddRef, and Release native actually
556 * defined them with the stdcall calling convention. */
557 pVtable = (void**)&itextHostVtbl + 3;
558 pVtableEnd = (void**)(&itextHostVtbl + 1);
559 while (pVtable != pVtableEnd) {
560 /* write byte code to executable memory */
561 thunk->pop_eax = 0x58; /* popl %eax */
562 thunk->push_ecx = 0x51; /* pushl %ecx */
563 thunk->push_eax = 0x50; /* pushl %eax */
564 thunk->jmp_func = 0xe9; /* jmp $func */
565 /* The address needs to be relative to the end of the jump instructions. */
566 thunk->func = (char*)*pVtable - (char*)(&thunk->func + 1);
572 /* Setup an ITextServices standard call vtable that will call the
573 * native thiscall vtable when the methods are called. */
575 /* QueryInterface, AddRef, and Release should be called directly on the
576 * real vtable since they use the stdcall calling convention. */
577 thunk2 = (STDCALL_TO_THISCALL_THUNK *)thunk;
578 pVtable = (void**)&itextServicesStdcallVtbl + 3;
579 pVtableEnd = (void**)(&itextServicesStdcallVtbl + 1);
580 while (pVtable != pVtableEnd) {
581 /* write byte code to executable memory */
582 thunk2->pop_eax = 0x58; /* popl %eax */
583 thunk2->pop_ecx = 0x59; /* popl %ecx */
584 thunk2->push_eax = 0x50; /* pushl %eax */
585 thunk2->mov_vtable_eax[0] = 0x8b; /* movl (%ecx), %eax */
586 thunk2->mov_vtable_eax[1] = 0x01;
587 thunk2->jmp_eax[0] = 0xff; /* jmp *$vtablefunc_offset(%eax) */
588 thunk2->jmp_eax[1] = 0xa0;
589 thunk2->vtablefunc_offset = (char*)pVtable - (char*)&itextServicesStdcallVtbl;
594 #endif /* __i386__ */
597 /*************************************************************************/
598 /* Conformance test functions. */
600 /* Initialize the test texthost structure */
601 static BOOL init_texthost(void)
605 PCreateTextServices pCreateTextServices;
607 dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
608 if (dummyTextHost == NULL) {
609 skip("Insufficient memory to create ITextHost interface\n");
612 dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl;
613 dummyTextHost->refCount = 1;
615 /* MSDN states that an IUnknown object is returned by
616 CreateTextServices which is then queried to obtain a
617 ITextServices object. */
618 pCreateTextServices = (void*)GetProcAddress(hmoduleRichEdit, "CreateTextServices");
619 result = (*pCreateTextServices)(NULL, &dummyTextHost->ITextHost_iface, &init);
620 ok(result == S_OK, "Did not return S_OK when created (result = %x)\n", result);
621 if (result != S_OK) {
622 CoTaskMemFree(dummyTextHost);
623 skip("CreateTextServices failed.\n");
627 result = IUnknown_QueryInterface(init, &IID_ITextServices,
629 ok((result == S_OK) && (txtserv != NULL), "Querying interface failed (result = %x, txtserv = %p)\n", result, txtserv);
630 IUnknown_Release(init);
631 if (!((result == S_OK) && (txtserv != NULL))) {
632 CoTaskMemFree(dummyTextHost);
633 skip("Could not retrieve ITextServices interface\n");
640 static void free_texthost(void)
642 IUnknown_Release(txtserv);
643 CoTaskMemFree(dummyTextHost);
646 static void test_TxGetText(void)
651 if (!init_texthost())
654 hres = ITextServices_TxGetText(txtserv, &rettext);
655 ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres);
660 static void test_TxSetText(void)
664 WCHAR settext[] = {'T','e','s','t',0};
666 if (!init_texthost())
669 hres = ITextServices_TxSetText(txtserv, settext);
670 ok(hres == S_OK, "ITextServices_TxSetText failed (result = %x)\n", hres);
672 hres = ITextServices_TxGetText(txtserv, &rettext);
673 ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres);
675 ok(SysStringLen(rettext) == 4,
676 "String returned of wrong length (expected 4, got %d)\n", SysStringLen(rettext));
677 ok(memcmp(rettext,settext,SysStringByteLen(rettext)) == 0,
678 "String returned differs\n");
680 SysFreeString(rettext);
684 static void test_TxGetNaturalSize(void) {
688 /* This value is used when calling TxGetNaturalSize. MSDN says
689 that this is not supported however a null pointer cannot be
690 used as it will cause a segmentation violation. The values in
691 the structure being pointed to are required to be INT_MAX
692 otherwise calculations can give wrong values. */
693 const SIZEL psizelExtent = {INT_MAX,INT_MAX};
695 static const WCHAR oneA[] = {'A',0};
697 /* Results of measurements */
700 /* The device context to do the tests in */
703 /* Variables with the text metric information */
704 INT charwidth_caps_text[26];
705 TEXTMETRIC tmInfo_text;
707 if (!init_texthost())
710 hdcDraw = GetDC(NULL);
713 /* Populate the metric strucs */
714 SetMapMode(hdcDraw,MM_TEXT);
715 GetTextMetrics(hdcDraw, &tmInfo_text);
716 SetLastError(0xdeadbeef);
717 ret = GetCharWidth32(hdcDraw,'A','Z',charwidth_caps_text);
718 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
719 win_skip("GetCharWidth32 is not available\n");
723 /* Make measurements in MM_TEXT */
724 SetMapMode(hdcDraw,MM_TEXT);
727 result = ITextServices_TxSetText(txtserv, oneA);
728 ok(result == S_OK, "ITextServices_TxSetText failed (result = %x)\n", result);
729 if (result != S_OK) {
730 skip("Could not set text\n");
734 SetLastError(0xdeadbeef);
735 result = ITextServices_TxGetNaturalSize(txtserv, DVASPECT_CONTENT,
737 TXTNS_FITTOCONTENT, &psizelExtent,
739 todo_wine ok(result == S_OK || broken(result == E_FAIL), /* WINXP Arabic Language */
740 "TxGetNaturalSize gave unexpected return value (result = %x)\n", result);
741 if (result == S_OK) {
742 todo_wine ok(ydim == tmInfo_text.tmHeight,
743 "Height calculated incorrectly (expected %d, got %d)\n",
744 tmInfo_text.tmHeight, ydim);
745 /* The native DLL adds one pixel extra when calculating widths. */
746 todo_wine ok(xdim >= charwidth_caps_text[0] && xdim <= charwidth_caps_text[0] + 1,
747 "Width calculated incorrectly (expected %d {+1}, got %d)\n",
748 charwidth_caps_text[0], xdim);
750 skip("TxGetNaturalSize measurements not performed (xdim = %d, ydim = %d, result = %x, error = %x)\n",
751 xdim, ydim, result, GetLastError());
754 RestoreDC(hdcDraw,1);
755 ReleaseDC(NULL,hdcDraw);
759 static void test_TxDraw(void)
761 HDC tmphdc = GetDC(NULL);
762 DWORD dwAspect = DVASPECT_CONTENT;
763 HDC hicTargetDev = NULL; /* Means "default" device */
764 DVTARGETDEVICE *ptd = NULL;
765 void *pvAspect = NULL;
767 RECTL client = {0,0,100,100};
769 if (!init_texthost())
773 result = ITextServices_TxDraw(txtserv, dwAspect, 0, pvAspect, ptd,
774 tmphdc, hicTargetDev, &client, NULL,
776 ok(result == S_OK, "TxDraw failed (result = %x)\n", result);
785 setup_thiscall_wrappers();
787 /* Must explicitly LoadLibrary(). The test has no references to functions in
788 * RICHED20.DLL, so the linker doesn't actually link to it. */
789 hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
790 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
798 test_TxGetNaturalSize();
801 if (wrapperCodeMem) VirtualFree(wrapperCodeMem, 0, MEM_RELEASE);