Implement EXPECT_THAT(QuicHeaderList, ElementsAre()). When trying to use the EXPECT_THAT(QuicHeaderList, ElementsAre()) idiom, gMock complained about QuicHeaderList::value_type not being defined. This CL defines QuicHeaderList::value_type and uses this idiom in a few tests. gfe-relnote: n/a. Test-only change. PiperOrigin-RevId: 243788793 Change-Id: Ia7816e85c5215e545ac0909609fbdef335361efc
diff --git a/quic/core/http/quic_header_list.h b/quic/core/http/quic_header_list.h index 5d5c2a4..cc6e7bc 100644 --- a/quic/core/http/quic_header_list.h +++ b/quic/core/http/quic_header_list.h
@@ -23,8 +23,9 @@ class QUIC_EXPORT_PRIVATE QuicHeaderList : public spdy::SpdyHeadersHandlerInterface { public: - typedef QuicDeque<std::pair<std::string, std::string>> ListType; - typedef ListType::const_iterator const_iterator; + using ListType = QuicDeque<std::pair<std::string, std::string>>; + using value_type = ListType::value_type; + using const_iterator = ListType::const_iterator; QuicHeaderList(); QuicHeaderList(QuicHeaderList&& other);
diff --git a/quic/core/http/quic_header_list_test.cc b/quic/core/http/quic_header_list_test.cc index a50396e..67bd35f 100644 --- a/quic/core/http/quic_header_list_test.cc +++ b/quic/core/http/quic_header_list_test.cc
@@ -9,6 +9,9 @@ #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" +using ::testing::ElementsAre; +using ::testing::Pair; + namespace quic { class QuicHeaderListTest : public QuicTest {}; @@ -20,6 +23,16 @@ headers.OnHeader("april", "fools"); headers.OnHeader("beep", ""); + EXPECT_THAT(headers, ElementsAre(Pair("foo", "bar"), Pair("april", "fools"), + Pair("beep", ""))); +} + +TEST_F(QuicHeaderListTest, DebugString) { + QuicHeaderList headers; + headers.OnHeader("foo", "bar"); + headers.OnHeader("april", "fools"); + headers.OnHeader("beep", ""); + EXPECT_EQ("{ foo=bar, april=fools, beep=, }", headers.DebugString()); } @@ -61,8 +74,10 @@ QuicHeaderList headers2(headers); QuicHeaderList headers3 = headers; - EXPECT_EQ("{ foo=bar, april=fools, beep=, }", headers2.DebugString()); - EXPECT_EQ("{ foo=bar, april=fools, beep=, }", headers3.DebugString()); + EXPECT_THAT(headers2, ElementsAre(Pair("foo", "bar"), Pair("april", "fools"), + Pair("beep", ""))); + EXPECT_THAT(headers3, ElementsAre(Pair("foo", "bar"), Pair("april", "fools"), + Pair("beep", ""))); } } // namespace quic
diff --git a/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc b/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc index 27c6fa1..eb6f622 100644 --- a/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc +++ b/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc
@@ -11,7 +11,9 @@ #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" #include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h" +using ::testing::ElementsAre; using ::testing::Eq; +using ::testing::Pair; using ::testing::StrictMock; namespace quic { @@ -83,13 +85,8 @@ EXPECT_TRUE(accumulator_.Decode(encoded_data)); EXPECT_TRUE(accumulator_.EndHeaderBlock()); - auto header_list = accumulator_.quic_header_list(); - auto it = header_list.begin(); - EXPECT_TRUE(it != header_list.end()); - EXPECT_EQ("foo", it->first); - EXPECT_EQ("bar", it->second); - ++it; - EXPECT_TRUE(it == header_list.end()); + const QuicHeaderList& header_list = accumulator_.quic_header_list(); + EXPECT_THAT(header_list, ElementsAre(Pair("foo", "bar"))); EXPECT_EQ(strlen("foo") + strlen("bar"), header_list.uncompressed_header_bytes());