Skip to content

Commit

Permalink
✅ (functional): RFIDKit - Refactor deep sleep functional tests w/ ena…
Browse files Browse the repository at this point in the history
…ble/disable
  • Loading branch information
YannLocatelli committed Jul 10, 2024
1 parent 2e90dd7 commit 68d3719
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_buffered_serial)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_motor)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_pwm)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_core_lcd)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_rfid_kit)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_log_kit)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/deep_sleep_mbed_hal)
add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/file_manager)
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/tests/deep_sleep_rfid_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Leka - LekaOS
# Copyright 2024 APF France handicap
# SPDX-License-Identifier: Apache-2.0

register_functional_test(
TARGET
functional_ut_deep_sleep_rfid_kit

INCLUDE_DIRECTORIES

SOURCES
suite_rfid_kit.cpp

LINK_LIBRARIES
CoreBufferedSerial
CoreRFIDReader
RFIDKit
)
90 changes: 90 additions & 0 deletions tests/functional/tests/deep_sleep_rfid_kit/suite_rfid_kit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Leka - LekaOS
// Copyright 2024 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreBufferedSerial.h"
#include "CoreRFIDReaderCR95HF.h"
#include "RFIDKit.h"
#include "tests/config.h"
#include "tests/utils.h"
#include "tests/utils_sleep.h"

using namespace leka;
using namespace boost::ut;
using namespace std::chrono;
using namespace boost::ut::bdd;

auto rfidserial = CoreBufferedSerial(RFID_UART_TX, RFID_UART_RX, 57600);
auto rfidreader = CoreRFIDReaderCR95HF(rfidserial);
auto rfidkit = RFIDKit(rfidreader);

suite suite_rfid_kit = [] {
scenario("rfid initialization") = [] {
given("rfid is in default configuration") = [] {
rfidkit.init();
rtos::ThisThread::sleep_for(5ms);

expect(neq(&rfidkit, nullptr));

when("I do nothing") = [&] {
then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.test_check_ok);
};
};
};
};

scenario("enabled/disable deepsleep") = [] {
given("rfid is in default configuration") = [] {
when("I enable rfid deep sleep") = [&] {
rtos::ThisThread::sleep_for(500ms);
rfidkit.enableDeepSleep();
rtos::ThisThread::sleep_for(500ms);

then("I expect deep sleep TO BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(status.test_check_ok);
};
};

when("I disable rfid deep sleep") = [&] {
rtos::ThisThread::sleep_for(500ms);
rfidkit.disableDeepSleep();
rtos::ThisThread::sleep_for(500ms);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.test_check_ok);
};
};

when("I enable rfid deep sleep") = [&] {
rtos::ThisThread::sleep_for(500ms);
rfidkit.enableDeepSleep();
rtos::ThisThread::sleep_for(500ms);

then("I expect deep sleep TO BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(status.test_check_ok);
};
};

when("I disable rfid deep sleep") = [&] {
rtos::ThisThread::sleep_for(500ms);
rfidkit.disableDeepSleep();
rtos::ThisThread::sleep_for(500ms);

then("I expect deep sleep TO NOT BE possible") = [] {
auto status = utils::sleep::system_deep_sleep_check();

expect(not status.test_check_ok);
};
};
};
};
};

0 comments on commit 68d3719

Please sign in to comment.