Commit 289005a7 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

oleaut32/tests: Use a proper static COM object.

parent 269f5bbe
...@@ -1130,16 +1130,27 @@ static void test_SafeArrayGetPutElement_BSTR(void) ...@@ -1130,16 +1130,27 @@ static void test_SafeArrayGetPutElement_BSTR(void)
SysFreeString(gotvalue); SysFreeString(gotvalue);
} }
static int tunk_xref = 0; struct xtunk_impl {
static HRESULT WINAPI tunk_QueryInterface(LPUNKNOWN punk,REFIID riid, LPVOID *x) { IUnknown IUnknown_iface;
return E_FAIL; LONG ref;
};
static const IUnknownVtbl xtunk_vtbl;
static struct xtunk_impl xtunk = {{&xtunk_vtbl}, 0};
static HRESULT WINAPI tunk_QueryInterface(IUnknown *punk, REFIID riid, void **x)
{
return E_FAIL;
} }
static ULONG WINAPI tunk_AddRef(LPUNKNOWN punk) {
return ++tunk_xref; static ULONG WINAPI tunk_AddRef(IUnknown *punk)
{
return ++xtunk.ref;
} }
static ULONG WINAPI tunk_Release(LPUNKNOWN punk) { static ULONG WINAPI tunk_Release(IUnknown *punk)
return --tunk_xref; {
return --xtunk.ref;
} }
static const IUnknownVtbl xtunk_vtbl = { static const IUnknownVtbl xtunk_vtbl = {
...@@ -1148,18 +1159,13 @@ static const IUnknownVtbl xtunk_vtbl = { ...@@ -1148,18 +1159,13 @@ static const IUnknownVtbl xtunk_vtbl = {
tunk_Release tunk_Release
}; };
static struct xtunk_iface {
const IUnknownVtbl *lpvtbl;
} xtunk_iface;
static void test_SafeArrayGetPutElement_IUnknown(void) static void test_SafeArrayGetPutElement_IUnknown(void)
{ {
SAFEARRAYBOUND sab; SAFEARRAYBOUND sab;
LONG indices[1]; LONG indices[1];
SAFEARRAY *sa; SAFEARRAY *sa;
HRESULT hres; HRESULT hres;
LPUNKNOWN value = 0, gotvalue; IUnknown *gotvalue;
sab.lLbound = 1; sab.lLbound = 1;
sab.cElements = 1; sab.cElements = 1;
...@@ -1173,22 +1179,19 @@ static void test_SafeArrayGetPutElement_IUnknown(void) ...@@ -1173,22 +1179,19 @@ static void test_SafeArrayGetPutElement_IUnknown(void)
return; return;
indices[0] = sab.lLbound; indices[0] = sab.lLbound;
xtunk_iface.lpvtbl = &xtunk_vtbl; xtunk.ref = 1;
value = (LPUNKNOWN)&xtunk_iface; hres = SafeArrayPutElement(sa, indices, &xtunk.IUnknown_iface);
tunk_xref = 1;
ok (value != NULL, "Expected non-NULL\n");
hres = SafeArrayPutElement(sa, indices, value);
ok(hres == S_OK, "Failed to put bstr element hres 0x%x\n", hres); ok(hres == S_OK, "Failed to put bstr element hres 0x%x\n", hres);
ok(tunk_xref == 2,"Failed to increment refcount of iface.\n"); ok(xtunk.ref == 2,"Failed to increment refcount of iface.\n");
gotvalue = NULL; gotvalue = NULL;
hres = SafeArrayGetElement(sa, indices, &gotvalue); hres = SafeArrayGetElement(sa, indices, &gotvalue);
ok(tunk_xref == 3,"Failed to increment refcount of iface.\n"); ok(xtunk.ref == 3,"Failed to increment refcount of iface.\n");
ok(hres == S_OK, "Failed to get bstr element at hres 0x%x\n", hres); ok(hres == S_OK, "Failed to get bstr element at hres 0x%x\n", hres);
if (hres == S_OK) if (hres == S_OK)
ok(value == gotvalue, "Got %p instead of %p\n", gotvalue, value); ok(gotvalue == &xtunk.IUnknown_iface, "Got %p instead of %p\n", gotvalue, &xtunk.IUnknown_iface);
hres = SafeArrayDestroy(sa); hres = SafeArrayDestroy(sa);
ok(hres == S_OK, "got 0x%08x\n", hres); ok(hres == S_OK, "got 0x%08x\n", hres);
ok(tunk_xref == 2,"Failed to decrement refcount of iface.\n"); ok(xtunk.ref == 2,"Failed to decrement refcount of iface.\n");
} }
static void test_SafeArrayRedim_IUnknown(void) static void test_SafeArrayRedim_IUnknown(void)
...@@ -1197,7 +1200,6 @@ static void test_SafeArrayRedim_IUnknown(void) ...@@ -1197,7 +1200,6 @@ static void test_SafeArrayRedim_IUnknown(void)
LONG indices[1]; LONG indices[1];
SAFEARRAY *sa; SAFEARRAY *sa;
HRESULT hres; HRESULT hres;
LPUNKNOWN value;
sab.lLbound = 1; sab.lLbound = 1;
sab.cElements = 2; sab.cElements = 2;
...@@ -1211,16 +1213,14 @@ static void test_SafeArrayRedim_IUnknown(void) ...@@ -1211,16 +1213,14 @@ static void test_SafeArrayRedim_IUnknown(void)
return; return;
indices[0] = 2; indices[0] = 2;
xtunk_iface.lpvtbl = &xtunk_vtbl; xtunk.ref = 1;
value = (LPUNKNOWN)&xtunk_iface; hres = SafeArrayPutElement(sa, indices, &xtunk.IUnknown_iface);
tunk_xref = 1;
hres = SafeArrayPutElement(sa, indices, value);
ok(hres == S_OK, "Failed to put IUnknown element hres 0x%x\n", hres); ok(hres == S_OK, "Failed to put IUnknown element hres 0x%x\n", hres);
ok(tunk_xref == 2,"Failed to increment refcount of iface.\n"); ok(xtunk.ref == 2,"Failed to increment refcount of iface.\n");
sab.cElements = 1; sab.cElements = 1;
hres = SafeArrayRedim(sa, &sab); hres = SafeArrayRedim(sa, &sab);
ok(hres == S_OK, "Failed to shrink array hres 0x%x\n", hres); ok(hres == S_OK, "Failed to shrink array hres 0x%x\n", hres);
ok(tunk_xref == 1, "Failed to decrement refcount\n"); ok(xtunk.ref == 1, "Failed to decrement refcount\n");
hres = SafeArrayDestroy(sa); hres = SafeArrayDestroy(sa);
ok(hres == S_OK, "got 0x%08x\n", hres); ok(hres == S_OK, "got 0x%08x\n", hres);
} }
......
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