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