// ST4Pin unit tests #include #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(); }