blob: dd4b980c711fff36ca9714df85d1401ded46fe74 [file] [log] [blame]
brandtrb78bc752017-02-22 01:26:59 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "api/video/i420_buffer.h"
15#include "test/gtest.h"
16#include "test/testsupport/fileutils.h"
17#include "test/testsupport/frame_reader.h"
brandtrb78bc752017-02-22 01:26:59 -080018
19namespace webrtc {
20namespace test {
21
22namespace {
23const std::string kInputFileContents = "bazouk";
24
25const size_t kFrameWidth = 2;
26const size_t kFrameHeight = 2;
27const size_t kFrameLength = 3 * kFrameWidth * kFrameHeight / 2; // I420.
28} // namespace
29
30class 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
53TEST_F(YuvFrameReaderTest, InitSuccess) {}
54
55TEST_F(YuvFrameReaderTest, FrameLength) {
56 EXPECT_EQ(kFrameLength, frame_reader_->FrameLength());
57}
58
59TEST_F(YuvFrameReaderTest, NumberOfFrames) {
60 EXPECT_EQ(1, frame_reader_->NumberOfFrames());
61}
62
63TEST_F(YuvFrameReaderTest, ReadFrame) {
Magnus Jedvert90e31902017-06-07 11:32:50 +020064 rtc::scoped_refptr<I420BufferInterface> buffer = frame_reader_->ReadFrame();
brandtrb78bc752017-02-22 01:26:59 -080065 ASSERT_TRUE(buffer);
66 // Expect I420 packed as YUV.
67 EXPECT_EQ(kInputFileContents[0], buffer->DataY()[0]);
68 EXPECT_EQ(kInputFileContents[1], buffer->DataY()[1]);
69 EXPECT_EQ(kInputFileContents[2], buffer->DataY()[2]);
70 EXPECT_EQ(kInputFileContents[3], buffer->DataY()[3]);
71 EXPECT_EQ(kInputFileContents[4], buffer->DataU()[0]);
72 EXPECT_EQ(kInputFileContents[5], buffer->DataV()[0]);
73 EXPECT_FALSE(frame_reader_->ReadFrame()); // End of file.
74}
75
76TEST_F(YuvFrameReaderTest, ReadFrameUninitialized) {
77 YuvFrameReaderImpl file_reader(temp_filename_, kFrameWidth, kFrameHeight);
78 EXPECT_FALSE(file_reader.ReadFrame());
79}
80
81} // namespace test
82} // namespace webrtc