C++ GMock

add it to cmake

target_link_libraries (target_name gtest_main gmock_main gtest )

Matchers

MATCHER_P(M1,p,""){
return p>10;
}

TEST(TESTS,t1){
    testing::Matcher<int> m1(12);
    EXPECT_THAT(12,m1);
    EXPECT_THAT(true,M1(12));
    EXPECT_TRUE(m1.Matches(12));
    EXPECT_THAT(12,testing::AllOf(testing::Gt(0),testing::Lt(100)));
}

expect call

class A{
public:
    virtual void fun()const=0;
    virtual void fun2(int l)const=0;
};
class MockA:public A{
public:
    MOCK_METHOD(void,fun,(),(const override));
    MOCK_METHOD(void,fun2,(int),(const override));
};

using ::testing::AtLeast;                         // #1

TEST(PainterTest, CanDrawSomething) {
    MockA turtle;
    EXPECT_CALL(turtle, fun2(22))                  // #3
            .Times(2);//expect call this function twice with argument 22
    turtle.fun2(22);// #2//first call
    turtle.fun2(22);// #2// second call 
    // test passed because this function called twice
}