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/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"
16 static const int kMaxDeltaStoredMs = 500;
17 static const base::TimeDelta kDeltaBetweenFrames =
18 base::TimeDelta::FromMilliseconds(33);
20 static const int64 kStartMillisecond = GG_INT64_C(12345678900000);
22 class PacketStorageTest : public ::testing::Test {
24 PacketStorageTest() : packet_storage_(&testing_clock_, kMaxDeltaStoredMs) {
25 testing_clock_.Advance(
26 base::TimeDelta::FromMilliseconds(kStartMillisecond));
29 base::SimpleTestTickClock testing_clock_;
30 PacketStorage packet_storage_;
33 TEST_F(PacketStorageTest, TimeOut) {
34 Packet test_123(100, 123); // 100 insertions of the value 123.
36 for (uint8 frame_id = 0; frame_id < 30; ++frame_id) {
37 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
38 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
40 testing_clock_.Advance(kDeltaBetweenFrames);
43 // All packets belonging to the first 14 frames is expected to be expired.
44 for (uint8 frame_id = 0; frame_id < 14; ++frame_id) {
45 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
47 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
50 // All packets belonging to the next 15 frames is expected to be valid.
51 for (uint8 frame_id = 14; frame_id < 30; ++frame_id) {
52 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
53 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
54 EXPECT_TRUE(packets.front() == test_123);
59 TEST_F(PacketStorageTest, MaxNumberOfPackets) {
60 Packet test_123(100, 123); // 100 insertions of the value 123.
64 for (uint16 packet_id = 0; packet_id <= PacketStorage::kMaxStoredPackets;
66 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
70 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
73 for (; packet_id <= PacketStorage::kMaxStoredPackets; ++packet_id) {
74 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
75 EXPECT_TRUE(packets.back() == test_123);
79 TEST_F(PacketStorageTest, PacketContent) {
80 Packet test_123(100, 123); // 100 insertions of the value 123.
81 Packet test_234(200, 234); // 200 insertions of the value 234.
84 for (uint8 frame_id = 0; frame_id < 10; ++frame_id) {
85 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
86 // Every other packet.
87 if (packet_id % 2 == 0) {
88 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
90 packet_storage_.StorePacket(frame_id, packet_id, &test_234);
93 testing_clock_.Advance(kDeltaBetweenFrames);
95 for (uint8 frame_id = 0; frame_id < 10; ++frame_id) {
96 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
97 EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
98 // Every other packet.
99 if (packet_id % 2 == 0) {
100 EXPECT_TRUE(packets.back() == test_123);
102 EXPECT_TRUE(packets.back() == test_234);