Mercurial > hg > svcore
comparison base/test/TestOurRealTime.h @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 622d193a00dc |
children | 71207822a7e0 |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
40 | 40 |
41 private slots: | 41 private slots: |
42 | 42 |
43 void zero() | 43 void zero() |
44 { | 44 { |
45 QCOMPARE(RealTime(0, 0), RealTime::zeroTime); | 45 QCOMPARE(RealTime(0, 0), RealTime::zeroTime); |
46 QCOMPARE(RealTime(0, 0).sec, 0); | 46 QCOMPARE(RealTime(0, 0).sec, 0); |
47 QCOMPARE(RealTime(0, 0).nsec, 0); | 47 QCOMPARE(RealTime(0, 0).nsec, 0); |
48 QCOMPARE(RealTime(0, 0).msec(), 0); | 48 QCOMPARE(RealTime(0, 0).msec(), 0); |
49 QCOMPARE(RealTime(0, 0).usec(), 0); | 49 QCOMPARE(RealTime(0, 0).usec(), 0); |
50 } | 50 } |
51 | 51 |
52 void ctor() | 52 void ctor() |
53 { | 53 { |
54 QCOMPARE(RealTime(0, 0), RealTime(0, 0)); | 54 QCOMPARE(RealTime(0, 0), RealTime(0, 0)); |
55 | 55 |
56 // wraparounds | 56 // wraparounds |
57 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2)); | 57 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2)); |
58 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2)); | 58 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2)); |
59 | 59 |
60 QCOMPARE(RealTime(1, ONE_BILLION), RealTime(2, 0)); | 60 QCOMPARE(RealTime(1, ONE_BILLION), RealTime(2, 0)); |
61 QCOMPARE(RealTime(1, -ONE_BILLION), RealTime(0, 0)); | 61 QCOMPARE(RealTime(1, -ONE_BILLION), RealTime(0, 0)); |
62 QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0)); | 62 QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0)); |
63 QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0)); | 63 QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0)); |
64 | 64 |
65 QCOMPARE(RealTime(1, -ONE_BILLION-ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); | 65 QCOMPARE(RealTime(1, -ONE_BILLION-ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); |
66 QCOMPARE(RealTime(-1, ONE_BILLION+ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); | 66 QCOMPARE(RealTime(-1, ONE_BILLION+ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); |
67 | 67 |
68 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0)); | 68 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0)); |
69 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); | 69 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); |
70 | 70 |
71 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0)); | 71 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0)); |
72 QCOMPARE(RealTime(-2, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); | 72 QCOMPARE(RealTime(-2, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); |
73 | 73 |
74 QCOMPARE(RealTime(0, 1).sec, 0); | 74 QCOMPARE(RealTime(1, -ONE_BILLION/2).sec, 0); |
75 QCOMPARE(RealTime(0, 1).nsec, 1); | 75 QCOMPARE(RealTime(1, -ONE_BILLION/2).nsec, ONE_BILLION/2); |
76 QCOMPARE(RealTime(0, -1).sec, 0); | 76 QCOMPARE(RealTime(-1, ONE_BILLION/2).sec, 0); |
77 QCOMPARE(RealTime(0, -1).nsec, -1); | 77 QCOMPARE(RealTime(-1, ONE_BILLION/2).nsec, -ONE_BILLION/2); |
78 QCOMPARE(RealTime(1, -1).sec, 0); | 78 |
79 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1); | 79 QCOMPARE(RealTime(0, 1).sec, 0); |
80 QCOMPARE(RealTime(-1, 1).sec, 0); | 80 QCOMPARE(RealTime(0, 1).nsec, 1); |
81 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1); | 81 QCOMPARE(RealTime(0, -1).sec, 0); |
82 QCOMPARE(RealTime(-1, -1).sec, -1); | 82 QCOMPARE(RealTime(0, -1).nsec, -1); |
83 QCOMPARE(RealTime(-1, -1).nsec, -1); | 83 QCOMPARE(RealTime(1, -1).sec, 0); |
84 | 84 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1); |
85 QCOMPARE(RealTime(2, -ONE_BILLION*2).sec, 0); | 85 QCOMPARE(RealTime(-1, 1).sec, 0); |
86 QCOMPARE(RealTime(2, -ONE_BILLION*2).nsec, 0); | 86 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1); |
87 QCOMPARE(RealTime(2, -ONE_BILLION/2).sec, 1); | 87 QCOMPARE(RealTime(-1, -1).sec, -1); |
88 QCOMPARE(RealTime(2, -ONE_BILLION/2).nsec, ONE_BILLION/2); | 88 QCOMPARE(RealTime(-1, -1).nsec, -1); |
89 | 89 |
90 QCOMPARE(RealTime(-2, ONE_BILLION*2).sec, 0); | 90 QCOMPARE(RealTime(2, -ONE_BILLION*2).sec, 0); |
91 QCOMPARE(RealTime(-2, ONE_BILLION*2).nsec, 0); | 91 QCOMPARE(RealTime(2, -ONE_BILLION*2).nsec, 0); |
92 QCOMPARE(RealTime(-2, ONE_BILLION/2).sec, -1); | 92 QCOMPARE(RealTime(2, -ONE_BILLION/2).sec, 1); |
93 QCOMPARE(RealTime(-2, ONE_BILLION/2).nsec, -ONE_BILLION/2); | 93 QCOMPARE(RealTime(2, -ONE_BILLION/2).nsec, ONE_BILLION/2); |
94 | |
95 QCOMPARE(RealTime(-2, ONE_BILLION*2).sec, 0); | |
96 QCOMPARE(RealTime(-2, ONE_BILLION*2).nsec, 0); | |
97 QCOMPARE(RealTime(-2, ONE_BILLION/2).sec, -1); | |
98 QCOMPARE(RealTime(-2, ONE_BILLION/2).nsec, -ONE_BILLION/2); | |
94 } | 99 } |
95 | 100 |
96 void fromSeconds() | 101 void fromSeconds() |
97 { | 102 { |
98 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0)); | 103 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0)); |
99 | 104 |
100 QCOMPARE(RealTime::fromSeconds(0.5).sec, 0); | 105 QCOMPARE(RealTime::fromSeconds(0.5).sec, 0); |
101 QCOMPARE(RealTime::fromSeconds(0.5).nsec, ONE_BILLION/2); | 106 QCOMPARE(RealTime::fromSeconds(0.5).nsec, ONE_BILLION/2); |
102 QCOMPARE(RealTime::fromSeconds(0.5).usec(), ONE_MILLION/2); | 107 QCOMPARE(RealTime::fromSeconds(0.5).usec(), ONE_MILLION/2); |
103 QCOMPARE(RealTime::fromSeconds(0.5).msec(), 500); | 108 QCOMPARE(RealTime::fromSeconds(0.5).msec(), 500); |
104 | 109 |
105 QCOMPARE(RealTime::fromSeconds(0.5), RealTime(0, ONE_BILLION/2)); | 110 QCOMPARE(RealTime::fromSeconds(0.5), RealTime(0, ONE_BILLION/2)); |
106 QCOMPARE(RealTime::fromSeconds(1), RealTime(1, 0)); | 111 QCOMPARE(RealTime::fromSeconds(1), RealTime(1, 0)); |
107 QCOMPARE(RealTime::fromSeconds(1.5), RealTime(1, ONE_BILLION/2)); | 112 QCOMPARE(RealTime::fromSeconds(1.5), RealTime(1, ONE_BILLION/2)); |
108 | 113 |
109 QCOMPARE(RealTime::fromSeconds(-0.5).sec, 0); | 114 QCOMPARE(RealTime::fromSeconds(-0.5).sec, 0); |
110 QCOMPARE(RealTime::fromSeconds(-0.5).nsec, -ONE_BILLION/2); | 115 QCOMPARE(RealTime::fromSeconds(-0.5).nsec, -ONE_BILLION/2); |
111 QCOMPARE(RealTime::fromSeconds(-0.5).usec(), -ONE_MILLION/2); | 116 QCOMPARE(RealTime::fromSeconds(-0.5).usec(), -ONE_MILLION/2); |
112 QCOMPARE(RealTime::fromSeconds(-0.5).msec(), -500); | 117 QCOMPARE(RealTime::fromSeconds(-0.5).msec(), -500); |
113 | 118 |
114 QCOMPARE(RealTime::fromSeconds(-1.5).sec, -1); | 119 QCOMPARE(RealTime::fromSeconds(-1.5).sec, -1); |
115 QCOMPARE(RealTime::fromSeconds(-1.5).nsec, -ONE_BILLION/2); | 120 QCOMPARE(RealTime::fromSeconds(-1.5).nsec, -ONE_BILLION/2); |
116 QCOMPARE(RealTime::fromSeconds(-1.5).usec(), -ONE_MILLION/2); | 121 QCOMPARE(RealTime::fromSeconds(-1.5).usec(), -ONE_MILLION/2); |
117 QCOMPARE(RealTime::fromSeconds(-1.5).msec(), -500); | 122 QCOMPARE(RealTime::fromSeconds(-1.5).msec(), -500); |
118 | 123 |
119 QCOMPARE(RealTime::fromSeconds(-0.5), RealTime(0, -ONE_BILLION/2)); | 124 QCOMPARE(RealTime::fromSeconds(-0.5), RealTime(0, -ONE_BILLION/2)); |
120 QCOMPARE(RealTime::fromSeconds(-1), RealTime(-1, 0)); | 125 QCOMPARE(RealTime::fromSeconds(-1), RealTime(-1, 0)); |
121 QCOMPARE(RealTime::fromSeconds(-1.5), RealTime(-1, -ONE_BILLION/2)); | 126 QCOMPARE(RealTime::fromSeconds(-1.5), RealTime(-1, -ONE_BILLION/2)); |
122 } | 127 } |
123 | 128 |
124 void fromMilliseconds() | 129 void fromMilliseconds() |
125 { | 130 { |
126 QCOMPARE(RealTime::fromMilliseconds(0), RealTime(0, 0)); | 131 QCOMPARE(RealTime::fromMilliseconds(0), RealTime(0, 0)); |
127 QCOMPARE(RealTime::fromMilliseconds(500), RealTime(0, ONE_BILLION/2)); | 132 QCOMPARE(RealTime::fromMilliseconds(500), RealTime(0, ONE_BILLION/2)); |
128 QCOMPARE(RealTime::fromMilliseconds(1000), RealTime(1, 0)); | 133 QCOMPARE(RealTime::fromMilliseconds(1000), RealTime(1, 0)); |
129 QCOMPARE(RealTime::fromMilliseconds(1500), RealTime(1, ONE_BILLION/2)); | 134 QCOMPARE(RealTime::fromMilliseconds(1500), RealTime(1, ONE_BILLION/2)); |
130 | 135 |
131 QCOMPARE(RealTime::fromMilliseconds(-0), RealTime(0, 0)); | 136 QCOMPARE(RealTime::fromMilliseconds(-0), RealTime(0, 0)); |
132 QCOMPARE(RealTime::fromMilliseconds(-500), RealTime(0, -ONE_BILLION/2)); | 137 QCOMPARE(RealTime::fromMilliseconds(-500), RealTime(0, -ONE_BILLION/2)); |
133 QCOMPARE(RealTime::fromMilliseconds(-1000), RealTime(-1, 0)); | 138 QCOMPARE(RealTime::fromMilliseconds(-1000), RealTime(-1, 0)); |
134 QCOMPARE(RealTime::fromMilliseconds(-1500), RealTime(-1, -ONE_BILLION/2)); | 139 QCOMPARE(RealTime::fromMilliseconds(-1500), RealTime(-1, -ONE_BILLION/2)); |
135 } | 140 } |
136 | 141 |
137 void fromTimeval() | 142 void fromTimeval() |
138 { | 143 { |
139 struct timeval tv; | 144 struct timeval tv; |
140 | 145 |
141 tv.tv_sec = 0; tv.tv_usec = 0; | 146 tv.tv_sec = 0; tv.tv_usec = 0; |
142 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, 0)); | 147 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, 0)); |
143 tv.tv_sec = 0; tv.tv_usec = ONE_MILLION/2; | 148 tv.tv_sec = 0; tv.tv_usec = ONE_MILLION/2; |
144 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, ONE_BILLION/2)); | 149 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, ONE_BILLION/2)); |
145 tv.tv_sec = 1; tv.tv_usec = 0; | 150 tv.tv_sec = 1; tv.tv_usec = 0; |
146 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, 0)); | 151 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, 0)); |
147 tv.tv_sec = 1; tv.tv_usec = ONE_MILLION/2; | 152 tv.tv_sec = 1; tv.tv_usec = ONE_MILLION/2; |
148 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, ONE_BILLION/2)); | 153 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, ONE_BILLION/2)); |
149 | 154 |
150 tv.tv_sec = 0; tv.tv_usec = -ONE_MILLION/2; | 155 tv.tv_sec = 0; tv.tv_usec = -ONE_MILLION/2; |
151 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, -ONE_BILLION/2)); | 156 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, -ONE_BILLION/2)); |
152 tv.tv_sec = -1; tv.tv_usec = 0; | 157 tv.tv_sec = -1; tv.tv_usec = 0; |
153 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, 0)); | 158 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, 0)); |
154 tv.tv_sec = -1; tv.tv_usec = -ONE_MILLION/2; | 159 tv.tv_sec = -1; tv.tv_usec = -ONE_MILLION/2; |
155 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, -ONE_BILLION/2)); | 160 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, -ONE_BILLION/2)); |
156 } | 161 } |
157 | 162 |
158 void fromXsdDuration() | 163 void fromXsdDuration() |
159 { | 164 { |
160 QCOMPARE(RealTime::fromXsdDuration("PT0"), RealTime::zeroTime); | 165 QCOMPARE(RealTime::fromXsdDuration("PT0"), RealTime::zeroTime); |
161 QCOMPARE(RealTime::fromXsdDuration("PT0S"), RealTime::zeroTime); | 166 QCOMPARE(RealTime::fromXsdDuration("PT0S"), RealTime::zeroTime); |
162 QCOMPARE(RealTime::fromXsdDuration("PT10S"), RealTime(10, 0)); | 167 QCOMPARE(RealTime::fromXsdDuration("PT10S"), RealTime(10, 0)); |
163 QCOMPARE(RealTime::fromXsdDuration("PT10.5S"), RealTime(10, ONE_BILLION/2)); | 168 QCOMPARE(RealTime::fromXsdDuration("PT10.5S"), RealTime(10, ONE_BILLION/2)); |
164 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").sec, 1); | 169 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").sec, 1); |
165 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").msec(), 500); | 170 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").msec(), 500); |
166 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").sec, -1); | 171 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").sec, -1); |
167 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").msec(), -500); | 172 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").msec(), -500); |
168 QCOMPARE(RealTime::fromXsdDuration("PT1M30.5S"), RealTime(90, ONE_BILLION/2)); | 173 QCOMPARE(RealTime::fromXsdDuration("PT1M30.5S"), RealTime(90, ONE_BILLION/2)); |
169 QCOMPARE(RealTime::fromXsdDuration("PT1H2M30.5S"), RealTime(3750, ONE_BILLION/2)); | 174 QCOMPARE(RealTime::fromXsdDuration("PT1H2M30.5S"), RealTime(3750, ONE_BILLION/2)); |
170 } | 175 } |
171 | 176 |
172 void toDouble() | 177 void toDouble() |
173 { | 178 { |
174 QCOMPARE(RealTime(0, 0).toDouble(), 0.0); | 179 QCOMPARE(RealTime(0, 0).toDouble(), 0.0); |
175 QCOMPARE(RealTime(0, ONE_BILLION/2).toDouble(), 0.5); | 180 QCOMPARE(RealTime(0, ONE_BILLION/2).toDouble(), 0.5); |
176 QCOMPARE(RealTime(1, 0).toDouble(), 1.0); | 181 QCOMPARE(RealTime(1, 0).toDouble(), 1.0); |
177 QCOMPARE(RealTime(1, ONE_BILLION/2).toDouble(), 1.5); | 182 QCOMPARE(RealTime(1, ONE_BILLION/2).toDouble(), 1.5); |
178 | 183 |
179 QCOMPARE(RealTime(0, -ONE_BILLION/2).toDouble(), -0.5); | 184 QCOMPARE(RealTime(0, -ONE_BILLION/2).toDouble(), -0.5); |
180 QCOMPARE(RealTime(-1, 0).toDouble(), -1.0); | 185 QCOMPARE(RealTime(-1, 0).toDouble(), -1.0); |
181 QCOMPARE(RealTime(-1, -ONE_BILLION/2).toDouble(), -1.5); | 186 QCOMPARE(RealTime(-1, -ONE_BILLION/2).toDouble(), -1.5); |
182 } | 187 } |
183 | 188 |
184 void assign() | 189 void assign() |
185 { | 190 { |
186 RealTime r; | 191 RealTime r; |
187 r = RealTime(0, 0); | 192 r = RealTime(0, 0); |
188 QCOMPARE(r, RealTime::zeroTime); | 193 QCOMPARE(r, RealTime::zeroTime); |
189 r = RealTime(0, ONE_BILLION/2); | 194 r = RealTime(0, ONE_BILLION/2); |
190 QCOMPARE(r.sec, 0); | 195 QCOMPARE(r.sec, 0); |
191 QCOMPARE(r.nsec, ONE_BILLION/2); | 196 QCOMPARE(r.nsec, ONE_BILLION/2); |
192 r = RealTime(-1, -ONE_BILLION/2); | 197 r = RealTime(-1, -ONE_BILLION/2); |
193 QCOMPARE(r.sec, -1); | 198 QCOMPARE(r.sec, -1); |
194 QCOMPARE(r.nsec, -ONE_BILLION/2); | 199 QCOMPARE(r.nsec, -ONE_BILLION/2); |
195 } | 200 } |
196 | 201 |
197 void plus() | 202 void plus() |
198 { | 203 { |
199 QCOMPARE(RealTime(0, 0) + RealTime(0, 0), RealTime(0, 0)); | 204 QCOMPARE(RealTime(0, 0) + RealTime(0, 0), RealTime(0, 0)); |
200 | 205 |
201 QCOMPARE(RealTime(0, 0) + RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); | 206 QCOMPARE(RealTime(0, 0) + RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); |
202 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(0, ONE_BILLION/2), RealTime(1, 0)); | 207 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(0, ONE_BILLION/2), RealTime(1, 0)); |
203 QCOMPARE(RealTime(1, 0) + RealTime(0, ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); | 208 QCOMPARE(RealTime(1, 0) + RealTime(0, ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); |
204 | 209 |
205 QCOMPARE(RealTime(0, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); | 210 QCOMPARE(RealTime(0, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); |
206 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(-1, 0)); | 211 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(-1, 0)); |
207 QCOMPARE(RealTime(-1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); | 212 QCOMPARE(RealTime(-1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); |
208 | 213 |
209 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); | 214 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); |
210 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, 0)); | 215 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, 0)); |
211 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); | 216 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); |
212 | 217 |
213 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(-1, 0), RealTime(0, -ONE_BILLION/2)); | 218 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(-1, 0), RealTime(0, -ONE_BILLION/2)); |
214 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(1, 0), RealTime(0, ONE_BILLION/2)); | 219 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(1, 0), RealTime(0, ONE_BILLION/2)); |
215 } | 220 } |
216 | 221 |
217 void minus() | 222 void minus() |
218 { | 223 { |
219 QCOMPARE(RealTime(0, 0) - RealTime(0, 0), RealTime(0, 0)); | 224 QCOMPARE(RealTime(0, 0) - RealTime(0, 0), RealTime(0, 0)); |
220 | 225 |
221 QCOMPARE(RealTime(0, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); | 226 QCOMPARE(RealTime(0, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); |
222 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(0, ONE_BILLION/2), RealTime(0, 0)); | 227 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(0, ONE_BILLION/2), RealTime(0, 0)); |
223 QCOMPARE(RealTime(1, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); | 228 QCOMPARE(RealTime(1, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); |
224 | 229 |
225 QCOMPARE(RealTime(0, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); | 230 QCOMPARE(RealTime(0, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2)); |
226 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(0, 0)); | 231 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(0, 0)); |
227 QCOMPARE(RealTime(-1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); | 232 QCOMPARE(RealTime(-1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2)); |
228 | 233 |
229 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); | 234 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); |
230 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, 0)); | 235 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, 0)); |
231 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2)); | 236 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2)); |
232 | 237 |
233 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2)); | 238 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2)); |
234 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2)); | 239 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2)); |
235 } | 240 } |
236 | 241 |
237 void negate() | 242 void negate() |
238 { | 243 { |
239 QCOMPARE(-RealTime(0, 0), RealTime(0, 0)); | 244 QCOMPARE(-RealTime(0, 0), RealTime(0, 0)); |
240 QCOMPARE(-RealTime(1, 0), RealTime(-1, 0)); | 245 QCOMPARE(-RealTime(1, 0), RealTime(-1, 0)); |
241 QCOMPARE(-RealTime(1, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); | 246 QCOMPARE(-RealTime(1, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2)); |
242 QCOMPARE(-RealTime(-1, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); | 247 QCOMPARE(-RealTime(-1, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2)); |
243 } | 248 } |
244 | 249 |
245 void compare() | 250 void compare() |
246 { | 251 { |
247 int sec, nsec; | 252 int sec, nsec; |
248 for (sec = -2; sec <= 2; sec += 2) { | 253 for (sec = -2; sec <= 2; sec += 2) { |
249 for (nsec = -1; nsec <= 1; nsec += 1) { | 254 for (nsec = -1; nsec <= 1; nsec += 1) { |
250 QCOMPARE(RealTime(sec, nsec) < RealTime(sec, nsec), false); | 255 QCOMPARE(RealTime(sec, nsec) < RealTime(sec, nsec), false); |
251 QCOMPARE(RealTime(sec, nsec) > RealTime(sec, nsec), false); | 256 QCOMPARE(RealTime(sec, nsec) > RealTime(sec, nsec), false); |
252 QCOMPARE(RealTime(sec, nsec) == RealTime(sec, nsec), true); | 257 QCOMPARE(RealTime(sec, nsec) == RealTime(sec, nsec), true); |
253 QCOMPARE(RealTime(sec, nsec) != RealTime(sec, nsec), false); | 258 QCOMPARE(RealTime(sec, nsec) != RealTime(sec, nsec), false); |
254 QCOMPARE(RealTime(sec, nsec) <= RealTime(sec, nsec), true); | 259 QCOMPARE(RealTime(sec, nsec) <= RealTime(sec, nsec), true); |
255 QCOMPARE(RealTime(sec, nsec) >= RealTime(sec, nsec), true); | 260 QCOMPARE(RealTime(sec, nsec) >= RealTime(sec, nsec), true); |
256 } | 261 } |
257 } | 262 } |
258 RealTime prev(-3, 0); | 263 RealTime prev(-3, 0); |
259 for (sec = -2; sec <= 2; sec += 2) { | 264 for (sec = -2; sec <= 2; sec += 2) { |
260 for (nsec = -1; nsec <= 1; nsec += 1) { | 265 for (nsec = -1; nsec <= 1; nsec += 1) { |
261 | 266 |
262 RealTime curr(sec, nsec); | 267 RealTime curr(sec, nsec); |
263 | 268 |
264 QCOMPARE(prev < curr, true); | 269 QCOMPARE(prev < curr, true); |
265 QCOMPARE(prev > curr, false); | 270 QCOMPARE(prev > curr, false); |
266 QCOMPARE(prev == curr, false); | 271 QCOMPARE(prev == curr, false); |
267 QCOMPARE(prev != curr, true); | 272 QCOMPARE(prev != curr, true); |
268 QCOMPARE(prev <= curr, true); | 273 QCOMPARE(prev <= curr, true); |
269 QCOMPARE(prev >= curr, false); | 274 QCOMPARE(prev >= curr, false); |
270 | 275 |
271 QCOMPARE(curr < prev, false); | 276 QCOMPARE(curr < prev, false); |
272 QCOMPARE(curr > prev, true); | 277 QCOMPARE(curr > prev, true); |
273 QCOMPARE(curr == prev, false); | 278 QCOMPARE(curr == prev, false); |
274 QCOMPARE(curr != prev, true); | 279 QCOMPARE(curr != prev, true); |
275 QCOMPARE(curr <= prev, false); | 280 QCOMPARE(curr <= prev, false); |
276 QCOMPARE(curr >= prev, true); | 281 QCOMPARE(curr >= prev, true); |
277 | 282 |
278 prev = curr; | 283 prev = curr; |
279 } | 284 } |
280 } | 285 } |
281 } | 286 } |
282 | 287 |
283 void frame() | 288 void frame() |
284 { | 289 { |
285 int frames[] = { | 290 int frames[] = { |