Add unit tests
parent
091a78d841
commit
bf14e8435b
|
|
@ -28,8 +28,12 @@ bool NoCommand::StepInner() {
|
|||
state = ProgressCode::OK;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break; // mui::Event::Middle
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break; // ProgressCode::ERRWaitingForUser
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ add_subdirectory(eject_filament)
|
|||
|
||||
add_subdirectory(load_filament)
|
||||
|
||||
add_subdirectory(no_command)
|
||||
|
||||
add_subdirectory(tool_change)
|
||||
|
||||
add_subdirectory(unload_filament)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
# define the test executable
|
||||
add_executable(
|
||||
no_command_tests
|
||||
${CMAKE_SOURCE_DIR}/src/application.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/registers.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/command_base.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/cut_filament.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/eject_filament.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/feed_to_finda.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/feed_to_bondtech.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/home.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/load_filament.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/move_selector.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/no_command.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/retract_from_finda.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/set_mode.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/tool_change.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/unload_filament.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/logic/unload_to_finda.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/buttons.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/debouncer.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/finda.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/fsensor.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/globals.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/idler.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/leds.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/movable_base.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/permanent_storage.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/protocol.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/pulley.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/selector.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/user_input.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/modules/pulse_gen.cpp
|
||||
${MODULES_STUBS_DIR}/stub_adc.cpp
|
||||
${MODULES_STUBS_DIR}/stub_cpu.cpp
|
||||
${MODULES_STUBS_DIR}/stub_eeprom.cpp
|
||||
${MODULES_STUBS_DIR}/stub_gpio.cpp
|
||||
${MODULES_STUBS_DIR}/stub_shr16.cpp
|
||||
${MODULES_STUBS_DIR}/stub_serial.cpp
|
||||
${MODULES_STUBS_DIR}/stub_timebase.cpp
|
||||
${MODULES_STUBS_DIR}/stub_tmc2130.cpp
|
||||
${LOGIC_STUBS_DIR}/homing.cpp
|
||||
${LOGIC_STUBS_DIR}/main_loop_stub.cpp
|
||||
${LOGIC_STUBS_DIR}/stub_motion.cpp
|
||||
test_no_command.cpp
|
||||
)
|
||||
|
||||
# define required search paths
|
||||
target_include_directories(
|
||||
no_command_tests PUBLIC "${CMAKE_SOURCE_DIR}/src/modules" "${CMAKE_SOURCE_DIR}/src/hal"
|
||||
"${CMAKE_SOURCE_DIR}/src/logic"
|
||||
)
|
||||
|
||||
# tell build system about the test case
|
||||
add_catch_test(no_command_tests)
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
#include "catch2/catch_test_macros.hpp"
|
||||
|
||||
#include "../../../../src/modules/buttons.h"
|
||||
#include "../../../../src/modules/finda.h"
|
||||
#include "../../../../src/modules/fsensor.h"
|
||||
#include "../../../../src/modules/globals.h"
|
||||
#include "../../../../src/modules/idler.h"
|
||||
#include "../../../../src/modules/leds.h"
|
||||
#include "../../../../src/modules/motion.h"
|
||||
#include "../../../../src/modules/permanent_storage.h"
|
||||
#include "../../../../src/modules/selector.h"
|
||||
#include "../../../../src/modules/pulley.h"
|
||||
#include "../../../../src/modules/user_input.h"
|
||||
|
||||
#include "../../../../src/logic/no_command.h"
|
||||
|
||||
#include "../../modules/stubs/stub_adc.h"
|
||||
|
||||
#include "../stubs/homing.h"
|
||||
#include "../stubs/main_loop_stub.h"
|
||||
#include "../stubs/stub_motion.h"
|
||||
|
||||
#include "../helpers/helpers.ipp"
|
||||
|
||||
TEST_CASE("no_command::SetInitError", "[no_command]") {
|
||||
logic::NoCommand nc;
|
||||
|
||||
// Step 1 - Check there are no errors
|
||||
REQUIRE(nc.Error() == ErrorCode::OK);
|
||||
REQUIRE(nc.State() == ProgressCode::OK);
|
||||
|
||||
// Step 2 - Create error
|
||||
nc.SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
|
||||
// Step 3 - Check error is waiting for user input
|
||||
REQUIRE(nc.Error() == ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
REQUIRE(nc.State() == ProgressCode::ERRWaitingForUser);
|
||||
|
||||
// Step 4 - Loop through a few iterations, error remains unchanged
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
nc.Step();
|
||||
}
|
||||
|
||||
REQUIRE(nc.Error() == ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
REQUIRE(nc.State() == ProgressCode::ERRWaitingForUser);
|
||||
}
|
||||
|
||||
TEST_CASE("no_command::FINDA_VS_EEPROM_DISREPANCY_retry", "[no_command]") {
|
||||
logic::NoCommand nc;
|
||||
|
||||
// Initalise the ADC
|
||||
hal::adc::SetADC(config::buttonsADCIndex, config::buttonADCMaxValue);
|
||||
|
||||
// Set FINDA and Fsensor on
|
||||
SetFSensorStateAndDebounce(true);
|
||||
SetFINDAStateAndDebounce(true);
|
||||
|
||||
// Step 1 - Check there are no errors
|
||||
REQUIRE(nc.Error() == ErrorCode::OK);
|
||||
REQUIRE(nc.State() == ProgressCode::OK);
|
||||
|
||||
// Step 2 - Create error
|
||||
nc.SetInitError(ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
|
||||
// Step 3 - Check error is waiting for user input
|
||||
REQUIRE(nc.Error() == ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
REQUIRE(nc.State() == ProgressCode::ERRWaitingForUser);
|
||||
|
||||
// Step 4 - Press and release button (from Printer)
|
||||
PressButtonAndDebounce(nc, mb::Middle, true);
|
||||
ClearButtons(nc);
|
||||
|
||||
// Check that the error is still present
|
||||
REQUIRE(nc.Error() == ErrorCode::FINDA_VS_EEPROM_DISREPANCY);
|
||||
REQUIRE(nc.State() == ProgressCode::ERRWaitingForUser);
|
||||
|
||||
// Untrigger FINDA and FSensor
|
||||
SetFSensorStateAndDebounce(false);
|
||||
SetFINDAStateAndDebounce(false);
|
||||
|
||||
// Step 4 - Press and release button
|
||||
PressButtonAndDebounce(nc, mb::Middle, true);
|
||||
ClearButtons(nc);
|
||||
|
||||
// Now the error should be gone :)
|
||||
REQUIRE(nc.Error() == ErrorCode::OK);
|
||||
REQUIRE(nc.State() == ProgressCode::OK);
|
||||
}
|
||||
Loading…
Reference in New Issue