Question: Missing example for Struct
Closed this issue · 1 comments
BlackEdder commented
I can't work out how to mock structs. I want to use the cairoD library, and want to mock their main struct (Context), so I can add tests without actually having to draw anything.
I am able to get a MockedStruct!Context, but do not understand how to then pass it to the next function. Resulting in the following error: Error: function plotd.drawing.funcToTest (Context cnt) is not callable using argument types (MockedStruct!(Context))
void funcToTest(cairo.Context cnt)
{
cnt.fill();
}
unittest
{
import dmocks.mocks;
auto mocker = new Mocker();
auto axes_surface = new cairo.ImageSurface(
cairo.Format.CAIRO_FORMAT_ARGB32, 400, 400);
//auto axes_context = cairo.Context( axes_surface );
auto mock = mocker.mockStruct!(cairo.Context, cairo.ImageSurface )(
axes_surface );
mocker.expect(mock.fill()).repeat( 1 );
mocker.replay;
funcToTest(mock);
mocker.verify;
}
BlackEdder commented
I posted to early. Found out that I need to create template functions in your README.
Closing, sorry for the noise!