diff options
| author | Stefan Boberg <[email protected]> | 2021-09-19 18:36:50 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-19 18:36:50 +0200 |
| commit | f920793c7585a11c60346d306108f90368878d32 (patch) | |
| tree | 9c246fb3dba5556ff9e6a24e1cb270051ae7a43b /zencore/testutils.cpp | |
| parent | Changed BasicFile implementation (diff) | |
| download | zen-f920793c7585a11c60346d306108f90368878d32.tar.xz zen-f920793c7585a11c60346d306108f90368878d32.zip | |
Added testutils for use in writing tests
Currently contains helpers for managing temporary directories used in tests
Diffstat (limited to 'zencore/testutils.cpp')
| -rw-r--r-- | zencore/testutils.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/zencore/testutils.cpp b/zencore/testutils.cpp new file mode 100644 index 000000000..116491950 --- /dev/null +++ b/zencore/testutils.cpp @@ -0,0 +1,33 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "zencore/testutils.h" +#include <zencore/session.h> +#include "zencore/string.h" + +namespace zen { + +static std::atomic<int> Sequence{0}; + +std::filesystem::path +CreateTemporaryDirectory() +{ + std::error_code Ec; + + std::filesystem::path DirPath = std::filesystem::temp_directory_path() / GetSessionIdString() / IntNum(++Sequence).c_str(); + std::filesystem::remove_all(DirPath, Ec); + std::filesystem::create_directories(DirPath); + + return DirPath; +} + +ScopedTemporaryDirectory::ScopedTemporaryDirectory() : m_RootPath(CreateTemporaryDirectory()) +{ +} + +ScopedTemporaryDirectory::~ScopedTemporaryDirectory() +{ + std::error_code Ec; + std::filesystem::remove_all(m_RootPath, Ec); +} + +} // namespace zen
\ No newline at end of file |