comsupport.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef _MSC_VER
4 #include <hippomocks.h>
5 #include <winerror.h>
6 
7 struct _GUID;
8 
9 template <typename T>
10 void AddComExpectations(HM_NS MockRepository &mocks, T *m)
11 {
12  mocks.OnCall(m, T::AddRef)
13  .Return(1);
14  mocks.OnCall(m, T::Release)
15  .Return(1);
16  mocks.OnCallOverload(m, (long(__stdcall T::*)(const _GUID &, void **))&T::QueryInterface)
17  .With(__uuidof(T), Out((void **)m))
18  .Return(S_OK);
19 
20  mocks.OnCallOverload(m, (long(__stdcall T::*)(const IID &, void **))&T::QueryInterface)
21  .With(__uuidof(IUnknown), Out((void **)m))
22  .Return(S_OK);
23 
24 }
25 
26 template <typename T1, typename T2>
27 void ConnectComInterfaces(HM_NS MockRepository &mocks, T1 *m1, T2 *m2)
28 {
29  //from T1 to T2
30  mocks.OnCallOverload(m1, (long(__stdcall T1::*)(const _GUID &, void **))&T1::QueryInterface)
31  .With(__uuidof(T2), Out((void **)m2))
32  .Return(S_OK);
33  //from T2 to T1
34  mocks.OnCallOverload(m2, (long(__stdcall T2::*)(const _GUID &, void **))&T2::QueryInterface)
35  .With(__uuidof(T1), Out((void **)m1))
36  .Return(S_OK);
37 
38  AddComExpectations(mocks, m1);
39  AddComExpectations(mocks, m2);
40 
41  //no support for interface hierarchies
42  //no Base IUnknown -> do it yourself if you really need that special case
43 }
44 #endif