Files
screen_cast/tests/utils/test_clock.cpp
T

21 lines
813 B
C++

#include "screencast/utils/clock.h"
#include <cassert>
#include <cstdint>
int main () {
assert ( sc::rtp_timestamp_from_ns ( 0 ) == 0u );
assert ( sc::rtp_timestamp_from_ns ( 1'000'000'000ULL ) == 90'000u );
assert ( sc::rtp_timestamp_from_ns ( 500'000'000ULL ) == 45'000u );
assert ( sc::rtp_timestamp_from_ns ( 16'666'667ULL ) == 1'500u );
// A multiple of the wrap period should wrap back to zero.
// Period in ns = ceil(2^32 * 100_000 / 9) because the helper uses
// integer floor division (ns * 9 / 100_000).
constexpr uint64_t period_ns = ( ( 1ULL << 32 ) * 100'000ULL + 9ULL - 1ULL ) / 9ULL;
static_assert ( sc::rtp_timestamp_from_ns ( period_ns ) == 0u );
static_assert ( sc::rtp_timestamp_from_ns ( period_ns + 1'000'000'000ULL ) == 90'000u );
return 0;
}