From 55c3600781a98f70b71c50682363a8dc2d5e8494 Mon Sep 17 00:00:00 2001 From: Tommi Date: Wed, 3 Jul 2024 13:01:35 +0200 Subject: [PATCH] Remove dependencies Some dependencies still exist but are a bit more complex to remove. This CL removes either unused or easily replaced with ToString() instances of ostream usage. In one case, moving the operator<< implementation to the one test file that requires it. Bug: webrtc:8982 Change-Id: Ia5c840b12a42893494af401317a3daf2fe50ba9b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/356240 Commit-Queue: Tomas Gunnarsson Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#42582} --- api/rtc_error.h | 17 ------------ api/units/data_rate.h | 12 --------- api/units/data_size.h | 12 --------- api/units/frequency.h | 12 --------- api/units/time_delta.h | 12 --------- api/units/timestamp.h | 12 --------- media/base/media_channel.h | 2 +- .../video_coding/timing/timing_unittest.cc | 27 ++++++++++++------- p2p/client/basic_port_allocator_unittest.cc | 17 ------------ pc/rtp_media_utils.h | 10 ------- rtc_base/bitrate_tracker_unittest.cc | 12 ++++----- rtc_base/frequency_tracker_unittest.cc | 10 +++---- rtc_base/ip_address.h | 7 ----- test/fake_encoded_frame.cc | 12 --------- test/fake_encoded_frame.h | 6 ----- video/video_receive_stream2_unittest.cc | 6 ++++- 16 files changed, 34 insertions(+), 152 deletions(-) diff --git a/api/rtc_error.h b/api/rtc_error.h index 917db7d4cb..8579ff637f 100644 --- a/api/rtc_error.h +++ b/api/rtc_error.h @@ -11,9 +11,6 @@ #ifndef API_RTC_ERROR_H_ #define API_RTC_ERROR_H_ -#ifdef WEBRTC_UNIT_TEST -#include -#endif // WEBRTC_UNIT_TEST #include #include @@ -164,20 +161,6 @@ class RTC_EXPORT RTCError { RTC_EXPORT absl::string_view ToString(RTCErrorType error); RTC_EXPORT absl::string_view ToString(RTCErrorDetailType error); -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - RTCErrorType error) { - return stream << ToString(error); -} - -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - RTCErrorDetailType error) { - return stream << ToString(error); -} -#endif // WEBRTC_UNIT_TEST - // Helper macro that can be used by implementations to create an error with a // message and log it. `message` should be a string literal or movable // std::string. diff --git a/api/units/data_rate.h b/api/units/data_rate.h index d813c61156..63bf39a3c3 100644 --- a/api/units/data_rate.h +++ b/api/units/data_rate.h @@ -11,10 +11,6 @@ #ifndef API_UNITS_DATA_RATE_H_ #define API_UNITS_DATA_RATE_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - #include #include #include @@ -142,14 +138,6 @@ inline std::string ToLogString(DataRate value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - DataRate value) { - return stream << ToString(value); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // API_UNITS_DATA_RATE_H_ diff --git a/api/units/data_size.h b/api/units/data_size.h index 9df6434fb9..937513f326 100644 --- a/api/units/data_size.h +++ b/api/units/data_size.h @@ -11,10 +11,6 @@ #ifndef API_UNITS_DATA_SIZE_H_ #define API_UNITS_DATA_SIZE_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - #include #include @@ -53,14 +49,6 @@ inline std::string ToLogString(DataSize value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - DataSize value) { - return stream << ToString(value); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // API_UNITS_DATA_SIZE_H_ diff --git a/api/units/frequency.h b/api/units/frequency.h index 06081e4c0d..e0ce2aa2d9 100644 --- a/api/units/frequency.h +++ b/api/units/frequency.h @@ -10,10 +10,6 @@ #ifndef API_UNITS_FREQUENCY_H_ #define API_UNITS_FREQUENCY_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - #include #include #include @@ -89,13 +85,5 @@ inline std::string ToLogString(Frequency value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - Frequency value) { - return stream << ToString(value); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // API_UNITS_FREQUENCY_H_ diff --git a/api/units/time_delta.h b/api/units/time_delta.h index 5981e32dce..bc4c285411 100644 --- a/api/units/time_delta.h +++ b/api/units/time_delta.h @@ -11,10 +11,6 @@ #ifndef API_UNITS_TIME_DELTA_H_ #define API_UNITS_TIME_DELTA_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - #include #include #include @@ -97,14 +93,6 @@ inline std::string ToLogString(TimeDelta value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - TimeDelta value) { - return stream << ToString(value); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // API_UNITS_TIME_DELTA_H_ diff --git a/api/units/timestamp.h b/api/units/timestamp.h index 8aabe05cad..91acc6c254 100644 --- a/api/units/timestamp.h +++ b/api/units/timestamp.h @@ -11,10 +11,6 @@ #ifndef API_UNITS_TIMESTAMP_H_ #define API_UNITS_TIMESTAMP_H_ -#ifdef WEBRTC_UNIT_TEST -#include // no-presubmit-check TODO(webrtc:8982) -#endif // WEBRTC_UNIT_TEST - #include #include @@ -126,14 +122,6 @@ inline std::string ToLogString(Timestamp value) { return ToString(value); } -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& stream, // no-presubmit-check TODO(webrtc:8982) - Timestamp value) { - return stream << ToString(value); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // API_UNITS_TIMESTAMP_H_ diff --git a/media/base/media_channel.h b/media/base/media_channel.h index 970a8f4df5..d656304971 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -99,7 +99,7 @@ static std::string ToStringIfSet(const char* key, template static std::string VectorToString(const std::vector& vals) { - rtc::StringBuilder ost; // no-presubmit-check TODO(webrtc:8982) + rtc::StringBuilder ost; ost << "["; for (size_t i = 0; i < vals.size(); ++i) { if (i > 0) { diff --git a/modules/video_coding/timing/timing_unittest.cc b/modules/video_coding/timing/timing_unittest.cc index 4ba8c4dcd2..ffb831b264 100644 --- a/modules/video_coding/timing/timing_unittest.cc +++ b/modules/video_coding/timing/timing_unittest.cc @@ -38,30 +38,37 @@ MATCHER(HasConsistentVideoDelayTimings, "") { // Delays should be internally consistent. bool m1 = arg.minimum_delay <= arg.target_delay; if (!m1) { - *result_listener << "\nminimum_delay: " << arg.minimum_delay << ", " - << "target_delay: " << arg.target_delay << "\n"; + *result_listener << "\nminimum_delay: " << ToString(arg.minimum_delay) + << ", " << "target_delay: " << ToString(arg.target_delay) + << "\n"; } bool m2 = arg.minimum_delay <= arg.current_delay; if (!m2) { - *result_listener << "\nminimum_delay: " << arg.minimum_delay << ", " - << "current_delay: " << arg.current_delay; + *result_listener << "\nminimum_delay: " << ToString(arg.minimum_delay) + << ", " + << "current_delay: " << ToString(arg.current_delay); } bool m3 = arg.target_delay >= arg.min_playout_delay; if (!m3) { - *result_listener << "\ntarget_delay: " << arg.target_delay << ", " - << "min_playout_delay: " << arg.min_playout_delay << "\n"; + *result_listener << "\ntarget_delay: " << ToString(arg.target_delay) << ", " + << "min_playout_delay: " << ToString(arg.min_playout_delay) + << "\n"; } // TODO(crbug.com/webrtc/15197): Uncomment when this is guaranteed. // bool m4 = arg.target_delay <= arg.max_playout_delay; bool m5 = arg.current_delay >= arg.min_playout_delay; if (!m5) { - *result_listener << "\ncurrent_delay: " << arg.current_delay << ", " - << "min_playout_delay: " << arg.min_playout_delay << "\n"; + *result_listener << "\ncurrent_delay: " << ToString(arg.current_delay) + << ", " + << "min_playout_delay: " << ToString(arg.min_playout_delay) + << "\n"; } bool m6 = arg.current_delay <= arg.max_playout_delay; if (!m6) { - *result_listener << "\ncurrent_delay: " << arg.current_delay << ", " - << "max_playout_delay: " << arg.max_playout_delay << "\n"; + *result_listener << "\ncurrent_delay: " << ToString(arg.current_delay) + << ", " + << "max_playout_delay: " << ToString(arg.max_playout_delay) + << "\n"; } bool m = m1 && m2 && m3 && m5 && m6; diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc index fa244c8024..e68013e0fe 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -11,7 +11,6 @@ #include "p2p/client/basic_port_allocator.h" #include -#include // no-presubmit-check TODO(webrtc:8982) #include "absl/algorithm/container.h" #include "absl/strings/string_view.h" @@ -134,22 +133,6 @@ void CheckStunKeepaliveIntervalOfAllReadyPorts( namespace cricket { -// Helper for dumping candidates -std::ostream& operator<<(std::ostream& os, - const std::vector& candidates) { - os << '['; - bool first = true; - for (const Candidate& c : candidates) { - if (!first) { - os << ", "; - } - os << c.ToString(); - first = false; - } - os << ']'; - return os; -} - class BasicPortAllocatorTestBase : public ::testing::Test, public sigslot::has_slots<> { public: diff --git a/pc/rtp_media_utils.h b/pc/rtp_media_utils.h index 240274fe05..02a491aa86 100644 --- a/pc/rtp_media_utils.h +++ b/pc/rtp_media_utils.h @@ -11,8 +11,6 @@ #ifndef PC_RTP_MEDIA_UTILS_H_ #define PC_RTP_MEDIA_UTILS_H_ -#include // no-presubmit-check TODO(webrtc:8982) - #include "api/rtp_transceiver_direction.h" namespace webrtc { @@ -51,14 +49,6 @@ RtpTransceiverDirection RtpTransceiverDirectionIntersection( RtpTransceiverDirection lhs, RtpTransceiverDirection rhs); -#ifdef WEBRTC_UNIT_TEST -inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& os, // no-presubmit-check TODO(webrtc:8982) - RtpTransceiverDirection direction) { - return os << RtpTransceiverDirectionToString(direction); -} -#endif // WEBRTC_UNIT_TEST - } // namespace webrtc #endif // PC_RTP_MEDIA_UTILS_H_ diff --git a/rtc_base/bitrate_tracker_unittest.cc b/rtc_base/bitrate_tracker_unittest.cc index 2129aebfdd..c9e3d1ea25 100644 --- a/rtc_base/bitrate_tracker_unittest.cc +++ b/rtc_base/bitrate_tracker_unittest.cc @@ -75,7 +75,7 @@ TEST(BitrateTrackerTest, MeasuresConstantRate) { DataSize total_size = kPacketSize; DataRate last_error = DataRate::PlusInfinity(); for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kInterval; total_size += kPacketSize; stats.Update(kPacketSize, now); @@ -95,7 +95,7 @@ TEST(BitrateTrackerTest, MeasuresConstantRate) { // Once window is full, bitrate measurment should be stable. for (TimeDelta i = TimeDelta::Zero(); i < kInterval; i += TimeDelta::Millis(1)) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); EXPECT_EQ(stats.Rate(now + i), kConstantRate); } } @@ -111,7 +111,7 @@ TEST(BitrateTrackerTest, IncreasingThenDecreasingBitrate) { stats.Update(kLargePacketSize, now); for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kLargeInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kLargeInterval; stats.Update(kLargePacketSize, now); } @@ -120,7 +120,7 @@ TEST(BitrateTrackerTest, IncreasingThenDecreasingBitrate) { // Decrease bitrate with smaller measurments. for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kLargeInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kLargeInterval; stats.Update(kSmallPacketSize, now); @@ -133,7 +133,7 @@ TEST(BitrateTrackerTest, IncreasingThenDecreasingBitrate) { // Increase bitrate with more frequent measurments. for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kSmallInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kSmallInterval; stats.Update(kSmallPacketSize, now); @@ -230,7 +230,7 @@ TEST(BitrateTrackerTest, HandlesZeroCounts) { EXPECT_GT(last_bitrate, DataRate::Zero()); now += kInterval; while (now < start + kWindow) { - SCOPED_TRACE(now - start); + SCOPED_TRACE(ToString(now - start)); stats.Update(0, now); absl::optional bitrate = stats.Rate(now); diff --git a/rtc_base/frequency_tracker_unittest.cc b/rtc_base/frequency_tracker_unittest.cc index 00788c3ee8..7f0b3d5cbd 100644 --- a/rtc_base/frequency_tracker_unittest.cc +++ b/rtc_base/frequency_tracker_unittest.cc @@ -70,7 +70,7 @@ TEST(FrequencyTrackerTest, MeasuresConstantRate) { stats.Update(now); Frequency last_error = Frequency::PlusInfinity(); for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kInterval; stats.Update(now); @@ -88,7 +88,7 @@ TEST(FrequencyTrackerTest, MeasuresConstantRate) { // Once window is full, rate measurment should be stable. for (TimeDelta i = TimeDelta::Zero(); i < kInterval; i += TimeDelta::Millis(1)) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); EXPECT_EQ(stats.Rate(now + i), kConstantRate); } } @@ -123,7 +123,7 @@ TEST(FrequencyTrackerTest, IncreasingThenDecreasingRate) { stats.Update(kLargeSize, now); for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kLargeInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kLargeInterval; stats.Update(kLargeSize, now); } @@ -132,7 +132,7 @@ TEST(FrequencyTrackerTest, IncreasingThenDecreasingRate) { // Decrease rate with smaller measurments. for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kLargeInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kLargeInterval; stats.Update(kSmallSize, now); @@ -145,7 +145,7 @@ TEST(FrequencyTrackerTest, IncreasingThenDecreasingRate) { // Increase rate with more frequent measurments. for (TimeDelta i = TimeDelta::Zero(); i < kWindow; i += kSmallInterval) { - SCOPED_TRACE(i); + SCOPED_TRACE(ToString(i)); now += kSmallInterval; stats.Update(kSmallSize, now); diff --git a/rtc_base/ip_address.h b/rtc_base/ip_address.h index c015206ab3..c89fa9f868 100644 --- a/rtc_base/ip_address.h +++ b/rtc_base/ip_address.h @@ -82,13 +82,6 @@ class RTC_EXPORT IPAddress { bool operator<(const IPAddress& other) const; bool operator>(const IPAddress& other) const; -#ifdef WEBRTC_UNIT_TEST - inline std::ostream& operator<<( // no-presubmit-check TODO(webrtc:8982) - std::ostream& os) { // no-presubmit-check TODO(webrtc:8982) - return os << ToString(); - } -#endif // WEBRTC_UNIT_TEST - int family() const { return family_; } in_addr ipv4_address() const; in6_addr ipv6_address() const; diff --git a/test/fake_encoded_frame.cc b/test/fake_encoded_frame.cc index 7ab63cbc76..7a74bf98e9 100644 --- a/test/fake_encoded_frame.cc +++ b/test/fake_encoded_frame.cc @@ -15,18 +15,6 @@ #include "api/video/video_frame_type.h" namespace webrtc { - -void PrintTo(const EncodedFrame& frame, - std::ostream* os) /* no-presubmit-check TODO(webrtc:8982) */ { - *os << "EncodedFrame with id=" << frame.Id() - << " rtp=" << frame.RtpTimestamp() << " size=" << frame.size() - << " refs=["; - for (size_t ref = 0; ref < frame.num_references; ++ref) { - *os << frame.references[ref] << ","; - } - *os << "]"; -} - namespace test { int64_t FakeEncodedFrame::ReceivedTime() const { diff --git a/test/fake_encoded_frame.h b/test/fake_encoded_frame.h index b4f120bfd9..36d478156d 100644 --- a/test/fake_encoded_frame.h +++ b/test/fake_encoded_frame.h @@ -12,7 +12,6 @@ #define TEST_FAKE_ENCODED_FRAME_H_ #include -#include // no-presubmit-check TODO(webrtc:8982) #include #include "api/rtp_packet_infos.h" @@ -21,11 +20,6 @@ #include "test/gmock.h" namespace webrtc { - -// For test printing. -void PrintTo(const EncodedFrame& frame, - std::ostream* os); // no-presubmit-check TODO(webrtc:8982) - namespace test { class FakeEncodedFrame : public EncodedFrame { diff --git a/video/video_receive_stream2_unittest.cc b/video/video_receive_stream2_unittest.cc index 5e0f1f07c5..32ee1f18a6 100644 --- a/video/video_receive_stream2_unittest.cc +++ b/video/video_receive_stream2_unittest.cc @@ -15,7 +15,7 @@ #include #include #include -#include +#include // no-presubmit-check bugs.webrtc.org/8982 #include #include #include @@ -68,6 +68,10 @@ void PrintTo(const RecordableEncodedFrame::EncodedResolution& value, *os << value.width << "x" << value.height; } +inline std::ostream& operator<<(std::ostream& stream, Timestamp value) { + return stream << ToString(value); +} + void PrintTo(const RecordableEncodedFrame& value, std::ostream* os) { *os << "RecordableEncodedFrame(render_time=" << value.render_time() << " resolution=" << ::testing::PrintToString(value.resolution()) << ")";