From 633c77d7cd2dd5cd22018aca17da1490e34d94ec Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 10 Jun 2024 13:40:32 +0800 Subject: test: develop SubProcess test, fix various error. NEED TEST: BufferStream, AutoReadStream, SubProcess. --- include/cru/common/Buffer.h | 1 + include/cru/common/String.h | 2 ++ include/cru/common/SubProcess.h | 5 +++++ include/cru/common/io/Stream.h | 4 ++-- 4 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/cru/common/Buffer.h b/include/cru/common/Buffer.h index a03b69eb..2c3b7b87 100644 --- a/include/cru/common/Buffer.h +++ b/include/cru/common/Buffer.h @@ -7,6 +7,7 @@ class Buffer final { friend void swap(Buffer& left, Buffer& right) noexcept; public: + Buffer(); explicit Buffer(Index size); Buffer(const Buffer& other); diff --git a/include/cru/common/String.h b/include/cru/common/String.h index 2156f060..5d9fc549 100644 --- a/include/cru/common/String.h +++ b/include/cru/common/String.h @@ -35,9 +35,11 @@ class CRU_BASE_API String { public: static String FromUtf8(const char* str); static String FromUtf8(const char* str, Index size); + static String FromUtf8(const std::byte* str, Index size); static String FromUtf8(std::string_view str) { return FromUtf8(str.data(), str.size()); } + static String FromUtf8(const Buffer& buffer); static String FromUtf16(const char16_t* str) { return String(str); } static String FromUtf16(const char16_t* str, Index size) { diff --git a/include/cru/common/SubProcess.h b/include/cru/common/SubProcess.h index 0f87b184..1f7193b5 100644 --- a/include/cru/common/SubProcess.h +++ b/include/cru/common/SubProcess.h @@ -196,6 +196,11 @@ class PlatformSubProcessBase : public Object { class CRU_BASE_API SubProcess : public Object { CRU_DEFINE_CLASS_LOG_TAG(u"SubProcess") + public: + static SubProcess Create( + String program, std::vector arguments = {}, + std::unordered_map environments = {}); + public: SubProcess(SubProcessStartInfo start_info); diff --git a/include/cru/common/io/Stream.h b/include/cru/common/io/Stream.h index 9f9807ae..014cd472 100644 --- a/include/cru/common/io/Stream.h +++ b/include/cru/common/io/Stream.h @@ -64,10 +64,10 @@ class CRU_BASE_API Stream : public Object { Index Write(const char* buffer, Index offset, Index size); Index Write(const char* buffer, Index size); - virtual std::vector ReadAll(); + virtual Buffer ReadToEnd(Index grow_size = 256); // Utf8 encoding. - String ReadAllAsString(); + String ReadToEndAsUtf8String(); virtual void Flush(); -- cgit v1.2.3