diff --git a/api/units/data_rate.cc b/api/units/data_rate.cc index 4e31d51f46..9170627715 100644 --- a/api/units/data_rate.cc +++ b/api/units/data_rate.cc @@ -20,7 +20,11 @@ std::string ToString(const DataRate& value) { if (value.IsInfinite()) { sb << "inf bps"; } else { - sb << value.bps() << " bps"; + if (value.bps() == 0 || value.bps() % 1000 != 0) { + sb << value.bps() << " bps"; + } else { + sb << value.kbps() << " kbps"; + } } return sb.str(); } diff --git a/api/units/data_rate.h b/api/units/data_rate.h index 47a143c889..5c421d4c43 100644 --- a/api/units/data_rate.h +++ b/api/units/data_rate.h @@ -10,6 +10,11 @@ #ifndef API_UNITS_DATA_RATE_H_ #define API_UNITS_DATA_RATE_H_ + +#ifdef UNIT_TEST +#include // no-presubmit-check TODO(webrtc:8982) +#endif // UNIT_TEST + #include #include #include @@ -197,6 +202,14 @@ inline DataSize operator*(const TimeDelta& duration, const DataRate& rate) { std::string ToString(const DataRate& value); +#ifdef 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 // 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 00ab2eccf7..ac61a6f5dd 100644 --- a/api/units/data_size.h +++ b/api/units/data_size.h @@ -11,6 +11,10 @@ #ifndef API_UNITS_DATA_SIZE_H_ #define API_UNITS_DATA_SIZE_H_ +#ifdef UNIT_TEST +#include // no-presubmit-check TODO(webrtc:8982) +#endif // UNIT_TEST + #include #include #include @@ -149,6 +153,14 @@ inline DataSize operator/(const DataSize& size, const int64_t& scalar) { std::string ToString(const DataSize& value); +#ifdef 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 // UNIT_TEST + } // namespace webrtc #endif // API_UNITS_DATA_SIZE_H_ diff --git a/api/units/time_delta.cc b/api/units/time_delta.cc index 398df77659..d38387a566 100644 --- a/api/units/time_delta.cc +++ b/api/units/time_delta.cc @@ -22,7 +22,12 @@ std::string ToString(const TimeDelta& value) { } else if (value.IsMinusInfinity()) { sb << "-inf ms"; } else { - sb << value.ms() << " ms"; + if (value.us() == 0 || (value.us() % 1000) != 0) + sb << value.us() << " us"; + else if (value.ms() % 1000 != 0) + sb << value.ms() << " ms"; + else + sb << value.seconds() << " s"; } return sb.str(); } diff --git a/api/units/time_delta.h b/api/units/time_delta.h index 1155eb526b..b82047285f 100644 --- a/api/units/time_delta.h +++ b/api/units/time_delta.h @@ -11,6 +11,10 @@ #ifndef API_UNITS_TIME_DELTA_H_ #define API_UNITS_TIME_DELTA_H_ +#ifdef UNIT_TEST +#include // no-presubmit-check TODO(webrtc:8982) +#endif // UNIT_TEST + #include #include #include @@ -253,6 +257,15 @@ inline TimeDelta operator/(const TimeDelta& delta, const int64_t& scalar) { return TimeDelta::us(delta.us() / scalar); } std::string ToString(const TimeDelta& value); + +#ifdef 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 // UNIT_TEST + } // namespace webrtc #endif // API_UNITS_TIME_DELTA_H_ diff --git a/api/units/timestamp.cc b/api/units/timestamp.cc index 4b2c44b9a7..feb144789c 100644 --- a/api/units/timestamp.cc +++ b/api/units/timestamp.cc @@ -19,7 +19,10 @@ std::string ToString(const Timestamp& value) { if (value.IsInfinite()) { sb << "inf ms"; } else { - sb << value.ms() << " ms"; + if (value.ms() % 1000 == 0) + sb << value.seconds() << " s"; + else + sb << value.ms() << " ms"; } return sb.str(); } diff --git a/api/units/timestamp.h b/api/units/timestamp.h index 1b5e84ff60..6e5e3925ac 100644 --- a/api/units/timestamp.h +++ b/api/units/timestamp.h @@ -11,6 +11,10 @@ #ifndef API_UNITS_TIMESTAMP_H_ #define API_UNITS_TIMESTAMP_H_ +#ifdef UNIT_TEST +#include // no-presubmit-check TODO(webrtc:8982) +#endif // UNIT_TEST + #include #include #include @@ -203,6 +207,14 @@ class Timestamp { std::string ToString(const Timestamp& value); +#ifdef 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 // UNIT_TEST + } // namespace webrtc #endif // API_UNITS_TIMESTAMP_H_ diff --git a/test/BUILD.gn b/test/BUILD.gn index b5ec01bf4f..ada60e2ce3 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -157,6 +157,10 @@ config("suppress_warning_4373") { } } +config("test_main_direct_config") { + visibility = [ ":*" ] + defines = [ "UNIT_TEST" ] +} rtc_source_set("test_support") { visibility = [ "*" ] testonly = true @@ -177,6 +181,7 @@ rtc_source_set("test_support") { public_deps += [ ":test_support_objc" ] } + public_configs = [ ":test_main_direct_config" ] deps = [ "../rtc_base:rtc_base_approved", "//testing/gmock",