Код: Выделить всё
TEST_F(at_operator_selection_tests, select_operators_selects_operator_with_best_signal)
{
// arrange
InSequence s;
// The next expectation will be referred to as exp#1
EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).WillOnce(Return(true));
// Some other expectations left out intentionally here
// The next expectation will be referred to as exp#2
EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).WillOnce(Return(true));
// Some other expectations left out intentionally here
_at_protocol_mock.select_operator(some_var, another_var); // will use exp#2
_at_protocol_mock.select_operator(some_var, another_var); // will use exp#2, which is already saturated
}
Я мог бы изменить свой код следующим образом
Код: Выделить всё
TEST_F(at_operator_selection_tests, select_operators_selects_operator_with_best_signal)
{
// arrange
InSequence s;
// The next expectation will be referred to as exp#1
EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).Times(2).WillOnce(Return(true));
// Some other expectations left out intentionally here
_at_protocol_mock.select_operator(some_var, another_var); // will use exp#1
_at_protocol_mock.select_operator(some_var, another_var); // will also use exp#1, which is now expected
}
Это работает, но выглядит странно, поскольку ожиданий больше, и я хочу, чтобы было ясно, что ожидание select_operator используется дважды в контексте.
Это работает, но выглядит странно, поскольку ожиданий больше, и я хочу, чтобы было ясно, что ожидание select_operator используется дважды в контексте.
p>
В ответе выше предлагается использовать функцию InSequence(s) следующим образом
Код: Выделить всё
TEST_F(at_operator_selection_tests, select_operators_selects_operator_with_best_signal)
{
// arrange
InSequence s;
// The next expectation will be referred to as exp#1
EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).Times(1).WillOnce(Return(true)).InSequence(s); // Compile error!!
// Some other expectations left out intentionally here
// The next expectation will be referred to as exp#1
EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).Times(1).WillOnce(Return(true)).InSequence(s);
// Some other expectations left out intentionally here
_at_protocol_mock.select_operator(some_var, another_var);
_at_protocol_mock.select_operator(some_var, another_var);
}
Код: Выделить всё
/home/bp/dev/iobox/firmware/unit_tests/source/valinso/modules/at/operator_selection_tests.cpp:216:104: error: no matching function for call to ‘testing::internal::TypedExpectation::InSequence(testing::InSequence&)’
216 | EXPECT_CALL(_at_protocol_mock, select_operator(_,_)).Times(1).WillOnce(Return(true)).InSequence(s);
И мне бы хотелось понять, что говорит компилятор, почему он не может скомпилировать вызов функции .InSequence(s)?
Подробнее здесь: https://stackoverflow.com/questions/735 ... s-in-order