1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/transport/rtp_sender/packet_storage/packet_storage.h"
9 #include "base/test/simple_test_tick_clock.h"
10 #include "base/time/time.h"
11 #include "testing/gmock/include/gmock/gmock.h"
17 static const int kMaxDeltaStoredMs = 500;
18 static const base::TimeDelta kDeltaBetweenFrames =
19 base::TimeDelta::FromMilliseconds(33);
21 static const int64 kStartMillisecond = GG_INT64_C(12345678900000);
23 class PacketStorageTest : public ::testing::Test {
25 PacketStorageTest() : packet_storage_(&testing_clock_, kMaxDeltaStoredMs) {
26 testing_clock_.Advance(
27 base::TimeDelta::FromMilliseconds(kStartMillisecond));
30 base::SimpleTestTickClock testing_clock_;
31 PacketStorage packet_storage_;
33 DISALLOW_COPY_AND_ASSIGN(PacketStorageTest);
36 TEST_F(PacketStorageTest, TimeOut) {
37 Packet test_123(100, 123); // 100 insertions of the value 123.
39 for (uint32 frame_id = 0; frame_id < 30; ++frame_id) {
40 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
41 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
43 testing_clock_.Advance(kDeltaBetweenFrames);
46 // All packets belonging to the first 14 frames is expected to be expired.
47 for (uint32 frame_id = 0; frame_id < 14; ++frame_id) {
48 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
50 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
53 // All packets belonging to the next 15 frames is expected to be valid.
54 for (uint32 frame_id = 14; frame_id < 30; ++frame_id) {
55 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
56 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
57 EXPECT_TRUE(packets.front() == test_123);
62 TEST_F(PacketStorageTest, MaxNumberOfPackets) {
63 Packet test_123(100, 123); // 100 insertions of the value 123.
67 for (uint16 packet_id = 0; packet_id <= PacketStorage::kMaxStoredPackets;
69 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
73 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
76 for (; packet_id <= PacketStorage::kMaxStoredPackets; ++packet_id) {
77 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
78 EXPECT_TRUE(packets.back() == test_123);
82 TEST_F(PacketStorageTest, PacketContent) {
83 Packet test_123(100, 123); // 100 insertions of the value 123.
84 Packet test_234(200, 234); // 200 insertions of the value 234.
87 for (uint32 frame_id = 0; frame_id < 10; ++frame_id) {
88 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
89 // Every other packet.
90 if (packet_id % 2 == 0) {
91 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
93 packet_storage_.StorePacket(frame_id, packet_id, &test_234);
96 testing_clock_.Advance(kDeltaBetweenFrames);
98 for (uint32 frame_id = 0; frame_id < 10; ++frame_id) {
99 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
100 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
101 // Every other packet.
102 if (packet_id % 2 == 0) {
103 EXPECT_TRUE(packets.back() == test_123);
105 EXPECT_TRUE(packets.back() == test_234);
111 } // namespace transport