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/api/video/i420_buffer.h" | |
15 #include "webrtc/test/gtest.h" | |
16 #include "webrtc/test/testsupport/fileutils.h" | |
17 #include "webrtc/test/testsupport/frame_reader.h" | |
18 | |
19 namespace webrtc { | |
20 namespace test { | |
21 | |
22 namespace { | |
23 const std::string kInputFileContents = "bazouk"; | |
24 | |
25 const size_t kFrameWidth = 2; | |
26 const size_t kFrameHeight = 2; | |
27 const size_t kFrameLength = 3 * kFrameWidth * kFrameHeight / 2; // I420. | |
28 } // namespace | |
29 | |
30 class YuvFrameReaderTest : public testing::Test { | |
31 protected: | |
32 YuvFrameReaderTest() = default; | |
33 ~YuvFrameReaderTest() override = default; | |
34 | |
35 void SetUp() override { | |
36 temp_filename_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), | |
37 "yuv_frame_reader_unittest"); | |
38 FILE* dummy = fopen(temp_filename_.c_str(), "wb"); | |
39 fprintf(dummy, "%s", kInputFileContents.c_str()); | |
40 fclose(dummy); | |
41 | |
42 frame_reader_.reset( | |
43 new YuvFrameReaderImpl(temp_filename_, kFrameWidth, kFrameHeight)); | |
44 ASSERT_TRUE(frame_reader_->Init()); | |
45 } | |
46 | |
47 void TearDown() override { remove(temp_filename_.c_str()); } | |
48 | |
49 std::unique_ptr<FrameReader> frame_reader_; | |
50 std::string temp_filename_; | |
51 }; | |
52 | |
53 TEST_F(YuvFrameReaderTest, InitSuccess) {} | |
54 | |
55 TEST_F(YuvFrameReaderTest, FrameLength) { | |
56 EXPECT_EQ(kFrameLength, frame_reader_->FrameLength()); | |
57 } | |
58 | |
59 TEST_F(YuvFrameReaderTest, NumberOfFrames) { | |
60 EXPECT_EQ(1, frame_reader_->NumberOfFrames()); | |
61 } | |
62 | |
63 TEST_F(YuvFrameReaderTest, ReadFrame) { | |
64 rtc::scoped_refptr<VideoFrameBuffer> buffer; | |
65 buffer = frame_reader_->ReadFrame(); | |
66 ASSERT_TRUE(buffer); | |
67 // Expect I420 packed as YUV. | |
68 EXPECT_EQ(kInputFileContents[0], buffer->DataY()[0]); | |
69 EXPECT_EQ(kInputFileContents[1], buffer->DataY()[1]); | |
70 EXPECT_EQ(kInputFileContents[2], buffer->DataY()[2]); | |
71 EXPECT_EQ(kInputFileContents[3], buffer->DataY()[3]); | |
72 EXPECT_EQ(kInputFileContents[4], buffer->DataU()[0]); | |
73 EXPECT_EQ(kInputFileContents[5], buffer->DataV()[0]); | |
74 EXPECT_FALSE(frame_reader_->ReadFrame()); // End of file. | |
75 } | |
76 | |
77 TEST_F(YuvFrameReaderTest, ReadFrameUninitialized) { | |
78 YuvFrameReaderImpl file_reader(temp_filename_, kFrameWidth, kFrameHeight); | |
79 EXPECT_FALSE(file_reader.ReadFrame()); | |
80 } | |
81 | |
82 } // namespace test | |
83 } // namespace webrtc | |
OLD | NEW |