ReactOS 0.4.16-dev-1948-gd260c1d
richole.c
Go to the documentation of this file.
1/*
2 * Tests for IRichEditOle and friends.
3 *
4 * Copyright 2008 Google (Dan Hipschman)
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define COBJMACROS
22
23#include <stdarg.h>
24
25#include <windef.h>
26#include <winbase.h>
27#include <wingdi.h>
28#include <winuser.h>
29#include <initguid.h>
30#include <ole2.h>
31#include <richedit.h>
32#include <richole.h>
33#include <tom.h>
34#include <imm.h>
35#include <textserv.h>
36#include <wine/test.h>
37
38#define EXPECT_TODO_WINE 0x80000000UL
39
41{
44 int line;
45
47
48 const CLSID *clsid;
52};
53
55{
57}
58
60{
61 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IRichEditOleCallback)) {
62 IRichEditOleCallback_AddRef(iface);
63 *obj = iface;
64 return S_OK;
65 }
66 *obj = NULL;
67 return E_NOINTERFACE;
68}
69
71{
74 return ref;
75}
76
78{
81 if (!ref) free(This);
82 return ref;
83}
84
86{
87 return E_NOTIMPL;
88}
89
91 IOleInPlaceFrame **frame,
93 OLEINPLACEFRAMEINFO *frame_info)
94{
95 return E_INVALIDARG;
96}
97
99{
100 return S_OK;
101}
102
105{
107 ULONG expect = This->expect_queryinsertobject;
108
110 ok_(__FILE__,This->line)( expect & ~EXPECT_TODO_WINE,
111 "unexpected call to IRichEditOleCallback_QueryInsertObject\n");
112 if (!(expect & ~EXPECT_TODO_WINE)) return S_OK;
113 This->expect_queryinsertobject--;
114
115 if (This->clsid && clsid)
116 ok_(__FILE__,This->line)( IsEqualGUID(This->clsid, clsid),
117 "QueryInsertObject clsid expected %s, got %s\n",
119 else
120 ok_(__FILE__,This->line)( This->clsid == clsid,
121 "QueryInsertObject clsid expected %p, got %p\n", This->clsid, clsid );
122 ok_(__FILE__,This->line)( This->stg == stg, "QueryInsertObject stg expected %p, got %p\n", This->stg, stg );
123 ok_(__FILE__,This->line)( This->cp == cp, "QueryInsertObject cp expected %ld, got %ld\n", This->cp, cp );
124 return This->queryinsertobject_result;
125}
126
128{
129 return S_OK;
130}
131
133 CLIPFORMAT *cf_format, DWORD reco, BOOL really,
134 HGLOBAL metapict)
135{
136 return S_OK;
137}
138
140{
141 return S_OK;
142}
143
145 DWORD reco, IDataObject **dataobj)
146{
147 return E_NOTIMPL;
148}
149
151 DWORD key_state, DWORD *effect)
152{
153 if (effect) *effect = DROPEFFECT_COPY;
154 return S_OK;
155}
156
158 IOleObject *oleobj, CHARRANGE *chrg, HMENU *hmenu)
159{
160 return E_NOTIMPL;
161}
162
163static const struct IRichEditOleCallbackVtbl reolecb_obj_Vtbl = {
177};
178
180{
181 struct reolecb_obj *obj;
182
183 obj = calloc(sizeof(struct reolecb_obj), 1);
184 if (!obj) return E_OUTOFMEMORY;
185
186#ifdef __REACTOS__
187 obj->IRichEditOleCallback_iface.lpVtbl = (IRichEditOleCallbackVtbl*)&reolecb_obj_Vtbl;
188#else
189 obj->IRichEditOleCallback_iface.lpVtbl = &reolecb_obj_Vtbl;
190#endif
191 obj->ref = 1;
192
193 *objptr = obj;
194 return S_OK;
195}
196
199{
200 if (!This) return;
201
202 This->line = line;
203 This->expect_queryinsertobject = expect;
204 This->clsid = clsid;
205 This->stg = stg;
206 This->cp = cp;
207 This->queryinsertobject_result = result;
208}
209
211{
212 if (!This) return;
213
214 todo_wine_if(This->expect_queryinsertobject & EXPECT_TODO_WINE)
215 ok( !(This->expect_queryinsertobject & ~EXPECT_TODO_WINE),
216 "expected IRichEditOleCallback_QueryInsertObject to be called\n" );
217
219}
220
221DEFINE_GUID(CLSID_testoleobj, 0x4484082e, 0x6d18, 0x4932, 0xa0, 0x86, 0x5b, 0x4d, 0xcf, 0x36, 0xb3, 0xde);
222
226 int line;
228
232
234};
235
237{
238 return CONTAINING_RECORD( iface, struct testoleobj, IOleObject_iface );
239}
240
242{
243 struct testoleobj *This = impl_from_IOleObject( iface );
244
246 {
247 *obj = iface;
248 }
249 else if (IsEqualGUID( riid, &IID_IViewObject ))
250 {
251 *obj = &This->IViewObject_iface;
252 }
253 else
254 {
255 if (!IsEqualGUID( riid, &IID_IOleLink ) &&
257 !IsEqualGUID( riid, &IID_IMarshal ))
258 {
259 trace( "Unsupported interface: %s\n", debugstr_guid( riid ));
260 }
261 *obj = NULL;
262 return E_NOINTERFACE;
263 }
264
265 IUnknown_AddRef( (IUnknown *)*obj );
266 return S_OK;
267}
268
270{
271 struct testoleobj *This = impl_from_IOleObject( iface );
273 return ref;
274}
275
277{
278 struct testoleobj *This = impl_from_IOleObject( iface );
280 if (!ref)
281 {
282 if (This->advise_holder)
283 {
284 IOleAdviseHolder_Release( This->advise_holder );
285 This->advise_holder = NULL;
286 }
287 if (This->clientsite)
288 {
289 IOleClientSite_Release( This->clientsite );
290 This->clientsite = NULL;
291 }
292 free( This );
293 }
294 return ref;
295}
296
298{
299 struct testoleobj *This = impl_from_IOleObject( iface );
300
301 if (This->clientsite != clientsite)
302 {
303 if (This->clientsite) IOleClientSite_Release( This->clientsite );
304 This->clientsite = clientsite;
305 if (This->clientsite) IOleClientSite_AddRef( This->clientsite );
306 }
307
308 return S_OK;
309}
310
312{
313 struct testoleobj *This = impl_from_IOleObject( iface );
314
315 if (This->clientsite) IOleClientSite_AddRef( This->clientsite );
316 *clientsite = This->clientsite;
317
318 return S_OK;
319}
320
322 LPCOLESTR container_app,
323 LPCOLESTR container_obj )
324{
325 return S_OK;
326}
327
329{
330 return S_OK;
331}
332
334 DWORD which_moniker, IMoniker *mk )
335{
336 return S_OK;
337}
338
340 DWORD which_moniker, IMoniker **mk )
341{
342 struct testoleobj *This = impl_from_IOleObject( iface );
343
344 *mk = NULL;
345
346 if (!This->clientsite) return E_UNEXPECTED;
347
348 return IOleClientSite_GetMoniker( This->clientsite, assign, which_moniker, mk );
349}
350
352 BOOL creation, DWORD reserved )
353{
354 return E_NOTIMPL;
355}
356
358 IDataObject **dataobj )
359{
360 *dataobj = NULL;
361 return E_NOTIMPL;
362}
363
365 IOleClientSite *activesite, LONG index,
366 HWND parentwnd, LPCRECT posrect )
367{
368 return E_NOTIMPL;
369}
370
372{
373 *enumoleverb = NULL;
374 return OLEOBJ_E_NOVERBS;
375}
376
378{
379 return S_OK;
380}
381
383{
384 return S_OK;
385}
386
388{
389 *clsid = CLSID_testoleobj;
390 return S_OK;
391}
392
394{
395 static const OLECHAR typename[] = L"richole testoleobj";
396
397 *user_type = CoTaskMemAlloc( sizeof(typename) );
398 if (!*user_type) return E_OUTOFMEMORY;
399
400 memcpy( *user_type, typename, sizeof(typename) );
401 return S_OK;
402}
403
405{
406 struct testoleobj *This = impl_from_IOleObject( iface );
407
408 if (draw_aspect != DVASPECT_CONTENT) return E_FAIL;
409
410 This->extent = *sizel;
411 return S_OK;
412}
413
415{
416 struct testoleobj *This = impl_from_IOleObject( iface );
417
418 if (draw_aspect != DVASPECT_CONTENT) return E_FAIL;
419
420 *sizel = This->extent;
421 return S_OK;
422}
423
425{
426 struct testoleobj *This = impl_from_IOleObject( iface );
427 HRESULT hr = S_OK;
428
429 if (!This->advise_holder) hr = CreateOleAdviseHolder( &This->advise_holder );
430 if (SUCCEEDED( hr )) hr = IOleAdviseHolder_Advise( This->advise_holder, adv_sink, connection );
431 return hr;
432}
433
435{
436 struct testoleobj *This = impl_from_IOleObject( iface );
437
438 if (!This->advise_holder) return OLE_E_NOCONNECTION;
439 return IOleAdviseHolder_Unadvise( This->advise_holder, connection );
440}
441
443{
444 struct testoleobj *This = impl_from_IOleObject( iface );
445
446 if (!This->advise_holder)
447 {
448 *enum_advise = NULL;
449 return S_OK;
450 }
451 return IOleAdviseHolder_EnumAdvise( This->advise_holder, enum_advise );
452}
453
455{
456 *status = 0;
457 return S_OK;
458}
459
461{
462 return E_NOTIMPL;
463}
464
465static const struct IOleObjectVtbl testoleobj_IOleObject_Vtbl = {
490};
491
493{
494 return CONTAINING_RECORD( iface, struct testoleobj, IViewObject_iface );
495}
496
498{
499 struct testoleobj *This = impl_from_IViewObject( iface );
500 return IOleObject_QueryInterface( &This->IOleObject_iface, riid, obj );
501}
502
504{
505 struct testoleobj *This = impl_from_IViewObject( iface );
506 return IOleObject_AddRef( &This->IOleObject_iface );
507}
508
510{
511 struct testoleobj *This = impl_from_IViewObject( iface );
512 return IOleObject_Release( &This->IOleObject_iface );
513}
514
516 LONG index, void *aspect, DVTARGETDEVICE *td,
517 HDC hdc_target_dev, HDC hdc_draw,
518 LPCRECTL bounds, LPCRECTL wbounds,
519 BOOL (CALLBACK *fn_continue)(ULONG_PTR),
520 ULONG_PTR arg_continue )
521{
522 struct testoleobj *This = impl_from_IViewObject( iface );
523 SIZEL dpi;
524
525 if (draw_aspect != DVASPECT_CONTENT || index != -1) return E_NOTIMPL;
526
527 ok_(__FILE__,This->line)( td == NULL, "expected td to be NULL, got %p\n", td );
528 ok_(__FILE__,This->line)( hdc_target_dev == NULL, "expected hdc_target_dev to be NULL, got %p\n", hdc_target_dev );
529 ok_(__FILE__,This->line)( wbounds == NULL, "expected wbounds to be NULL, got %p\n", wbounds );
530
531 dpi.cx = GetDeviceCaps(hdc_draw, LOGPIXELSX);
532 dpi.cy = GetDeviceCaps(hdc_draw, LOGPIXELSY);
533
534 ok_(__FILE__,This->line)( bounds->right - bounds->left == MulDiv( This->extent.cx, dpi.cx, 2540 ),
535 "bounds->right (= %ld) - bounds->left (= %ld) != "
536 "MulDiv( This->extent.cx (= %ld), dpi.cx (= %ld), 2540 )\n",
537 bounds->right, bounds->left, This->extent.cx, dpi.cx );
538 ok_(__FILE__,This->line)( bounds->bottom - bounds->top == MulDiv( This->extent.cy, dpi.cy, 2540 ),
539 "bounds->bottom (= %ld) - bounds->top (= %ld) != "
540 "MulDiv( This->extent.cy (= %ld), dpi.cy (= %ld), 2540 )\n",
541 bounds->bottom, bounds->top, This->extent.cy, dpi.cy );
542
543 FillRect( hdc_draw, (const RECT *)bounds, GetStockObject( DKGRAY_BRUSH ));
544 This->draw_count++;
545
546 return S_OK;
547}
548
550 LONG index, void *aspect, DVTARGETDEVICE *td,
551 HDC hdc_target_dev, LOGPALETTE **color_set )
552{
553 *color_set = NULL;
554 return E_NOTIMPL;
555}
556
558 LONG index, void *aspect, DWORD *freeze )
559{
560 *freeze = 0;
561 return E_NOTIMPL;
562}
563
565{
566 return E_NOTIMPL;
567}
568
570 DWORD advf, IAdviseSink *adv_sink )
571{
572 return E_NOTIMPL;
573}
574
576 DWORD *advf, IAdviseSink **adv_sink )
577{
578 *aspects = 0;
579 *advf = 0;
580 *adv_sink = NULL;
581 return E_NOTIMPL;
582}
583
584static const struct IViewObjectVtbl testoleobj_IViewObject_Vtbl = {
594};
595
596static HRESULT testoleobj_Create( struct testoleobj **objptr )
597{
598 struct testoleobj *obj;
599
600 obj = calloc( sizeof(struct testoleobj), 1 );
601 *objptr = obj;
602 if (!obj) return E_OUTOFMEMORY;
603
604
605#ifdef __REACTOS__
606 obj->IOleObject_iface.lpVtbl = (IOleObjectVtbl*)&testoleobj_IOleObject_Vtbl;
607#else
608 obj->IOleObject_iface.lpVtbl = &testoleobj_IOleObject_Vtbl;
609#endif
610 obj->ref = 1;
611#ifdef __REACTOS__
612 obj->IViewObject_iface.lpVtbl = (IViewObjectVtbl*)&testoleobj_IViewObject_Vtbl;
613#else
614 obj->IViewObject_iface.lpVtbl = &testoleobj_IViewObject_Vtbl;
615#endif
616
617 return S_OK;
618}
619
621
622DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
623DEFINE_GUID(IID_ITextServices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
624
625static const WCHAR sysW[] = {'S','y','s','t','e','m',0};
626
627#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
629{
630 ULONG rc;
631 IUnknown_AddRef(obj);
632 rc = IUnknown_Release(obj);
633 ok_(__FILE__,line)(rc == ref, "expected refcount %ld, got %ld\n", ref, rc);
634}
635
636static HWND new_window(LPCSTR lpClassName, DWORD dwStyle, HWND parent)
637{
638 HWND hwnd = CreateWindowA(lpClassName, NULL,
640 0, 0, 200, 60, parent, NULL, hmoduleRichEdit, NULL);
641 ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
642 return hwnd;
643}
644
646{
648}
649
651{
652 HANDLE file;
653
656
658 return FALSE;
660 return TRUE;
661}
662
664{
665 HANDLE file;
666
668 OPEN_EXISTING, 0, NULL);
670 return FALSE;
672 return TRUE;
673}
674
675static void create_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc,
676 ITextSelection **txtSel)
677{
678 *w = new_richedit(NULL);
680 IRichEditOle_QueryInterface(*reOle, &IID_ITextDocument,
681 (void **) txtDoc);
682 ITextDocument_GetSelection(*txtDoc, txtSel);
683}
684
685static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc,
686 ITextSelection **txtSel)
687{
688 if(txtSel)
689 ITextSelection_Release(*txtSel);
690 ITextDocument_Release(*txtDoc);
691 IRichEditOle_Release(*reOle);
693}
694
696{
697 IUnknown_AddRef(iface);
698 return IUnknown_Release(iface);
699}
700
701#define CHECK_TYPEINFO(disp,expected_riid) _check_typeinfo((IDispatch *)disp, expected_riid, __LINE__)
702static void _check_typeinfo(IDispatch* disp, REFIID expected_riid, int line)
703{
705 TYPEATTR *typeattr;
706 UINT count;
707 HRESULT hr;
708
709 count = 10;
710 hr = IDispatch_GetTypeInfoCount(disp, &count);
711 ok_(__FILE__,line)(hr == S_OK, "IDispatch_GetTypeInfoCount failed: 0x%08lx.\n", hr);
712 ok_(__FILE__,line)(count == 1, "got wrong count: %u.\n", count);
713
714 hr = IDispatch_GetTypeInfo(disp, 0, LOCALE_SYSTEM_DEFAULT, &typeinfo);
715 ok_(__FILE__,line)(hr == S_OK, "IDispatch_GetTypeInfo failed: 0x%08lx.\n", hr);
716
717 hr = ITypeInfo_GetTypeAttr(typeinfo, &typeattr);
718 ok_(__FILE__,line)(hr == S_OK, "ITypeInfo_GetTypeAttr failed: 0x%08lx.\n", hr);
719 ok_(__FILE__,line)(IsEqualGUID(&typeattr->guid, expected_riid),
720 "Unexpected type guid: %s.\n", wine_dbgstr_guid(&typeattr->guid));
721
722 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
723 ITypeInfo_Release(typeinfo);
724}
725
726static void test_Interfaces(void)
727{
728 IRichEditOle *reOle = NULL, *reOle1 = NULL;
729 ITextDocument *txtDoc = NULL;
730 ITextDocument2Old *txtDoc2Old = NULL;
731 ITextSelection *txtSel = NULL, *txtSel2;
732 IUnknown *punk;
734 LRESULT res;
735 HWND w;
736 ULONG refcount;
737 IUnknown *unk, *unk2;
738
740 if (!w) {
741 skip("Couldn't create window\n");
742 return;
743 }
744
746 ok(res, "SendMessage\n");
747 ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
748 EXPECT_REF(reOle, 2);
749
750 res = SendMessageA(w, EM_GETOLEINTERFACE, 0, (LPARAM)&reOle1);
751 ok(res == 1, "SendMessage\n");
752 ok(reOle1 == reOle, "Should not return a new IRichEditOle interface\n");
753 EXPECT_REF(reOle, 3);
754
755 hres = IRichEditOle_QueryInterface(reOle, &IID_ITextDocument,
756 (void **) &txtDoc);
757 ok(hres == S_OK, "IRichEditOle_QueryInterface\n");
758 ok(txtDoc != NULL, "IRichEditOle_QueryInterface\n");
759 CHECK_TYPEINFO(txtDoc, &IID_ITextDocument);
760
761 hres = ITextDocument_GetSelection(txtDoc, NULL);
762 ok(hres == E_INVALIDARG, "ITextDocument_GetSelection: 0x%lx\n", hres);
763
764 EXPECT_REF(txtDoc, 4);
765
766 hres = ITextDocument_GetSelection(txtDoc, &txtSel);
767 ok(hres == S_OK, "got 0x%08lx\n", hres);
768
769 hres = ITextDocument_QueryInterface(txtDoc, &IID_IUnknown, (void **)&unk);
770 ok(hres == S_OK, "got 0x%08lx\n", hres);
771 hres = ITextSelection_QueryInterface(txtSel, &IID_IUnknown, (void **)&unk2);
772 ok(hres == S_OK, "got 0x%08lx\n", hres);
773 ok(unk != unk2, "unknowns are the same\n");
774 IUnknown_Release(unk2);
775 IUnknown_Release(unk);
776
777 EXPECT_REF(txtDoc, 4);
778 EXPECT_REF(txtSel, 2);
779
780 hres = ITextDocument_GetSelection(txtDoc, &txtSel2);
781 ok(hres == S_OK, "got 0x%08lx\n", hres);
782 ok(txtSel2 == txtSel, "got %p, %p\n", txtSel, txtSel2);
783
784 EXPECT_REF(txtDoc, 4);
785 EXPECT_REF(txtSel, 3);
786
787 ITextSelection_Release(txtSel2);
788
789 punk = NULL;
790 hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk);
791 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
792 ok(punk != NULL, "ITextSelection_QueryInterface\n");
793 IUnknown_Release(punk);
794
795 punk = NULL;
796 hres = ITextSelection_QueryInterface(txtSel, &IID_ITextRange, (void **) &punk);
797 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
798 ok(punk != NULL, "ITextSelection_QueryInterface\n");
799 IUnknown_Release(punk);
800
801 punk = NULL;
802 hres = ITextSelection_QueryInterface(txtSel, &IID_IDispatch, (void **) &punk);
803 ok(hres == S_OK, "ITextSelection_QueryInterface\n");
804 ok(punk != NULL, "ITextSelection_QueryInterface\n");
805 IUnknown_Release(punk);
806
807 punk = NULL;
808 hres = IRichEditOle_QueryInterface(reOle, &IID_IOleClientSite, (void **) &punk);
809 ok(hres == E_NOINTERFACE, "IRichEditOle_QueryInterface\n");
810
811 punk = NULL;
812 hres = IRichEditOle_QueryInterface(reOle, &IID_IOleWindow, (void **) &punk);
813 ok(hres == E_NOINTERFACE, "IRichEditOle_QueryInterface\n");
814
815 punk = NULL;
816 hres = IRichEditOle_QueryInterface(reOle, &IID_IOleInPlaceSite, (void **) &punk);
817 ok(hres == E_NOINTERFACE, "IRichEditOle_QueryInterface\n");
818
819 hres = IRichEditOle_QueryInterface(reOle, &IID_ITextDocument2Old, (void **)&txtDoc2Old);
820 ok(hres == S_OK, "IRichEditOle_QueryInterface\n");
821 ok(txtDoc2Old != NULL, "IRichEditOle_QueryInterface\n");
822 ok((ITextDocument *)txtDoc2Old == txtDoc, "interface pointer isn't equal.\n");
823 EXPECT_REF(txtDoc2Old, 5);
824 EXPECT_REF(reOle, 5);
825 CHECK_TYPEINFO(txtDoc2Old, &IID_ITextDocument);
826
827 ITextDocument2Old_Release(txtDoc2Old);
828
829 ITextDocument_Release(txtDoc);
830 IRichEditOle_Release(reOle);
831 refcount = IRichEditOle_Release(reOle);
832 ok(refcount == 1, "got wrong ref count: %ld\n", refcount);
834
835 /* Methods should return CO_E_RELEASED if the backing document has
836 been released. One test should suffice. */
837 hres = ITextSelection_CanEdit(txtSel, NULL);
838 ok(hres == CO_E_RELEASED, "ITextSelection after ITextDocument destroyed\n");
839
840 ITextSelection_Release(txtSel);
841
844 ok(res, "SendMessage\n");
845 ok(reOle != NULL, "EM_GETOLEINTERFACE\n");
846
847 hres = IRichEditOle_QueryInterface(reOle, &IID_ITextDocument2Old, (void **)&txtDoc2Old);
848 ok(hres == S_OK, "IRichEditOle_QueryInterface failed: 0x%08lx.\n", hres);
849 ok(txtDoc2Old != NULL, "IRichEditOle_QueryInterface\n");
850 CHECK_TYPEINFO(txtDoc2Old, &IID_ITextDocument);
851 ITextDocument2Old_Release(txtDoc2Old);
852 IRichEditOle_Release(reOle);
854}
855
856static void test_ITextDocument_Open(void)
857{
858 IRichEditOle *reOle = NULL;
859 ITextDocument *txtDoc = NULL;
860 ITextSelection *txtSel = NULL;
862 HWND w;
864 VARIANT testfile;
865 WCHAR filename[] = {'t', 'e', 's', 't','.','t','x','t', 0};
866 int result;
867 DWORD dw;
868 static const CHAR chACP[] = "TestSomeText";
869 static const CHAR chUTF8[] = "\xef\xbb\xbfTextWithUTF8BOM";
870 static const WCHAR chUTF16[] = {0xfeff, 'T', 'e', 's', 't', 'S', 'o', 'm',
871 'e', 'T', 'e', 'x', 't', 0};
872
873#define MAX_BUF_LEN 1024
874 CHAR bufACP[MAX_BUF_LEN];
875 WCHAR bufUnicode[MAX_BUF_LEN];
876
877 static const int tomConstantsSingle[] =
878 {
882 };
883
884 static const int tomConstantsMulti[] =
885 {
892 };
893
894 int tomNumSingle = ARRAY_SIZE(tomConstantsSingle);
895 int tomNumMulti = ARRAY_SIZE(tomConstantsMulti);
896 int i;
897
898 V_VT(&testfile) = VT_BSTR;
899 V_BSTR(&testfile) = SysAllocString(filename);
900
901 for(i=0; i < tomNumSingle; i++)
902 {
904 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
905 hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_ACP);
906 todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%lx\n",
907 tomConstantsSingle[i], hres);
908 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
910
912 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
913 hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsSingle[i], CP_UTF8);
914 todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%lx\n",
915 tomConstantsSingle[i], hres);
916 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
918 }
919
920 for(i=0; i < tomNumMulti; i++)
921 {
923 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
924 hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_ACP);
925 todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_ACP hres:0x%lx\n",
926 tomConstantsMulti[i], hres);
927 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
929
931 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
932 hres = ITextDocument_Open(txtDoc, &testfile, tomConstantsMulti[i], CP_UTF8);
933 todo_wine ok(hres == S_OK, "ITextDocument_Open: Filename:test.txt Flags:0x%x Codepage:CP_UTF8 hres:0x%lx\n",
934 tomConstantsMulti[i], hres);
935 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
937 }
938
939 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
940 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_ACP);
941 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
942 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
943 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
945
946 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
947 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateAlways, CP_UTF8);
948 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
949 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
950 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
952
953 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
954 hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_ACP);
955 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
956 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
957 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
959
960 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
961 hres = ITextDocument_Open(txtDoc, &testfile, tomOpenAlways, CP_UTF8);
962 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
963 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
964 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
966
967 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
968 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
969 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_ACP\n");
970 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
971 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
973
974 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
975 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
976 todo_wine ok(hres == S_OK, "ITextDocument_Open should success Codepage:CP_UTF8\n");
977 todo_wine ok(is_existing_file(filename), "ITextDocument_Open should create a file\n");
978 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
980
981 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
983 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_ACP);
984 todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_ACP\n");
985 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
987
988 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
990 hres = ITextDocument_Open(txtDoc, &testfile, tomCreateNew, CP_UTF8);
991 todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
992 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
994
995 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
996 hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_ACP);
997 todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_ACP\n");
998 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
999
1000 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1001 hres = ITextDocument_Open(txtDoc, &testfile, tomOpenExisting, CP_UTF8);
1002 todo_wine ok(hres == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "ITextDocument_Open should fail Codepage:CP_UTF8\n");
1003 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1004
1005 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1007 hres = ITextDocument_Open(txtDoc, &testfile, tomText, CP_ACP);
1008todo_wine {
1009 ok(hres == S_OK, "got 0x%08lx\n", hres);
1010 ok(is_existing_file(filename) == TRUE, "a file should be created default\n");
1011}
1012 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1014
1015 /* test of share mode */
1017 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1018 hres = ITextDocument_Open(txtDoc, &testfile, tomShareDenyRead, CP_ACP);
1019 todo_wine
1020 ok(hres == S_OK, "got 0x%08lx\n", hres);
1021 SetLastError(0xdeadbeef);
1024 todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
1026 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1028
1030 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1031 hres = ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite, CP_ACP);
1032 todo_wine
1033 ok(hres == S_OK, "got 0x%08lx\n", hres);
1034 SetLastError(0xdeadbeef);
1037 todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
1039 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1041
1043 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1044 SetLastError(0xdeadbeef);
1045 hres = ITextDocument_Open(txtDoc, &testfile, tomShareDenyWrite|tomShareDenyRead, CP_ACP);
1046 todo_wine
1047 ok(hres == S_OK, "got 0x%08lx\n", hres);
1050 todo_wine ok(GetLastError() == ERROR_SHARING_VIOLATION, "ITextDocument_Open should fail\n");
1052 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1054
1055 /* tests to check the content */
1058 WriteFile(hFile, chACP, sizeof(chACP)-sizeof(CHAR), &dw, NULL);
1060 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1061 hres = ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_ACP);
1062 todo_wine
1063 ok(hres == S_OK, "got 0x%08lx\n", hres);
1064 result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
1065 todo_wine ok(result == 12, "ITextDocument_Open: Test ASCII returned %d, expected 12\n", result);
1066 result = strcmp(bufACP, chACP);
1067 todo_wine ok(result == 0, "ITextDocument_Open: Test ASCII set wrong text: Result: %s\n", bufACP);
1068 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1070
1073 WriteFile(hFile, chUTF8, sizeof(chUTF8)-sizeof(CHAR), &dw, NULL);
1075 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1076 hres = ITextDocument_Open(txtDoc, &testfile, tomReadOnly, CP_UTF8);
1077 todo_wine
1078 ok(hres == S_OK, "got 0x%08lx\n", hres);
1079 result = SendMessageA(w, WM_GETTEXT, 1024, (LPARAM)bufACP);
1080 todo_wine ok(result == 15, "ITextDocument_Open: Test UTF-8 returned %d, expected 15\n", result);
1081 result = strcmp(bufACP, &chUTF8[3]);
1082 todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-8 set wrong text: Result: %s\n", bufACP);
1083 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1085
1088 WriteFile(hFile, chUTF16, sizeof(chUTF16)-sizeof(WCHAR), &dw, NULL);
1090 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1091 hres = ITextDocument_Open(txtDoc, &testfile, tomReadOnly, 1200);
1092 todo_wine
1093 ok(hres == S_OK, "got 0x%08lx\n", hres);
1094 result = SendMessageW(w, WM_GETTEXT, 1024, (LPARAM)bufUnicode);
1095 todo_wine ok(result == 12, "ITextDocument_Open: Test UTF-16 returned %d, expected 12\n", result);
1096 result = lstrcmpW(bufUnicode, &chUTF16[1]);
1097 todo_wine ok(result == 0, "ITextDocument_Open: Test UTF-16 set wrong text: Result: %s\n", wine_dbgstr_w(bufUnicode));
1098 release_interfaces(&w, &reOle, &txtDoc, &txtSel);
1100
1101 VariantClear(&testfile);
1102}
1103
1104static void test_GetText(void)
1105{
1106 HWND w;
1107 IRichEditOle *reOle = NULL;
1108 ITextDocument *txtDoc = NULL;
1109 ITextSelection *txtSel = NULL;
1110 HRESULT hres;
1111 BSTR bstr = NULL;
1112 int first, lim;
1113 static const CHAR test_text1[] = "TestSomeText";
1114 static const WCHAR bufW1[] = {'T', 'e', 's', 't', 0};
1115 static const WCHAR bufW2[] = {'T', 'e', 'x', 't', '\r', 0};
1116 static const WCHAR bufW3[] = {'T', 'e', 'x', 't', 0};
1117 static const WCHAR bufW4[] = {'T', 'e', 's', 't', 'S', 'o', 'm',
1118 'e', 'T', 'e', 'x', 't', '\r', 0};
1119 static const WCHAR bufW5[] = {'\r', 0};
1120 static const WCHAR bufW6[] = {'T','e','s','t','S','o','m','e','T',0};
1121 BOOL is64bit = sizeof(void *) > sizeof(int);
1123
1124 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1125 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1126
1127 /* ITextSelection */
1128 first = 0; lim = 4;
1129 SendMessageA(w, EM_SETSEL, first, lim);
1130 hres = ITextSelection_GetText(txtSel, &bstr);
1131 ok(hres == S_OK, "ITextSelection_GetText\n");
1132 ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1133 SysFreeString(bstr);
1134
1135 first = 4; lim = 0;
1136 SendMessageA(w, EM_SETSEL, first, lim);
1137 hres = ITextSelection_GetText(txtSel, &bstr);
1138 ok(hres == S_OK, "ITextSelection_GetText\n");
1139 ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1140 SysFreeString(bstr);
1141
1142 first = 1; lim = 1;
1143 SendMessageA(w, EM_SETSEL, first, lim);
1144 hres = ITextSelection_GetText(txtSel, &bstr);
1145 ok(hres == S_OK, "ITextSelection_GetText\n");
1146 ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
1147
1148 if (!is64bit)
1149 {
1150 hres = ITextSelection_GetText(txtSel, NULL);
1151 ok(hres == E_INVALIDARG, "ITextSelection_GetText\n");
1152 }
1153
1154 first = 8; lim = 12;
1155 SendMessageA(w, EM_SETSEL, first, lim);
1156 hres = ITextSelection_GetText(txtSel, &bstr);
1157 ok(hres == S_OK, "ITextSelection_GetText\n");
1158 ok(!lstrcmpW(bstr, bufW3), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1159 SysFreeString(bstr);
1160
1161 first = 8; lim = 13;
1162 SendMessageA(w, EM_SETSEL, first, lim);
1163 hres = ITextSelection_GetText(txtSel, &bstr);
1164 ok(hres == S_OK, "ITextSelection_GetText\n");
1165 ok(!lstrcmpW(bstr, bufW2), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1166 SysFreeString(bstr);
1167
1168 first = 12; lim = 13;
1169 SendMessageA(w, EM_SETSEL, first, lim);
1170 hres = ITextSelection_GetText(txtSel, &bstr);
1171 ok(hres == S_OK, "ITextSelection_GetText\n");
1172 ok(!lstrcmpW(bstr, bufW5), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1173 SysFreeString(bstr);
1174
1175 first = 0; lim = -1;
1176 SendMessageA(w, EM_SETSEL, first, lim);
1177 hres = ITextSelection_GetText(txtSel, &bstr);
1178 ok(hres == S_OK, "ITextSelection_GetText\n");
1179 ok(!lstrcmpW(bstr, bufW4), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1180 SysFreeString(bstr);
1181
1182 first = -1; lim = 9;
1183 SendMessageA(w, EM_SETSEL, first, lim);
1184 hres = ITextSelection_GetText(txtSel, &bstr);
1185 ok(hres == S_OK, "ITextSelection_GetText\n");
1186 ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
1187
1188 /* ITextRange */
1189 hres = ITextDocument_Range(txtDoc, 0, 4, &range);
1190 ok(hres == S_OK, "got 0x%08lx\n", hres);
1191 hres = ITextRange_GetText(range, &bstr);
1192 ok(hres == S_OK, "got 0x%08lx\n", hres);
1193 ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1194
1195 SysFreeString(bstr);
1196 ITextRange_Release(range);
1197
1198 hres = ITextDocument_Range(txtDoc, 4, 0, &range);
1199 ok(hres == S_OK, "got 0x%08lx\n", hres);
1200 hres = ITextRange_GetText(range, &bstr);
1201 ok(hres == S_OK, "got 0x%08lx\n", hres);
1202 ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1203
1204 SysFreeString(bstr);
1205 ITextRange_Release(range);
1206
1207 hres = ITextDocument_Range(txtDoc, 1, 1, &range);
1208 ok(hres == S_OK, "got 0x%08lx\n", hres);
1209 hres = ITextRange_GetText(range, &bstr);
1210 ok(hres == S_OK, "got 0x%08lx\n", hres);
1211 ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
1212 if (!is64bit)
1213 {
1214 hres = ITextRange_GetText(range, NULL);
1215 ok(hres == E_INVALIDARG, "got 0x%08lx\n", hres);
1216 }
1217 ITextRange_Release(range);
1218
1219 hres = ITextDocument_Range(txtDoc, 8, 12, &range);
1220 ok(hres == S_OK, "got 0x%08lx\n", hres);
1221 hres = ITextRange_GetText(range, &bstr);
1222 ok(hres == S_OK, "got 0x%08lx\n", hres);
1223 ok(!lstrcmpW(bstr, bufW3), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1224
1225 SysFreeString(bstr);
1226 ITextRange_Release(range);
1227
1228 hres = ITextDocument_Range(txtDoc, 8, 13, &range);
1229 ok(hres == S_OK, "got 0x%08lx\n", hres);
1230 hres = ITextRange_GetText(range, &bstr);
1231 ok(hres == S_OK, "got 0x%08lx\n", hres);
1232 ok(!lstrcmpW(bstr, bufW2), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1233
1234 SysFreeString(bstr);
1235 ITextRange_Release(range);
1236
1237 hres = ITextDocument_Range(txtDoc, 12, 13, &range);
1238 ok(hres == S_OK, "got 0x%08lx\n", hres);
1239 hres = ITextRange_GetText(range, &bstr);
1240 ok(hres == S_OK, "got 0x%08lx\n", hres);
1241 ok(!lstrcmpW(bstr, bufW5), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1242
1243 SysFreeString(bstr);
1244 ITextRange_Release(range);
1245
1246 hres = ITextDocument_Range(txtDoc, 0, -1, &range);
1247 ok(hres == S_OK, "got 0x%08lx\n", hres);
1248 hres = ITextRange_GetText(range, &bstr);
1249 ok(hres == S_OK, "got 0x%08lx\n", hres);
1250 ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
1251 ITextRange_Release(range);
1252
1253 hres = ITextDocument_Range(txtDoc, -1, 9, &range);
1254 ok(hres == S_OK, "got 0x%08lx\n", hres);
1255 hres = ITextRange_GetText(range, &bstr);
1256 ok(hres == S_OK, "got 0x%08lx\n", hres);
1257 ok(!lstrcmpW(bstr, bufW6), "got wrong text: %s\n", wine_dbgstr_w(bstr));
1258
1259 SysFreeString(bstr);
1260
1261 release_interfaces(&w, &reOle, &txtDoc, NULL);
1262
1263 /* detached selection/range */
1264 if (is64bit) {
1265 bstr = (void*)0xdeadbeef;
1266 hres = ITextSelection_GetText(txtSel, &bstr);
1267 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1268 todo_wine
1269 ok(bstr == NULL, "got %p\n", bstr);
1270
1271 bstr = (void*)0xdeadbeef;
1272 hres = ITextRange_GetText(range, &bstr);
1273 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1274 todo_wine
1275 ok(bstr == NULL, "got %p\n", bstr);
1276 }
1277 else {
1278 hres = ITextSelection_GetText(txtSel, NULL);
1279 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1280
1281 hres = ITextRange_GetText(range, NULL);
1282 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1283 }
1284
1285 ITextRange_Release(range);
1286 ITextSelection_Release(txtSel);
1287}
1288
1290{
1291 static const CHAR test_text1[] = "TestSomeText";
1292 HWND w;
1293 IRichEditOle *reOle = NULL;
1294 ITextDocument *txtDoc = NULL;
1295 ITextRange *txtRge, *range2;
1296 HRESULT hres;
1297 LONG value;
1298
1299 create_interfaces(&w, &reOle, &txtDoc, NULL);
1300 hres = ITextDocument_Range(txtDoc, 0, 0, &txtRge);
1301 ok(hres == S_OK, "ITextDocument_Range fails 0x%lx.\n", hres);
1302 EXPECT_REF(txtRge, 1);
1303
1304 hres = ITextDocument_Range(txtDoc, 0, 0, &range2);
1305 ok(hres == S_OK, "ITextDocument_Range fails 0x%lx.\n", hres);
1306 ok(range2 != txtRge, "A new pointer should be returned\n");
1307 ITextRange_Release(range2);
1308
1309 hres = ITextDocument_Range(txtDoc, 0, 0, NULL);
1310 ok(hres == E_INVALIDARG, "ITextDocument_Range should fail 0x%lx.\n", hres);
1311
1312 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1313
1314 hres = ITextDocument_Range(txtDoc, 8, 30, &range2);
1315 ok(hres == S_OK, "ITextDocument_Range fails 0x%lx.\n", hres);
1316 hres = ITextRange_GetStart(range2, &value);
1317 ok(hres == S_OK, "got 0x%08lx\n", hres);
1318 ok(value == 8, "got %ld\n", value);
1319
1320 hres = ITextRange_GetEnd(range2, &value);
1321 ok(hres == S_OK, "got 0x%08lx\n", hres);
1322 ok(value == 13, "got %ld\n", value);
1323 ITextRange_Release(range2);
1324
1325 release_interfaces(&w, &reOle, &txtDoc, NULL);
1326 hres = ITextRange_CanEdit(txtRge, NULL);
1327 ok(hres == CO_E_RELEASED, "ITextRange after ITextDocument destroyed\n");
1328 ITextRange_Release(txtRge);
1329}
1330
1332{
1333 HWND w;
1334 IRichEditOle *reOle = NULL;
1335 ITextDocument *txtDoc = NULL;
1336 ITextRange *txtRge = NULL;
1337 HRESULT hres;
1338 LONG pch;
1339 int first, lim;
1340 static const CHAR test_text1[] = "TestSomeText";
1341
1342 first = 0, lim = 4;
1343 create_interfaces(&w, &reOle, &txtDoc, NULL);
1344 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1345 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1346 ok(hres == S_OK, "got 0x%08lx\n", hres);
1347 pch = 0xdeadbeef;
1348 hres = ITextRange_GetChar(txtRge, &pch);
1349 ok(hres == S_OK, "ITextRange_GetChar\n");
1350 ok(pch == 'T', "got wrong char: %c\n", (char)pch);
1351 ITextRange_Release(txtRge);
1352 release_interfaces(&w, &reOle, &txtDoc, NULL);
1353
1354 first = 0; lim = 0;
1355 create_interfaces(&w, &reOle, &txtDoc, NULL);
1356 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1357 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1358 ok(hres == S_OK, "got 0x%08lx\n", hres);
1359 pch = 0xdeadbeef;
1360 hres = ITextRange_GetChar(txtRge, &pch);
1361 ok(hres == S_OK, "ITextRange_GetChar\n");
1362 ok(pch == 'T', "got wrong char: %c\n", (char)pch);
1363 ITextRange_Release(txtRge);
1364 release_interfaces(&w, &reOle, &txtDoc, NULL);
1365
1366 first = 12; lim = 12;
1367 create_interfaces(&w, &reOle, &txtDoc, NULL);
1368 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1369 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1370 ok(hres == S_OK, "got 0x%08lx\n", hres);
1371 pch = 0xdeadbeef;
1372 hres = ITextRange_GetChar(txtRge, &pch);
1373 ok(hres == S_OK, "ITextRange_GetChar\n");
1374 ok(pch == '\r', "got wrong char: %c\n", (char)pch);
1375 ITextRange_Release(txtRge);
1376 release_interfaces(&w, &reOle, &txtDoc, NULL);
1377
1378 first = 13; lim = 13;
1379 create_interfaces(&w, &reOle, &txtDoc, NULL);
1380 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1381 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1382 ok(hres == S_OK, "got 0x%08lx\n", hres);
1383 pch = 0xdeadbeef;
1384 hres = ITextRange_GetChar(txtRge, &pch);
1385 ok(hres == S_OK, "ITextRange_GetChar\n");
1386 ok(pch == '\r', "got wrong char: %c\n", (char)pch);
1387 ITextRange_Release(txtRge);
1388 release_interfaces(&w, &reOle, &txtDoc, NULL);
1389
1390 create_interfaces(&w, &reOle, &txtDoc, NULL);
1391 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1392 first = 12; lim = 12;
1393 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1394 ok(hres == S_OK, "got 0x%08lx\n", hres);
1395 hres = ITextRange_GetChar(txtRge, NULL);
1396 ok(hres == E_INVALIDARG, "ITextRange_GetChar\n");
1397
1398 release_interfaces(&w, &reOle, &txtDoc, NULL);
1399
1400 hres = ITextRange_GetChar(txtRge, NULL);
1401 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1402
1403 hres = ITextRange_GetChar(txtRge, &pch);
1404 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1405
1406 ITextRange_Release(txtRge);
1407}
1408
1409/* Helper function for testing ITextRange_ScrollIntoView */
1410static void check_range(HWND w, ITextDocument* doc, int first, int lim,
1411 LONG bStart, int expected_nonzero)
1412{
1413 SCROLLINFO si;
1414 ITextRange *txtRge = NULL;
1415 HRESULT hres;
1416
1417 si.cbSize = sizeof(SCROLLINFO);
1418 si.fMask = SIF_POS | SIF_RANGE;
1419
1420 hres = ITextDocument_Range(doc, first, lim, &txtRge);
1421 ok(hres == S_OK, "got 0x%08lx\n", hres);
1422 hres = ITextRange_ScrollIntoView(txtRge, bStart);
1423 ok(hres == S_OK, "got 0x%08lx\n", hres);
1424 GetScrollInfo(w, SB_VERT, &si);
1425 if (expected_nonzero) {
1426 ok(si.nPos != 0,
1427 "Scrollbar at 0, should be >0. (TextRange %d-%d, scroll range %d-%d.)\n",
1428 first, lim, si.nMin, si.nMax);
1429 } else {
1430 ok(si.nPos == 0,
1431 "Scrollbar at %d, should be 0. (TextRange %d-%d, scroll range %d-%d.)\n",
1432 si.nPos, first, lim, si.nMin, si.nMax);
1433 }
1434}
1435
1437{
1438 HWND w;
1439 IRichEditOle *reOle = NULL;
1440 ITextDocument *txtDoc = NULL;
1441 ITextRange *txtRge = NULL;
1442 HRESULT hres;
1443 static const CHAR test_text1[] = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
1444
1445 create_interfaces(&w, &reOle, &txtDoc, NULL);
1446 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1447
1448 /* Scroll to the top. */
1449 check_range(w, txtDoc, 0, 1, tomStart, 0);
1450 check_range(w, txtDoc, 0, 1, tomEnd, 0);
1451
1452 /* Scroll to the bottom. */
1453 check_range(w, txtDoc, 19, 20, tomStart, 1);
1454 check_range(w, txtDoc, 19, 20, tomEnd, 1);
1455
1456 /* Back up to the top. */
1457 check_range(w, txtDoc, 0, 1, tomStart, 0);
1458 check_range(w, txtDoc, 0, 1, tomEnd, 0);
1459
1460 /* Large range */
1461 check_range(w, txtDoc, 0, 20, tomStart, 0);
1462 check_range(w, txtDoc, 0, 20, tomEnd, 1);
1463
1464 hres = ITextDocument_Range(txtDoc, 0, 0, &txtRge);
1465 ok(hres == S_OK, "got 0x%08lx\n", hres);
1466 release_interfaces(&w, &reOle, &txtDoc, NULL);
1467 hres = ITextRange_ScrollIntoView(txtRge, tomStart);
1468 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1469 ITextRange_Release(txtRge);
1470}
1471
1473{
1474 HWND w;
1475 IRichEditOle *reOle = NULL;
1476 ITextDocument *txtDoc = NULL;
1477 ITextSelection *txtSel = NULL;
1478 HRESULT hres;
1479 LONG pch;
1480 int first, lim;
1481 static const CHAR test_text1[] = "TestSomeText";
1482
1483 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1484 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1485
1486 first = 0; lim = 4;
1487 SendMessageA(w, EM_SETSEL, first, lim);
1488 pch = 0xdeadbeef;
1489 hres = ITextSelection_GetChar(txtSel, &pch);
1490 ok(hres == S_OK, "ITextSelection_GetChar\n");
1491 ok(pch == 'T', "got wrong char: %c\n", (char)pch);
1492
1493 first = 0; lim = 0;
1494 SendMessageA(w, EM_SETSEL, first, lim);
1495 pch = 0xdeadbeef;
1496 hres = ITextSelection_GetChar(txtSel, &pch);
1497 ok(hres == S_OK, "ITextSelection_GetChar\n");
1498 ok(pch == 'T', "got wrong char: %c\n", (char)pch);
1499
1500 first = 12; lim = 12;
1501 SendMessageA(w, EM_SETSEL, first, lim);
1502 pch = 0xdeadbeef;
1503 hres = ITextSelection_GetChar(txtSel, &pch);
1504 ok(hres == S_OK, "ITextSelection_GetChar\n");
1505 ok(pch == '\r', "got wrong char: %c\n", (char)pch);
1506
1507 first = 13; lim = 13;
1508 SendMessageA(w, EM_SETSEL, first, lim);
1509 pch = 0xdeadbeef;
1510 hres = ITextSelection_GetChar(txtSel, &pch);
1511 ok(hres == S_OK, "ITextSelection_GetChar\n");
1512 ok(pch == '\r', "got wrong char: %c\n", (char)pch);
1513
1514 hres = ITextSelection_GetChar(txtSel, NULL);
1515 ok(hres == E_INVALIDARG, "ITextSelection_GetChar\n");
1516
1517 release_interfaces(&w, &reOle, &txtDoc, NULL);
1518
1519 hres = ITextSelection_GetChar(txtSel, NULL);
1520 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1521
1522 hres = ITextSelection_GetChar(txtSel, &pch);
1523 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1524
1525 ITextSelection_Release(txtSel);
1526}
1527
1529{
1530 HWND w;
1531 IRichEditOle *reOle = NULL;
1532 ITextDocument *txtDoc = NULL;
1533 ITextRange *txtRge = NULL;
1534 HRESULT hres;
1535 int first, lim;
1536 LONG start, end;
1537 static const CHAR test_text1[] = "TestSomeText";
1538
1539 create_interfaces(&w, &reOle, &txtDoc, NULL);
1540 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1541
1542 first = 1; lim = 6;
1543 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1544 ok(hres == S_OK, "got 0x%08lx\n", hres);
1545 start = 0xdeadbeef;
1546 hres = ITextRange_GetStart(txtRge, &start);
1547 ok(hres == S_OK, "ITextRange_GetStart\n");
1548 ok(start == 1, "got wrong start value: %ld\n", start);
1549 end = 0xdeadbeef;
1550 hres = ITextRange_GetEnd(txtRge, &end);
1551 ok(hres == S_OK, "ITextRange_GetEnd\n");
1552 ok(end == 6, "got wrong end value: %ld\n", end);
1553 ITextRange_Release(txtRge);
1554
1555 first = 6; lim = 1;
1556 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1557 ok(hres == S_OK, "got 0x%08lx\n", hres);
1558 start = 0xdeadbeef;
1559 hres = ITextRange_GetStart(txtRge, &start);
1560 ok(hres == S_OK, "ITextRange_GetStart\n");
1561 ok(start == 1, "got wrong start value: %ld\n", start);
1562 end = 0xdeadbeef;
1563 hres = ITextRange_GetEnd(txtRge, &end);
1564 ok(hres == S_OK, "ITextRange_GetEnd\n");
1565 ok(end == 6, "got wrong end value: %ld\n", end);
1566 ITextRange_Release(txtRge);
1567
1568 first = -1; lim = 13;
1569 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1570 ok(hres == S_OK, "got 0x%08lx\n", hres);
1571 start = 0xdeadbeef;
1572 hres = ITextRange_GetStart(txtRge, &start);
1573 ok(hres == S_OK, "ITextRange_GetStart\n");
1574 ok(start == 0, "got wrong start value: %ld\n", start);
1575 end = 0xdeadbeef;
1576 hres = ITextRange_GetEnd(txtRge, &end);
1577 ok(hres == S_OK, "ITextRange_GetEnd\n");
1578 ok(end == 13, "got wrong end value: %ld\n", end);
1579 ITextRange_Release(txtRge);
1580
1581 first = 13; lim = 13;
1582 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1583 ok(hres == S_OK, "got 0x%08lx\n", hres);
1584 start = 0xdeadbeef;
1585 hres = ITextRange_GetStart(txtRge, &start);
1586 ok(hres == S_OK, "ITextRange_GetStart\n");
1587 ok(start == 12, "got wrong start value: %ld\n", start);
1588 end = 0xdeadbeef;
1589 hres = ITextRange_GetEnd(txtRge, &end);
1590 ok(hres == S_OK, "ITextRange_GetEnd\n");
1591 ok(end == 12, "got wrong end value: %ld\n", end);
1592
1593 /* SetStart */
1594 hres = ITextRange_SetStart(txtRge, 0);
1595 ok(hres == S_OK, "got 0x%08lx\n", hres);
1596
1597 /* same value */
1598 hres = ITextRange_SetStart(txtRge, 0);
1599 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1600
1601 hres = ITextRange_SetStart(txtRge, 1);
1602 ok(hres == S_OK, "got 0x%08lx\n", hres);
1603
1604 /* negative resets to 0, return value is S_FALSE when
1605 position wasn't changed */
1606 hres = ITextRange_SetStart(txtRge, -1);
1607 ok(hres == S_OK, "got 0x%08lx\n", hres);
1608
1609 hres = ITextRange_SetStart(txtRge, -1);
1610 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1611
1612 hres = ITextRange_SetStart(txtRge, 0);
1613 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1614
1615 start = -1;
1616 hres = ITextRange_GetStart(txtRge, &start);
1617 ok(hres == S_OK, "got 0x%08lx\n", hres);
1618 ok(start == 0, "got %ld\n", start);
1619
1620 /* greater than initial end, but less than total char count */
1621 hres = ITextRange_SetStart(txtRge, 1);
1622 ok(hres == S_OK, "got 0x%08lx\n", hres);
1623
1624 hres = ITextRange_SetEnd(txtRge, 3);
1625 ok(hres == S_OK, "got 0x%08lx\n", hres);
1626
1627 hres = ITextRange_SetStart(txtRge, 10);
1628 ok(hres == S_OK, "got 0x%08lx\n", hres);
1629
1630 start = 0;
1631 hres = ITextRange_GetStart(txtRge, &start);
1632 ok(hres == S_OK, "got 0x%08lx\n", hres);
1633 ok(start == 10, "got %ld\n", start);
1634
1635 end = 0;
1636 hres = ITextRange_GetEnd(txtRge, &end);
1637 ok(hres == S_OK, "got 0x%08lx\n", hres);
1638 ok(end == 10, "got %ld\n", end);
1639
1640 /* more that total text length */
1641 hres = ITextRange_SetStart(txtRge, 50);
1642 ok(hres == S_OK, "got 0x%08lx\n", hres);
1643
1644 start = 0;
1645 hres = ITextRange_GetStart(txtRge, &start);
1646 ok(hres == S_OK, "got 0x%08lx\n", hres);
1647 ok(start == 12, "got %ld\n", start);
1648
1649 end = 0;
1650 hres = ITextRange_GetEnd(txtRge, &end);
1651 ok(hres == S_OK, "got 0x%08lx\n", hres);
1652 ok(end == 12, "got %ld\n", end);
1653
1654 /* SetEnd */
1655 hres = ITextRange_SetStart(txtRge, 0);
1656 ok(hres == S_OK, "got 0x%08lx\n", hres);
1657
1658 /* same value */
1659 hres = ITextRange_SetEnd(txtRge, 5);
1660 ok(hres == S_OK, "got 0x%08lx\n", hres);
1661
1662 hres = ITextRange_SetEnd(txtRge, 5);
1663 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1664
1665 /* negative resets to 0 */
1666 hres = ITextRange_SetEnd(txtRge, -1);
1667 ok(hres == S_OK, "got 0x%08lx\n", hres);
1668
1669 end = -1;
1670 hres = ITextRange_GetEnd(txtRge, &end);
1671 ok(hres == S_OK, "got 0x%08lx\n", hres);
1672 ok(end == 0, "got %ld\n", end);
1673
1674 start = -1;
1675 hres = ITextRange_GetStart(txtRge, &start);
1676 ok(hres == S_OK, "got 0x%08lx\n", hres);
1677 ok(start == 0, "got %ld\n", start);
1678
1679 /* greater than initial end, but less than total char count */
1680 hres = ITextRange_SetStart(txtRge, 3);
1681 ok(hres == S_OK, "got 0x%08lx\n", hres);
1682
1683 hres = ITextRange_SetEnd(txtRge, 1);
1684 ok(hres == S_OK, "got 0x%08lx\n", hres);
1685
1686 start = 0;
1687 hres = ITextRange_GetStart(txtRge, &start);
1688 ok(hres == S_OK, "got 0x%08lx\n", hres);
1689 ok(start == 1, "got %ld\n", start);
1690
1691 end = 0;
1692 hres = ITextRange_GetEnd(txtRge, &end);
1693 ok(hres == S_OK, "got 0x%08lx\n", hres);
1694 ok(end == 1, "got %ld\n", end);
1695
1696 /* more than total count */
1697 hres = ITextRange_SetEnd(txtRge, 50);
1698 ok(hres == S_OK, "got 0x%08lx\n", hres);
1699
1700 start = 0;
1701 hres = ITextRange_GetStart(txtRge, &start);
1702 ok(hres == S_OK, "got 0x%08lx\n", hres);
1703 ok(start == 1, "got %ld\n", start);
1704
1705 end = 0;
1706 hres = ITextRange_GetEnd(txtRge, &end);
1707 ok(hres == S_OK, "got 0x%08lx\n", hres);
1708 ok(end == 13, "got %ld\n", end);
1709
1710 /* zero */
1711 hres = ITextRange_SetEnd(txtRge, 0);
1712 ok(hres == S_OK, "got 0x%08lx\n", hres);
1713
1714 start = 0;
1715 hres = ITextRange_GetStart(txtRge, &start);
1716 ok(hres == S_OK, "got 0x%08lx\n", hres);
1717 ok(start == 0, "got %ld\n", start);
1718
1719 end = 0;
1720 hres = ITextRange_GetEnd(txtRge, &end);
1721 ok(hres == S_OK, "got 0x%08lx\n", hres);
1722 ok(end == 0, "got %ld\n", end);
1723
1724 release_interfaces(&w, &reOle, &txtDoc, NULL);
1725
1726 /* detached range */
1727 hres = ITextRange_SetStart(txtRge, 0);
1728 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1729
1730 hres = ITextRange_SetEnd(txtRge, 3);
1731 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1732
1733 hres = ITextRange_GetStart(txtRge, &start);
1734 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1735
1736 hres = ITextRange_GetStart(txtRge, NULL);
1737 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1738
1739 hres = ITextRange_GetEnd(txtRge, &end);
1740 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1741
1742 hres = ITextRange_GetEnd(txtRge, NULL);
1743 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1744
1745 ITextRange_Release(txtRge);
1746}
1747
1749{
1750 HWND w;
1751 IRichEditOle *reOle = NULL;
1752 ITextDocument *txtDoc = NULL;
1753 ITextSelection *txtSel = NULL;
1754 HRESULT hres;
1755 int first, lim;
1756 LONG start, end;
1757 static const CHAR test_text1[] = "TestSomeText";
1758
1759 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
1760 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1761
1762 first = 2; lim = 5;
1763 SendMessageA(w, EM_SETSEL, first, lim);
1764 start = 0xdeadbeef;
1765 hres = ITextSelection_GetStart(txtSel, &start);
1766 ok(hres == S_OK, "ITextSelection_GetStart\n");
1767 ok(start == 2, "got wrong start value: %ld\n", start);
1768 end = 0xdeadbeef;
1769 hres = ITextSelection_GetEnd(txtSel, &end);
1770 ok(hres == S_OK, "ITextSelection_GetEnd\n");
1771 ok(end == 5, "got wrong end value: %ld\n", end);
1772
1773 first = 5; lim = 2;
1774 SendMessageA(w, EM_SETSEL, first, lim);
1775 start = 0xdeadbeef;
1776 hres = ITextSelection_GetStart(txtSel, &start);
1777 ok(hres == S_OK, "ITextSelection_GetStart\n");
1778 ok(start == 2, "got wrong start value: %ld\n", start);
1779 end = 0xdeadbeef;
1780 hres = ITextSelection_GetEnd(txtSel, &end);
1781 ok(hres == S_OK, "ITextSelection_GetEnd\n");
1782 ok(end == 5, "got wrong end value: %ld\n", end);
1783
1784 first = 0; lim = -1;
1785 SendMessageA(w, EM_SETSEL, first, lim);
1786 start = 0xdeadbeef;
1787 hres = ITextSelection_GetStart(txtSel, &start);
1788 ok(hres == S_OK, "ITextSelection_GetStart\n");
1789 ok(start == 0, "got wrong start value: %ld\n", start);
1790 end = 0xdeadbeef;
1791 hres = ITextSelection_GetEnd(txtSel, &end);
1792 ok(hres == S_OK, "ITextSelection_GetEnd\n");
1793 ok(end == 13, "got wrong end value: %ld\n", end);
1794
1795 first = 13; lim = 13;
1796 SendMessageA(w, EM_SETSEL, first, lim);
1797 start = 0xdeadbeef;
1798 hres = ITextSelection_GetStart(txtSel, &start);
1799 ok(hres == S_OK, "ITextSelection_GetStart\n");
1800 ok(start == 12, "got wrong start value: %ld\n", start);
1801 end = 0xdeadbeef;
1802 hres = ITextSelection_GetEnd(txtSel, &end);
1803 ok(hres == S_OK, "ITextSelection_GetEnd\n");
1804 ok(end == 12, "got wrong end value: %ld\n", end);
1805
1806 /* SetStart/SetEnd */
1807 hres = ITextSelection_SetStart(txtSel, 0);
1808 ok(hres == S_OK, "got 0x%08lx\n", hres);
1809
1810 /* same value */
1811 hres = ITextSelection_SetStart(txtSel, 0);
1812 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1813
1814 hres = ITextSelection_SetStart(txtSel, 1);
1815 ok(hres == S_OK, "got 0x%08lx\n", hres);
1816
1817 /* negative resets to 0, return value is S_FALSE when
1818 position wasn't changed */
1819 hres = ITextSelection_SetStart(txtSel, -1);
1820 ok(hres == S_OK, "got 0x%08lx\n", hres);
1821
1822 hres = ITextSelection_SetStart(txtSel, -1);
1823 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1824
1825 hres = ITextSelection_SetStart(txtSel, 0);
1826 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1827
1828 start = -1;
1829 hres = ITextSelection_GetStart(txtSel, &start);
1830 ok(hres == S_OK, "got 0x%08lx\n", hres);
1831 ok(start == 0, "got %ld\n", start);
1832
1833 /* greater than initial end, but less than total char count */
1834 hres = ITextSelection_SetStart(txtSel, 1);
1835 ok(hres == S_OK, "got 0x%08lx\n", hres);
1836
1837 hres = ITextSelection_SetEnd(txtSel, 3);
1838 ok(hres == S_OK, "got 0x%08lx\n", hres);
1839
1840 hres = ITextSelection_SetStart(txtSel, 10);
1841 ok(hres == S_OK, "got 0x%08lx\n", hres);
1842
1843 start = 0;
1844 hres = ITextSelection_GetStart(txtSel, &start);
1845 ok(hres == S_OK, "got 0x%08lx\n", hres);
1846 ok(start == 10, "got %ld\n", start);
1847
1848 end = 0;
1849 hres = ITextSelection_GetEnd(txtSel, &end);
1850 ok(hres == S_OK, "got 0x%08lx\n", hres);
1851 ok(end == 10, "got %ld\n", end);
1852
1853 /* more that total text length */
1854 hres = ITextSelection_SetStart(txtSel, 50);
1855 ok(hres == S_OK, "got 0x%08lx\n", hres);
1856
1857 start = 0;
1858 hres = ITextSelection_GetStart(txtSel, &start);
1859 ok(hres == S_OK, "got 0x%08lx\n", hres);
1860 ok(start == 12, "got %ld\n", start);
1861
1862 end = 0;
1863 hres = ITextSelection_GetEnd(txtSel, &end);
1864 ok(hres == S_OK, "got 0x%08lx\n", hres);
1865 ok(end == 12, "got %ld\n", end);
1866
1867 /* SetEnd */
1868 hres = ITextSelection_SetStart(txtSel, 0);
1869 ok(hres == S_OK, "got 0x%08lx\n", hres);
1870
1871 /* same value */
1872 hres = ITextSelection_SetEnd(txtSel, 5);
1873 ok(hres == S_OK, "got 0x%08lx\n", hres);
1874
1875 hres = ITextSelection_SetEnd(txtSel, 5);
1876 ok(hres == S_FALSE, "got 0x%08lx\n", hres);
1877
1878 /* negative resets to 0 */
1879 hres = ITextSelection_SetEnd(txtSel, -1);
1880 ok(hres == S_OK, "got 0x%08lx\n", hres);
1881
1882 end = -1;
1883 hres = ITextSelection_GetEnd(txtSel, &end);
1884 ok(hres == S_OK, "got 0x%08lx\n", hres);
1885 ok(end == 0, "got %ld\n", end);
1886
1887 start = -1;
1888 hres = ITextSelection_GetStart(txtSel, &start);
1889 ok(hres == S_OK, "got 0x%08lx\n", hres);
1890 ok(start == 0, "got %ld\n", start);
1891
1892 /* greater than initial end, but less than total char count */
1893 hres = ITextSelection_SetStart(txtSel, 3);
1894 ok(hres == S_OK, "got 0x%08lx\n", hres);
1895
1896 hres = ITextSelection_SetEnd(txtSel, 1);
1897 ok(hres == S_OK, "got 0x%08lx\n", hres);
1898
1899 start = 0;
1900 hres = ITextSelection_GetStart(txtSel, &start);
1901 ok(hres == S_OK, "got 0x%08lx\n", hres);
1902 ok(start == 1, "got %ld\n", start);
1903
1904 end = 0;
1905 hres = ITextSelection_GetEnd(txtSel, &end);
1906 ok(hres == S_OK, "got 0x%08lx\n", hres);
1907 ok(end == 1, "got %ld\n", end);
1908
1909 /* more than total count */
1910 hres = ITextSelection_SetEnd(txtSel, 50);
1911 ok(hres == S_OK, "got 0x%08lx\n", hres);
1912
1913 start = 0;
1914 hres = ITextSelection_GetStart(txtSel, &start);
1915 ok(hres == S_OK, "got 0x%08lx\n", hres);
1916 ok(start == 1, "got %ld\n", start);
1917
1918 end = 0;
1919 hres = ITextSelection_GetEnd(txtSel, &end);
1920 ok(hres == S_OK, "got 0x%08lx\n", hres);
1921 ok(end == 13, "got %ld\n", end);
1922
1923 /* zero */
1924 hres = ITextSelection_SetEnd(txtSel, 0);
1925 ok(hres == S_OK, "got 0x%08lx\n", hres);
1926
1927 start = 0;
1928 hres = ITextSelection_GetStart(txtSel, &start);
1929 ok(hres == S_OK, "got 0x%08lx\n", hres);
1930 ok(start == 0, "got %ld\n", start);
1931
1932 end = 0;
1933 hres = ITextSelection_GetEnd(txtSel, &end);
1934 ok(hres == S_OK, "got 0x%08lx\n", hres);
1935 ok(end == 0, "got %ld\n", end);
1936
1937 release_interfaces(&w, &reOle, &txtDoc, NULL);
1938
1939 /* detached selection */
1940 hres = ITextSelection_GetStart(txtSel, NULL);
1941 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1942
1943 hres = ITextSelection_GetStart(txtSel, &start);
1944 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1945
1946 hres = ITextSelection_GetEnd(txtSel, NULL);
1947 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1948
1949 hres = ITextSelection_GetEnd(txtSel, &end);
1950 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1951
1952 ITextSelection_Release(txtSel);
1953}
1954
1956{
1957 HWND w;
1958 IRichEditOle *reOle = NULL;
1959 ITextDocument *txtDoc = NULL;
1960 ITextRange *txtRge = NULL;
1961 ITextRange *txtRgeDup = NULL;
1962 HRESULT hres;
1963 LONG first, lim, start, end;
1964 static const CHAR test_text1[] = "TestSomeText";
1965
1966 create_interfaces(&w, &reOle, &txtDoc, NULL);
1967 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
1968 first = 0; lim = 4;
1969 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
1970 ok(hres == S_OK, "ITextDocument_Range fails 0x%lx.\n", hres);
1971
1972 hres = ITextRange_GetDuplicate(txtRge, &txtRgeDup);
1973 ok(hres == S_OK, "ITextRange_GetDuplicate\n");
1974 ok(txtRgeDup != txtRge, "A new pointer should be returned\n");
1975 hres = ITextRange_GetStart(txtRgeDup, &start);
1976 ok(hres == S_OK, "got 0x%08lx\n", hres);
1977 ok(start == first, "got wrong value: %ld\n", start);
1978 hres = ITextRange_GetEnd(txtRgeDup, &end);
1979 ok(hres == S_OK, "got 0x%08lx\n", hres);
1980 ok(end == lim, "got wrong value: %ld\n", end);
1981
1982 ITextRange_Release(txtRgeDup);
1983
1984 hres = ITextRange_GetDuplicate(txtRge, NULL);
1985 ok(hres == E_INVALIDARG, "ITextRange_GetDuplicate\n");
1986
1987 release_interfaces(&w, &reOle, &txtDoc, NULL);
1988
1989 hres = ITextRange_GetDuplicate(txtRge, NULL);
1990 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1991
1992 hres = ITextRange_GetDuplicate(txtRge, &txtRgeDup);
1993 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
1994
1995 ITextRange_Release(txtRge);
1996}
1997
1999{
2000 HWND w;
2001 IRichEditOle *reOle = NULL;
2002 ITextDocument *txtDoc = NULL;
2003 ITextRange *txtRge = NULL;
2004 HRESULT hres;
2005 LONG first, lim, start, end;
2006 static const CHAR test_text1[] = "TestSomeText";
2007
2008 create_interfaces(&w, &reOle, &txtDoc, NULL);
2009 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
2010
2011 first = 4; lim = 8;
2012 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2013 ok(hres == S_OK, "got 0x%08lx\n", hres);
2014 hres = ITextRange_Collapse(txtRge, tomTrue);
2015 ok(hres == S_OK, "ITextRange_Collapse\n");
2016 hres = ITextRange_GetStart(txtRge, &start);
2017 ok(hres == S_OK, "got 0x%08lx\n", hres);
2018 ok(start == 4, "got wrong start value: %ld\n", start);
2019 hres = ITextRange_GetEnd(txtRge, &end);
2020 ok(hres == S_OK, "got 0x%08lx\n", hres);
2021 ok(end == 4, "got wrong end value: %ld\n", end);
2022 ITextRange_Release(txtRge);
2023
2024 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2025 ok(hres == S_OK, "got 0x%08lx\n", hres);
2026 hres = ITextRange_Collapse(txtRge, tomStart);
2027 ok(hres == S_OK, "ITextRange_Collapse\n");
2028 hres = ITextRange_GetStart(txtRge, &start);
2029 ok(hres == S_OK, "got 0x%08lx\n", hres);
2030 ok(start == 4, "got wrong start value: %ld\n", start);
2031 hres = ITextRange_GetEnd(txtRge, &end);
2032 ok(hres == S_OK, "got 0x%08lx\n", hres);
2033 ok(end == 4, "got wrong end value: %ld\n", end);
2034 ITextRange_Release(txtRge);
2035
2036 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2037 ok(hres == S_OK, "got 0x%08lx\n", hres);
2038 hres = ITextRange_Collapse(txtRge, tomFalse);
2039 ok(hres == S_OK, "ITextRange_Collapse\n");
2040 hres = ITextRange_GetStart(txtRge, &start);
2041 ok(hres == S_OK, "got 0x%08lx\n", hres);
2042 ok(start == 8, "got wrong start value: %ld\n", start);
2043 hres = ITextRange_GetEnd(txtRge, &end);
2044 ok(hres == S_OK, "got 0x%08lx\n", hres);
2045 ok(end == 8, "got wrong end value: %ld\n", end);
2046 ITextRange_Release(txtRge);
2047
2048 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2049 ok(hres == S_OK, "got 0x%08lx\n", hres);
2050 hres = ITextRange_Collapse(txtRge, tomEnd);
2051 ok(hres == S_OK, "ITextRange_Collapse\n");
2052 hres = ITextRange_GetStart(txtRge, &start);
2053 ok(hres == S_OK, "got 0x%08lx\n", hres);
2054 ok(start == 8, "got wrong start value: %ld\n", start);
2055 hres = ITextRange_GetEnd(txtRge, &end);
2056 ok(hres == S_OK, "got 0x%08lx\n", hres);
2057 ok(end == 8, "got wrong end value: %ld\n", end);
2058 ITextRange_Release(txtRge);
2059
2060 /* tomStart is the default */
2061 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2062 ok(hres == S_OK, "got 0x%08lx\n", hres);
2063 hres = ITextRange_Collapse(txtRge, 256);
2064 ok(hres == S_OK, "ITextRange_Collapse\n");
2065 hres = ITextRange_GetStart(txtRge, &start);
2066 ok(hres == S_OK, "got 0x%08lx\n", hres);
2067 ok(start == 4, "got wrong start value: %ld\n", start);
2068 hres = ITextRange_GetEnd(txtRge, &end);
2069 ok(hres == S_OK, "got 0x%08lx\n", hres);
2070 ok(end == 4, "got wrong end value: %ld\n", end);
2071 ITextRange_Release(txtRge);
2072
2073 first = 6; lim = 6;
2074 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2075 ok(hres == S_OK, "got 0x%08lx\n", hres);
2076 hres = ITextRange_Collapse(txtRge, tomEnd);
2077 ok(hres == S_FALSE, "ITextRange_Collapse\n");
2078 hres = ITextRange_GetStart(txtRge, &start);
2079 ok(hres == S_OK, "got 0x%08lx\n", hres);
2080 ok(start == 6, "got wrong start value: %ld\n", start);
2081 hres = ITextRange_GetEnd(txtRge, &end);
2082 ok(hres == S_OK, "got 0x%08lx\n", hres);
2083 ok(end == 6, "got wrong end value: %ld\n", end);
2084 ITextRange_Release(txtRge);
2085
2086 first = 8; lim = 8;
2087 hres = ITextDocument_Range(txtDoc, first, lim, &txtRge);
2088 ok(hres == S_OK, "got 0x%08lx\n", hres);
2089 hres = ITextRange_Collapse(txtRge, tomStart);
2090 ok(hres == S_FALSE, "ITextRange_Collapse\n");
2091 hres = ITextRange_GetStart(txtRge, &start);
2092 ok(hres == S_OK, "got 0x%08lx\n", hres);
2093 ok(start == 8, "got wrong start value: %ld\n", start);
2094 hres = ITextRange_GetEnd(txtRge, &end);
2095 ok(hres == S_OK, "got 0x%08lx\n", hres);
2096 ok(end == 8, "got wrong end value: %ld\n", end);
2097
2098 release_interfaces(&w, &reOle, &txtDoc, NULL);
2099
2100 hres = ITextRange_Collapse(txtRge, tomStart);
2101 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
2102
2103 hres = ITextRange_Collapse(txtRge, tomUndefined);
2104 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
2105
2106 ITextRange_Release(txtRge);
2107}
2108
2110{
2111 HWND w;
2112 IRichEditOle *reOle = NULL;
2113 ITextDocument *txtDoc = NULL;
2114 ITextSelection *txtSel = NULL;
2115 HRESULT hres;
2116 LONG first, lim, start, end;
2117 static const CHAR test_text1[] = "TestSomeText";
2118
2119 create_interfaces(&w, &reOle, &txtDoc, &txtSel);
2120 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
2121
2122 first = 4; lim = 8;
2123 SendMessageA(w, EM_SETSEL, first, lim);
2124 hres = ITextSelection_Collapse(txtSel, tomTrue);
2125 ok(hres == S_OK, "ITextSelection_Collapse\n");
2127 ok(start == 4, "got wrong start value: %ld\n", start);
2128 ok(end == 4, "got wrong end value: %ld\n", end);
2129
2130 SendMessageA(w, EM_SETSEL, first, lim);
2131 hres = ITextSelection_Collapse(txtSel, tomStart);
2132 ok(hres == S_OK, "ITextSelection_Collapse\n");
2134 ok(start == 4, "got wrong start value: %ld\n", start);
2135 ok(end == 4, "got wrong end value: %ld\n", end);
2136
2137 SendMessageA(w, EM_SETSEL, first, lim);
2138 hres = ITextSelection_Collapse(txtSel, tomFalse);
2139 ok(hres == S_OK, "ITextSelection_Collapse\n");
2141 ok(start == 8, "got wrong start value: %ld\n", start);
2142 ok(end == 8, "got wrong end value: %ld\n", end);
2143
2144 SendMessageA(w, EM_SETSEL, first, lim);
2145 hres = ITextSelection_Collapse(txtSel, tomEnd);
2146 ok(hres == S_OK, "ITextSelection_Collapse\n");
2148 ok(start == 8, "got wrong start value: %ld\n", start);
2149 ok(end == 8, "got wrong end value: %ld\n", end);
2150
2151 /* tomStart is the default */
2152 SendMessageA(w, EM_SETSEL, first, lim);
2153 hres = ITextSelection_Collapse(txtSel, 256);
2154 ok(hres == S_OK, "ITextSelection_Collapse\n");
2156 ok(start == 4, "got wrong start value: %ld\n", start);
2157 ok(end == 4, "got wrong end value: %ld\n", end);
2158
2159 first = 6; lim = 6;
2160 SendMessageA(w, EM_SETSEL, first, lim);
2161 hres = ITextSelection_Collapse(txtSel, tomEnd);
2162 ok(hres == S_FALSE, "ITextSelection_Collapse\n");
2164 ok(start == 6, "got wrong start value: %ld\n", start);
2165 ok(end == 6, "got wrong end value: %ld\n", end);
2166
2167 first = 8; lim = 8;
2168 SendMessageA(w, EM_SETSEL, first, lim);
2169 hres = ITextSelection_Collapse(txtSel, tomStart);
2170 ok(hres == S_FALSE, "ITextSelection_Collapse\n");
2172 ok(start == 8, "got wrong start value: %ld\n", start);
2173 ok(end == 8, "got wrong end value: %ld\n", end);
2174
2175 release_interfaces(&w, &reOle, &txtDoc, NULL);
2176
2177 hres = ITextSelection_Collapse(txtSel, tomStart);
2178 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
2179
2180 hres = ITextSelection_Collapse(txtSel, tomUndefined);
2181 ok(hres == CO_E_RELEASED, "got 0x%08lx\n", hres);
2182
2183 ITextSelection_Release(txtSel);
2184}
2185
2186static void test_GetClientSite(void)
2187{
2188 HWND w;
2189 IRichEditOle *reOle = NULL, *reOle1 = NULL;
2190 ITextDocument *txtDoc = NULL;
2191 IOleClientSite *clientSite = NULL, *clientSite1 = NULL, *clientSite2 = NULL;
2192 IOleWindow *oleWin = NULL, *oleWin1 = NULL;
2193 IOleInPlaceSite *olePlace = NULL, *olePlace1 = NULL;
2194 HRESULT hres;
2195 LONG refcount1, refcount2;
2196
2197 create_interfaces(&w, &reOle, &txtDoc, NULL);
2198 hres = IRichEditOle_GetClientSite(reOle, &clientSite);
2199 ok(hres == S_OK, "IRichEditOle_QueryInterface: 0x%08lx\n", hres);
2200 EXPECT_REF(clientSite, 1);
2201
2202 hres = IOleClientSite_QueryInterface(clientSite, &IID_IRichEditOle, (void **)&reOle1);
2203 ok(hres == E_NOINTERFACE, "IOleClientSite_QueryInterface: %lx\n", hres);
2204
2205 hres = IRichEditOle_GetClientSite(reOle, &clientSite1);
2206 ok(hres == S_OK, "got 0x%08lx\n", hres);
2207 ok(clientSite != clientSite1, "got %p, %p\n", clientSite, clientSite1);
2208 IOleClientSite_Release(clientSite1);
2209
2210 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleClientSite, (void **)&clientSite1);
2211 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2212 ok(clientSite == clientSite1, "Should not return a new pointer.\n");
2213 EXPECT_REF(clientSite, 2);
2214
2215 /* IOleWindow interface */
2216 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleWindow, (void **)&oleWin);
2217 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2218 refcount1 = get_refcount((IUnknown *)clientSite);
2219 refcount2 = get_refcount((IUnknown *)oleWin);
2220 ok(refcount1 == refcount2, "got wrong ref count.\n");
2221
2222 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleWindow, (void **)&oleWin1);
2223 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2224 ok(oleWin == oleWin1, "Should not return a new pointer.\n");
2225 refcount1 = get_refcount((IUnknown *)clientSite);
2226 refcount2 = get_refcount((IUnknown *)oleWin);
2227 ok(refcount1 == refcount2, "got wrong ref count.\n");
2228
2229 hres = IOleWindow_QueryInterface(oleWin, &IID_IOleClientSite, (void **)&clientSite2);
2230 ok(hres == S_OK, "IOleWindow_QueryInterface: 0x%08lx\n", hres);
2231 ok(clientSite2 == clientSite1, "got wrong pointer\n");
2232
2233 /* IOleInPlaceSite interface */
2234 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleInPlaceSite, (void **)&olePlace);
2235 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2236 refcount1 = get_refcount((IUnknown *)olePlace);
2237 refcount2 = get_refcount((IUnknown *)clientSite);
2238 ok(refcount1 == refcount2, "got wrong ref count.\n");
2239
2240 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleInPlaceSite, (void **)&olePlace1);
2241 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2242 ok(olePlace == olePlace1, "Should not return a new pointer.\n");
2243 IOleInPlaceSite_Release(olePlace1);
2244
2245 hres = IOleWindow_QueryInterface(oleWin, &IID_IOleInPlaceSite, (void **)&olePlace1);
2246 ok(hres == S_OK, "IOleWindow_QueryInterface: 0x%08lx\n", hres);
2247 refcount1 = get_refcount((IUnknown *)olePlace1);
2248 refcount2 = get_refcount((IUnknown *)oleWin);
2249 ok(refcount1 == refcount2, "got wrong ref count.\n");
2250
2251 IOleInPlaceSite_Release(olePlace1);
2252 IOleInPlaceSite_Release(olePlace);
2253 IOleWindow_Release(oleWin1);
2254 IOleWindow_Release(oleWin);
2255 IOleClientSite_Release(clientSite2);
2256 IOleClientSite_Release(clientSite1);
2257 IOleClientSite_Release(clientSite);
2258 release_interfaces(&w, &reOle, &txtDoc, NULL);
2259}
2260
2262{
2263 HWND w;
2264 IRichEditOle *reOle = NULL;
2265 ITextDocument *txtDoc = NULL;
2266 IOleClientSite *clientSite = NULL;
2267 IOleWindow *oleWin = NULL;
2268 HRESULT hres;
2269 HWND hwnd;
2270
2271 create_interfaces(&w, &reOle, &txtDoc, NULL);
2272 hres = IRichEditOle_GetClientSite(reOle, &clientSite);
2273 ok(hres == S_OK, "IRichEditOle_QueryInterface: 0x%08lx\n", hres);
2274
2275 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleWindow, (void **)&oleWin);
2276 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2277 hres = IOleWindow_GetWindow(oleWin, &hwnd);
2278 ok(hres == S_OK, "IOleClientSite_GetWindow: 0x%08lx\n", hres);
2279 ok(w == hwnd, "got wrong pointer\n");
2280
2281 hres = IOleWindow_GetWindow(oleWin, NULL);
2282 ok(hres == E_INVALIDARG, "IOleClientSite_GetWindow: 0x%08lx\n", hres);
2283
2284 IOleWindow_Release(oleWin);
2285 IOleClientSite_Release(clientSite);
2286 release_interfaces(&w, &reOle, &txtDoc, NULL);
2287}
2288
2290{
2291 HWND w;
2292 IRichEditOle *reOle = NULL;
2293 ITextDocument *txtDoc = NULL;
2294 IOleClientSite *clientSite = NULL;
2295 IOleInPlaceSite *olePlace = NULL;
2296 HRESULT hres;
2297 HWND hwnd;
2298
2299 create_interfaces(&w, &reOle, &txtDoc, NULL);
2300 hres = IRichEditOle_GetClientSite(reOle, &clientSite);
2301 ok(hres == S_OK, "IRichEditOle_QueryInterface: 0x%08lx\n", hres);
2302
2303 hres = IOleClientSite_QueryInterface(clientSite, &IID_IOleInPlaceSite, (void **)&olePlace);
2304 ok(hres == S_OK, "IOleClientSite_QueryInterface: 0x%08lx\n", hres);
2305 hres = IOleInPlaceSite_GetWindow(olePlace, &hwnd);
2306 ok(hres == S_OK, "IOleInPlaceSite_GetWindow: 0x%08lx\n", hres);
2307 ok(w == hwnd, "got wrong pointer.\n");
2308
2309 hres = IOleInPlaceSite_GetWindow(olePlace, NULL);
2310 ok(hres == E_INVALIDARG, "IOleInPlaceSite_GetWindow: 0x%08lx\n", hres);
2311
2312 IOleInPlaceSite_Release(olePlace);
2313 IOleClientSite_Release(clientSite);
2314 release_interfaces(&w, &reOle, &txtDoc, NULL);
2315}
2316
2317static void test_GetFont(void)
2318{
2319 static const CHAR test_text1[] = "TestSomeText";
2320 IRichEditOle *reOle = NULL;
2321 ITextDocument *doc = NULL;
2324 ITextFont *font, *font2;
2326 LONG value;
2327 float size;
2328 HRESULT hr;
2329 HWND hwnd;
2330 BOOL ret;
2331
2332 create_interfaces(&hwnd, &reOle, &doc, NULL);
2333 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
2334
2335 hr = ITextDocument_GetSelection(doc, &selection);
2336 ok(hr == S_OK, "got 0x%08lx\n", hr);
2337 hr = ITextSelection_GetFont(selection, &font);
2338 ok(hr == S_OK, "got 0x%08lx\n", hr);
2339 hr = ITextSelection_GetFont(selection, &font2);
2340 ok(hr == S_OK, "got 0x%08lx\n", hr);
2341 ok(font != font2, "got %p, %p\n", font, font2);
2342 ITextFont_Release(font2);
2343 ITextFont_Release(font);
2344 ITextSelection_Release(selection);
2345
2346 EXPECT_REF(reOle, 3);
2347 EXPECT_REF(doc, 3);
2348
2349 hr = ITextDocument_Range(doc, 0, 4, &range);
2350 ok(hr == S_OK, "got 0x%08lx\n", hr);
2351
2352 EXPECT_REF(reOle, 3);
2353 EXPECT_REF(doc, 3);
2354 EXPECT_REF(range, 1);
2355
2356 hr = ITextRange_GetFont(range, NULL);
2357 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2358
2359 hr = ITextRange_GetFont(range, &font);
2360 ok(hr == S_OK, "got 0x%08lx\n", hr);
2361
2362 EXPECT_REF(reOle, 3);
2363 EXPECT_REF(doc, 3);
2364 EXPECT_REF(range, 2);
2365 EXPECT_REF(font, 1);
2366
2367 hr = ITextRange_GetFont(range, &font2);
2368 ok(hr == S_OK, "got 0x%08lx\n", hr);
2369 ok(font != font2, "got %p, %p\n", font, font2);
2370
2371 EXPECT_REF(reOle, 3);
2372 EXPECT_REF(doc, 3);
2373 EXPECT_REF(range, 3);
2374 EXPECT_REF(font, 1);
2375 EXPECT_REF(font2, 1);
2376
2377 ITextFont_Release(font2);
2378
2379 /* set different font style within a range */
2380 hr = ITextFont_GetItalic(font, NULL);
2381 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2382
2383 hr = ITextFont_GetSize(font, NULL);
2384 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2385
2386 size = 0.0;
2387 hr = ITextFont_GetSize(font, &size);
2388 ok(hr == S_OK, "got 0x%08lx\n", hr);
2389 ok(size > 0.0, "size %.2f\n", size);
2390
2391 value = 0;
2392 hr = ITextFont_GetLanguageID(font, &value);
2393 ok(hr == S_OK, "got 0x%08lx\n", hr);
2394 ok(value == GetSystemDefaultLCID(), "got lcid %lx, user lcid %lx\n", value,
2396
2397 /* range is non-italic */
2398 value = tomTrue;
2399 hr = ITextFont_GetItalic(font, &value);
2400 ok(hr == S_OK, "got 0x%08lx\n", hr);
2401 ok(value == tomFalse, "got %ld\n", value);
2402
2403 cf.cbSize = sizeof(CHARFORMAT2A);
2404 cf.dwMask = CFM_ITALIC|CFM_SIZE;
2405 cf.dwEffects = CFE_ITALIC;
2406 cf.yHeight = 24.0;
2407
2408 SendMessageA(hwnd, EM_SETSEL, 2, 3);
2410 ok(ret, "got %d\n", ret);
2411
2412 /* now range is partially italicized */
2413 value = tomFalse;
2414 hr = ITextFont_GetItalic(font, &value);
2415 ok(hr == S_OK, "got 0x%08lx\n", hr);
2416 ok(value == tomUndefined, "got %ld\n", value);
2417
2418 size = 0.0;
2419 hr = ITextFont_GetSize(font, &size);
2420 ok(hr == S_OK, "got 0x%08lx\n", hr);
2421 ok(size == tomUndefined, "size %.2f\n", size);
2422
2423 ITextFont_Release(font);
2424 release_interfaces(&hwnd, &reOle, &doc, NULL);
2425
2426 hr = ITextRange_GetFont(range, NULL);
2427 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2428
2429 hr = ITextRange_GetFont(range, &font2);
2430 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2431
2432 ITextRange_Release(range);
2433}
2434
2435static void test_GetPara(void)
2436{
2437 static const CHAR test_text1[] = "TestSomeText";
2438 IRichEditOle *reOle = NULL;
2439 ITextDocument *doc = NULL;
2442 ITextPara *para, *para2;
2443 HRESULT hr;
2444 HWND hwnd;
2445
2446 create_interfaces(&hwnd, &reOle, &doc, &selection);
2447 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
2448
2449 EXPECT_REF(reOle, 3);
2450 EXPECT_REF(doc, 3);
2451
2452 hr = ITextDocument_Range(doc, 0, 4, &range);
2453 ok(hr == S_OK, "got 0x%08lx\n", hr);
2454
2455 EXPECT_REF(reOle, 3);
2456 EXPECT_REF(doc, 3);
2457 EXPECT_REF(range, 1);
2458
2459 hr = ITextRange_GetPara(range, NULL);
2460 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2461
2462 hr = ITextRange_GetPara(range, &para);
2463 ok(hr == S_OK, "got 0x%08lx\n", hr);
2464
2465 EXPECT_REF(reOle, 3);
2466 EXPECT_REF(doc, 3);
2467 EXPECT_REF(range, 2);
2468 EXPECT_REF(para, 1);
2469
2470 hr = ITextRange_GetPara(range, &para2);
2471 ok(hr == S_OK, "got 0x%08lx\n", hr);
2472 ok(para != para2, "got %p, %p\n", para, para2);
2473
2474 EXPECT_REF(reOle, 3);
2475 EXPECT_REF(doc, 3);
2476 EXPECT_REF(range, 3);
2477 EXPECT_REF(para, 1);
2478 EXPECT_REF(para2, 1);
2479
2480 ITextPara_Release(para);
2481 ITextPara_Release(para2);
2482
2483 EXPECT_REF(reOle, 3);
2484 EXPECT_REF(doc, 3);
2486
2487 hr = ITextSelection_GetPara(selection, &para);
2488 ok(hr == S_OK, "got 0x%08lx\n", hr);
2489
2490 EXPECT_REF(reOle, 3);
2491 EXPECT_REF(doc, 3);
2493 EXPECT_REF(para, 1);
2494
2495 hr = ITextSelection_GetPara(selection, &para2);
2496 ok(hr == S_OK, "got 0x%08lx\n", hr);
2497 ok(para != para2, "got %p, %p\n", para, para2);
2498
2499 ITextPara_Release(para);
2500 ITextPara_Release(para2);
2501 release_interfaces(&hwnd, &reOle, &doc, NULL);
2502
2503 hr = ITextRange_GetPara(range, NULL);
2504 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2505
2506 hr = ITextRange_GetPara(range, &para);
2507 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2508
2509 hr = ITextSelection_GetPara(selection, NULL);
2510 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2511
2512 hr = ITextSelection_GetPara(selection, &para);
2513 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
2514
2515 ITextSelection_Release(selection);
2516 ITextRange_Release(range);
2517}
2518
2519static void test_dispatch(void)
2520{
2521 static const WCHAR testnameW[] = {'G','e','t','T','e','x','t',0};
2522 static const WCHAR testname2W[] = {'T','e','x','t',0};
2523 IRichEditOle *reOle = NULL;
2524 ITextDocument *doc = NULL;
2526 WCHAR *nameW;
2527 DISPID dispid;
2528 HRESULT hr;
2529 UINT count;
2530 HWND hwnd;
2531
2532 create_interfaces(&hwnd, &reOle, &doc, NULL);
2533
2534 range = NULL;
2535 hr = ITextDocument_Range(doc, 0, 0, &range);
2536 ok(hr == S_OK, "got 0x%08lx\n", hr);
2537 ok(range != NULL, "got %p\n", range);
2538
2539 dispid = 123;
2540 nameW = (WCHAR*)testnameW;
2541 hr = ITextRange_GetIDsOfNames(range, &IID_NULL, &nameW, 1, LOCALE_USER_DEFAULT, &dispid);
2542 ok(hr == DISP_E_UNKNOWNNAME, "got 0x%08lx\n", hr);
2543 ok(dispid == DISPID_UNKNOWN, "got %ld\n", dispid);
2544
2545 dispid = 123;
2546 nameW = (WCHAR*)testname2W;
2547 hr = ITextRange_GetIDsOfNames(range, &IID_NULL, &nameW, 1, LOCALE_USER_DEFAULT, &dispid);
2548 ok(hr == S_OK, "got 0x%08lx\n", hr);
2549 ok(dispid == DISPID_VALUE, "got %ld\n", dispid);
2550
2551 release_interfaces(&hwnd, &reOle, &doc, NULL);
2552
2553 /* try dispatch methods on detached range */
2554 hr = ITextRange_GetTypeInfoCount(range, &count);
2555 ok(hr == S_OK, "got 0x%08lx\n", hr);
2556
2557 dispid = 123;
2558 nameW = (WCHAR*)testname2W;
2559 hr = ITextRange_GetIDsOfNames(range, &IID_NULL, &nameW, 1, LOCALE_USER_DEFAULT, &dispid);
2560 ok(hr == S_OK, "got 0x%08lx\n", hr);
2561 ok(dispid == DISPID_VALUE, "got %ld\n", dispid);
2562
2563 ITextRange_Release(range);
2564}
2565
2567{
2568 HRESULT hr, hrexp = duplicate ? S_OK : CO_E_RELEASED;
2569 LONG value;
2570 float size;
2571 BSTR str;
2572
2573 hr = ITextFont_GetBold(font, NULL);
2574 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2575
2576 hr = ITextFont_GetBold(font, &value);
2577 ok(hr == hrexp, "got 0x%08lx\n", hr);
2578
2579 hr = ITextFont_GetForeColor(font, NULL);
2580 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2581
2582 hr = ITextFont_GetForeColor(font, &value);
2583 ok(hr == hrexp, "got 0x%08lx\n", hr);
2584
2585 hr = ITextFont_GetItalic(font, NULL);
2586 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2587
2588 hr = ITextFont_GetItalic(font, &value);
2589 ok(hr == hrexp, "got 0x%08lx\n", hr);
2590
2591 hr = ITextFont_GetLanguageID(font, NULL);
2592 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2593
2594 hr = ITextFont_GetLanguageID(font, &value);
2595 ok(hr == hrexp, "got 0x%08lx\n", hr);
2596
2597 hr = ITextFont_GetName(font, NULL);
2598 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2599
2600 hr = ITextFont_GetName(font, &str);
2601 ok(hr == hrexp, "got 0x%08lx\n", hr);
2602
2603 hr = ITextFont_GetSize(font, NULL);
2604 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2605
2606 hr = ITextFont_GetSize(font, &size);
2607 ok(hr == hrexp, "got 0x%08lx\n", hr);
2608
2609 hr = ITextFont_GetStrikeThrough(font, NULL);
2610 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2611
2612 hr = ITextFont_GetStrikeThrough(font, &value);
2613 ok(hr == hrexp, "got 0x%08lx\n", hr);
2614
2615 hr = ITextFont_GetSubscript(font, NULL);
2616 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2617
2618 hr = ITextFont_GetSubscript(font, &value);
2619 ok(hr == hrexp, "got 0x%08lx\n", hr);
2620
2621 hr = ITextFont_GetSuperscript(font, NULL);
2622 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2623
2624 hr = ITextFont_GetSuperscript(font, &value);
2625 ok(hr == hrexp, "got 0x%08lx\n", hr);
2626
2627 hr = ITextFont_GetUnderline(font, NULL);
2628 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2629
2630 hr = ITextFont_GetUnderline(font, &value);
2631 ok(hr == hrexp, "got 0x%08lx\n", hr);
2632}
2633
2635{
2636 float valuef;
2637 LONG value;
2638 HRESULT hr;
2639 BSTR str;
2640
2642 hr = ITextFont_GetAllCaps(font, &value);
2643 ok(hr == S_OK, "got 0x%08lx\n", hr);
2644 ok(value == tomFalse, "got %ld\n", value);
2645
2647 hr = ITextFont_GetAnimation(font, &value);
2648 ok(hr == S_OK, "got 0x%08lx\n", hr);
2649 ok(value == tomFalse, "got %ld\n", value);
2650
2652 hr = ITextFont_GetBackColor(font, &value);
2653 ok(hr == S_OK, "got 0x%08lx\n", hr);
2654 ok(value == tomAutoColor, "got %ld\n", value);
2655
2657 hr = ITextFont_GetBold(font, &value);
2658 ok(hr == S_OK, "got 0x%08lx\n", hr);
2659 ok(value == tomFalse || value == tomTrue, "got %ld\n", value);
2660
2662 hr = ITextFont_GetEmboss(font, &value);
2663 ok(hr == S_OK, "got 0x%08lx\n", hr);
2664 ok(value == tomFalse, "got %ld\n", value);
2665
2667 hr = ITextFont_GetForeColor(font, &value);
2668 ok(hr == S_OK, "got 0x%08lx\n", hr);
2669 ok(value == tomAutoColor, "got %ld\n", value);
2670
2672 hr = ITextFont_GetHidden(font, &value);
2673 ok(hr == S_OK, "got 0x%08lx\n", hr);
2674 ok(value == tomFalse, "got %ld\n", value);
2675
2677 hr = ITextFont_GetEngrave(font, &value);
2678 ok(hr == S_OK, "got 0x%08lx\n", hr);
2679 ok(value == tomFalse, "got %ld\n", value);
2680
2682 hr = ITextFont_GetItalic(font, &value);
2683 ok(hr == S_OK, "got 0x%08lx\n", hr);
2684 ok(value == tomFalse, "got %ld\n", value);
2685
2686 valuef = 1.0;
2687 hr = ITextFont_GetKerning(font, &valuef);
2688 ok(hr == S_OK, "got 0x%08lx\n", hr);
2689 ok(valuef == 0.0, "got %.2f\n", valuef);
2690
2692 hr = ITextFont_GetLanguageID(font, &value);
2693 ok(hr == S_OK, "got 0x%08lx\n", hr);
2694 ok(value == GetSystemDefaultLCID(), "got %ld\n", value);
2695
2696 str = NULL;
2697 hr = ITextFont_GetName(font, &str);
2698 ok(hr == S_OK, "got 0x%08lx\n", hr);
2699 ok(!lstrcmpW(sysW, str), "%s\n", wine_dbgstr_w(str));
2701
2703 hr = ITextFont_GetOutline(font, &value);
2704 ok(hr == S_OK, "got 0x%08lx\n", hr);
2705 ok(value == tomFalse, "got %ld\n", value);
2706
2707 valuef = 1.0;
2708 hr = ITextFont_GetPosition(font, &valuef);
2709 ok(hr == S_OK, "got 0x%08lx\n", hr);
2710 ok(valuef == 0.0, "got %.2f\n", valuef);
2711
2713 hr = ITextFont_GetProtected(font, &value);
2714 ok(hr == S_OK, "got 0x%08lx\n", hr);
2715 ok(value == tomFalse, "got %ld\n", value);
2716
2718 hr = ITextFont_GetShadow(font, &value);
2719 ok(hr == S_OK, "got 0x%08lx\n", hr);
2720 ok(value == tomFalse, "got %ld\n", value);
2721
2722 valuef = 0.0;
2723 hr = ITextFont_GetSize(font, &valuef);
2724 ok(hr == S_OK, "got 0x%08lx\n", hr);
2725 ok(valuef >= 0.0, "got %.2f\n", valuef);
2726
2728 hr = ITextFont_GetSmallCaps(font, &value);
2729 ok(hr == S_OK, "got 0x%08lx\n", hr);
2730 ok(value == tomFalse, "got %ld\n", value);
2731
2732 valuef = 1.0;
2733 hr = ITextFont_GetSpacing(font, &valuef);
2734 ok(hr == S_OK, "got 0x%08lx\n", hr);
2735 ok(valuef == 0.0, "got %.2f\n", valuef);
2736
2738 hr = ITextFont_GetStrikeThrough(font, &value);
2739 ok(hr == S_OK, "got 0x%08lx\n", hr);
2740 ok(value == tomFalse, "got %ld\n", value);
2741
2743 hr = ITextFont_GetSubscript(font, &value);
2744 ok(hr == S_OK, "got 0x%08lx\n", hr);
2745 ok(value == tomFalse, "got %ld\n", value);
2746
2748 hr = ITextFont_GetSuperscript(font, &value);
2749 ok(hr == S_OK, "got 0x%08lx\n", hr);
2750 ok(value == tomFalse, "got %ld\n", value);
2751
2753 hr = ITextFont_GetUnderline(font, &value);
2754 ok(hr == S_OK, "got 0x%08lx\n", hr);
2755 ok(value == tomFalse, "got %ld\n", value);
2756
2758 hr = ITextFont_GetWeight(font, &value);
2759 ok(hr == S_OK, "got 0x%08lx\n", hr);
2760 ok(value == FW_NORMAL || value == FW_BOLD, "got %ld\n", value);
2761}
2762
2764{
2765 float valuef;
2766 LONG value;
2767 HRESULT hr;
2768
2769 value = tomFalse;
2770 hr = ITextFont_GetAllCaps(font, &value);
2771 ok(hr == S_OK, "got 0x%08lx\n", hr);
2772 ok(value == tomUndefined, "got %ld\n", value);
2773
2774 value = tomFalse;
2775 hr = ITextFont_GetAnimation(font, &value);
2776 ok(hr == S_OK, "got 0x%08lx\n", hr);
2777 ok(value == tomUndefined, "got %ld\n", value);
2778
2779 value = tomFalse;
2780 hr = ITextFont_GetBackColor(font, &value);
2781 ok(hr == S_OK, "got 0x%08lx\n", hr);
2782 ok(value == tomUndefined, "got %ld\n", value);
2783
2784 value = tomFalse;
2785 hr = ITextFont_GetBold(font, &value);
2786 ok(hr == S_OK, "got 0x%08lx\n", hr);
2787 ok(value == tomUndefined, "got %ld\n", value);
2788
2789 value = tomFalse;
2790 hr = ITextFont_GetEmboss(font, &value);
2791 ok(hr == S_OK, "got 0x%08lx\n", hr);
2792 ok(value == tomUndefined, "got %ld\n", value);
2793
2794 value = tomFalse;
2795 hr = ITextFont_GetForeColor(font, &value);
2796 ok(hr == S_OK, "got 0x%08lx\n", hr);
2797 ok(value == tomUndefined, "got %ld\n", value);
2798
2799 value = tomFalse;
2800 hr = ITextFont_GetHidden(font, &value);
2801 ok(hr == S_OK, "got 0x%08lx\n", hr);
2802 ok(value == tomUndefined, "got %ld\n", value);
2803
2804 value = tomFalse;
2805 hr = ITextFont_GetEngrave(font, &value);
2806 ok(hr == S_OK, "got 0x%08lx\n", hr);
2807 ok(value == tomUndefined, "got %ld\n", value);
2808
2809 value = tomFalse;
2810 hr = ITextFont_GetItalic(font, &value);
2811 ok(hr == S_OK, "got 0x%08lx\n", hr);
2812 ok(value == tomUndefined, "got %ld\n", value);
2813
2814 valuef = 0.0;
2815 hr = ITextFont_GetKerning(font, &valuef);
2816 ok(hr == S_OK, "got 0x%08lx\n", hr);
2817 ok(valuef == tomUndefined, "got %.2f\n", valuef);
2818
2819 value = tomFalse;
2820 hr = ITextFont_GetLanguageID(font, &value);
2821 ok(hr == S_OK, "got 0x%08lx\n", hr);
2822 ok(value == tomUndefined, "got %ld\n", value);
2823
2824 value = tomFalse;
2825 hr = ITextFont_GetOutline(font, &value);
2826 ok(hr == S_OK, "got 0x%08lx\n", hr);
2827 ok(value == tomUndefined, "got %ld\n", value);
2828
2829 valuef = 0.0;
2830 hr = ITextFont_GetPosition(font, &valuef);
2831 ok(hr == S_OK, "got 0x%08lx\n", hr);
2832 ok(valuef == tomUndefined, "got %.2f\n", valuef);
2833
2834 value = tomFalse;
2835 hr = ITextFont_GetProtected(font, &value);
2836 ok(hr == S_OK, "got 0x%08lx\n", hr);
2837 ok(value == tomUndefined, "got %ld\n", value);
2838
2839 value = tomFalse;
2840 hr = ITextFont_GetShadow(font, &value);
2841 ok(hr == S_OK, "got 0x%08lx\n", hr);
2842 ok(value == tomUndefined, "got %ld\n", value);
2843
2844 valuef = 0.0;
2845 hr = ITextFont_GetSize(font, &valuef);
2846 ok(hr == S_OK, "got 0x%08lx\n", hr);
2847 ok(valuef == tomUndefined, "got %.2f\n", valuef);
2848
2849 value = tomFalse;
2850 hr = ITextFont_GetSmallCaps(font, &value);
2851 ok(hr == S_OK, "got 0x%08lx\n", hr);
2852 ok(value == tomUndefined, "got %ld\n", value);
2853
2854 valuef = 0.0;
2855 hr = ITextFont_GetSpacing(font, &valuef);
2856 ok(hr == S_OK, "got 0x%08lx\n", hr);
2857 ok(valuef == tomUndefined, "got %.2f\n", valuef);
2858
2859 value = tomFalse;
2860 hr = ITextFont_GetStrikeThrough(font, &value);
2861 ok(hr == S_OK, "got 0x%08lx\n", hr);
2862 ok(value == tomUndefined, "got %ld\n", value);
2863
2864 value = tomFalse;
2865 hr = ITextFont_GetSubscript(font, &value);
2866 ok(hr == S_OK, "got 0x%08lx\n", hr);
2867 ok(value == tomUndefined, "got %ld\n", value);
2868
2869 value = tomFalse;
2870 hr = ITextFont_GetSuperscript(font, &value);
2871 ok(hr == S_OK, "got 0x%08lx\n", hr);
2872 ok(value == tomUndefined, "got %ld\n", value);
2873
2874 value = tomFalse;
2875 hr = ITextFont_GetUnderline(font, &value);
2876 ok(hr == S_OK, "got 0x%08lx\n", hr);
2877 ok(value == tomUndefined, "got %ld\n", value);
2878
2879 value = tomFalse;
2880 hr = ITextFont_GetWeight(font, &value);
2881 ok(hr == S_OK, "got 0x%08lx\n", hr);
2882 ok(value == tomUndefined, "got %ld\n", value);
2883}
2884
2886{
2887 return value * 72.0 / 1440;
2888}
2889
2890static void test_ITextFont(void)
2891{
2892 static const WCHAR arialW[] = {'A','r','i','a','l',0};
2893 static const CHAR test_text1[] = "TestSomeText";
2894 ITextFont *font, *font2, *font3;
2895 FLOAT size, position, kerning;
2896 IRichEditOle *reOle = NULL;
2897 ITextDocument *doc = NULL;
2900 LONG value;
2901 HRESULT hr;
2902 HWND hwnd;
2903 BOOL ret;
2904 BSTR str;
2905
2906 create_interfaces(&hwnd, &reOle, &doc, NULL);
2907 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
2908
2909 hr = ITextDocument_Range(doc, 0, 10, &range);
2910 ok(hr == S_OK, "got 0x%08lx\n", hr);
2911
2912 hr = ITextRange_GetFont(range, &font);
2913 ok(hr == S_OK, "got 0x%08lx\n", hr);
2914
2915 hr = ITextFont_Reset(font, tomUseTwips);
2916 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2917
2918 hr = ITextFont_Reset(font, tomUsePoints);
2919 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2920
2921 hr = ITextFont_GetName(font, NULL);
2922 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2923
2924 /* default font size unit is point */
2925 size = 0.0;
2926 hr = ITextFont_GetSize(font, &size);
2927 ok(hr == S_OK, "got 0x%08lx\n", hr);
2928
2929 /* set to some non-zero values */
2930 hr = ITextFont_SetPosition(font, 20.0);
2931 ok(hr == S_OK, "got 0x%08lx\n", hr);
2932
2933 hr = ITextFont_SetKerning(font, 10.0);
2934 ok(hr == S_OK, "got 0x%08lx\n", hr);
2935
2936 position = 0.0;
2937 hr = ITextFont_GetPosition(font, &position);
2938 ok(hr == S_OK, "got 0x%08lx\n", hr);
2939
2940 kerning = 0.0;
2941 hr = ITextFont_GetKerning(font, &kerning);
2942 ok(hr == S_OK, "got 0x%08lx\n", hr);
2943
2944 memset(&cf, 0, sizeof(cf));
2945 cf.cbSize = sizeof(cf);
2947
2948 /* CHARFORMAT members are in twips */
2949 SendMessageA(hwnd, EM_SETSEL, 0, 10);
2951 ok(ret, "got %d\n", ret);
2952 ok(size == twips_to_points(cf.yHeight), "got yHeight %ld, size %.2f\n", cf.yHeight, size);
2953 ok(position == twips_to_points(cf.yOffset), "got yOffset %ld, position %.2f\n", cf.yOffset, position);
2954 ok(kerning == twips_to_points(cf.wKerning), "got wKerning %d, kerning %.2f\n", cf.wKerning, kerning);
2955
2956 hr = ITextFont_Reset(font, tomUseTwips);
2957 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2958
2959 hr = ITextFont_Reset(font, tomUsePoints);
2960 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2961
2962 hr = ITextFont_GetDuplicate(font, &font2);
2963 ok(hr == S_OK, "got 0x%08lx\n", hr);
2964
2965 hr = ITextFont_Reset(font2, tomUseTwips);
2966 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2967
2968 hr = ITextFont_Reset(font2, tomUsePoints);
2969 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
2970
2971 ITextFont_Release(font2);
2972
2973 /* default font name */
2974 str = NULL;
2975 hr = ITextFont_GetName(font, &str);
2976 ok(hr == S_OK, "got 0x%08lx\n", hr);
2977 ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
2979
2980 /* change font name for an inner subrange */
2981 memset(&cf, 0, sizeof(cf));
2982 cf.cbSize = sizeof(cf);
2983 cf.dwMask = CFM_FACE;
2984 strcpy(cf.szFaceName, "Arial");
2985
2986 SendMessageA(hwnd, EM_SETSEL, 3, 4);
2988 ok(ret, "got %d\n", ret);
2989
2990 /* still original name */
2991 str = NULL;
2992 hr = ITextFont_GetName(font, &str);
2993 ok(hr == S_OK, "got 0x%08lx\n", hr);
2994 ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
2996
2997 SendMessageA(hwnd, EM_SETSEL, 1, 2);
2999 ok(ret, "got %d\n", ret);
3000
3001 str = NULL;
3002 hr = ITextFont_GetName(font, &str);
3003 ok(hr == S_OK, "got 0x%08lx\n", hr);
3004 ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
3006
3007 /* name is returned for first position within a range */
3008 SendMessageA(hwnd, EM_SETSEL, 0, 1);
3010 ok(ret, "got %d\n", ret);
3011
3012 str = NULL;
3013 hr = ITextFont_GetName(font, &str);
3014 ok(hr == S_OK, "got 0x%08lx\n", hr);
3015 ok(!lstrcmpW(str, arialW), "got %s\n", wine_dbgstr_w(str));
3017
3018 /* GetDuplicate() */
3019 hr = ITextFont_GetDuplicate(font, NULL);
3020 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3021
3022 EXPECT_REF(range, 2);
3023 font2 = NULL;
3024 hr = ITextFont_GetDuplicate(font, &font2);
3025 ok(hr == S_OK, "got 0x%08lx\n", hr);
3026 EXPECT_REF(range, 2);
3027
3028 /* set whole range to italic */
3029 cf.cbSize = sizeof(CHARFORMAT2A);
3030 cf.dwMask = CFM_ITALIC;
3031 cf.dwEffects = CFE_ITALIC;
3032
3033 SendMessageA(hwnd, EM_SETSEL, 0, 10);
3035 ok(ret, "got %d\n", ret);
3036
3037 value = tomFalse;
3038 hr = ITextFont_GetItalic(font, &value);
3039 ok(hr == S_OK, "got 0x%08lx\n", hr);
3040 ok(value == tomTrue, "got %ld\n", value);
3041
3042 /* duplicate retains original value */
3043 value = tomTrue;
3044 hr = ITextFont_GetItalic(font2, &value);
3045 ok(hr == S_OK, "got 0x%08lx\n", hr);
3046 ok(value == tomFalse, "got %ld\n", value);
3047
3048 /* get a duplicate from a cloned font */
3049 hr = ITextFont_GetDuplicate(font2, &font3);
3050 ok(hr == S_OK, "got 0x%08lx\n", hr);
3051 ITextFont_Release(font3);
3052
3053 ITextRange_Release(range);
3054 release_interfaces(&hwnd, &reOle, &doc, NULL);
3055
3056 hr = ITextFont_GetDuplicate(font, NULL);
3057 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3058
3061
3062 /* get a duplicate of detached font */
3063 hr = ITextFont_GetDuplicate(font2, &font3);
3064 ok(hr == S_OK, "got 0x%08lx\n", hr);
3065 ITextFont_Release(font3);
3066
3067 /* reset detached font to undefined */
3069 hr = ITextFont_GetBold(font2, &value);
3070 ok(hr == S_OK, "got 0x%08lx\n", hr);
3071 ok(value != tomUndefined, "got %ld\n", value);
3072
3073 /* reset to undefined for detached font */
3074 hr = ITextFont_Reset(font2, tomUndefined);
3075 ok(hr == S_OK, "got 0x%08lx\n", hr);
3077
3078 /* font is detached, default means global TOM defaults */
3079 hr = ITextFont_Reset(font2, tomDefault);
3080 ok(hr == S_OK, "got 0x%08lx\n", hr);
3082
3083 hr = ITextFont_GetDuplicate(font2, &font3);
3084 ok(hr == S_OK, "got 0x%08lx\n", hr);
3086
3087 hr = ITextFont_Reset(font2, tomApplyNow);
3088 ok(hr == S_OK, "got 0x%08lx\n", hr);
3090
3091 hr = ITextFont_Reset(font2, tomApplyLater);
3092 ok(hr == S_OK, "got 0x%08lx\n", hr);
3094
3095 hr = ITextFont_Reset(font2, tomTrackParms);
3096 ok(hr == S_OK, "got 0x%08lx\n", hr);
3098
3099 hr = ITextFont_SetItalic(font2, tomUndefined);
3100 ok(hr == S_OK, "got 0x%08lx\n", hr);
3101
3102 hr = ITextFont_GetItalic(font2, &value);
3103 ok(hr == S_OK, "got 0x%08lx\n", hr);
3104 ok(value == tomFalse, "got %ld\n", value);
3105
3106 hr = ITextFont_Reset(font2, tomCacheParms);
3107 ok(hr == S_OK, "got 0x%08lx\n", hr);
3109
3110 ITextFont_Release(font3);
3111 ITextFont_Release(font2);
3112
3113 font2 = (void*)0xdeadbeef;
3114 hr = ITextFont_GetDuplicate(font, &font2);
3115 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3116 ok(font2 == NULL, "got %p\n", font2);
3117
3118 hr = ITextFont_Reset(font, tomDefault);
3119 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3120
3121 ITextFont_Release(font);
3122
3123 /* Reset() */
3124 create_interfaces(&hwnd, &reOle, &doc, NULL);
3125 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3126
3127 hr = ITextDocument_Range(doc, 0, 10, &range);
3128 ok(hr == S_OK, "got 0x%08lx\n", hr);
3129
3130 hr = ITextRange_GetFont(range, &font);
3131 ok(hr == S_OK, "got 0x%08lx\n", hr);
3132
3134 hr = ITextFont_GetBold(font, &value);
3135 ok(hr == S_OK, "got 0x%08lx\n", hr);
3136 ok(value != tomUndefined, "got %ld\n", value);
3137
3138 /* reset to undefined for attached font */
3139 hr = ITextFont_Reset(font, tomUndefined);
3140 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3141
3143 hr = ITextFont_GetBold(font, &value);
3144 ok(hr == S_OK, "got 0x%08lx\n", hr);
3145 ok(value != tomUndefined, "got %ld\n", value);
3146
3147 /* tomCacheParms/tomTrackParms */
3148 hr = ITextFont_Reset(font, tomCacheParms);
3149 ok(hr == S_OK, "got 0x%08lx\n", hr);
3150
3151 hr = ITextFont_GetItalic(font, &value);
3152 ok(hr == S_OK, "got 0x%08lx\n", hr);
3153 ok(value == tomFalse, "got %ld\n", value);
3154
3155 memset(&cf, 0, sizeof(cf));
3156 cf.cbSize = sizeof(CHARFORMAT2A);
3157 cf.dwMask = CFM_ITALIC;
3158
3159 cf.dwEffects = CFE_ITALIC;
3160 SendMessageA(hwnd, EM_SETSEL, 0, 10);
3162 ok(ret, "got %d\n", ret);
3163
3164 /* still cached value */
3165 hr = ITextFont_GetItalic(font, &value);
3166 ok(hr == S_OK, "got 0x%08lx\n", hr);
3167 ok(value == tomFalse, "got %ld\n", value);
3168
3169 hr = ITextFont_Reset(font, tomTrackParms);
3170 ok(hr == S_OK, "got 0x%08lx\n", hr);
3171
3172 hr = ITextFont_GetItalic(font, &value);
3173 ok(hr == S_OK, "got 0x%08lx\n", hr);
3174 ok(value == tomTrue, "got %ld\n", value);
3175
3176 /* switch back to cache - value retained */
3177 hr = ITextFont_Reset(font, tomCacheParms);
3178 ok(hr == S_OK, "got 0x%08lx\n", hr);
3179
3180 hr = ITextFont_GetItalic(font, &value);
3181 ok(hr == S_OK, "got 0x%08lx\n", hr);
3182 ok(value == tomTrue, "got %ld\n", value);
3183
3184 /* tomApplyLater */
3185 hr = ITextFont_Reset(font, tomApplyLater);
3186 ok(hr == S_OK, "got 0x%08lx\n", hr);
3187
3188 hr = ITextFont_SetItalic(font, tomFalse);
3189 ok(hr == S_OK, "got 0x%08lx\n", hr);
3190
3191 hr = ITextFont_GetItalic(font, &value);
3192 ok(hr == S_OK, "got 0x%08lx\n", hr);
3193 ok(value == tomFalse, "got %ld\n", value);
3194
3195 cf.dwEffects = 0;
3196 SendMessageA(hwnd, EM_SETSEL, 0, 10);
3198 ok(ret, "got %d\n", ret);
3199 ok((cf.dwEffects & CFE_ITALIC) == CFE_ITALIC, "got 0x%08lx\n", cf.dwEffects);
3200
3201 hr = ITextFont_Reset(font, tomApplyNow);
3202 ok(hr == S_OK, "got 0x%08lx\n", hr);
3203
3204 cf.dwEffects = 0;
3205 SendMessageA(hwnd, EM_SETSEL, 0, 10);
3207 ok(ret, "got %d\n", ret);
3208 ok((cf.dwEffects & CFE_ITALIC) == 0, "got 0x%08lx\n", cf.dwEffects);
3209
3210 hr = ITextFont_SetItalic(font, tomUndefined);
3211 ok(hr == S_OK, "got 0x%08lx\n", hr);
3212
3213 hr = ITextFont_GetItalic(font, &value);
3214 ok(hr == S_OK, "got 0x%08lx\n", hr);
3215 ok(value == tomFalse, "got %ld\n", value);
3216
3217 hr = ITextFont_SetItalic(font, tomAutoColor);
3218 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3219
3220 cf.dwEffects = 0;
3221 SendMessageA(hwnd, EM_SETSEL, 0, 10);
3223 ok(ret, "got %d\n", ret);
3224 ok((cf.dwEffects & CFE_ITALIC) == 0, "got 0x%08lx\n", cf.dwEffects);
3225
3226 ITextRange_Release(range);
3227 ITextFont_Release(font);
3228 release_interfaces(&hwnd, &reOle, &doc, NULL);
3229}
3230
3231static void test_Delete(void)
3232{
3233 static const CHAR test_text1[] = "TestSomeText";
3234 IRichEditOle *reOle = NULL;
3235 ITextDocument *doc = NULL;
3236 ITextRange *range, *range2;
3237 LONG value;
3238 HRESULT hr;
3239 HWND hwnd;
3240
3241 create_interfaces(&hwnd, &reOle, &doc, NULL);
3242 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3243
3244 hr = ITextDocument_Range(doc, 0, 4, &range);
3245 ok(hr == S_OK, "got 0x%08lx\n", hr);
3246
3247 hr = ITextDocument_Range(doc, 1, 2, &range2);
3248 ok(hr == S_OK, "got 0x%08lx\n", hr);
3249
3250 hr = ITextRange_GetEnd(range, &value);
3251 ok(hr == S_OK, "got 0x%08lx\n", hr);
3252 ok(value == 4, "got %ld\n", value);
3253
3254 /* unit type doesn't matter is count is 0 */
3255 value = 0;
3256 hr = ITextRange_Delete(range2, tomSentence, 0, &value);
3257todo_wine {
3258 ok(hr == S_OK, "got 0x%08lx\n", hr);
3259 ok(value == 1, "got %ld\n", value);
3260}
3261 value = 1;
3262 hr = ITextRange_Delete(range2, tomCharacter, 0, &value);
3263todo_wine {
3264 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3265 ok(value == 0, "got %ld\n", value);
3266}
3267 hr = ITextRange_GetEnd(range, &value);
3268 ok(hr == S_OK, "got 0x%08lx\n", hr);
3269 todo_wine
3270 ok(value == 3, "got %ld\n", value);
3271
3272 hr = ITextRange_GetStart(range2, &value);
3273 ok(hr == S_OK, "got 0x%08lx\n", hr);
3274 ok(value == 1, "got %ld\n", value);
3275
3276 hr = ITextRange_GetEnd(range2, &value);
3277 ok(hr == S_OK, "got 0x%08lx\n", hr);
3278 todo_wine
3279 ok(value == 1, "got %ld\n", value);
3280
3281 ITextRange_Release(range);
3282 ITextRange_Release(range2);
3283 release_interfaces(&hwnd, &reOle, &doc, NULL);
3284}
3285
3286static void test_SetText(void)
3287{
3288 static const CHAR test_text1[] = "TestSomeText";
3289 static const WCHAR textW[] = {'a','b','c','d','e','f','g','h','i',0};
3290 IRichEditOle *reOle = NULL;
3291 ITextDocument *doc = NULL;
3292 ITextRange *range, *range2;
3293 LONG value;
3294 HRESULT hr;
3295 HWND hwnd;
3296 BSTR str;
3297
3298 create_interfaces(&hwnd, &reOle, &doc, NULL);
3299 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3300
3301 hr = ITextDocument_Range(doc, 0, 4, &range);
3302 ok(hr == S_OK, "got 0x%08lx\n", hr);
3303
3304 hr = ITextDocument_Range(doc, 0, 4, &range2);
3305 ok(hr == S_OK, "got 0x%08lx\n", hr);
3306
3307 value = 1;
3308 hr = ITextRange_GetStart(range2, &value);
3309 ok(hr == S_OK, "got 0x%08lx\n", hr);
3310 ok(value == 0, "got %ld\n", value);
3311
3312 value = 0;
3313 hr = ITextRange_GetEnd(range2, &value);
3314 ok(hr == S_OK, "got 0x%08lx\n", hr);
3315 ok(value == 4, "got %ld\n", value);
3316
3317 hr = ITextRange_SetText(range, NULL);
3318 ok(hr == S_OK, "got 0x%08lx\n", hr);
3319
3320 value = 1;
3321 hr = ITextRange_GetEnd(range2, &value);
3322 ok(hr == S_OK, "got 0x%08lx\n", hr);
3323 ok(value == 0, "got %ld\n", value);
3324
3326 hr = ITextRange_SetText(range, str);
3327 ok(hr == S_OK, "got 0x%08lx\n", hr);
3329
3330 value = 1;
3331 hr = ITextRange_GetStart(range, &value);
3332 ok(hr == S_OK, "got 0x%08lx\n", hr);
3333 ok(value == 0, "got %ld\n", value);
3334
3335 value = 0;
3336 hr = ITextRange_GetEnd(range, &value);
3337 ok(hr == S_OK, "got 0x%08lx\n", hr);
3338 ok(value == 9, "got %ld\n", value);
3339
3340 value = 1;
3341 hr = ITextRange_GetStart(range2, &value);
3342 ok(hr == S_OK, "got 0x%08lx\n", hr);
3343 ok(value == 0, "got %ld\n", value);
3344
3345 value = 0;
3346 hr = ITextRange_GetEnd(range2, &value);
3347 ok(hr == S_OK, "got 0x%08lx\n", hr);
3348 ok(value == 0, "got %ld\n", value);
3349
3351 hr = ITextRange_SetText(range, str);
3352 ok(hr == S_OK, "got 0x%08lx\n", hr);
3353 value = 1;
3354 hr = ITextRange_GetEnd(range, &value);
3355 ok(hr == S_OK, "got 0x%08lx\n", hr);
3356 ok(value == 0, "got %ld\n", value);
3358
3359 ITextRange_Release(range2);
3360 release_interfaces(&hwnd, &reOle, &doc, NULL);
3361
3362 hr = ITextRange_SetText(range, NULL);
3363 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3364
3366 hr = ITextRange_SetText(range, str);
3367 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3369
3370 ITextRange_Release(range);
3371}
3372
3373static void test_InRange(void)
3374{
3375 static const CHAR test_text1[] = "TestSomeText";
3376 ITextRange *range, *range2, *range3;
3377 IRichEditOle *reOle = NULL;
3378 ITextDocument *doc = NULL;
3380 LONG value;
3381 HRESULT hr;
3382 HWND hwnd;
3383
3384 create_interfaces(&hwnd, &reOle, &doc, &selection);
3385 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3386 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3387
3388 hr = ITextDocument_Range(doc, 0, 4, &range);
3389 ok(hr == S_OK, "got 0x%08lx\n", hr);
3390
3391 hr = ITextDocument_Range(doc, 0, 4, &range2);
3392 ok(hr == S_OK, "got 0x%08lx\n", hr);
3393
3394 /* matches selection */
3395 hr = ITextDocument_Range(doc, 1, 2, &range3);
3396 ok(hr == S_OK, "got 0x%08lx\n", hr);
3397
3398 hr = ITextRange_InRange(range, NULL, NULL);
3399 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3400
3401 value = tomTrue;
3402 hr = ITextRange_InRange(range, NULL, &value);
3403 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3404 ok(value == tomFalse, "got %ld\n", value);
3405
3406 hr = ITextRange_InRange(range, range2, NULL);
3407 ok(hr == S_OK, "got 0x%08lx\n", hr);
3408
3409 value = tomFalse;
3410 hr = ITextRange_InRange(range, range2, &value);
3411 ok(hr == S_OK, "got 0x%08lx\n", hr);
3412 ok(value == tomTrue, "got %ld\n", value);
3413
3414 /* selection */
3415 hr = ITextSelection_InRange(selection, NULL, NULL);
3416 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3417
3418 value = tomTrue;
3419 hr = ITextSelection_InRange(selection, NULL, &value);
3420 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3421 ok(value == tomFalse, "got %ld\n", value);
3422
3423 hr = ITextSelection_InRange(selection, range2, NULL);
3424 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3425
3426 value = tomTrue;
3427 hr = ITextSelection_InRange(selection, range2, &value);
3428 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3429 ok(value == tomFalse, "got %ld\n", value);
3430
3431 value = tomTrue;
3432 hr = ITextSelection_InRange(selection, range3, &value);
3433 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3434 ok(value == tomFalse, "got %ld\n", value);
3435
3436 /* seems to work on ITextSelection ranges only */
3437 value = tomFalse;
3438 hr = ITextSelection_InRange(selection, (ITextRange*)selection, &value);
3439 ok(hr == S_OK, "got 0x%08lx\n", hr);
3440 ok(value == tomTrue, "got %ld\n", value);
3441
3442 release_interfaces(&hwnd, &reOle, &doc, NULL);
3443
3444 hr = ITextRange_InRange(range, NULL, NULL);
3445 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3446
3447 value = tomTrue;
3448 hr = ITextRange_InRange(range, NULL, &value);
3449 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3450 ok(value == tomFalse, "got %ld\n", value);
3451
3452 hr = ITextRange_InRange(range, range2, NULL);
3453 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3454
3455 value = tomTrue;
3456 hr = ITextRange_InRange(range, range2, &value);
3457 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3458 ok(value == tomFalse, "got %ld\n", value);
3459
3460 /* selection */
3461 hr = ITextSelection_InRange(selection, NULL, NULL);
3462 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3463
3464 value = tomTrue;
3465 hr = ITextSelection_InRange(selection, NULL, &value);
3466 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3467 ok(value == tomFalse, "got %ld\n", value);
3468
3469 hr = ITextSelection_InRange(selection, range2, NULL);
3470 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3471
3472 value = tomTrue;
3473 hr = ITextSelection_InRange(selection, range2, &value);
3474 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3475 ok(value == tomFalse, "got %ld\n", value);
3476
3477 ITextRange_Release(range);
3478 ITextRange_Release(range2);
3479 ITextRange_Release(range3);
3480 ITextSelection_Release(selection);
3481}
3482
3484{
3485 static const CHAR test_text1[] = "TestSomeText";
3486 ITextRange *range, *range2, *range3;
3487 IRichEditOle *reOle = NULL;
3488 ITextDocument *doc = NULL;
3490 LONG value;
3491 HRESULT hr;
3492 HWND hwnd;
3493
3494 create_interfaces(&hwnd, &reOle, &doc, &selection);
3495 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3496 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3497
3498 hr = ITextDocument_Range(doc, 0, 4, &range);
3499 ok(hr == S_OK, "got 0x%08lx\n", hr);
3500
3501 hr = ITextDocument_Range(doc, 0, 4, &range2);
3502 ok(hr == S_OK, "got 0x%08lx\n", hr);
3503
3504 /* matches selection */
3505 hr = ITextDocument_Range(doc, 1, 2, &range3);
3506 ok(hr == S_OK, "got 0x%08lx\n", hr);
3507
3508 hr = ITextRange_IsEqual(range, NULL, NULL);
3509 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3510
3511 value = tomTrue;
3512 hr = ITextRange_IsEqual(range, NULL, &value);
3513 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3514 ok(value == tomFalse, "got %ld\n", value);
3515
3516 hr = ITextRange_IsEqual(range, range2, NULL);
3517 ok(hr == S_OK, "got 0x%08lx\n", hr);
3518
3519 value = tomFalse;
3520 hr = ITextRange_IsEqual(range, range2, &value);
3521 ok(hr == S_OK, "got 0x%08lx\n", hr);
3522 ok(value == tomTrue, "got %ld\n", value);
3523
3524 value = tomTrue;
3525 hr = ITextRange_IsEqual(range, range3, &value);
3526 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3527 ok(value == tomFalse, "got %ld\n", value);
3528
3529 /* selection */
3530 hr = ITextSelection_IsEqual(selection, NULL, NULL);
3531 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3532
3533 value = tomTrue;
3534 hr = ITextSelection_IsEqual(selection, NULL, &value);
3535 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3536 ok(value == tomFalse, "got %ld\n", value);
3537
3538 hr = ITextSelection_IsEqual(selection, range2, NULL);
3539 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3540
3541 value = tomTrue;
3542 hr = ITextSelection_IsEqual(selection, range2, &value);
3543 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3544 ok(value == tomFalse, "got %ld\n", value);
3545
3546 value = tomTrue;
3547 hr = ITextSelection_IsEqual(selection, range3, &value);
3548 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
3549 ok(value == tomFalse, "got %ld\n", value);
3550
3551 /* seems to work on ITextSelection ranges only */
3552 value = tomFalse;
3553 hr = ITextSelection_IsEqual(selection, (ITextRange*)selection, &value);
3554 ok(hr == S_OK, "got 0x%08lx\n", hr);
3555 ok(value == tomTrue, "got %ld\n", value);
3556
3557 release_interfaces(&hwnd, &reOle, &doc, NULL);
3558
3559 hr = ITextRange_IsEqual(range, NULL, NULL);
3560 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3561
3562 value = tomTrue;
3563 hr = ITextRange_IsEqual(range, NULL, &value);
3564 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3565 ok(value == tomFalse, "got %ld\n", value);
3566
3567 hr = ITextRange_IsEqual(range, range2, NULL);
3568 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3569
3570 value = tomTrue;
3571 hr = ITextRange_IsEqual(range, range2, &value);
3572 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3573 ok(value == tomFalse, "got %ld\n", value);
3574
3575 /* selection */
3576 hr = ITextSelection_IsEqual(selection, NULL, NULL);
3577 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3578
3579 value = tomTrue;
3580 hr = ITextSelection_IsEqual(selection, NULL, &value);
3581 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3582 ok(value == tomFalse, "got %ld\n", value);
3583
3584 hr = ITextSelection_IsEqual(selection, range2, NULL);
3585 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3586
3587 value = tomTrue;
3588 hr = ITextSelection_IsEqual(selection, range2, &value);
3589 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3590 ok(value == tomFalse, "got %ld\n", value);
3591
3592 ITextRange_Release(range);
3593 ITextRange_Release(range2);
3594 ITextRange_Release(range3);
3595 ITextSelection_Release(selection);
3596}
3597
3599{
3600 POINT p = {-1, -1};
3602 ok(p.x != -1 && p.y != -1, "p.x:%ld p.y:%ld\n", p.x, p.y);
3603 return p.y;
3604}
3605
3606static void test_Select(void)
3607{
3608 static const CHAR test_text1[] = "TestSomeText";
3609 static const CHAR test_text2[] = "text\nwith\nbreak\n"
3610 "lines\ntest\ntest\n";
3611 IRichEditOle *reOle = NULL;
3612 ITextDocument *doc = NULL;
3615 int scroll_pos1;
3616 int scroll_pos2;
3617 LONG value;
3618 HRESULT hr;
3619 HWND hwnd;
3620
3621 create_interfaces(&hwnd, &reOle, &doc, &selection);
3622 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3623 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3624
3625 hr = ITextDocument_Range(doc, 0, 4, &range);
3626 ok(hr == S_OK, "got 0x%08lx\n", hr);
3627
3628 scroll_pos1 = get_scroll_pos_y(hwnd);
3629 hr = ITextRange_Select(range);
3630 ok(hr == S_OK, "got 0x%08lx\n", hr);
3631 scroll_pos2 = get_scroll_pos_y(hwnd);
3632 ok(scroll_pos1 == scroll_pos2, "%d != %d\n", scroll_pos1, scroll_pos2);
3633
3634 value = 1;
3635 hr = ITextSelection_GetStart(selection, &value);
3636 ok(hr == S_OK, "got 0x%08lx\n", hr);
3637 ok(value == 0, "got %ld\n", value);
3638
3639 hr = ITextRange_Select(range);
3640 ok(hr == S_OK, "got 0x%08lx\n", hr);
3641
3642 hr = ITextSelection_Select(selection);
3643 ok(hr == S_OK, "got 0x%08lx\n", hr);
3644
3645 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text2);
3646 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3647 hr = ITextDocument_Range(doc, 10, 16, &range);
3648 ok(hr == S_OK, "got 0x%08lx\n", hr);
3649 scroll_pos1 = get_scroll_pos_y(hwnd);
3650 hr = ITextRange_Select(range);
3651 ok(hr == S_OK, "got 0x%08lx\n", hr);
3652 scroll_pos2 = get_scroll_pos_y(hwnd);
3653 ok(scroll_pos1 != scroll_pos2, "%d == %d\n", scroll_pos1, scroll_pos2);
3654
3655 release_interfaces(&hwnd, &reOle, &doc, NULL);
3656
3657 hr = ITextRange_Select(range);
3658 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3659
3660 hr = ITextSelection_Select(selection);
3661 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3662
3663 ITextRange_Release(range);
3664 ITextSelection_Release(selection);
3665}
3666
3667static void test_GetStoryType(void)
3668{
3669 static const CHAR test_text1[] = "TestSomeText";
3670 IRichEditOle *reOle = NULL;
3671 ITextDocument *doc = NULL;
3674 LONG value;
3675 HRESULT hr;
3676 HWND hwnd;
3677
3678 create_interfaces(&hwnd, &reOle, &doc, &selection);
3679 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3680 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3681
3682 hr = ITextDocument_Range(doc, 0, 4, &range);
3683 ok(hr == S_OK, "got 0x%08lx\n", hr);
3684
3685 hr = ITextRange_GetStoryType(range, NULL);
3686 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3687
3689 hr = ITextRange_GetStoryType(range, &value);
3690 ok(hr == S_OK, "got 0x%08lx\n", hr);
3691 ok(value == tomUnknownStory, "got %ld\n", value);
3692
3693 hr = ITextSelection_GetStoryType(selection, NULL);
3694 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3695
3697 hr = ITextSelection_GetStoryType(selection, &value);
3698 ok(hr == S_OK, "got 0x%08lx\n", hr);
3699 ok(value == tomUnknownStory, "got %ld\n", value);
3700
3701 release_interfaces(&hwnd, &reOle, &doc, NULL);
3702
3703 hr = ITextRange_GetStoryType(range, NULL);
3704 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3705
3706 value = 123;
3707 hr = ITextRange_GetStoryType(range, &value);
3708 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3709 ok(value == 123, "got %ld\n", value);
3710
3711 hr = ITextSelection_GetStoryType(selection, NULL);
3712 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3713
3714 value = 123;
3715 hr = ITextSelection_GetStoryType(selection, &value);
3716 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3717 ok(value == 123, "got %ld\n", value);
3718
3719 ITextRange_Release(range);
3720 ITextSelection_Release(selection);
3721}
3722
3723static void test_SetFont(void)
3724{
3725 static const CHAR test_text1[] = "TestSomeText";
3726 IRichEditOle *reOle = NULL;
3727 ITextDocument *doc = NULL;
3729 ITextRange *range, *range2;
3730 ITextFont *font, *font2;
3731 LONG value;
3732 HRESULT hr;
3733 HWND hwnd;
3734
3735 create_interfaces(&hwnd, &reOle, &doc, &selection);
3736 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3737 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3738
3739 hr = ITextDocument_Range(doc, 0, 4, &range);
3740 ok(hr == S_OK, "got 0x%08lx\n", hr);
3741
3742 hr = ITextDocument_Range(doc, 5, 2, &range2);
3743 ok(hr == S_OK, "got 0x%08lx\n", hr);
3744
3745 EXPECT_REF(range, 1);
3746 hr = ITextRange_GetFont(range, &font);
3747 ok(hr == S_OK, "got 0x%08lx\n", hr);
3748 EXPECT_REF(range, 2);
3749
3750 EXPECT_REF(range2, 1);
3751 hr = ITextRange_GetFont(range2, &font2);
3752 ok(hr == S_OK, "got 0x%08lx\n", hr);
3753 EXPECT_REF(range2, 2);
3754
3755 hr = ITextRange_SetFont(range, NULL);
3756 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3757
3758 /* setting same font, no-op */
3759 EXPECT_REF(range, 2);
3760 hr = ITextRange_SetFont(range, font);
3761 ok(hr == S_OK, "got 0x%08lx\n", hr);
3762 EXPECT_REF(range, 2);
3763
3764 EXPECT_REF(range2, 2);
3765 EXPECT_REF(range, 2);
3766 hr = ITextRange_SetFont(range, font2);
3767 ok(hr == S_OK, "got 0x%08lx\n", hr);
3768 EXPECT_REF(range2, 2);
3769 EXPECT_REF(range, 2);
3770
3771 /* originally range 0-4 is non-italic */
3772 value = tomTrue;
3773 hr = ITextFont_GetItalic(font, &value);
3774 ok(hr == S_OK, "got 0x%08lx\n", hr);
3775 ok(value == tomFalse, "got %ld\n", value);
3776
3777 /* set range 5-2 to italic, then set this font to range 0-4 */
3778 hr = ITextFont_SetItalic(font2, tomTrue);
3779 ok(hr == S_OK, "got 0x%08lx\n", hr);
3780
3781 hr = ITextRange_SetFont(range, font2);
3782 ok(hr == S_OK, "got 0x%08lx\n", hr);
3783
3784 value = tomFalse;
3785 hr = ITextFont_GetItalic(font, &value);
3786 ok(hr == S_OK, "got 0x%08lx\n", hr);
3787 ok(value == tomTrue, "got %ld\n", value);
3788
3789 release_interfaces(&hwnd, &reOle, &doc, NULL);
3790
3791 hr = ITextRange_SetFont(range, NULL);
3792 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3793
3794 hr = ITextRange_SetFont(range, font);
3795 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3796
3797 hr = ITextSelection_SetFont(selection, NULL);
3798 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3799
3800 hr = ITextSelection_SetFont(selection, font);
3801 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
3802
3803 ITextFont_Release(font);
3804 ITextFont_Release(font2);
3805 ITextRange_Release(range);
3806 ITextRange_Release(range2);
3807 ITextSelection_Release(selection);
3808}
3809
3810static void fill_reobject_struct(REOBJECT *reobj, LONG cp, LPOLEOBJECT poleobj,
3811 LPSTORAGE pstg, LPOLECLIENTSITE polesite, LONG sizel_cx,
3812 LONG sizel_cy, DWORD aspect, DWORD flags, DWORD user)
3813{
3814 reobj->cbStruct = sizeof(*reobj);
3815 reobj->clsid = CLSID_NULL;
3816 reobj->cp = cp;
3817 reobj->poleobj = poleobj;
3818 reobj->pstg = pstg;
3819 reobj->polesite = polesite;
3820 reobj->sizel.cx = sizel_cx;
3821 reobj->sizel.cy = sizel_cy;
3822 reobj->dvaspect = aspect;
3823 reobj->dwFlags = flags;
3824 reobj->dwUser = user;
3825}
3826
3827#define CHECK_REOBJECT_STRUCT(reole,index,flags,cp,cp_check,poleobj,pstg,polesite,user) \
3828 _check_reobject_struct(reole, index, flags, cp, cp_check, poleobj, pstg, polesite, user, __LINE__)
3830 LPOLEOBJECT poleobj, LPSTORAGE pstg, LPOLECLIENTSITE polesite, DWORD user, int line)
3831{
3832 REOBJECT reobj;
3833 HRESULT hr;
3834
3835 reobj.cbStruct = sizeof(reobj);
3836 reobj.cp = cp;
3837 hr = IRichEditOle_GetObject(reole, index, &reobj, flags);
3838 ok(hr == S_OK, "IRichEditOle_GetObject failed: %#lx.\n", hr);
3839 ok_(__FILE__,line)(reobj.cp == cp_check, "expected cp = %ld, got %ld.\n", cp_check, reobj.cp);
3840 ok_(__FILE__,line)(reobj.poleobj == poleobj, "got wrong object interface.\n");
3841 ok_(__FILE__,line)(reobj.pstg == pstg, "got wrong storage interface.\n");
3842 ok_(__FILE__,line)(reobj.polesite == polesite, "got wrong site interface.\n");
3843 ok_(__FILE__,line)(reobj.dwUser == user, "got wrong user-defined value.\n");
3844}
3845
3846#define INSERT_REOBJECT(callback,reole,reobj,cp,user) \
3847 _insert_reobject(callback, reole, reobj, cp, user, __LINE__)
3849 REOBJECT *reobj, LONG cp, DWORD user, int line)
3850{
3852 HRESULT hr;
3853
3855 &CLSID_NULL, NULL, REO_CP_SELECTION /* cp overridden */, S_OK);
3856 hr = IRichEditOle_GetClientSite(reole, &clientsite);
3857 ok_(__FILE__,line)(hr == S_OK, "IRichEditOle_GetClientSite got hr %#lx.\n", hr);
3858 fill_reobject_struct(reobj, cp, NULL, NULL, clientsite, 10, 10, DVASPECT_CONTENT, 0, user);
3859 hr = IRichEditOle_InsertObject(reole, reobj);
3860 ok_(__FILE__,line)(hr == S_OK, "IRichEditOle_InsertObject got hr %#lx.\n", hr);
3861 IOleClientSite_Release(clientsite);
3863}
3864
3866{
3867 MSG msg;
3868 while (PeekMessageW( &msg, NULL, 0, 0, PM_REMOVE ))
3869 {
3872 }
3873}
3874
3876{
3877 static CHAR test_text1[] = "abcdefg";
3878 IRichEditOle *reole = NULL;
3879 ITextDocument *doc = NULL;
3880 REOBJECT reo1, reo2, reo3, received_reo;
3881 HRESULT hr;
3882 HWND hwnd;
3883 const WCHAR *expected_string, *string;
3884 const CHAR *expected_stringA;
3886 IDataObject *dataobject;
3887 TEXTRANGEA textrange;
3888 FORMATETC formatetc;
3889 CHARRANGE charrange;
3890 GETTEXTEX gettextex;
3891 STGMEDIUM stgmedium;
3892 WCHAR buffer[1024];
3893 CHAR bufferA[1024];
3894 LONG count, result;
3896 BSTR bstr;
3897 struct testoleobj *testobj;
3899 REOBJECT reobj;
3900 BOOL bad_getsel;
3901 DWORD gle;
3902
3903 create_interfaces(&hwnd, &reole, &doc, &selection);
3904 if (callback)
3905 {
3906 LRESULT sendres = SendMessageA(hwnd, EM_SETOLECALLBACK, 0, (LPARAM)&callback->IRichEditOleCallback_iface);
3907 ok( !!sendres, "EM_SETOLECALLBACK should succeed\n" );
3908 }
3909
3911 SendMessageA(hwnd, EM_SETSEL, 0, -1);
3912 *bufferA = '\0';
3913 SetLastError(0xdeadbeef);
3914 result = SendMessageA(hwnd, EM_GETSELTEXT, 0, (LPARAM)bufferA);
3915 gle = GetLastError();
3916 ok((result > 0 && gle == 0xdeadbeef) ||
3917 broken(result == 0 && gle == ERROR_INVALID_PARAMETER /* Hindi */),
3918 "EM_GETSELTEXT returned %ld gle=%lu\n", result, gle);
3919 bad_getsel = (gle != 0xdeadbeef);
3920 if (bad_getsel)
3921 trace("EM_GETSELTEXT is broken, some tests will be ignored\n");
3922
3923 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
3924
3925 hr = IRichEditOle_InsertObject(reole, NULL);
3926 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
3927
3928 /* insert object1 in (0, 1)*/
3929 SendMessageA(hwnd, EM_SETSEL, 0, 1);
3930 INSERT_REOBJECT(callback, reole, &reo1, REO_CP_SELECTION, 1);
3931 count = IRichEditOle_GetObjectCount(reole);
3932 ok(count == 1, "got wrong object count: %ld\n", count);
3933
3934 /* insert object2 in (2, 3)*/
3935 SendMessageA(hwnd, EM_SETSEL, 2, 3);
3936 INSERT_REOBJECT(callback, reole, &reo2, REO_CP_SELECTION, 2);
3937 count = IRichEditOle_GetObjectCount(reole);
3938 ok(count == 2, "got wrong object count: %ld\n", count);
3939
3940 /* insert object3 in (1, 2)*/
3941 SendMessageA(hwnd, EM_SETSEL, 1, 2);
3942 INSERT_REOBJECT(callback, reole, &reo3, REO_CP_SELECTION, 3);
3943 count = IRichEditOle_GetObjectCount(reole);
3944 ok(count == 3, "got wrong object count: %ld\n", count);
3945
3946 if (callback)
3947 {
3948 /* (fail to) insert object1 in (3, 4)*/
3949 SendMessageA(hwnd, EM_SETSEL, 3, 4);
3950
3951 hr = IRichEditOle_GetClientSite(reole, &clientsite);
3952 ok(hr == S_OK, "IRichEditOle_GetClientSite got hr %#lx.\n", hr);
3953
3955 &CLSID_NULL, NULL, REO_CP_SELECTION, S_FALSE);
3956 fill_reobject_struct(&reobj, REO_CP_SELECTION, NULL, NULL, clientsite, 10, 10, DVASPECT_CONTENT, 0, 0);
3957 hr = IRichEditOle_InsertObject(reole, &reobj);
3958 ok(hr == S_FALSE, "IRichEditOle_InsertObject got hr %#lx.\n", hr);
3960
3961 IOleClientSite_Release(clientsite);
3962
3963 count = IRichEditOle_GetObjectCount(reole);
3964 ok(count == 3, "got wrong object count: %ld\n", count);
3965 }
3966
3967 /* tests below show that order of rebject (from 0 to 2) is: reo1,reo3,reo2 */
3968 CHECK_REOBJECT_STRUCT(reole, 0, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
3969 CHECK_REOBJECT_STRUCT(reole, 1, REO_GETOBJ_ALL_INTERFACES, 0, 1, NULL, NULL, reo3.polesite, 3);
3970 CHECK_REOBJECT_STRUCT(reole, 2, REO_GETOBJ_ALL_INTERFACES, 0, 2, NULL, NULL, reo2.polesite, 2);
3971
3972 hr = IRichEditOle_GetObject(reole, 2, NULL, REO_GETOBJ_ALL_INTERFACES);
3973 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3974
3975 received_reo.cbStruct = 0;
3976 hr = IRichEditOle_GetObject(reole, 2, &received_reo, REO_GETOBJ_ALL_INTERFACES);
3977 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3978
3979 CHECK_REOBJECT_STRUCT(reole, 2, REO_GETOBJ_PSTG, 0, 2, NULL, NULL, NULL, 2);
3980 CHECK_REOBJECT_STRUCT(reole, 2, REO_GETOBJ_POLESITE, 0, 2, NULL, NULL, reo2.polesite, 2);
3981
3982 hr = IRichEditOle_GetObject(reole, 3, &received_reo, REO_GETOBJ_POLESITE);
3983 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3984
3985 hr = IRichEditOle_GetObject(reole, 4, &received_reo, REO_GETOBJ_POLESITE);
3986 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3987
3988 hr = IRichEditOle_GetObject(reole, 1024, &received_reo, REO_GETOBJ_POLESITE);
3989 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3990
3991 hr = IRichEditOle_GetObject(reole, -10, &received_reo, REO_GETOBJ_POLESITE);
3992 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
3993
3994 /* received_reo will be zeroed before be used */
3995 received_reo.cbStruct = sizeof(received_reo);
3996 received_reo.polesite = (IOleClientSite *)0xdeadbeef;
3997 hr = IRichEditOle_GetObject(reole, 2, &received_reo, REO_GETOBJ_NO_INTERFACES);
3998 ok(hr == S_OK, "IRichEditOle_GetObject failed: 0x%08lx\n", hr);
3999 ok(received_reo.polesite == NULL, "Got wrong site interface.\n");
4000
4001 CHECK_REOBJECT_STRUCT(reole, REO_IOB_USE_CP, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
4002 CHECK_REOBJECT_STRUCT(reole, REO_IOB_USE_CP, REO_GETOBJ_ALL_INTERFACES, 1, 1, NULL, NULL, reo3.polesite, 3);
4003 CHECK_REOBJECT_STRUCT(reole, REO_IOB_USE_CP, REO_GETOBJ_ALL_INTERFACES, 2, 2, NULL, NULL, reo2.polesite, 2);
4004
4005 received_reo.cbStruct = sizeof(received_reo);
4006 received_reo.polesite = (IOleClientSite *)0xdeadbeef;
4007 received_reo.dwUser = 4;
4008 received_reo.cp = 4;
4009 hr = IRichEditOle_GetObject(reole, REO_IOB_USE_CP, &received_reo, REO_GETOBJ_ALL_INTERFACES);
4010 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
4011 ok(received_reo.polesite == (IOleClientSite *)0xdeadbeef, "Got wrong site interface.\n");
4012 ok(received_reo.dwUser == 4, "Got wrong user-defined value: %ld.\n", received_reo.dwUser);
4013
4014 SendMessageA(hwnd, EM_SETSEL, 0, 1);
4015 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
4016
4017 SendMessageA(hwnd, EM_SETSEL, 1, 2);
4018 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 1, NULL, NULL, reo3.polesite, 3);
4019
4020 SendMessageA(hwnd, EM_SETSEL, 2, 3);
4021 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 2, NULL, NULL, reo2.polesite, 2);
4022
4023 SendMessageA(hwnd, EM_SETSEL, 0, 2);
4024 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
4025
4026 SendMessageA(hwnd, EM_SETSEL, 1, 3);
4027 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 1, NULL, NULL, reo3.polesite, 3);
4028
4029 SendMessageA(hwnd, EM_SETSEL, 2, 0);
4030 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
4031
4032 SendMessageA(hwnd, EM_SETSEL, 0, 6);
4033 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 0, 0, NULL, NULL, reo1.polesite, 1);
4034
4035 SendMessageA(hwnd, EM_SETSEL, 4, 5);
4036 received_reo.cbStruct = sizeof(received_reo);
4037 received_reo.cp = 0;
4038 hr = IRichEditOle_GetObject(reole, REO_IOB_SELECTION, &received_reo, REO_GETOBJ_ALL_INTERFACES);
4039 ok(hr == E_INVALIDARG, "IRichEditOle_GetObject should fail: 0x%08lx\n", hr);
4040
4041 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4042
4043 /* "abc|d|efg" */
4044 INSERT_REOBJECT(callback, reole, &reo1, 3, 1);
4045 INSERT_REOBJECT(callback, reole, &reo2, 5, 2);
4046
4047 SendMessageW(hwnd, EM_SETSEL, 2, 3);
4049 ok(result == SEL_TEXT, "Got selection type: %lx.\n", result);
4050
4051 SendMessageW(hwnd, EM_SETSEL, 3, 4);
4053 ok(result == SEL_OBJECT, "Got selection type: %lx.\n", result);
4054 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 1, 3, NULL, NULL, reo1.polesite, 1);
4055
4056 SendMessageW(hwnd, EM_SETSEL, 2, 4);
4058 ok(result == (SEL_TEXT | SEL_OBJECT), "Got selection type: %lx.\n", result);
4059
4060 SendMessageW(hwnd, EM_SETSEL, 5, 6);
4061 CHECK_REOBJECT_STRUCT(reole, REO_IOB_SELECTION, REO_GETOBJ_ALL_INTERFACES, 1, 5, NULL, NULL, reo2.polesite, 2);
4062
4063#ifdef __REACTOS__
4064 expected_string = L"abc\xfffc"L"d\xfffc"L"efg";
4065#else
4066 expected_string = L"abc\xfffc""d\xfffc""efg";
4067#endif
4068
4069 gettextex.cb = sizeof(buffer);
4070 gettextex.flags = GT_DEFAULT;
4071 gettextex.codepage = 1200;
4072 gettextex.lpDefaultChar = NULL;
4073 gettextex.lpUsedDefChar = NULL;
4075 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4076 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4077
4078 gettextex.flags = GT_RAWTEXT;
4079 memset(buffer, 0, sizeof(buffer));
4081 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4082 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4083
4084 gettextex.flags = GT_NOHIDDENTEXT;
4085 memset(buffer, 0, sizeof(buffer));
4087 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4088 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4089
4090 gettextex.flags = GT_SELECTION;
4091 memset(buffer, 0, sizeof(buffer));
4092 SendMessageW(hwnd, EM_SETSEL, 0, -1);
4094 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4095 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4096
4097 expected_string = L"abc d efg";
4098 gettextex.flags = GT_USECRLF;
4099 memset(buffer, 0, sizeof(buffer));
4101 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4102 ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4103
4104 expected_stringA = "abc d efg";
4105 memset(bufferA, 0, sizeof(bufferA));
4106 SendMessageA(hwnd, EM_SETSEL, 0, -1);
4107 SetLastError(0xdeadbeef);
4108 result = SendMessageA(hwnd, EM_GETSELTEXT, 0, (LPARAM)bufferA);
4109 gle = GetLastError();
4110 ok(result == strlen(expected_stringA) || broken(bad_getsel && result == 0),
4111 "Got wrong length: %ld (gle %lu)\n", result, gle);
4112 ok(!strcmp(bufferA, expected_stringA) || broken(bad_getsel && !*bufferA),
4113 "Got wrong content: %s (gle %lu)\n", bufferA, gle);
4114
4115 memset(bufferA, 0, sizeof(bufferA));
4116 textrange.lpstrText = bufferA;
4117 textrange.chrg.cpMin = 0;
4118 textrange.chrg.cpMax = 11;
4119 result = SendMessageA(hwnd, EM_GETTEXTRANGE, 0, (LPARAM)&textrange);
4120 ok(result == strlen(expected_stringA), "Got wrong length: %ld.\n", result);
4121 ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA);
4122
4123#ifdef __REACTOS__
4124 expected_string = L"abc\xfffc"L"d\xfffc"L"efg\r";
4125#else
4126 expected_string = L"abc\xfffc""d\xfffc""efg\r";
4127#endif
4128
4129 hr = ITextDocument_Range(doc, 0, 11, &range);
4130 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4131 hr = ITextRange_GetText(range, &bstr);
4132 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4133 ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
4134 todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
4135 SysFreeString(bstr);
4136 hr = ITextRange_SetRange(range, 3, 4);
4137 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4138 hr = ITextRange_GetChar(range, &result);
4139 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4140 todo_wine ok(result == 0xfffc, "Got char: %lc\n", (WCHAR)result);
4141 ITextRange_Release(range);
4142
4143 SendMessageW(hwnd, EM_SETSEL, 0, -1);
4144 hr = ITextSelection_GetText(selection, &bstr);
4145 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4146 ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
4147 todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
4148 SysFreeString(bstr);
4149 SendMessageW(hwnd, EM_SETSEL, 3, 4);
4150 result = 0;
4151 hr = ITextSelection_GetChar(selection, &result);
4152 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4153 todo_wine ok(result == 0xfffc, "Got char: %lc\n", (WCHAR)result);
4154
4157 ok(!result, "Got result %lx.\n", result);
4158 /* "abc|d|efg" */
4159 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4160 INSERT_REOBJECT(callback, reole, &reo1, 3, 1);
4161 INSERT_REOBJECT(callback, reole, &reo2, 5, 2);
4162
4163 expected_string = L"abc d efg";
4164 charrange.cpMin = 0;
4165 charrange.cpMax = 11;
4166 hr = IRichEditOle_GetClipboardData(reole, &charrange, 1, &dataobject);
4167 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4168 formatetc.cfFormat = CF_UNICODETEXT;
4169 formatetc.dwAspect = DVASPECT_CONTENT;
4170 formatetc.ptd = NULL;
4171 formatetc.tymed = TYMED_HGLOBAL;
4172 formatetc.lindex = -1;
4173 hr = IDataObject_GetData(dataobject, &formatetc, &stgmedium);
4174 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4175 string = GlobalLock(stgmedium.hGlobal);
4176 ok(lstrlenW(string) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(string));
4177 ok(!lstrcmpW(string, expected_string), "Got wrong content: %s.\n", debugstr_w(string));
4178 GlobalUnlock(stgmedium.hGlobal);
4179
4180#ifdef __REACTOS__
4181 expected_string = L"abc\xfffc"L"d\xfffc"L"efg";
4182#else
4183 expected_string = L"abc\xfffc""d\xfffc""efg";
4184#endif
4185
4186 gettextex.cb = sizeof(buffer);
4187 gettextex.flags = GT_DEFAULT;
4188 gettextex.codepage = 1200;
4189 gettextex.lpDefaultChar = NULL;
4190 gettextex.lpUsedDefChar = NULL;
4192 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4193 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4194
4195 gettextex.flags = GT_RAWTEXT;
4196 memset(buffer, 0, sizeof(buffer));
4198 ok(result == lstrlenW(expected_string), "Got wrong length: %ld.\n", result);
4199 todo_wine ok(!lstrcmpW(buffer, expected_string), "Got wrong content: %s.\n", debugstr_w(buffer));
4200
4201 expected_stringA = "abc d efg";
4202 memset(bufferA, 0, sizeof(bufferA));
4203 SendMessageA(hwnd, EM_SETSEL, 0, -1);
4204 SetLastError(0xdeadbeef);
4205 result = SendMessageA(hwnd, EM_GETSELTEXT, 0, (LPARAM)bufferA);
4206 gle = GetLastError();
4207 ok(result == strlen(expected_stringA) || broken(bad_getsel && result == 0),
4208 "Got wrong length: %ld (gle %lu)\n", result, gle);
4209 ok(!strcmp(bufferA, expected_stringA) || broken(bad_getsel && !*bufferA),
4210 "Got wrong content: %s (gle %lu)\n", bufferA, gle);
4211
4212 memset(bufferA, 0, sizeof(bufferA));
4213 textrange.lpstrText = bufferA;
4214 textrange.chrg.cpMin = 0;
4215 textrange.chrg.cpMax = 11;
4216 result = SendMessageA(hwnd, EM_GETTEXTRANGE, 0, (LPARAM)&textrange);
4217 ok(result == strlen(expected_stringA), "Got wrong length: %ld.\n", result);
4218 ok(!strcmp(bufferA, expected_stringA), "Got wrong content: %s.\n", bufferA);
4219
4220#ifdef __REACTOS__
4221 expected_string = L"abc\xfffc"L"d\xfffc"L"efg";
4222#else
4223 expected_string = L"abc\xfffc""d\xfffc""efg";
4224#endif
4225
4226 hr = ITextDocument_Range(doc, 0, 11, &range);
4227 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4228 hr = ITextRange_GetText(range, &bstr);
4229 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4230 todo_wine ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
4231 todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
4232 SysFreeString(bstr);
4233 hr = ITextRange_SetRange(range, 3, 4);
4234 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4235 hr = ITextRange_GetChar(range, &result);
4236 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4237 todo_wine ok(result == 0xfffc, "Got char: %lc\n", (WCHAR)result);
4238 ITextRange_Release(range);
4239
4240 SendMessageW(hwnd, EM_SETSEL, 0, -1);
4241 hr = ITextSelection_GetText(selection, &bstr);
4242 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4243 todo_wine ok(lstrlenW(bstr) == lstrlenW(expected_string), "Got wrong length: %d.\n", lstrlenW(bstr));
4244 todo_wine ok(!lstrcmpW(bstr, expected_string), "Got text: %s.\n", wine_dbgstr_w(bstr));
4245 SysFreeString(bstr);
4246 SendMessageW(hwnd, EM_SETSEL, 3, 4);
4247 result = 0;
4248 hr = ITextSelection_GetChar(selection, &result);
4249 ok(hr == S_OK, "Got hr %#lx.\n", hr);
4250 todo_wine ok(result == 0xfffc, "Got char: %lc\n", (WCHAR)result);
4251
4253 ok(hr == S_OK, "testoleobj_Create got hr %#lx.\n", hr);
4254 testobj->extent.cx = 800;
4255 testobj->extent.cy = 400;
4256
4258 testobj->draw_count = 0;
4259 testobj->line = __LINE__;
4260
4261 hr = IRichEditOle_GetClientSite(reole, &clientsite);
4262 ok(hr == S_OK, "IRichEditOle_GetClientSite got hr %#lx.\n", hr);
4263 hr = IOleObject_SetClientSite(&testobj->IOleObject_iface, clientsite);
4264 ok(hr == S_OK, "IOleObject_SetClientSite got hr %#lx.\n", hr);
4265
4267 &CLSID_testoleobj, NULL, REO_CP_SELECTION, S_OK);
4268 fill_reobject_struct(&reobj, REO_CP_SELECTION, &testobj->IOleObject_iface, NULL, clientsite, 800, 400, DVASPECT_CONTENT, 0, 0);
4269 reobj.clsid = CLSID_testoleobj;
4270 hr = IRichEditOle_InsertObject(reole, &reobj);
4271 ok(hr == S_OK, "IRichEditOle_InsertObject got hr %#lx.\n", hr);
4273
4274 IOleClientSite_Release(clientsite);
4275
4276 testobj->line = __LINE__;
4278 testobj->line = __LINE__;
4280 ok(testobj->draw_count != 0, "expected draw_count to be nonzero, got %d\n", testobj->draw_count);
4281
4283 testobj->draw_count = 0;
4284 testobj->line = __LINE__;
4285
4286 hr = IRichEditOle_GetClientSite(reole, &clientsite);
4287 ok(hr == S_OK, "IRichEditOle_GetClientSite got hr %#lx.\n", hr);
4288 hr = IOleObject_SetClientSite(&testobj->IOleObject_iface, clientsite);
4289 ok(hr == S_OK, "IOleObject_SetClientSite got hr %#lx.\n", hr);
4290
4292 &CLSID_testoleobj, NULL, REO_CP_SELECTION, S_OK);
4293 fill_reobject_struct(&reobj, REO_CP_SELECTION, &testobj->IOleObject_iface, NULL, clientsite, 0, 0, DVASPECT_CONTENT, 0, 0);
4294 reobj.clsid = CLSID_testoleobj;
4295 hr = IRichEditOle_InsertObject(reole, &reobj);
4296 ok(hr == S_OK, "IRichEditOle_InsertObject got hr %#lx.\n", hr);
4298
4299 memset(&reobj, 0xcc, sizeof(reobj));
4300 reobj.cbStruct = sizeof(reobj);
4301 hr = IRichEditOle_GetObject(reole, 0, &reobj, REO_GETOBJ_NO_INTERFACES);
4302 ok(hr == S_OK, "IRichEditOle_GetObject got hr %#lx.\n", hr);
4303 ok(reobj.sizel.cx == 800, "expected reobj.sizel.cx to be %ld, got %ld\n", 800L, reobj.sizel.cx);
4304 ok(reobj.sizel.cy == 400, "expected reobj.sizel.cy to be %ld, got %ld\n", 400L, reobj.sizel.cy);
4305 IOleClientSite_Release(clientsite);
4306
4307 testobj->line = __LINE__;
4309 testobj->line = __LINE__;
4311 ok(testobj->draw_count != 0, "expected draw_count to be nonzero, got %d\n", testobj->draw_count);
4312
4314 IOleObject_Release(&testobj->IOleObject_iface);
4315
4316 if (callback)
4317 {
4318 LRESULT sendres = SendMessageA(hwnd, EM_SETOLECALLBACK, 0, 0);
4319 ok( !!sendres, "EM_SETOLECALLBACK should succeed\n" );
4320 }
4321
4322 release_interfaces(&hwnd, &reole, &doc, &selection);
4323}
4324
4325static void test_InsertObject(void)
4326{
4327 struct reolecb_obj *callback;
4328 HRESULT hr;
4329 ULONG ref;
4330
4332
4334 ok(SUCCEEDED(hr), "reolecb_obj_Create returned %#lx\n", hr);
4335 if (SUCCEEDED(hr))
4336 {
4338 ref = IRichEditOleCallback_Release(&callback->IRichEditOleCallback_iface);
4339 ok(ref == 0, "expected IRichEditOleCallback recount to be 0, got %lu\n", ref);
4340 }
4341 else
4342 {
4343 skip("cannot test InsertObject with callback\n");
4344 }
4345}
4346
4347static void test_GetStoryLength(void)
4348{
4349 static const CHAR test_text1[] = "TestSomeText";
4350 IRichEditOle *reOle = NULL;
4351 ITextDocument *doc = NULL;
4354 LONG value;
4355 HRESULT hr;
4356 HWND hwnd;
4357
4358 create_interfaces(&hwnd, &reOle, &doc, &selection);
4359 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4360 SendMessageA(hwnd, EM_SETSEL, 1, 2);
4361
4362 hr = ITextDocument_Range(doc, 0, 4, &range);
4363 ok(hr == S_OK, "got 0x%08lx\n", hr);
4364
4365 hr = ITextRange_GetStoryLength(range, NULL);
4366 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
4367
4368 value = 0;
4369 hr = ITextRange_GetStoryLength(range, &value);
4370 ok(hr == S_OK, "got 0x%08lx\n", hr);
4371 ok(value == 13, "got %ld\n", value);
4372
4373 hr = ITextSelection_GetStoryLength(selection, NULL);
4374 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
4375
4376 value = 0;
4377 hr = ITextSelection_GetStoryLength(selection, &value);
4378 ok(hr == S_OK, "got 0x%08lx\n", hr);
4379 ok(value == 13, "got %ld\n", value);
4380
4382
4383 value = 0;
4384 hr = ITextRange_GetStoryLength(range, &value);
4385 ok(hr == S_OK, "got 0x%08lx\n", hr);
4386 ok(value == 1, "got %ld\n", value);
4387
4388 value = 0;
4389 hr = ITextSelection_GetStoryLength(selection, &value);
4390 ok(hr == S_OK, "got 0x%08lx\n", hr);
4391 ok(value == 1, "got %ld\n", value);
4392
4393 release_interfaces(&hwnd, &reOle, &doc, NULL);
4394
4395 hr = ITextRange_GetStoryLength(range, NULL);
4396 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4397
4398 value = 100;
4399 hr = ITextRange_GetStoryLength(range, &value);
4400 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4401 ok(value == 100, "got %ld\n", value);
4402
4403 hr = ITextSelection_GetStoryLength(selection, NULL);
4404 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4405
4406 value = 100;
4407 hr = ITextSelection_GetStoryLength(selection, &value);
4408 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4409 ok(value == 100, "got %ld\n", value);
4410
4411 ITextSelection_Release(selection);
4412 ITextRange_Release(range);
4413}
4414
4416{
4417 static const CHAR test_text1[] = "TestSomeText";
4418 IRichEditOle *reOle = NULL;
4419 ITextDocument *doc = NULL;
4420 ITextSelection *selection, *sel2;
4421 ITextRange *range, *range2;
4422 ITextFont *font;
4423 LONG value;
4424 HRESULT hr;
4425 HWND hwnd;
4426
4427 create_interfaces(&hwnd, &reOle, &doc, &selection);
4428 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4429 SendMessageA(hwnd, EM_SETSEL, 1, 2);
4430
4431 hr = ITextSelection_GetDuplicate(selection, NULL);
4432 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
4433
4435
4436 hr = ITextSelection_GetDuplicate(selection, &range);
4437 ok(hr == S_OK, "got 0x%08lx\n", hr);
4438
4439 hr = ITextSelection_GetDuplicate(selection, &range2);
4440 ok(hr == S_OK, "got 0x%08lx\n", hr);
4441 ok(range != range2, "got %p, %p\n", range, range2);
4442
4444 EXPECT_REF(range, 1);
4445 EXPECT_REF(range2, 1);
4446
4447 ITextRange_Release(range2);
4448
4449 value = 0;
4450 hr = ITextRange_GetStart(range, &value);
4451 ok(hr == S_OK, "got 0x%08lx\n", hr);
4452 ok(value == 1, "got %ld\n", value);
4453
4454 value = 0;
4455 hr = ITextRange_GetEnd(range, &value);
4456 ok(hr == S_OK, "got 0x%08lx\n", hr);
4457 ok(value == 2, "got %ld\n", value);
4458
4459 SendMessageA(hwnd, EM_SETSEL, 2, 3);
4460
4461 value = 0;
4462 hr = ITextRange_GetStart(range, &value);
4463 ok(hr == S_OK, "got 0x%08lx\n", hr);
4464 ok(value == 1, "got %ld\n", value);
4465
4466 value = 0;
4467 hr = ITextRange_GetEnd(range, &value);
4468 ok(hr == S_OK, "got 0x%08lx\n", hr);
4469 ok(value == 2, "got %ld\n", value);
4470
4471 hr = ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&sel2);
4472 ok(hr == E_NOINTERFACE, "got 0x%08lx\n", hr);
4473
4474 release_interfaces(&hwnd, &reOle, &doc, NULL);
4475
4476 hr = ITextSelection_GetDuplicate(selection, NULL);
4477 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4478
4479 hr = ITextSelection_GetDuplicate(selection, &range);
4480 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4481
4482 hr = ITextRange_GetFont(range, &font);
4483 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4484
4485 ITextSelection_Release(selection);
4486 ITextRange_Release(range);
4487}
4488
4489#define RESET_RANGE(range,start,end) \
4490 _reset_range(range, start, end, __LINE__)
4492{
4493 HRESULT hr;
4494
4495 hr = ITextRange_SetStart(range, start);
4496 ok_(__FILE__,line)(hr == S_OK, "SetStart failed: 0x%08lx\n", hr);
4497 hr = ITextRange_SetEnd(range, end);
4498 ok_(__FILE__,line)(hr == S_OK, "SetEnd failed: 0x%08lx\n", hr);
4499}
4500
4501#define CHECK_RANGE(range,expected_start,expected_end) \
4502 _check_range(range, expected_start, expected_end, __LINE__)
4503static void _check_range(ITextRange* range, LONG expected_start, LONG expected_end, int line)
4504{
4505 HRESULT hr;
4506 LONG value;
4507
4508 hr = ITextRange_GetStart(range, &value);
4509 ok_(__FILE__,line)(hr == S_OK, "GetStart failed: 0x%08lx\n", hr);
4510 ok_(__FILE__,line)(value == expected_start, "Expected start %ld got %ld\n",
4511 expected_start, value);
4512 hr = ITextRange_GetEnd(range, &value);
4513 ok_(__FILE__,line)(hr == S_OK, "GetEnd failed: 0x%08lx\n", hr);
4514 ok_(__FILE__,line)(value == expected_end, "Expected end %ld got %ld\n",
4515 expected_end, value);
4516}
4517
4518#define RESET_SELECTION(selection,start,end) \
4519 _reset_selection(selection, start, end, __LINE__)
4521{
4522 HRESULT hr;
4523
4524 hr = ITextSelection_SetStart(selection, start);
4525 ok_(__FILE__,line)(hr == S_OK, "SetStart failed: 0x%08lx\n", hr);
4526 hr = ITextSelection_SetEnd(selection, end);
4527 ok_(__FILE__,line)(hr == S_OK, "SetEnd failed: 0x%08lx\n", hr);
4528}
4529
4530#define CHECK_SELECTION(selection,expected_start,expected_end) \
4531 _check_selection(selection, expected_start, expected_end, __LINE__)
4532static void _check_selection(ITextSelection *selection, LONG expected_start, LONG expected_end, int line)
4533{
4534 HRESULT hr;
4535 LONG value;
4536
4537 hr = ITextSelection_GetStart(selection, &value);
4538 ok_(__FILE__,line)(hr == S_OK, "GetStart failed: 0x%08lx\n", hr);
4539 ok_(__FILE__,line)(value == expected_start, "Expected start %ld got %ld\n",
4540 expected_start, value);
4541 hr = ITextSelection_GetEnd(selection, &value);
4542 ok_(__FILE__,line)(hr == S_OK, "GetEnd failed: 0x%08lx\n", hr);
4543 ok_(__FILE__,line)(value == expected_end, "Expected end %ld got %ld\n",
4544 expected_end, value);
4545}
4546
4548{
4549 static const CHAR test_text1[] = "TestSomeText";
4550 ITextDocument *txtDoc = NULL;
4551 IRichEditOle *reOle = NULL;
4552 ITextRange *txtRge = NULL;
4553 HRESULT hr;
4554 HWND w;
4555
4556 create_interfaces(&w, &reOle, &txtDoc, NULL);
4557 SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
4558 ITextDocument_Range(txtDoc, 0, 0, &txtRge);
4559
4560 hr = ITextRange_SetRange(txtRge, 2, 4);
4561 ok(hr == S_OK, "got 0x%08lx.\n", hr);
4562 CHECK_RANGE(txtRge, 2, 4);
4563
4564 hr = ITextRange_SetRange(txtRge, 2, 4);
4565 ok(hr == S_FALSE, "got 0x%08lx.\n", hr);
4566 CHECK_RANGE(txtRge, 2, 4);
4567
4568 hr = ITextRange_SetRange(txtRge, 4, 2);
4569 ok(hr == S_FALSE, "got 0x%08lx.\n", hr);
4570 CHECK_RANGE(txtRge, 2, 4);
4571
4572 hr = ITextRange_SetRange(txtRge, 14, 14);
4573 ok(hr == S_OK, "got 0x%08lx.\n", hr);
4574 CHECK_RANGE(txtRge, 12, 12);
4575
4576 hr = ITextRange_SetRange(txtRge, 15, 15);
4577 ok(hr == S_FALSE, "got 0x%08lx.\n", hr);
4578 CHECK_RANGE(txtRge, 12, 12);
4579
4580 hr = ITextRange_SetRange(txtRge, 14, 1);
4581 ok(hr == S_OK, "got 0x%08lx.\n", hr);
4582 CHECK_RANGE(txtRge, 1, 13);
4583
4584 hr = ITextRange_SetRange(txtRge, -1, 4);
4585 ok(hr == S_OK, "got 0x%08lx.\n", hr);
4586 CHECK_RANGE(txtRge, 0, 4);
4587
4588 ITextRange_Release(txtRge);
4589 release_interfaces(&w, &reOle, &txtDoc, NULL);
4590}
4591
4592static void test_Expand(void)
4593{
4594 static const char test_text1[] = "TestSomeText";
4595 IRichEditOle *reole = NULL;
4596 ITextDocument *doc = NULL;
4599 LONG value;
4600 HRESULT hr;
4601 HWND hwnd;
4602
4603 create_interfaces(&hwnd, &reole, &doc, &selection);
4604 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4605 SendMessageA(hwnd, EM_SETSEL, 1, 2);
4606
4607 hr = ITextDocument_Range(doc, 0, 4, &range);
4608 ok(hr == S_OK, "got 0x%08lx\n", hr);
4609
4610 hr = ITextRange_Expand(range, tomStory, NULL);
4611 ok(hr == S_OK, "got 0x%08lx\n", hr);
4612 CHECK_RANGE(range, 0, 13);
4613
4614 hr = ITextSelection_Expand(selection, tomStory, NULL);
4615 ok(hr == S_OK, "got 0x%08lx\n", hr);
4616 CHECK_SELECTION(selection, 0, 13);
4617
4618 RESET_RANGE(range, 1, 2);
4620
4621 value = 0;
4622 hr = ITextRange_Expand(range, tomStory, &value);
4623 ok(hr == S_OK, "got 0x%08lx\n", hr);
4624 ok(value == 12, "got %ld\n", value);
4625 CHECK_RANGE(range, 0, 13);
4626
4627 value = 0;
4628 hr = ITextSelection_Expand(selection, tomStory, &value);
4629 ok(hr == S_OK, "got 0x%08lx\n", hr);
4630 ok(value == 12, "got %ld\n", value);
4631 CHECK_SELECTION(selection, 0, 13);
4632
4633 release_interfaces(&hwnd, &reole, &doc, NULL);
4634
4635 hr = ITextRange_Expand(range, tomStory, NULL);
4636 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4637
4638 hr = ITextRange_Expand(range, tomStory, &value);
4639 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4640
4641 hr = ITextSelection_Expand(selection, tomStory, NULL);
4642 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4643
4644 hr = ITextSelection_Expand(selection, tomStory, &value);
4645 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4646
4647 ITextSelection_Release(selection);
4648 ITextRange_Release(range);
4649}
4650
4651static void test_MoveEnd_story(void)
4652{
4653 static const char test_text1[] = "Word1 Word2";
4654 IRichEditOle *reole = NULL;
4655 ITextDocument *doc = NULL;
4658 LONG delta;
4659 HRESULT hr;
4660 HWND hwnd;
4661
4662 create_interfaces(&hwnd, &reole, &doc, &selection);
4663 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4664 SendMessageA(hwnd, EM_SETSEL, 1, 2);
4665
4666 hr = ITextDocument_Range(doc, 1, 2, &range);
4667 ok(hr == S_OK, "got 0x%08lx\n", hr);
4668
4669 hr = ITextRange_MoveEnd(range, tomStory, 0, &delta);
4670 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4671 ok(delta == 0, "got %ld\n", delta);
4672 CHECK_RANGE(range, 1, 2);
4673
4674 hr = ITextRange_MoveEnd(range, tomStory, -1, &delta);
4675 ok(hr == S_OK, "got 0x%08lx\n", hr);
4676 ok(delta == -1, "got %ld\n", delta);
4677 CHECK_RANGE(range, 0, 0);
4678
4679 hr = ITextRange_MoveEnd(range, tomStory, 1, &delta);
4680 ok(hr == S_OK, "got 0x%08lx\n", hr);
4681 ok(delta == 1, "got %ld\n", delta);
4682 CHECK_RANGE(range, 0, 12);
4683
4684 hr = ITextRange_MoveEnd(range, tomStory, 1, &delta);
4685 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4686 ok(delta == 0, "got %ld\n", delta);
4687 CHECK_RANGE(range, 0, 12);
4688
4689 RESET_RANGE(range, 1, 2);
4690
4691 hr = ITextRange_MoveEnd(range, tomStory, 3, &delta);
4692 ok(hr == S_OK, "got 0x%08lx\n", hr);
4693 ok(delta == 1, "got %ld\n", delta);
4694 CHECK_RANGE(range, 1, 12);
4695
4696 RESET_RANGE(range, 2, 3);
4697
4698 hr = ITextRange_MoveEnd(range, tomStory, -3, &delta);
4699 ok(hr == S_OK, "got 0x%08lx\n", hr);
4700 ok(delta == -1, "got %ld\n", delta);
4701 CHECK_RANGE(range, 0, 0);
4702
4703 hr = ITextRange_MoveEnd(range, tomStory, -1, &delta);
4704 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4705 ok(delta == 0, "got %ld\n", delta);
4706 CHECK_RANGE(range, 0, 0);
4707
4708 hr = ITextSelection_MoveEnd(selection, tomStory, 0, &delta);
4709 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4710 ok(delta == 0, "got %ld\n", delta);
4712
4713 hr = ITextSelection_MoveEnd(selection, tomStory, -1, &delta);
4714 ok(hr == S_OK, "got 0x%08lx\n", hr);
4715 ok(delta == -1, "got %ld\n", delta);
4717
4718 hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta);
4719 ok(hr == S_OK, "got 0x%08lx\n", hr);
4720 ok(delta == 1, "got %ld\n", delta);
4721 CHECK_SELECTION(selection, 0, 12);
4722
4723 hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta);
4724 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4725 ok(delta == 0, "got %ld\n", delta);
4726 CHECK_SELECTION(selection, 0, 12);
4727
4729
4730 hr = ITextSelection_MoveEnd(selection, tomStory, 3, &delta);
4731 ok(hr == S_OK, "got 0x%08lx\n", hr);
4732 ok(delta == 1, "got %ld\n", delta);
4733 CHECK_SELECTION(selection, 1, 12);
4734
4736
4737 hr = ITextSelection_MoveEnd(selection, tomStory, -3, &delta);
4738 ok(hr == S_OK, "got 0x%08lx\n", hr);
4739 ok(delta == -1, "got %ld\n", delta);
4741
4742 hr = ITextSelection_MoveEnd(selection, tomStory, -1, &delta);
4743 ok(hr == S_FALSE, "got 0x%08lx\n", hr);
4744 ok(delta == 0, "got %ld\n", delta);
4746
4747 release_interfaces(&hwnd, &reole, &doc, NULL);
4748
4749 hr = ITextRange_MoveEnd(range, tomStory, 1, NULL);
4750 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4751
4752 hr = ITextRange_MoveEnd(range, tomStory, 1, &delta);
4753 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4754
4755 hr = ITextSelection_MoveEnd(selection, tomStory, 1, NULL);
4756 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4757
4758 hr = ITextSelection_MoveEnd(selection, tomStory, 1, &delta);
4759 ok(hr == CO_E_RELEASED, "got 0x%08lx\n", hr);
4760
4761 ITextSelection_Release(selection);
4762 ITextRange_Release(range);
4763}
4764
4765static void test_character_movestart(ITextRange *range, int textlen, int i, int j, LONG target)
4766{
4767 HRESULT hr;
4768 LONG delta = 0;
4769 LONG expected_delta;
4770 LONG expected_start = target;
4771
4772 if (expected_start < 0)
4773 expected_start = 0;
4774 else if (expected_start > textlen)
4775 expected_start = textlen;
4776 expected_delta = expected_start - i;
4777 hr = ITextRange_SetRange(range, i, j);
4778 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4779 hr = ITextRange_MoveStart(range, tomCharacter, target - i, &delta);
4780 if (expected_start == i) {
4781 ok(hr == S_FALSE, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, target - i, hr);
4782 ok(delta == 0, "(%d,%d) move by %ld got delta %ld\n", i, j, target - i, delta);
4783 CHECK_RANGE(range, i, j);
4784 } else {
4785 ok(hr == S_OK, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, target - i, hr);
4786 ok(delta == expected_delta, "(%d,%d) move by %ld got delta %ld\n", i, j, target - i, delta);
4787 if (expected_start <= j)
4788 CHECK_RANGE(range, expected_start, j);
4789 else
4790 CHECK_RANGE(range, expected_start, expected_start);
4791 }
4792}
4793
4794static void test_character_moveend(ITextRange *range, int textlen, int i, int j, LONG target)
4795{
4796 HRESULT hr;
4797 LONG delta;
4798 LONG expected_delta;
4799 LONG expected_end = target;
4800
4801 if (expected_end < 0)
4802 expected_end = 0;
4803 else if (expected_end > textlen + 1)
4804 expected_end = textlen + 1;
4805 expected_delta = expected_end - j;
4806 hr = ITextRange_SetRange(range, i, j);
4807 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4808 hr = ITextRange_MoveEnd(range, tomCharacter, target - j, &delta);
4809 if (expected_end == j) {
4810 ok(hr == S_FALSE, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, target - j, hr);
4811 ok(delta == 0, "(%d,%d) move by %ld got delta %ld\n", i, j, target - j, delta);
4812 CHECK_RANGE(range, i, j);
4813 } else {
4814 ok(hr == S_OK, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, target - j, hr);
4815 ok(delta == expected_delta, "(%d,%d) move by %ld got delta %ld\n", i, j, target - j, delta);
4816 if (i <= expected_end)
4817 CHECK_RANGE(range, i, expected_end);
4818 else
4819 CHECK_RANGE(range, expected_end, expected_end);
4820 }
4821}
4822
4823static void test_character_move(ITextRange *range, int textlen, int i, int j, LONG target)
4824{
4825 HRESULT hr;
4826 LONG move_by;
4827 LONG delta = 0;
4828 LONG expected_delta;
4829 LONG expected_location = target;
4830
4831 if (expected_location < 0)
4832 expected_location = 0;
4833 else if (expected_location > textlen)
4834 expected_location = textlen;
4835
4836 if (target <= i) {
4837 move_by = target - i;
4838 expected_delta = expected_location - i;
4839 if (i != j) {
4840 --move_by;
4841 --expected_delta;
4842 }
4843 } else if (j <= target) {
4844 move_by = target - j;
4845 expected_delta = expected_location - j;
4846 if (i != j) {
4847 ++move_by;
4848 ++expected_delta;
4849 }
4850 } else {
4851 /* There's no way to move to a point between start and end: */
4852 return;
4853 }
4854
4855 hr = ITextRange_SetRange(range, i, j);
4856 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4857 hr = ITextRange_Move(range, tomCharacter, move_by, &delta);
4858 if (expected_delta == 0) {
4859 ok(hr == S_FALSE, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, move_by, hr);
4860 ok(delta == 0, "(%d,%d) move by %ld got delta %ld\n", i, j, move_by, delta);
4861 CHECK_RANGE(range, expected_location, expected_location);
4862 } else {
4863 ok(hr == S_OK, "(%d,%d) move by %ld got hr=0x%08lx\n", i, j, move_by, hr);
4864 ok(delta == expected_delta, "(%d,%d) move by %ld got delta %ld\n", i, j, move_by, delta);
4865 CHECK_RANGE(range, expected_location, expected_location);
4866 }
4867}
4868
4869static void test_character_startof(ITextRange *range, int textlen, int i, int j)
4870{
4871 HRESULT hr;
4872 LONG delta;
4873
4874 hr = ITextRange_SetRange(range, i, j);
4875 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4876 hr = ITextRange_StartOf(range, tomCharacter, tomMove, &delta);
4877 if (i == j) {
4878 ok(hr == S_FALSE, "(%d,%d) tomMove got hr=0x%08lx\n", i, j, hr);
4879 ok(delta == 0, "(%d,%d) tomMove got delta %ld\n", i, j, delta);
4880 } else {
4881 ok(hr == S_OK, "(%d,%d) tomMove got hr=0x%08lx\n", i, j, hr);
4882 ok(delta == -1, "(%d,%d) tomMove got delta %ld\n", i, j, delta);
4883 }
4884 CHECK_RANGE(range, i, i);
4885
4886 hr = ITextRange_SetRange(range, i, j);
4887 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4888 hr = ITextRange_StartOf(range, tomCharacter, tomExtend, &delta);
4889 ok(hr == S_FALSE, "(%d,%d) tomExtend got hr=0x%08lx\n", i, j, hr);
4890 ok(delta == 0, "(%d,%d) tomExtend got delta %ld\n", i, j, delta);
4891 CHECK_RANGE(range, i, j);
4892}
4893
4894static void test_character_endof(ITextRange *range, int textlen, int i, int j)
4895{
4896 HRESULT hr;
4897 LONG end;
4898 LONG delta;
4899
4900 hr = ITextRange_SetRange(range, i, j);
4901 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4902 hr = ITextRange_EndOf(range, tomCharacter, tomMove, &delta);
4903
4904 /* A character "end", apparently cannot be before the very first character */
4905 end = j;
4906 if (j == 0)
4907 ++end;
4908
4909 if (i == end) {
4910 ok(hr == S_FALSE, "(%d,%d) tomMove got hr=0x%08lx\n", i, j, hr);
4911 ok(delta == 0, "(%d,%d) tomMove got delta %ld\n", i, j, delta);
4912 } else {
4913 ok(hr == S_OK, "(%d,%d) tomMove got hr=0x%08lx\n", i, j, hr);
4914 ok(delta == 1, "(%d,%d) tomMove got delta %ld\n", i, j, delta);
4915 }
4917
4918 hr = ITextRange_SetRange(range, i, j);
4919 ok(SUCCEEDED(hr), "got 0x%08lx\n", hr);
4920 hr = ITextRange_EndOf(range, tomCharacter, tomExtend, &delta);
4921 if (0 < j) {
4922 ok(hr == S_FALSE, "(%d,%d) tomExtend got hr=0x%08lx\n", i, j, hr);
4923 ok(delta == 0, "(%d,%d) tomExtend got delta %ld\n", i, j, delta);
4924 } else {
4925 ok(hr == S_OK, "(%d,%d) tomExtend got hr=0x%08lx\n", i, j, hr);
4926 ok(delta == 1, "(%d,%d) tomExtend got delta %ld\n", i, j, delta);
4927 }
4929}
4930
4932{
4933 static const char test_text1[] = "ab\n c";
4934 IRichEditOle *reole = NULL;
4935 ITextDocument *doc = NULL;
4938 HRESULT hr;
4939 HWND hwnd;
4940 int i, j;
4941 const int textlen = strlen(test_text1);
4942
4943 create_interfaces(&hwnd, &reole, &doc, &selection);
4944 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1);
4945
4946 hr = ITextDocument_Range(doc, 0, 0, &range);
4947 ok(hr == S_OK, "got 0x%08lx\n", hr);
4948
4949 /* Exhaustive test of every possible combination of (start,end) locations,
4950 * against every possible target location to move to. */
4951 for (i = 0; i <= textlen; i++) {
4952 for (j = i; j <= textlen; j++) {
4953 LONG target;
4954 for (target = -2; target <= textlen + 3; target++) {
4955 test_character_moveend(range, textlen, i, j, target);
4957 test_character_move(range, textlen, i, j, target);
4958 }
4959 test_character_startof(range, textlen, i, j);
4960 test_character_endof(range, textlen, i, j);
4961 }
4962 }
4963
4964 release_interfaces(&hwnd, &reole, &doc, NULL);
4965 ITextSelection_Release(selection);
4966 ITextRange_Release(range);
4967}
4968
4970{
4972 while (1)
4973 {
4976 return ret;
4977 if (GetTickCount() - start > 100)
4978 {
4979 char classname[256];
4980 DWORD le = GetLastError();
4981 HWND clipwnd = GetOpenClipboardWindow();
4982 /* Provide a hint as to the source of interference:
4983 * - The class name would typically be CLIPBRDWNDCLASS if the
4984 * clipboard was opened by a Windows application using the
4985 * ole32 API.
4986 * - And it would be __wine_clipboard_manager if it was opened in
4987 * response to a native application.
4988 */
4990 trace("%p (%s) opened the clipboard\n", clipwnd, classname);
4991 SetLastError(le);
4992 return ret;
4993 }
4994 Sleep(15);
4995 }
4996}
4997
4998#define CLIPBOARD_RANGE_CONTAINS(range, start, end, expected) _clipboard_range_contains(range, start, end, expected, __LINE__, 0);
4999#define TODO_CLIPBOARD_RANGE_CONTAINS(range, start, end, expected) _clipboard_range_contains(range, start, end, expected, __LINE__, 1);
5001{
5002 HRESULT hr;
5003 BOOL clipboard_open;
5005 const char *clipboard_text;
5006
5007 hr = ITextRange_SetRange(range, start, end);
5008 ok_(__FILE__,line)(SUCCEEDED(hr), "SetRange failed: 0x%08lx\n", hr);
5009 hr = ITextRange_Copy(range, NULL);
5010 ok_(__FILE__,line)(hr == S_OK, "Copy failed: 0x%08lx\n", hr);
5011
5012 clipboard_open = open_clipboard(NULL);
5013 ok_(__FILE__,line)(clipboard_open, "OpenClipboard failed: %ld\n", GetLastError());
5015 ok_(__FILE__,line)(global != NULL, "GetClipboardData failed: %p\n", global);
5016 clipboard_text = GlobalLock(global);
5017 ok_(__FILE__,line)(clipboard_text != NULL, "GlobalLock failed: %p\n", clipboard_text);
5018#ifdef __REACTOS__
5019 if (expected != NULL && clipboard_text != NULL)
5020 todo_wine_if(todo) ok_(__FILE__,line)(!strcmp(expected, clipboard_text), "unexpected contents: %s\n", wine_dbgstr_a(clipboard_text));
5021 else
5022 todo_wine_if(todo) ok_(__FILE__,line)(FALSE, "Either 'expected' or 'clipboard_text' was NULL\n");
5023#else
5024 todo_wine_if(todo) ok_(__FILE__,line)(!strcmp(expected, clipboard_text), "unexpected contents: %s\n", wine_dbgstr_a(clipboard_text));
5025#endif
5028}
5029
5030static void test_clipboard(void)
5031{
5032 static const char text_in[] = "ab\n c";
5033 IRichEditOle *reole = NULL;
5034 ITextDocument *doc = NULL;
5037 HRESULT hr;
5038 HWND hwnd;
5039
5040 create_interfaces(&hwnd, &reole, &doc, &selection);
5041 SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)text_in);
5042
5043 hr = ITextDocument_Range(doc, 0, 0, &range);
5044 ok(hr == S_OK, "got 0x%08lx\n", hr);
5045
5046 CLIPBOARD_RANGE_CONTAINS(range, 0, 5, "ab\r\n c")
5047 CLIPBOARD_RANGE_CONTAINS(range, 0, 0, "ab\r\n c")
5048 CLIPBOARD_RANGE_CONTAINS(range, 1, 1, "ab\r\n c")
5051
5052 /* Setting password char does not stop Copy */
5055
5056 /* Cut can be undone */
5057 hr = ITextRange_SetRange(range, 0, 1);
5058 ok(SUCCEEDED(hr), "SetRange failed: 0x%08lx\n", hr);
5059 hr = ITextRange_Cut(range, NULL);
5060 ok(hr == S_OK, "Cut failed: 0x%08lx\n", hr);
5061 CLIPBOARD_RANGE_CONTAINS(range, 0, 4, "b\r\n c");
5062 hr = ITextDocument_Undo(doc, 1, NULL);
5063 ok(hr == S_OK, "Undo failed: 0x%08lx\n", hr);
5064 CLIPBOARD_RANGE_CONTAINS(range, 0, 5, "ab\r\n c");
5065
5066 /* Cannot cut when read-only */
5068 hr = ITextRange_SetRange(range, 0, 1);
5069 ok(SUCCEEDED(hr), "SetRange failed: 0x%08lx\n", hr);
5070 hr = ITextRange_Cut(range, NULL);
5071 ok(hr == E_ACCESSDENIED, "got 0x%08lx\n", hr);
5072
5073 release_interfaces(&hwnd, &reole, &doc, NULL);
5074 ITextSelection_Release(selection);
5075 ITextRange_Release(range);
5076}
5077
5078static void subtest_undo(const char *dummy_text)
5079{
5080 static const char *text_seq[] = {
5081 "",
5082 "1-alpha",
5083 "2-beta",
5084 "3-gamma",
5085 "4-delta",
5086 "5-epsilon",
5087 "6-zeta",
5088 "7-eta",
5089 };
5090 static LONG seq[] = { -1, -2, -3, -1, 1, 2, 3, 1, -5, 2, -1, 3, 1, 0 };
5091 LONG i = 0, stack_pos = 0;
5092 IRichEditOle *reole = NULL;
5093 ITextDocument *doc = NULL;
5095 char buffer[1024] = "";
5096 HRESULT hr;
5097 HWND hwnd;
5098 LONG count = 0;
5099
5100 winetest_push_context("(%Iu)", dummy_text ? strlen(dummy_text) : 0);
5101
5102 create_interfaces(&hwnd, &reole, &doc, &selection);
5103
5104 for (i = -2; i <= 2; i++)
5105 {
5106 if (i != tomFalse && i != tomTrue)
5107 {
5108 hr = ITextDocument_Undo(doc, i, NULL);
5109 todo_wine_if(i >= 1)
5110 ok(hr == (i >= 1 ? S_OK : S_FALSE), "(%ld@0) Undo: %#lx\n", i, hr);
5111
5112 count = 0xcccccccc;
5113 hr = ITextDocument_Undo(doc, i, &count);
5114 todo_wine_if(i >= 1)
5115 ok(hr == (i >= 1 ? S_OK : S_FALSE), "(%ld@0) Undo: %#lx\n", i, hr);
5116 todo_wine_if(i >= 1)
5117 ok(count == (i >= 1 ? i : 0), "(%ld@0) Expected %ld, got %ld\n", i, i >= 0 ? i : 0, count);
5118 }
5119
5120 hr = ITextDocument_Redo(doc, i, NULL);
5121 ok(hr == (i == 0 ? S_OK : S_FALSE), "(%ld@0) Redo: %#lx\n", i, hr);
5122
5123 count = 0xcccccccc;
5124 hr = ITextDocument_Redo(doc, i, &count);
5125 ok(hr == (i == 0 ? S_OK : S_FALSE), "(%ld@0) Redo: %#lx\n", i, hr);
5126 ok(count == 0, "(%ld@0) got %ld\n", i, count);
5127 }
5128
5129 while (stack_pos < ARRAY_SIZE(text_seq) - 1)
5130 {
5131 stack_pos++;
5132 if (dummy_text)
5133 {
5134 hr = ITextDocument_Undo(doc, tomSuspend, NULL);
5135 ok(hr == S_FALSE, "(@%ld) Undo: %#lx\n", stack_pos, hr);
5136 if (SUCCEEDED(hr))
5137 {
5138 SendMessageA(hwnd, EM_SETSEL, 0, 0);
5139 SendMessageA(hwnd, EM_REPLACESEL, TRUE, (LPARAM)dummy_text);
5140 SendMessageA(hwnd, EM_SETSEL, 0, strlen(dummy_text));
5142 hr = ITextDocument_Undo(doc, tomResume, NULL);
5143 ok(hr == S_FALSE, "(@%ld) Undo: %#lx\n", stack_pos, hr);
5144 }
5145 }
5146 SendMessageA(hwnd, EM_SETSEL, 0, -1);
5147 SendMessageA(hwnd, EM_REPLACESEL, TRUE, (LPARAM)text_seq[stack_pos]);
5148 }
5149
5150 for (i = 0; i < ARRAY_SIZE(seq); i++)
5151 {
5152 LONG expect_count;
5153
5154 memset(buffer, 0, sizeof(buffer));
5156 ok(strcmp(buffer, text_seq[stack_pos]) == 0, "Expected %s, got %s\n",
5157 wine_dbgstr_a(text_seq[stack_pos]), wine_dbgstr_a(buffer));
5158
5159 if (!seq[i]) break;
5160
5161 count = 0xcccccccc;
5162 expect_count = labs(stack_pos - min(max(stack_pos + seq[i], 0), (LONG)ARRAY_SIZE(seq) - 1));
5163 if (seq[i] < 0)
5164 {
5165 hr = ITextDocument_Undo(doc, -seq[i], &count);
5166 ok(hr == S_OK, "(%ld@%ld) Undo: %#lx\n", i, stack_pos, hr);
5167 ok(count == expect_count, "(%ld@%ld) Expected %ld, got %ld\n", i, stack_pos, expect_count, count);
5168 stack_pos -= count;
5169 }
5170 else
5171 {
5172 hr = ITextDocument_Redo(doc, seq[i], &count);
5173 ok(hr == (expect_count ? S_OK : S_FALSE), "(%ld@%ld) Redo: %#lx\n", i, stack_pos, hr);
5174 ok(count == expect_count, "(%ld@%ld) Expected %ld, got %ld\n", i, stack_pos, expect_count, count);
5175 stack_pos += count;
5176 }
5177
5178 if (FAILED(hr) || count <= 0) break;
5179 }
5180
5181 release_interfaces(&hwnd, &reole, &doc, &selection);
5183}
5184
5185static void test_undo(void)
5186{
5188 subtest_undo("dummy 12345");
5189}
5190
5191#define ok_msg_result(h,m,w,l,r) ok_msg_result_(__LINE__,#m,h,m,w,l,r)
5193{
5195 ok_(__FILE__,line)(lresult == expect, "%s: Expected %Id, got %Id\n", desc, expect, lresult);
5196}
5197
5204};
5205
5213 numUndoActions = 5
5215
5223};
5224
5226{
5234};
5235
5237{
5238 HRESULT hr = S_OK;
5239
5240 if (count) *count = 0xcccccccc;
5241
5242 switch (action)
5243 {
5244 case undoActionNoOp:
5245 if (count) *count = 0;
5246 break;
5247 case undoActionEnable:
5249 {
5250 LONG_PTR cur_undo_limit = SendMessageA(inst->hwnd, EM_SETUNDOLIMIT, inst->undo_limit, 0);
5251 ok(cur_undo_limit == inst->undo_limit, "Expected undo limit %Id, got %Id\n",
5252 inst->undo_limit, cur_undo_limit);
5253 if (count) *count = 0;
5254 }
5255 else
5256 {
5257 hr = ITextDocument_Undo(inst->doc, tomTrue, count);
5258 ok(hr == S_FALSE, "Undo: %#lx\n", hr);
5259 }
5260 if (SUCCEEDED(hr))
5261 {
5262 if (inst->undo_ctl_state == undoStateDisabled)
5263 {
5265 }
5266 inst->last_undo_status = TRUE;
5267 }
5268 break;
5269 case undoActionDisable:
5270 hr = ITextDocument_Undo(inst->doc, tomFalse, count);
5271 ok(hr == S_OK, "Undo: %#lx\n", hr);
5272 if (SUCCEEDED(hr))
5273 {
5275 inst->last_undo_status = FALSE;
5276 inst->last_redo_status = FALSE;
5277 }
5278 break;
5279 case undoActionSuspend:
5280 hr = ITextDocument_Undo(inst->doc, tomSuspend, count);
5281 ok(hr == S_FALSE, "Undo: %#lx\n", hr);
5282 if (SUCCEEDED(hr) && inst->undo_ctl_state == undoStateActive)
5283 {
5285 }
5286 break;
5287 case undoActionResume:
5288 hr = ITextDocument_Undo(inst->doc, tomResume, count);
5289 ok(hr == S_FALSE, "Undo: %#lx\n", hr);
5290 if (SUCCEEDED(hr))
5291 {
5293 }
5294 break;
5295 default:
5296 ok(0, "unreachable\n");
5297 break;
5298 }
5299
5300 if (count)
5301 {
5302 ok(*count == 0, "Got %ld\n", *count);
5303 }
5304 return hr;
5305}
5306
5308{
5309 HRESULT hr = S_OK;
5310 if (inst->undo_ctl_state == state) return hr;
5311 switch (state)
5312 {
5313 case undoStateActive:
5316 break;
5317 case undoStateSuspended:
5320 break;
5321 case undoStateDisabled:
5323 break;
5324 default:
5325 ok(0, "unreachable\n");
5326 break;
5327 }
5328 ok(inst->undo_ctl_state == state, "expected state %d, got %d\n", state, inst->undo_ctl_state);
5329 ok(SUCCEEDED(hr), "cannot set state to %d: %#lx\n", undoStateActive, hr);
5330 return hr;
5331}
5332
5333#define perform_undo(i,c) perform_undo_(i,c,__LINE__)
5334static BOOL perform_undo_(struct undo_test *inst, BOOL can_undo, int line)
5335{
5336 LONG count;
5337 HRESULT hr;
5339
5341 {
5342 LRESULT lres = SendMessageA(inst->hwnd, EM_UNDO, 0, 0);
5343 ok_(__FILE__, line)(lres == FALSE || lres == TRUE, "unexpected LRESULT %#Ix\n", lres);
5344 result = lres;
5345 }
5346 else
5347 {
5348 count = 0xcccccccc;
5349 hr = ITextDocument_Undo(inst->doc, 1, &count);
5350 ok_(__FILE__, line)(SUCCEEDED(hr), "got hr %#lx\n", hr);
5351 ok_(__FILE__, line)(count == (hr == S_OK), "expected count %d, got %ld\n", hr == S_OK, count);
5352 result = hr == S_OK && count > 0;
5353 }
5354
5355 expect = FALSE;
5356 if (inst->undo_ctl_state == undoStateActive)
5357 {
5358 if (can_undo) inst->last_undo_status = TRUE;
5359 expect = inst->last_undo_status;
5360 }
5361 todo_wine_if(!can_undo && !result && expect)
5362 ok_(__FILE__, line)(result == expect, "state %d: expected %d, got %d\n", inst->undo_ctl_state, expect, result);
5363
5364 return can_undo && result;
5365}
5366
5367#define perform_redo(i,c) perform_redo_(i,c,__LINE__)
5368static BOOL perform_redo_(struct undo_test *inst, BOOL can_redo, int line)
5369{
5370 LONG count;
5371 HRESULT hr;
5373
5375 {
5376 LRESULT lres = SendMessageA(inst->hwnd, EM_REDO, 0, 0);
5377 ok_(__FILE__, line)(lres == FALSE || lres == TRUE, "unexpected LRESULT %#Ix\n", lres);
5378 result = lres;
5379 }
5380 else
5381 {
5382 count = 0xcccccccc;
5383 hr = ITextDocument_Redo(inst->doc, 1, &count);
5384 ok_(__FILE__, line)(SUCCEEDED(hr), "got hr %#lx\n", hr);
5385 ok_(__FILE__, line)(count == (hr == S_OK), "expected count %d, got %ld\n", hr == S_OK, count);
5386 result = hr == S_OK && count > 0;
5387 }
5388
5389 expect = FALSE;
5390 if (inst->undo_ctl_state == undoStateActive)
5391 {
5392 if (can_redo) inst->last_redo_status = TRUE;
5393 expect = inst->last_redo_status;
5394 }
5395 todo_wine_if(!can_redo && !result && expect)
5396 ok_(__FILE__, line)(result == expect, "state %d: expected %d, got %d\n", inst->undo_ctl_state, expect, result);
5397
5398 return can_redo && result;
5399}
5400
5402{
5403 LONG undo_count, redo_count, count;
5404 static const char text_foo[] = "foo";
5405 static const char text_bar[] = "bar";
5406 static const char *last_text, *last_text2;
5407 char buffer[1024] = "";
5408 HRESULT hr;
5409
5410 SendMessageA(inst->hwnd, EM_EMPTYUNDOBUFFER, 0, 0);
5411 undo_count = redo_count = 0;
5412 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5413 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5414
5415 SendMessageA(inst->hwnd, WM_SETTEXT, 0, (LPARAM)(last_text = ""));
5417 last_text = "";
5418 ok(strcmp(buffer, last_text) == 0,
5419 "Expected %s, got %s\n", wine_dbgstr_a(""), wine_dbgstr_a(buffer));
5420
5421 SendMessageA(inst->hwnd, EM_SETSEL, 0, -1);
5422 SendMessageA(inst->hwnd, EM_REPLACESEL, TRUE, (LPARAM)(last_text = text_foo));
5423 if (inst->undo_ctl_state == undoStateActive) undo_count++, redo_count = 0;
5424 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5425 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5427 ok(strcmp(buffer, last_text) == 0, "Expected %s, got %s\n", wine_dbgstr_a(text_foo), wine_dbgstr_a(buffer));
5428
5430 ok(SUCCEEDED(hr), "got %#lx\n", hr);
5431 if (FAILED(hr)) return hr;
5432 if (inst->undo_ctl_state == undoStateDisabled) undo_count = redo_count = 0;
5433 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5434 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5435
5436 if (inst->test_flags & undoTestDoFirstUndo)
5437 {
5438 if (perform_undo(inst, undo_count > 0)) undo_count--, redo_count++, last_text = "";
5439 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5440 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5442 ok(strcmp(buffer, last_text) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text), wine_dbgstr_a(buffer));
5443 }
5444
5446 {
5448 ok(SUCCEEDED(hr), "got %#lx\n", hr);
5449 if (FAILED(hr)) return hr;
5450 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5451 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5452
5453 if (perform_undo(inst, undo_count > 0)) undo_count--, redo_count++, last_text = "";
5454 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5455 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5457 ok(strcmp(buffer, last_text) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text), wine_dbgstr_a(buffer));
5458 }
5459
5460 if (inst->test_flags & undoTestDoFirstRedo)
5461 {
5462 if (perform_redo(inst, redo_count > 0)) undo_count++, redo_count--, last_text = text_foo;
5463 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5464 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5466 ok(strcmp(buffer, last_text) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text), wine_dbgstr_a(buffer));
5467 }
5468
5469 SendMessageA(inst->hwnd, EM_SETSEL, 0, -1);
5470 SendMessageA(inst->hwnd, EM_REPLACESEL, TRUE, (LPARAM)(last_text2 = text_bar));
5471 if (inst->undo_ctl_state == undoStateActive) undo_count++, redo_count = 0;
5472 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5473 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5475 ok(strcmp(buffer, last_text2) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text2), wine_dbgstr_a(buffer));
5476
5477 if (perform_undo(inst, undo_count > 0)) undo_count--, redo_count++, last_text2 = last_text;
5478 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5479 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5481 ok(strcmp(buffer, last_text2) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text2), wine_dbgstr_a(buffer));
5482
5483 if (perform_redo(inst, redo_count > 0)) undo_count++, redo_count--, last_text2 = text_bar;
5484 ok_msg_result(inst->hwnd, EM_CANUNDO, 0, 0, undo_count > 0);
5485 ok_msg_result(inst->hwnd, EM_CANREDO, 0, 0, redo_count > 0);
5487 ok(strcmp(buffer, last_text2) == 0, "Expected %s, got %s\n", wine_dbgstr_a(last_text2), wine_dbgstr_a(buffer));
5488
5489 return S_OK;
5490}
5491
5492static void test_undo_control(void)
5493{
5494 enum editorUndoState state0;
5495 enum editorUndoStateAction action0, action1;
5496 IRichEditOle *reole = NULL;
5498 struct undo_test inst = { NULL };
5499 HRESULT hr;
5500
5501 create_interfaces(&inst.hwnd, &reole, &inst.doc, &selection);
5503 inst.last_undo_status = TRUE;
5504 inst.last_redo_status = TRUE;
5505 inst.undo_limit = SendMessageA(inst.hwnd, EM_SETUNDOLIMIT, 100, 0);
5506 ok(inst.undo_limit >= 1, "Message EM_SETUNDOLIMIT returned %#Ix\n", inst.undo_limit);
5507
5508 if (SUCCEEDED(ITextDocument_Undo(inst.doc, 1, NULL)))
5509 {
5510 for (inst.test_flags = 0; inst.test_flags < undoTestMaxFlag; inst.test_flags++)
5511 {
5512 for (state0 = firstUndoState; state0 < numUndoStates; state0++)
5513 {
5514 for (action0 = firstUndoAction; action0 < numUndoActions; action0++)
5515 {
5516 for (action1 = firstUndoAction; action1 < numUndoActions; action1++)
5517 {
5518 winetest_push_context("%x:%d:%d >?:%d", inst.test_flags, state0, action0, action1);
5519 hr = set_editor_undo_state(&inst, state0);
5521
5522 if (FAILED(hr)) continue;
5523
5524 winetest_push_context("%x:%d:%d+>?:%d", inst.test_flags, state0, action0, action1);
5525 hr = subtest_undo_control(&inst, action0);
5527
5528 if (FAILED(hr)) continue;
5529
5530 winetest_push_context("%x:%d:%d>%d:%d+", inst.test_flags, state0, action0, inst.undo_ctl_state, action1);
5531 subtest_undo_control(&inst, action1);
5533 }
5534 }
5535 }
5536 }
5537 }
5538
5539 release_interfaces(&inst.hwnd, &reole, &inst.doc, &selection);
5540}
5541
5542static void test_freeze(void)
5543{
5545 DWORD lasterr, style1, style2;
5546 IRichEditOle *reole = NULL;
5548 HRESULT hr;
5549 LONG count;
5550 HWND hwnd;
5551
5552 create_interfaces(&hwnd, &reole, &doc, &selection);
5553
5554 SetLastError(0xdeadbeef);
5555 style1 = GetWindowLongW(hwnd, GWL_STYLE);
5556 lasterr = GetLastError();
5557 ok(lasterr == 0xdeadbeefUL, "GetLastError() returned %#lx\n", lasterr);
5558
5559 count = 0xdeadbeef;
5560 hr = ITextDocument_Freeze(doc, &count);
5561 ok(hr == S_OK, "ITextDocument_Freeze returned %#lx\n", hr);
5562 ok(count == 1, "expected count to be %d, got %ld\n", 1, count);
5563
5564 style2 = GetWindowLongW(hwnd, GWL_STYLE);
5565 ok(style2 == style1, "expected window style to not change from %#lx, got %#lx\n", style1, style2);
5566
5567 count = 0xdeadbeef;
5568 hr = ITextDocument_Freeze(doc, &count);
5569 ok(hr == S_OK, "ITextDocument_Freeze returned %#lx\n", hr);
5570 ok(count == 2, "expected count to be %d, got %ld\n", 2, count);
5571
5572 count = 0xdeadbeef;
5573 hr = ITextDocument_Unfreeze(doc, &count);
5574 ok(hr == S_FALSE, "ITextDocument_Unfreeze returned %#lx\n", hr);
5575 ok(count == 1, "expected count to be %d, got %ld\n", 1, count);
5576
5577 count = 0xdeadbeef;
5578 hr = ITextDocument_Unfreeze(doc, &count);
5579 ok(hr == S_OK, "ITextDocument_Unfreeze returned %#lx\n", hr);
5580 ok(count == 0, "expected count to be %d, got %ld\n", 0, count);
5581
5582 count = 0xdeadbeef;
5583 hr = ITextDocument_Unfreeze(doc, &count);
5584 ok(hr == S_OK, "ITextDocument_Unfreeze returned %#lx\n", hr);
5585 ok(count == 0, "expected count to be %d, got %ld\n", 0, count);
5586
5587 count = 0xdeadbeef;
5588 hr = ITextDocument_Freeze(doc, &count);
5589 ok(hr == S_OK, "ITextDocument_Freeze returned %#lx\n", hr);
5590 ok(count == 1, "expected count to be %d, got %ld\n", 1, count);
5591
5592 count = 0xdeadbeef;
5593 hr = ITextDocument_Unfreeze(doc, &count);
5594 ok(hr == S_OK, "ITextDocument_Unfreeze returned %#lx\n", hr);
5595 ok(count == 0, "expected count to be %d, got %ld\n", 0, count);
5596
5597 count = 0xdeadbeef;
5598 hr = ITextDocument_Freeze(doc, NULL);
5599 ok(hr == S_OK, "ITextDocument_Freeze returned %#lx\n", hr);
5600
5601 count = 0xdeadbeef;
5602 hr = ITextDocument_Unfreeze(doc, NULL);
5603 ok(hr == S_OK, "ITextDocument_Unfreeze returned %#lx\n", hr);
5604
5605 release_interfaces(&hwnd, &reole, &doc, &selection);
5606}
5607
5609{
5610 /* Must explicitly LoadLibrary(). The test has no references to functions in
5611 * RICHED20.DLL, so the linker doesn't actually link to it. */
5612 hmoduleRichEdit = LoadLibraryA("riched20.dll");
5613 ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
5614
5617 test_GetText();
5631 test_GetFont();
5632 test_GetPara();
5633 test_dispatch();
5635 test_Delete();
5636 test_SetText();
5637 test_InRange();
5639 test_Select();
5641 test_SetFont();
5645 test_Expand();
5649 test_undo();
5651 test_freeze();
5652}
@ lparam
Definition: SystemMenu.c:31
@ wparam
Definition: SystemMenu.c:30
#define expect(EXPECTED, GOT)
Definition: SystemMenu.c:483
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static int state
Definition: maze.c:121
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
#define msg(x)
Definition: auth_time.c:54
static const WCHAR nameW[]
Definition: main.c:49
#define CF_UNICODETEXT
Definition: constants.h:408
#define CF_TEXT
Definition: constants.h:396
void user(int argc, const char *argv[])
Definition: cmds.c:1350
#define ARRAY_SIZE(A)
Definition: main.h:20
const GUID IID_IUnknown
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
int selection
Definition: ctm.c:92
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
key_state
Definition: listview.c:430
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define SetLastError(x)
Definition: compat.h:752
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
WCHAR OLECHAR
Definition: compat.h:2292
OLECHAR * BSTR
Definition: compat.h:2293
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CALLBACK
Definition: compat.h:35
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define FILE_SHARE_READ
Definition: compat.h:136
@ VT_BSTR
Definition: compat.h:2303
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4246
LCID WINAPI GetSystemDefaultLCID(void)
Definition: locale.c:1235
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
static FLOAT twips_to_points(LONG value)
Definition: richole.c:399
return ret
Definition: mutex.c:146
action
Definition: namespace.c:707
#define L(x)
Definition: resources.c:13
r parent
Definition: btrfs.c:3010
r reserved
Definition: btrfs.c:3006
int global
Definition: ehframes.cpp:22
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint start
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLenum GLint * range
Definition: glext.h:7539
GLbitfield flags
Definition: glext.h:7161
const GLint * first
Definition: glext.h:5794
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
_Check_return_ long __cdecl labs(_In_ long x)
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
const char * filename
Definition: ioapi.h:137
static ERESOURCE GlobalLock
Definition: sys_arch.c:8
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
#define wine_dbgstr_w
Definition: kernel32.h:34
#define GUID_NULL
Definition: ks.h:106
POINT cp
Definition: magnifier.c:59
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
#define todo_wine_if(is_todo)
Definition: minitest.h:81
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
#define todo_wine
Definition: minitest.h:80
LONG_PTR LPARAM
Definition: minwindef.h:175
LONG_PTR LRESULT
Definition: minwindef.h:176
UINT_PTR WPARAM
Definition: minwindef.h:174
#define pch(ap)
Definition: match.c:418
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
char string[160]
Definition: util.h:11
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static HDC
Definition: imagelist.c:88
BOOL todo
Definition: filedlg.c:313
static const WCHAR textW[]
Definition: itemdlg.c:1559
static IPrintDialogCallback callback
Definition: printdlg.c:326
BOOL expected
Definition: store.c:2000
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1204
HRESULT hres
Definition: protocol.c:465
static LPOLESTR
Definition: stg_prop.c:27
#define open_clipboard(hwnd)
Definition: editor.c:4816
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_Advise(IOleObject *iface, IAdviseSink *adv_sink, DWORD *connection)
Definition: richole.c:424
static void _check_selection(ITextSelection *selection, LONG expected_start, LONG expected_end, int line)
Definition: richole.c:4532
static struct testoleobj * impl_from_IOleObject(IOleObject *iface)
Definition: richole.c:236
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetUserType(IOleObject *iface, DWORD form_of_type, LPOLESTR *user_type)
Definition: richole.c:393
static HRESULT STDMETHODCALLTYPE reolecb_obj_QueryAcceptData(IRichEditOleCallback *iface, IDataObject *dataobj, CLIPFORMAT *cf_format, DWORD reco, BOOL really, HGLOBAL metapict)
Definition: richole.c:132
static void subtest_InsertObject(struct reolecb_obj *callback)
Definition: richole.c:3875
static ULONG STDMETHODCALLTYPE testoleobj_Release(IOleObject *iface)
Definition: richole.c:276
static void test_Interfaces(void)
Definition: richole.c:726
static void test_Expand(void)
Definition: richole.c:4592
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **enum_advise)
Definition: richole.c:442
static void _reset_range(ITextRange *range, LONG start, LONG end, int line)
Definition: richole.c:4491
static void test_SetText(void)
Definition: richole.c:3286
static void test_character_movement(void)
Definition: richole.c:4931
static void test_ITextSelection_GetDuplicate(void)
Definition: richole.c:4415
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetUserClassID(IOleObject *iface, CLSID *clsid)
Definition: richole.c:387
static void _insert_reobject(struct reolecb_obj *callback, IRichEditOle *reole, REOBJECT *reobj, LONG cp, DWORD user, int line)
Definition: richole.c:3848
static HRESULT set_editor_undo_state(struct undo_test *inst, enum editorUndoState state)
Definition: richole.c:5307
#define perform_undo(i, c)
Definition: richole.c:5333
static void test_character_moveend(ITextRange *range, int textlen, int i, int j, LONG target)
Definition: richole.c:4794
static const struct IViewObjectVtbl testoleobj_IViewObject_Vtbl
Definition: richole.c:584
#define EXPECT_TODO_WINE
Definition: richole.c:38
static void fill_reobject_struct(REOBJECT *reobj, LONG cp, LPOLEOBJECT poleobj, LPSTORAGE pstg, LPOLECLIENTSITE polesite, LONG sizel_cx, LONG sizel_cy, DWORD aspect, DWORD flags, DWORD user)
Definition: richole.c:3810
static void test_character_startof(ITextRange *range, int textlen, int i, int j)
Definition: richole.c:4869
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetMiscStatus(IOleObject *iface, DWORD aspect, DWORD *status)
Definition: richole.c:454
static void test_ITextSelection_GetStart_GetEnd(void)
Definition: richole.c:1748
static void test_GetPara(void)
Definition: richole.c:2435
static void test_detached_font_getters(ITextFont *font, BOOL duplicate)
Definition: richole.c:2566
#define CLIPBOARD_RANGE_CONTAINS(range, start, end, expected)
Definition: richole.c:4998
static void test_character_endof(ITextRange *range, int textlen, int i, int j)
Definition: richole.c:4894
static void test_GetClientSite(void)
Definition: richole.c:2186
static HRESULT subtest_undo_control(struct undo_test *inst, enum editorUndoStateAction action)
Definition: richole.c:5401
static void test_GetStoryLength(void)
Definition: richole.c:4347
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetExtent(IOleObject *iface, DWORD draw_aspect, SIZEL *sizel)
Definition: richole.c:414
static HRESULT STDMETHODCALLTYPE reolecb_obj_QueryInsertObject(IRichEditOleCallback *iface, CLSID *clsid, IStorage *stg, LONG cp)
Definition: richole.c:103
static HMODULE hmoduleRichEdit
Definition: richole.c:620
#define INSERT_REOBJECT(callback, reole, reobj, cp, user)
Definition: richole.c:3846
static void test_textfont_undefined(ITextFont *font)
Definition: richole.c:2763
static void test_IOleInPlaceSite_GetWindow(void)
Definition: richole.c:2289
static void subtest_undo(const char *dummy_text)
Definition: richole.c:5078
static HWND new_richedit(HWND parent)
Definition: richole.c:645
static void test_ITextRange_GetDuplicate(void)
Definition: richole.c:1955
editorUndoStateAction
Definition: richole.c:5206
@ undoActionDisable
Definition: richole.c:5210
@ undoActionEnable
Definition: richole.c:5209
@ firstUndoAction
Definition: richole.c:5207
@ undoActionSuspend
Definition: richole.c:5211
@ undoActionResume
Definition: richole.c:5212
@ numUndoActions
Definition: richole.c:5213
@ undoActionNoOp
Definition: richole.c:5208
static void test_character_move(ITextRange *range, int textlen, int i, int j, LONG target)
Definition: richole.c:4823
static void test_Delete(void)
Definition: richole.c:3231
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_GetAdvise(IViewObject *iface, DWORD *aspects, DWORD *advf, IAdviseSink **adv_sink)
Definition: richole.c:575
static void test_undo_control(void)
Definition: richole.c:5492
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_SetMoniker(IOleObject *iface, DWORD which_moniker, IMoniker *mk)
Definition: richole.c:333
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_QueryInterface(IViewObject *iface, REFIID riid, void **obj)
Definition: richole.c:497
static void test_ITextSelection_GetChar(void)
Definition: richole.c:1472
#define CHECK_TYPEINFO(disp, expected_riid)
Definition: richole.c:701
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetClientSite(IOleObject *iface, IOleClientSite **clientsite)
Definition: richole.c:311
static void test_clipboard(void)
Definition: richole.c:5030
static HRESULT STDMETHODCALLTYPE testoleobj_QueryInterface(IOleObject *iface, REFIID riid, void **obj)
Definition: richole.c:241
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_Unadvise(IOleObject *iface, DWORD connection)
Definition: richole.c:434
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_Freeze(IViewObject *iface, DWORD draw_aspect, LONG index, void *aspect, DWORD *freeze)
Definition: richole.c:557
static void _expect_ref(IUnknown *obj, ULONG ref, int line)
Definition: richole.c:628
static struct testoleobj * impl_from_IViewObject(IViewObject *iface)
Definition: richole.c:492
static void test_InRange(void)
Definition: richole.c:3373
static const struct IRichEditOleCallbackVtbl reolecb_obj_Vtbl
Definition: richole.c:163
static void test_GetStoryType(void)
Definition: richole.c:3667
static HRESULT perform_editor_undo_state_action(struct undo_test *inst, enum editorUndoStateAction action, LONG *count)
Definition: richole.c:5236
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_Close(IOleObject *iface, DWORD save_option)
Definition: richole.c:328
#define RESET_RANGE(range, start, end)
Definition: richole.c:4489
static BOOL touch_file(LPCWSTR filename)
Definition: richole.c:650
static HRESULT testoleobj_Create(struct testoleobj **objptr)
Definition: richole.c:596
static void ok_msg_result_(int line, const char *desc, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT expect)
Definition: richole.c:5192
static void test_ITextRange_GetStart_GetEnd(void)
Definition: richole.c:1528
static HRESULT STDMETHODCALLTYPE reolecb_obj_GetContextMenu(IRichEditOleCallback *iface, WORD seltype, IOleObject *oleobj, CHARRANGE *chrg, HMENU *hmenu)
Definition: richole.c:157
static const struct IOleObjectVtbl testoleobj_IOleObject_Vtbl
Definition: richole.c:465
static ULONG STDMETHODCALLTYPE reolecb_obj_AddRef(IRichEditOleCallback *iface)
Definition: richole.c:70
static void _check_reobject_struct(IRichEditOle *reole, LONG index, DWORD flags, LONG cp, LONG cp_check, LPOLEOBJECT poleobj, LPSTORAGE pstg, LPOLECLIENTSITE polesite, DWORD user, int line)
Definition: richole.c:3829
static void test_ITextRange_IsEqual(void)
Definition: richole.c:3483
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_GetColorSet(IViewObject *iface, DWORD draw_aspect, LONG index, void *aspect, DVTARGETDEVICE *td, HDC hdc_target_dev, LOGPALETTE **color_set)
Definition: richole.c:549
#define CHECK_REOBJECT_STRUCT(reole, index, flags, cp, cp_check, poleobj, pstg, polesite, user)
Definition: richole.c:3827
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_SetColorScheme(IOleObject *iface, LOGPALETTE *palette)
Definition: richole.c:460
#define perform_redo(i, c)
Definition: richole.c:5367
static void test_ITextDocument_Open(void)
Definition: richole.c:856
static void test_ITextRange_Collapse(void)
Definition: richole.c:1998
static void create_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc, ITextSelection **txtSel)
Definition: richole.c:675
static ULONG STDMETHODCALLTYPE testoleobj_IViewObject_AddRef(IViewObject *iface)
Definition: richole.c:503
static BOOL is_existing_file(LPCWSTR filename)
Definition: richole.c:663
static HRESULT STDMETHODCALLTYPE reolecb_obj_QueryInterface(IRichEditOleCallback *iface, REFIID riid, void **obj)
Definition: richole.c:59
#define CHECK_SELECTION(selection, expected_start, expected_end)
Definition: richole.c:4530
static void test_IOleWindow_GetWindow(void)
Definition: richole.c:2261
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **enumoleverb)
Definition: richole.c:371
static void test_ITextRange_ScrollIntoView(void)
Definition: richole.c:1436
static ULONG STDMETHODCALLTYPE testoleobj_AddRef(IOleObject *iface)
Definition: richole.c:269
static void flush_dispatch_messages(void)
Definition: richole.c:3865
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_InitFromData(IOleObject *iface, IDataObject *dataobj, BOOL creation, DWORD reserved)
Definition: richole.c:351
static void test_dispatch(void)
Definition: richole.c:2519
static void test_textfont_global_defaults(ITextFont *font)
Definition: richole.c:2634
static BOOL perform_redo_(struct undo_test *inst, BOOL can_redo, int line)
Definition: richole.c:5368
#define ok_msg_result(h, m, w, l, r)
Definition: richole.c:5191
#define MAX_BUF_LEN
static void _reset_selection(ITextSelection *selection, LONG start, LONG end, int line)
Definition: richole.c:4520
#define EXPECT_REF(obj, ref)
Definition: richole.c:627
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_DoVerb(IOleObject *iface, LONG verb, MSG *msg, IOleClientSite *activesite, LONG index, HWND parentwnd, LPCRECT posrect)
Definition: richole.c:364
static void test_ITextSelection_Collapse(void)
Definition: richole.c:2109
static int get_scroll_pos_y(HWND hwnd)
Definition: richole.c:3598
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_Update(IOleObject *iface)
Definition: richole.c:377
static ULONG STDMETHODCALLTYPE reolecb_obj_Release(IRichEditOleCallback *iface)
Definition: richole.c:77
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_IsUpToDate(IOleObject *iface)
Definition: richole.c:382
static void test_Select(void)
Definition: richole.c:3606
static ULONG STDMETHODCALLTYPE testoleobj_IViewObject_Release(IViewObject *iface)
Definition: richole.c:509
static void olecb_expect_QueryInsertObject(struct reolecb_obj *This, int line, ULONG expect, const CLSID *clsid, IStorage *stg, LONG cp, HRESULT result)
Definition: richole.c:197
static void test_ITextRange_SetRange(void)
Definition: richole.c:4547
static const WCHAR sysW[]
Definition: richole.c:625
static void test_undo(void)
Definition: richole.c:5185
static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc, ITextSelection **txtSel)
Definition: richole.c:685
static void test_GetFont(void)
Definition: richole.c:2317
static void olecb_check_QueryInsertObject(struct reolecb_obj *This, int line)
Definition: richole.c:210
#define CHECK_RANGE(range, expected_start, expected_end)
Definition: richole.c:4501
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_SetExtent(IOleObject *iface, DWORD draw_aspect, SIZEL *sizel)
Definition: richole.c:404
static void test_character_movestart(ITextRange *range, int textlen, int i, int j, LONG target)
Definition: richole.c:4765
static struct reolecb_obj * impl_from_IRichEditOleCallback(IRichEditOleCallback *iface)
Definition: richole.c:54
static void test_ITextFont(void)
Definition: richole.c:2890
static HRESULT STDMETHODCALLTYPE reolecb_obj_ShowContainerUI(IRichEditOleCallback *iface, BOOL show)
Definition: richole.c:98
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetClipboardData(IOleObject *iface, DWORD reserved, IDataObject **dataobj)
Definition: richole.c:357
#define RESET_SELECTION(selection, start, end)
Definition: richole.c:4518
static HRESULT STDMETHODCALLTYPE reolecb_obj_DeleteObject(IRichEditOleCallback *iface, IOleObject *oleobj)
Definition: richole.c:127
static void test_ITextRange_GetChar(void)
Definition: richole.c:1331
static HRESULT reolecb_obj_Create(struct reolecb_obj **objptr)
Definition: richole.c:179
static void _check_range(ITextRange *range, LONG expected_start, LONG expected_end, int line)
Definition: richole.c:4503
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_GetMoniker(IOleObject *iface, DWORD assign, DWORD which_moniker, IMoniker **mk)
Definition: richole.c:339
static void check_range(HWND w, ITextDocument *doc, int first, int lim, LONG bStart, int expected_nonzero)
Definition: richole.c:1410
static HRESULT STDMETHODCALLTYPE reolecb_obj_GetInPlaceContext(IRichEditOleCallback *iface, IOleInPlaceFrame **frame, IOleInPlaceUIWindow **doc, OLEINPLACEFRAMEINFO *frame_info)
Definition: richole.c:90
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_Unfreeze(IViewObject *iface, DWORD freeze)
Definition: richole.c:564
static HRESULT STDMETHODCALLTYPE reolecb_obj_GetDragDropEffect(IRichEditOleCallback *iface, BOOL drag, DWORD key_state, DWORD *effect)
Definition: richole.c:150
static HWND new_window(LPCSTR lpClassName, DWORD dwStyle, HWND parent)
Definition: richole.c:636
static void _check_typeinfo(IDispatch *disp, REFIID expected_riid, int line)
Definition: richole.c:702
static void test_GetText(void)
Definition: richole.c:1104
static void _clipboard_range_contains(ITextRange *range, LONG start, LONG end, const char *expected, int line, int todo)
Definition: richole.c:5000
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_SetAdvise(IViewObject *iface, DWORD aspects, DWORD advf, IAdviseSink *adv_sink)
Definition: richole.c:569
static void test_InsertObject(void)
Definition: richole.c:4325
static void test_MoveEnd_story(void)
Definition: richole.c:4651
static HRESULT STDMETHODCALLTYPE reolecb_obj_GetNewStorage(IRichEditOleCallback *iface, IStorage **stg)
Definition: richole.c:85
static BOOL perform_undo_(struct undo_test *inst, BOOL can_undo, int line)
Definition: richole.c:5334
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_SetHostNames(IOleObject *iface, LPCOLESTR container_app, LPCOLESTR container_obj)
Definition: richole.c:321
static ULONG get_refcount(IUnknown *iface)
Definition: richole.c:695
editorUndoState
Definition: richole.c:5198
@ undoStateSuspended
Definition: richole.c:5201
@ undoStateDisabled
Definition: richole.c:5202
@ undoStateActive
Definition: richole.c:5200
@ numUndoStates
Definition: richole.c:5203
@ firstUndoState
Definition: richole.c:5199
static void test_SetFont(void)
Definition: richole.c:3723
static HRESULT STDMETHODCALLTYPE reolecb_obj_ContextSensitiveHelp(IRichEditOleCallback *iface, BOOL enter_mode)
Definition: richole.c:139
static void test_ITextDocument_Range(void)
Definition: richole.c:1289
static HRESULT STDMETHODCALLTYPE testoleobj_IOleObject_SetClientSite(IOleObject *iface, IOleClientSite *clientsite)
Definition: richole.c:297
static HRESULT STDMETHODCALLTYPE testoleobj_IViewObject_Draw(IViewObject *iface, DWORD draw_aspect, LONG index, void *aspect, DVTARGETDEVICE *td, HDC hdc_target_dev, HDC hdc_draw, LPCRECTL bounds, LPCRECTL wbounds, BOOL(CALLBACK *fn_continue)(ULONG_PTR), ULONG_PTR arg_continue)
Definition: richole.c:515
static HRESULT STDMETHODCALLTYPE reolecb_obj_GetClipboardData(IRichEditOleCallback *iface, CHARRANGE *chrg, DWORD reco, IDataObject **dataobj)
Definition: richole.c:144
editorUndoStateTestFlags
Definition: richole.c:5216
@ undoTestDoSecondUndoAfterEnable
Definition: richole.c:5221
@ undoTestResetUndoLimit
Definition: richole.c:5218
@ undoTestDoFirstUndo
Definition: richole.c:5219
@ undoTestDoFirstRedo
Definition: richole.c:5220
@ undoTestUseWindowMessages
Definition: richole.c:5217
@ undoTestMaxFlag
Definition: richole.c:5222
static void test_freeze(void)
Definition: richole.c:5542
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
static VARIANTARG static DISPID
Definition: ordinal.c:49
static HPALETTE palette
Definition: clipboard.c:1341
static HMENU hmenu
Definition: win.c:66
static IDispatch testobj
Definition: run.c:299
#define min(a, b)
Definition: monoChain.cc:55
const CLSID * clsid
Definition: msctf.cpp:50
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
_In_ HANDLE hFile
Definition: mswsock.h:90
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
Definition: mk_font.cpp:20
unsigned int UINT
Definition: ndis.h:50
#define GENERIC_WRITE
Definition: nt_native.h:90
#define LOCALE_USER_DEFAULT
#define LOCALE_SYSTEM_DEFAULT
interface IStorage * LPSTORAGE
Definition: objfwd.h:30
HRESULT WINAPI CreateOleAdviseHolder(IOleAdviseHolder **ppOAHolder)
Definition: oleobj.c:875
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
const GUID IID_IOleInPlaceSite
const GUID IID_IViewObject
const GUID IID_IOleWindow
const GUID IID_IRunnableObject
const GUID IID_IOleClientSite
const GUID IID_IDispatch
const GUID IID_IOleLink
const GUID IID_IOleObject
#define WS_POPUP
Definition: pedump.c:616
#define WS_VSCROLL
Definition: pedump.c:627
#define WS_VISIBLE
Definition: pedump.c:620
long LONG
Definition: pedump.c:60
#define WS_HSCROLL
Definition: pedump.c:628
#define ES_MULTILINE
Definition: pedump.c:667
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define CLSID_NULL
Definition: guiddef.h:99
#define REFIID
Definition: guiddef.h:118
#define IID_NULL
Definition: guiddef.h:98
_In_opt_ IUnknown * punk
Definition: shlwapi.h:158
#define GT_DEFAULT
Definition: richedit.h:1036
#define EM_CANREDO
Definition: richedit.h:118
#define SEL_OBJECT
Definition: richedit.h:824
#define EM_SETOLECALLBACK
Definition: richedit.h:103
#define EM_REDO
Definition: richedit.h:117
#define EM_GETSELTEXT
Definition: richedit.h:95
#define CFM_OFFSET
Definition: richedit.h:359
#define CFE_ITALIC
Definition: richedit.h:407
#define SCF_SELECTION
Definition: richedit.h:235
#define EM_GETCHARFORMAT
Definition: richedit.h:91
#define SEL_TEXT
Definition: richedit.h:823
#define EM_SETCHARFORMAT
Definition: richedit.h:101
#define RICHEDIT_CLASS20A
Definition: richedit.h:43
#define CFM_KERNING
Definition: richedit.h:352
#define CFM_ITALIC
Definition: richedit.h:333
#define EM_GETTEXTRANGE
Definition: richedit.h:108
#define EM_SETTEXTMODE
Definition: richedit.h:123
#define CFM_SIZE
Definition: richedit.h:362
#define GT_RAWTEXT
Definition: richedit.h:1039
#define GT_SELECTION
Definition: richedit.h:1038
#define EM_GETSCROLLPOS
Definition: richedit.h:165
struct _charformat2a CHARFORMAT2A
#define EM_SELECTIONTYPE
Definition: richedit.h:99
#define TM_PLAINTEXT
Definition: richedit.h:1028
#define GT_NOHIDDENTEXT
Definition: richedit.h:1040
#define GT_USECRLF
Definition: richedit.h:1037
#define CFM_FACE
Definition: richedit.h:360
#define EM_GETOLEINTERFACE
Definition: richedit.h:93
#define EM_GETTEXTEX
Definition: richedit.h:128
#define EM_SETUNDOLIMIT
Definition: richedit.h:116
WCHAR classname[128]
Definition: startup.c:15
#define calloc
Definition: rosglue.h:14
const WCHAR * str
#define CP_UTF8
Definition: nls.h:20
strcpy
Definition: string.h:131
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:187
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
long bottom
Definition: polytest.cpp:53
long right
Definition: polytest.cpp:53
long top
Definition: polytest.cpp:53
long left
Definition: polytest.cpp:53
LONG cx
Definition: kdterminal.h:27
LONG cy
Definition: kdterminal.h:28
LONG cpMax
Definition: richedit.h:501
LONG cpMin
Definition: richedit.h:500
DWORD cb
Definition: richedit.h:706
DWORD flags
Definition: richedit.h:707
LPCSTR lpDefaultChar
Definition: richedit.h:709
LPBOOL lpUsedDefChar
Definition: richedit.h:710
UINT codepage
Definition: richedit.h:708
DWORD dwUser
Definition: richole.idl:67
CLSID clsid
Definition: richole.idl:60
DWORD dwFlags
Definition: richole.idl:66
LPSTORAGE pstg
Definition: richole.idl:62
LPOLEOBJECT poleobj
Definition: richole.idl:61
DWORD dvaspect
Definition: richole.idl:65
LPOLECLIENTSITE polesite
Definition: richole.idl:63
DWORD cbStruct
Definition: richole.idl:58
LONG cp
Definition: richole.idl:59
SIZEL sizel
Definition: richole.idl:64
CHARRANGE chrg
Definition: richedit.h:508
LPSTR lpstrText
Definition: richedit.h:509
Definition: fci.c:127
Definition: parser.c:49
Definition: tftpd.h:60
Definition: send.c:48
IRichEditOleCallback IRichEditOleCallback_iface
Definition: richole.c:42
IStorage * stg
Definition: richole.c:49
int line
Definition: richole.c:44
ULONG expect_queryinsertobject
Definition: richole.c:46
const CLSID * clsid
Definition: richole.c:48
LONG ref
Definition: richole.c:43
HRESULT queryinsertobject_result
Definition: richole.c:51
LONG cp
Definition: richole.c:50
Definition: ps.c:97
Definition: windef.h:99
Definition: tools.h:99
int draw_count
Definition: richole.c:227
LONG ref
Definition: richole.c:225
int line
Definition: richole.c:226
IOleObject IOleObject_iface
Definition: richole.c:224
SIZEL extent
Definition: richole.c:231
IOleClientSite * clientsite
Definition: richole.c:229
IViewObject IViewObject_iface
Definition: richole.c:233
IOleAdviseHolder * advise_holder
Definition: richole.c:230
HWND hwnd
Definition: richole.c:5227
BOOL last_undo_status
Definition: richole.c:5232
ITextDocument * doc
Definition: richole.c:5228
int test_flags
Definition: richole.c:5229
enum editorUndoState undo_ctl_state
Definition: richole.c:5230
LONG_PTR undo_limit
Definition: richole.c:5231
BOOL last_redo_status
Definition: richole.c:5233
#define max(a, b)
Definition: svc.c:63
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
EXTERN_C const IID IID_ITextServices
Definition: textserv.h:36
@ tomUseTwips
Definition: tom.idl:46
@ tomAutoColor
Definition: tom.idl:32
@ tomRTF
Definition: tom.idl:178
@ tomApplyNow
Definition: tom.idl:38
@ tomPasteFile
Definition: tom.idl:172
@ tomSentence
Definition: tom.idl:120
@ tomEnd
Definition: tom.idl:66
@ tomText
Definition: tom.idl:179
@ tomOpenExisting
Definition: tom.idl:175
@ tomUnknownStory
Definition: tom.idl:139
@ tomStory
Definition: tom.idl:123
@ tomResume
Definition: tom.idl:35
@ tomUsePoints
Definition: tom.idl:45
@ tomDefault
Definition: tom.idl:33
@ tomExtend
Definition: tom.idl:51
@ tomCreateAlways
Definition: tom.idl:174
@ tomApplyLater
Definition: tom.idl:39
@ tomSuspend
Definition: tom.idl:34
@ tomReadOnly
Definition: tom.idl:169
@ tomCharacter
Definition: tom.idl:118
@ tomTextFrameStory
Definition: tom.idl:144
@ tomShareDenyWrite
Definition: tom.idl:171
@ tomMove
Definition: tom.idl:50
@ tomTruncateExisting
Definition: tom.idl:177
@ tomStart
Definition: tom.idl:67
@ tomCacheParms
Definition: tom.idl:41
@ tomShareDenyRead
Definition: tom.idl:170
@ tomTrue
Definition: tom.idl:29
@ tomOpenAlways
Definition: tom.idl:176
@ tomFalse
Definition: tom.idl:28
@ tomCreateNew
Definition: tom.idl:173
@ tomTrackParms
Definition: tom.idl:40
@ tomUndefined
Definition: tom.idl:30
FT_UInt FT_UInt FT_Vector * kerning
Definition: ttdriver.c:207
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
float FLOAT
Definition: typedefs.h:69
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static uacpi_status enter_mode(enum hw_mode mode, uacpi_bool *did_change)
Definition: uacpi.c:249
Definition: pdh_main.c:96
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
#define dpi
Definition: sysparams.c:23
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define OLE_E_NOCONNECTION
Definition: winerror.h:3729
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:257
#define E_NOINTERFACE
Definition: winerror.h:3479
#define E_ACCESSDENIED
Definition: winerror.h:4116
#define ERROR_FILE_EXISTS
Definition: winerror.h:287
#define OLEOBJ_E_NOVERBS
Definition: winerror.h:3840
#define E_UNEXPECTED
Definition: winerror.h:3528
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618
#define CO_E_RELEASED
Definition: winerror.h:3932
HGDIOBJ WINAPI GetStockObject(_In_ int)
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define DKGRAY_BRUSH
Definition: wingdi.h:897
#define FW_BOLD
Definition: wingdi.h:378
#define LOGPIXELSY
Definition: wingdi.h:719
#define FW_NORMAL
Definition: wingdi.h:373
#define LOGPIXELSX
Definition: wingdi.h:718
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define EM_SETREADONLY
Definition: winuser.h:2044
BOOL WINAPI TranslateMessage(_In_ const MSG *)
struct tagSCROLLINFO SCROLLINFO
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4417
#define SIF_RANGE
Definition: winuser.h:1246
#define EM_GETSEL
Definition: winuser.h:2026
#define EM_SETPASSWORDCHAR
Definition: winuser.h:2043
#define SB_VERT
Definition: winuser.h:553
int WINAPI GetClassNameA(_In_ HWND hWnd, _Out_writes_to_(nMaxCount, return) LPSTR lpClassName, _In_ int nMaxCount)
#define EM_EMPTYUNDOBUFFER
Definition: winuser.h:2014
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
HWND WINAPI GetOpenClipboardWindow(void)
Definition: ntwrapper.h:214
#define EM_REPLACESEL
Definition: winuser.h:2035
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define WM_GETTEXT
Definition: winuser.h:1646
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
HANDLE WINAPI GetClipboardData(_In_ UINT)
#define WM_SETTEXT
Definition: winuser.h:1645
#define EM_CANUNDO
Definition: winuser.h:2012
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define EM_UNDO
Definition: winuser.h:2050
#define PM_REMOVE
Definition: winuser.h:1207
BOOL WINAPI UpdateWindow(_In_ HWND)
#define EM_SETSEL
Definition: winuser.h:2047
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
#define SIF_POS
Definition: winuser.h:1245
#define GWL_STYLE
Definition: winuser.h:863
BOOL WINAPI GetScrollInfo(_In_ HWND, _In_ int, _Inout_ LPSCROLLINFO)
BOOL WINAPI DestroyWindow(_In_ HWND)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175