riched20: Implement IsEqual() for ranges.

This commit is contained in:
Nikolay Sivov 2015-05-27 02:24:01 +03:00 committed by Alexandre Julliard
parent cebee9bd71
commit 6ccfde327a
2 changed files with 161 additions and 6 deletions

View File

@ -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)

View File

@ -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();
}