gmock


In gmock, Is there a way to have mock object return an instance of an user defined object?


For UT purposes, I am trying to Mock out a function that returns a vector of user defined structs.
std::vector<myStruct> myClass::foo()
In gmock, Is there a way to do something like this:
std::vector<myStruct> TestVector;
//code to populate my vector ....
ON_CALL(MockMyClass, foo()).WillByDefault(Return(TestVector))
I couldn't find anything in the gmock cookbook, it looks like the return values are all primitives. Thanks
I ended up using ReturnPointee
https://code.google.com/p/googlemock/wiki/CookBook#Returning_Live_Values_from_Mock_Methods
std::vector * ptr;
//instantiate and populate vector...
ON_CALL(MockMyClass, foo()).WillByDefault(ReturnPointee(ptr));

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
android
ng-idle
amp-html
character-encoding
devise
can
r-googlesheets
static-site
echo
spring-session
nstableheaderview
nfs
sendgrid-api-v3
g++
vimdiff
plist
startup
tput
renjin
screen-readers
xmonad
connector
enterprise-miner
sencha-touch
asp.net-core-webapi
guzzle
postscript
inno-download-plugin
imageresizer
dynamically-generated
game-theory
genexus-sd
spotipy
python-2.6
mockjax
angularjs-material
rselenium
activexobject
carriage-return
least-squares
processwire
fiware-cygnus
searchkit
latitude-longitude
openerp-7
magento-1.9.2.4
gdata
health-monitoring
css-position
stringtokenizer
print-css
lpsolve
berkeley-db-je
procfile
nanoc
robomongo
hammer.js
lightning
semantic-logging
cup
er-diagram
java-websocket
monkey
rackspace-cloud
polyline
rocks
visual-studio-2008-sp1
flex-monkey
qtplugin
xcode-server
observablecollection
qiime
nservicebus5
database-relations
beanstalk
cycle2
design-principles
pypiserver
rate-limiting
jdk1.7
amiga
branch-and-bound
entity-framework-4.3
public-html
cross-join
execve
primitive-types
browserify-shim
sql-scripts
linkedin-jsapi
encryption-asymmetric
mobility
personalization
winginx
buffering
paste
server-administration
mysql-error-2013
joomla3.1
pyunit
xui
load-time
folding
lxr
firefox-3
ifilter
idatareader

Resources

Encrypt Message