Skip to content

Commit

Permalink
UnitTests Added tests for TRAP::FileSystem::FileSystemStatus 11/17/20…
Browse files Browse the repository at this point in the history
…24 | 24w46b1
  • Loading branch information
GamesTrap committed Nov 17, 2024
1 parent 956c471 commit 09dc91a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions SITREPS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions TRAP/src/FileSystem/FileSystemWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions TRAP/src/FileSystem/FileSystemWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -177,11 +177,12 @@ struct fmt::formatter<TRAP::FileSystem::FileSystemStatus>
case Erased:
enumStr = "Erased";
break;
}

default:
if(enumStr.empty())
{
TRAP_ASSERT(false, "fmt::formatter<TRAP::FileSystem::FileSystemStatus>: Missing enum value!");
enumStr = "<MISSING ENUM VALUE>";
break;
}

return fmt::format_to(ctx.out(), "{}", enumStr);
Expand Down
10 changes: 10 additions & 0 deletions UnitTests/src/FileSystem/FileSystemWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TRAP::FileSystem::FileSystemStatus>(100u)) == "<MISSING ENUM VALUE>");
}

0 comments on commit 09dc91a

Please sign in to comment.