Verifying Fields in Nested Structs

1,139 views
Skip to first unread message

Den S

unread,
May 27, 2011, 8:52:57 AM5/27/11
to Google C++ Mocking Framework

Hi, I am trying to verify a field of a struct that is nested inside
another struct?

For example:

struct s1 {
int x;
};

struct s2 {
int y;
s1 s;
};

...

void do( s2 z );

...

EXPECT_CALL( obj, do ( Field( & s2::y, Eq (5 ) ) ) ); // syntax
that works for non-nested struct member

What would the syntax be to check field x of the s1 struct inside of
the s2 struct?

Thanks.

-Den

Vlad Losev

unread,
May 27, 2011, 11:53:24 PM5/27/11
to Den S, Google C++ Mocking Framework
Hi Den,

Nesting matchers should work:

EXPECT_CALL(obj, do(Field(&s2::s, Field(&s1::x, Eq(10))));
 

Thanks.

-Den


HTH,
Vlad

ErikS

unread,
Oct 4, 2011, 11:42:59 AM10/4/11
to googl...@googlegroups.com, Den S
I'm trying to do the same thing but I get an 
"a nonstatic member reference must be relative to a specific object" compiler error. It appears the error is on the &s1::x resolution.

My "do" method does not take a reference to a struct, however. Instead it takes a pointer to a struct. 

Thanks in advance for any help.

Erik

ErikS

unread,
Oct 4, 2011, 12:39:35 PM10/4/11
to Google C++ Mocking Framework
Solved it myself with a small change to my code... my issue was
related to the use of a typedef on the nested union.
Reply all
Reply to author
Forward
0 new messages