| 15 | #include "fl/stl/static_assert.h" |
| 16 | |
| 17 | FL_TEST_FILE(FL_FILEPATH) { |
| 18 | |
| 19 | using namespace fl; |
| 20 | |
| 21 | FL_TEST_CASE("RxDevice - default template returns non-null device") { |
| 22 | // Factory always returns a non-null device on all platforms |
| 23 | auto device = RxDevice::create<RxDeviceType::RMT>(6); // GPIO 6 |
| 24 | FL_REQUIRE(device != nullptr); |
| 25 | FL_REQUIRE(device->name() != nullptr); |
| 26 | |
| 27 | #ifdef FL_IS_STUB |
| 28 | // On stub platform, returns NativeRxDevice |
| 29 | FL_CHECK(fl::strcmp(device->name(), "native") == 0); |
| 30 | #elif defined(ESP32) |
| 31 | // On ESP32, returns real device (name varies) |
| 32 | FL_CHECK(device->name() != nullptr); |
| 33 | #else |
| 34 | // On other platforms, returns dummy device |
| 35 | FL_CHECK(fl::strcmp(device->name(), "dummy") == 0); |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | FL_TEST_CASE("RxDevice - non-stub non-esp32 returns dummy that fails") { |
| 40 | #if !defined(FL_IS_STUB) && !defined(ESP32) |
| 41 | // On non-ESP32, non-stub platforms, factory returns dummy device |
| 42 | auto device = RxDevice::create<RxDeviceType::RMT>(6); |
| 43 | FL_REQUIRE(device != nullptr); |
| 44 | FL_CHECK(fl::strcmp(device->name(), "dummy") == 0); |
| 45 | |
| 46 | // begin() should return false |
| 47 | RxConfig config; |
| 48 | config.buffer_size = 512; |
| 49 | FL_CHECK(device->begin(config) == false); |
| 50 | |
| 51 | // finished() should return true (always "done") |
| 52 | FL_CHECK(device->finished() == true); |
| 53 | |
| 54 | // wait() should timeout |
| 55 | FL_CHECK(device->wait(100) == RxWaitResult::TIMEOUT); |
| 56 | |
| 57 | // decode() should fail |
| 58 | ChipsetTiming4Phase timing{}; |
| 59 | uint8_t buffer[10]; |
| 60 | auto result = device->decode(timing, buffer); |
| 61 | FL_CHECK(!result.ok()); |
| 62 | FL_CHECK(result.error() == DecodeError::INVALID_ARGUMENT); |
| 63 | |
| 64 | // getRawEdgeTimes should return 0 |
| 65 | EdgeTime edges[10]; |
| 66 | size_t count = device->getRawEdgeTimes(edges); |
| 67 | FL_CHECK(count == 0); |
| 68 | #endif |
| 69 | } |
| 70 | |
| 71 | FL_TEST_CASE("RxDevice - template factory creates devices by type") { |
| 72 | // Template-based factory should work with enum |
| 73 | auto rmt_device = RxDevice::create<RxDeviceType::RMT>(6); // GPIO 6 |
| 74 | auto isr_device = RxDevice::create<RxDeviceType::ISR>(7); // GPIO 7 |
nothing calls this directly
no test coverage detected