| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // This file contains mock implementations of observers used in PeerConnection. | 11 // This file contains mock implementations of observers used in PeerConnection. |
| 12 | 12 |
| 13 #ifndef WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ | 13 #ifndef WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ |
| 14 #define WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ | 14 #define WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ |
| 15 | 15 |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "webrtc/api/datachannelinterface.h" | 19 #include "webrtc/api/datachannelinterface.h" |
| 20 #include "webrtc/base/checks.h" |
| 20 | 21 |
| 21 namespace webrtc { | 22 namespace webrtc { |
| 22 | 23 |
| 23 class MockCreateSessionDescriptionObserver | 24 class MockCreateSessionDescriptionObserver |
| 24 : public webrtc::CreateSessionDescriptionObserver { | 25 : public webrtc::CreateSessionDescriptionObserver { |
| 25 public: | 26 public: |
| 26 MockCreateSessionDescriptionObserver() | 27 MockCreateSessionDescriptionObserver() |
| 27 : called_(false), | 28 : called_(false), |
| 28 result_(false) {} | 29 result_(false) {} |
| 29 virtual ~MockCreateSessionDescriptionObserver() {} | 30 virtual ~MockCreateSessionDescriptionObserver() {} |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 DataChannelInterface::DataState state_; | 103 DataChannelInterface::DataState state_; |
| 103 std::vector<std::string> messages_; | 104 std::vector<std::string> messages_; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 class MockStatsObserver : public webrtc::StatsObserver { | 107 class MockStatsObserver : public webrtc::StatsObserver { |
| 107 public: | 108 public: |
| 108 MockStatsObserver() : called_(false), stats_() {} | 109 MockStatsObserver() : called_(false), stats_() {} |
| 109 virtual ~MockStatsObserver() {} | 110 virtual ~MockStatsObserver() {} |
| 110 | 111 |
| 111 virtual void OnComplete(const StatsReports& reports) { | 112 virtual void OnComplete(const StatsReports& reports) { |
| 112 ASSERT(!called_); | 113 RTC_CHECK(!called_); |
| 113 called_ = true; | 114 called_ = true; |
| 114 stats_.Clear(); | 115 stats_.Clear(); |
| 115 stats_.number_of_reports = reports.size(); | 116 stats_.number_of_reports = reports.size(); |
| 116 for (const auto* r : reports) { | 117 for (const auto* r : reports) { |
| 117 if (r->type() == StatsReport::kStatsReportTypeSsrc) { | 118 if (r->type() == StatsReport::kStatsReportTypeSsrc) { |
| 118 stats_.timestamp = r->timestamp(); | 119 stats_.timestamp = r->timestamp(); |
| 119 GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel, | 120 GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel, |
| 120 &stats_.audio_output_level); | 121 &stats_.audio_output_level); |
| 121 GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel, | 122 GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel, |
| 122 &stats_.audio_input_level); | 123 &stats_.audio_input_level); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 136 &stats_.srtp_cipher); | 137 &stats_.srtp_cipher); |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 | 141 |
| 141 bool called() const { return called_; } | 142 bool called() const { return called_; } |
| 142 size_t number_of_reports() const { return stats_.number_of_reports; } | 143 size_t number_of_reports() const { return stats_.number_of_reports; } |
| 143 double timestamp() const { return stats_.timestamp; } | 144 double timestamp() const { return stats_.timestamp; } |
| 144 | 145 |
| 145 int AudioOutputLevel() const { | 146 int AudioOutputLevel() const { |
| 146 ASSERT(called_); | 147 RTC_CHECK(called_); |
| 147 return stats_.audio_output_level; | 148 return stats_.audio_output_level; |
| 148 } | 149 } |
| 149 | 150 |
| 150 int AudioInputLevel() const { | 151 int AudioInputLevel() const { |
| 151 ASSERT(called_); | 152 RTC_CHECK(called_); |
| 152 return stats_.audio_input_level; | 153 return stats_.audio_input_level; |
| 153 } | 154 } |
| 154 | 155 |
| 155 int BytesReceived() const { | 156 int BytesReceived() const { |
| 156 ASSERT(called_); | 157 RTC_CHECK(called_); |
| 157 return stats_.bytes_received; | 158 return stats_.bytes_received; |
| 158 } | 159 } |
| 159 | 160 |
| 160 int BytesSent() const { | 161 int BytesSent() const { |
| 161 ASSERT(called_); | 162 RTC_CHECK(called_); |
| 162 return stats_.bytes_sent; | 163 return stats_.bytes_sent; |
| 163 } | 164 } |
| 164 | 165 |
| 165 int AvailableReceiveBandwidth() const { | 166 int AvailableReceiveBandwidth() const { |
| 166 ASSERT(called_); | 167 RTC_CHECK(called_); |
| 167 return stats_.available_receive_bandwidth; | 168 return stats_.available_receive_bandwidth; |
| 168 } | 169 } |
| 169 | 170 |
| 170 std::string DtlsCipher() const { | 171 std::string DtlsCipher() const { |
| 171 ASSERT(called_); | 172 RTC_CHECK(called_); |
| 172 return stats_.dtls_cipher; | 173 return stats_.dtls_cipher; |
| 173 } | 174 } |
| 174 | 175 |
| 175 std::string SrtpCipher() const { | 176 std::string SrtpCipher() const { |
| 176 ASSERT(called_); | 177 RTC_CHECK(called_); |
| 177 return stats_.srtp_cipher; | 178 return stats_.srtp_cipher; |
| 178 } | 179 } |
| 179 | 180 |
| 180 private: | 181 private: |
| 181 bool GetIntValue(const StatsReport* report, | 182 bool GetIntValue(const StatsReport* report, |
| 182 StatsReport::StatsValueName name, | 183 StatsReport::StatsValueName name, |
| 183 int* value) { | 184 int* value) { |
| 184 const StatsReport::Value* v = report->FindValue(name); | 185 const StatsReport::Value* v = report->FindValue(name); |
| 185 if (v) { | 186 if (v) { |
| 186 // TODO(tommi): We should really just be using an int here :-/ | 187 // TODO(tommi): We should really just be using an int here :-/ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 int bytes_sent; | 221 int bytes_sent; |
| 221 int available_receive_bandwidth; | 222 int available_receive_bandwidth; |
| 222 std::string dtls_cipher; | 223 std::string dtls_cipher; |
| 223 std::string srtp_cipher; | 224 std::string srtp_cipher; |
| 224 } stats_; | 225 } stats_; |
| 225 }; | 226 }; |
| 226 | 227 |
| 227 } // namespace webrtc | 228 } // namespace webrtc |
| 228 | 229 |
| 229 #endif // WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ | 230 #endif // WEBRTC_API_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ |
| OLD | NEW |