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.
93 lines
2.5 KiB
C++
93 lines
2.5 KiB
C++
// ST4Pin unit tests
|
|
#include <unity.h>
|
|
#include "mock_state.h"
|
|
#include "ST4Pin.h"
|
|
|
|
void setUp() { MockState::reset(); }
|
|
void tearDown() {}
|
|
|
|
void test_active_high_activate() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_HIGH);
|
|
pin.activate();
|
|
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[5]);
|
|
TEST_ASSERT_TRUE(pin.isActive());
|
|
}
|
|
|
|
void test_active_high_deactivate() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_HIGH);
|
|
pin.activate();
|
|
pin.deactivate();
|
|
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[5]);
|
|
TEST_ASSERT_FALSE(pin.isActive());
|
|
}
|
|
|
|
void test_active_low_activate() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_LOW);
|
|
pin.activate();
|
|
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[5]);
|
|
TEST_ASSERT_TRUE(pin.isActive());
|
|
}
|
|
|
|
void test_active_low_deactivate() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_LOW);
|
|
pin.activate();
|
|
pin.deactivate();
|
|
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[5]);
|
|
TEST_ASSERT_FALSE(pin.isActive());
|
|
}
|
|
|
|
void test_begin_sets_output() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_HIGH);
|
|
TEST_ASSERT_EQUAL(OUTPUT, MockState::gpioModes[5]);
|
|
}
|
|
|
|
void test_begin_deactivates() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_HIGH);
|
|
// ACTIVE_HIGH deactivated = LOW
|
|
TEST_ASSERT_EQUAL(LOW, MockState::gpioStates[5]);
|
|
TEST_ASSERT_FALSE(pin.isActive());
|
|
}
|
|
|
|
void test_begin_deactivates_active_low() {
|
|
ST4Pin pin;
|
|
pin.begin(5, ST4PinLogic::ACTIVE_LOW);
|
|
// ACTIVE_LOW deactivated = HIGH
|
|
TEST_ASSERT_EQUAL(HIGH, MockState::gpioStates[5]);
|
|
TEST_ASSERT_FALSE(pin.isActive());
|
|
}
|
|
|
|
void test_negative_pin_noop() {
|
|
ST4Pin pin;
|
|
// Default constructed pin has pin_=-1
|
|
pin.activate();
|
|
pin.deactivate();
|
|
TEST_ASSERT_FALSE(pin.isActive());
|
|
TEST_ASSERT_EQUAL(-1, pin.pin());
|
|
}
|
|
|
|
void test_pin_returns_assigned() {
|
|
ST4Pin pin;
|
|
pin.begin(7, ST4PinLogic::ACTIVE_HIGH);
|
|
TEST_ASSERT_EQUAL(7, pin.pin());
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_active_high_activate);
|
|
RUN_TEST(test_active_high_deactivate);
|
|
RUN_TEST(test_active_low_activate);
|
|
RUN_TEST(test_active_low_deactivate);
|
|
RUN_TEST(test_begin_sets_output);
|
|
RUN_TEST(test_begin_deactivates);
|
|
RUN_TEST(test_begin_deactivates_active_low);
|
|
RUN_TEST(test_negative_pin_noop);
|
|
RUN_TEST(test_pin_returns_assigned);
|
|
return UNITY_END();
|
|
}
|