Bug 1772053 - Enable dynamic code disable mitigations only on Windows 10 1703+ r...
[gecko.git] / dom / media / gtest / TestRTCStatsTimestampMaker.cpp
blob931d5e107da86838fe10de6fae180b585dae3f26
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include <cmath>
8 #include "gtest/gtest.h"
9 #include "libwebrtcglue/SystemTime.h"
11 using namespace mozilla;
12 using namespace dom;
14 TEST(RTCStatsTimestampMakerRealtimeClock, ConvertTimestampToNtpTime)
16 RTCStatsTimestampMaker maker;
17 RTCStatsTimestampMakerRealtimeClock clock(maker);
18 constexpr auto ntpTo1Jan1970Ms = webrtc::kNtpJan1970 * 1000LL;
19 for (int i = 1000; i < 20000; i += 93) {
20 const auto t = webrtc::Timestamp::Micros(i);
21 const auto ntp = clock.ConvertTimestampToNtpTime(t);
22 // Because of precision differences, these round to a specific millisecond
23 // slightly differently.
24 EXPECT_NEAR(ntp.ToMs() - ntpTo1Jan1970Ms,
25 maker.ConvertRealtimeTo1Jan1970(t).ms(), 1.0)
26 << " for i=" << i;
30 TEST(RTCStatsTimestampMaker, ConvertNtpToDomTime)
32 RTCStatsTimestampMaker maker;
33 RTCStatsTimestampMakerRealtimeClock clock(maker);
34 for (int i = 1000; i < 20000; i += 93) {
35 const auto t = webrtc::Timestamp::Micros(i);
36 const auto ntp = clock.ConvertTimestampToNtpTime(t);
37 const auto dom =
38 maker.ConvertNtpToDomTime(webrtc::Timestamp::Millis(ntp.ToMs()));
39 // Because of precision differences, these round to a specific millisecond
40 // slightly differently.
41 EXPECT_NEAR(std::lround(dom), std::lround(maker.ReduceRealtimePrecision(t)),
42 1.0)
43 << " for i=" << i;