gzc9047 / cppfreemock Goto Github PK
View Code? Open in Web Editor NEWBased on gmock, can mock global function, member function, class static function without changing source code.
License: Apache License 2.0
Based on gmock, can mock global function, member function, class static function without changing source code.
License: Apache License 2.0
This implement code migrate from the prototype, it don't have UT, so we need it.
cpp11/impl.h:77:34: error: cannot bind non-const lvalue reference of type ‘testing::internal::MockSpec<std::__cxx11::basic_string()>&’ to an rvalue of type ‘testing::internal::MockSpec<std::__cxx11::basic_string()>’
return gmocker.With(p ...);
how to solve overloaded function
When mocker function of abort return, program don't run the code just after it, it's run unexpected.
If add "return 0;" after https://github.com/gzc9047/CppFreeMock/blob/master/runtime_patch.h#L46 it don't run.
So find the root cause and fix it.
Till now, all the case are for inline function in the source code(except mprotect). Should use some real function.
Hello,
I am trying to run the example present in "https://github.com/gzc9047/CppFreeMock/tree/master/example".
I am using google test release version - googletest-release-1.8.1
Steps performed:
1.)Download the "CppFreeMock" repository and placed it on my SUT
2.)Navigated to Examples folder and modified the Makefile to update paths to my libraries and include files as follows:
TMPDIR=..
PROJECT_ROOT=..
GMOCK_LIB = -L/opt/gtest/lib
GMOCK_INCLUDE = -I/opt/gtest/include -I/usr/include/gtest/ -I/usr/include/gmock/ -I$(PROJECT_ROOT)
3.)Executed make as below:
[root@SUT example]# make all
g++ -g -O0 -std=c++11 -fno-inline -falign-functions=32 test_member_function.cpp -I/opt/gtest/include -I/usr/include/gtest/ -I/usr/include/gmock/ -I.. -L/opt/gtest/lib -o ../test_member_function.out
In file included from ../impl.h:12:0,
from ../internal_macro.h:11,
from ../cpp_free_mock.h:12,
from test_member_function.cpp:16:
../cpp11/impl.h: In instantiation of ‘testing::internal::MockSpec<R(P ...)>& CppFreeMock::MockerBase<R(P ...)>::gmock_CppFreeMockStubFunction(const testing::Matcher<P>& ...) [with R = std::basic_string<char>; P = {const void*}]’:
test_member_function.cpp:102:5: required from here
../cpp11/impl.h:77:34: error: invalid initialization of non-const reference of type ‘testing::internal::MockSpec<std::basic_string<char>(const void*)>&’ from an rvalue of type ‘testing::internal::MockSpec<std::basic_string<char>(const void*)>’
return gmocker.With(p ...);
^
../cpp11/impl.h: In instantiation of ‘testing::internal::MockSpec<R(P ...)>& CppFreeMock::MockerBase<R(P ...)>::gmock_CppFreeMockStubFunction(const testing::Matcher<P>& ...) [with R = std::basic_string<char>; P = {const void*, bool, char, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’:
test_member_function.cpp:114:5: required from here
../cpp11/impl.h:77:34: error: invalid initialization of non-const reference of type ‘testing::internal::MockSpec<std::basic_string<char>(const void*, bool, char, int, std::basic_string<char>, const std::basic_string<char>&)>&’ from an rvalue of type ‘testing::internal::MockSpec<std::basic_string<char>(const void*, bool, char, int, std::basic_string<char>, const std::basic_string<char>&)>’
../cpp11/impl.h: In instantiation of ‘testing::internal::MockSpec<R(P ...)>& CppFreeMock::MockerBase<R(P ...)>::gmock_CppFreeMockStubFunction(const testing::Matcher<P>& ...) [with R = int; P = {const void*, bool&, char&, int&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&}]’:
test_member_function.cpp:136:5: required from here
../cpp11/impl.h:77:34: error: invalid initialization of non-const reference of type ‘testing::internal::MockSpec<int(const void*, bool&, char&, int&, std::basic_string<char>&, const std::basic_string<char>&)>&’ from an rvalue of type ‘testing::internal::MockSpec<int(const void*, bool&, char&, int&, std::basic_string<char>&, const std::basic_string<char>&)>’
make: *** [test_member_function] Error 1
Not sure what I am missing..
Any guidance on same will be helpful..
As the title, I meet this problem when I try to mock API mprotect. So do it.
I am adding gtests for our codes and found your way that may be used. But you said you had tested it only on mac. Is there one version to support windows? We are now using VS2015 update3.
Thanks.
Till now this tool don't support non-posix and non-c++11, so if try to build on them will need compiler error, so just make the error message be helpful.
I'm trying to implement #15 , there is a way to create anonymous mocker. But multi mocker creation will return different mocker, this is not we want, so we need this issue.
Such as:
MOCK(func); // instead of CREATE_MOCKER(mocker, func);
EXPECT_CALL(MOCKER(func), MOCKER_FUNCTION(...)).Times(...);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.