From: Jactry Zeng Subject: [PATCH 3/5] riched20: Implement ITextRange::GetDuplicate. (try 3) Message-Id: <54181358.8090306@jactry.com> Date: Tue, 16 Sep 2014 18:39:20 +0800 Superseded patch 106522. ChangeLog: try 3: - Use if(FAILED(hres)) instead of if(hres) try 2: - Alloc txtRge in CreateITextRange() --- dlls/riched20/richole.c | 13 +++++++++++-- dlls/riched20/tests/richole.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index ddaee28..1aa1d56 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -602,14 +602,23 @@ static HRESULT WINAPI ITextRange_fnSetChar(ITextRange *me, LONG ch) return E_NOTIMPL; } +static HRESULT CreateITextRange(IRichEditOleImpl *reOle, LONG start, LONG end, ITextRange** ppRange); + static HRESULT WINAPI ITextRange_fnGetDuplicate(ITextRange *me, ITextRange **ppRange) { ITextRangeImpl *This = impl_from_ITextRange(me); + HRESULT hres; if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented %p\n", This); - return E_NOTIMPL; + TRACE("%p %p\n", This, ppRange); + if (!ppRange) + return E_INVALIDARG; + + hres = CreateITextRange(This->reOle, This->start, This->end, ppRange); + if (FAILED(hres)) + return E_FAIL; + return hres; } static HRESULT WINAPI ITextRange_fnGetFormattedText(ITextRange *me, ITextRange **ppRange) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 312ab28..2fd12a5 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -755,6 +755,40 @@ static void test_ITextSelection_GetStart_GetEnd(void) release_interfaces(&w, &reOle, &txtDoc, &txtSel); } +static void test_ITextRange_GetDuplicate(void) +{ + HWND w; + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextRange *txtRge = NULL; + ITextRange *txtRgeDup = NULL; + HRESULT hres; + LONG first, lim, start, end; + static const CHAR test_text1[] = "TestSomeText"; + + create_interfaces(&w, &reOle, &txtDoc, NULL); + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); + first = 0, lim = 4; + hres = ITextDocument_Range(txtDoc, first, lim, &txtRge); + ok(hres == S_OK, "ITextDocument_Range fails 0x%x.\n", hres); + + hres = ITextRange_GetDuplicate(txtRge, &txtRgeDup); + ok(hres == S_OK, "ITextRange_GetDuplicate\n"); + ok(txtRgeDup != txtRge, "A new pointer should be returned\n"); + ITextRange_GetStart(txtRgeDup, &start); + ok(start == first, "got wrong value: %d\n", start); + ITextRange_GetEnd(txtRgeDup, &end); + ok(end == lim, "got wrong value: %d\n", end); + + ITextRange_Release(txtRgeDup); + + hres = ITextRange_GetDuplicate(txtRge, NULL); + ok(hres == E_INVALIDARG, "ITextRange_GetDuplicate\n"); + + ITextRange_Release(txtRge); + release_interfaces(&w, &reOle, &txtDoc, NULL); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -770,4 +804,5 @@ START_TEST(richole) test_ITextDocument_Range(); test_ITextRange_GetChar(); test_ITextRange_GetStart_GetEnd(); + test_ITextRange_GetDuplicate(); }