OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 |
11 #include "webrtc/test/testsupport/frame_writer.h" | 11 #include <memory> |
| 12 #include <string> |
12 | 13 |
13 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
14 #include "webrtc/test/testsupport/fileutils.h" | 15 #include "webrtc/test/testsupport/fileutils.h" |
| 16 #include "webrtc/test/testsupport/frame_writer.h" |
15 | 17 |
16 namespace webrtc { | 18 namespace webrtc { |
17 namespace test { | 19 namespace test { |
18 | 20 |
19 const size_t kFrameLength = 1000; | 21 namespace { |
| 22 const size_t kFrameWidth = 50; |
| 23 const size_t kFrameHeight = 20; |
| 24 const size_t kFrameLength = 3 * kFrameWidth * kFrameHeight / 2; // I420. |
| 25 const size_t kFrameRate = 30; |
20 | 26 |
21 class FrameWriterTest: public testing::Test { | 27 const std::string kFileHeader = "YUV4MPEG2 W50 H20 F30:1 C420\n"; |
| 28 const std::string kFrameHeader = "FRAME\n"; |
| 29 } // namespace |
| 30 |
| 31 class Y4mFrameWriterTest : public testing::Test { |
22 protected: | 32 protected: |
23 FrameWriterTest() {} | 33 Y4mFrameWriterTest() = default; |
24 virtual ~FrameWriterTest() {} | 34 ~Y4mFrameWriterTest() override = default; |
25 void SetUp() { | 35 |
| 36 void SetUp() override { |
26 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), | 37 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), |
27 "frame_writer_unittest"); | 38 "y4m_frame_writer_unittest"); |
28 frame_writer_ = new FrameWriterImpl(temp_filename_, kFrameLength); | 39 frame_writer_.reset(new Y4mFrameWriterImpl(temp_filename_, kFrameWidth, |
| 40 kFrameHeight, kFrameRate)); |
29 ASSERT_TRUE(frame_writer_->Init()); | 41 ASSERT_TRUE(frame_writer_->Init()); |
30 } | 42 } |
31 void TearDown() { | 43 |
32 delete frame_writer_; | 44 void TearDown() override { remove(temp_filename_.c_str()); } |
33 // Cleanup the temporary file. | 45 |
34 remove(temp_filename_.c_str()); | 46 std::unique_ptr<FrameWriter> frame_writer_; |
35 } | |
36 FrameWriter* frame_writer_; | |
37 std::string temp_filename_; | 47 std::string temp_filename_; |
38 }; | 48 }; |
39 | 49 |
40 TEST_F(FrameWriterTest, InitSuccess) { | 50 TEST_F(Y4mFrameWriterTest, InitSuccess) {} |
41 FrameWriterImpl frame_writer(temp_filename_, kFrameLength); | 51 |
42 ASSERT_TRUE(frame_writer.Init()); | 52 TEST_F(Y4mFrameWriterTest, FrameLength) { |
43 ASSERT_EQ(kFrameLength, frame_writer.FrameLength()); | 53 EXPECT_EQ(kFrameLength, frame_writer_->FrameLength()); |
44 } | 54 } |
45 | 55 |
46 TEST_F(FrameWriterTest, WriteFrame) { | 56 TEST_F(Y4mFrameWriterTest, WriteFrame) { |
47 uint8_t buffer[kFrameLength]; | 57 uint8_t buffer[kFrameLength]; |
48 memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer | 58 memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer. |
49 bool result = frame_writer_->WriteFrame(buffer); | 59 bool result = frame_writer_->WriteFrame(buffer); |
50 ASSERT_TRUE(result); // success | 60 ASSERT_TRUE(result); |
51 // Close the file and verify the size. | 61 result = frame_writer_->WriteFrame(buffer); |
| 62 ASSERT_TRUE(result); |
| 63 |
52 frame_writer_->Close(); | 64 frame_writer_->Close(); |
53 ASSERT_EQ(kFrameLength, GetFileSize(temp_filename_)); | 65 EXPECT_EQ(kFileHeader.size() + 2 * kFrameHeader.size() + 2 * kFrameLength, |
| 66 GetFileSize(temp_filename_)); |
54 } | 67 } |
55 | 68 |
56 TEST_F(FrameWriterTest, WriteFrameUninitialized) { | 69 TEST_F(Y4mFrameWriterTest, WriteFrameUninitialized) { |
57 uint8_t buffer[3]; | 70 uint8_t buffer[kFrameLength]; |
58 FrameWriterImpl frame_writer(temp_filename_, kFrameLength); | 71 Y4mFrameWriterImpl frame_writer(temp_filename_, kFrameWidth, kFrameHeight, |
59 ASSERT_FALSE(frame_writer.WriteFrame(buffer)); | 72 kFrameRate); |
| 73 EXPECT_FALSE(frame_writer.WriteFrame(buffer)); |
60 } | 74 } |
61 | 75 |
62 } // namespace test | 76 } // namespace test |
63 } // namespace webrtc | 77 } // namespace webrtc |
OLD | NEW |