Guest User

Untitled

a guest
Apr 9th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct destroy_context
  2. {
  3.     IDirect3DRMObject *obj;
  4.     unsigned int test_idx;
  5.     int called;
  6. };
  7.  
  8. struct callback_order
  9. {
  10.     int id;
  11.     void *callback;
  12.     void *context;
  13. } corder[10], d3drm_corder[10];
  14.  
  15. static void CDECL destroy_callback(IDirect3DRMObject *obj, void *arg)
  16. {
  17.     struct destroy_context *ctxt = arg;
  18.     ok(ctxt->called == 1 || ctxt->called == 2, "got called counter %d\n", ctxt->called);
  19.     ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
  20.     d3drm_corder[ctxt->called].id = ctxt->called;
  21.     d3drm_corder[ctxt->called].callback = &destroy_callback;
  22.     d3drm_corder[ctxt->called++].context = ctxt;
  23. }
  24.  
  25. static void CDECL destroy_callback1(IDirect3DRMObject *obj, void *arg)
  26. {
  27.     struct destroy_context *ctxt = (struct destroy_context*)arg;
  28.     ok(ctxt->called == 0, "got called counter %d\n", ctxt->called);
  29.     ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
  30.     d3drm_corder[ctxt->called].id = ctxt->called;
  31.     d3drm_corder[ctxt->called].callback = &destroy_callback1;
  32.     d3drm_corder[ctxt->called++].context = ctxt;
  33. }
  34.  
  35. static void test_destroy_callback(unsigned int test_idx, REFCLSID clsid, REFIID iid)
  36. {
  37.     struct destroy_context context;
  38.     IDirect3DRMObject *obj;
  39.     IUnknown *unknown;
  40.     IDirect3DRM *d3drm;
  41.     HRESULT hr;
  42.     int i;
  43.  
  44.     hr = Direct3DRMCreate(&d3drm);
  45.     ok(SUCCEEDED(hr), "Test %u: Cannot get IDirect3DRM interface (hr = %x).\n", test_idx, hr);
  46.  
  47.     hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
  48.     ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
  49.     hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
  50.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  51.     IUnknown_Release(unknown);
  52.  
  53.     context.called = 0;
  54.     context.test_idx = test_idx;
  55.     context.obj = obj;
  56.  
  57.     hr = IDirect3DRMObject_AddDestroyCallback(obj, NULL, &context);
  58.     ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRMERR_BADVALUE (hr = %x).\n", test_idx, hr);
  59.  
  60.     hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
  61.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  62.     corder[2].id = 2;
  63.     corder[2].callback = &destroy_callback;
  64.     corder[2].context = &context;
  65.  
  66.     /* same callback added twice */
  67.     hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
  68.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  69.     corder[1].id = 1;
  70.     corder[1].callback = &destroy_callback;
  71.     corder[1].context = &context;
  72.  
  73.     hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, NULL);
  74.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  75.  
  76.     hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, &context);
  77.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  78.  
  79.     /* add one more */
  80.     hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
  81.     ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
  82.     corder[0].id = 0;
  83.     corder[0].callback = &destroy_callback1;
  84.     corder[0].context = &context;
  85.  
  86.     hr = IDirect3DRMObject_DeleteDestroyCallback(obj, NULL, NULL);
  87.     ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRM_BADVALUE (hr = %x).\n", test_idx, hr);
  88.  
  89.     context.called = 0;
  90.     IDirect3DRMObject_Release(obj);
  91.     ok(context.called == 3, "Test %u: got %d, expected 3.\n", test_idx, context.called);
  92.     for (i = 0; i < context.called; i++)
  93.     {
  94.         ok(corder[i].callback == d3drm_corder[i].callback
  95.            && corder[i].context == d3drm_corder[i].context
  96.            && corder[i].id == d3drm_corder[i].id, "Call order not matching.\n");
  97.     }
  98. /* ... */
Add Comment
Please, Sign In to add comment