OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2017 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 <memory> | |
12 #include <string> | |
13 | |
14 #include "webrtc/test/gtest.h" | |
15 #include "webrtc/test/testsupport/fileutils.h" | |
16 #include "webrtc/test/testsupport/frame_writer.h" | |
17 | |
18 namespace webrtc { | |
19 namespace test { | |
20 | |
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; | |
26 | |
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 { | |
32 protected: | |
33 Y4mFrameWriterTest() = default; | |
34 ~Y4mFrameWriterTest() override = default; | |
35 | |
36 void SetUp() override { | |
37 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), | |
38 "y4m_frame_writer_unittest"); | |
39 frame_writer_.reset(new Y4mFrameWriterImpl(temp_filename_, kFrameWidth, | |
40 kFrameHeight, kFrameRate)); | |
41 ASSERT_TRUE(frame_writer_->Init()); | |
42 } | |
43 | |
44 void TearDown() override { remove(temp_filename_.c_str()); } | |
45 | |
46 std::unique_ptr<FrameWriter> frame_writer_; | |
47 std::string temp_filename_; | |
48 }; | |
49 | |
50 TEST_F(Y4mFrameWriterTest, InitSuccess) {} | |
51 | |
52 TEST_F(Y4mFrameWriterTest, FrameLength) { | |
53 EXPECT_EQ(kFrameLength, frame_writer_->FrameLength()); | |
54 } | |
55 | |
56 TEST_F(Y4mFrameWriterTest, WriteFrame) { | |
57 uint8_t buffer[kFrameLength]; | |
58 memset(buffer, 9, kFrameLength); // Write lots of 9s to the buffer. | |
59 bool result = frame_writer_->WriteFrame(buffer); | |
60 ASSERT_TRUE(result); | |
61 result = frame_writer_->WriteFrame(buffer); | |
62 ASSERT_TRUE(result); | |
63 | |
64 frame_writer_->Close(); | |
65 EXPECT_EQ(kFileHeader.size() + 2 * kFrameHeader.size() + 2 * kFrameLength, | |
66 GetFileSize(temp_filename_)); | |
67 } | |
68 | |
69 TEST_F(Y4mFrameWriterTest, WriteFrameUninitialized) { | |
70 uint8_t buffer[kFrameLength]; | |
71 Y4mFrameWriterImpl frame_writer(temp_filename_, kFrameWidth, kFrameHeight, | |
72 kFrameRate); | |
73 EXPECT_FALSE(frame_writer.WriteFrame(buffer)); | |
74 } | |
75 | |
76 } // namespace test | |
77 } // namespace webrtc | |
OLD | NEW |