cpp-stub icon indicating copy to clipboard operation
cpp-stub copied to clipboard

是否支持 stub 命名空间函数?

Open yiyiarrow opened this issue 1 year ago • 6 comments

example: namespace A { namespace B { namespace C { int func(int a, std::string b) { xxxx; return 0; } } } }

int stub_func(int a, std::string b) { return 1; }

我试了以下几种方式都不行: Stub stub; stub.set(func, stub_func); stub.set(A::B::C::func, stub_func); stub.set(ADDR(A::B::C, func), stub_func);

yiyiarrow avatar Jul 27 '24 09:07 yiyiarrow

stub.set(&A::B::C::func, stub_func);

coolxv avatar Jul 27 '24 11:07 coolxv

stub.set(&A::B::C::func, stub_func);

这样 stub,我单独写的 demo 代码可以的。但是在我的工程里就不行,比较奇怪。

yiyiarrow avatar Jul 27 '24 13:07 yiyiarrow

你工程里的函数是不是特殊函数,例如虚函数

coolxv avatar Jul 28 '24 03:07 coolxv

你工程里的函数是不是特殊函数,例如虚函数

不是虚函数。就是开源代码库 ceph 的 src/cls/clock/cls_lock_client.cc 里面的 get_lock_info 函数。不知道是不是 ceph 工程的问题,使用 cpp_free_mock 也没办法 mock 这个命名空间函数。(但是其它源文件的类成员函数是可以 mock 的)。 我在工程里面的测试文件简单写了一个全局函数测试,发现也 stub 不了。

yiyiarrow avatar Jul 29 '24 00:07 yiyiarrow

nm ceph | c++filter | grep get_lock_info

coolxv avatar Jul 29 '24 13:07 coolxv

nm ceph | c++filter | grep get_lock_info

编译是没问题的。能调用到 get_lock_info,但是没进 stub_get_lock_info

yiyiarrow avatar Jul 30 '24 00:07 yiyiarrow