diff --git a/Sming/Core/Data/Buffer/CircularBuffer.cpp b/Sming/Core/Data/Buffer/CircularBuffer.cpp index 6f0a221384..9e9064bf71 100644 --- a/Sming/Core/Data/Buffer/CircularBuffer.cpp +++ b/Sming/Core/Data/Buffer/CircularBuffer.cpp @@ -68,7 +68,7 @@ size_t CircularBuffer::room() const size_t CircularBuffer::write(uint8_t charToWrite) { - if(!room()) { + if(room() == 0) { return 0; } diff --git a/Sming/Core/Data/StreamTransformer.cpp b/Sming/Core/Data/StreamTransformer.cpp index 4090ec6122..f719e4698f 100644 --- a/Sming/Core/Data/StreamTransformer.cpp +++ b/Sming/Core/Data/StreamTransformer.cpp @@ -37,7 +37,7 @@ void StreamTransformer::fillTempStream(char* buffer, size_t bufSize) while((room = tempStream->room()) >= maxChunkSize) { auto chunkSize = sourceStream->readMemoryBlock(buffer, maxChunkSize); if(chunkSize == 0) { - return; + break; } saveState(); @@ -55,7 +55,9 @@ void StreamTransformer::fillTempStream(char* buffer, size_t bufSize) if(sourceStream->isFinished()) { auto outLength = transform(nullptr, 0, result, resultSize); - tempStream->write(result, outLength); + auto written = tempStream->write(result, outLength); + (void)written; + assert(written == outLength); } } diff --git a/tests/HostTests/modules/Stream.cpp b/tests/HostTests/modules/Stream.cpp index 90802023ac..a3d98ffa83 100644 --- a/tests/HostTests/modules/Stream.cpp +++ b/tests/HostTests/modules/Stream.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include DEFINE_FSTR_LOCAL(template1, "Stream containing {var1}, {var2} and {var3}. {} {{}} {{12345") @@ -86,6 +87,19 @@ class StreamTest : public TestGroup REQUIRE(Resource::image_png == s); } + TEST_CASE("ChunkedStream / StreamTransformer") + { + DEFINE_FSTR_LOCAL(FS_INPUT, "Some test data"); + DEFINE_FSTR_LOCAL(FS_OUTPUT, "e\r\nSome test data\r\n0\r\n\r\n"); + ChunkedStream chunked(new FlashMemoryStream(FS_INPUT)); + MemoryDataStream output; + output.copyFrom(&chunked); + String s; + REQUIRE(output.moveString(s)); + m_printHex("OUTPUT", s.c_str(), s.length()); + REQUIRE(FS_OUTPUT == s); + } + TEST_CASE("MultipartStream / MultiStream") { unsigned itemIndex{0};