aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-25 00:09:19 +0800
committercrupest <crupest@outlook.com>2022-01-25 00:09:19 +0800
commit6b34acefdbf82e3bcc5d3a103ecb2118ae05b81e (patch)
tree06e56cc868dcbdd5062a15e87dc7baec320c8b4b /test
parent24e1dc8723aea1e46a3aa15794747f3fa52f8eca (diff)
downloadcru-6b34acefdbf82e3bcc5d3a103ecb2118ae05b81e.tar.gz
cru-6b34acefdbf82e3bcc5d3a103ecb2118ae05b81e.tar.bz2
cru-6b34acefdbf82e3bcc5d3a103ecb2118ae05b81e.zip
...
Diffstat (limited to 'test')
-rw-r--r--test/common/CMakeLists.txt4
-rw-r--r--test/common/io/Win32FileStreamTest.cpp32
2 files changed, 36 insertions, 0 deletions
diff --git a/test/common/CMakeLists.txt b/test/common/CMakeLists.txt
index 7926437c..38c15000 100644
--- a/test/common/CMakeLists.txt
+++ b/test/common/CMakeLists.txt
@@ -13,6 +13,10 @@ if (UNIX)
endif()
if (WIN32)
+ target_sources(cru_base_test PRIVATE
+ io/Win32FileStreamTest.cpp
+ )
+
add_custom_command(TARGET cru_base_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:cru_base_test> $<TARGET_FILE_DIR:cru_base_test>
COMMAND_EXPAND_LISTS
diff --git a/test/common/io/Win32FileStreamTest.cpp b/test/common/io/Win32FileStreamTest.cpp
new file mode 100644
index 00000000..6c3edb6f
--- /dev/null
+++ b/test/common/io/Win32FileStreamTest.cpp
@@ -0,0 +1,32 @@
+#include "cru/common/io/OpenFileFlag.hpp"
+#include "cru/common/io/Win32FileStream.hpp"
+
+#include <gtest/gtest.h>
+
+#include <cstdio>
+#include <filesystem>
+
+TEST(UnixFileStream, Work) {
+ using namespace cru;
+ using namespace cru::io;
+
+ auto temp_file_path =
+ (std::filesystem::temp_directory_path() / "cru_test_temp.XXXXXX")
+ .native();
+ _wmktemp(temp_file_path.data());
+
+ String path = temp_file_path;
+
+ Win32FileStream file(path, OpenFileFlags::Write | OpenFileFlags::Create);
+ file.Write("abc", 3);
+ file.Close();
+
+ Win32FileStream file2(path, OpenFileFlags::Read);
+ auto buffer = std::make_unique<std::byte[]>(3);
+ file2.Read(buffer.get(), 3);
+ ASSERT_EQ(std::string_view(reinterpret_cast<const char*>(buffer.get()), 3),
+ "abc");
+ file2.Close();
+
+ std::filesystem::remove(temp_file_path);
+}