| 23 | #include "platforms/esp/32/drivers/spi/ispi_peripheral.h" |
| 24 | |
| 25 | FL_TEST_FILE(FL_FILEPATH) { |
| 26 | |
| 27 | using namespace fl; |
| 28 | using namespace fl::detail; |
| 29 | |
| 30 | // Disambiguate SpiTransaction from fl::SpiTransaction (in fl/spi.h) |
| 31 | using SpiTrans = fl::detail::SpiTransaction; |
| 32 | |
| 33 | //============================================================================= |
| 34 | // Test Fixtures and Helpers |
| 35 | //============================================================================= |
| 36 | |
| 37 | /// @brief Reset mock to clean state before each test |
| 38 | struct SpiPeripheralFixture { |
| 39 | SpiPeripheralMock& mock = SpiPeripheralMock::instance(); |
| 40 | |
| 41 | SpiPeripheralFixture() { |
| 42 | // Reset mock to clean state |
| 43 | mock.reset(); |
| 44 | mock.clearTransactionHistory(); |
| 45 | } |
| 46 | |
| 47 | ~SpiPeripheralFixture() { |
| 48 | // Cleanup after test |
| 49 | if (mock.hasDevice()) { |
| 50 | mock.removeDevice(); |
| 51 | } |
| 52 | if (mock.isInitialized()) { |
| 53 | mock.freeBus(); |
| 54 | } |
| 55 | mock.reset(); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | /// @brief Callback function for transaction completion testing |
| 60 | static int gCallbackCount = 0; |
| 61 | static void testCallback(void* trans) { |
| 62 | (void)trans; // Unused |
| 63 | gCallbackCount++; |
| 64 | } |
| 65 | |
| 66 | //============================================================================= |
| 67 | // Bus Lifecycle Tests |
| 68 | //============================================================================= |
| 69 | |
| 70 | FL_TEST_CASE("SpiPeripheralMock - initialize bus") { |
| 71 | SpiPeripheralFixture fixture; |
| 72 | auto& mock = fixture.mock; |
| 73 | |
| 74 | // Valid configuration |
| 75 | SpiBusConfig config(/*mosi=*/23, /*sclk=*/18); |
| 76 | FL_CHECK(mock.initializeBus(config)); |
| 77 | FL_CHECK(mock.isInitialized()); |
| 78 | |
| 79 | // Verify stored configuration |
| 80 | const auto& stored = mock.getBusConfig(); |
| 81 | FL_CHECK_EQ(stored.mosi_pin, 23); |
| 82 | FL_CHECK_EQ(stored.sclk_pin, 18); |
nothing calls this directly
no test coverage detected