stub 可以与 mock并用,用来取代mock的接口函数.
1.
TEST(Logcreate, init)
{
UT_PTR_SET(log_type_a->init, stub_init);
UT_PTR_SET(log_type_b->init, stub_init);
UT_PTR_SET(log_type_c->init, stub_init);
UT_PTR_SET(log_type_d->init, stub_init);
mock().ignoreOtherCalls();
LONGS_EQUAL(SUCCESS_EC, log_create_init_r());
}
in log_create_init_r, it invokes log_type_a->init, log_type_b->init...
tst/ut/stub_tst.cpp
static bool stub_init()
{
return 0;
}
2. only using stub.
TEST(EditToolTest, copytest)
{
UT_PTR_SET(etool->copy_line_str, stub_etool_copy_line_str);
CHECK(SUCCESS_EC == edittool_cp_str());
}
in edittool_cp_str, it invokes, etool->copy_line_str(xx,yy).
tst/ut/stub_tst2.cpp
static int stub_etool_copy_line_str(const char *path, int type)
{
return 0;
}