Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: media/cast/rtp_sender/packet_storage/packet_storage_unittest.cc

Issue 112133002: Cast:Moving netwrok sender related code to a designated folder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moving const' to .cc Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "media/cast/rtp_sender/packet_storage/packet_storage.h"
6
7 #include <vector>
8
9 #include "base/test/simple_test_tick_clock.h"
10 #include "base/time/time.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12
13 namespace media {
14 namespace cast {
15
16 static const int kMaxDeltaStoredMs = 500;
17 static const base::TimeDelta kDeltaBetweenFrames =
18 base::TimeDelta::FromMilliseconds(33);
19
20 static const int64 kStartMillisecond = GG_INT64_C(12345678900000);
21
22 class PacketStorageTest : public ::testing::Test {
23 protected:
24 PacketStorageTest() : packet_storage_(&testing_clock_, kMaxDeltaStoredMs) {
25 testing_clock_.Advance(
26 base::TimeDelta::FromMilliseconds(kStartMillisecond));
27 }
28
29 base::SimpleTestTickClock testing_clock_;
30 PacketStorage packet_storage_;
31 };
32
33 TEST_F(PacketStorageTest, TimeOut) {
34 Packet test_123(100, 123); // 100 insertions of the value 123.
35 PacketList packets;
36 for (uint32 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);
39 }
40 testing_clock_.Advance(kDeltaBetweenFrames);
41 }
42
43 // All packets belonging to the first 14 frames is expected to be expired.
44 for (uint32 frame_id = 0; frame_id < 14; ++frame_id) {
45 for (uint16 packet_id = 0; packet_id < 10; ++packet_id) {
46 Packet packet;
47 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
48 }
49 }
50 // All packets belonging to the next 15 frames is expected to be valid.
51 for (uint32 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);
55 }
56 }
57 }
58
59 TEST_F(PacketStorageTest, MaxNumberOfPackets) {
60 Packet test_123(100, 123); // 100 insertions of the value 123.
61 PacketList packets;
62
63 uint32 frame_id = 0;
64 for (uint16 packet_id = 0; packet_id <= PacketStorage::kMaxStoredPackets;
65 ++packet_id) {
66 packet_storage_.StorePacket(frame_id, packet_id, &test_123);
67 }
68 Packet packet;
69 uint16 packet_id = 0;
70 EXPECT_FALSE(packet_storage_.GetPacket(frame_id, packet_id, &packets));
71
72 ++packet_id;
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);
76 }
77 }
78
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.
82 PacketList packets;
83
84 for (uint32 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);
89 } else {
90 packet_storage_.StorePacket(frame_id, packet_id, &test_234);
91 }
92 }
93 testing_clock_.Advance(kDeltaBetweenFrames);
94 }
95 for (uint32 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);
101 } else {
102 EXPECT_TRUE(packets.back() == test_234);
103 }
104 }
105 }
106 }
107
108 } // namespace cast
109 } // namespace media
110
OLDNEW
« no previous file with comments | « media/cast/rtp_sender/packet_storage/packet_storage.gyp ('k') | media/cast/rtp_sender/rtp_packetizer/rtp_packetizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698