From 6ccfde327aa9f985e7450af233c2978a0fc4b0ea Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 27 May 2015 02:24:01 +0300 Subject: [PATCH] riched20: Implement IsEqual() for ranges. --- dlls/riched20/richole.c | 51 +++++++++++++-- dlls/riched20/tests/richole.c | 116 ++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 6 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index cbd3060dbda..db002a93686 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -1790,14 +1790,36 @@ static HRESULT WINAPI ITextRange_fnInStory(ITextRange *me, ITextRange *pRange, L return E_NOTIMPL; } -static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *pRange, LONG *pb) +static HRESULT textrange_isequal(LONG start, LONG end, ITextRange *range, LONG *ret) +{ + LONG from, to, v; + + if (!ret) + ret = &v; + + ITextRange_GetStart(range, &from); + ITextRange_GetEnd(range, &to); + + *ret = (start == from && end == to) ? tomTrue : tomFalse; + return *ret == tomTrue ? S_OK : S_FALSE; +} + +static HRESULT WINAPI ITextRange_fnIsEqual(ITextRange *me, ITextRange *range, LONG *ret) { ITextRangeImpl *This = impl_from_ITextRange(me); + + TRACE("(%p)->(%p %p)\n", This, range, ret); + + if (ret) + *ret = tomFalse; + if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented %p\n", This); - return E_NOTIMPL; + if (!range) + return S_FALSE; + + return textrange_isequal(This->start, This->end, range, ret); } static HRESULT WINAPI ITextRange_fnSelect(ITextRange *me) @@ -4188,14 +4210,31 @@ static HRESULT WINAPI ITextSelection_fnInStory(ITextSelection *me, ITextRange *p return E_NOTIMPL; } -static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *pRange, LONG *pb) +static HRESULT WINAPI ITextSelection_fnIsEqual(ITextSelection *me, ITextRange *range, LONG *ret) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + ITextSelection *selection = NULL; + LONG start, end; + + TRACE("(%p)->(%p %p)\n", This, range, ret); + + if (ret) + *ret = tomFalse; + if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented\n"); - return E_NOTIMPL; + if (!range) + return S_FALSE; + + ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&selection); + if (!selection) + return S_FALSE; + ITextSelection_Release(selection); + + ITextSelection_GetStart(me, &start); + ITextSelection_GetEnd(me, &end); + return textrange_isequal(start, end, range, ret); } static HRESULT WINAPI ITextSelection_fnSelect(ITextSelection *me) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 359a8cb3a87..f4bf6f958b5 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -2631,6 +2631,121 @@ static void test_InRange(void) ITextSelection_Release(selection); } +static void test_ITextRange_IsEqual(void) +{ + static const CHAR test_text1[] = "TestSomeText"; + ITextRange *range, *range2, *range3; + IRichEditOle *reOle = NULL; + ITextDocument *doc = NULL; + ITextSelection *selection; + LONG value; + HRESULT hr; + HWND hwnd; + + create_interfaces(&hwnd, &reOle, &doc, &selection); + SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)test_text1); + SendMessageA(hwnd, EM_SETSEL, 1, 2); + + hr = ITextDocument_Range(doc, 0, 4, &range); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = ITextDocument_Range(doc, 0, 4, &range2); + ok(hr == S_OK, "got 0x%08x\n", hr); + + /* matches selection */ + hr = ITextDocument_Range(doc, 1, 2, &range3); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = ITextRange_IsEqual(range, NULL, NULL); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextRange_IsEqual(range, NULL, &value); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + hr = ITextRange_IsEqual(range, range2, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + value = tomFalse; + hr = ITextRange_IsEqual(range, range2, &value); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(value == tomTrue, "got %d\n", value); + + value = tomTrue; + hr = ITextRange_IsEqual(range, range3, &value); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + /* selection */ + hr = ITextSelection_IsEqual(selection, NULL, NULL); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextSelection_IsEqual(selection, NULL, &value); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + hr = ITextSelection_IsEqual(selection, range2, NULL); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextSelection_IsEqual(selection, range2, &value); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + value = tomTrue; + hr = ITextSelection_IsEqual(selection, range3, &value); + ok(hr == S_FALSE, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + /* seems to work on ITextSelection ranges only */ + value = tomFalse; + hr = ITextSelection_IsEqual(selection, (ITextRange*)selection, &value); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(value == tomTrue, "got %d\n", value); + + release_interfaces(&hwnd, &reOle, &doc, NULL); + + hr = ITextRange_IsEqual(range, NULL, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextRange_IsEqual(range, NULL, &value); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + hr = ITextRange_IsEqual(range, range2, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextRange_IsEqual(range, range2, &value); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + /* selection */ + hr = ITextSelection_IsEqual(selection, NULL, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextSelection_IsEqual(selection, NULL, &value); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + hr = ITextSelection_IsEqual(selection, range2, NULL); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + + value = tomTrue; + hr = ITextSelection_IsEqual(selection, range2, &value); + ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr); + ok(value == tomFalse, "got %d\n", value); + + ITextRange_Release(range); + ITextRange_Release(range2); + ITextRange_Release(range3); + ITextSelection_Release(selection); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -2659,4 +2774,5 @@ START_TEST(richole) test_Delete(); test_SetText(); test_InRange(); + test_ITextRange_IsEqual(); }