st-4-esp32/test/test_axis/test_axis.cpp
Ryan Malloy 71e5484507 Add native tests, ASCOM Alpaca API, and README
Native test suite (61 tests, 5 suites) with thin mock layer for
Arduino/FreeRTOS/esp_timer enabling host-side testing without hardware.

ASCOM Alpaca REST API on port 32323 with UDP discovery, implementing
Telescope v3 interface for N.I.N.A., PHD2, and compatible software.
Follows existing ST4WiFi conditional compilation pattern.

README documents wiring, all three protocols (serial, WebSocket, Alpaca),
pin/rate configuration, and build instructions.
2026-02-18 13:40:34 -07:00

106 lines
2.8 KiB
C++

// ST4Axis unit tests
#include <unity.h>
#include "mock_state.h"
#include "ST4Axis.h"
void setUp() { MockState::reset(); }
void tearDown() {}
void test_plus_activates_correct_pin() {
ST4Axis axis;
axis.begin(10, 11);
axis.plus();
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[10]);
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[11]);
TEST_ASSERT_EQUAL(ST4Direction::PLUS, axis.direction());
}
void test_minus_activates_correct_pin() {
ST4Axis axis;
axis.begin(10, 11);
axis.minus();
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[10]);
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[11]);
TEST_ASSERT_EQUAL(ST4Direction::MINUS, axis.direction());
}
void test_mutual_exclusion() {
ST4Axis axis;
axis.begin(10, 11);
axis.plus();
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[10]);
// Switching to minus should deactivate plus first
axis.minus();
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[10]);
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[11]);
}
void test_stop_deactivates_both() {
ST4Axis axis;
axis.begin(10, 11);
axis.plus();
axis.stop();
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[10]);
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[11]);
TEST_ASSERT_EQUAL(ST4Direction::STOP, axis.direction());
}
void test_move_direction_plus() {
ST4Axis axis;
axis.begin(10, 11);
axis.move(ST4Direction::PLUS);
TEST_ASSERT_EQUAL(ST4Direction::PLUS, axis.direction());
}
void test_move_direction_minus() {
ST4Axis axis;
axis.begin(10, 11);
axis.move(ST4Direction::MINUS);
TEST_ASSERT_EQUAL(ST4Direction::MINUS, axis.direction());
}
void test_move_direction_stop() {
ST4Axis axis;
axis.begin(10, 11);
axis.move(ST4Direction::PLUS);
axis.move(ST4Direction::STOP);
TEST_ASSERT_EQUAL(ST4Direction::STOP, axis.direction());
}
void test_is_active_plus() {
ST4Axis axis;
axis.begin(10, 11);
axis.plus();
TEST_ASSERT_TRUE(axis.isActive());
}
void test_is_active_stop() {
ST4Axis axis;
axis.begin(10, 11);
axis.plus();
axis.stop();
TEST_ASSERT_FALSE(axis.isActive());
}
void test_initial_state_stopped() {
ST4Axis axis;
axis.begin(10, 11);
TEST_ASSERT_EQUAL(ST4Direction::STOP, axis.direction());
TEST_ASSERT_FALSE(axis.isActive());
}
int main() {
UNITY_BEGIN();
RUN_TEST(test_plus_activates_correct_pin);
RUN_TEST(test_minus_activates_correct_pin);
RUN_TEST(test_mutual_exclusion);
RUN_TEST(test_stop_deactivates_both);
RUN_TEST(test_move_direction_plus);
RUN_TEST(test_move_direction_minus);
RUN_TEST(test_move_direction_stop);
RUN_TEST(test_is_active_plus);
RUN_TEST(test_is_active_stop);
RUN_TEST(test_initial_state_stopped);
return UNITY_END();
}