views:

51

answers:

2

Every COM object must have integrity. In simplified terms this means that if an object implements 3 interfaces - A, B and C and I have A* pointer to the object I must be able to successfully QueryInterface() both B and C and having B I must be able to retrieve A and C and having C I must be able to retrieve A and B.

Now my object implements 5 interfaces and I want to test its integrity. Writing checks for all of the above myself will require a substantial effort. Is there a tool or some easily tweakable code or a code pattern that would do it?

+2  A: 

I don't see the problem. If you implement A, B and C then interface A must QI properly for A, B, C and IUnknown. Including itself. The test is the same for all interfaces, you need only one small function that takes an IUnknown* argument.

Hans Passant
Did like this, works great. It becomes even simpler if IUnknown is added to the set of interfaces to test.
sharptooth
+1  A: 

Hi,

If I understood it correctly you want to proof that your implementation abides by COM IUnknown rules (transitivity, reflexivity, etc.) and you are concerned with the exponential explosion based on the number of interfaces right?

If you have the component type library you can write an application that figures out the coclasses/interfaces and emits code to test these rules (this application is generic and can be used with any component that has a type library). Maybe you can even find one in the net (I didn't searched)

Best

Adriano

Vagaus
Actually the exponential exposion is not that of a problem since it's hard to imagine that any object implements like more than 20 interfaces. The problem is how to write the code that surely tests all the necessary QI() request paths.
sharptooth