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/codecs/interface/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/main/interface/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
23using ::testing::_;
24using ::testing::AtLeast;
25using ::testing::Return;
26
27namespace webrtc {
28namespace test {
29
30// Very basic testing for VideoProcessor. It's mostly tested by running the
31// video_quality_measurement program.
32class 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(_, _, _))
57      .Times(1);
58    EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_))
59      .Times(AtLeast(1));
60    EXPECT_CALL(decoder_mock_, InitDecode(_, _))
61      .Times(1);
62    EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_))
63      .Times(AtLeast(1));
64    EXPECT_CALL(frame_reader_mock_, NumberOfFrames())
65      .WillOnce(Return(1));
66    EXPECT_CALL(frame_reader_mock_, FrameLength())
67      .WillOnce(Return(152064));
68  }
69};
70
71TEST_F(VideoProcessorTest, Init) {
72  ExpectInit();
73  VideoProcessorImpl video_processor(&encoder_mock_, &decoder_mock_,
74                                     &frame_reader_mock_,
75                                     &frame_writer_mock_,
76                                     &packet_manipulator_mock_, config_,
77                                     &stats_);
78  ASSERT_TRUE(video_processor.Init());
79}
80
81TEST_F(VideoProcessorTest, ProcessFrame) {
82  ExpectInit();
83  EXPECT_CALL(encoder_mock_, Encode(_, _, _))
84    .Times(1);
85  EXPECT_CALL(frame_reader_mock_, ReadFrame(_))
86    .WillOnce(Return(true));
87  // Since we don't return any callback from the mock, the decoder will not
88  // be more than initialized...
89  VideoProcessorImpl video_processor(&encoder_mock_, &decoder_mock_,
90                                     &frame_reader_mock_,
91                                     &frame_writer_mock_,
92                                     &packet_manipulator_mock_, config_,
93                                     &stats_);
94  ASSERT_TRUE(video_processor.Init());
95  video_processor.ProcessFrame(0);
96}
97
98}  // namespace test
99}  // namespace webrtc
100