aboutsummaryrefslogtreecommitdiff
path: root/zencore/filesystem.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-15 16:32:59 +0200
committerMartin Ridgers <[email protected]>2021-09-16 10:07:22 +0200
commit75a1cb75d080bdc56c351c359acdef19a9865608 (patch)
tree0a0ef19934f74bb2280c6f6cb684d98a442d9acd /zencore/filesystem.cpp
parentImplemented GetRunningExecutablePath() for Linux (diff)
downloadzen-75a1cb75d080bdc56c351c359acdef19a9865608.tar.xz
zen-75a1cb75d080bdc56c351c359acdef19a9865608.zip
Added a simple filesystem test case
Diffstat (limited to 'zencore/filesystem.cpp')
-rw-r--r--zencore/filesystem.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 4f3ee44b0..14eef812f 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -15,6 +15,7 @@
#include <winnt.h>
#include <filesystem>
+#include <doctest/doctest.h>
#include <gsl/gsl-lite.hpp>
namespace zen {
@@ -655,4 +656,45 @@ GetRunningExecutablePath()
#endif // ZEN_PLATFORM_WINDOWS
}
+
+
+//////////////////////////////////////////////////////////////////////////
+//
+// Testing related code follows...
+//
+
+void
+filesystem_forcelink()
+{
+}
+
+TEST_CASE("filesystem")
+{
+ using namespace std::filesystem;
+
+ path BinPath = GetRunningExecutablePath();
+ CHECK(BinPath.stem() == "zencore-test");
+ CHECK(is_regular_file(BinPath));
+
+ void* Handle;
+#if ZEN_PLATFORM_WINDOWS
+ Handle = CreateFileW(BinPath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr,
+ OPEN_EXISTING, 0, nullptr);
+ CHECK(Handle != INVALID_HANDLE_VALUE);
+#else
+ int Fd = open(BinPath.c_str(), O_RDONLY);
+ CHECK(Fd >= 0);
+ Handle = (void*)uintptr_t(Fd);
+#endif
+
+ auto FromHandle = PathFromHandle((void*)uintptr_t(Handle));
+ CHECK(equivalent(FromHandle, BinPath));
+
+#if ZEN_PLATFORM_WINDOWS
+ CloseHandle(Handle);
+#else
+ close(int(uintptr_t(Handle)));
+#endif
+}
+
} // namespace zen