Use IsStreamError() and friends gMock matchers in quic/core (but not subdirectories). gfe-relnote: n/a, test-only change. PiperOrigin-RevId: 282792467 Change-Id: I827d913c14334b493b46977a827d44e72143fa4e
diff --git a/quic/core/quic_config_test.cc b/quic/core/quic_config_test.cc index 41a5d77..69ce78d 100644 --- a/quic/core/quic_config_test.cc +++ b/quic/core/quic_config_test.cc
@@ -96,15 +96,15 @@ uint32_t value; QuicErrorCode error = msg.GetUint32(kICSL, &value); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_EQ(5u, value); error = msg.GetUint32(kSFCW, &value); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value); error = msg.GetUint32(kCFCW, &value); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value); } @@ -142,7 +142,7 @@ EXPECT_FALSE( config_.SetInitialReceivedConnectionOptions(initial_received_options)) << "You cannot set initial options after the hello."; - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs), config_.IdleNetworkTimeout()); @@ -196,7 +196,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, SERVER, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2), config_.IdleNetworkTimeout()); @@ -236,7 +236,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); } @@ -251,7 +251,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, SERVER, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); } @@ -261,7 +261,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); + EXPECT_THAT(error, IsError(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND)); } TEST_P(QuicConfigTest, MissingValueInSHLO) { @@ -270,7 +270,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, SERVER, &error_details); - EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); + EXPECT_THAT(error, IsError(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND)); } TEST_P(QuicConfigTest, OutOfBoundSHLO) { @@ -284,7 +284,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, SERVER, &error_details); - EXPECT_EQ(QUIC_INVALID_NEGOTIATED_VALUE, error); + EXPECT_THAT(error, IsError(QUIC_INVALID_NEGOTIATED_VALUE)); } TEST_P(QuicConfigTest, InvalidFlowControlWindow) { @@ -314,7 +314,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); EXPECT_TRUE(config_.HasReceivedConnectionOptions()); @@ -335,7 +335,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); EXPECT_FALSE(config_.HasReceivedConnectionOptions()); @@ -362,7 +362,7 @@ std::string error_details; const QuicErrorCode error = config_.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); EXPECT_TRUE(config_.negotiated()); EXPECT_TRUE(config_.HasReceivedConnectionOptions()); @@ -382,8 +382,9 @@ params.idle_timeout_milliseconds.set_value(120000); std::string error_details = "foobar"; - EXPECT_EQ(QUIC_NO_ERROR, - config_.ProcessTransportParameters(params, SERVER, &error_details)); + EXPECT_THAT( + config_.ProcessTransportParameters(params, SERVER, &error_details), + IsQuicNoError()); EXPECT_EQ("", error_details); EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(60), config_.IdleNetworkTimeout()); @@ -430,8 +431,9 @@ params.max_datagram_frame_size.set_value(kMaxDatagramFrameSizeForTest); std::string error_details; - EXPECT_EQ(QUIC_NO_ERROR, - config_.ProcessTransportParameters(params, SERVER, &error_details)); + EXPECT_THAT( + config_.ProcessTransportParameters(params, SERVER, &error_details), + IsQuicNoError()); ASSERT_TRUE( config_.HasReceivedInitialMaxStreamDataBytesIncomingBidirectional()); @@ -461,8 +463,9 @@ TransportParameters params; params.disable_migration = true; std::string error_details; - EXPECT_EQ(QUIC_NO_ERROR, - config_.ProcessTransportParameters(params, SERVER, &error_details)); + EXPECT_THAT( + config_.ProcessTransportParameters(params, SERVER, &error_details), + IsQuicNoError()); EXPECT_TRUE(config_.DisableConnectionMigration()); }
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc index f9de358..8aa33a5 100644 --- a/quic/core/quic_connection_test.cc +++ b/quic/core/quic_connection_test.cc
@@ -1523,8 +1523,8 @@ EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) == nullptr); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_ACK_DATA, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_ACK_DATA)); } void BlockOnNextWrite() { @@ -3834,8 +3834,8 @@ writer_->SetWriteBlocked(); } EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, AddToWriteBlockedListIfBlockedOnFlushPackets) { @@ -5490,7 +5490,7 @@ client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -5539,8 +5539,8 @@ EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_NETWORK_IDLE_TIMEOUT, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_NETWORK_IDLE_TIMEOUT)); } TEST_P(QuicConnectionTest, TimeoutAfterSendSilentCloseAndTLP) { @@ -5567,7 +5567,7 @@ client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -5624,7 +5624,7 @@ client_config.ToHandshakeMessage(&msg, connection_.transport_version()); const QuicErrorCode error = config.ProcessPeerHello(msg, CLIENT, &error_details); - EXPECT_EQ(QUIC_NO_ERROR, error); + EXPECT_THAT(error, IsQuicNoError()); connection_.SetFromConfig(config); EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); @@ -6911,8 +6911,8 @@ EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); ProcessClosePacket(2); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SendWhenDisconnected) { @@ -6930,8 +6930,8 @@ connection_.SendPacket(ENCRYPTION_INITIAL, 1, std::move(packet), HAS_RETRANSMITTABLE_DATA, false, false); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SendConnectivityProbingWhenDisconnected) { @@ -6956,8 +6956,8 @@ "Not sending connectivity probing packet as connection is " "disconnected."); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, WriteBlockedAfterClientSendsConnectivityProbe) { @@ -7038,7 +7038,8 @@ .WillOnce(Invoke(this, &QuicConnectionTest::SaveConnectionCloseFrame)); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PUBLIC_RESET, saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PUBLIC_RESET)); } TEST_P(QuicConnectionTest, IetfStatelessReset) { @@ -7060,7 +7061,8 @@ .WillOnce(Invoke(this, &QuicConnectionTest::SaveConnectionCloseFrame)); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PUBLIC_RESET, saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_PUBLIC_RESET)); } TEST_P(QuicConnectionTest, GoAway) { @@ -7142,8 +7144,8 @@ connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_VERSION, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_VERSION)); } TEST_P(QuicConnectionTest, BadVersionNegotiation) { @@ -7161,8 +7163,8 @@ ConstructReceivedPacket(*encrypted, QuicTime::Zero())); connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET)); } TEST_P(QuicConnectionTest, CheckSendStats) { @@ -7267,8 +7269,8 @@ kSelfAddress, kPeerAddress, QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_PEER_GOING_AWAY, - saved_connection_close_frame_.extracted_error_code); + EXPECT_THAT(saved_connection_close_frame_.extracted_error_code, + IsError(QUIC_PEER_GOING_AWAY)); } TEST_P(QuicConnectionTest, SelectMutualVersion) { @@ -7511,8 +7513,8 @@ "Cannot send stream data with level: ENCRYPTION_INITIAL"); EXPECT_FALSE(connection_.connected()); EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA)); } TEST_P(QuicConnectionTest, SetRetransmissionAlarmForCryptoPacket) { @@ -8672,8 +8674,8 @@ EXPECT_EQ(0, connection_close_frame_count_); } else { EXPECT_EQ(1, connection_close_frame_count_); - EXPECT_EQ(QUIC_INVALID_ACK_DATA, - saved_connection_close_frame_.quic_error_code); + EXPECT_THAT(saved_connection_close_frame_.quic_error_code, + IsError(QUIC_INVALID_ACK_DATA)); } }
diff --git a/quic/core/quic_crypto_client_stream_test.cc b/quic/core/quic_crypto_client_stream_test.cc index 9e957e4..827cb03 100644 --- a/quic/core/quic_crypto_client_stream_test.cc +++ b/quic/core/quic_crypto_client_stream_test.cc
@@ -389,14 +389,14 @@ // Verify preferred version is the highest version that session supports, and // is different from connection's version. QuicVersionLabel client_version_label; - EXPECT_EQ(QUIC_NO_ERROR, - session_->sent_crypto_handshake_messages()[0].GetVersionLabel( - kVER, &client_version_label)); + EXPECT_THAT(session_->sent_crypto_handshake_messages()[0].GetVersionLabel( + kVER, &client_version_label), + IsQuicNoError()); EXPECT_EQ(CreateQuicVersionLabel(supported_versions_[0]), client_version_label); - EXPECT_EQ(QUIC_NO_ERROR, - session_->sent_crypto_handshake_messages()[1].GetVersionLabel( - kVER, &client_version_label)); + EXPECT_THAT(session_->sent_crypto_handshake_messages()[1].GetVersionLabel( + kVER, &client_version_label), + IsQuicNoError()); EXPECT_EQ(CreateQuicVersionLabel(supported_versions_[0]), client_version_label); EXPECT_NE(CreateQuicVersionLabel(connection_->version()),
diff --git a/quic/core/quic_framer_test.cc b/quic/core/quic_framer_test.cc index 2d158fb..9dc6fde 100644 --- a/quic/core/quic_framer_test.cc +++ b/quic/core/quic_framer_test.cc
@@ -5312,7 +5312,7 @@ QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); EXPECT_FALSE(framer_.ProcessPacket(encrypted)); - ASSERT_EQ(QUIC_INVALID_PUBLIC_RST_PACKET, framer_.error()); + ASSERT_THAT(framer_.error(), IsError(QUIC_INVALID_PUBLIC_RST_PACKET)); EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); } @@ -11146,7 +11146,7 @@ EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); - EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); + EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); } @@ -11179,7 +11179,7 @@ EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); - EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); + EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); } @@ -11211,7 +11211,7 @@ EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); - EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); + EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); } @@ -11615,7 +11615,7 @@ EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); - EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); + EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); } }
diff --git a/quic/core/quic_ietf_framer_test.cc b/quic/core/quic_ietf_framer_test.cc index 725eb68..e4feb47 100644 --- a/quic/core/quic_ietf_framer_test.cc +++ b/quic/core/quic_ietf_framer_test.cc
@@ -822,7 +822,7 @@ // Now check that received == sent EXPECT_EQ(sent_frame.quic_error_code, sink_frame.quic_error_code); - EXPECT_EQ(sink_frame.quic_error_code, QUIC_NO_ERROR); + EXPECT_THAT(sink_frame.quic_error_code, IsQuicNoError()); EXPECT_EQ(sink_frame.error_details, test_string); EXPECT_EQ(sink_frame.close_type, sent_frame.close_type); EXPECT_EQ(sent_frame.close_type, IETF_QUIC_TRANSPORT_CONNECTION_CLOSE);
diff --git a/quic/core/quic_stream_sequencer_buffer_test.cc b/quic/core/quic_stream_sequencer_buffer_test.cc index 028c12b..b17dcc4 100644 --- a/quic/core/quic_stream_sequencer_buffer_test.cc +++ b/quic/core/quic_stream_sequencer_buffer_test.cc
@@ -110,15 +110,15 @@ TEST_F(QuicStreamSequencerBufferTest, OnStreamData0length) { QuicErrorCode error = buffer_->OnStreamData(800, "", &written_, &error_details_); - EXPECT_EQ(error, QUIC_EMPTY_STREAM_FRAME_NO_FIN); + EXPECT_THAT(error, IsError(QUIC_EMPTY_STREAM_FRAME_NO_FIN)); EXPECT_TRUE(helper_->CheckBufferInvariants()); } TEST_F(QuicStreamSequencerBufferTest, OnStreamDataWithinBlock) { EXPECT_FALSE(helper_->IsBufferAllocated()); std::string source(1024, 'a'); - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(800, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(800, source, &written_, &error_details_), + IsQuicNoError()); BufferBlock* block_ptr = helper_->GetBlock(0); for (size_t i = 0; i < source.size(); ++i) { ASSERT_EQ('a', block_ptr->buffer[helper_->GetInBlockOffset(800) + i]); @@ -135,8 +135,8 @@ TEST_F(QuicStreamSequencerBufferTest, Move) { EXPECT_FALSE(helper_->IsBufferAllocated()); std::string source(1024, 'a'); - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(800, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(800, source, &written_, &error_details_), + IsQuicNoError()); BufferBlock* block_ptr = helper_->GetBlock(0); for (size_t i = 0; i < source.size(); ++i) { ASSERT_EQ('a', block_ptr->buffer[helper_->GetInBlockOffset(800) + i]); @@ -160,8 +160,8 @@ // Pass in an invalid source, expects to return error. QuicStringPiece source; source = QuicStringPiece(nullptr, 1024); - EXPECT_EQ(QUIC_STREAM_SEQUENCER_INVALID_STATE, - buffer_->OnStreamData(800, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(800, source, &written_, &error_details_), + IsError(QUIC_STREAM_SEQUENCER_INVALID_STATE)); EXPECT_EQ(0u, error_details_.find(QuicStrCat( "QuicStreamSequencerBuffer error: OnStreamData() " "dest == nullptr: ", @@ -171,13 +171,13 @@ TEST_F(QuicStreamSequencerBufferTest, OnStreamDataWithOverlap) { std::string source(1024, 'a'); // Write something into [800, 1824) - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(800, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(800, source, &written_, &error_details_), + IsQuicNoError()); // Try to write to [0, 1024) and [1024, 2048). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(0, source, &written_, &error_details_)); - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(1024, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(0, source, &written_, &error_details_), + IsQuicNoError()); + EXPECT_THAT(buffer_->OnStreamData(1024, source, &written_, &error_details_), + IsQuicNoError()); } TEST_F(QuicStreamSequencerBufferTest, @@ -188,31 +188,31 @@ source = std::string(800, 'b'); std::string one_byte = "c"; // Write [1, 801). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(1, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(1, source, &written_, &error_details_), + IsQuicNoError()); // Write [0, 800). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(0, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(0, source, &written_, &error_details_), + IsQuicNoError()); // Write [1823, 1824). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(1823, one_byte, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(1823, one_byte, &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(0u, written_); // write one byte to [1824, 1825) - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(1824, one_byte, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(1824, one_byte, &written_, &error_details_), + IsQuicNoError()); EXPECT_TRUE(helper_->CheckBufferInvariants()); } TEST_F(QuicStreamSequencerBufferTest, OnStreamDataWithoutOverlap) { std::string source(1024, 'a'); // Write something into [800, 1824). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(800, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(800, source, &written_, &error_details_), + IsQuicNoError()); source = std::string(100, 'b'); // Write something into [kBlockSizeBytes * 2 - 20, kBlockSizeBytes * 2 + 80). - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(kBlockSizeBytes * 2 - 20, source, &written_, - &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(kBlockSizeBytes * 2 - 20, source, &written_, + &error_details_), + IsQuicNoError()); EXPECT_EQ(3, helper_->IntervalSize()); EXPECT_EQ(1024u + 100u, buffer_->BytesBuffered()); EXPECT_TRUE(helper_->CheckBufferInvariants()); @@ -229,20 +229,20 @@ std::string source(kBytesToWrite, 'a'); // Frame [2^32 + 500, 2^32 + 600). QuicStreamOffset offset = pow(2, 32) + 500; - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(offset, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(offset, source, &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(2, helper_->IntervalSize()); // Frame [2^32 + 700, 2^32 + 800). offset = pow(2, 32) + 700; - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(offset, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(offset, source, &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(3, helper_->IntervalSize()); // Another frame [2^32 + 300, 2^32 + 400). offset = pow(2, 32) + 300; - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(offset, source, &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(offset, source, &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(4, helper_->IntervalSize()); } @@ -250,9 +250,9 @@ // Write 50 bytes to the end. const size_t kBytesToWrite = 50; std::string source(kBytesToWrite, 'a'); - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(max_capacity_bytes_ - kBytesToWrite, source, - &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(max_capacity_bytes_ - kBytesToWrite, source, + &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(50u, buffer_->BytesBuffered()); EXPECT_TRUE(helper_->CheckBufferInvariants()); } @@ -261,42 +261,42 @@ // Write 1 byte to the end. const size_t kBytesToWrite = 1; std::string source(kBytesToWrite, 'a'); - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->OnStreamData(max_capacity_bytes_ - kBytesToWrite, source, - &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(max_capacity_bytes_ - kBytesToWrite, source, + &written_, &error_details_), + IsQuicNoError()); EXPECT_EQ(1u, buffer_->BytesBuffered()); EXPECT_TRUE(helper_->CheckBufferInvariants()); } TEST_F(QuicStreamSequencerBufferTest, OnStreamDataBeyondCapacity) { std::string source(60, 'a'); - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(max_capacity_bytes_ - 50, source, &written_, - &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(max_capacity_bytes_ - 50, source, &written_, + &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); source = "b"; - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(max_capacity_bytes_, source, &written_, - &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(max_capacity_bytes_, source, &written_, + &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(max_capacity_bytes_ * 1000, source, &written_, - &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(max_capacity_bytes_ * 1000, source, + &written_, &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); // Disallow current_gap != gaps_.end() - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(static_cast<QuicStreamOffset>(-1), source, - &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(static_cast<QuicStreamOffset>(-1), source, + &written_, &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); // Disallow offset + size overflow source = "bbb"; - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(static_cast<QuicStreamOffset>(-2), source, - &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(static_cast<QuicStreamOffset>(-2), source, + &written_, &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); EXPECT_EQ(0u, buffer_->BytesBuffered()); } @@ -314,7 +314,8 @@ char dest[120]; iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(iovecs, 3, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(iovecs, 3, &read, &error_details_), + IsQuicNoError()); QUIC_LOG(ERROR) << error_details_; EXPECT_EQ(100u, read); EXPECT_EQ(100u, buffer_->BytesConsumed()); @@ -335,7 +336,8 @@ std::fill(dest, dest + 512, 0); iovec iovecs[2]{iovec{dest, 256}, iovec{dest + 256, 256}}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(iovecs, 2, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(iovecs, 2, &read, &error_details_), + IsQuicNoError()); } // The last read only reads the rest 50 bytes in 2nd block. EXPECT_EQ(std::string(50, 'a'), std::string(dest, 50)); @@ -353,7 +355,7 @@ char dest[512]{0}; const iovec iov{dest, 512}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov, 1, &read, &error_details_), IsQuicNoError()); // Clear() should make buffer empty while preserving BytesConsumed() buffer_->Clear(); EXPECT_TRUE(buffer_->Empty()); @@ -369,14 +371,15 @@ char dest[512]{0}; const iovec iov{dest, 512}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov, 1, &read, &error_details_), IsQuicNoError()); EXPECT_EQ(source.size(), written_); // Write more than half block size of bytes in the last block with 'b', which // will wrap to the beginning and reaches the full capacity. source = std::string(0.5 * kBlockSizeBytes + 512, 'b'); - EXPECT_EQ(QUIC_NO_ERROR, buffer_->OnStreamData(2 * kBlockSizeBytes, source, - &written_, &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(2 * kBlockSizeBytes, source, &written_, + &error_details_), + IsQuicNoError()); EXPECT_EQ(source.size(), written_); EXPECT_TRUE(helper_->CheckBufferInvariants()); } @@ -390,14 +393,14 @@ char dest[512]{0}; const iovec iov{dest, 512}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov, 1, &read, &error_details_), IsQuicNoError()); // Try to write from [max_capacity_bytes_ - 0.5 * kBlockSizeBytes, // max_capacity_bytes_ + 512 + 1). But last bytes exceeds current capacity. source = std::string(0.5 * kBlockSizeBytes + 512 + 1, 'b'); - EXPECT_EQ(QUIC_INTERNAL_ERROR, - buffer_->OnStreamData(2 * kBlockSizeBytes, source, &written_, - &error_details_)); + EXPECT_THAT(buffer_->OnStreamData(2 * kBlockSizeBytes, source, &written_, + &error_details_), + IsError(QUIC_INTERNAL_ERROR)); EXPECT_TRUE(helper_->CheckBufferInvariants()); } @@ -409,7 +412,7 @@ char dest[512]{0}; const iovec iov{dest, 512}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov, 1, &read, &error_details_), IsQuicNoError()); source = std::string(256, 'b'); buffer_->OnStreamData(max_capacity_bytes_, source, &written_, &error_details_); @@ -419,7 +422,8 @@ std::unique_ptr<char[]> dest1{new char[max_capacity_bytes_]}; dest1[0] = 0; const iovec iov1{dest1.get(), max_capacity_bytes_}; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov1, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov1, 1, &read, &error_details_), + IsQuicNoError()); EXPECT_EQ(max_capacity_bytes_ - 512 + 256, read); EXPECT_EQ(max_capacity_bytes_ + 256, buffer_->BytesConsumed()); EXPECT_TRUE(buffer_->Empty()); @@ -430,7 +434,7 @@ char dest[512]{0}; iovec iov{dest, 512}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(&iov, 1, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(&iov, 1, &read, &error_details_), IsQuicNoError()); EXPECT_EQ(0u, read); EXPECT_TRUE(helper_->CheckBufferInvariants()); } @@ -452,7 +456,8 @@ char dest[120]; iovec iovecs[3]{iovec{dest, 40}, iovec{dest + 40, 40}, iovec{dest + 80, 40}}; size_t read; - EXPECT_EQ(QUIC_NO_ERROR, buffer_->Readv(iovecs, 3, &read, &error_details_)); + EXPECT_THAT(buffer_->Readv(iovecs, 3, &read, &error_details_), + IsQuicNoError()); EXPECT_EQ(100u, read); EXPECT_EQ(100u, buffer_->BytesConsumed()); EXPECT_TRUE(helper_->CheckBufferInvariants()); @@ -847,7 +852,7 @@ QuicStreamOffset last_straw = 2 * kMaxNumGapsAllowed - 1; if (begin == last_straw) { - EXPECT_EQ(QUIC_TOO_MANY_STREAM_DATA_INTERVALS, rs); + EXPECT_THAT(rs, IsError(QUIC_TOO_MANY_STREAM_DATA_INTERVALS)); EXPECT_EQ("Too many data intervals received for this stream.", error_details_); break; @@ -982,9 +987,9 @@ num_to_read += dest_iov[i].iov_len; } size_t actually_read; - EXPECT_EQ(QUIC_NO_ERROR, - buffer_->Readv(dest_iov, kNumReads, &actually_read, - &error_details_)); + EXPECT_THAT(buffer_->Readv(dest_iov, kNumReads, &actually_read, + &error_details_), + IsQuicNoError()); ASSERT_LE(actually_read, num_to_read); QUIC_DVLOG(1) << " read from offset: " << total_bytes_read_ << " size: " << num_to_read