Hi,
I am new to google mock so sorry if you think this is an easy question.
I am currently testing codes for a project.
There are async calls and i am having a hard time checking the sequence of function calls.
I cannot share the codes so I'll just give sample sequence based on logs.
- service::start
- manager::start
- manager::apples //first thread
- manager::egg //second thread
- service::doSomething
- apples::start //async
- apples::create_apples //async
- eggs::start //async
- eggs::create_eggs //async
- service::doAnother
- eggs::pack_eggs //async
- apples::pack_apples //async
I checked google mock CheatSheet: https://code.google.com/p/googlemock/wiki/CheatSheet#Sequences
But i can't get it to work as I wanted to.
sequence_check_mock obj;
mock_obj_ = &obj;
{
Sequence s1, s2;
EXPECT_CALL( *mock_obj_, service_start() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, manager_start() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, manager_apples() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, manager_eggs() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, service_doSomething() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, apples_start() ).InSequence( s1 );
EXPECT_CALL( *mock_obj_, apples_create_apples() ).InSequence( s1 );
EXPECT_CALL( *mock_obj_, eggs_start() ).InSequence( s2 );
EXPECT_CALL( *mock_obj_, eggs_create_eggs() ).InSequence( s2 );
EXPECT_CALL( *mock_obj_, service_doAnother() ).InSequence( s1, s2 );
EXPECT_CALL( *mock_obj_, eggs_pack_eggs() ).InSequence( s2 );
EXPECT_CALL( *mock_obj_, apples_pack_apples() ).InSequence( s1 );
}
The checking is ok until service_doAnother. But sometimes, service_doAnother is called after eggs_pack_eggs or apples_pack_apples
so the test would fail. Since in the sequence, it is expected that doAnother should be called before.
- eggs::pack_eggs //async
- apples::pack_apples //async
- service::doAnother
Thanks in advance.