Commit a50e0d71 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

riched20/tests: Don't use global vars for host/textservices.

parent 242beac6
...@@ -506,8 +506,6 @@ static ITextHostVtbl itextHostVtbl = { ...@@ -506,8 +506,6 @@ static ITextHostVtbl itextHostVtbl = {
ITextHostImpl_TxGetSelectionBarWidth ITextHostImpl_TxGetSelectionBarWidth
}; };
static ITextServices *txtserv = NULL;
static ITextHostTestImpl *dummyTextHost;
static void *wrapperCodeMem = NULL; static void *wrapperCodeMem = NULL;
#include "pshpack1.h" #include "pshpack1.h"
...@@ -606,14 +604,15 @@ static void setup_thiscall_wrappers(void) ...@@ -606,14 +604,15 @@ static void setup_thiscall_wrappers(void)
/* Conformance test functions. */ /* Conformance test functions. */
/* Initialize the test texthost structure */ /* Initialize the test texthost structure */
static BOOL init_texthost(void) static BOOL init_texthost(ITextServices **txtserv, ITextHost **ret)
{ {
ITextHostTestImpl *dummyTextHost;
IUnknown *init; IUnknown *init;
HRESULT result; HRESULT result;
dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost)); dummyTextHost = CoTaskMemAlloc(sizeof(*dummyTextHost));
if (dummyTextHost == NULL) { if (dummyTextHost == NULL) {
skip("Insufficient memory to create ITextHost interface\n"); win_skip("Insufficient memory to create ITextHost interface\n");
return FALSE; return FALSE;
} }
dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl; dummyTextHost->ITextHost_iface.lpVtbl = &itextHostVtbl;
...@@ -622,54 +621,53 @@ static BOOL init_texthost(void) ...@@ -622,54 +621,53 @@ static BOOL init_texthost(void)
/* MSDN states that an IUnknown object is returned by /* MSDN states that an IUnknown object is returned by
CreateTextServices which is then queried to obtain a CreateTextServices which is then queried to obtain a
ITextServices object. */ ITextServices object. */
result = (*pCreateTextServices)(NULL, &dummyTextHost->ITextHost_iface, &init); result = pCreateTextServices(NULL, &dummyTextHost->ITextHost_iface, &init);
ok(result == S_OK, "Did not return S_OK when created (result = %x)\n", result); ok(result == S_OK, "Did not return S_OK when created (result = %x)\n", result);
if (result != S_OK) { if (result != S_OK) {
CoTaskMemFree(dummyTextHost); CoTaskMemFree(dummyTextHost);
skip("CreateTextServices failed.\n"); win_skip("CreateTextServices failed.\n");
return FALSE; return FALSE;
} }
result = IUnknown_QueryInterface(init, pIID_ITextServices, result = IUnknown_QueryInterface(init, pIID_ITextServices, (void**)txtserv);
(void **)&txtserv); ok((result == S_OK) && (*txtserv != NULL), "Querying interface failed (result = %x, txtserv = %p)\n", result, *txtserv);
ok((result == S_OK) && (txtserv != NULL), "Querying interface failed (result = %x, txtserv = %p)\n", result, txtserv);
IUnknown_Release(init); IUnknown_Release(init);
if (!((result == S_OK) && (txtserv != NULL))) { if (!((result == S_OK) && (*txtserv != NULL))) {
CoTaskMemFree(dummyTextHost); CoTaskMemFree(dummyTextHost);
skip("Could not retrieve ITextServices interface\n"); win_skip("Could not retrieve ITextServices interface\n");
return FALSE; return FALSE;
} }
*ret = &dummyTextHost->ITextHost_iface;
return TRUE; return TRUE;
} }
static void free_texthost(void)
{
ITextServices_Release(txtserv);
CoTaskMemFree(dummyTextHost);
}
static void test_TxGetText(void) static void test_TxGetText(void)
{ {
ITextServices *txtserv;
ITextHost *host;
HRESULT hres; HRESULT hres;
BSTR rettext; BSTR rettext;
if (!init_texthost()) if (!init_texthost(&txtserv, &host))
return; return;
hres = ITextServices_TxGetText(txtserv, &rettext); hres = ITextServices_TxGetText(txtserv, &rettext);
ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres); ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres);
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
} }
static void test_TxSetText(void) static void test_TxSetText(void)
{ {
ITextServices *txtserv;
ITextHost *host;
HRESULT hres; HRESULT hres;
BSTR rettext; BSTR rettext;
WCHAR settext[] = {'T','e','s','t',0}; WCHAR settext[] = {'T','e','s','t',0};
if (!init_texthost()) if (!init_texthost(&txtserv, &host))
return; return;
hres = ITextServices_TxSetText(txtserv, settext); hres = ITextServices_TxSetText(txtserv, settext);
...@@ -684,10 +682,14 @@ static void test_TxSetText(void) ...@@ -684,10 +682,14 @@ static void test_TxSetText(void)
"String returned differs\n"); "String returned differs\n");
SysFreeString(rettext); SysFreeString(rettext);
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
} }
static void test_TxGetNaturalSize(void) { static void test_TxGetNaturalSize(void)
{
ITextServices *txtserv;
ITextHost *host;
HRESULT result; HRESULT result;
BOOL ret; BOOL ret;
...@@ -710,7 +712,7 @@ static void test_TxGetNaturalSize(void) { ...@@ -710,7 +712,7 @@ static void test_TxGetNaturalSize(void) {
INT charwidth_caps_text[26]; INT charwidth_caps_text[26];
TEXTMETRICA tmInfo_text; TEXTMETRICA tmInfo_text;
if (!init_texthost()) if (!init_texthost(&txtserv, &host))
return; return;
hdcDraw = GetDC(NULL); hdcDraw = GetDC(NULL);
...@@ -759,11 +761,14 @@ static void test_TxGetNaturalSize(void) { ...@@ -759,11 +761,14 @@ static void test_TxGetNaturalSize(void) {
cleanup: cleanup:
RestoreDC(hdcDraw,1); RestoreDC(hdcDraw,1);
ReleaseDC(NULL,hdcDraw); ReleaseDC(NULL,hdcDraw);
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
} }
static void test_TxDraw(void) static void test_TxDraw(void)
{ {
ITextServices *txtserv;
ITextHost *host;
HDC tmphdc = GetDC(NULL); HDC tmphdc = GetDC(NULL);
DWORD dwAspect = DVASPECT_CONTENT; DWORD dwAspect = DVASPECT_CONTENT;
HDC hicTargetDev = NULL; /* Means "default" device */ HDC hicTargetDev = NULL; /* Means "default" device */
...@@ -772,7 +777,8 @@ static void test_TxDraw(void) ...@@ -772,7 +777,8 @@ static void test_TxDraw(void)
HRESULT result; HRESULT result;
RECTL client = {0,0,100,100}; RECTL client = {0,0,100,100};
if (!init_texthost())
if (!init_texthost(&txtserv, &host))
return; return;
todo_wine { todo_wine {
...@@ -782,8 +788,8 @@ static void test_TxDraw(void) ...@@ -782,8 +788,8 @@ static void test_TxDraw(void)
ok(result == S_OK, "TxDraw failed (result = %x)\n", result); ok(result == S_OK, "TxDraw failed (result = %x)\n", result);
} }
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
} }
DEFINE_GUID(expected_iid_itextservices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5); DEFINE_GUID(expected_iid_itextservices, 0x8d33f740, 0xcf58, 0x11ce, 0xa8, 0x9d, 0x00, 0xaa, 0x00, 0x6c, 0xad, 0xc5);
...@@ -872,12 +878,14 @@ static ULONG get_refcount(IUnknown *iface) ...@@ -872,12 +878,14 @@ static ULONG get_refcount(IUnknown *iface)
static void test_QueryInterface(void) static void test_QueryInterface(void)
{ {
ITextServices *txtserv;
ITextHost *host;
HRESULT hres; HRESULT hres;
IRichEditOle *reole, *txtsrv_reole; IRichEditOle *reole, *txtsrv_reole;
ITextDocument *txtdoc, *txtsrv_txtdoc; ITextDocument *txtdoc, *txtsrv_txtdoc;
ULONG refcount; ULONG refcount;
if(!init_texthost()) if(!init_texthost(&txtserv, &host))
return; return;
refcount = get_refcount((IUnknown *)txtserv); refcount = get_refcount((IUnknown *)txtserv);
...@@ -927,11 +935,15 @@ static void test_QueryInterface(void) ...@@ -927,11 +935,15 @@ static void test_QueryInterface(void)
refcount = get_refcount((IUnknown *)txtserv); refcount = get_refcount((IUnknown *)txtserv);
ok(refcount == 1, "got wrong ref count: %d\n", refcount); ok(refcount == 1, "got wrong ref count: %d\n", refcount);
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
} }
START_TEST( txtsrv ) START_TEST( txtsrv )
{ {
ITextServices *txtserv;
ITextHost *host;
setup_thiscall_wrappers(); setup_thiscall_wrappers();
/* Must explicitly LoadLibrary(). The test has no references to functions in /* Must explicitly LoadLibrary(). The test has no references to functions in
...@@ -947,9 +959,10 @@ START_TEST( txtsrv ) ...@@ -947,9 +959,10 @@ START_TEST( txtsrv )
test_IIDs(); test_IIDs();
test_COM(); test_COM();
if (init_texthost()) if (init_texthost(&txtserv, &host))
{ {
free_texthost(); ITextServices_Release(txtserv);
ITextHost_Release(host);
test_TxGetText(); test_TxGetText();
test_TxSetText(); test_TxSetText();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment