gmock


Mocking non-virtual method generating errors


I'm trying to get the hang of Google Mocks but I've hit a snag trying to mock non-virtual methods. I have a Socket class that I want to mock. It has a non-virtual method called "write" that takes to arguments:
class Socket {
public:
int write(const unsigned char* buffer, size_t bufferLength) const;
}
So I create a Mock class as specified cook book:
class MockSocket {
public:
MOCK_CONST_METHOD0(write, int(const unsigned char* data, size_t dataLength));
};
But this doesn't compile. It generates the following errors:
error: size of array ‘this_method_does_not_take_0_arguments’ is negative
error: no matching function for call to ‘testing::internal::FunctionMocker<int ()(const unsigned char*, size_t)>::Invoke()’
error: no matching function for call to ‘testing::internal::FunctionMocker<int ()(const unsigned char*, size_t)>::With()’
Could someone tell me why??
Thanks.
Okay, didn't mix my coffee strong enough this morning. Figured out the problem. Was using the wrong macro. This works:
class MockSocket {
public:
MOCK_CONST_METHOD2(foo, int(const unsigned char* buffer, size_t len));
};

Related Links

gmock ReturnRef returns compilation error
How to call function pointer which is passed to Mock method?
In gmock, Is there a way to have mock object return an instance of an user defined object?
GMock testing destructor calls
set EXPECT_CALL to redirect the call to the original method
Capture GMOCK string parameter
Mocking non-virtual method generating errors
gmock matcher doesn't match my arguments by reference
What did you do to solve gmock you mentioned (link enclosed)?
how to set custom ref-variable in gmock

Categories

HOME
eclipse
assembly
cobalt
spark-streaming
ecmascript-6
serialization
spring-data-redis
owl-carousel
vscode-extensions
ms-access-2016
javacc
permissions
dojo
pyqt4
bookmarks
jax-ws
syntaxnet
categorical-data
enthought
php-5.6
libc
stellar.js
symmetricds
enterprise-architect
symbol
keytool
modbus-tcp
atlassian-stash
dimensional-modeling
vuejs
apache2.4
undertow
springfox
react-toolbox
easeljs
flask-sqlalchemy
direct3d11
jasmine-node
progress-bar
sqlpackage
eviews
autolisp
pdw-file-browser
sharepoint-workflow
apic
xdocreport
ods
recurrent-neural-network
signals-slots
postgresql-8.4
glm-math
placeholder
plan-9
dynamic-linq
hammer.js
facebook-pixel
insight
carrot2
azure-cli
context-sensitive-grammar
android-testing
swingworker
renaming
testrail
gets
custom-lists
adafruit
signalr.client
cifilter
mediametadataretriever
ascii-art
dllimport
video-player
rubaxa-sortable
sony-lifelog-api
batik
omnifaces
bufferedinputstream
qtwebengine
dbaccess
packet-sniffers
device-tree
matrix-inverse
dot42
conditionaltagsupport
nevron
curb
tree-balancing
saxparseexception
drawtobitmap
socketserver
aspmenu
openfaces
interop-domino
xpsdocument
image-capture

Resources

Encrypt Message