diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-15 16:43:25 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-16 00:01:49 +0800 |
| commit | 246eb9266b9349b44cbe96f3f839124ab30cbb89 (patch) | |
| tree | 31604c8a4764d3a601d56599e56c98d91bd97758 /test/base/platform/win/StreamTest.cpp | |
| parent | b92aa78ac19476049ab881b49c51b1a970a4a973 (diff) | |
| download | cru-246eb9266b9349b44cbe96f3f839124ab30cbb89.tar.gz cru-246eb9266b9349b44cbe96f3f839124ab30cbb89.tar.bz2 cru-246eb9266b9349b44cbe96f3f839124ab30cbb89.zip | |
Impl win subprocess.
Diffstat (limited to 'test/base/platform/win/StreamTest.cpp')
| -rw-r--r-- | test/base/platform/win/StreamTest.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/base/platform/win/StreamTest.cpp b/test/base/platform/win/StreamTest.cpp new file mode 100644 index 00000000..e1a6e4fe --- /dev/null +++ b/test/base/platform/win/StreamTest.cpp @@ -0,0 +1,67 @@ +#include "cru/base/StringUtil.h" +#include "cru/base/platform/win/Stream.h" + +#include <catch2/catch_test_macros.hpp> + +#include <cstdio> +#include <filesystem> + +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()); + + std::string path = string::ToUtf8(temp_file_path); + + ComStream file(path, OpenFileFlags::Write | OpenFileFlags::Create); + file.Write("abc", 3); + file.Close(); + + ComStream file2(path, OpenFileFlags::Read); + IStream* com_stream = ToComStream(&file2); + LARGE_INTEGER position; + position.QuadPart = 0; + CheckHResult(com_stream->Seek(position, SEEK_SET, nullptr)); + auto buffer = std::make_unique<char[]>(3); + CheckHResult(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); +} + +TEST_CASE("ComStream Work", "[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()); + + std::string path = string::ToUtf8(temp_file_path); + + ComStream file(path, OpenFileFlags::Write | OpenFileFlags::Create); + auto write_count = file.Write("abc", 3); + REQUIRE(write_count == 3); + file.Close(); + + REQUIRE(std::filesystem::file_size(path) == 3); + + ComStream file2(path, OpenFileFlags::Read); + auto buffer = std::make_unique<std::byte[]>(3); + auto read_count = file2.Read(buffer.get(), 3); + REQUIRE(read_count == 3); + REQUIRE(std::string_view(reinterpret_cast<const char*>(buffer.get()), 3) == + "abc"); + file2.Close(); + + std::filesystem::remove(temp_file_path); +} |
