riched20: Implement GetDuplicate() for selection.

This commit is contained in:
Nikolay Sivov 2015-06-06 21:32:00 +03:00 committed by Alexandre Julliard
parent 9c6bcec509
commit 5f933018a2
2 changed files with 86 additions and 3 deletions

View File

@ -4223,14 +4223,22 @@ static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
return E_NOTIMPL;
}
static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **ppRange)
static HRESULT WINAPI ITextSelection_fnGetDuplicate(ITextSelection *me, ITextRange **range)
{
ITextSelectionImpl *This = impl_from_ITextSelection(me);
LONG start, end;
TRACE("(%p)->(%p)\n", This, range);
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented\n");
return E_NOTIMPL;
if (!range)
return E_INVALIDARG;
ITextSelection_GetStart(me, &start);
ITextSelection_GetEnd(me, &end);
return CreateITextRange(This->reOle, start, end, range);
}
static HRESULT WINAPI ITextSelection_fnGetFormattedText(ITextSelection *me, ITextRange **ppRange)

View File

@ -3177,6 +3177,80 @@ static void test_GetStoryLength(void)
ITextRange_Release(range);
}
static void test_ITextSelection_GetDuplicate(void)
{
static const CHAR test_text1[] = "TestSomeText";
IRichEditOle *reOle = NULL;
ITextDocument *doc = NULL;
ITextSelection *selection, *sel2;
ITextRange *range, *range2;
ITextFont *font;
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 = ITextSelection_GetDuplicate(selection, NULL);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
EXPECT_REF(selection, 2);
hr = ITextSelection_GetDuplicate(selection, &range);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ITextSelection_GetDuplicate(selection, &range2);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(range != range2, "got %p, %p\n", range, range2);
EXPECT_REF(selection, 2);
EXPECT_REF(range, 1);
EXPECT_REF(range2, 1);
ITextRange_Release(range2);
value = 0;
hr = ITextRange_GetStart(range, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == 1, "got %d\n", value);
value = 0;
hr = ITextRange_GetEnd(range, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == 2, "got %d\n", value);
SendMessageA(hwnd, EM_SETSEL, 2, 3);
value = 0;
hr = ITextRange_GetStart(range, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == 1, "got %d\n", value);
value = 0;
hr = ITextRange_GetEnd(range, &value);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(value == 2, "got %d\n", value);
hr = ITextRange_QueryInterface(range, &IID_ITextSelection, (void**)&sel2);
ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
release_interfaces(&hwnd, &reOle, &doc, NULL);
hr = ITextSelection_GetDuplicate(selection, NULL);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
hr = ITextSelection_GetDuplicate(selection, &range);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
hr = ITextRange_GetFont(range, &font);
ok(hr == CO_E_RELEASED, "got 0x%08x\n", hr);
ITextSelection_Release(selection);
ITextRange_Release(range);
}
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@ -3211,4 +3285,5 @@ START_TEST(richole)
test_SetFont();
test_InsertObject();
test_GetStoryLength();
test_ITextSelection_GetDuplicate();
}