Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.7 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // File: cfrace.cxx
  4. //
  5. // Contents: test for class factory race condition
  6. //
  7. //--------------------------------------------------------------------
  8. #include <tstmain.hxx>
  9. #include "cfrace.h"
  10. #include <iballs.h>
  11. // BUGBUG: these should be in a public place somewhere.
  12. DEFINE_OLEGUID(CLSID_Balls, 0x0000013a, 1, 8);
  13. DEFINE_OLEGUID(CLSID_Cubes, 0x0000013b, 1, 8);
  14. DEFINE_OLEGUID(CLSID_LoopSrv, 0x0000013c, 1, 8);
  15. DEFINE_OLEGUID(CLSID_QI, 0x00000140, 0, 8);
  16. const GUID CLSID_QI =
  17. {0x00000140,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  18. DWORD gdwSleepValue = 400;
  19. LONG gcFails = 0;
  20. void TEST_FAILED2(HRESULT hRes, CHAR *pszMsg)
  21. {
  22. BOOL RetVal = TRUE;
  23. CHAR szMsg2[80];
  24. if (FAILED(hRes))
  25. {
  26. gcFails++;
  27. sprintf(szMsg2, "Error:%x %s", hRes, pszMsg);
  28. }
  29. TEST_FAILED(FAILED(hRes), (FAILED(hRes)) ? szMsg2 : pszMsg);
  30. }
  31. void TEST_FAILED3(ULONG cRefs, CHAR *pszMsg)
  32. {
  33. BOOL RetVal = TRUE;
  34. CHAR szMsg2[80];
  35. if (cRefs != 0)
  36. {
  37. gcFails++;
  38. sprintf(szMsg2, "cRefs:%x %s", cRefs, pszMsg);
  39. }
  40. TEST_FAILED(cRefs != 0, (cRefs != 0) ? szMsg2 : pszMsg);
  41. }
  42. // ----------------------------------------------------------------------
  43. //
  44. // TestCFRace - main test driver. read the ini file to determine
  45. // which tests to run.
  46. //
  47. // ----------------------------------------------------------------------
  48. BOOL TestCFRace(void)
  49. {
  50. BOOL RetVal = TRUE;
  51. CHAR szMsg[80];
  52. LONG cLoops = 0;
  53. while (1)
  54. {
  55. IClassFactory *pICF = NULL;
  56. IBalls *pIBalls = NULL;
  57. ULONG cRefs = 0;
  58. // get the class object
  59. HRESULT hRes = CoGetClassObject(CLSID_Balls, CLSCTX_LOCAL_SERVER, NULL,
  60. IID_IClassFactory, (void **)&pICF);
  61. TEST_FAILED2(hRes, "CoGetClassObject failed\n");
  62. if (SUCCEEDED(hRes))
  63. {
  64. // lock server
  65. hRes = pICF->LockServer(TRUE);
  66. TEST_FAILED2(hRes, "LockServer TRUE failed\n");
  67. if (SUCCEEDED(hRes))
  68. {
  69. // create instance
  70. hRes = pICF->CreateInstance(NULL, IID_IBalls, (void **)&pIBalls);
  71. TEST_FAILED2(hRes, "CreateInstance failed\n");
  72. // unlock server
  73. hRes = pICF->LockServer(FALSE);
  74. TEST_FAILED2(hRes, "LockServer FALSE failed\n");
  75. }
  76. // release class object
  77. cRefs = pICF->Release();
  78. TEST_FAILED3(cRefs, "Release pICF not 0\n");
  79. if (pIBalls)
  80. {
  81. // call instance
  82. hRes = pIBalls->MoveBall(10, 20);
  83. TEST_FAILED2(hRes, "pIBalls MoveBall failed\n");
  84. // release instance
  85. cRefs = pIBalls->Release();
  86. TEST_FAILED3(cRefs, "Release pIBalls not 0\n");
  87. }
  88. }
  89. cLoops++;
  90. sprintf(szMsg, " - Iterations:%x Fails:%x\n", cLoops, gcFails);
  91. OUTPUT(szMsg);
  92. Sleep(gdwSleepValue);
  93. }
  94. return RetVal;
  95. }