| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class RtpFileWriterTest : public ::testing::Test { | 22 class RtpFileWriterTest : public ::testing::Test { |
| 23 public: | 23 public: |
| 24 void Init(const std::string& filename) { | 24 void Init(const std::string& filename) { |
| 25 filename_ = test::OutputPath() + filename; | 25 filename_ = test::OutputPath() + filename; |
| 26 rtp_writer_.reset( | 26 rtp_writer_.reset( |
| 27 test::RtpFileWriter::Create(test::RtpFileWriter::kRtpDump, filename_)); | 27 test::RtpFileWriter::Create(test::RtpFileWriter::kRtpDump, filename_)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void WriteRtpPackets(int num_packets) { | 30 void WriteRtpPackets(int num_packets) { |
| 31 ASSERT_TRUE(rtp_writer_.get() != NULL); | 31 ASSERT_TRUE(rtp_writer_.get() != nullptr); |
| 32 test::RtpPacket packet; | 32 test::RtpPacket packet; |
| 33 for (int i = 1; i <= num_packets; ++i) { | 33 for (int i = 1; i <= num_packets; ++i) { |
| 34 packet.length = i; | 34 packet.length = i; |
| 35 packet.original_length = i; | 35 packet.original_length = i; |
| 36 packet.time_ms = i; | 36 packet.time_ms = i; |
| 37 memset(packet.data, i, packet.length); | 37 memset(packet.data, i, packet.length); |
| 38 EXPECT_TRUE(rtp_writer_->WritePacket(&packet)); | 38 EXPECT_TRUE(rtp_writer_->WritePacket(&packet)); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CloseOutputFile() { rtp_writer_.reset(); } | 42 void CloseOutputFile() { rtp_writer_.reset(); } |
| 43 | 43 |
| 44 void VerifyFileContents(int expected_packets) { | 44 void VerifyFileContents(int expected_packets) { |
| 45 ASSERT_TRUE(rtp_writer_.get() == NULL) | 45 ASSERT_TRUE(rtp_writer_.get() == nullptr) |
| 46 << "Must call CloseOutputFile before VerifyFileContents"; | 46 << "Must call CloseOutputFile before VerifyFileContents"; |
| 47 std::unique_ptr<test::RtpFileReader> rtp_reader( | 47 std::unique_ptr<test::RtpFileReader> rtp_reader( |
| 48 test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filename_)); | 48 test::RtpFileReader::Create(test::RtpFileReader::kRtpDump, filename_)); |
| 49 ASSERT_TRUE(rtp_reader.get() != NULL); | 49 ASSERT_TRUE(rtp_reader.get() != nullptr); |
| 50 test::RtpPacket packet; | 50 test::RtpPacket packet; |
| 51 int i = 0; | 51 int i = 0; |
| 52 while (rtp_reader->NextPacket(&packet)) { | 52 while (rtp_reader->NextPacket(&packet)) { |
| 53 ++i; | 53 ++i; |
| 54 EXPECT_EQ(static_cast<size_t>(i), packet.length); | 54 EXPECT_EQ(static_cast<size_t>(i), packet.length); |
| 55 EXPECT_EQ(static_cast<size_t>(i), packet.original_length); | 55 EXPECT_EQ(static_cast<size_t>(i), packet.original_length); |
| 56 EXPECT_EQ(static_cast<uint32_t>(i), packet.time_ms); | 56 EXPECT_EQ(static_cast<uint32_t>(i), packet.time_ms); |
| 57 for (int j = 0; j < i; ++j) { | 57 for (int j = 0; j < i; ++j) { |
| 58 EXPECT_EQ(i, packet.data[j]); | 58 EXPECT_EQ(i, packet.data[j]); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 EXPECT_EQ(expected_packets, i); | 61 EXPECT_EQ(expected_packets, i); |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 std::unique_ptr<test::RtpFileWriter> rtp_writer_; | 65 std::unique_ptr<test::RtpFileWriter> rtp_writer_; |
| 66 std::string filename_; | 66 std::string filename_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 TEST_F(RtpFileWriterTest, WriteToRtpDump) { | 69 TEST_F(RtpFileWriterTest, WriteToRtpDump) { |
| 70 Init("test_rtp_file_writer.rtp"); | 70 Init("test_rtp_file_writer.rtp"); |
| 71 WriteRtpPackets(10); | 71 WriteRtpPackets(10); |
| 72 CloseOutputFile(); | 72 CloseOutputFile(); |
| 73 VerifyFileContents(10); | 73 VerifyFileContents(10); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace webrtc | 76 } // namespace webrtc |
| OLD | NEW |