From efa1266f10e90c0c46f47cc06645422142cb2d9f Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Wed, 3 Sep 2025 12:42:10 +0800 Subject: common -> base in test dir. --- test/base/platform/win/StreamConvertTest.cpp | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/base/platform/win/StreamConvertTest.cpp (limited to 'test/base/platform/win/StreamConvertTest.cpp') diff --git a/test/base/platform/win/StreamConvertTest.cpp b/test/base/platform/win/StreamConvertTest.cpp new file mode 100644 index 00000000..90ebb568 --- /dev/null +++ b/test/base/platform/win/StreamConvertTest.cpp @@ -0,0 +1,39 @@ +#include "cru/base/io/OpenFileFlag.h" +#include "cru/base/platform/win/Exception.h" +#include "cru/base/platform/win/StreamConvert.h" +#include "cru/base/platform/win/Win32FileStream.h" + +#include + +#include +#include + +TEST_CASE("StreamConvert FileStreamWork", "[stream]") { + using namespace cru; + using namespace cru::io; + using namespace cru::platform::win; + + 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); + IStream* com_stream = ConvertStreamToComStream(&file2); + LARGE_INTEGER position; + position.QuadPart = 0; + ThrowIfFailed(com_stream->Seek(position, SEEK_SET, nullptr)); + auto buffer = std::make_unique(3); + ThrowIfFailed(com_stream->Read(buffer.get(), 3, nullptr)); + REQUIRE(std::string_view(buffer.get(), 3) == "abc"); + com_stream->Release(); + file2.Close(); + + std::filesystem::remove(temp_file_path); +} -- cgit v1.2.3