Adds debug printing of units in unit tests.

Bug: webrtc:9656
Change-Id: I643b79bc214643f47b2b64967ce713665dbef5c9
Reviewed-on: https://webrtc-review.googlesource.com/95652
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24436}
This commit is contained in:
Sebastian Jansson
2018-08-23 14:44:05 +02:00
committed by Commit Bot
parent 1946a3f0fe
commit 2afd281ec4
8 changed files with 70 additions and 3 deletions

View File

@ -20,7 +20,11 @@ std::string ToString(const DataRate& value) {
if (value.IsInfinite()) { if (value.IsInfinite()) {
sb << "inf bps"; sb << "inf bps";
} else { } 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(); return sb.str();
} }

View File

@ -10,6 +10,11 @@
#ifndef API_UNITS_DATA_RATE_H_ #ifndef API_UNITS_DATA_RATE_H_
#define API_UNITS_DATA_RATE_H_ #define API_UNITS_DATA_RATE_H_
#ifdef UNIT_TEST
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#endif // UNIT_TEST
#include <stdint.h> #include <stdint.h>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
@ -197,6 +202,14 @@ inline DataSize operator*(const TimeDelta& duration, const DataRate& rate) {
std::string ToString(const DataRate& value); 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 } // namespace webrtc
#endif // API_UNITS_DATA_RATE_H_ #endif // API_UNITS_DATA_RATE_H_

View File

@ -11,6 +11,10 @@
#ifndef API_UNITS_DATA_SIZE_H_ #ifndef API_UNITS_DATA_SIZE_H_
#define API_UNITS_DATA_SIZE_H_ #define API_UNITS_DATA_SIZE_H_
#ifdef UNIT_TEST
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#endif // UNIT_TEST
#include <stdint.h> #include <stdint.h>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
@ -149,6 +153,14 @@ inline DataSize operator/(const DataSize& size, const int64_t& scalar) {
std::string ToString(const DataSize& value); 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 } // namespace webrtc
#endif // API_UNITS_DATA_SIZE_H_ #endif // API_UNITS_DATA_SIZE_H_

View File

@ -22,7 +22,12 @@ std::string ToString(const TimeDelta& value) {
} else if (value.IsMinusInfinity()) { } else if (value.IsMinusInfinity()) {
sb << "-inf ms"; sb << "-inf ms";
} else { } 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(); return sb.str();
} }

View File

@ -11,6 +11,10 @@
#ifndef API_UNITS_TIME_DELTA_H_ #ifndef API_UNITS_TIME_DELTA_H_
#define API_UNITS_TIME_DELTA_H_ #define API_UNITS_TIME_DELTA_H_
#ifdef UNIT_TEST
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#endif // UNIT_TEST
#include <stdint.h> #include <stdint.h>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
@ -253,6 +257,15 @@ inline TimeDelta operator/(const TimeDelta& delta, const int64_t& scalar) {
return TimeDelta::us(delta.us() / scalar); return TimeDelta::us(delta.us() / scalar);
} }
std::string ToString(const TimeDelta& value); 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 } // namespace webrtc
#endif // API_UNITS_TIME_DELTA_H_ #endif // API_UNITS_TIME_DELTA_H_

View File

@ -19,7 +19,10 @@ std::string ToString(const Timestamp& value) {
if (value.IsInfinite()) { if (value.IsInfinite()) {
sb << "inf ms"; sb << "inf ms";
} else { } else {
sb << value.ms() << " ms"; if (value.ms() % 1000 == 0)
sb << value.seconds() << " s";
else
sb << value.ms() << " ms";
} }
return sb.str(); return sb.str();
} }

View File

@ -11,6 +11,10 @@
#ifndef API_UNITS_TIMESTAMP_H_ #ifndef API_UNITS_TIMESTAMP_H_
#define API_UNITS_TIMESTAMP_H_ #define API_UNITS_TIMESTAMP_H_
#ifdef UNIT_TEST
#include <ostream> // no-presubmit-check TODO(webrtc:8982)
#endif // UNIT_TEST
#include <stdint.h> #include <stdint.h>
#include <limits> #include <limits>
#include <string> #include <string>
@ -203,6 +207,14 @@ class Timestamp {
std::string ToString(const Timestamp& value); 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 } // namespace webrtc
#endif // API_UNITS_TIMESTAMP_H_ #endif // API_UNITS_TIMESTAMP_H_

View File

@ -157,6 +157,10 @@ config("suppress_warning_4373") {
} }
} }
config("test_main_direct_config") {
visibility = [ ":*" ]
defines = [ "UNIT_TEST" ]
}
rtc_source_set("test_support") { rtc_source_set("test_support") {
visibility = [ "*" ] visibility = [ "*" ]
testonly = true testonly = true
@ -177,6 +181,7 @@ rtc_source_set("test_support") {
public_deps += [ ":test_support_objc" ] public_deps += [ ":test_support_objc" ]
} }
public_configs = [ ":test_main_direct_config" ]
deps = [ deps = [
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",
"//testing/gmock", "//testing/gmock",