Skip to content

Commit

Permalink
Tests: rework after DELAY_BETWEEN_SWEEPS
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Aug 11, 2024
1 parent bca7140 commit 805305a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions test/test_logic/test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ namespace fabomatic::tests
{
constexpr auto DEFAULT_CYCLES = 3;

// Ignore DELAY_BETWEEN_SWEEPS delay between cards events
rfid.setDisabledUntil(std::nullopt);
MockMrfc522 &driver = rfid.getDriver();

driver.resetUid();
rfid.setDisabledUntil(std::nullopt);

for (auto i = 0; i < DEFAULT_CYCLES; i++)
{
logic.checkRfid();
rfid.setDisabledUntil(std::nullopt);
}

if (uid.has_value())
{
driver.setUid(uid.value(), duration_tap);
TEST_ASSERT_TRUE_MESSAGE(uid == rfid.getUid(), "Card UID not equal");
auto start = fabomatic::Tasks::arduinoNow();

do
{
logic.checkRfid();
rfid.setDisabledUntil(std::nullopt);
delay(50);
} while (duration_tap.has_value() && fabomatic::Tasks::arduinoNow() - start < duration_tap);
}
Expand Down
8 changes: 5 additions & 3 deletions test/test_logic/test_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ namespace fabomatic::tests
const auto card_uid = get_test_uid(1);

simulate_rfid_card(rfid, logic, card_uid, std::nullopt);

Tasks::delay(fabomatic::conf::machine::DELAY_BETWEEN_SWEEPS);
TEST_ASSERT_TRUE_MESSAGE(rfid.isNewCardPresent(), "New card not present");
TEST_ASSERT_TRUE_MESSAGE(rfid.readCardSerial().has_value(), "Card serial not read");
TEST_ASSERT_TRUE_MESSAGE(rfid.readCardSerial().value() == card_uid, "Card serial not equal");
Expand Down Expand Up @@ -271,8 +273,8 @@ namespace fabomatic::tests
TEST_ASSERT_EQUAL_UINT16_MESSAGE(BoardLogic::Status::MaintenanceNeeded, logic.getStatus(), "Status not MaintenanceNeeded");

simulate_rfid_card(rfid, logic, std::nullopt);
simulate_rfid_card(rfid, logic, card_admin, conf::machine::LONG_TAP_DURATION + 10s); // Log in + Conferma manutenzione perché non ritorna prima della conclusione
simulate_rfid_card(rfid, logic, std::nullopt); // Card away
simulate_rfid_card(rfid, logic, card_admin, conf::machine::LONG_TAP_DURATION + 3s); // Log in + Conferma manutenzione perché non ritorna prima della conclusione
simulate_rfid_card(rfid, logic, std::nullopt); // Card away
TEST_ASSERT_EQUAL_UINT16_MESSAGE(BoardLogic::Status::MachineInUse, logic.getStatus(), "Status not MachineInUse by admin");
TEST_ASSERT_FALSE_MESSAGE(logic.getMachine().isMaintenanceNeeded(), "Maintenance not cleared by admin");

Expand Down Expand Up @@ -355,7 +357,7 @@ void setup()
{
delay(1000);
esp_log_level_set(TAG, LOG_LOCAL_LEVEL);

auto config = fabomatic::SavedConfig::LoadFromEEPROM();
UNITY_BEGIN();
RUN_TEST(fabomatic::tests::test_machine_defaults);
Expand Down

0 comments on commit 805305a

Please sign in to comment.