From: Jactry Zeng Subject: [PATCH 2/5] riched20: Implement ITextSelection::GetStart and ITextSelection::GetEnd. (try 2) Message-Id: <5418134E.4000804@jactry.com> Date: Tue, 16 Sep 2014 18:39:10 +0800 ChangeLog: - Avoid huge macro in tests. --- dlls/riched20/richole.c | 16 +++++++++--- dlls/riched20/tests/richole.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c index dab26f3..ddaee28 100644 --- a/dlls/riched20/richole.c +++ b/dlls/riched20/richole.c @@ -1630,11 +1630,15 @@ static HRESULT WINAPI ITextSelection_fnSetFormattedText(ITextSelection *me, ITex static HRESULT WINAPI ITextSelection_fnGetStart(ITextSelection *me, LONG *pcpFirst) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + LONG lim; if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented\n"); - return E_NOTIMPL; + if (!pcpFirst) + return E_INVALIDARG; + ME_GetSelectionOfs(This->reOle->editor, pcpFirst, &lim); + TRACE("%d\n", *pcpFirst); + return S_OK; } static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst) @@ -1650,11 +1654,15 @@ static HRESULT WINAPI ITextSelection_fnSetStart(ITextSelection *me, LONG cpFirst static HRESULT WINAPI ITextSelection_fnGetEnd(ITextSelection *me, LONG *pcpLim) { ITextSelectionImpl *This = impl_from_ITextSelection(me); + LONG first; if (!This->reOle) return CO_E_RELEASED; - FIXME("not implemented\n"); - return E_NOTIMPL; + if (!pcpLim) + return E_INVALIDARG; + ME_GetSelectionOfs(This->reOle->editor, &first, pcpLim); + TRACE("%d\n", *pcpLim); + return S_OK; } static HRESULT WINAPI ITextSelection_fnSetEnd(ITextSelection *me, LONG cpLim) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 681c5f7..312ab28 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -695,6 +695,66 @@ static void test_ITextRange_GetStart_GetEnd(void) release_interfaces(&w, &reOle, &txtDoc, NULL); } +static void test_ITextSelection_GetStart_GetEnd(void) +{ + HWND w; + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextSelection *txtSel = NULL; + HRESULT hres; + int first, lim, start, end; + static const CHAR test_text1[] = "TestSomeText"; + + create_interfaces(&w, &reOle, &txtDoc, &txtSel); + SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1); + + first = 2, lim = 5; + SendMessageA(w, EM_SETSEL, first, lim); + start = 0xdeadbeef; + hres = ITextSelection_GetStart(txtSel, &start); + ok(hres == S_OK, "ITextSelection_GetStart\n"); + ok(start == 2, "got wrong start value: %d\n", start); + end = 0xdeadbeef; + hres = ITextSelection_GetEnd(txtSel, &end); + ok(hres == S_OK, "ITextSelection_GetEnd\n"); + ok(end == 5, "got wrong end value: %d\n", end); + + first = 5, lim = 2; + SendMessageA(w, EM_SETSEL, first, lim); + start = 0xdeadbeef; + hres = ITextSelection_GetStart(txtSel, &start); + ok(hres == S_OK, "ITextSelection_GetStart\n"); + ok(start == 2, "got wrong start value: %d\n", start); + end = 0xdeadbeef; + hres = ITextSelection_GetEnd(txtSel, &end); + ok(hres == S_OK, "ITextSelection_GetEnd\n"); + ok(end == 5, "got wrong end value: %d\n", end); + + first = 0, lim = -1; + SendMessageA(w, EM_SETSEL, first, lim); + start = 0xdeadbeef; + hres = ITextSelection_GetStart(txtSel, &start); + ok(hres == S_OK, "ITextSelection_GetStart\n"); + ok(start == 0, "got wrong start value: %d\n", start); + end = 0xdeadbeef; + hres = ITextSelection_GetEnd(txtSel, &end); + ok(hres == S_OK, "ITextSelection_GetEnd\n"); + ok(end == 13, "got wrong end value: %d\n", end); + + first = 13, lim = 13; + SendMessageA(w, EM_SETSEL, first, lim); + start = 0xdeadbeef; + hres = ITextSelection_GetStart(txtSel, &start); + ok(hres == S_OK, "ITextSelection_GetStart\n"); + ok(start == 12, "got wrong start value: %d\n", start); + end = 0xdeadbeef; + hres = ITextSelection_GetEnd(txtSel, &end); + ok(hres == S_OK, "ITextSelection_GetEnd\n"); + ok(end == 12, "got wrong end value: %d\n", end); + + release_interfaces(&w, &reOle, &txtDoc, &txtSel); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -706,6 +766,7 @@ START_TEST(richole) test_ITextDocument_Open(); test_ITextSelection_GetText(); test_ITextSelection_GetChar(); + test_ITextSelection_GetStart_GetEnd(); test_ITextDocument_Range(); test_ITextRange_GetChar(); test_ITextRange_GetStart_GetEnd();