Giter Club home page Giter Club logo

emock's People

Contributors

godsme avatar orca-zhang avatar slllovehaski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emock's Issues

连续mock两个不同的类内普通方法,发现走的同一个will()

class BaseFoo {
public: 
    int GetValue() {return 10;}
    int GetValue2() {return 20;}
};

TEST(emockTest, test0)
{
    FooA fooA;
    BaseFoo baseFoo;
    EMOCK(&BaseFoo::GetValue2).stubs().will(returnValue(2));
    EMOCK(&BaseFoo::GetValue).stubs().will(returnValue(1));
    std::cout<<"=== emockTest: "<<baseFoo.GetValue2()<<" "<<baseFoo.GetValue()<<std::endl;
}

你好,我像上边这样写打印得到的是=== emockTest: 1 1
我的编译环境是Visual Studio 15 2017
使用的是c++ 11 的标准set(CMAKE_CXX_STANDARD 11)
我单步调试看了一下,调用函数时,

// \\include\\emock\\\HookMockObject.h
    template <typename RT>
    ChainableMockMethod<RT> invoke(const void* api) 
    {
      return ChainableMockMethod<RT>(getInvokable(api)); 
    }

这里的api每次都是同一个,都是最后用EMOCK设置的函数的地址。

单步调试时中间有几步提示加载的模块中为找到当前堆栈
然后就到EMOCK_API_HOOK_FUNCTOR_DEF(1);
后边就。。没太看懂,,我是希望找到invoke里的api是在哪传入的,为什么两次都传入相同的。
希望大佬帮忙看看,thanks。

MacOS 段错误

有没有更详细的文档,include哪些文件,怎么编译单元测试,怎么使用?源码工程中单元测试cmake编译不过,我自己编译了个静态库移植到自己的工程中

#include "emock/emock.hpp"

// 待测成员函数
class Foo
{
public:
    void bar1(int) {
        printf("aaaa\n");
    }
//    virtual void bar2(double);
//    static int bar3();
};

////////////////////////////////////

// 指定调用的mock函数
void EMOCK_API mock_bar1(Foo* obj, int) {
    // ...
}
void EMOCK_API mock_bar2(Foo* obj, double) {
    // ...
}

int main(int argc, char **argv) {
    EMOCK(&Foo::bar1)
            .stubs()
            .will(invoke(mock_bar1)); // 指定调用自定义的函数而不是指定返回值
}
_platform_memmove$VARIANT$Haswell 0x00007fff691539c2
[Inlined] emock::JmpOnlyApiHookImpl::saveOriginalData() JmpOnlyApiHook.cpp:56
[Inlined] emock::JmpOnlyApiHookImpl::startHook() JmpOnlyApiHook.cpp:62
[Inlined] emock::JmpOnlyApiHookImpl::JmpOnlyApiHookImpl(const void *, const void *) JmpOnlyApiHook.cpp:43
[Inlined] emock::JmpOnlyApiHookImpl::JmpOnlyApiHookImpl(const void *, const void *) JmpOnlyApiHook.cpp:42
emock::JmpOnlyApiHook::JmpOnlyApiHook(const void *, const void *) JmpOnlyApiHook.cpp:89
[Inlined] emock::ApiHookImpl::ApiHookImpl(const void *, const void *) ApiHook.cpp:36
[Inlined] emock::ApiHookImpl::ApiHookImpl(const void *, const void *) ApiHook.cpp:37
[Inlined] emock::ApiHook::ApiHook(const void *, const void *) ApiHook.cpp:48
emock::ApiHook::ApiHook(const void *, const void *) ApiHook.cpp:49
[Inlined] emock::ApiHookKey::ApiHookKey(const void *, emock::ApiHookHolder *, bool) ApiHookKey.cpp:36
emock::ApiHookKey::ApiHookKey(const void *, emock::ApiHookHolder *, bool) ApiHookKey.cpp:35
emock::HookMockObjectImpl::addMethod(const std::string &, const void *, emock::ApiHookHolder *, emock::InvocationMockerNamespace *, bool) HookMockObject.cpp:88
emock::HookMockObjectImpl::getMethod(const std::string &, const void *, emock::ApiHookHolder *, emock::InvocationMockerNamespace *, bool) HookMockObject.cpp:110
emock::HookMockObject::method(const std::string &, const void *, emock::ApiHookHolder *, bool) HookMockObject.cpp:139
emock::mockAPI<…>(const std::string &, void (Foo::*)(int)) ApiHookMocker.h:137
main main.cpp:36
start 0x00007fff68f5dcc9

mock普通成员函数会出段错误

系统信息:
Linux 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

堆栈如下:
Program received signal SIGSEGV, Segmentation fault.
__memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:314
314 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.
(gdb) bt
#0 __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:314
#1 0x00005555555f9286 in memcpy (__len=, __src=, __dest=) at /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
#2 emock::JmpOnlyApiHookImpl::saveOriginalData (this=0x555555852bc0) at /usr1/home/00273119/tmp/emock-master/src/JmpOnlyApiHook.cpp:56
#3 emock::JmpOnlyApiHookImpl::startHook (this=0x555555852bc0) at /usr1/home/00273119/tmp/emock-master/src/JmpOnlyApiHook.cpp:62
#4 emock::JmpOnlyApiHookImpl::JmpOnlyApiHookImpl (stub=0x7ffff7ed100e, api=0x11e04, this=0x555555852bc0) at /usr1/home/00273119/tmp/emock-master/src/JmpOnlyApiHook.cpp:43
#5 emock::JmpOnlyApiHook::JmpOnlyApiHook (this=0x555555852ca0, api=0x11e04, stub=0x7ffff7ed100e) at /usr1/home/00273119/tmp/emock-master/src/JmpOnlyApiHook.cpp:89
#6 0x00005555555f479e in emock::ApiHookImpl::ApiHookImpl (stub=0x7ffff7ed100e, api=0x11e04, this=0x555555852ca0) at /usr1/home/00273119/tmp/emock-master/src/ApiHook.cpp:36
#7 emock::ApiHook::ApiHook (this=0x555555852cc0, api=0x11e04, stub=0x7ffff7ed100e) at /usr1/home/00273119/tmp/emock-master/src/ApiHook.cpp:48
#8 0x00005555555f423b in emock::ApiHookKey::ApiHookKey (this=0x555555852c20, api=0x11e04, holder=, isMemFun=) at /usr1/home/00273119/tmp/emock-master/src/ApiHookKey.cpp:38
#9 0x00005555555f3dd2 in emock::HookMockObjectImpl::addMethod (this=0x5555558514f0, name=..., api=0x11e04, hookHolder=0x555555852b80, ns=0x55555583ba80 emock::GlobalMockObject::instance,
isMemFun=) at /usr1/home/00273119/tmp/emock-master/src/HookMockObject.cpp:88
#10 0x00005555555f3f9e in emock::HookMockObjectImpl::getMethod (this=, name=..., api=, hookHolder=, ns=, isMemFun=)
at /usr1/home/00273119/tmp/emock-master/src/HookMockObject.cpp:110
#11 0x00005555555f3fc0 in emock::HookMockObject::method (this=, name=..., api=, hookHolder=, isMemFun=)
at /usr1/home/00273119/tmp/emock-master/src/HookMockObject.cpp:139
#12 0x000055555556aed6 in emock::InvocationMockBuilderGetter emock::mockAPI<int, ParkMaze, int, int>(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int (ParkMaze::*)(int, int)) ()

Cannot build in windows

While generating makefile this error occurs in windows. I guess sys/mman.h is not available for windows. Then how can I run emock in windows. Can anyone please tell the step by step procedure to get emock running? It would be helpful.

emock-master\emock-master\src\SymbolRetriever.cpp:33:18: fatal error: sys/mman.h: No such file or directory
33 | #include <sys/mman.h>

你好,请问mock普通成员函数为什么会崩溃?

1、我mock动态链接库dll中的普通函数总是会报异常。
emock语句可以正常执行。调用mock后的函数时报如下异常:
发生异常:W32/0xC0000005
Unhandled exception at 0x00007FF9B14677BB in XXX.exe: 0xC0000005: Access violation executing location 0x00007FF9B14677BB.
2、mock虚函数虽然没有异常,但是mock没有生效,还是走的mock前的函数流程。
请问这是什么原因呢?
感谢回复!

文档

有详细的使用配置文档和使用文档吗?另外简单看了一下代码结构,里面的python 脚本有何用处呀?

VS2019 MSVC x64场景下mock类的普通成员函数时会奔溃,不能成功,详情分析见描述

分析过程如下:
HookMockObject::method函数中api的地址为0x00007ff797a93680
JmpOnlyApiHookImpl结构体初始化时api地址为0x00007ff797a93680,stub地址为0x0000021cf1320000
进入JmpCodeImpl结构体初始化时,from地址0x00007ff797a93680, to地址为0x0000021cf1320000
使用(unsigned long)to - (unsigned long)from公式计算后的结果为FFFF 8225 5988 C980。这个数值明显大于unsigned int能存放的大小。
因此m_code中存放的计算数值已经不对了。

然后我又参考mockcpp的源代码,在JmpCodeImpl的构造函数中,修改为
#if BUILD_FOR_X64
::memcpy(m_code, jmpCodeTemplateLong, sizeof(jmpCodeTemplateLong));
set_jmp_code_long(m_code, from, to);
#elif BUILD_FOR_X86
::memcpy(m_code, jmpCodeTemplate, sizeof(jmpCodeTemplate));
set_jmp_code(m_code, from, to);
#endif
其中
const unsigned char jmpCodeTemplateLong[] =
{ 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

inline void set_jmp_code_long(unsigned char base[], const void* from, const void* to)
{
(uintptr_t)(base + 6) = (uintptr_t)to;
}
这样处理后mock类的普通成员函数可以成功,但是类实例的成员变量地址被修改到了,导致类析构时奔溃。

mock的思路没有看懂,所以代码修改不动,还请指导一下。

defined but not used [-Wunused-function]

1.问题现象
编译时出现如下报错:
emock/types/ValueHolder.h:54:13: warning: ‘emock::Constraint* emock::{anonymous}::constraint(const emock::Constraint*)’ defined but not used [-Wunused-function]
Constraint* constraint(const Constraint* c)
2.问题分析
在C程序中,如果定义了一个静态函数或变量,而没有去使用,编译时会有一个警告:
'at_wait_send_finish' defined but not used [-Wunused-function],
当前报错是由于函数定义在 .h 头文件中,但是没有使用。
3.解决办法
把函数定义在 .cpp 源文件中
4.参考信息:
https://stackoverflow.com/questions/2845748/function-defined-but-not-used-warning-in-c
https://blog.csdn.net/hanhui22/article/details/108869744

如何把EMOCK之后的函数设置为不被MOCK的状态

我想在多个TEST中 mock同一个函数,但是mock的返回值结果是不一样的,例如如下代码,TEST-01设置fun返回值为1,TEST-02设置fun返回值为2. 我的运行结果是TEST-01是成功的,但是TEST-02是失败的。怎么样才能是TEST-02也成功吗?


int fun()
{
  return 0;
}

// Success
TEST(Demo, 01)
{
  EMOCK(fun)
    .expects(atLeast(1))
    .will(returnValue(1));

  EXPECT_EQ(1, fun());

}

// Fail, because 'fun' return value is 1. 
TEST(Demo, 02)
{
  EMOCK(fun)
    .expects(atLeast(1))
    .will(returnValue(2));
  
  EXPECT_EQ(2, fun());
}

编译报错,多次定义,编译-用的std=c++11

:在函数‘emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*)’中:
reg_son_log.cpp:(.text+0x4d): emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*) 的多重定义
CMakeFiles/main.dir/main.cpp.o:main.cpp:(.text+0x4d):第一次在此定义
src/libMysrc.a(grammar.cpp.o):在函数‘emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*)’中:
grammar.cpp:(.text+0xf1): emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*) 的多重定义
CMakeFiles/main.dir/main.cpp.o:main.cpp:(.text+0x4d):第一次在此定义
src/libMysrc.a(stonewt.cpp.o):在函数‘emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*)’中:
stonewt.cpp:(.text+0x4d): emock::InvocationMockBuilderGetter emock::mockAPI(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, char const*) 的多重定义
CMakeFiles/main.dir/main.cpp.o:main.cpp:(.text+0x4d):第一次在此定义

gtest下mock类成员函数运行时coredump

#include<gtest/gtest.h>

#include <emock/emock.hpp>

class Foo
{
public:
	int test(double)
	{
		return 1;
	}
};

TEST(test, testcase)
{
	EMOCK(
		&Foo::test)
		.stubs()
		.with(any())
		.will(returnValue(2));
	Foo foo;
	EXPECT_EQ(2, foo.test(4));
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

image

mingw64无法编译通过

emock-master\emock-master\src\Formatter.cpp:41:44: error: cast from 'void*' to 'long unsigned int' loses precision [-fpermissive]
oss << reinterpret_cast(p);

mac os compile error

cmake info:
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/xxx/code/emock/build

compile info:
[ 1%] Building CXX object src/CMakeFiles/emock.dir/SymbolRetriever.cpp.o
/Users/zhangchao/code/emock/src/SymbolRetriever.cpp:30:11: fatal error:
'link.h' file not found
#include <link.h>
^~~~~~~~
1 error generated.

Mock sleep, crash

I use Emock to mock sleep, it will crash at exit.

TEST_F(MockExpect, mockSleep)
{
EMOCK(sleep).stubs().will(returnValue(1));
sleep(5);

GlobalMockObject::verify();

}

call stack:
Program received signal SIGSEGV, Segmentation fault.
__GI__exit (status=status@entry=0) at ../sysdeps/unix/sysv/linux/_exit.c:27
27 ../sysdeps/unix/sysv/linux/_exit.c: No such file or directory.
(gdb) where
#0 __GI__exit (status=status@entry=0) at ../sysdeps/unix/sysv/linux/_exit.c:27
#1 0x00007ffff6c051c2 in __run_exit_handlers (status=0, listp=, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:132
#2 0x00007ffff6c051ea in __GI_exit (status=) at exit.c:139
#3 0x00007ffff6be3b9e in __libc_start_main (main=0x5555555609da <main(int, char**)>, argc=2, argv=0x7fffffffe498, init=, fini=, rtld_fini=, stack_end=0x7fffffffe488)
at ../csu/libc-start.c:344
#4 0x00005555555608fa in _start ()

my system: Ubuntu18, g++ 7.3

请问常函数可以mock吗?

请问常函数可以mock吗?我mock常函数总是报语法不对。另外在wiki中的使用手册是不是看不到了?多谢回复。

同一个函数在目标被测函数中多次调用(会有不同结果)该如何mock?

如何在同一个用例中mock同一个函数多次,并且期望的行为每次都不同?
例如下面的示例:

class a {
public:
    int aFunc(int i) {
        // do something, return different value
        // or read differen value from file...
    }
};

class call {
public:
    int call_aFunc(int x) {
        int ret = 0;
        if (x==y) {
            ret = x * aobj.aFunc(x);  // expect return 2
        } else if (x%y==0) {
            ret = x % aobj.aFunc(x);  // expect return 10
            rer += y*aobj.aFunc(y);   // expect return 6
        } else if (x/y) {
            rer += y/aobj.aFunc(y);   // expect return 8
        } else {
            rer += aobj.aFunc(x);   // expect return 0
        }
        return rer += aobj.aFunc(ret);   // expect return 666
    }
a aobj;
int y;
};

mockcpp中有类似的语法:
.stubs().will(returnValue(10)).then(returnValue(6)).then(returnVaule(666));

emock也支持类似的语法,但是实测then没效果,每次返回的都是will中设定的10.

系统:Linux x86_64,编译器:g++

CMakeList.txt选项需要修改

SET(MOCKCPP_XUNIT "testngpp" CACHE STRING "Set to gtest/cpputest/cppunit to use other testframeworks.")
{MOCKCPP_XUNIT} --> {EMOCK_XUNIT}

尝试对QTextStream的符号重载函数打桩失败

尝试对QTextStream的符号重载函数打桩失败
QTextStream& (*addrQTSOperator) (QTextStream*,const QString&)=(QTextStream& (*) (QTextStream*,const QString&)) ((QTextStream& (QTextStream::*)(const QString&))&QTextStream::operator<<); EMOCK(addrQTSOperator) .stubs() .will(invoke(mock_QTSOperator));
QTextStream& EMOCK_API mock_QTSOperator(QTextStream* obj,const QString& s) { auto fileName=((QFile*)(obj->device()))->fileName(); qDebug()<<fileName; qDebug()<<s; return *obj; }
报错如下:
/home/ken/tstPluginSaveRuntime/lemock/include/emock/IsEqual.h:42: error: use of deleted function ‘QTextStream::QTextStream(const QTextStream&)’ lemock/include/emock/IsEqual.h:45:25: required from ‘bool emock::IsEqual<T>::eval(const emock::RefAny&) const [with T = QTextStream]’ lemock/include/emock/IsEqual.h:42:10: required from here lemock/include/emock/types/AnyCast.h:155:38: error: use of deleted function ‘QTextStream::QTextStream(const QTextStream&)’ 155 | return *const_cast<nonref*>(result); | ^ /usr/include/qt/QtCore/qtextstream.h:195:20: note: declared here 195 | Q_DISABLE_COPY(QTextStream) | ^~~~~~~~~~~ /usr/include/qt/QtCore/qglobal.h:443:5: note: in definition of macro ‘Q_DISABLE_COPY’ 443 | Class(const Class &) = delete;\ | ^~~~~

请问下如何恢复打桩前?

发现
EMOCK(&Foo::bar1)
.stubs()
.will(returnValue(1));
后Foo::bar1就永远打桩成这样了。
我有个场景
先打桩跑一下,然后再恢复没打桩之前的状态继续跑。不知道如何操作。多谢

wsl ubuntu环境下mock 类成员函数 出现段错误

Program received signal SIGSEGV, Segmentation fault.
__memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:312
312 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.
(gdb) bt
#0 __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:312
#1 0x000000000812ffae in emock::JmpOnlyApiHook::JmpOnlyApiHook(void const*, void const*, void const*) ()
#2 0x000000000812c5b6 in emock::ApiHook::ApiHook(void const*, void const*, void const*) ()
#3 0x000000000812c287 in emock::ApiHookKey::ApiHookKey(void const*, emock::ApiHookHolder*, bool) ()
#4 0x000000000812be27 in emock::HookMockObjectImpl::addMethod(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const*, emock::ApiHookHolder*, emock::InvocationMockerNamespace*, bool) ()
#5 0x000000000812c005 in emock::HookMockObject::method(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const*, emock::ApiHookHolder*, bool) ()
#6 0x00000000080aaa81 in emock::InvocationMockBuilderGetter emock::mockAPI<void, Foo, int>(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void (Foo::)(int)) ()
#7 0x00000000080a95f6 in member_func_ut_member_func_Test::TestBody() ()
#8 0x00000000080f85b6 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test
, void (testing::Test::)(), char const) ()
#9 0x00000000080f0349 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::)(), char const) ()
#10 0x00000000080ca286 in testing::Test::Run() ()
#11 0x00000000080cad55 in testing::TestInfo::Run() ()
#12 0x00000000080cb72b in testing::TestSuite::Run() ()
#13 0x00000000080db6b6 in testing::internal::UnitTestImpl::RunAllTests() ()
#14 0x00000000080f9beb in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::)(), char const) ()
#15 0x00000000080f1657 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::)(), char const) ()
#16 0x00000000080d9cb0 in testing::UnitTest::Run() ()
#17 0x00000000080a9e70 in RUN_ALL_TESTS() ()
#18 0x00000000080a9754 in main ()
(gdb)

经常不知原因的段错误

_ZN5emock16getDemangledNameEPKc+0x1f)[0xa4b7df]
emock/src/SymbolRetriever.cpp:439(_findAddr<Elf64_Ehdr, Elf64_Shdr, Elf64_Sym>)[0xa4973f]
emock/src/SymbolRetriever.cpp:477(_ZN5emock14symbolRetrieveEPNS_12_GLOBAL__N_114ISymbolCheckorE.constprop.94)[0xa4a332]

虚函数打桩失败

EMOCK((bool (QFile::*)(QFile::OpenMode))&QFile::open)
.stubs()
.will(returnValue(true));

terminate called after throwing an instance of 'emock::Exception'
what(): Failed to get address of [(bool (QFile::*)(QFile::OpenMode))&QFile::open], maybe inlined or haven't been overridden in derived class.

请问能否mock protected属性的方法?

你好,请教一下,emock是否可以mock 类protected属性函数的方法呢?
我用一个测试类TestClass继承类BaseFoo,然后在TestClass里边是可以访问到BaseFoo的protected方法,
但由于无法对protected的方法取地址所以无法使用EMOCK。
如果有方法取得protected属性的成员函数地址,应该可以解决我的问题。大佬有没有什么建议?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.