From 00fae61b14e2ab45b915de5171c28d6b7b453ce6 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 21 Jun 2025 22:47:33 +0200 Subject: [PATCH] Build fixes --- Tactility/Source/Tactility.cpp | 2 +- Tactility/Source/service/wifi/WifiMock.cpp | 2 +- Tests/Tactility/UrlTest.cpp | 98 ++++++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 Tests/Tactility/UrlTest.cpp diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index 4f8ba1cd..5cf7e9cf 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -80,7 +80,6 @@ static void registerSystemApps() { addApp(app::alertdialog::manifest); addApp(app::applist::manifest); addApp(app::calculator::manifest); - addApp(app::development::manifest); addApp(app::display::manifest); addApp(app::filebrowser::manifest); addApp(app::fileselection::manifest); @@ -112,6 +111,7 @@ static void registerSystemApps() { #ifdef ESP_PLATFORM addApp(app::chat::manifest); addApp(app::crashdiagnostics::manifest); + addApp(app::development::manifest); #endif if (getConfiguration()->hardware->power != nullptr) { diff --git a/Tactility/Source/service/wifi/WifiMock.cpp b/Tactility/Source/service/wifi/WifiMock.cpp index a019a110..9828ca92 100644 --- a/Tactility/Source/service/wifi/WifiMock.cpp +++ b/Tactility/Source/service/wifi/WifiMock.cpp @@ -136,7 +136,7 @@ int getRssi() { } std::string getIp() { - return "192.168.1.2" + return "192.168.1.2"; } // endregion Public functions diff --git a/Tests/Tactility/UrlTest.cpp b/Tests/Tactility/UrlTest.cpp new file mode 100644 index 00000000..70243947 --- /dev/null +++ b/Tests/Tactility/UrlTest.cpp @@ -0,0 +1,98 @@ +#include "doctest.h" +#include + +#include + +using namespace tt; + +class TestDevice final : public hal::Device { + +private: + + hal::Device::Type type; + std::string name; + std::string description; + +public: + + TestDevice(hal::Device::Type type, std::string name, std::string description) : + type(type), + name(std::move(name)), + description(std::move(description)) + {} + + TestDevice() : TestDevice(hal::Device::Type::Power, "PowerMock", "PowerMock description") {} + + ~TestDevice() final = default; + + Type getType() const final { return type; } + std::string getName() const final { return name; } + std::string getDescription() const final { return description; } +}; + +class DeviceAutoRegistration { + + std::shared_ptr device; + +public: + + explicit DeviceAutoRegistration(std::shared_ptr inDevice) : device(std::move(inDevice)) { + hal::registerDevice(device); + } + + ~DeviceAutoRegistration() { + hal::deregisterDevice(device); + } +}; + +/** We add 3 tests into 1 to ensure cleanup happens */ +TEST_CASE("registering and deregistering a device works") { + auto device = std::make_shared(); + + // Pre-registration + CHECK_EQ(hal::findDevice(device->getId()), nullptr); + + // Registration + hal::registerDevice(device); + auto found_device = hal::findDevice(device->getId()); + CHECK_NE(found_device, nullptr); + CHECK_EQ(found_device->getId(), device->getId()); + + // Deregistration + hal::deregisterDevice(device); + CHECK_EQ(hal::findDevice(device->getId()), nullptr); + found_device = nullptr; // to decrease use count + CHECK_EQ(device.use_count(), 1); +} + +TEST_CASE("find device by id") { + auto device = std::make_shared(); + DeviceAutoRegistration auto_registration(device); + + auto found_device = hal::findDevice(device->getId()); + CHECK_NE(found_device, nullptr); + CHECK_EQ(found_device->getId(), device->getId()); +} + +TEST_CASE("find device by name") { + auto device = std::make_shared(); + DeviceAutoRegistration auto_registration(device); + + auto found_device = hal::findDevice(device->getName()); + CHECK_NE(found_device, nullptr); + CHECK_EQ(found_device->getId(), device->getId()); +} + +TEST_CASE("find device by type") { + // Headless mode shouldn't have a display, so we want to create one to find only our own display as unique device + // We first verify the initial assumption that there is no display: + auto unexpected_display = hal::findFirstDevice(hal::Device::Type::Display); + CHECK_EQ(unexpected_display, nullptr); + + auto device = std::make_shared(hal::Device::Type::Display, "DisplayMock", ""); + DeviceAutoRegistration auto_registration(device); + + auto found_device = hal::findFirstDevice(hal::Device::Type::Display); + CHECK_NE(found_device, nullptr); + CHECK_EQ(found_device->getId(), device->getId()); +}