Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2012 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 "testing/gmock/include/gmock/gmock.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h"
     14 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h"
     15 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h"
     16 #include "webrtc/modules/video_coding/include/video_coding.h"
     17 #include "webrtc/test/testsupport/mock/mock_frame_reader.h"
     18 #include "webrtc/test/testsupport/mock/mock_frame_writer.h"
     19 #include "webrtc/test/testsupport/packet_reader.h"
     20 #include "webrtc/test/testsupport/unittest_utils.h"
     21 #include "webrtc/typedefs.h"
     22 
     23 using ::testing::_;
     24 using ::testing::AtLeast;
     25 using ::testing::Return;
     26 
     27 namespace webrtc {
     28 namespace test {
     29 
     30 // Very basic testing for VideoProcessor. It's mostly tested by running the
     31 // video_quality_measurement program.
     32 class VideoProcessorTest : public testing::Test {
     33  protected:
     34   MockVideoEncoder encoder_mock_;
     35   MockVideoDecoder decoder_mock_;
     36   MockFrameReader frame_reader_mock_;
     37   MockFrameWriter frame_writer_mock_;
     38   MockPacketManipulator packet_manipulator_mock_;
     39   Stats stats_;
     40   TestConfig config_;
     41   VideoCodec codec_settings_;
     42 
     43   VideoProcessorTest() {}
     44   virtual ~VideoProcessorTest() {}
     45   void SetUp() {
     46     // Get a codec configuration struct and configure it.
     47     VideoCodingModule::Codec(kVideoCodecVP8, &codec_settings_);
     48     config_.codec_settings = &codec_settings_;
     49     config_.codec_settings->startBitrate = 100;
     50     config_.codec_settings->width = 352;
     51     config_.codec_settings->height = 288;
     52   }
     53   void TearDown() {}
     54 
     55   void ExpectInit() {
     56     EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1);
     57     EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_))
     58         .Times(AtLeast(1));
     59     EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1);
     60     EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_))
     61         .Times(AtLeast(1));
     62     EXPECT_CALL(frame_reader_mock_, NumberOfFrames()).WillOnce(Return(1));
     63     EXPECT_CALL(frame_reader_mock_, FrameLength()).WillOnce(Return(152064));
     64   }
     65 };
     66 
     67 TEST_F(VideoProcessorTest, Init) {
     68   ExpectInit();
     69   VideoProcessorImpl video_processor(
     70       &encoder_mock_, &decoder_mock_, &frame_reader_mock_, &frame_writer_mock_,
     71       &packet_manipulator_mock_, config_, &stats_);
     72   ASSERT_TRUE(video_processor.Init());
     73 }
     74 
     75 TEST_F(VideoProcessorTest, ProcessFrame) {
     76   ExpectInit();
     77   EXPECT_CALL(encoder_mock_, Encode(_, _, _)).Times(1);
     78   EXPECT_CALL(frame_reader_mock_, ReadFrame(_)).WillOnce(Return(true));
     79   // Since we don't return any callback from the mock, the decoder will not
     80   // be more than initialized...
     81   VideoProcessorImpl video_processor(
     82       &encoder_mock_, &decoder_mock_, &frame_reader_mock_, &frame_writer_mock_,
     83       &packet_manipulator_mock_, config_, &stats_);
     84   ASSERT_TRUE(video_processor.Init());
     85   video_processor.ProcessFrame(0);
     86 }
     87 
     88 }  // namespace test
     89 }  // namespace webrtc
     90