MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
test_time.cpp File Reference
#include <cstdint>
#include <ctime>
#include <catch2/catch_test_macros.hpp>
#include <mxl/mxl.h>
#include <mxl/time.h>
Include dependency graph for test_time.cpp:

Go to the source code of this file.

Functions

 for (auto i=30 '000 '000U;i< 60 '000 '000U;++i)
 REQUIRE (calculatedIndex==currentIndex)
 REQUIRE (mxlGetNsUntilIndex(currentIndex+33, &rate) > 0)
 REQUIRE (timeDelta< 33 '366 '667LL)
 TEST_CASE ("Index 0 and 1", "[time]")
 TEST_CASE ("Invalid Times", "[time]")
 TEST_CASE ("Test TAI Epoch", "[time]")

Variables

auto const calculatedIndex = mxlTimestampToIndex(&rate, timestamp)
auto const currentIndex = mxlTimestampToIndex(&rate, currentTime)
auto const currentTime = mxlGetTime()
auto const timeDelta = (currentTime > timestamp) ? currentTime - timestamp : timestamp - currentTime
auto const timestamp = mxlIndexToTimestamp(&rate, currentIndex)

Function Documentation

◆ for()

for ( )

Definition at line 75 of file test_time.cpp.

76 {
77 auto const ts = mxlIndexToTimestamp(&editRate, i);
78 auto const rti = mxlTimestampToIndex(&editRate, ts);
79 REQUIRE(i == rti);
80 }
REQUIRE(timeDelta< 33 '366 '667LL)
MXL_EXPORT uint64_t mxlIndexToTimestamp(mxlRational const *editRate, uint64_t index)
Definition time.cpp:38
MXL_EXPORT uint64_t mxlTimestampToIndex(mxlRational const *editRate, uint64_t timestamp)
Definition time.cpp:31

◆ REQUIRE() [1/3]

◆ REQUIRE() [2/3]

REQUIRE ( mxlGetNsUntilIndex(currentIndex+33, &rate) ,
0  )

◆ REQUIRE() [3/3]

REQUIRE ( )

◆ TEST_CASE() [1/3]

TEST_CASE ( "Index 0 and 1" ,
"" [time] )

Definition at line 26 of file test_time.cpp.

27{
28 auto const rate = mxlRational{30000, 1001};
29
30 auto const firstIndexTimeNs = 0ULL;
31 auto const secondIndexTimeNs = (rate.denominator * 1'000'000'000ULL + (rate.numerator / 2)) / rate.numerator;
32
33 REQUIRE(mxlTimestampToIndex(&rate, firstIndexTimeNs) == 0);
34 REQUIRE(mxlTimestampToIndex(&rate, secondIndexTimeNs) == 1);
35
36 REQUIRE(mxlIndexToTimestamp(&rate, 0) == firstIndexTimeNs);
37 REQUIRE(mxlIndexToTimestamp(&rate, 1) == secondIndexTimeNs);
38}
struct mxlRational_t mxlRational
auto const rate
Compute the grain index for the flow rate and current TAI time.

◆ TEST_CASE() [2/3]

TEST_CASE ( "Invalid Times" ,
"" [time] )

Definition at line 10 of file test_time.cpp.

11{
12 auto const badRate = mxlRational{0, 0};
13 auto const badNumerator = mxlRational{0, 1001};
14 auto const badDenominator = mxlRational{30000, 0};
15 auto const goodRate = mxlRational{30000, 1001};
16
17 auto const now = mxlGetTime();
18
24}
#define MXL_UNDEFINED_INDEX
Definition rational.h:17
auto const now
MXL_EXPORT uint64_t mxlGetTime(void)
Definition time.cpp:11

◆ TEST_CASE() [3/3]

TEST_CASE ( "Test TAI Epoch" ,
"" [time] )

Definition at line 40 of file test_time.cpp.

41{
42 auto ts = std::timespec{0, 0};
43 tm t;
44 gmtime_r(&ts.tv_sec, &t);
45
46 REQUIRE(t.tm_year == 70);
47 REQUIRE(t.tm_mon == 0);
48 REQUIRE(t.tm_mday == 1);
49 REQUIRE(t.tm_hour == 0);
50 REQUIRE(t.tm_min == 0);
51 REQUIRE(t.tm_sec == 0);
52}

Variable Documentation

◆ calculatedIndex

auto const calculatedIndex = mxlTimestampToIndex(&rate, timestamp)

Definition at line 62 of file test_time.cpp.

◆ currentIndex

auto const currentIndex = mxlTimestampToIndex(&rate, currentTime)

Definition at line 59 of file test_time.cpp.

◆ currentTime

auto const currentTime = mxlGetTime()

Definition at line 58 of file test_time.cpp.

◆ timeDelta

auto const timeDelta = (currentTime > timestamp) ? currentTime - timestamp : timestamp - currentTime

Definition at line 64 of file test_time.cpp.

◆ timestamp

auto const timestamp = mxlIndexToTimestamp(&rate, currentIndex)

Definition at line 61 of file test_time.cpp.