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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/time_util_unittest.cc

Issue 1535113002: [rtp_rtcp] time helper functions (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #include "webrtc/modules/rtp_rtcp/source/time_util.h"
11
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace webrtc {
15
16 TEST(TimeUtilTest, CompactNtp) {
17 const uint32_t kNtpSec = 0x12345678;
18 const uint32_t kNtpFrac = 0x23456789;
19 const NtpTime kNtp(kNtpSec, kNtpFrac);
20 const uint32_t kNtpMid = 0x56782345;
21 EXPECT_EQ(kNtpMid, CompactNtp(kNtp));
22 }
23
24 TEST(TimeUtilTest, CompactNtpToMs) {
25 const NtpTime ntp1(0x12345, 0x23456);
26 const NtpTime ntp2(0x12654, 0x64335);
27 uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
28 uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
29
30 uint32_t ntp_to_ms_diff = CompactNtpToMs(ntp_diff);
31
32 EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
33 }
34
35 TEST(TimeUtilTest, CompactNtpToMsWithWrap) {
36 const NtpTime ntp1(0x1ffff, 0x23456);
37 const NtpTime ntp2(0x20000, 0x64335);
38 uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
39
40 // While ntp2 > ntp1, there compact ntp presentation happen to be opposite.
41 // That shouldn't be a problem as long as unsigned arithmetic is used.
42 ASSERT_GT(ntp2.ToMs(), ntp1.ToMs());
43 ASSERT_LT(CompactNtp(ntp2), CompactNtp(ntp1));
44
45 uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
46 uint32_t ntp_to_ms_diff = CompactNtpToMs(ntp_diff);
åsapersson 2015/12/21 11:19:17 How about this diff? uint32_t ms1 = CompactNtpToMs
danilchap 2015/12/21 12:49:50 I do not see a valid use case in this example: Ti
åsapersson 2015/12/21 15:16:20 Yes that makes it more clear.
47
48 EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
49 }
50
51 TEST(TimeUtilTest, CompactNtpToMsLarge) {
52 const NtpTime ntp1(0x10000, 0x23456);
53 const NtpTime ntp2(0x1ffff, 0x64335);
54 uint32_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
55 // Ntp difference close to maximum of ~18 hours should convert correctly too.
56 ASSERT_GT(ms_diff, 18u * 3600 * 1000);
57 uint32_t ntp_diff = CompactNtp(ntp2) - CompactNtp(ntp1);
58 uint32_t ntp_to_ms_diff = CompactNtpToMs(ntp_diff);
59
60 EXPECT_NEAR(ms_diff, ntp_to_ms_diff, 1);
61 }
62 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698