Use IsStreamError() and friends gMock matchers in quic/core/crypto. gfe-relnote: n/a, test-only change. PiperOrigin-RevId: 284003398 Change-Id: I27ee2d63d0b0d0a12c206dcb9ecaf4935468b3eb
diff --git a/quic/core/crypto/crypto_framer_test.cc b/quic/core/crypto/crypto_framer_test.cc index 4ca98a5..d54de07 100644 --- a/quic/core/crypto/crypto_framer_test.cc +++ b/quic/core/crypto/crypto_framer_test.cc
@@ -380,7 +380,7 @@ EXPECT_FALSE(framer.ProcessInput( QuicStringPiece(AsChars(input), QUIC_ARRAYSIZE(input)))); - EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error()); + EXPECT_THAT(framer.error(), IsError(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); EXPECT_EQ(1, visitor.error_count_); } @@ -408,7 +408,7 @@ EXPECT_FALSE(framer.ProcessInput( QuicStringPiece(AsChars(input), QUIC_ARRAYSIZE(input)))); - EXPECT_EQ(QUIC_CRYPTO_TAGS_OUT_OF_ORDER, framer.error()); + EXPECT_THAT(framer.error(), IsError(QUIC_CRYPTO_TAGS_OUT_OF_ORDER)); EXPECT_EQ(1, visitor.error_count_); } @@ -428,7 +428,7 @@ EXPECT_FALSE(framer.ProcessInput( QuicStringPiece(AsChars(input), QUIC_ARRAYSIZE(input)))); - EXPECT_EQ(QUIC_CRYPTO_TOO_MANY_ENTRIES, framer.error()); + EXPECT_THAT(framer.error(), IsError(QUIC_CRYPTO_TOO_MANY_ENTRIES)); EXPECT_EQ(1, visitor.error_count_); }
diff --git a/quic/core/crypto/crypto_server_test.cc b/quic/core/crypto/crypto_server_test.cc index 2db49d2..a3cbbf4 100644 --- a/quic/core/crypto/crypto_server_test.cc +++ b/quic/core/crypto/crypto_server_test.cc
@@ -324,7 +324,7 @@ QuicTagVector reject_reasons; static_assert(sizeof(QuicTag) == sizeof(uint32_t), "header out of sync"); QuicErrorCode error_code = out_.GetTaglist(kRREJ, &reject_reasons); - ASSERT_EQ(QUIC_NO_ERROR, error_code); + ASSERT_THAT(error_code, IsQuicNoError()); EXPECT_EQ(expected_count, reject_reasons.size()); for (size_t i = 0; i < reject_reasons.size(); ++i) {
diff --git a/quic/core/crypto/quic_crypto_client_config_test.cc b/quic/core/crypto/quic_crypto_client_config_test.cc index 8b5f116..acf26d6 100644 --- a/quic/core/crypto/quic_crypto_client_config_test.cc +++ b/quic/core/crypto/quic_crypto_client_config_test.cc
@@ -186,7 +186,7 @@ /* demand_x509_proof= */ true, params, &msg); QuicVersionLabel cver; - EXPECT_EQ(QUIC_NO_ERROR, msg.GetVersionLabel(kVER, &cver)); + EXPECT_THAT(msg.GetVersionLabel(kVER, &cver), IsQuicNoError()); EXPECT_EQ(CreateQuicVersionLabel(QuicVersionMax()), cver); QuicStringPiece proof_nonce; EXPECT_TRUE(msg.GetStringPiece(kNONP, &proof_nonce)); @@ -241,7 +241,7 @@ /* demand_x509_proof= */ true, params, &msg); QuicTag pdmd; - EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kPDMD, &pdmd)); + EXPECT_THAT(msg.GetUint32(kPDMD, &pdmd), IsQuicNoError()); EXPECT_EQ(kX509, pdmd); QuicStringPiece scid; EXPECT_FALSE(msg.GetStringPiece(kSCID, &scid)); @@ -316,7 +316,7 @@ // Verify that the version label has been set correctly in the CHLO. QuicVersionLabel cver; - EXPECT_EQ(QUIC_NO_ERROR, chlo.GetVersionLabel(kVER, &cver)); + EXPECT_THAT(chlo.GetVersionLabel(kVER, &cver), IsQuicNoError()); EXPECT_EQ(CreateQuicVersionLabel(QuicVersionMax()), cver); } @@ -337,7 +337,7 @@ // Verify that the version label has been set correctly in the CHLO. QuicVersionLabel cver; - EXPECT_EQ(QUIC_NO_ERROR, chlo.GetVersionLabel(kVER, &cver)); + EXPECT_THAT(chlo.GetVersionLabel(kVER, &cver), IsQuicNoError()); EXPECT_EQ(CreateQuicVersionLabel(QuicVersionMax()), cver); EXPECT_EQ(chlo.minimum_size(), 1u); } @@ -363,10 +363,10 @@ new QuicCryptoNegotiatedParameters); std::string error; QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting()); - EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, - config.ProcessServerHello( - msg, EmptyQuicConnectionId(), supported_versions.front(), - supported_versions, &cached, out_params, &error)); + EXPECT_THAT(config.ProcessServerHello( + msg, EmptyQuicConnectionId(), supported_versions.front(), + supported_versions, &cached, out_params, &error), + IsError(QUIC_VERSION_NEGOTIATION_MISMATCH)); EXPECT_THAT(error, StartsWith("Downgrade attack detected: ServerVersions")); } @@ -526,10 +526,10 @@ new QuicCryptoNegotiatedParameters); std::string error; QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting()); - EXPECT_EQ(QUIC_NO_ERROR, - config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0), - AllSupportedTransportVersions().front(), "", - &cached, out_params, &error)); + EXPECT_THAT(config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0), + AllSupportedTransportVersions().front(), + "", &cached, out_params, &error), + IsQuicNoError()); EXPECT_FALSE(cached.has_server_designated_connection_id()); EXPECT_FALSE(cached.has_server_nonce()); } @@ -547,10 +547,10 @@ new QuicCryptoNegotiatedParameters); std::string error; QuicCryptoClientConfig config(crypto_test_utils::ProofVerifierForTesting()); - EXPECT_EQ(QUIC_NO_ERROR, - config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0), - AllSupportedTransportVersions().front(), "", - &cached, out_params, &error)); + EXPECT_THAT(config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0), + AllSupportedTransportVersions().front(), + "", &cached, out_params, &error), + IsQuicNoError()); cached.SetProofValid(); EXPECT_FALSE(cached.IsComplete(QuicWallTime::FromUNIXSeconds(long_ttl))); EXPECT_FALSE( @@ -574,10 +574,10 @@ QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> out_params( new QuicCryptoNegotiatedParameters); std::string error_details; - EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, - config.ProcessServerHello(msg, EmptyQuicConnectionId(), version, - supported_versions, &cached, out_params, - &error_details)); + EXPECT_THAT(config.ProcessServerHello(msg, EmptyQuicConnectionId(), version, + supported_versions, &cached, out_params, + &error_details), + IsError(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER)); EXPECT_EQ("server hello missing server nonce", error_details); }
diff --git a/quic/core/crypto/quic_crypto_server_config_test.cc b/quic/core/crypto/quic_crypto_server_config_test.cc index 8f9e4ba..ce47d24 100644 --- a/quic/core/crypto/quic_crypto_server_config_test.cc +++ b/quic/core/crypto/quic_crypto_server_config_test.cc
@@ -22,6 +22,7 @@ #include "net/third_party/quiche/src/quic/test_tools/crypto_test_utils.h" #include "net/third_party/quiche/src/quic/test_tools/mock_clock.h" #include "net/third_party/quiche/src/quic/test_tools/quic_crypto_server_config_peer.h" +#include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" namespace quic { namespace test { @@ -52,7 +53,7 @@ // The default configuration should have AES-GCM and at least one ChaCha20 // cipher. QuicTagVector aead; - ASSERT_EQ(QUIC_NO_ERROR, message->GetTaglist(kAEAD, &aead)); + ASSERT_THAT(message->GetTaglist(kAEAD, &aead), IsQuicNoError()); EXPECT_THAT(aead, ::testing::Contains(kAESG)); EXPECT_LE(1u, aead.size()); }
diff --git a/quic/core/crypto/transport_parameters_test.cc b/quic/core/crypto/transport_parameters_test.cc index 61a6e0d..8fa7a0b 100644 --- a/quic/core/crypto/transport_parameters_test.cc +++ b/quic/core/crypto/transport_parameters_test.cc
@@ -648,8 +648,8 @@ EXPECT_TRUE(new_params.google_quic_params->GetStringPiece(42, &test_string)); EXPECT_EQ(test_string, kTestString); uint32_t test_value; - EXPECT_EQ(new_params.google_quic_params->GetUint32(1337, &test_value), - QUIC_NO_ERROR); + EXPECT_THAT(new_params.google_quic_params->GetUint32(1337, &test_value), + IsQuicNoError()); EXPECT_EQ(test_value, kTestValue); EXPECT_EQ(kFakeVersionLabel, new_params.version); EXPECT_EQ(kFakeMaxPacketSize, new_params.max_packet_size.value());