From c1b32c6f3d09cb7ab47309eb90b7c31bc828dd0c Mon Sep 17 00:00:00 2001 From: "wtc@chromium.org" Date: Sun, 20 Jan 2013 02:49:10 +0000 Subject: Teach gtest how to print QuicConsumedData and QuicEncryptedPacket. R=rch@chromium.org,glider@chromium.org BUG=170327 TEST=net_unittests has no unitialized memory errors. Review URL: https://chromiumcodereview.appspot.com/11973021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177869 0039d316-1c4b-4281-b951-d872f2087c98 --- net/quic/quic_protocol.cc | 13 ++++++++++++- net/quic/quic_protocol.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'net/quic') diff --git a/net/quic/quic_protocol.cc b/net/quic/quic_protocol.cc index 37ba15e4..90a5dab 100644 --- a/net/quic/quic_protocol.cc +++ b/net/quic/quic_protocol.cc @@ -79,7 +79,7 @@ QuicAckFrame::QuicAckFrame(QuicPacketSequenceNumber largest_observed, } ostream& operator<<(ostream& os, const SentPacketInfo& sent_info) { - os << "least_waiting: " << sent_info.least_unacked; + os << "least_unacked: " << sent_info.least_unacked; return os; } @@ -169,4 +169,15 @@ QuicData::~QuicData() { } } +ostream& operator<<(ostream& os, const QuicEncryptedPacket& s) { + os << s.length() << "-byte data"; + return os; +} + +ostream& operator<<(ostream& os, const QuicConsumedData& s) { + os << "bytes_consumed: " << s.bytes_consumed + << " fin_consumed: " << s.fin_consumed; + return os; +} + } // namespace net diff --git a/net/quic/quic_protocol.h b/net/quic/quic_protocol.h index a391421..bc486dc 100644 --- a/net/quic/quic_protocol.h +++ b/net/quic/quic_protocol.h @@ -479,6 +479,13 @@ class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) : QuicData(buffer, length, owns_buffer) { } + // By default, gtest prints the raw bytes of an object. The bool data + // member (in the base class QuicData) causes this object to have padding + // bytes, which causes the default gtest object printer to read + // uninitialize memory. So we need to teach gtest how to print this object. + NET_EXPORT_PRIVATE friend std::ostream& operator<<( + std::ostream& os, const QuicEncryptedPacket& s); + base::StringPiece AssociatedData() const { return base::StringPiece(data() + kStartOfHashData, kStartOfEncryptedData); } @@ -495,6 +502,14 @@ struct QuicConsumedData { : bytes_consumed(bytes_consumed), fin_consumed(fin_consumed) { } + + // By default, gtest prints the raw bytes of an object. The bool data + // member causes this object to have padding bytes, which causes the + // default gtest object printer to read uninitialize memory. So we need + // to teach gtest how to print this object. + NET_EXPORT_PRIVATE friend std::ostream& operator<<( + std::ostream& os, const QuicConsumedData& s); + size_t bytes_consumed; bool fin_consumed; }; -- cgit v1.1