-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
TimeTest.cpp
103 lines (80 loc) · 2.56 KB
/
TimeTest.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* TimeTest.cpp
*
* Created on: Apr 22, 2016
* Author: tcanham
*/
#include <Fw/Time/Time.hpp>
#include <iostream>
#include <gtest/gtest.h>
TEST(TimeTestNominal,InstantiateTest) {
Fw::Time time(TB_NONE,1,2);
ASSERT_EQ(time.m_timeBase,TB_NONE);
ASSERT_EQ(time.m_timeContext,0);
ASSERT_EQ(time.m_seconds,1);
ASSERT_EQ(time.m_useconds,2);
std::cout << time << std::endl;
}
TEST(TimeTestNominal,MathTest) {
Fw::Time time1;
Fw::Time time2;
// Try various operations
time1.set(1000,1000);
time2.set(4000,2000);
// test add
// test subtract
// normal subtract
Fw::Time time3 = Fw::Time::sub(time2,time1);
ASSERT_EQ(time3.m_timeBase,TB_NONE);
ASSERT_EQ(time3.m_timeContext,0);
ASSERT_EQ(time3.m_seconds,3000);
ASSERT_EQ(time3.m_useconds,1000);
// rollover subtract
time1.set(1,999999);
time2.set(2,000001);
time3 = Fw::Time::sub(time2,time1);
ASSERT_EQ(time3.m_timeBase,TB_NONE);
ASSERT_EQ(time3.m_timeContext,0);
EXPECT_EQ(time3.m_seconds,0);
EXPECT_EQ(time3.m_useconds,2);
}
TEST(TimeTestNominal,CopyTest) {
Fw::Time time0;
// make time that's guaranteed to be different from default
Fw::Time time1(
(time0.getTimeBase() != TB_NONE ? TB_NONE : TB_PROC_TIME),
time0.getContext()+1,
time0.getSeconds()+1,
time0.getUSeconds()+1
);
// copy construction
Fw::Time time2 = time1;
ASSERT_EQ(time1.getSeconds(), time2.getSeconds());
ASSERT_EQ(time1.getUSeconds(), time2.getUSeconds());
ASSERT_EQ(time1.getTimeBase(), time2.getTimeBase());
ASSERT_EQ(time1.getContext(), time2.getContext());
// assignment operator
Fw::Time time3;
time3 = time1;
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
ASSERT_EQ(time1.getContext(), time3.getContext());
// set method
Fw::Time time4;
time4.set(time1.getTimeBase(), time1.getContext(), time1.getSeconds(), time1.getUSeconds());
ASSERT_EQ(time1.getSeconds(), time3.getSeconds());
ASSERT_EQ(time1.getUSeconds(), time3.getUSeconds());
ASSERT_EQ(time1.getTimeBase(), time3.getTimeBase());
ASSERT_EQ(time1.getContext(), time3.getContext());
}
TEST(TimeTestNominal,ZeroTimeEquality) {
Fw::Time time(TB_PROC_TIME,1,2);
ASSERT_NE(time, Fw::ZERO_TIME);
Fw::Time time2;
ASSERT_EQ(time2, Fw::ZERO_TIME);
}
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}