Add tests for single and multi-axis AbortPlannedMoves()
This introduces a new #define UNITTEST_MOTION which is used to control the testing scenario: - Normal tests, we allow the stub to override the built-in definition. - For motion tests, we stub the lower-level classes and test the effective implementation We also repeat the prototype of the function, which IMHO is more readable and more flexible: we need to use inline for the real definition, which would require even more macros otherwise.pull/120/head
parent
37ff9b8a8f
commit
b7fcfa5cb5
|
|
@ -239,13 +239,13 @@ public:
|
|||
|
||||
/// @returns true if all planned moves have been finished for one axis
|
||||
/// @param axis requested
|
||||
bool QueueEmpty(Axis axis) const
|
||||
#ifndef UNITTEST
|
||||
{
|
||||
#if !defined(UNITTEST) || defined(UNITTEST_MOTION)
|
||||
bool QueueEmpty(Axis axis) const {
|
||||
return axisData[axis].ctrl.QueueEmpty();
|
||||
}
|
||||
#else
|
||||
;
|
||||
// Force STUB for testing
|
||||
bool QueueEmpty(Axis axis) const;
|
||||
#endif
|
||||
|
||||
/// @returns false if new moves can still be planned for one axis
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# common include and source directories
|
||||
add_compile_definitions(UNITTEST_MOTION)
|
||||
set(include_common ${CMAKE_SOURCE_DIR}/src/modules ${CMAKE_SOURCE_DIR}/src/hal)
|
||||
set(source_common
|
||||
${CMAKE_SOURCE_DIR}/src/modules/motion.cpp
|
||||
|
|
|
|||
|
|
@ -205,3 +205,47 @@ TEST_CASE("motion::triple_move", "[motion]") {
|
|||
REQUIRE(motion.Position(Selector) == 20);
|
||||
REQUIRE(motion.Position(Pulley) == 30);
|
||||
}
|
||||
|
||||
TEST_CASE("motion::queue_abort", "[motion]") {
|
||||
// queue should start empty
|
||||
REQUIRE(motion.QueueEmpty());
|
||||
|
||||
// enqueue two moves
|
||||
motion.PlanMoveTo(Pulley, 10, 1);
|
||||
motion.PlanMoveTo(Idler, 10, 1);
|
||||
REQUIRE(!motion.QueueEmpty(Pulley));
|
||||
REQUIRE(!motion.QueueEmpty(Idler));
|
||||
REQUIRE(motion.QueueEmpty(Selector));
|
||||
REQUIRE(!motion.QueueEmpty());
|
||||
|
||||
// step ~1/3 way through
|
||||
REQUIRE(stepUntilDone(3) == -1);
|
||||
|
||||
// abort the whole queue
|
||||
motion.AbortPlannedMoves();
|
||||
REQUIRE(motion.QueueEmpty(Pulley));
|
||||
REQUIRE(motion.QueueEmpty(Idler));
|
||||
REQUIRE(motion.QueueEmpty());
|
||||
}
|
||||
|
||||
TEST_CASE("motion::queue_abort_1", "[motion]") {
|
||||
// queue should start empty
|
||||
REQUIRE(motion.QueueEmpty());
|
||||
|
||||
// enqueue two moves
|
||||
motion.PlanMoveTo(Pulley, 10, 1);
|
||||
motion.PlanMoveTo(Idler, 10, 1);
|
||||
REQUIRE(!motion.QueueEmpty(Pulley));
|
||||
REQUIRE(!motion.QueueEmpty(Idler));
|
||||
REQUIRE(motion.QueueEmpty(Selector));
|
||||
REQUIRE(!motion.QueueEmpty());
|
||||
|
||||
// step ~1/3 way through
|
||||
REQUIRE(stepUntilDone(3) == -1);
|
||||
|
||||
// abort one axis only
|
||||
motion.AbortPlannedMoves(Pulley);
|
||||
REQUIRE(motion.QueueEmpty(Pulley));
|
||||
REQUIRE(!motion.QueueEmpty(Idler));
|
||||
REQUIRE(!motion.QueueEmpty());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue