diff --git a/SITREPS.txt b/SITREPS.txt index 7f4f1dd76..b147b233d 100644 --- a/SITREPS.txt +++ b/SITREPS.txt @@ -5391,3 +5391,4 @@ SITREP 11/17/2024|24w46b1 - Utils/String Fixed unnecessary extra null terminator in CreateUTF8StringFromWideStringWin32()/CreateWideStringFromUTF8StringWin32() ~<5 mins - Utils Added SafeSystem() as a replacement for unsafe system()/shell calls ~>30 mins - FileSystem Replaced calls to popen()/ShellExecuteW() with SafeSystem() ~<10 mins + - UnitTests Added tests for TRAP::FileSystem::FileSystemStatus ~<5 mins diff --git a/TRAP/src/FileSystem/FileSystemWatcher.cpp b/TRAP/src/FileSystem/FileSystemWatcher.cpp index 7722f095f..385cad47d 100644 --- a/TRAP/src/FileSystem/FileSystemWatcher.cpp +++ b/TRAP/src/FileSystem/FileSystemWatcher.cpp @@ -593,7 +593,8 @@ void TRAP::FileSystem::FileSystemWatcher::Watch(const std::stop_token& stopToken if(!events.empty()) { DeduplicateEvents(events); - DispatchEvents(events, *m_callback.ReadLock()); + const auto callback = m_callback.ReadLock(); + DispatchEvents(events, *callback); } } } @@ -917,7 +918,8 @@ void TRAP::FileSystem::FileSystemWatcher::Watch(const std::stop_token& stopToken if(!events.empty()) { DeduplicateEvents(events); - DispatchEvents(events, *m_callback.ReadLock()); + const auto callback = m_callback.ReadLock(); + DispatchEvents(events, *callback); } } } diff --git a/TRAP/src/FileSystem/FileSystemWatcher.h b/TRAP/src/FileSystem/FileSystemWatcher.h index 36b9ee219..136ca44f1 100644 --- a/TRAP/src/FileSystem/FileSystemWatcher.h +++ b/TRAP/src/FileSystem/FileSystemWatcher.h @@ -35,7 +35,7 @@ namespace TRAP::Events namespace TRAP::FileSystem { /// @brief Specifies the status of a file or folder. - enum class FileSystemStatus + enum class FileSystemStatus : u8 { Created, Renamed, @@ -177,11 +177,12 @@ struct fmt::formatter case Erased: enumStr = "Erased"; break; + } - default: + if(enumStr.empty()) + { TRAP_ASSERT(false, "fmt::formatter: Missing enum value!"); enumStr = ""; - break; } return fmt::format_to(ctx.out(), "{}", enumStr); diff --git a/UnitTests/src/FileSystem/FileSystemWatcher.cpp b/UnitTests/src/FileSystem/FileSystemWatcher.cpp index 47af9feb1..759c50234 100644 --- a/UnitTests/src/FileSystem/FileSystemWatcher.cpp +++ b/UnitTests/src/FileSystem/FileSystemWatcher.cpp @@ -320,3 +320,13 @@ TEST_CASE("TRAP::FileSystem::FileSystemWatcher - Recursive", "[filesystem][files TestEvents(fsWatcher, BasePath); } } + +TEST_CASE("TRAP::FileSystem::FileSystemStatus", "[filesystem][filesystemstatus]") +{ + REQUIRE(fmt::format("{}", TRAP::FileSystem::FileSystemStatus::Created) == "Created"); + REQUIRE(fmt::format("{}", TRAP::FileSystem::FileSystemStatus::Renamed) == "Renamed"); + REQUIRE(fmt::format("{}", TRAP::FileSystem::FileSystemStatus::Modified) == "Modified"); + REQUIRE(fmt::format("{}", TRAP::FileSystem::FileSystemStatus::Erased) == "Erased"); + + REQUIRE(fmt::format("{}", static_cast(100u)) == ""); +}