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

Side by Side Diff: media/cast/net/rtp/packet_storage_unittest.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/net/rtp/packet_storage.h" 5 #include "media/cast/net/rtp/packet_storage.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/test/simple_test_tick_clock.h" 12 #include "base/test/simple_test_tick_clock.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "media/cast/constants.h" 14 #include "media/cast/constants.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 16
17 namespace media { 17 namespace media {
18 namespace cast { 18 namespace cast {
19 19
20 static const size_t kStoredFrames = 10; 20 static const size_t kStoredFrames = 10;
21 21
22 // Generate |number_of_frames| and store into |*storage|. 22 // Generate |number_of_frames| and store into |*storage|.
23 // First frame has 1 packet, second frame has 2 packets, etc. 23 // First frame has 1 packet, second frame has 2 packets, etc.
24 static void StoreFrames(size_t number_of_frames, 24 static void StoreFrames(size_t number_of_frames,
25 uint32 first_frame_id, 25 uint32_t first_frame_id,
26 PacketStorage* storage) { 26 PacketStorage* storage) {
27 const int kSsrc = 1; 27 const int kSsrc = 1;
28 for (size_t i = 0; i < number_of_frames; ++i) { 28 for (size_t i = 0; i < number_of_frames; ++i) {
29 SendPacketVector packets; 29 SendPacketVector packets;
30 // First frame has 1 packet, second frame has 2 packets, etc. 30 // First frame has 1 packet, second frame has 2 packets, etc.
31 const size_t kNumberOfPackets = i + 1; 31 const size_t kNumberOfPackets = i + 1;
32 for (size_t j = 0; j < kNumberOfPackets; ++j) { 32 for (size_t j = 0; j < kNumberOfPackets; ++j) {
33 Packet test_packet(1, 0); 33 Packet test_packet(1, 0);
34 packets.push_back(std::make_pair( 34 packets.push_back(std::make_pair(
35 PacedPacketSender::MakePacketKey(PacketKey::RTP, i, kSsrc, 35 PacedPacketSender::MakePacketKey(PacketKey::RTP, i, kSsrc,
36 base::checked_cast<uint16>(j)), 36 base::checked_cast<uint16_t>(j)),
37 new base::RefCountedData<Packet>(test_packet))); 37 new base::RefCountedData<Packet>(test_packet)));
38 } 38 }
39 storage->StoreFrame(first_frame_id, packets); 39 storage->StoreFrame(first_frame_id, packets);
40 ++first_frame_id; 40 ++first_frame_id;
41 } 41 }
42 } 42 }
43 43
44 TEST(PacketStorageTest, NumberOfStoredFrames) { 44 TEST(PacketStorageTest, NumberOfStoredFrames) {
45 PacketStorage storage; 45 PacketStorage storage;
46 46
47 uint32 frame_id = 0; 47 uint32_t frame_id = 0;
48 frame_id = ~frame_id; // The maximum value of uint32. 48 frame_id = ~frame_id; // The maximum value of uint32_t.
49 StoreFrames(kMaxUnackedFrames / 2, frame_id, &storage); 49 StoreFrames(kMaxUnackedFrames / 2, frame_id, &storage);
50 EXPECT_EQ(static_cast<size_t>(kMaxUnackedFrames / 2), 50 EXPECT_EQ(static_cast<size_t>(kMaxUnackedFrames / 2),
51 storage.GetNumberOfStoredFrames()); 51 storage.GetNumberOfStoredFrames());
52 } 52 }
53 53
54 TEST(PacketStorageTest, GetFrameWrapAround8bits) { 54 TEST(PacketStorageTest, GetFrameWrapAround8bits) {
55 PacketStorage storage; 55 PacketStorage storage;
56 56
57 const uint32 kFirstFrameId = 250; 57 const uint32_t kFirstFrameId = 250;
58 StoreFrames(kStoredFrames, kFirstFrameId, &storage); 58 StoreFrames(kStoredFrames, kFirstFrameId, &storage);
59 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, kStoredFrames), 59 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, kStoredFrames),
60 storage.GetNumberOfStoredFrames()); 60 storage.GetNumberOfStoredFrames());
61 61
62 // Expect we get the correct frames by looking at the number of 62 // Expect we get the correct frames by looking at the number of
63 // packets. 63 // packets.
64 uint32 frame_id = kFirstFrameId; 64 uint32_t frame_id = kFirstFrameId;
65 for (size_t i = 0; i < kStoredFrames; ++i) { 65 for (size_t i = 0; i < kStoredFrames; ++i) {
66 ASSERT_TRUE(storage.GetFrame8(frame_id)); 66 ASSERT_TRUE(storage.GetFrame8(frame_id));
67 EXPECT_EQ(i + 1, storage.GetFrame8(frame_id)->size()); 67 EXPECT_EQ(i + 1, storage.GetFrame8(frame_id)->size());
68 ++frame_id; 68 ++frame_id;
69 } 69 }
70 } 70 }
71 71
72 TEST(PacketStorageTest, GetFrameWrapAround32bits) { 72 TEST(PacketStorageTest, GetFrameWrapAround32bits) {
73 PacketStorage storage; 73 PacketStorage storage;
74 74
75 // First frame ID is close to the maximum value of uint32. 75 // First frame ID is close to the maximum value of uint32_t.
76 uint32 first_frame_id = 0xffffffff - 5; 76 uint32_t first_frame_id = 0xffffffff - 5;
77 StoreFrames(kStoredFrames, first_frame_id, &storage); 77 StoreFrames(kStoredFrames, first_frame_id, &storage);
78 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, kStoredFrames), 78 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, kStoredFrames),
79 storage.GetNumberOfStoredFrames()); 79 storage.GetNumberOfStoredFrames());
80 80
81 // Expect we get the correct frames by looking at the number of 81 // Expect we get the correct frames by looking at the number of
82 // packets. 82 // packets.
83 uint32 frame_id = first_frame_id; 83 uint32_t frame_id = first_frame_id;
84 for (size_t i = 0; i < kStoredFrames; ++i) { 84 for (size_t i = 0; i < kStoredFrames; ++i) {
85 ASSERT_TRUE(storage.GetFrame8(frame_id)); 85 ASSERT_TRUE(storage.GetFrame8(frame_id));
86 EXPECT_EQ(i + 1, storage.GetFrame8(frame_id)->size()); 86 EXPECT_EQ(i + 1, storage.GetFrame8(frame_id)->size());
87 ++frame_id; 87 ++frame_id;
88 } 88 }
89 } 89 }
90 90
91 TEST(PacketStorageTest, FramesReleased) { 91 TEST(PacketStorageTest, FramesReleased) {
92 PacketStorage storage; 92 PacketStorage storage;
93 93
94 const uint32 kFirstFrameId = 0; 94 const uint32_t kFirstFrameId = 0;
95 StoreFrames(5, kFirstFrameId, &storage); 95 StoreFrames(5, kFirstFrameId, &storage);
96 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, 5), 96 EXPECT_EQ(std::min<size_t>(kMaxUnackedFrames, 5),
97 storage.GetNumberOfStoredFrames()); 97 storage.GetNumberOfStoredFrames());
98 98
99 for (uint32 frame_id = kFirstFrameId; frame_id < kFirstFrameId + 5; 99 for (uint32_t frame_id = kFirstFrameId; frame_id < kFirstFrameId + 5;
100 ++frame_id) { 100 ++frame_id) {
101 EXPECT_TRUE(storage.GetFrame8(frame_id)); 101 EXPECT_TRUE(storage.GetFrame8(frame_id));
102 } 102 }
103 103
104 storage.ReleaseFrame(kFirstFrameId + 2); 104 storage.ReleaseFrame(kFirstFrameId + 2);
105 EXPECT_EQ(4u, storage.GetNumberOfStoredFrames()); 105 EXPECT_EQ(4u, storage.GetNumberOfStoredFrames());
106 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 2)); 106 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 2));
107 107
108 storage.ReleaseFrame(kFirstFrameId + 0); 108 storage.ReleaseFrame(kFirstFrameId + 0);
109 EXPECT_EQ(3u, storage.GetNumberOfStoredFrames()); 109 EXPECT_EQ(3u, storage.GetNumberOfStoredFrames());
110 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 0)); 110 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 0));
111 111
112 storage.ReleaseFrame(kFirstFrameId + 3); 112 storage.ReleaseFrame(kFirstFrameId + 3);
113 EXPECT_EQ(2u, storage.GetNumberOfStoredFrames()); 113 EXPECT_EQ(2u, storage.GetNumberOfStoredFrames());
114 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 3)); 114 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 3));
115 115
116 storage.ReleaseFrame(kFirstFrameId + 4); 116 storage.ReleaseFrame(kFirstFrameId + 4);
117 EXPECT_EQ(1u, storage.GetNumberOfStoredFrames()); 117 EXPECT_EQ(1u, storage.GetNumberOfStoredFrames());
118 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 4)); 118 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 4));
119 119
120 storage.ReleaseFrame(kFirstFrameId + 1); 120 storage.ReleaseFrame(kFirstFrameId + 1);
121 EXPECT_EQ(0u, storage.GetNumberOfStoredFrames()); 121 EXPECT_EQ(0u, storage.GetNumberOfStoredFrames());
122 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 1)); 122 EXPECT_FALSE(storage.GetFrame8(kFirstFrameId + 1));
123 } 123 }
124 124
125 } // namespace cast 125 } // namespace cast
126 } // namespace media 126 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698