I am trying to test two serial write + read calls ports. The first should block on read for 101 ms and thus cause a timeout error. The second should work fine. Based on the Google mock guide , the InSequence variable should provide this. Here is the code:
{
TimeoutRead is just a function that makes the current thread sleep for 101 ms. However, I keep getting this runtime error:
[ RUN ] MasterTest.LostReply /host/Users/blah/work/bitbucket/master_test.cc:631: Failure Mock function called more times than expected - returning default value. Function call: Read(0x5652c3f31120 pointing to "\xFF\xFF", 4096, 0x7ffda19d2960) Returns: false Expected: to be called once Actual: called twice - over-saturated and active
GTest seems to be trying to call the last EXPECT_CALL intended for the second read .
Is there a way to force this call sequence?
[THIS IS A TEMPORARY PICTURE OF THIS PROCESS TO BE PROVIDED ANSWERED]
This is SSCCE. I expect you to tune in correctly to get the error you mention in your question. The code below works and passes:
class Serial_ { public: MOCK_METHOD2(Write, void(int* elems, size_t n)); MOCK_METHOD3(Read, bool(int* elems, int dummy, size_t* n)); }; int command1_[] = {1,2,3}; int command2_[] = {4,5}; std::array<int, 4> response_{{ 6, 7, 8, 9 }}; void testScenario(Serial_& serial_) { int dummy_arr[100]; size_t dummy_size; serial_.Write(command1_, 3); serial_.Read(dummy_arr, 123, &dummy_size); serial_.Write(command2_, 2); serial_.Read(dummy_arr, 123, &dummy_size); } bool TimeoutRead(int* elems, int dummy, size_t* n) { return true; } void Write(int* elems, size_t n) {} TEST(A,A) { Serial_ serial_;
c ++ googletest googlemock gmock
ilya1725
source share