c++ - Can Hippomocks set expectations for the same MockRepository in different source files? -


i have multiple tests in multiple files able call separately-compiled utility method file sets same expectations each test. however, hippomocks seems have problem setting expectations same mockrepository in different source files.

here's simple example:

file1.cpp is:

void setotherexpectations(mockrepository &mocks);  int method45() {     return -45;  } int method88() {     return -88; }  test(testofsettingvalueinanothersourcefile) {     mockrepository mocks;     mocks.oncallfunc(method45).return(45);     mocks.oncallfunc(method88).return(88);     setotherexpectations(mocks);     testequal(45, method45()); // failed condition: (expected: <45>, actual: <8888> } 

file2.cpp is:

int methodint(int) {     return -145; } int methodchar(char) {     return -188; }  void setotherexpectations(testframework::mockrepository &mocks) {     mocks.oncallfunc(methodchar).return(8888); // line     mocks.oncallfunc(methodint).return(9999); // line b } 

if swap line , b, method45 call returns 9999. turns out when method45 call made, search matching expectation finds first mocked function in file2 before finds correct mocked function file1.

there 4 mocked methods in mockrepository, hippomocks assigns funcindex value on per-source-file basis, since uses __counter__ preprocessor variable (which starts @ 0 in each source file , incremented 1 every time used in source file) in calls registerexpect. therefore each subsequent expectation setting in separate source file “hides” previous expectations set index.

it seems need include inline code utility functions set expectations each separately-compiled source file, not great solution. there other way this?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -