From fbd912822d267df5427bbba845486557ac80cfe0 Mon Sep 17 00:00:00 2001 From: Jactry Zeng Date: Mon, 17 Mar 2014 22:46:25 +0800 Subject: riched20/tests: Add tests for ITextDocument::Range. --- dlls/riched20/tests/richole.c | 74 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c index 5bfb999..1945770 100644 --- a/dlls/riched20/tests/richole.c +++ b/dlls/riched20/tests/richole.c @@ -80,7 +80,8 @@ static void create_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txt SendMessageA(*w, EM_GETOLEINTERFACE, 0, (LPARAM)reOle); IRichEditOle_QueryInterface(*reOle, &IID_ITextDocument, (void **) txtDoc); - ITextDocument_GetSelection(*txtDoc, txtSel); + if(txtSel) + ITextDocument_GetSelection(*txtDoc, txtSel); } static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc, @@ -89,7 +90,13 @@ static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **tx ITextDocument_Release(*txtDoc); IRichEditOle_Release(*reOle); DestroyWindow(*w); - ITextSelection_Release(*txtSel); + if(txtSel) + ITextSelection_Release(*txtSel); +} + +static void release_txtrge(ITextRange **txtRge) +{ + if(*txtRge) ITextRange_Release(*txtRge); } static void test_Interfaces(void) @@ -97,6 +104,7 @@ static void test_Interfaces(void) IRichEditOle *reOle = NULL; ITextDocument *txtDoc = NULL; ITextSelection *txtSel = NULL; + ITextRange *txtRge = NULL; IUnknown *punk; HRESULT hres; LRESULT res; @@ -118,6 +126,7 @@ static void test_Interfaces(void) ok(txtDoc != NULL, "IRichEditOle_QueryInterface\n"); ITextDocument_GetSelection(txtDoc, &txtSel); + ITextDocument_Range(txtDoc, 0, 0, &txtRge); punk = NULL; hres = ITextSelection_QueryInterface(txtSel, &IID_ITextSelection, (void **) &punk); @@ -129,12 +138,23 @@ static void test_Interfaces(void) hres = ITextSelection_QueryInterface(txtSel, &IID_ITextRange, (void **) &punk); ok(hres == S_OK, "ITextSelection_QueryInterface\n"); ok(punk != NULL, "ITextSelection_QueryInterface\n"); + + if(txtRge) { + hres = ITextRange_QueryInterface(txtRge, &IID_ITextRange, (void **) &punk); + ok(hres == S_OK, "ITextRange_QueryInterface\n"); + ok(punk != NULL, "ITextRange_QueryInterface\n"); + } else skip("Couldn't create ITextRange interface.\n"); IUnknown_Release(punk); punk = NULL; hres = ITextSelection_QueryInterface(txtSel, &IID_IDispatch, (void **) &punk); ok(hres == S_OK, "ITextSelection_QueryInterface\n"); ok(punk != NULL, "ITextSelection_QueryInterface\n"); + if(txtRge) { + hres = ITextRange_QueryInterface(txtRge, &IID_IDispatch, (void **) &punk); + ok(hres == S_OK, "ITextRange_QueryInterface\n"); + ok(punk != NULL, "ITextRange_QueryInterface\n"); + } else skip("Couldn't create ITextRange interface.\n"); IUnknown_Release(punk); ITextDocument_Release(txtDoc); @@ -147,6 +167,7 @@ static void test_Interfaces(void) ok(hres == CO_E_RELEASED, "ITextSelection after ITextDocument destroyed\n"); ITextSelection_Release(txtSel); + release_txtrge(&txtRge); } static void test_ITextDocument_Open(void) @@ -382,6 +403,54 @@ static void test_ITextDocument_Open(void) VariantClear(&testfile); } +void static test_ITextDocument_Range(void) +{ + IRichEditOle *reOle = NULL; + ITextDocument *txtDoc = NULL; + ITextRange *txtRge = NULL; + HRESULT hres; + HWND w; + WCHAR textW[] = {'T', 'e', 's', 't', 'S', 'o', 'm', + 'e', 'T', 'e', 'x', 't', 0}; + LONG cpFirst = 0, cpLim = 0; + BSTR bstr; + + + create_interfaces(&w, &reOle, &txtDoc, NULL); + hres = ITextDocument_Range(txtDoc, 0, 0, &txtRge); + todo_wine ok(hres == S_OK, "ITextDocument_Range fails: 0x%x.\n", hres); + release_txtrge(&txtRge); + release_interfaces(&w, &reOle, &txtDoc, NULL); + + create_interfaces(&w, &reOle, &txtDoc, NULL); + hres = ITextDocument_Range(txtDoc, 0, 0, NULL); + todo_wine ok(hres == E_INVALIDARG, "ITextDocument_Range should return E_INVALIDARG\n"); + release_interfaces(&w, &reOle, &txtDoc, NULL); + + /* The next two tests testify the sequence of pFirst and pLim won't the result. */ + create_interfaces(&w, &reOle, &txtDoc, NULL); + SendMessageW(w, WM_SETTEXT, 0, (LPARAM)textW); + cpFirst = 8; + cpLim = 12; + ITextDocument_Range(txtDoc, cpFirst, cpLim, &txtRge); + if(txtRge) { + hres = ITextRange_GetText(txtRge, &bstr); + todo_wine ok(hres == S_OK, "ITextRange_GetText fails: 0x%x.\n", hres); + todo_wine ok(!lstrcmpW(bstr, &textW[cpFirst]), "ITextDocument_Range get wrong text: %s\n", wine_dbgstr_w(bstr)); + ITextRange_Release(txtRge); + } else skip("Couldn't create ITextRange interface.\n"); + + create_interfaces(&w, &reOle, &txtDoc, NULL); + SendMessageW(w, WM_SETTEXT, 0, (LPARAM)textW); + ITextDocument_Range(txtDoc, cpLim, cpFirst, &txtRge); + if(txtRge) { + hres = ITextRange_GetText(txtRge, &bstr); + todo_wine ok(hres == S_OK, "ITextRange_GetText fails: 0x%x.\n", hres); + todo_wine ok(!lstrcmpW(bstr, &textW[cpFirst]), "ITextDocument_Range get wrong text: %s\n", wine_dbgstr_w(bstr)); + ITextRange_Release(txtRge); + } else skip("Couldn't create ITextRange interface.\n"); +} + START_TEST(richole) { /* Must explicitly LoadLibrary(). The test has no references to functions in @@ -391,4 +460,5 @@ START_TEST(richole) test_Interfaces(); test_ITextDocument_Open(); + test_ITextDocument_Range(); } -- 1.8.3.2