clist.c
来自「一个类似windows」· C语言 代码 · 共 644 行 · 第 1/2 页
C
644 行
for (i = 0; i < inserted->ulSize - sizeof(SHLWAPI_CLIST); i++)
if (bufftest[sizeof(SHLWAPI_CLIST)+i] != i*2)
bDataOK = FALSE;
ok(bDataOK == TRUE, "data corrupted on insert\n");
}
ok(!inserted || inserted->ulId==item->ulId, "find got wrong item\n");
}
item++;
}
/* Write the list */
InitDummyStream(&streamobj);
hRet = pSHLWAPI_17(&streamobj, list);
ok(hRet == S_OK, "write failed\n");
if (hRet == S_OK)
{
/* 1 call for each element, + 1 for OK (use our null element for this) */
ok(streamobj.writecalls == sizeof(SHLWAPI_CLIST_items)/sizeof(SHLWAPI_CLIST),
"wrong call count\n");
ok(streamobj.readcalls == 0,"called Read() in write\n");
ok(streamobj.seekcalls == 0,"called Seek() in write\n");
}
/* Failure cases for writing */
InitDummyStream(&streamobj);
streamobj.failwritecall = TRUE;
hRet = pSHLWAPI_17(&streamobj, list);
ok(hRet == STG_E_ACCESSDENIED, "changed object failure return\n");
ok(streamobj.writecalls == 1, "called object after failure\n");
ok(streamobj.readcalls == 0,"called Read() after failure\n");
ok(streamobj.seekcalls == 0,"called Seek() after failure\n");
InitDummyStream(&streamobj);
streamobj.failwritesize = TRUE;
hRet = pSHLWAPI_17(&streamobj, list);
ok(hRet == STG_E_MEDIUMFULL, "changed size failure return\n");
ok(streamobj.writecalls == 1, "called object after size failure\n");
ok(streamobj.readcalls == 0,"called Read() after failure\n");
ok(streamobj.seekcalls == 0,"called Seek() after failure\n");
/* Invalid inputs for adding */
inserted = (LPSHLWAPI_CLIST)buff;
inserted->ulSize = sizeof(SHLWAPI_CLIST) -1;
inserted->ulId = 33;
hRet = pSHLWAPI_20(&list, inserted);
/* The call succeeds but the item is not inserted, except on some early
* versions which return failure. Wine behaves like later versions.
*/
#if 0
ok(hRet == S_OK, "failed bad element size\n");
#endif
inserted = pSHLWAPI_22(list, 33);
ok(inserted == NULL, "inserted bad element size\n");
inserted = (LPSHLWAPI_CLIST)buff;
inserted->ulSize = 44;
inserted->ulId = ~0UL;
hRet = pSHLWAPI_20(&list, inserted);
/* See comment above, some early versions fail this call */
#if 0
ok(hRet == S_OK, "failed adding a container\n");
#endif
item = SHLWAPI_CLIST_items;
/* Look for nonexistent item in populated list */
inserted = pSHLWAPI_22(list, 99999999);
ok(inserted == NULL, "found a nonexistent item\n");
while (item->ulSize)
{
/* Delete items */
BOOL bRet = pSHLWAPI_21(&list, item->ulId);
ok(bRet == TRUE, "couldn't find item to delete\n");
item++;
}
/* Look for nonexistent item in empty list */
inserted = pSHLWAPI_22(list, 99999999);
ok(inserted == NULL, "found an item in empty list\n");
/* Create a list by reading in data */
InitDummyStream(&streamobj);
hRet = pSHLWAPI_18(&streamobj, &list);
ok(hRet == S_OK, "failed create from Read()\n");
if (hRet == S_OK)
{
ok(streamobj.readbeyondend == FALSE, "read beyond end\n");
/* 2 calls per item, but only 1 for the terminator */
ok(streamobj.readcalls == sizeof(SHLWAPI_CLIST_items)/sizeof(SHLWAPI_CLIST)*2-1,
"wrong call count\n");
ok(streamobj.writecalls == 0, "called Write() from create\n");
ok(streamobj.seekcalls == 0,"called Seek() from create\n");
item = SHLWAPI_CLIST_items;
/* Check the items were added correctly */
while (item->ulSize)
{
inserted = pSHLWAPI_22(list, item->ulId);
ok(inserted != NULL, "lost after adding\n");
ok(!inserted || inserted->ulId != ~0UL, "find returned a container\n");
/* Check size */
if (inserted && inserted->ulSize & 0x3)
{
/* Contained */
ok(inserted[-1].ulId == ~0UL, "invalid size is not countained\n");
ok(inserted[-1].ulSize > inserted->ulSize+sizeof(SHLWAPI_CLIST),
"container too small\n");
}
else if (inserted)
{
ok(inserted->ulSize==item->ulSize+sizeof(SHLWAPI_CLIST),
"id %ld size wrong (%ld!=%ld)\n", inserted->ulId, inserted->ulSize,
item->ulSize+sizeof(SHLWAPI_CLIST));
}
ok(!inserted || inserted->ulId==item->ulId, "find got wrong item\n");
if (inserted)
{
BOOL bDataOK = TRUE;
LPBYTE bufftest = (LPBYTE)inserted;
for (i = 0; i < inserted->ulSize - sizeof(SHLWAPI_CLIST); i++)
if (bufftest[sizeof(SHLWAPI_CLIST)+i] != i*2)
bDataOK = FALSE;
ok(bDataOK == TRUE, "data corrupted on insert\n");
}
item++;
}
}
/* Failure cases for reading */
InitDummyStream(&streamobj);
streamobj.failreadcall = TRUE;
hRet = pSHLWAPI_18(&streamobj, &list);
ok(hRet == STG_E_ACCESSDENIED, "changed object failure return\n");
ok(streamobj.readbeyondend == FALSE, "read beyond end\n");
ok(streamobj.readcalls == 1, "called object after read failure\n");
ok(streamobj.writecalls == 0,"called Write() after read failure\n");
ok(streamobj.seekcalls == 0,"called Seek() after read failure\n");
/* Read returns large object */
InitDummyStream(&streamobj);
streamobj.readreturnlarge = TRUE;
hRet = pSHLWAPI_18(&streamobj, &list);
ok(hRet == S_OK, "failed create from Read() with large item\n");
ok(streamobj.readbeyondend == FALSE, "read beyond end\n");
ok(streamobj.readcalls == 1,"wrong call count\n");
ok(streamobj.writecalls == 0,"called Write() after read failure\n");
ok(streamobj.seekcalls == 2,"wrong Seek() call count (%d)\n", streamobj.seekcalls);
pSHLWAPI_19(list);
}
static BOOL test_SHLWAPI_166(void)
{
_IDummyStream streamobj;
BOOL bRet;
if (!pSHLWAPI_166)
return FALSE;
InitDummyStream(&streamobj);
bRet = pSHLWAPI_166(&streamobj);
if (bRet != TRUE)
return FALSE; /* This version doesn't support stream ops on clists */
ok(streamobj.readcalls == 0, "called Read()\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 0, "called Seek()\n");
ok(streamobj.statcalls == 1, "wrong call count\n");
streamobj.statcalls = 0;
streamobj.pos.QuadPart = 50001;
bRet = pSHLWAPI_166(&streamobj);
ok(bRet == FALSE, "failed after seek adjusted\n");
ok(streamobj.readcalls == 0, "called Read()\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 0, "called Seek()\n");
ok(streamobj.statcalls == 1, "wrong call count\n");
/* Failure cases */
InitDummyStream(&streamobj);
streamobj.pos.QuadPart = 50001;
streamobj.failstatcall = TRUE; /* 1: Stat() Bad, Read() OK */
bRet = pSHLWAPI_166(&streamobj);
ok(bRet == FALSE, "should be FALSE after read is OK\n");
ok(streamobj.readcalls == 1, "wrong call count\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 1, "wrong call count\n");
ok(streamobj.statcalls == 1, "wrong call count\n");
ok(streamobj.pos.QuadPart == 0, "Didn't seek to start\n");
InitDummyStream(&streamobj);
streamobj.pos.QuadPart = 50001;
streamobj.failstatcall = TRUE;
streamobj.failreadcall = TRUE; /* 2: Stat() Bad, Read() Bad Also */
bRet = pSHLWAPI_166(&streamobj);
ok(bRet == TRUE, "Should be true after read fails\n");
ok(streamobj.readcalls == 1, "wrong call count\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 0, "Called Seek()\n");
ok(streamobj.statcalls == 1, "wrong call count\n");
ok(streamobj.pos.QuadPart == 50001, "called Seek() after read failed\n");
return TRUE;
}
static void test_SHLWAPI_184(void)
{
_IDummyStream streamobj;
char buff[256];
HRESULT hRet;
if (!pSHLWAPI_184)
return;
InitDummyStream(&streamobj);
hRet = pSHLWAPI_184(&streamobj, buff, sizeof(buff));
ok(hRet == S_OK, "failed Read()\n");
ok(streamobj.readcalls == 1, "wrong call count\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 0, "called Seek()\n");
}
static void test_SHLWAPI_212(void)
{
_IDummyStream streamobj;
char buff[256];
HRESULT hRet;
if (!pSHLWAPI_212)
return;
InitDummyStream(&streamobj);
hRet = pSHLWAPI_212(&streamobj, buff, sizeof(buff));
ok(hRet == S_OK, "failed Write()\n");
ok(streamobj.readcalls == 0, "called Read()\n");
ok(streamobj.writecalls == 1, "wrong call count\n");
ok(streamobj.seekcalls == 0, "called Seek()\n");
}
static void test_SHLWAPI_213(void)
{
_IDummyStream streamobj;
ULARGE_INTEGER ul;
LARGE_INTEGER ll;
HRESULT hRet;
if (!pSHLWAPI_213 || !pSHLWAPI_214)
return;
InitDummyStream(&streamobj);
ll.QuadPart = 5000l;
Seek(&streamobj, ll, 0, NULL); /* Seek to 5000l */
streamobj.seekcalls = 0;
pSHLWAPI_213(&streamobj); /* Should rewind */
ok(streamobj.statcalls == 0, "called Stat()\n");
ok(streamobj.readcalls == 0, "called Read()\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 1, "wrong call count\n");
ul.QuadPart = 50001;
hRet = pSHLWAPI_214(&streamobj, &ul);
ok(hRet == S_OK, "failed Stat()\n");
ok(ul.QuadPart == 0, "213 didn't rewind stream\n");
}
static void test_SHLWAPI_214(void)
{
_IDummyStream streamobj;
ULARGE_INTEGER ul;
LARGE_INTEGER ll;
HRESULT hRet;
if (!pSHLWAPI_214)
return;
InitDummyStream(&streamobj);
ll.QuadPart = 5000l;
Seek(&streamobj, ll, 0, NULL);
ul.QuadPart = 0;
streamobj.seekcalls = 0;
hRet = pSHLWAPI_214(&streamobj, &ul);
ok(hRet == S_OK, "failed Stat()\n");
ok(streamobj.statcalls == 1, "wrong call count\n");
ok(streamobj.readcalls == 0, "called Read()\n");
ok(streamobj.writecalls == 0, "called Write()\n");
ok(streamobj.seekcalls == 0, "called Seek()\n");
ok(ul.QuadPart == 5000l, "Stat gave wrong size\n");
}
START_TEST(clist)
{
InitFunctionPtrs();
test_CList();
/* Test streaming if this version supports it */
if (test_SHLWAPI_166())
{
test_SHLWAPI_184();
test_SHLWAPI_212();
test_SHLWAPI_213();
test_SHLWAPI_214();
}
if (SHLWAPI_hshlwapi)
FreeLibrary(SHLWAPI_hshlwapi);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?