rollbear / trompeloeil

Header only C++14 mocking framework
Boost Software License 1.0
802 stars 85 forks source link

Allow specifying STDMETHODCALLTYPE to Mock methods #337

Closed cesenaLA closed 1 month ago

cesenaLA commented 3 months ago

Adds new IMPLEMENT_STDMETHOD_MOCKn and MAKE_STDMETHOD_MOCKn to allow to mock COM interfaces declared using STDMETHOD(name) i.e. virtual HRESULT __stdcall name (...). As .idl/.tlb do not support cvref-qualified methods, so there's no need for all the permutations of STDMETHODCALLTYPE vs const/volatile/rvalue/etc.

The new macros are implemented by extending TROMPELOEIL_MAKE_MOCK_ to take a calling convention and placing it in the correct location allowed by the microsoft compiler. This also means that the new macros only work on Windows.

It also add tests and documentation for the new macros.

Closes #329

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.09%. Comparing base (8f36c45) to head (fd94c04). Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #337 +/- ## ========================================== - Coverage 99.10% 99.09% -0.01% ========================================== Files 12 12 Lines 1001 996 -5 Branches 21 0 -21 ========================================== - Hits 992 987 -5 Misses 9 9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

rollbear commented 2 months ago

I'm a bit confused by this. It solves a much more specific problem than the issue you originally opened. Is there a reason for limiting the support to only ´STDMETHOD`?

The change is good, BTW. Very good! Especially the docs and the extended test suite.

cesenaLA commented 2 months ago

Yes, the scope of the PR was reduced to only handle STDMETHOD, use when implementing COM interfaces on windows (which is our use case) based on the comment from @puetzk https://github.com/rollbear/trompeloeil/issues/329#issuecomment-2036157088