1 /*
2  *  Copyright (c) 2013 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 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
13 
14 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
15 
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b.h"
19 #include "webrtc/typedefs.h"
20 
21 namespace webrtc {
22 
23 using ::testing::_;
24 using ::testing::Invoke;
25 
26 // Implement an external version of the PCM16b decoder. This is a copy from
27 // audio_decoder_impl.{cc, h}.
28 class ExternalPcm16B : public AudioDecoder {
29  public:
ExternalPcm16B()30   ExternalPcm16B() {}
Reset()31   void Reset() override {}
32 
DecodeInternal(const uint8_t * encoded,size_t encoded_len,int sample_rate_hz,int16_t * decoded,SpeechType * speech_type)33   int DecodeInternal(const uint8_t* encoded,
34                      size_t encoded_len,
35                      int sample_rate_hz,
36                      int16_t* decoded,
37                      SpeechType* speech_type) override {
38     size_t ret = WebRtcPcm16b_Decode(encoded, encoded_len, decoded);
39     *speech_type = ConvertSpeechType(1);
40     return static_cast<int>(ret);
41   }
Channels()42   size_t Channels() const override { return 1; }
43 
44  private:
45   RTC_DISALLOW_COPY_AND_ASSIGN(ExternalPcm16B);
46 };
47 
48 // Create a mock of ExternalPcm16B which delegates all calls to the real object.
49 // The reason is that we can then track that the correct calls are being made.
50 class MockExternalPcm16B : public ExternalPcm16B {
51  public:
MockExternalPcm16B()52   MockExternalPcm16B() {
53     // By default, all calls are delegated to the real object.
54     ON_CALL(*this, DecodeInternal(_, _, _, _, _))
55         .WillByDefault(Invoke(&real_, &ExternalPcm16B::DecodeInternal));
56     ON_CALL(*this, HasDecodePlc())
57         .WillByDefault(Invoke(&real_, &ExternalPcm16B::HasDecodePlc));
58     ON_CALL(*this, DecodePlc(_, _))
59         .WillByDefault(Invoke(&real_, &ExternalPcm16B::DecodePlc));
60     ON_CALL(*this, Reset())
61         .WillByDefault(Invoke(&real_, &ExternalPcm16B::Reset));
62     ON_CALL(*this, IncomingPacket(_, _, _, _, _))
63         .WillByDefault(Invoke(&real_, &ExternalPcm16B::IncomingPacket));
64     ON_CALL(*this, ErrorCode())
65         .WillByDefault(Invoke(&real_, &ExternalPcm16B::ErrorCode));
66   }
~MockExternalPcm16B()67   virtual ~MockExternalPcm16B() { Die(); }
68 
69   MOCK_METHOD0(Die, void());
70   MOCK_METHOD5(DecodeInternal,
71                int(const uint8_t* encoded,
72                    size_t encoded_len,
73                    int sample_rate_hz,
74                    int16_t* decoded,
75                    SpeechType* speech_type));
76   MOCK_CONST_METHOD0(HasDecodePlc,
77       bool());
78   MOCK_METHOD2(DecodePlc,
79       size_t(size_t num_frames, int16_t* decoded));
80   MOCK_METHOD0(Reset, void());
81   MOCK_METHOD5(IncomingPacket,
82       int(const uint8_t* payload, size_t payload_len,
83           uint16_t rtp_sequence_number, uint32_t rtp_timestamp,
84           uint32_t arrival_timestamp));
85   MOCK_METHOD0(ErrorCode,
86       int());
87 
88  private:
89   ExternalPcm16B real_;
90 };
91 
92 }  // namespace webrtc
93 #endif  // WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_
94