c++ - Gmock - matching structures -


how can match value of element in union input argument e.g - if mock method following signatiure -

    struct somestruct     {            int data1;         int data2;      };      void somemethod(somestruct data); 

how can match mock method called correct value in argument?

after reading through google mock documentation in detail, solved problem documented in defining matchers section. (an example have been great!)

so solution use matcher_p macros define custom matcher. matching somestruct.data1 defined matcher:

matcher_p(data1areequal, ,"") { return (arg.data1 == somestructtocompare.data1); } 

to match in expectation used custom macro this:

expect_call(somemock, somemethod(data1areequal(expectedsomestruct))); 

here, expectedsomestruct value of structure.data1 expecting.

note that, suggested in other answers (in post , others), requires unit under test change make testable. should not necessary! e.g. overloading.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -