2013-07-10 00:45:36 +00:00
|
|
|
/*
|
|
|
|
|
* libjingle
|
2015-01-20 21:36:13 +00:00
|
|
|
* Copyright 2012 Google Inc.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains mock implementations of observers used in PeerConnection.
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|
|
|
|
|
#define WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/datachannelinterface.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class MockCreateSessionDescriptionObserver
|
|
|
|
|
: public webrtc::CreateSessionDescriptionObserver {
|
|
|
|
|
public:
|
|
|
|
|
MockCreateSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
|
|
|
|
result_(false) {}
|
|
|
|
|
virtual ~MockCreateSessionDescriptionObserver() {}
|
|
|
|
|
virtual void OnSuccess(SessionDescriptionInterface* desc) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = true;
|
|
|
|
|
desc_.reset(desc);
|
|
|
|
|
}
|
|
|
|
|
virtual void OnFailure(const std::string& error) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = false;
|
|
|
|
|
}
|
|
|
|
|
bool called() const { return called_; }
|
|
|
|
|
bool result() const { return result_; }
|
|
|
|
|
SessionDescriptionInterface* release_desc() {
|
|
|
|
|
return desc_.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool called_;
|
|
|
|
|
bool result_;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_ptr<SessionDescriptionInterface> desc_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockSetSessionDescriptionObserver
|
|
|
|
|
: public webrtc::SetSessionDescriptionObserver {
|
|
|
|
|
public:
|
|
|
|
|
MockSetSessionDescriptionObserver()
|
|
|
|
|
: called_(false),
|
|
|
|
|
result_(false) {}
|
|
|
|
|
virtual ~MockSetSessionDescriptionObserver() {}
|
|
|
|
|
virtual void OnSuccess() {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = true;
|
|
|
|
|
}
|
|
|
|
|
virtual void OnFailure(const std::string& error) {
|
|
|
|
|
called_ = true;
|
|
|
|
|
result_ = false;
|
|
|
|
|
}
|
|
|
|
|
bool called() const { return called_; }
|
|
|
|
|
bool result() const { return result_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool called_;
|
|
|
|
|
bool result_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockDataChannelObserver : public webrtc::DataChannelObserver {
|
|
|
|
|
public:
|
|
|
|
|
explicit MockDataChannelObserver(webrtc::DataChannelInterface* channel)
|
2014-06-12 21:59:29 +00:00
|
|
|
: channel_(channel), received_message_count_(0) {
|
2013-07-10 00:45:36 +00:00
|
|
|
channel_->RegisterObserver(this);
|
|
|
|
|
state_ = channel_->state();
|
|
|
|
|
}
|
|
|
|
|
virtual ~MockDataChannelObserver() {
|
|
|
|
|
channel_->UnregisterObserver();
|
|
|
|
|
}
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
void OnBufferedAmountChange(uint64_t previous_amount) override {}
|
2015-07-01 13:34:33 -07:00
|
|
|
|
|
|
|
|
void OnStateChange() override { state_ = channel_->state(); }
|
|
|
|
|
void OnMessage(const DataBuffer& buffer) override {
|
rtc::Buffer improvements
1. Constructors, SetData(), and AppendData() now accept uint8_t*,
int8_t*, and char*. Previously, they accepted void*, meaning that
any kind of pointer was accepted. I think requiring an explicit
cast in cases where the input array isn't already of a byte-sized
type is a better compromise between convenience and safety.
2. data() can now return a uint8_t* instead of a char*, which seems
more appropriate for a byte array, and is harder to mix up with
zero-terminated C strings. data<int8_t>() is also available so
that callers that want that type instead won't have to cast, as
is data<char>() (which remains the default until all existing
callers have been fixed).
3. Constructors, SetData(), and AppendData() now accept arrays
natively, not just decayed to pointers. The advantage of this is
that callers don't have to pass the size separately.
4. There are new constructors that allow setting size and capacity
without initializing the array. Previously, this had to be done
separately after construction.
5. Instead of TransferTo(), Buffer now supports swap(), and move
construction and assignment, and has a Pass() method that works
just like std::move(). (The Pass method is modeled after
scoped_ptr::Pass().)
R=jmarusic@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/42989004
Cr-Commit-Position: refs/heads/master@{#9033}
2015-04-20 14:03:07 +02:00
|
|
|
last_message_.assign(buffer.data.data<char>(), buffer.data.size());
|
2014-06-12 21:59:29 +00:00
|
|
|
++received_message_count_;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsOpen() const { return state_ == DataChannelInterface::kOpen; }
|
|
|
|
|
const std::string& last_message() const { return last_message_; }
|
2014-06-12 21:59:29 +00:00
|
|
|
size_t received_message_count() const { return received_message_count_; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::DataChannelInterface> channel_;
|
2013-07-10 00:45:36 +00:00
|
|
|
DataChannelInterface::DataState state_;
|
|
|
|
|
std::string last_message_;
|
2014-06-12 21:59:29 +00:00
|
|
|
size_t received_message_count_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MockStatsObserver : public webrtc::StatsObserver {
|
|
|
|
|
public:
|
2014-12-17 14:09:05 +00:00
|
|
|
MockStatsObserver() : called_(false), stats_() {}
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual ~MockStatsObserver() {}
|
2014-12-17 14:09:05 +00:00
|
|
|
|
2014-08-15 08:38:30 +00:00
|
|
|
virtual void OnComplete(const StatsReports& reports) {
|
2014-12-17 14:09:05 +00:00
|
|
|
ASSERT(!called_);
|
2013-07-10 00:45:36 +00:00
|
|
|
called_ = true;
|
2015-03-04 01:38:30 +00:00
|
|
|
stats_.Clear();
|
2014-12-17 14:09:05 +00:00
|
|
|
stats_.number_of_reports = reports.size();
|
|
|
|
|
for (const auto* r : reports) {
|
2015-01-21 11:36:18 +00:00
|
|
|
if (r->type() == StatsReport::kStatsReportTypeSsrc) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2014-12-17 14:09:05 +00:00
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel,
|
|
|
|
|
&stats_.audio_output_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel,
|
|
|
|
|
&stats_.audio_input_level);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesReceived,
|
|
|
|
|
&stats_.bytes_received);
|
|
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameBytesSent,
|
|
|
|
|
&stats_.bytes_sent);
|
2015-01-21 11:36:18 +00:00
|
|
|
} else if (r->type() == StatsReport::kStatsReportTypeBwe) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2014-12-17 14:09:05 +00:00
|
|
|
GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth,
|
|
|
|
|
&stats_.available_receive_bandwidth);
|
2015-03-04 01:38:30 +00:00
|
|
|
} else if (r->type() == StatsReport::kStatsReportTypeComponent) {
|
2015-06-22 15:06:43 -07:00
|
|
|
stats_.timestamp = r->timestamp();
|
2015-03-04 01:38:30 +00:00
|
|
|
GetStringValue(r, StatsReport::kStatsValueNameDtlsCipher,
|
|
|
|
|
&stats_.dtls_cipher);
|
|
|
|
|
GetStringValue(r, StatsReport::kStatsValueNameSrtpCipher,
|
|
|
|
|
&stats_.srtp_cipher);
|
2014-12-17 14:09:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool called() const { return called_; }
|
2014-12-17 14:09:05 +00:00
|
|
|
size_t number_of_reports() const { return stats_.number_of_reports; }
|
2015-06-22 15:06:43 -07:00
|
|
|
double timestamp() const { return stats_.timestamp; }
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioOutputLevel() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.audio_output_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AudioInputLevel() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.audio_input_level;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesReceived() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.bytes_received;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int BytesSent() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.bytes_sent;
|
2014-08-25 12:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
int AvailableReceiveBandwidth() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.available_receive_bandwidth;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 01:38:30 +00:00
|
|
|
std::string DtlsCipher() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.dtls_cipher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SrtpCipher() const {
|
|
|
|
|
ASSERT(called_);
|
|
|
|
|
return stats_.srtp_cipher;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
private:
|
2014-12-17 14:09:05 +00:00
|
|
|
bool GetIntValue(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
int* value) {
|
2015-03-04 15:25:19 +00:00
|
|
|
const StatsReport::Value* v = report->FindValue(name);
|
|
|
|
|
if (v) {
|
|
|
|
|
// TODO(tommi): We should really just be using an int here :-/
|
|
|
|
|
*value = rtc::FromString<int>(v->ToString());
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-03-04 15:25:19 +00:00
|
|
|
return v != nullptr;
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
2015-03-04 15:25:19 +00:00
|
|
|
|
2015-03-04 01:38:30 +00:00
|
|
|
bool GetStringValue(const StatsReport* report,
|
|
|
|
|
StatsReport::StatsValueName name,
|
|
|
|
|
std::string* value) {
|
2015-03-04 15:25:19 +00:00
|
|
|
const StatsReport::Value* v = report->FindValue(name);
|
|
|
|
|
if (v)
|
|
|
|
|
*value = v->ToString();
|
|
|
|
|
return v != nullptr;
|
2015-03-04 01:38:30 +00:00
|
|
|
}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
bool called_;
|
2014-12-17 14:09:05 +00:00
|
|
|
struct {
|
2015-03-04 01:38:30 +00:00
|
|
|
void Clear() {
|
|
|
|
|
number_of_reports = 0;
|
2015-06-22 15:06:43 -07:00
|
|
|
timestamp = 0;
|
2015-03-04 01:38:30 +00:00
|
|
|
audio_output_level = 0;
|
|
|
|
|
audio_input_level = 0;
|
|
|
|
|
bytes_received = 0;
|
|
|
|
|
bytes_sent = 0;
|
|
|
|
|
available_receive_bandwidth = 0;
|
|
|
|
|
dtls_cipher.clear();
|
|
|
|
|
srtp_cipher.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:09:05 +00:00
|
|
|
size_t number_of_reports;
|
2015-06-22 15:06:43 -07:00
|
|
|
double timestamp;
|
2014-12-17 14:09:05 +00:00
|
|
|
int audio_output_level;
|
|
|
|
|
int audio_input_level;
|
|
|
|
|
int bytes_received;
|
|
|
|
|
int bytes_sent;
|
|
|
|
|
int available_receive_bandwidth;
|
2015-03-04 01:38:30 +00:00
|
|
|
std::string dtls_cipher;
|
|
|
|
|
std::string srtp_cipher;
|
2014-12-17 14:09:05 +00:00
|
|
|
} stats_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_
|