1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/cast/rtp_sender/packet_storage/packet_storage.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <vector>
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
namespace media {
namespace cast {
static const int kMaxDeltaStoredMs = 500;
static const base::TimeDelta kDeltaBetweenFrames =
base::TimeDelta::FromMilliseconds(33);
static const int64 kStartMillisecond = 123456789;
class PacketStorageTest : public ::testing::Test {
protected:
PacketStorageTest() : packet_storage_(kMaxDeltaStoredMs) {
testing_clock_.Advance(
base::TimeDelta::FromMilliseconds(kStartMillisecond));
packet_storage_.set_clock(&testing_clock_);
}
PacketStorage packet_storage_;
base::SimpleTestTickClock testing_clock_;
};
TEST_F(PacketStorageTest, TimeOut) {
std::vector<uint8> test_123(100, 123); // 100 insertions of the value 123.
for (uint8 frame_id = 0; frame_id < 30; ++frame_id) {
for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
packet_storage_.StorePacket(frame_id, packet_id, test_123);
}
testing_clock_.Advance(kDeltaBetweenFrames);
}
// All packets belonging to the first 14 frames is expected to be expired.
for (uint8 frame_id = 0; frame_id < 14; ++frame_id) {
for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
std::vector<uint8> packet;
EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packet));
}
}
// All packets belonging to the next 15 frames is expected to be valid.
for (uint8 frame_id = 14; frame_id < 30; ++frame_id) {
for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
std::vector<uint8> packet;
EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packet));
EXPECT_TRUE(packet == test_123);
}
}
}
TEST_F(PacketStorageTest, MaxNumberOfPackets) {
std::vector<uint8> test_123(100, 123); // 100 insertions of the value 123.
uint8 frame_id = 0;
for (uint16 packet_id = 0; packet_id <= PacketStorage::kMaxStoredPackets;
++packet_id) {
packet_storage_.StorePacket(frame_id, packet_id, test_123);
}
std::vector<uint8> packet;
uint16 packet_id = 0;
EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packet));
++packet_id;
for (; packet_id <= PacketStorage::kMaxStoredPackets; ++packet_id) {
std::vector<uint8> packet;
EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packet));
EXPECT_TRUE(packet == test_123);
}
}
TEST_F(PacketStorageTest, PacketContent) {
std::vector<uint8> test_123(100, 123); // 100 insertions of the value 123.
std::vector<uint8> test_234(200, 234); // 200 insertions of the value 234.
for (uint8 frame_id = 0; frame_id < 10; ++frame_id) {
for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
// Every other packet.
if (packet_id % 2 == 0) {
packet_storage_.StorePacket(frame_id, packet_id, test_123);
} else {
packet_storage_.StorePacket(frame_id, packet_id, test_234);
}
}
testing_clock_.Advance(kDeltaBetweenFrames);
}
for (uint8 frame_id = 0; frame_id < 10; ++frame_id) {
for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
std::vector<uint8> packet;
EXPECT_TRUE(packet_storage_.GetPacket(frame_id, packet_id, &packet));
// Every other packet.
if (packet_id % 2 == 0) {
EXPECT_TRUE(packet == test_123);
} else {
EXPECT_TRUE(packet == test_234);
}
}
}
}
} // namespace cast
} // namespace media
|