Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / test / rtp_file_reader_unittest.cc
1 /*
2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 #include <map>
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
15 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
16 #include "webrtc/test/rtp_file_reader.h"
17 #include "webrtc/test/testsupport/fileutils.h"
18
19 namespace webrtc {
20
21 class TestRtpFileReader : public ::testing::Test {
22  public:
23   void Init(const std::string& filename, bool headers_only_file) {
24     std::string filepath =
25         test::ResourcePath("video_coding/" + filename, "rtp");
26     rtp_packet_source_.reset(
27         test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filepath));
28     ASSERT_TRUE(rtp_packet_source_.get() != NULL);
29     headers_only_file_ = headers_only_file;
30   }
31
32   int CountRtpPackets() {
33     test::RtpFileReader::Packet packet;
34     int c = 0;
35     while (rtp_packet_source_->NextPacket(&packet)) {
36       if (headers_only_file_)
37         EXPECT_LT(packet.length, packet.original_length);
38       else
39         EXPECT_EQ(packet.length, packet.original_length);
40       c++;
41     }
42     return c;
43   }
44
45  private:
46   scoped_ptr<test::RtpFileReader> rtp_packet_source_;
47   bool headers_only_file_;
48 };
49
50 TEST_F(TestRtpFileReader, Test60Packets) {
51   Init("pltype103", false);
52   EXPECT_EQ(60, CountRtpPackets());
53 }
54
55 TEST_F(TestRtpFileReader, Test60PacketsHeaderOnly) {
56   Init("pltype103_header_only", true);
57   EXPECT_EQ(60, CountRtpPackets());
58 }
59
60 typedef std::map<uint32_t, int> PacketsPerSsrc;
61
62 class TestPcapFileReader : public ::testing::Test {
63  public:
64   void Init(const std::string& filename) {
65     std::string filepath =
66         test::ResourcePath("video_coding/" + filename, "pcap");
67     rtp_packet_source_.reset(
68         test::RtpFileReader::Create(test::RtpFileReader::kPcap, filepath));
69     ASSERT_TRUE(rtp_packet_source_.get() != NULL);
70   }
71
72   int CountRtpPackets() {
73     int c = 0;
74     test::RtpFileReader::Packet packet;
75     while (rtp_packet_source_->NextPacket(&packet)) {
76       EXPECT_EQ(packet.length, packet.original_length);
77       c++;
78     }
79     return c;
80   }
81
82   PacketsPerSsrc CountRtpPacketsPerSsrc() {
83     PacketsPerSsrc pps;
84     test::RtpFileReader::Packet packet;
85     while (rtp_packet_source_->NextPacket(&packet)) {
86       RtpUtility::RtpHeaderParser rtp_header_parser(packet.data, packet.length);
87       webrtc::RTPHeader header;
88       if (!rtp_header_parser.RTCP() && rtp_header_parser.Parse(header, NULL)) {
89         pps[header.ssrc]++;
90       }
91     }
92     return pps;
93   }
94
95  private:
96   scoped_ptr<test::RtpFileReader> rtp_packet_source_;
97 };
98
99 TEST_F(TestPcapFileReader, TestEthernetIIFrame) {
100   Init("frame-ethernet-ii");
101   EXPECT_EQ(368, CountRtpPackets());
102 }
103
104 TEST_F(TestPcapFileReader, TestLoopbackFrame) {
105   Init("frame-loopback");
106   EXPECT_EQ(491, CountRtpPackets());
107 }
108
109 TEST_F(TestPcapFileReader, TestTwoSsrc) {
110   Init("ssrcs-2");
111   PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
112   EXPECT_EQ(2UL, pps.size());
113   EXPECT_EQ(370, pps[0x78d48f61]);
114   EXPECT_EQ(60, pps[0xae94130b]);
115 }
116
117 TEST_F(TestPcapFileReader, TestThreeSsrc) {
118   Init("ssrcs-3");
119   PacketsPerSsrc pps = CountRtpPacketsPerSsrc();
120   EXPECT_EQ(3UL, pps.size());
121   EXPECT_EQ(162, pps[0x938c5eaa]);
122   EXPECT_EQ(113, pps[0x59fe6ef0]);
123   EXPECT_EQ(61, pps[0xed2bd2ac]);
124 }
125 }  // namespace webrtc