clist.c

来自「Wine-20031016」· C语言 代码 · 共 633 行 · 第 1/2 页

C
633
字号
      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");      }      ok(!inserted || inserted->ulId==item->ulId, "find got wrong item");    }    item++;  }  /* Write the list */  InitDummyStream(&streamobj);  hRet = pSHLWAPI_17(&streamobj, list);  ok(hRet == S_OK, "write failed");  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");    ok(streamobj.readcalls == 0,"called Read() in write");    ok(streamobj.seekcalls == 0,"called Seek() in write");  }  /* Failure cases for writing */  InitDummyStream(&streamobj);  streamobj.failwritecall = TRUE;  hRet = pSHLWAPI_17(&streamobj, list);  ok(hRet == STG_E_ACCESSDENIED, "changed object failure return");  ok(streamobj.writecalls == 1, "called object after failure");  ok(streamobj.readcalls == 0,"called Read() after failure");  ok(streamobj.seekcalls == 0,"called Seek() after failure");  InitDummyStream(&streamobj);  streamobj.failwritesize = TRUE;  hRet = pSHLWAPI_17(&streamobj, list);  ok(hRet == STG_E_MEDIUMFULL, "changed size failure return");  ok(streamobj.writecalls == 1, "called object after size failure");  ok(streamobj.readcalls == 0,"called Read() after failure");  ok(streamobj.seekcalls == 0,"called Seek() after failure");  /* 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 */  ok(hRet == S_OK, "failed bad element size");  inserted = pSHLWAPI_22(list, 33);  ok(inserted == NULL, "inserted bad element size");  inserted = (LPSHLWAPI_CLIST)buff;  inserted->ulSize = 44;  inserted->ulId = ~0UL;  hRet = pSHLWAPI_20(&list, inserted);  /* The call succeeds but the item is not inserted */  ok(hRet == S_OK, "failed adding a container");  item = SHLWAPI_CLIST_items;  /* Look for non-existing item in populated list */  inserted = pSHLWAPI_22(list, 99999999);  ok(inserted == NULL, "found a non-existing item");  while (item->ulSize)  {    /* Delete items */    BOOL bRet = pSHLWAPI_21(&list, item->ulId);    ok(bRet == TRUE, "couldn't find item to delete");    item++;  }  /* Look for non-existing item in empty list */  inserted = pSHLWAPI_22(list, 99999999);  ok(inserted == NULL, "found an item in empty list");  /* Create a list by reading in data */  InitDummyStream(&streamobj);  hRet = pSHLWAPI_18(&streamobj, &list);  ok(hRet == S_OK, "failed create from Read()");  if (hRet == S_OK)  {    ok(streamobj.readbeyondend == FALSE, "read beyond end");    /* 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");    ok(streamobj.writecalls == 0, "called Write() from create");    ok(streamobj.seekcalls == 0,"called Seek() from create");    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");      ok(!inserted || inserted->ulId != ~0UL, "find returned a container");      /* Check size */      if (inserted && inserted->ulSize & 0x3)      {        /* Contained */        ok(inserted[-1].ulId == ~0UL, "invalid size is not countained");        ok(inserted[-1].ulSize > inserted->ulSize+sizeof(SHLWAPI_CLIST),           "container too small");      }      else if (inserted)      {        ok(inserted->ulSize==item->ulSize+sizeof(SHLWAPI_CLIST),           "id %ld size wrong (%ld!=%ld)", inserted->ulId, inserted->ulSize,           item->ulSize+sizeof(SHLWAPI_CLIST));      }      ok(!inserted || inserted->ulId==item->ulId, "find got wrong item");      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");      }      item++;    }  }  /* Failure cases for reading */  InitDummyStream(&streamobj);  streamobj.failreadcall = TRUE;  hRet = pSHLWAPI_18(&streamobj, &list);  ok(hRet == STG_E_ACCESSDENIED, "changed object failure return");  ok(streamobj.readbeyondend == FALSE, "read beyond end");  ok(streamobj.readcalls == 1, "called object after read failure");  ok(streamobj.writecalls == 0,"called Write() after read failure");  ok(streamobj.seekcalls == 0,"called Seek() after read failure");  /* 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");  ok(streamobj.readbeyondend == FALSE, "read beyond end");  ok(streamobj.readcalls == 1,"wrong call count");  ok(streamobj.writecalls == 0,"called Write() after read failure");  ok(streamobj.seekcalls == 2,"wrong Seek() call count (%d)", streamobj.seekcalls);  pSHLWAPI_19(list);}static void test_SHLWAPI_166(void){  _IDummyStream streamobj;  BOOL bRet;  if (!pSHLWAPI_166)    return;  InitDummyStream(&streamobj);  bRet = pSHLWAPI_166(&streamobj);  ok(bRet == TRUE, "failed before seek adjusted");  ok(streamobj.readcalls == 0, "called Read()");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 0, "called Seek()");  ok(streamobj.statcalls == 1, "wrong call count");  streamobj.statcalls = 0;  streamobj.pos.QuadPart = 50001;  bRet = pSHLWAPI_166(&streamobj);  ok(bRet == FALSE, "failed after seek adjusted");  ok(streamobj.readcalls == 0, "called Read()");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 0, "called Seek()");  ok(streamobj.statcalls == 1, "wrong call count");  /* 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");  ok(streamobj.readcalls == 1, "wrong call count");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 1, "wrong call count");  ok(streamobj.statcalls == 1, "wrong call count");  ok(streamobj.pos.QuadPart == 0, "Didn't seek to start");  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");  ok(streamobj.readcalls == 1, "wrong call count");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 0, "Called Seek()");  ok(streamobj.statcalls == 1, "wrong call count");  ok(streamobj.pos.QuadPart == 50001, "called Seek() after read failed");}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()");  ok(streamobj.readcalls == 1, "wrong call count");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 0, "called Seek()");}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()");  ok(streamobj.readcalls == 0, "called Read()");  ok(streamobj.writecalls == 1, "wrong call count");  ok(streamobj.seekcalls == 0, "called Seek()");}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()");  ok(streamobj.readcalls == 0, "called Read()");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 1, "wrong call count");  ul.QuadPart = 50001;  hRet = pSHLWAPI_214(&streamobj, &ul);  ok(hRet == S_OK, "failed Stat()");  ok(ul.QuadPart == 0, "213 didn't rewind stream");}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()");  ok(streamobj.statcalls == 1, "wrong call count");  ok(streamobj.readcalls == 0, "called Read()");  ok(streamobj.writecalls == 0, "called Write()");  ok(streamobj.seekcalls == 0, "called Seek()");  ok(ul.QuadPart == 5000l, "Stat gave wrong size");}START_TEST(clist){  InitFunctionPtrs();  test_CList();  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 + -
显示快捷键?