Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / cast / transport / rtp_sender / packet_storage / packet_storage_unittest.cc
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/transport/rtp_sender/packet_storage/packet_storage.h"
6
7 #include <stdint.h>
8
9 #include <vector>
10
11 #include "base/test/simple_test_tick_clock.h"
12 #include "base/time/time.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 namespace media {
16 namespace cast {
17 namespace transport {
18
19 static int kStoredFrames = 10;
20
21 class PacketStorageTest : public ::testing::Test {
22  protected:
23   PacketStorageTest() : packet_storage_(kStoredFrames) {
24   }
25
26   PacketStorage packet_storage_;
27
28   DISALLOW_COPY_AND_ASSIGN(PacketStorageTest);
29 };
30
31 TEST_F(PacketStorageTest, PacketContent) {
32   base::TimeTicks frame_tick;
33   for (uint32 frame_id = 0; frame_id < 200; ++frame_id) {
34     for (uint16 packet_id = 0; packet_id < 5; ++packet_id) {
35       Packet test_packet(frame_id + 1, packet_id);
36       packet_storage_.StorePacket(
37           frame_id,
38           packet_id,
39           PacedPacketSender::MakePacketKey(frame_tick,
40                                            1, // ssrc
41                                            packet_id),
42           new base::RefCountedData<Packet>(test_packet));
43     }
44
45     for (uint32 f = 0; f <= frame_id; f++) {
46       for (uint16 packet_id = 0; packet_id < 5; ++packet_id) {
47         SendPacketVector packets;
48         if (packet_storage_.GetPacket32(f, packet_id, &packets)) {
49           EXPECT_GT(f + kStoredFrames, frame_id);
50           EXPECT_EQ(f + 1, packets.back().second->data.size());
51           EXPECT_EQ(packet_id, packets.back().second->data[0]);
52           EXPECT_TRUE(packet_storage_.GetPacket(f & 0xff, packet_id, &packets));
53           EXPECT_TRUE(packets.back().second->data ==
54                       packets.front().second->data);
55         } else {
56           EXPECT_LE(f + kStoredFrames, frame_id);
57         }
58       }
59     }
60   }
61 }
62
63 }  // namespace transport
64 }  // namespace cast
65 }  // namespace media