template <typename R, typename... Ts>

class MockFunction

Defined at line 61 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

This class mocks a single function. The Expect*() functions are used by the test to set

expectations, and Call() is used by the code under test. There are three variants:

* ExpectCall(return_value, arg1, arg2, ...) sets the expectation that the call will be made with

arguments `arg1`, `arg2`, etc., each compared using operator==. `return_value` will be returned

unconditionally, or is omitted if the function returns void.

* ExpectCallWithMatcher(matcher) uses a `matcher` validate the arguments. The matcher will be

called with the arguments to the mocked function call, and the call will return the matcher's

return value.

* ExpectNoCall() expects that the function will not be called.

Example:

class SomeClassTest : SomeClass {

public:

zx_status_t CallsSomeMethod();

mock_function::MockFunction

<zx

_status_t, uint32_t, uint32_t>

&

mock_SomeMethod() {

return mock_some_method_;

}

private:

zx_status_t SomeMethod(uint32_t a, uint32_t b) override {

return mock_some_method_.Call(a, b);

}

mock_function::MockFunction

<zx

_status_t, uint32_t, uint32_t> mock_some_method_;

};

TEST(SomeDriver, SomeTest) {

SomeClassTest test;

test.mock_SomeMethod().ExpectCall(ZX_OK, 100, 30);

test.mock_SomeMethod().ExpectCallWithMatcher([](uint32_t a, uint32_t b) {

EXPECT_EQ(200, a);

EXPECT_EQ(60, b);

return ZX_OK;

});

EXPECT_OK(test.CallsSomeMethod(100, 30));

EXPECT_OK(test.CallsSomeMethod(200, 60));

test.mock_SomeMethod().VerifyAndClear();

}

Public Methods

template <typename... As>
MockFunction<R, Ts...> & ExpectCall (R retval, As &&... args)

Defined at line 64 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

template <typename M>
MockFunction<R, Ts...> & ExpectCallWithMatcher (M matcher)

Defined at line 78 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

MockFunction<R, Ts...> & ExpectNoCall ()

Defined at line 84 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

R Call (Ts... args)

Defined at line 89 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

bool HasExpectations ()

Defined at line 95 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h

void VerifyAndClear ()

Defined at line 97 of file ../../zircon/system/ulib/mock-function/include/lib/mock-function/mock-function.h