Add unit test for empty event queue
parent
786bdb2a38
commit
1d8b649c09
|
|
@ -26,6 +26,8 @@ Event UserInput::StripFromPrinterBit(uint8_t e) {
|
|||
}
|
||||
|
||||
Event UserInput::ConsumeEvent() {
|
||||
if (eventQueue.empty())
|
||||
return Event::NoEvent;
|
||||
if (printerInCharge) {
|
||||
Event rv = eventQueue.front();
|
||||
if (rv & Event::FromPrinter) {
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ void ToolChangeFailLoadToFinda(logic::ToolChange &tc, uint8_t fromSlot, uint8_t
|
|||
|
||||
void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) {
|
||||
// now waiting for user input
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Left, true);
|
||||
|
||||
REQUIRE(WhileTopState(tc, ProgressCode::ERREngagingIdler, 5000UL));
|
||||
|
|
@ -224,6 +225,7 @@ void ToolChangeFailLoadToFindaLeftBtn(logic::ToolChange &tc, uint8_t toSlot) {
|
|||
|
||||
void ToolChangeFailLoadToFindaMiddleBtn(logic::ToolChange &tc, uint8_t toSlot) {
|
||||
// now waiting for user input
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Middle, true);
|
||||
|
||||
REQUIRE(WhileCondition(
|
||||
|
|
@ -255,6 +257,8 @@ void ToolChangeFailLoadToFindaRightBtnFINDA_FSensor(logic::ToolChange &tc, uint8
|
|||
REQUIRE(mf::finda.Pressed());
|
||||
SetFSensorStateAndDebounce(true);
|
||||
REQUIRE(mfs::fsensor.Pressed());
|
||||
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Right, true);
|
||||
|
||||
CheckFinishedCorrectly(tc, toSlot);
|
||||
|
|
@ -265,6 +269,8 @@ void ToolChangeFailLoadToFindaRightBtnFINDA_FSensor(logic::ToolChange &tc, uint8
|
|||
void ToolChangeFailLoadToFindaRightBtnFINDA(logic::ToolChange &tc, uint8_t toSlot) {
|
||||
// now waiting for user input - press FINDA
|
||||
SetFINDAStateAndDebounce(true);
|
||||
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Right, true);
|
||||
|
||||
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), toSlot, true, false, ml::off, ml::blink0, ErrorCode::FSENSOR_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
|
||||
|
|
@ -274,6 +280,7 @@ void ToolChangeFailLoadToFindaRightBtnFINDA(logic::ToolChange &tc, uint8_t toSlo
|
|||
|
||||
void ToolChangeFailLoadToFindaRightBtn(logic::ToolChange &tc, uint8_t toSlot) {
|
||||
// now waiting for user input - do not press anything
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Right, true);
|
||||
|
||||
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, mi::Idler::IdleSlotIndex(), toSlot, false, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser));
|
||||
|
|
@ -352,7 +359,9 @@ void ToolChangeFailFSensorMiddleBtn(logic::ToolChange &tc, uint8_t fromSlot, uin
|
|||
|
||||
// user pulls filament out from the fsensor and presses Retry
|
||||
SetFSensorStateAndDebounce(false);
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
PressButtonAndDebounce(tc, mb::Middle, true);
|
||||
|
||||
REQUIRE(VerifyState(tc, mg::FilamentLoadState::InSelector, mi::idler.IdleSlotIndex(), fromSlot, false, false, ml::blink0, ml::off, ErrorCode::RUNNING, ProgressCode::UnloadingFilament));
|
||||
REQUIRE(tc.unl.State() == ProgressCode::FeedingToFinda); // MMU must find out where the filament is FS is OFF, FINDA is OFF
|
||||
|
||||
|
|
|
|||
|
|
@ -36,16 +36,20 @@ TEST_CASE("user_input::printer_in_charge", "[user_input]") {
|
|||
mui::userInput.ProcessMessage(button);
|
||||
// i.e. we should NOT be able to extract that message with ConsumeEventForPrinter()
|
||||
REQUIRE(mui::userInput.ConsumeEventForPrinter() == mui::NoEvent);
|
||||
REQUIRE(mui::userInput.AnyEvent());
|
||||
// but we should be able to extract that message with ConsumeEvent()
|
||||
REQUIRE(mui::userInput.ConsumeEvent() == event);
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
|
||||
// press a button on the MMU
|
||||
PressButtonAndDebounce(button);
|
||||
REQUIRE(mb::buttons.ButtonPressed(button));
|
||||
// we should NOT be able to extract the event with ConsumeEvent
|
||||
REQUIRE(mui::userInput.ConsumeEvent() == mui::NoEvent);
|
||||
REQUIRE(mui::userInput.AnyEvent());
|
||||
// but we should be able to extract that message with ConsumeEventForPrinter
|
||||
REQUIRE(mui::userInput.ConsumeEventForPrinter() == event);
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
}
|
||||
|
||||
TEST_CASE("user_input::button_pressed_MMU", "[user_input]") {
|
||||
|
|
@ -67,5 +71,21 @@ TEST_CASE("user_input::button_pressed_MMU", "[user_input]") {
|
|||
PressButtonAndDebounce(button);
|
||||
REQUIRE(mb::buttons.ButtonPressed(button));
|
||||
// we should be able to extract the event with ConsumeEvent
|
||||
REQUIRE(mui::userInput.AnyEvent());
|
||||
REQUIRE(mui::userInput.ConsumeEvent() == event);
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
}
|
||||
|
||||
TEST_CASE("user_input::empty_queue", "[user_input]") {
|
||||
mt::ReinitTimebase();
|
||||
mb::Buttons b;
|
||||
|
||||
// reset UI
|
||||
new (&mui::userInput) mui::UserInput();
|
||||
REQUIRE_FALSE(mui::userInput.PrinterInCharge());
|
||||
|
||||
REQUIRE_FALSE(mui::userInput.AnyEvent());
|
||||
// try extracting something
|
||||
REQUIRE(mui::userInput.ConsumeEvent() == mui::NoEvent);
|
||||
REQUIRE(mui::userInput.ConsumeEventForPrinter() == mui::NoEvent);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue