Commit 3879d98d authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

shlwapi/tests: COM cleanup for the dummy IStream iface.

parent 4d3ba031
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#define COBJMACROS
#include <stdarg.h> #include <stdarg.h>
#include "wine/test.h" #include "wine/test.h"
...@@ -50,9 +51,9 @@ static const SHLWAPI_CLIST SHLWAPI_CLIST_items[] = ...@@ -50,9 +51,9 @@ static const SHLWAPI_CLIST SHLWAPI_CLIST_items[] =
}; };
/* Dummy IStream object for testing calls */ /* Dummy IStream object for testing calls */
typedef struct typedef struct dummystream
{ {
void* lpVtbl; IStream IStream_iface;
LONG ref; LONG ref;
int readcalls; int readcalls;
BOOL failreadcall; BOOL failreadcall;
...@@ -69,28 +70,43 @@ typedef struct ...@@ -69,28 +70,43 @@ typedef struct
ULARGE_INTEGER pos; ULARGE_INTEGER pos;
} _IDummyStream; } _IDummyStream;
static static inline struct dummystream *impl_from_IStream(IStream *iface)
HRESULT WINAPI QueryInterface(_IDummyStream *This,REFIID riid, LPVOID *ppvObj)
{ {
return S_OK; return CONTAINING_RECORD(iface, struct dummystream, IStream_iface);
} }
static ULONG WINAPI AddRef(_IDummyStream *This) static HRESULT WINAPI QueryInterface(IStream *iface, REFIID riid, void **ret_iface)
{ {
return InterlockedIncrement(&This->ref); if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IStream, riid)) {
*ret_iface = iface;
IStream_AddRef(iface);
return S_OK;
}
trace("Unexpected REFIID %s\n", wine_dbgstr_guid(riid));
*ret_iface = NULL;
return E_NOINTERFACE;
} }
static ULONG WINAPI Release(_IDummyStream *This) static ULONG WINAPI AddRef(IStream *iface)
{ {
return InterlockedDecrement(&This->ref); struct dummystream *This = impl_from_IStream(iface);
return InterlockedIncrement(&This->ref);
} }
static HRESULT WINAPI Read(_IDummyStream* This, LPVOID lpMem, ULONG ulSize, static ULONG WINAPI Release(IStream *iface)
PULONG lpRead)
{ {
struct dummystream *This = impl_from_IStream(iface);
return InterlockedDecrement(&This->ref);
}
static HRESULT WINAPI Read(IStream *iface, void *lpMem, ULONG ulSize, ULONG *lpRead)
{
struct dummystream *This = impl_from_IStream(iface);
HRESULT hRet = S_OK; HRESULT hRet = S_OK;
++This->readcalls;
++This->readcalls;
if (This->failreadcall) if (This->failreadcall)
{ {
return STG_E_ACCESSDENIED; return STG_E_ACCESSDENIED;
...@@ -136,9 +152,9 @@ static HRESULT WINAPI Read(_IDummyStream* This, LPVOID lpMem, ULONG ulSize, ...@@ -136,9 +152,9 @@ static HRESULT WINAPI Read(_IDummyStream* This, LPVOID lpMem, ULONG ulSize,
return hRet; return hRet;
} }
static HRESULT WINAPI Write(_IDummyStream* This, LPVOID lpMem, ULONG ulSize, static HRESULT WINAPI Write(IStream *iface, const void *lpMem, ULONG ulSize, ULONG *lpWritten)
PULONG lpWritten)
{ {
struct dummystream *This = impl_from_IStream(iface);
HRESULT hRet = S_OK; HRESULT hRet = S_OK;
++This->writecalls; ++This->writecalls;
...@@ -155,9 +171,11 @@ static HRESULT WINAPI Write(_IDummyStream* This, LPVOID lpMem, ULONG ulSize, ...@@ -155,9 +171,11 @@ static HRESULT WINAPI Write(_IDummyStream* This, LPVOID lpMem, ULONG ulSize,
return hRet; return hRet;
} }
static HRESULT WINAPI Seek(_IDummyStream* This, LARGE_INTEGER dlibMove, static HRESULT WINAPI Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) ULARGE_INTEGER *plibNewPosition)
{ {
struct dummystream *This = impl_from_IStream(iface);
++This->seekcalls; ++This->seekcalls;
This->pos.QuadPart = dlibMove.QuadPart; This->pos.QuadPart = dlibMove.QuadPart;
if (plibNewPosition) if (plibNewPosition)
...@@ -165,9 +183,10 @@ static HRESULT WINAPI Seek(_IDummyStream* This, LARGE_INTEGER dlibMove, ...@@ -165,9 +183,10 @@ static HRESULT WINAPI Seek(_IDummyStream* This, LARGE_INTEGER dlibMove,
return S_OK; return S_OK;
} }
static HRESULT WINAPI Stat(_IDummyStream* This, STATSTG* pstatstg, static HRESULT WINAPI Stat(IStream *iface, STATSTG *pstatstg, DWORD grfStatFlag)
DWORD grfStatFlag)
{ {
struct dummystream *This = impl_from_IStream(iface);
++This->statcalls; ++This->statcalls;
if (This->failstatcall) if (This->failstatcall)
return E_FAIL; return E_FAIL;
...@@ -177,7 +196,7 @@ static HRESULT WINAPI Stat(_IDummyStream* This, STATSTG* pstatstg, ...@@ -177,7 +196,7 @@ static HRESULT WINAPI Stat(_IDummyStream* This, STATSTG* pstatstg,
} }
/* VTable */ /* VTable */
static void* iclvt[] = static IStreamVtbl iclvt =
{ {
QueryInterface, QueryInterface,
AddRef, AddRef,
...@@ -248,23 +267,23 @@ static BOOL InitFunctionPtrs(void) ...@@ -248,23 +267,23 @@ static BOOL InitFunctionPtrs(void)
return TRUE; return TRUE;
} }
static void InitDummyStream(_IDummyStream* iface) static void InitDummyStream(struct dummystream *obj)
{ {
iface->lpVtbl = (void*)iclvt; obj->IStream_iface.lpVtbl = &iclvt;
iface->ref = 1; obj->ref = 1;
iface->readcalls = 0; obj->readcalls = 0;
iface->failreadcall = FALSE; obj->failreadcall = FALSE;
iface->failreadsize = FALSE; obj->failreadsize = FALSE;
iface->readbeyondend = FALSE; obj->readbeyondend = FALSE;
iface->readreturnlarge = FALSE; obj->readreturnlarge = FALSE;
iface->writecalls = 0; obj->writecalls = 0;
iface->failwritecall = FALSE; obj->failwritecall = FALSE;
iface->failwritesize = FALSE; obj->failwritesize = FALSE;
iface->seekcalls = 0; obj->seekcalls = 0;
iface->statcalls = 0; obj->statcalls = 0;
iface->failstatcall = FALSE; obj->failstatcall = FALSE;
iface->item = SHLWAPI_CLIST_items; obj->item = SHLWAPI_CLIST_items;
iface->pos.QuadPart = 0; obj->pos.QuadPart = 0;
} }
...@@ -585,7 +604,7 @@ static void test_SHLWAPI_213(void) ...@@ -585,7 +604,7 @@ static void test_SHLWAPI_213(void)
InitDummyStream(&streamobj); InitDummyStream(&streamobj);
ll.QuadPart = 5000l; ll.QuadPart = 5000l;
Seek(&streamobj, ll, 0, NULL); /* Seek to 5000l */ Seek(&streamobj.IStream_iface, ll, 0, NULL); /* Seek to 5000l */
streamobj.seekcalls = 0; streamobj.seekcalls = 0;
pSHLWAPI_213(&streamobj); /* Should rewind */ pSHLWAPI_213(&streamobj); /* Should rewind */
...@@ -612,7 +631,7 @@ static void test_SHLWAPI_214(void) ...@@ -612,7 +631,7 @@ static void test_SHLWAPI_214(void)
InitDummyStream(&streamobj); InitDummyStream(&streamobj);
ll.QuadPart = 5000l; ll.QuadPart = 5000l;
Seek(&streamobj, ll, 0, NULL); Seek(&streamobj.IStream_iface, ll, 0, NULL);
ul.QuadPart = 0; ul.QuadPart = 0;
streamobj.seekcalls = 0; streamobj.seekcalls = 0;
hRet = pSHLWAPI_214(&streamobj, &ul); hRet = pSHLWAPI_214(&streamobj, &ul);
......
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