Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying STDMETHODCALLTYPE to Mock methods #337

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cesenaLA
Copy link

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

puetzk and others added 4 commits May 20, 2024 08:06
MSVC insistes that calling-convention modifiers go between the
return type and function name, rather than at the end with other spec

In this commit all higher-level macros just pass an empty callconv
can be used to mock COM interfaces declared using STDMETHOD(name)
i.e. virtual HRESULT __stdcall name (...)

.idl/.tlb do not support cvref-qualified methods, so there's no need for
all the permutations of STDMETHODCALL_TYPE vs const/volatile/rvalue/etc
As these macros are expected to work with COM interfaces, we mock the
IDispatch interface as a test, this brings windows headers into the test
which unfourtunetly has to come before the trompeloeil.hpp header to
work. It also defines "interface" as a macro, but we don't need it so
we can undefine it.

We also add the same test as the other  MAKE_*_MOCKn macros to test the
15 variants.
Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rollbear
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Allow specifying calling convention attributes to Mock methods
3 participants