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}
This commit is contained in:
Sebastian Jansson
2018-03-29 11:01:32 +02:00
committed by Commit Bot
parent 003211c5da
commit 01cb965d34
12 changed files with 133 additions and 49 deletions

View File

@ -48,6 +48,7 @@ if (rtc_include_tests) {
":windowed_filter",
"../../../test:test_support",
"../network_control",
"../network_control:network_control_test",
]
}
}

View File

@ -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_;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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 = [

View File

@ -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_

View File

@ -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_

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -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) {

View File

@ -15,6 +15,19 @@
#include "modules/congestion_controller/network_control/include/network_types.h"
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);