aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorSebastian Jansson <srte@webrtc.org>2018-03-29 11:01:32 +0200
committerCommit Bot <commit-bot@chromium.org>2018-03-29 11:21:37 +0000
commit01cb965d34f6aef54cd52c334a8f036a3b01fc1c (patch)
treea2bc04d2bf0914da7d787d5bfcdf26cff7a0b173 /modules
parent003211c5da78e51a04229b3f28da8a831224e541 (diff)
downloadwebrtc-01cb965d34f6aef54cd52c334a8f036a3b01fc1c.tar.gz
Moved ostream operators for network units to test.
Added ToString functions in a separate header and move the ostream operators to a test only header. Bug: webrtc:8982 Change-Id: If547173aa39bbae2244531e2d3091886f14eae31 Reviewed-on: https://webrtc-review.googlesource.com/65280 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22674}
Diffstat (limited to 'modules')
-rw-r--r--modules/congestion_controller/bbr/BUILD.gn1
-rw-r--r--modules/congestion_controller/bbr/data_transfer_tracker.cc8
-rw-r--r--modules/congestion_controller/bbr/rtt_stats.cc3
-rw-r--r--modules/congestion_controller/bbr/windowed_filter_unittest.cc1
-rw-r--r--modules/congestion_controller/network_control/BUILD.gn2
-rw-r--r--modules/congestion_controller/network_control/include/network_units.h6
-rw-r--r--modules/congestion_controller/network_control/include/network_units_to_string.h22
-rw-r--r--modules/congestion_controller/network_control/network_units.cc38
-rw-r--r--modules/congestion_controller/network_control/network_units_to_string.cc64
-rw-r--r--modules/congestion_controller/network_control/test/network_control_tester.cc1
-rw-r--r--modules/congestion_controller/network_control/test/network_ostream_operators.cc23
-rw-r--r--modules/congestion_controller/network_control/test/network_ostream_operators.h13
12 files changed, 133 insertions, 49 deletions
diff --git a/modules/congestion_controller/bbr/BUILD.gn b/modules/congestion_controller/bbr/BUILD.gn
index 0e8bb58e1e..3773a6cd09 100644
--- a/modules/congestion_controller/bbr/BUILD.gn
+++ b/modules/congestion_controller/bbr/BUILD.gn
@@ -48,6 +48,7 @@ if (rtc_include_tests) {
":windowed_filter",
"../../../test:test_support",
"../network_control",
+ "../network_control:network_control_test",
]
}
}
diff --git a/modules/congestion_controller/bbr/data_transfer_tracker.cc b/modules/congestion_controller/bbr/data_transfer_tracker.cc
index 502d3f1972..5de85efb8b 100644
--- a/modules/congestion_controller/bbr/data_transfer_tracker.cc
+++ b/modules/congestion_controller/bbr/data_transfer_tracker.cc
@@ -24,10 +24,10 @@ void DataTransferTracker::AddSample(DataSize size_delta,
Timestamp send_time,
Timestamp ack_time) {
size_sum_ += size_delta;
- if (!samples_.empty()) {
- RTC_DCHECK_GE(send_time, samples_.back().send_time);
- RTC_DCHECK_GE(ack_time, samples_.back().ack_time);
- }
+
+ RTC_DCHECK(samples_.empty() || send_time >= samples_.back().send_time);
+ RTC_DCHECK(samples_.empty() || ack_time >= samples_.back().ack_time);
+
if (!samples_.empty() && ack_time == samples_.back().ack_time) {
samples_.back().send_time = send_time;
samples_.back().size_sum = size_sum_;
diff --git a/modules/congestion_controller/bbr/rtt_stats.cc b/modules/congestion_controller/bbr/rtt_stats.cc
index a7cfea81d4..3d197e304e 100644
--- a/modules/congestion_controller/bbr/rtt_stats.cc
+++ b/modules/congestion_controller/bbr/rtt_stats.cc
@@ -13,6 +13,7 @@
#include <cstdlib>
#include "modules/congestion_controller/network_control/include/network_units.h"
+#include "modules/congestion_controller/network_control/include/network_units_to_string.h"
#include "rtc_base/logging.h"
namespace webrtc {
@@ -49,7 +50,7 @@ void RttStats::UpdateRtt(TimeDelta send_delta,
if (send_delta.IsInfinite() || send_delta <= TimeDelta::Zero()) {
RTC_LOG(LS_WARNING) << "Ignoring measured send_delta, because it's is "
<< "either infinite, zero, or negative. send_delta = "
- << send_delta;
+ << ToString(send_delta);
return;
}
diff --git a/modules/congestion_controller/bbr/windowed_filter_unittest.cc b/modules/congestion_controller/bbr/windowed_filter_unittest.cc
index 2edddc6d6f..8a8d726e70 100644
--- a/modules/congestion_controller/bbr/windowed_filter_unittest.cc
+++ b/modules/congestion_controller/bbr/windowed_filter_unittest.cc
@@ -11,6 +11,7 @@
#include "modules/congestion_controller/bbr/windowed_filter.h"
#include "modules/congestion_controller/bbr/rtt_stats.h"
+#include "modules/congestion_controller/network_control/test/network_ostream_operators.h"
#include "test/gtest.h"
namespace webrtc {
diff --git a/modules/congestion_controller/network_control/BUILD.gn b/modules/congestion_controller/network_control/BUILD.gn
index b57cc5bdd9..4ced3f2e80 100644
--- a/modules/congestion_controller/network_control/BUILD.gn
+++ b/modules/congestion_controller/network_control/BUILD.gn
@@ -13,8 +13,10 @@ rtc_static_library("network_control") {
"include/network_control.h",
"include/network_types.h",
"include/network_units.h",
+ "include/network_units_to_string.h",
"network_types.cc",
"network_units.cc",
+ "network_units_to_string.cc",
]
deps = [
diff --git a/modules/congestion_controller/network_control/include/network_units.h b/modules/congestion_controller/network_control/include/network_units.h
index 2b05981d93..60cbb519d9 100644
--- a/modules/congestion_controller/network_control/include/network_units.h
+++ b/modules/congestion_controller/network_control/include/network_units.h
@@ -12,7 +12,6 @@
#define MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_UNITS_H_
#include <stdint.h>
#include <limits>
-#include <ostream>
#include "rtc_base/checks.h"
namespace webrtc {
@@ -386,11 +385,6 @@ TimeDelta operator/(const DataSize& size, const DataRate& rate);
DataSize operator*(const DataRate& rate, const TimeDelta& duration);
DataSize operator*(const TimeDelta& duration, const DataRate& rate);
-::std::ostream& operator<<(::std::ostream& os, const DataRate& datarate);
-::std::ostream& operator<<(::std::ostream& os, const DataSize& datasize);
-::std::ostream& operator<<(::std::ostream& os, const Timestamp& timestamp);
-::std::ostream& operator<<(::std::ostream& os, const TimeDelta& delta);
-
} // namespace webrtc
#endif // MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_UNITS_H_
diff --git a/modules/congestion_controller/network_control/include/network_units_to_string.h b/modules/congestion_controller/network_control/include/network_units_to_string.h
new file mode 100644
index 0000000000..2d62b64707
--- /dev/null
+++ b/modules/congestion_controller/network_control/include/network_units_to_string.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_UNITS_TO_STRING_H_
+#define MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_UNITS_TO_STRING_H_
+
+#include <string>
+#include "modules/congestion_controller/network_control/include/network_units.h"
+
+namespace webrtc {
+std::string ToString(const DataRate& datarate);
+std::string ToString(const DataSize& datarate);
+std::string ToString(const Timestamp& datarate);
+std::string ToString(const TimeDelta& datarate);
+} // namespace webrtc
+#endif // MODULES_CONGESTION_CONTROLLER_NETWORK_CONTROL_INCLUDE_NETWORK_UNITS_TO_STRING_H_
diff --git a/modules/congestion_controller/network_control/network_units.cc b/modules/congestion_controller/network_control/network_units.cc
index f48d453cd7..48eb8c48ac 100644
--- a/modules/congestion_controller/network_control/network_units.cc
+++ b/modules/congestion_controller/network_control/network_units.cc
@@ -50,43 +50,5 @@ DataSize operator*(const TimeDelta& duration, const DataRate& rate) {
return rate * duration;
}
-::std::ostream& operator<<(::std::ostream& os, const DataRate& value) {
- if (value.IsInfinite()) {
- return os << "inf bps";
- } else if (!value.IsInitialized()) {
- return os << "? bps";
- } else {
- return os << value.bps() << " bps";
- }
-}
-::std::ostream& operator<<(::std::ostream& os, const DataSize& value) {
- if (value.IsInfinite()) {
- return os << "inf bytes";
- } else if (!value.IsInitialized()) {
- return os << "? bytes";
- } else {
- return os << value.bytes() << " bytes";
- }
-}
-::std::ostream& operator<<(::std::ostream& os, const Timestamp& value) {
- if (value.IsInfinite()) {
- return os << "inf ms";
- } else if (!value.IsInitialized()) {
- return os << "? ms";
- } else {
- return os << value.ms() << " ms";
- }
-}
-::std::ostream& operator<<(::std::ostream& os, const TimeDelta& value) {
- if (value.IsPlusInfinity()) {
- return os << "+inf ms";
- } else if (value.IsMinusInfinity()) {
- return os << "-inf ms";
- } else if (!value.IsInitialized()) {
- return os << "? ms";
- } else {
- return os << value.ms() << " ms";
- }
-}
} // namespace webrtc
diff --git a/modules/congestion_controller/network_control/network_units_to_string.cc b/modules/congestion_controller/network_control/network_units_to_string.cc
new file mode 100644
index 0000000000..bbc6a250b1
--- /dev/null
+++ b/modules/congestion_controller/network_control/network_units_to_string.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "modules/congestion_controller/network_control/include/network_units_to_string.h"
+#include "rtc_base/strings/string_builder.h"
+
+namespace webrtc {
+std::string ToString(const DataRate& value) {
+ char buf[64];
+ rtc::SimpleStringBuilder sb(buf);
+ if (value.IsInfinite()) {
+ sb << "inf bps";
+ } else if (!value.IsInitialized()) {
+ sb << "? bps";
+ } else {
+ sb << value.bps() << " bps";
+ }
+ return sb.str();
+}
+std::string ToString(const DataSize& value) {
+ char buf[64];
+ rtc::SimpleStringBuilder sb(buf);
+ if (value.IsInfinite()) {
+ sb << "inf bytes";
+ } else if (!value.IsInitialized()) {
+ sb << "? bytes";
+ } else {
+ sb << value.bytes() << " bytes";
+ }
+ return sb.str();
+}
+std::string ToString(const Timestamp& value) {
+ char buf[64];
+ rtc::SimpleStringBuilder sb(buf);
+ if (value.IsInfinite()) {
+ sb << "inf ms";
+ } else if (!value.IsInitialized()) {
+ sb << "? ms";
+ } else {
+ sb << value.ms() << " ms";
+ }
+ return sb.str();
+}
+std::string ToString(const TimeDelta& value) {
+ char buf[64];
+ rtc::SimpleStringBuilder sb(buf);
+ if (value.IsPlusInfinity()) {
+ sb << "+inf ms";
+ } else if (value.IsMinusInfinity()) {
+ sb << "-inf ms";
+ } else if (!value.IsInitialized()) {
+ sb << "? ms";
+ } else {
+ sb << value.ms() << " ms";
+ }
+ return sb.str();
+}
+} // namespace webrtc
diff --git a/modules/congestion_controller/network_control/test/network_control_tester.cc b/modules/congestion_controller/network_control/test/network_control_tester.cc
index 67d5611d83..0fe6308384 100644
--- a/modules/congestion_controller/network_control/test/network_control_tester.cc
+++ b/modules/congestion_controller/network_control/test/network_control_tester.cc
@@ -9,6 +9,7 @@
*/
#include "modules/congestion_controller/network_control/test/network_control_tester.h"
+#include "modules/congestion_controller/network_control/test/network_ostream_operators.h"
#include <algorithm>
diff --git a/modules/congestion_controller/network_control/test/network_ostream_operators.cc b/modules/congestion_controller/network_control/test/network_ostream_operators.cc
index 819628a557..353c3c8c58 100644
--- a/modules/congestion_controller/network_control/test/network_ostream_operators.cc
+++ b/modules/congestion_controller/network_control/test/network_ostream_operators.cc
@@ -9,8 +9,31 @@
*/
#include "modules/congestion_controller/network_control/test/network_ostream_operators.h"
+#include "modules/congestion_controller/network_control/include/network_units_to_string.h"
namespace webrtc {
+
+std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const DataRate& value) {
+ return os << ToString(value);
+}
+std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const DataSize& value) {
+ return os << ToString(value);
+}
+std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const Timestamp& value) {
+ return os << ToString(value);
+}
+std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const TimeDelta& value) {
+ return os << ToString(value);
+}
+
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
const CongestionWindow& window) {
diff --git a/modules/congestion_controller/network_control/test/network_ostream_operators.h b/modules/congestion_controller/network_control/test/network_ostream_operators.h
index b7e54b87bd..2177aa9e4b 100644
--- a/modules/congestion_controller/network_control/test/network_ostream_operators.h
+++ b/modules/congestion_controller/network_control/test/network_ostream_operators.h
@@ -17,6 +17,19 @@
namespace webrtc {
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const DataRate& datarate);
+::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ ::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const DataSize& datasize);
+::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ ::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const Timestamp& timestamp);
+::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ ::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
+ const TimeDelta& delta);
+
+::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
+ ::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)
const CongestionWindow& window);
::std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982)
::std::ostream& os, // no-presubmit-check TODO(webrtc:8982)