Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: webrtc/modules/rtp_rtcp/source/time_util_unittest.cc

Issue 1763823003: rtt calculation handles time go backwards (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/time_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/time_util_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/time_util_unittest.cc b/webrtc/modules/rtp_rtcp/source/time_util_unittest.cc
index 7efb83ccadc50e24cea84b40a87e450b51e3ac37..8333a64e70aa2dcac51d504608b8bc42961d9e80 100644
--- a/webrtc/modules/rtp_rtcp/source/time_util_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/time_util_unittest.cc
@@ -21,21 +21,21 @@ TEST(TimeUtilTest, CompactNtp) {
EXPECT_EQ(kNtpMid, CompactNtp(kNtp));
}
-TEST(TimeUtilTest, CompactNtpToMs) {
+TEST(TimeUtilTest, CompactNtpRttToMs) {
const NtpTime ntp1(0x12345, 0x23456);
const NtpTime ntp2(0x12654, 0x64335);
- uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
+ int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
- uint32_t ntp_to_ms_diff = CompactNtpIntervalToMs(ntp_diff);
+ int64_t ntp_to_ms_diff = CompactNtpRttToMs(ntp_diff);
EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
}
-TEST(TimeUtilTest, CompactNtpToMsWithWrap) {
+TEST(TimeUtilTest, CompactNtpRttToMsWithWrap) {
const NtpTime ntp1(0x1ffff, 0x23456);
const NtpTime ntp2(0x20000, 0x64335);
- uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
+ int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
// While ntp2 > ntp1, there compact ntp presentation happen to be opposite.
// That shouldn't be a problem as long as unsigned arithmetic is used.
@@ -43,20 +43,31 @@ TEST(TimeUtilTest, CompactNtpToMsWithWrap) {
ASSERT_LT(CompactNtp(ntp2), CompactNtp(ntp1));
uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
- uint32_t ntp_to_ms_diff = CompactNtpIntervalToMs(ntp_diff);
+ int64_t ntp_to_ms_diff = CompactNtpRttToMs(ntp_diff);
EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
}
-TEST(TimeUtilTest, CompactNtpToMsLarge) {
- const NtpTime ntp1(0x10000, 0x23456);
- const NtpTime ntp2(0x1ffff, 0x64335);
- uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
- // Ntp difference close to maximum of ~18 hours should convert correctly too.
- ASSERT_GT(ms_diff, 18u * 3600 * 1000);
+TEST(TimeUtilTest, CompactNtpRttToMsLarge) {
+ const NtpTime ntp1(0x10000, 0x00006);
+ const NtpTime ntp2(0x17fff, 0xffff5);
+ int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
+ // Ntp difference close to 2^15 seconds should convert correctly too.
+ ASSERT_NEAR(ms_diff, ((1 << 15) - 1) * 1000, 1);
uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
- uint32_t ntp_to_ms_diff = CompactNtpIntervalToMs(ntp_diff);
+ int64_t ntp_to_ms_diff = CompactNtpRttToMs(ntp_diff);
EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
}
+
+TEST(TimeUtilTest, CompactNtpRttToMsNegative) {
+ const NtpTime ntp1(0x20000, 0x23456);
+ const NtpTime ntp2(0x1ffff, 0x64335);
+ int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
+ ASSERT_GT(0, ms_diff);
+ // Ntp difference close to 2^16 seconds should be treated as negative.
+ uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
+ int64_t ntp_to_ms_diff = CompactNtpRttToMs(ntp_diff);
+ EXPECT_EQ(1, ntp_to_ms_diff);
+}
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/time_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698