Chromium Code Reviews| Index: webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc |
| diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc |
| index 82f7246cc7bf0918a5c582d53cac439a2b2d568c..2dd1382f037d3c0edb07d2085053afd23ed67e71 100644 |
| --- a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc |
| +++ b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc |
| @@ -22,6 +22,8 @@ |
| using ::testing::Return; |
| using ::testing::StrictMock; |
| using ::testing::_; |
| +using ::testing::InSequence; |
| +using ::testing::MockFunction; |
| namespace webrtc { |
| @@ -314,26 +316,39 @@ TEST(PacketBuffer, DiscardPackets) { |
| // Discard them one by one and make sure that the right packets are at the |
| // front of the buffer. |
| constexpr int kDiscardPackets = 5; |
| + |
| + // Interleaving the EXPECT_CALL sequence with expectations on the MockFunction |
| + // check ensures that exactly one call to PacketsDiscarded happens in each |
| + // DiscardNextPacket call. |
|
minyue-webrtc
2017/07/05 12:11:08
nice, another way would be avoid the for-loop. It
hlundin-webrtc
2017/07/05 13:42:35
True. But I still think I would like to have the I
|
| + InSequence s; |
| + MockFunction<void(int check_point_id)> check; |
| for (int i = 0; i < kDiscardPackets; ++i) { |
| uint32_t ts; |
| EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); |
| EXPECT_EQ(current_ts, ts); |
| - EXPECT_CALL(mock_stats, PacketsDiscarded(1)).Times(1); |
| + EXPECT_CALL(mock_stats, PacketsDiscarded(1)); |
| + EXPECT_CALL(check, Call(i)); |
|
minyue-webrtc
2017/07/05 12:11:08
why not arbitrary number
hlundin-webrtc
2017/07/05 13:42:35
Indexing the calls to the check function makes the
|
| EXPECT_EQ(PacketBuffer::kOK, buffer.DiscardNextPacket(&mock_stats)); |
| current_ts += ts_increment; |
| + check.Call(i); |
| } |
| constexpr int kRemainingPackets = kTotalPackets - kDiscardPackets; |
| - // This will not discard any packets because the oldest packet is newer than |
| - // the indicated horizon_samples. |
| + // This will all remaining packets but one. The oldest packet is older than |
|
minyue-webrtc
2017/07/05 12:11:08
This will "discard" all remaining ...
hlundin-webrtc
2017/07/05 13:42:35
Done.
|
| + // the indicated horizon_samples, and will thus be left in the buffer. |
| + EXPECT_CALL(mock_stats, PacketsDiscarded(kRemainingPackets - 1)); |
|
minyue-webrtc
2017/07/05 12:11:08
define 1 as kSkipPackets
hlundin-webrtc
2017/07/05 13:42:35
Done.
|
| + EXPECT_CALL(check, Call(17)); // Arbitrary id number. |
| buffer.DiscardOldPackets(start_ts + kTotalPackets * ts_increment, |
| kRemainingPackets * ts_increment, &mock_stats); |
| + check.Call(17); // Same arbitrary id number. |
| + |
| + EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
| uint32_t ts; |
| EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); |
| EXPECT_EQ(current_ts, ts); |
| // Discard all remaining packets. |
| - EXPECT_CALL(mock_stats, PacketsDiscarded(1)).Times(kRemainingPackets); |
| + EXPECT_CALL(mock_stats, PacketsDiscarded(1)); |
| buffer.DiscardAllOldPackets(start_ts + kTotalPackets * ts_increment, |
| &mock_stats); |