gmock


Capture GMOCK string parameter


If I have the following interface member function:
virtual bool print_string(const char* data) = 0;
with the following mock
MOCK_METHOD1(print_string, bool(const char * data));
Is it possible to capture the string that is passed to print_string()?
I tried to:
char out_string[20]; //
SaveArg<0>(out_string); // this saves the first char of the sting
this saves the first char of the sting but not the whole string.
Class
struct Foo {
virtual bool print_string(const char* data) = 0;
};
Mock
struct FooMock {
MOCK_METHOD1(print_string, bool(const char * data));
};
Test
struct StrArg {
bool print_string(const char* data) {
arg = data;
return true;
}
string arg;
};
TEST(FooTest, first) {
FooMock f;
StrArg out_string;
EXPECT_CALL(f, print_string(_))
.WillOnce(Invoke(&out_string, &StrArg::print_string));
f.print_string("foo");
EXPECT_EQ(string("foo"), out_string.arg);
}
You can always use Invoke to capture parameter value in structure.
May be something like:
char* p = out_string[0];
SaveArg<0>(&p);
since SaveArg(pointer) save the Nth argument to *pointer.
I think if you just need to validate the content of the array without deep copy, there is no need to create another array since only the pointer to the array could be obtained using this method.

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
css3
components
camera
sh
sitecore
graphics
maxscript
zip
tvos
gluon-mobile
vert.x
character
performancepoint
extjs4.2
spin
fosrestbundle
radgridview
onedrive-api
gource
scrolltop
cumulocity
bitnami
jmp
sse
solrcloud
ag
php-mysqlidb
maze
jackson-modules
entity-relationship-model
firebase-analytics
genexus-sd
winexe
datastax-enterprise-graph
constexpr
recurring-events
mailkit
gojs
parse-tree
sql-server-ce
watchman
zoomify
google-earth-engine
android-augmented-reality
setup.py
apache-stanbol
preloader
movilizer
logback-groovy
ssrs-2014
xmldocument
wc
memory-mapping
xbmc
linter
openrasta
wcftestclient
chai-as-promised
pair-programming
ngmaterial
ampps
pocketsphinx-android
stax
dotnetnuke-7
nikeplus-api
android-dateutils
observablecollection
turbo-prolog
exim4
jbase
google-books
bufferedinputstream
fits
actionfilterattribute
phpldapadmin
mruby
iso-prolog
webfinger
machine-instruction
personalization
file-not-found
maven-scm
square-bracket
scmmanager
sqlclr
mkv
zope.interface
wcf-configuration
iboutlet
ilasm
jsr286
cross-database
entitydatasource
spread
business-model

Resources

Encrypt Message