diff --git a/lldb/include/lldb/Core/StreamAsynchronousIO.h b/lldb/include/lldb/Core/StreamAsynchronousIO.h index 29b109757da7..8791315dbeb5 100644 --- a/lldb/include/lldb/Core/StreamAsynchronousIO.h +++ b/lldb/include/lldb/Core/StreamAsynchronousIO.h @@ -30,7 +30,8 @@ public: void Flush() override; - size_t Write(const void *src, size_t src_len) override; +protected: + size_t WriteImpl(const void *src, size_t src_len) override; private: Debugger &m_debugger; diff --git a/lldb/include/lldb/Core/StreamBuffer.h b/lldb/include/lldb/Core/StreamBuffer.h index 307dc7e18a5e..7b2468330ad2 100644 --- a/lldb/include/lldb/Core/StreamBuffer.h +++ b/lldb/include/lldb/Core/StreamBuffer.h @@ -30,12 +30,6 @@ public: // Nothing to do when flushing a buffer based stream... } - virtual size_t Write(const void *s, size_t length) { - if (s && length) - m_packet.append((const char *)s, ((const char *)s) + length); - return length; - } - void Clear() { m_packet.clear(); } // Beware, this might not be NULL terminated as you can expect from @@ -48,6 +42,12 @@ public: protected: llvm::SmallVector m_packet; + + virtual size_t WriteImpl(const void *s, size_t length) { + if (s && length) + m_packet.append((const char *)s, ((const char *)s) + length); + return length; + } }; } // namespace lldb_private diff --git a/lldb/include/lldb/Core/StreamFile.h b/lldb/include/lldb/Core/StreamFile.h index a26ae84c7be5..250876bdefbc 100644 --- a/lldb/include/lldb/Core/StreamFile.h +++ b/lldb/include/lldb/Core/StreamFile.h @@ -46,13 +46,13 @@ public: void Flush() override; - size_t Write(const void *s, size_t length) override; protected: //------------------------------------------------------------------ // Classes that inherit from StreamFile can see and modify these //------------------------------------------------------------------ File m_file; + size_t WriteImpl(const void *s, size_t length) override; private: DISALLOW_COPY_AND_ASSIGN(StreamFile); diff --git a/lldb/include/lldb/Utility/Stream.h b/lldb/include/lldb/Utility/Stream.h index 24c69ba9f573..96a238aef9ac 100644 --- a/lldb/include/lldb/Utility/Stream.h +++ b/lldb/include/lldb/Utility/Stream.h @@ -83,7 +83,13 @@ public: /// @return /// The number of bytes that were appended to the stream. //------------------------------------------------------------------ - virtual size_t Write(const void *src, size_t src_len) = 0; + size_t Write(const void *src, size_t src_len) { + size_t appended_byte_count = WriteImpl(src, src_len); + m_bytes_written += appended_byte_count; + return appended_byte_count; + } + + size_t GetWrittenBytes() const { return m_bytes_written; } //------------------------------------------------------------------ // Member functions @@ -523,8 +529,25 @@ protected: lldb::ByteOrder m_byte_order; ///< Byte order to use when encoding scalar types. int m_indent_level; ///< Indention level. + std::size_t m_bytes_written = 0; ///< Number of bytes written so far. size_t _PutHex8(uint8_t uvalue, bool add_prefix); + + //------------------------------------------------------------------ + /// Output character bytes to the stream. + /// + /// Appends \a src_len characters from the buffer \a src to the stream. + /// + /// @param[in] src + /// A buffer containing at least \a src_len bytes of data. + /// + /// @param[in] src_len + /// A number of bytes to append to the stream. + /// + /// @return + /// The number of bytes that were appended to the stream. + //------------------------------------------------------------------ + virtual size_t WriteImpl(const void *src, size_t src_len) = 0; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Utility/StreamString.h b/lldb/include/lldb/Utility/StreamString.h index 0ae3e82a3498..28c11fcc0f8f 100644 --- a/lldb/include/lldb/Utility/StreamString.h +++ b/lldb/include/lldb/Utility/StreamString.h @@ -31,8 +31,6 @@ public: void Flush() override; - size_t Write(const void *s, size_t length) override; - void Clear(); bool Empty() const; @@ -49,6 +47,7 @@ public: protected: std::string m_packet; + size_t WriteImpl(const void *s, size_t length) override; }; } // namespace lldb_private diff --git a/lldb/include/lldb/Utility/StreamTee.h b/lldb/include/lldb/Utility/StreamTee.h index 569ba1979978..4f8e6ab1f002 100644 --- a/lldb/include/lldb/Utility/StreamTee.h +++ b/lldb/include/lldb/Utility/StreamTee.h @@ -70,29 +70,6 @@ public: } } - size_t Write(const void *s, size_t length) override { - std::lock_guard guard(m_streams_mutex); - if (m_streams.empty()) - return 0; - - size_t min_bytes_written = SIZE_MAX; - collection::iterator pos, end; - for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) { - // Allow for our collection to contain NULL streams. This allows the - // StreamTee to be used with hard coded indexes for clients that might - // want N total streams with only a few that are set to valid values. - Stream *strm = pos->get(); - if (strm) { - const size_t bytes_written = strm->Write(s, length); - if (min_bytes_written > bytes_written) - min_bytes_written = bytes_written; - } - } - if (min_bytes_written == SIZE_MAX) - return 0; - return min_bytes_written; - } - size_t AppendStream(const lldb::StreamSP &stream_sp) { size_t new_idx = m_streams.size(); std::lock_guard guard(m_streams_mutex); @@ -131,6 +108,29 @@ protected: typedef std::vector collection; mutable std::recursive_mutex m_streams_mutex; collection m_streams; + + size_t WriteImpl(const void *s, size_t length) override { + std::lock_guard guard(m_streams_mutex); + if (m_streams.empty()) + return 0; + + size_t min_bytes_written = SIZE_MAX; + collection::iterator pos, end; + for (pos = m_streams.begin(), end = m_streams.end(); pos != end; ++pos) { + // Allow for our collection to contain NULL streams. This allows the + // StreamTee to be used with hard coded indexes for clients that might + // want N total streams with only a few that are set to valid values. + Stream *strm = pos->get(); + if (strm) { + const size_t bytes_written = strm->Write(s, length); + if (min_bytes_written > bytes_written) + min_bytes_written = bytes_written; + } + } + if (min_bytes_written == SIZE_MAX) + return 0; + return min_bytes_written; + } }; } // namespace lldb_private diff --git a/lldb/source/Core/StreamAsynchronousIO.cpp b/lldb/source/Core/StreamAsynchronousIO.cpp index aae8636bff09..eb8bf3620afc 100644 --- a/lldb/source/Core/StreamAsynchronousIO.cpp +++ b/lldb/source/Core/StreamAsynchronousIO.cpp @@ -31,7 +31,7 @@ void StreamAsynchronousIO::Flush() { } } -size_t StreamAsynchronousIO::Write(const void *s, size_t length) { +size_t StreamAsynchronousIO::WriteImpl(const void *s, size_t length) { m_data.append((const char *)s, length); return length; } diff --git a/lldb/source/Core/StreamFile.cpp b/lldb/source/Core/StreamFile.cpp index f59415485021..3e7214032fa8 100644 --- a/lldb/source/Core/StreamFile.cpp +++ b/lldb/source/Core/StreamFile.cpp @@ -41,7 +41,7 @@ StreamFile::~StreamFile() {} void StreamFile::Flush() { m_file.Flush(); } -size_t StreamFile::Write(const void *s, size_t length) { +size_t StreamFile::WriteImpl(const void *s, size_t length) { m_file.Write(s, length); return length; } diff --git a/lldb/source/Utility/StreamString.cpp b/lldb/source/Utility/StreamString.cpp index 75f58de28b97..152096198858 100644 --- a/lldb/source/Utility/StreamString.cpp +++ b/lldb/source/Utility/StreamString.cpp @@ -24,12 +24,15 @@ void StreamString::Flush() { // Nothing to do when flushing a buffer based stream... } -size_t StreamString::Write(const void *s, size_t length) { +size_t StreamString::WriteImpl(const void *s, size_t length) { m_packet.append(reinterpret_cast(s), length); return length; } -void StreamString::Clear() { m_packet.clear(); } +void StreamString::Clear() { + m_packet.clear(); + m_bytes_written = 0; +} bool StreamString::Empty() const { return GetSize() == 0; } diff --git a/lldb/unittests/Utility/StreamTeeTest.cpp b/lldb/unittests/Utility/StreamTeeTest.cpp index 150a8a5b1206..9fcfbc802587 100644 --- a/lldb/unittests/Utility/StreamTeeTest.cpp +++ b/lldb/unittests/Utility/StreamTeeTest.cpp @@ -90,7 +90,9 @@ namespace { void Flush() override { ++m_flush_count; } - size_t Write(const void *src, size_t src_len) override { return src_len; } + size_t WriteImpl(const void *src, size_t src_len) override { + return src_len; + } }; } diff --git a/lldb/unittests/Utility/StreamTest.cpp b/lldb/unittests/Utility/StreamTest.cpp index 3210a6247f20..0fdee0969c0e 100644 --- a/lldb/unittests/Utility/StreamTest.cpp +++ b/lldb/unittests/Utility/StreamTest.cpp @@ -44,149 +44,211 @@ TEST_F(StreamTest, ChangingByteOrder) { TEST_F(StreamTest, PutChar) { s.PutChar('a'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("a", TakeValue()); s.PutChar('1'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("1", TakeValue()); } TEST_F(StreamTest, PutCharWhitespace) { s.PutChar(' '); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); s.PutChar('\n'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\n", TakeValue()); s.PutChar('\r'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\r", TakeValue()); s.PutChar('\t'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\t", TakeValue()); } TEST_F(StreamTest, PutCString) { s.PutCString(""); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCString("foobar"); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("foobar", TakeValue()); s.PutCString(" "); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); } TEST_F(StreamTest, PutCStringWithStringRef) { s.PutCString(llvm::StringRef("")); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCString(llvm::StringRef("foobar")); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("foobar", TakeValue()); s.PutCString(llvm::StringRef(" ")); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(" ", TakeValue()); } TEST_F(StreamTest, QuotedCString) { s.QuotedCString("foo"); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ(R"("foo")", TakeValue()); s.QuotedCString("ba r"); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ(R"("ba r")", TakeValue()); s.QuotedCString(" "); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ(R"(" ")", TakeValue()); } TEST_F(StreamTest, PutCharNull) { s.PutChar('\0'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); s.PutChar('a'); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("a", 1), TakeValue()); } TEST_F(StreamTest, PutCStringAsRawHex8) { s.PutCStringAsRawHex8(""); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); s.PutCStringAsRawHex8("foobar"); + EXPECT_EQ(12U, s.GetWrittenBytes()); EXPECT_EQ("666f6f626172", TakeValue()); s.PutCStringAsRawHex8(" "); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("20", TakeValue()); } TEST_F(StreamTest, PutHex8) { s.PutHex8((uint8_t)55); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("37", TakeValue()); + s.PutHex8(std::numeric_limits::max()); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("ff", TakeValue()); + s.PutHex8((uint8_t)0); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("00", TakeValue()); } TEST_F(StreamTest, PutNHex8) { s.PutNHex8(0, (uint8_t)55); + EXPECT_EQ(0U, s.GetWrittenBytes()); EXPECT_EQ("", TakeValue()); + s.PutNHex8(1, (uint8_t)55); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("37", TakeValue()); + s.PutNHex8(2, (uint8_t)55); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("3737", TakeValue()); + s.PutNHex8(1, (uint8_t)56); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("38", TakeValue()); } TEST_F(StreamTest, PutHex16ByteOrderLittle) { s.PutHex16(0x1234U, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("3412", TakeValue()); + s.PutHex16(std::numeric_limits::max(), lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("ffff", TakeValue()); + s.PutHex16(0U, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0000", TakeValue()); } TEST_F(StreamTest, PutHex16ByteOrderBig) { s.PutHex16(0x1234U, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("1234", TakeValue()); + s.PutHex16(std::numeric_limits::max(), lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("ffff", TakeValue()); + s.PutHex16(0U, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0000", TakeValue()); } TEST_F(StreamTest, PutHex32ByteOrderLittle) { s.PutHex32(0x12345678U, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("78563412", TakeValue()); + s.PutHex32(std::numeric_limits::max(), lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("ffffffff", TakeValue()); + s.PutHex32(0U, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("00000000", TakeValue()); } TEST_F(StreamTest, PutHex32ByteOrderBig) { s.PutHex32(0x12345678U, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("12345678", TakeValue()); + s.PutHex32(std::numeric_limits::max(), lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("ffffffff", TakeValue()); + s.PutHex32(0U, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("00000000", TakeValue()); } TEST_F(StreamTest, PutHex64ByteOrderLittle) { s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("efcdab9078563412", TakeValue()); + s.PutHex64(std::numeric_limits::max(), lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("ffffffffffffffff", TakeValue()); + s.PutHex64(0U, lldb::eByteOrderLittle); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("0000000000000000", TakeValue()); } TEST_F(StreamTest, PutHex64ByteOrderBig) { s.PutHex64(0x1234567890ABCDEFU, lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("1234567890abcdef", TakeValue()); + s.PutHex64(std::numeric_limits::max(), lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("ffffffffffffffff", TakeValue()); + s.PutHex64(0U, lldb::eByteOrderBig); + EXPECT_EQ(16U, s.GetWrittenBytes()); EXPECT_EQ("0000000000000000", TakeValue()); } @@ -200,6 +262,7 @@ TEST_F(StreamTest, PutMaxHex64ByteOrderBig) { EXPECT_EQ(8U, bytes); bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderBig); EXPECT_EQ(16U, bytes); + EXPECT_EQ(30U, s.GetWrittenBytes()); EXPECT_EQ("121234123456781234567890abcdef", TakeValue()); } @@ -213,6 +276,7 @@ TEST_F(StreamTest, PutMaxHex64ByteOrderLittle) { EXPECT_EQ(8U, bytes); bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderLittle); EXPECT_EQ(16U, bytes); + EXPECT_EQ(30U, s.GetWrittenBytes()); EXPECT_EQ("12341278563412efcdab9078563412", TakeValue()); } @@ -222,12 +286,15 @@ TEST_F(StreamTest, PutMaxHex64ByteOrderLittle) { TEST_F(StreamTest, ShiftOperatorChars) { s << 'a' << 'b'; + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("ab", TakeValue()); } TEST_F(StreamTest, ShiftOperatorStrings) { s << "cstring\n"; + EXPECT_EQ(8U, s.GetWrittenBytes()); s << llvm::StringRef("llvm::StringRef\n"); + EXPECT_EQ(24U, s.GetWrittenBytes()); EXPECT_EQ("cstring\nllvm::StringRef\n", TakeValue()); } @@ -236,6 +303,7 @@ TEST_F(StreamTest, ShiftOperatorInts) { s << std::numeric_limits::max() << " "; s << std::numeric_limits::max() << " "; s << std::numeric_limits::max(); + EXPECT_EQ(40U, s.GetWrittenBytes()); EXPECT_EQ("127 32767 2147483647 9223372036854775807", TakeValue()); } @@ -244,6 +312,7 @@ TEST_F(StreamTest, ShiftOperatorUInts) { s << std::numeric_limits::max() << " "; s << std::numeric_limits::max() << " "; s << std::numeric_limits::max(); + EXPECT_EQ(33U, s.GetWrittenBytes()); EXPECT_EQ("ff ffff ffffffff ffffffffffffffff", TakeValue()); } @@ -259,6 +328,7 @@ TEST_F(StreamTest, ShiftOperatorPtr) { int *ptr = &i; s << ptr; + EXPECT_NE(0U, s.GetWrittenBytes()); EXPECT_TRUE(!TakeValue().empty()); } @@ -268,6 +338,7 @@ TEST_F(StreamTest, PutPtr) { int *ptr = &i; s.PutPointer(ptr); + EXPECT_NE(0U, s.GetWrittenBytes()); EXPECT_TRUE(!TakeValue().empty()); } @@ -283,6 +354,7 @@ TEST_F(StreamTest, PutBytesAsRawHex8ToBigEndian) { uint32_t value = 0x12345678; s.PutBytesAsRawHex8(static_cast(&value), sizeof(value), hostByteOrder, lldb::eByteOrderBig); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("78563412", TakeValue()); } @@ -290,6 +362,7 @@ TEST_F(StreamTest, PutRawBytesToBigEndian) { uint32_t value = 0x12345678; s.PutRawBytes(static_cast(&value), sizeof(value), hostByteOrder, lldb::eByteOrderBig); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\x78\x56\x34\x12", TakeValue()); } @@ -297,6 +370,7 @@ TEST_F(StreamTest, PutBytesAsRawHex8ToLittleEndian) { uint32_t value = 0x12345678; s.PutBytesAsRawHex8(static_cast(&value), sizeof(value), hostByteOrder, lldb::eByteOrderLittle); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("12345678", TakeValue()); } @@ -304,6 +378,7 @@ TEST_F(StreamTest, PutRawBytesToLittleEndian) { uint32_t value = 0x12345678; s.PutRawBytes(static_cast(&value), sizeof(value), hostByteOrder, lldb::eByteOrderLittle); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\x12\x34\x56\x78", TakeValue()); } @@ -337,72 +412,84 @@ TEST_F(StreamTest, PutRawBytesToMixedEndian) { TEST_F(BinaryStreamTest, PutULEB128OneByte) { auto bytes = s.PutULEB128(0x74ULL); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\x74", TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutULEB128TwoBytes) { auto bytes = s.PutULEB128(0x1985ULL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("\x85\x33", TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutULEB128ThreeBytes) { auto bytes = s.PutULEB128(0x5023ULL); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ("\xA3\xA0\x1", TakeValue()); EXPECT_EQ(3U, bytes); } TEST_F(BinaryStreamTest, PutULEB128FourBytes) { auto bytes = s.PutULEB128(0xA48032ULL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\xB2\x80\x92\x5", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(BinaryStreamTest, PutULEB128FiveBytes) { auto bytes = s.PutULEB128(0x12345678ULL); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue()); EXPECT_EQ(5U, bytes); } TEST_F(BinaryStreamTest, PutULEB128SixBytes) { auto bytes = s.PutULEB128(0xABFE3FAFDFULL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue()); EXPECT_EQ(6U, bytes); } TEST_F(BinaryStreamTest, PutULEB128SevenBytes) { auto bytes = s.PutULEB128(0xDABFE3FAFDFULL); + EXPECT_EQ(7U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue()); EXPECT_EQ(7U, bytes); } TEST_F(BinaryStreamTest, PutULEB128EightBytes) { auto bytes = s.PutULEB128(0x7CDABFE3FAFDFULL); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue()); EXPECT_EQ(8U, bytes); } TEST_F(BinaryStreamTest, PutULEB128NineBytes) { auto bytes = s.PutULEB128(0x327CDABFE3FAFDFULL); + EXPECT_EQ(9U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue()); EXPECT_EQ(9U, bytes); } TEST_F(BinaryStreamTest, PutULEB128MaxValue) { auto bytes = s.PutULEB128(std::numeric_limits::max()); + EXPECT_EQ(10U, s.GetWrittenBytes()); EXPECT_EQ("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1", TakeValue()); EXPECT_EQ(10U, bytes); } TEST_F(BinaryStreamTest, PutULEB128Zero) { auto bytes = s.PutULEB128(0x0U); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutULEB128One) { auto bytes = s.PutULEB128(0x1U); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ("\x1", TakeValue()); EXPECT_EQ(1U, bytes); } @@ -413,72 +500,84 @@ TEST_F(BinaryStreamTest, PutULEB128One) { TEST_F(BinaryStreamTest, PutSLEB128OneByte) { auto bytes = s.PutSLEB128(0x74LL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\xF4\0", 2), TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128TwoBytes) { auto bytes = s.PutSLEB128(0x1985LL); + EXPECT_EQ(2U, s.GetWrittenBytes()); EXPECT_EQ("\x85\x33", TakeValue()); EXPECT_EQ(2U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128ThreeBytes) { auto bytes = s.PutSLEB128(0x5023LL); + EXPECT_EQ(3U, s.GetWrittenBytes()); EXPECT_EQ("\xA3\xA0\x1", TakeValue()); EXPECT_EQ(3U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128FourBytes) { auto bytes = s.PutSLEB128(0xA48032LL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("\xB2\x80\x92\x5", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128FiveBytes) { auto bytes = s.PutSLEB128(0x12345678LL); + EXPECT_EQ(5U, s.GetWrittenBytes()); EXPECT_EQ("\xF8\xAC\xD1\x91\x1", TakeValue()); EXPECT_EQ(5U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128SixBytes) { auto bytes = s.PutSLEB128(0xABFE3FAFDFLL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\x15", TakeValue()); EXPECT_EQ(6U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128SevenBytes) { auto bytes = s.PutSLEB128(0xDABFE3FAFDFLL); + EXPECT_EQ(7U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\x3", TakeValue()); EXPECT_EQ(7U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128EightBytes) { auto bytes = s.PutSLEB128(0x7CDABFE3FAFDFLL); + EXPECT_EQ(8U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x3", TakeValue()); EXPECT_EQ(8U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128NineBytes) { auto bytes = s.PutSLEB128(0x327CDABFE3FAFDFLL); + EXPECT_EQ(9U, s.GetWrittenBytes()); EXPECT_EQ("\xDF\xDF\xFE\xF1\xBF\xB5\xF3\x93\x3", TakeValue()); EXPECT_EQ(9U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128MaxValue) { auto bytes = s.PutSLEB128(std::numeric_limits::max()); + EXPECT_EQ(10U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0", 10), TakeValue()); EXPECT_EQ(10U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128Zero) { auto bytes = s.PutSLEB128(0x0); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\0", 1), TakeValue()); EXPECT_EQ(1U, bytes); } TEST_F(BinaryStreamTest, PutSLEB128One) { auto bytes = s.PutSLEB128(0x1); + EXPECT_EQ(1U, s.GetWrittenBytes()); EXPECT_EQ(std::string("\x1", 1), TakeValue()); EXPECT_EQ(1U, bytes); } @@ -492,12 +591,14 @@ TEST_F(BinaryStreamTest, PutSLEB128One) { TEST_F(StreamTest, PutULEB128) { auto bytes = s.PutULEB128(0x74ULL); + EXPECT_EQ(4U, s.GetWrittenBytes()); EXPECT_EQ("0x74", TakeValue()); EXPECT_EQ(4U, bytes); } TEST_F(StreamTest, PutSLEB128) { auto bytes = s.PutSLEB128(0x1985LL); + EXPECT_EQ(6U, s.GetWrittenBytes()); EXPECT_EQ("0x6533", TakeValue()); EXPECT_EQ(6U, bytes); }