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/neteq/interface/audio_decoder.h" 15 16 #include "gmock/gmock.h" 17 #include "webrtc/base/constructormagic.h" 18 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/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: 30 explicit ExternalPcm16B(enum NetEqDecoder type) 31 : AudioDecoder(type) { 32 } 33 34 virtual int Decode(const uint8_t* encoded, size_t encoded_len, 35 int16_t* decoded, SpeechType* speech_type) { 36 int16_t temp_type; 37 int16_t ret = WebRtcPcm16b_DecodeW16( 38 state_, reinterpret_cast<int16_t*>(const_cast<uint8_t*>(encoded)), 39 static_cast<int16_t>(encoded_len), decoded, &temp_type); 40 *speech_type = ConvertSpeechType(temp_type); 41 return ret; 42 } 43 44 virtual int Init() { return 0; } 45 46 private: 47 DISALLOW_COPY_AND_ASSIGN(ExternalPcm16B); 48 }; 49 50 // Create a mock of ExternalPcm16B which delegates all calls to the real object. 51 // The reason is that we can then track that the correct calls are being made. 52 class MockExternalPcm16B : public ExternalPcm16B { 53 public: 54 explicit MockExternalPcm16B(enum NetEqDecoder type) 55 : ExternalPcm16B(type), 56 real_(type) { 57 // By default, all calls are delegated to the real object. 58 ON_CALL(*this, Decode(_, _, _, _)) 59 .WillByDefault(Invoke(&real_, &ExternalPcm16B::Decode)); 60 ON_CALL(*this, HasDecodePlc()) 61 .WillByDefault(Invoke(&real_, &ExternalPcm16B::HasDecodePlc)); 62 ON_CALL(*this, DecodePlc(_, _)) 63 .WillByDefault(Invoke(&real_, &ExternalPcm16B::DecodePlc)); 64 ON_CALL(*this, Init()) 65 .WillByDefault(Invoke(&real_, &ExternalPcm16B::Init)); 66 ON_CALL(*this, IncomingPacket(_, _, _, _, _)) 67 .WillByDefault(Invoke(&real_, &ExternalPcm16B::IncomingPacket)); 68 ON_CALL(*this, ErrorCode()) 69 .WillByDefault(Invoke(&real_, &ExternalPcm16B::ErrorCode)); 70 ON_CALL(*this, codec_type()) 71 .WillByDefault(Invoke(&real_, &ExternalPcm16B::codec_type)); 72 } 73 virtual ~MockExternalPcm16B() { Die(); } 74 75 MOCK_METHOD0(Die, void()); 76 MOCK_METHOD4(Decode, 77 int(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, 78 SpeechType* speech_type)); 79 MOCK_CONST_METHOD0(HasDecodePlc, 80 bool()); 81 MOCK_METHOD2(DecodePlc, 82 int(int num_frames, int16_t* decoded)); 83 MOCK_METHOD0(Init, 84 int()); 85 MOCK_METHOD5(IncomingPacket, 86 int(const uint8_t* payload, size_t payload_len, 87 uint16_t rtp_sequence_number, uint32_t rtp_timestamp, 88 uint32_t arrival_timestamp)); 89 MOCK_METHOD0(ErrorCode, 90 int()); 91 MOCK_CONST_METHOD0(codec_type, 92 NetEqDecoder()); 93 94 private: 95 ExternalPcm16B real_; 96 }; 97 98 } // namespace webrtc 99 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_MOCK_MOCK_EXTERNAL_DECODER_PCM16B_H_ 100