forked from h4tr3d/avcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimestamp.cpp
72 lines (55 loc) · 1.63 KB
/
Timestamp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <catch2/catch.hpp>
#include <vector>
#ifdef __cpp_lib_print
# include <format>
#endif
#include "rational.h"
#include "timestamp.h"
#ifdef _MSC_VER
# pragma warning(disable : 4702) // Disable warning: unreachable code
#endif
using namespace std;
TEST_CASE("Core::Timestamp", "Timestamp")
{
SECTION("Overflow operator+(a,b)")
{
{
auto const tsLimit = std::numeric_limits<int64_t>::max() / 48000;
av::Timestamp t {
tsLimit, av::Rational {1, 48000}
};
av::Timestamp inc {48000, t.timebase()}; // 1s
auto v1 = t;
v1 += inc;
auto v2 = t + inc;
auto v3 = inc + t;
CHECK(v1 == v2);
CHECK(v1 == v3);
}
#if 0
av::Timestamp t1(48000, av::Rational {1, 48000}); // 1s
av::Timestamp t2 = t1;
av::Timestamp t3 = t1;
for (int64_t i = 0; i < 4194258; ++i) {
t1 = t1 + av::Timestamp {1024, t1.timebase()}; // fail case
t2 += av::Timestamp {1024, t2.timebase()}; // good
t3 = av::Timestamp {1024, t1.timebase()} + t3;
CHECK(t3 == t2);
CHECK(t1 == t2);
CHECK(t1.seconds() >= 1.0);
if (t1 != t2 || t2 != t3 || t1.seconds() < 1.0) {
CHECK(i < 0); // always fail, just for report
break;
}
}
#endif
}
#ifdef __cpp_lib_print
SECTION("std::format formatter")
{
av::Timestamp ts(48000, av::Rational {1, 48000}); // 1s
auto str = std::format("{}", ts);
CHECK(str == "48000*1/48000");
}
#endif
}