Mocking Windows APP SDK classes using C++/winrt

43 views Asked by At

I face a problem how to create SolidColorBrush inside test suites. When I do it using the constructor, I get winrt::hresult_wrong_thread, which seems reasonable because when I run the tests, there is no corresponding thread.

constexpr winrt::Windows::UI::Color color(100, 101, 102, 103);
const auto brush = SolidColorBrush(color); 

I tried to propose a solution on how to mock this class using gmock, but unfortunately I did not find any working solution. I tried with inheritance from winrt::Microsoft::UI::Xaml::Media::BrushT (there is also a problem with winrt::hresult_wrong_thread) and tried winrt::implements but I get:

error C2079: "winrt::impl::producer<D,winrt::impl::default_interfacewinrt::Microsoft::UI::Xaml::Media::SolidColorBrush,void::type,void>::vtable" use undefined struct "winrt::impl::produce<D,I>"

I'm not sure exactly how to use this mechanism. This was my code:

struct SolidColorBrushMock : winrt::implements<SolidColorBrushMock, SolidColorBrush>
{
  // MOCK_METHOD(Windows::UI::Color, Color, (), (noexcept));
  // ...
};

How to create a mock of SolidColorBrush and others UI elements?

Thanks in advance, MichaƂ

0

There are 0 answers