Chris@1012
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1012
|
2
|
Chris@1012
|
3 /*
|
Chris@1012
|
4 Sonic Visualiser
|
Chris@1012
|
5 An audio file viewer and annotation editor.
|
Chris@1012
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1012
|
7
|
Chris@1012
|
8 This program is free software; you can redistribute it and/or
|
Chris@1012
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1012
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1012
|
11 License, or (at your option) any later version. See the file
|
Chris@1012
|
12 COPYING included with this distribution for more information.
|
Chris@1012
|
13 */
|
Chris@1012
|
14
|
Chris@1012
|
15 #ifndef TEST_REALTIME_H
|
Chris@1012
|
16 #define TEST_REALTIME_H
|
Chris@1012
|
17
|
Chris@1012
|
18 #include "../RealTime.h"
|
Chris@1012
|
19
|
Chris@1012
|
20 #include <QObject>
|
Chris@1012
|
21 #include <QtTest>
|
Chris@1012
|
22 #include <QDir>
|
Chris@1012
|
23
|
Chris@1012
|
24 #include <iostream>
|
Chris@1012
|
25
|
Chris@1012
|
26 using namespace std;
|
Chris@1012
|
27
|
Chris@1012
|
28 class TestRealTime : public QObject
|
Chris@1012
|
29 {
|
Chris@1012
|
30 Q_OBJECT
|
Chris@1012
|
31
|
Chris@1070
|
32 void compareTexts(string s, const char *e) {
|
Chris@1070
|
33 QCOMPARE(QString(s.c_str()), QString(e));
|
Chris@1070
|
34 }
|
Chris@1070
|
35
|
Chris@1012
|
36 private slots:
|
Chris@1012
|
37
|
Chris@1012
|
38 #define ONE_MILLION 1000000
|
Chris@1012
|
39 #define ONE_BILLION 1000000000
|
Chris@1012
|
40
|
Chris@1012
|
41 void zero()
|
Chris@1012
|
42 {
|
Chris@1012
|
43 QCOMPARE(RealTime(0, 0), RealTime::zeroTime);
|
Chris@1012
|
44 QCOMPARE(RealTime(0, 0).sec, 0);
|
Chris@1012
|
45 QCOMPARE(RealTime(0, 0).nsec, 0);
|
Chris@1012
|
46 QCOMPARE(RealTime(0, 0).msec(), 0);
|
Chris@1012
|
47 QCOMPARE(RealTime(0, 0).usec(), 0);
|
Chris@1012
|
48 }
|
Chris@1012
|
49
|
Chris@1012
|
50 void ctor()
|
Chris@1012
|
51 {
|
Chris@1012
|
52 QCOMPARE(RealTime(0, 0), RealTime(0, 0));
|
Chris@1012
|
53
|
Chris@1012
|
54 // wraparounds
|
Chris@1012
|
55 QCOMPARE(RealTime(0, ONE_BILLION/2), RealTime(1, -ONE_BILLION/2));
|
Chris@1012
|
56 QCOMPARE(RealTime(0, -ONE_BILLION/2), RealTime(-1, ONE_BILLION/2));
|
Chris@1012
|
57
|
Chris@1015
|
58 QCOMPARE(RealTime(1, ONE_BILLION), RealTime(2, 0));
|
Chris@1015
|
59 QCOMPARE(RealTime(1, -ONE_BILLION), RealTime(0, 0));
|
Chris@1015
|
60 QCOMPARE(RealTime(-1, ONE_BILLION), RealTime(0, 0));
|
Chris@1015
|
61 QCOMPARE(RealTime(-1, -ONE_BILLION), RealTime(-2, 0));
|
Chris@1015
|
62
|
Chris@1012
|
63 QCOMPARE(RealTime(2, -ONE_BILLION*2), RealTime(0, 0));
|
Chris@1012
|
64 QCOMPARE(RealTime(2, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
|
Chris@1012
|
65
|
Chris@1012
|
66 QCOMPARE(RealTime(-2, ONE_BILLION*2), RealTime(0, 0));
|
Chris@1012
|
67 QCOMPARE(RealTime(-2, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
|
Chris@1012
|
68
|
Chris@1012
|
69 QCOMPARE(RealTime(0, 1).sec, 0);
|
Chris@1012
|
70 QCOMPARE(RealTime(0, 1).nsec, 1);
|
Chris@1012
|
71 QCOMPARE(RealTime(0, -1).sec, 0);
|
Chris@1012
|
72 QCOMPARE(RealTime(0, -1).nsec, -1);
|
Chris@1012
|
73 QCOMPARE(RealTime(1, -1).sec, 0);
|
Chris@1012
|
74 QCOMPARE(RealTime(1, -1).nsec, ONE_BILLION-1);
|
Chris@1012
|
75 QCOMPARE(RealTime(-1, 1).sec, 0);
|
Chris@1012
|
76 QCOMPARE(RealTime(-1, 1).nsec, -ONE_BILLION+1);
|
Chris@1012
|
77 QCOMPARE(RealTime(-1, -1).sec, -1);
|
Chris@1012
|
78 QCOMPARE(RealTime(-1, -1).nsec, -1);
|
Chris@1015
|
79
|
Chris@1015
|
80 QCOMPARE(RealTime(2, -ONE_BILLION*2).sec, 0);
|
Chris@1015
|
81 QCOMPARE(RealTime(2, -ONE_BILLION*2).nsec, 0);
|
Chris@1015
|
82 QCOMPARE(RealTime(2, -ONE_BILLION/2).sec, 1);
|
Chris@1015
|
83 QCOMPARE(RealTime(2, -ONE_BILLION/2).nsec, ONE_BILLION/2);
|
Chris@1015
|
84
|
Chris@1015
|
85 QCOMPARE(RealTime(-2, ONE_BILLION*2).sec, 0);
|
Chris@1015
|
86 QCOMPARE(RealTime(-2, ONE_BILLION*2).nsec, 0);
|
Chris@1015
|
87 QCOMPARE(RealTime(-2, ONE_BILLION/2).sec, -1);
|
Chris@1015
|
88 QCOMPARE(RealTime(-2, ONE_BILLION/2).nsec, -ONE_BILLION/2);
|
Chris@1012
|
89 }
|
Chris@1012
|
90
|
Chris@1012
|
91 void fromSeconds()
|
Chris@1012
|
92 {
|
Chris@1012
|
93 QCOMPARE(RealTime::fromSeconds(0), RealTime(0, 0));
|
Chris@1012
|
94
|
Chris@1012
|
95 QCOMPARE(RealTime::fromSeconds(0.5).sec, 0);
|
Chris@1012
|
96 QCOMPARE(RealTime::fromSeconds(0.5).nsec, ONE_BILLION/2);
|
Chris@1012
|
97 QCOMPARE(RealTime::fromSeconds(0.5).usec(), ONE_MILLION/2);
|
Chris@1012
|
98 QCOMPARE(RealTime::fromSeconds(0.5).msec(), 500);
|
Chris@1012
|
99
|
Chris@1012
|
100 QCOMPARE(RealTime::fromSeconds(0.5), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
101 QCOMPARE(RealTime::fromSeconds(1), RealTime(1, 0));
|
Chris@1012
|
102 QCOMPARE(RealTime::fromSeconds(1.5), RealTime(1, ONE_BILLION/2));
|
Chris@1012
|
103
|
Chris@1012
|
104 QCOMPARE(RealTime::fromSeconds(-0.5).sec, 0);
|
Chris@1012
|
105 QCOMPARE(RealTime::fromSeconds(-0.5).nsec, -ONE_BILLION/2);
|
Chris@1012
|
106 QCOMPARE(RealTime::fromSeconds(-0.5).usec(), -ONE_MILLION/2);
|
Chris@1012
|
107 QCOMPARE(RealTime::fromSeconds(-0.5).msec(), -500);
|
Chris@1012
|
108
|
Chris@1012
|
109 QCOMPARE(RealTime::fromSeconds(-1.5).sec, -1);
|
Chris@1012
|
110 QCOMPARE(RealTime::fromSeconds(-1.5).nsec, -ONE_BILLION/2);
|
Chris@1012
|
111 QCOMPARE(RealTime::fromSeconds(-1.5).usec(), -ONE_MILLION/2);
|
Chris@1012
|
112 QCOMPARE(RealTime::fromSeconds(-1.5).msec(), -500);
|
Chris@1012
|
113
|
Chris@1012
|
114 QCOMPARE(RealTime::fromSeconds(-0.5), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
115 QCOMPARE(RealTime::fromSeconds(-1), RealTime(-1, 0));
|
Chris@1012
|
116 QCOMPARE(RealTime::fromSeconds(-1.5), RealTime(-1, -ONE_BILLION/2));
|
Chris@1012
|
117 }
|
Chris@1012
|
118
|
Chris@1012
|
119 void fromMilliseconds()
|
Chris@1012
|
120 {
|
Chris@1012
|
121 QCOMPARE(RealTime::fromMilliseconds(0), RealTime(0, 0));
|
Chris@1012
|
122 QCOMPARE(RealTime::fromMilliseconds(500), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
123 QCOMPARE(RealTime::fromMilliseconds(1000), RealTime(1, 0));
|
Chris@1012
|
124 QCOMPARE(RealTime::fromMilliseconds(1500), RealTime(1, ONE_BILLION/2));
|
Chris@1012
|
125
|
Chris@1012
|
126 QCOMPARE(RealTime::fromMilliseconds(-0), RealTime(0, 0));
|
Chris@1012
|
127 QCOMPARE(RealTime::fromMilliseconds(-500), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
128 QCOMPARE(RealTime::fromMilliseconds(-1000), RealTime(-1, 0));
|
Chris@1012
|
129 QCOMPARE(RealTime::fromMilliseconds(-1500), RealTime(-1, -ONE_BILLION/2));
|
Chris@1012
|
130 }
|
Chris@1012
|
131
|
Chris@1012
|
132 void fromTimeval()
|
Chris@1012
|
133 {
|
Chris@1012
|
134 struct timeval tv;
|
Chris@1012
|
135
|
Chris@1012
|
136 tv.tv_sec = 0; tv.tv_usec = 0;
|
Chris@1012
|
137 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, 0));
|
Chris@1012
|
138 tv.tv_sec = 0; tv.tv_usec = ONE_MILLION/2;
|
Chris@1012
|
139 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
140 tv.tv_sec = 1; tv.tv_usec = 0;
|
Chris@1012
|
141 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, 0));
|
Chris@1012
|
142 tv.tv_sec = 1; tv.tv_usec = ONE_MILLION/2;
|
Chris@1012
|
143 QCOMPARE(RealTime::fromTimeval(tv), RealTime(1, ONE_BILLION/2));
|
Chris@1012
|
144
|
Chris@1012
|
145 tv.tv_sec = 0; tv.tv_usec = -ONE_MILLION/2;
|
Chris@1012
|
146 QCOMPARE(RealTime::fromTimeval(tv), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
147 tv.tv_sec = -1; tv.tv_usec = 0;
|
Chris@1012
|
148 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, 0));
|
Chris@1012
|
149 tv.tv_sec = -1; tv.tv_usec = -ONE_MILLION/2;
|
Chris@1012
|
150 QCOMPARE(RealTime::fromTimeval(tv), RealTime(-1, -ONE_BILLION/2));
|
Chris@1012
|
151 }
|
Chris@1012
|
152
|
Chris@1012
|
153 void fromXsdDuration()
|
Chris@1012
|
154 {
|
Chris@1012
|
155 QCOMPARE(RealTime::fromXsdDuration("PT0"), RealTime::zeroTime);
|
Chris@1012
|
156 QCOMPARE(RealTime::fromXsdDuration("PT0S"), RealTime::zeroTime);
|
Chris@1012
|
157 QCOMPARE(RealTime::fromXsdDuration("PT10S"), RealTime(10, 0));
|
Chris@1012
|
158 QCOMPARE(RealTime::fromXsdDuration("PT10.5S"), RealTime(10, ONE_BILLION/2));
|
Chris@1012
|
159 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").sec, 1);
|
Chris@1012
|
160 QCOMPARE(RealTime::fromXsdDuration("PT1.5S").msec(), 500);
|
Chris@1012
|
161 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").sec, -1);
|
Chris@1012
|
162 QCOMPARE(RealTime::fromXsdDuration("-PT1.5S").msec(), -500);
|
Chris@1012
|
163 QCOMPARE(RealTime::fromXsdDuration("PT1M30.5S"), RealTime(90, ONE_BILLION/2));
|
Chris@1012
|
164 QCOMPARE(RealTime::fromXsdDuration("PT1H2M30.5S"), RealTime(3750, ONE_BILLION/2));
|
Chris@1012
|
165 }
|
Chris@1012
|
166
|
Chris@1012
|
167 void toDouble()
|
Chris@1012
|
168 {
|
Chris@1012
|
169 QCOMPARE(RealTime(0, 0).toDouble(), 0.0);
|
Chris@1012
|
170 QCOMPARE(RealTime(0, ONE_BILLION/2).toDouble(), 0.5);
|
Chris@1012
|
171 QCOMPARE(RealTime(1, 0).toDouble(), 1.0);
|
Chris@1012
|
172 QCOMPARE(RealTime(1, ONE_BILLION/2).toDouble(), 1.5);
|
Chris@1012
|
173
|
Chris@1012
|
174 QCOMPARE(RealTime(0, -ONE_BILLION/2).toDouble(), -0.5);
|
Chris@1012
|
175 QCOMPARE(RealTime(-1, 0).toDouble(), -1.0);
|
Chris@1012
|
176 QCOMPARE(RealTime(-1, -ONE_BILLION/2).toDouble(), -1.5);
|
Chris@1012
|
177 }
|
Chris@1012
|
178
|
Chris@1012
|
179 void assign()
|
Chris@1012
|
180 {
|
Chris@1012
|
181 RealTime r;
|
Chris@1012
|
182 r = RealTime(0, 0);
|
Chris@1012
|
183 QCOMPARE(r, RealTime::zeroTime);
|
Chris@1012
|
184 r = RealTime(0, ONE_BILLION/2);
|
Chris@1012
|
185 QCOMPARE(r.toDouble(), 0.5);
|
Chris@1012
|
186 r = RealTime(-1, -ONE_BILLION/2);
|
Chris@1012
|
187 QCOMPARE(r.toDouble(), -1.5);
|
Chris@1012
|
188 }
|
Chris@1012
|
189
|
Chris@1012
|
190 void plus()
|
Chris@1012
|
191 {
|
Chris@1012
|
192 QCOMPARE(RealTime(0, 0) + RealTime(0, 0), RealTime(0, 0));
|
Chris@1012
|
193
|
Chris@1012
|
194 QCOMPARE(RealTime(0, 0) + RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
195 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(0, ONE_BILLION/2), RealTime(1, 0));
|
Chris@1012
|
196 QCOMPARE(RealTime(1, 0) + RealTime(0, ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
|
Chris@1012
|
197
|
Chris@1012
|
198 QCOMPARE(RealTime(0, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
199 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(-1, 0));
|
Chris@1012
|
200 QCOMPARE(RealTime(-1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
|
Chris@1012
|
201
|
Chris@1012
|
202 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
203 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, 0));
|
Chris@1012
|
204 QCOMPARE(RealTime(1, 0) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2) + RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
205
|
Chris@1012
|
206 QCOMPARE(RealTime(0, ONE_BILLION/2) + RealTime(-1, 0), RealTime(0, -ONE_BILLION/2));
|
Chris@1012
|
207 QCOMPARE(RealTime(0, -ONE_BILLION/2) + RealTime(1, 0), RealTime(0, ONE_BILLION/2));
|
Chris@1012
|
208 }
|
Chris@1014
|
209
|
Chris@1014
|
210 void minus()
|
Chris@1014
|
211 {
|
Chris@1014
|
212 QCOMPARE(RealTime(0, 0) - RealTime(0, 0), RealTime(0, 0));
|
Chris@1014
|
213
|
Chris@1014
|
214 QCOMPARE(RealTime(0, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
|
Chris@1014
|
215 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(0, ONE_BILLION/2), RealTime(0, 0));
|
Chris@1014
|
216 QCOMPARE(RealTime(1, 0) - RealTime(0, ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
|
Chris@1014
|
217
|
Chris@1014
|
218 QCOMPARE(RealTime(0, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, ONE_BILLION/2));
|
Chris@1014
|
219 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(0, 0));
|
Chris@1014
|
220 QCOMPARE(RealTime(-1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(0, -ONE_BILLION/2));
|
Chris@1014
|
221
|
Chris@1014
|
222 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
|
Chris@1014
|
223 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, 0));
|
Chris@1014
|
224 QCOMPARE(RealTime(1, 0) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2) - RealTime(0, -ONE_BILLION/2), RealTime(2, ONE_BILLION/2));
|
Chris@1014
|
225
|
Chris@1014
|
226 QCOMPARE(RealTime(0, ONE_BILLION/2) - RealTime(-1, 0), RealTime(1, ONE_BILLION/2));
|
Chris@1014
|
227 QCOMPARE(RealTime(0, -ONE_BILLION/2) - RealTime(1, 0), RealTime(-1, -ONE_BILLION/2));
|
Chris@1014
|
228 }
|
Chris@1015
|
229
|
Chris@1015
|
230 void negate()
|
Chris@1015
|
231 {
|
Chris@1015
|
232 QCOMPARE(-RealTime(0, 0), RealTime(0, 0));
|
Chris@1015
|
233 QCOMPARE(-RealTime(1, 0), RealTime(-1, 0));
|
Chris@1015
|
234 QCOMPARE(-RealTime(1, ONE_BILLION/2), RealTime(-1, -ONE_BILLION/2));
|
Chris@1015
|
235 QCOMPARE(-RealTime(-1, -ONE_BILLION/2), RealTime(1, ONE_BILLION/2));
|
Chris@1015
|
236 }
|
Chris@1015
|
237
|
Chris@1015
|
238 void compare()
|
Chris@1015
|
239 {
|
Chris@1015
|
240 int sec, nsec;
|
Chris@1015
|
241 for (sec = -2; sec <= 2; sec += 2) {
|
Chris@1015
|
242 for (nsec = -1; nsec <= 1; nsec += 1) {
|
Chris@1015
|
243 QCOMPARE(RealTime(sec, nsec) < RealTime(sec, nsec), false);
|
Chris@1015
|
244 QCOMPARE(RealTime(sec, nsec) > RealTime(sec, nsec), false);
|
Chris@1015
|
245 QCOMPARE(RealTime(sec, nsec) == RealTime(sec, nsec), true);
|
Chris@1015
|
246 QCOMPARE(RealTime(sec, nsec) != RealTime(sec, nsec), false);
|
Chris@1015
|
247 QCOMPARE(RealTime(sec, nsec) <= RealTime(sec, nsec), true);
|
Chris@1015
|
248 QCOMPARE(RealTime(sec, nsec) >= RealTime(sec, nsec), true);
|
Chris@1015
|
249 }
|
Chris@1015
|
250 }
|
Chris@1015
|
251 RealTime prev(-3, 0);
|
Chris@1015
|
252 for (sec = -2; sec <= 2; sec += 2) {
|
Chris@1015
|
253 for (nsec = -1; nsec <= 1; nsec += 1) {
|
Chris@1015
|
254
|
Chris@1015
|
255 RealTime curr(sec, nsec);
|
Chris@1015
|
256
|
Chris@1015
|
257 QCOMPARE(prev < curr, true);
|
Chris@1015
|
258 QCOMPARE(prev > curr, false);
|
Chris@1015
|
259 QCOMPARE(prev == curr, false);
|
Chris@1015
|
260 QCOMPARE(prev != curr, true);
|
Chris@1015
|
261 QCOMPARE(prev <= curr, true);
|
Chris@1015
|
262 QCOMPARE(prev >= curr, false);
|
Chris@1015
|
263
|
Chris@1015
|
264 QCOMPARE(curr < prev, false);
|
Chris@1015
|
265 QCOMPARE(curr > prev, true);
|
Chris@1015
|
266 QCOMPARE(curr == prev, false);
|
Chris@1015
|
267 QCOMPARE(curr != prev, true);
|
Chris@1015
|
268 QCOMPARE(curr <= prev, false);
|
Chris@1015
|
269 QCOMPARE(curr >= prev, true);
|
Chris@1015
|
270
|
Chris@1015
|
271 prev = curr;
|
Chris@1015
|
272 }
|
Chris@1015
|
273 }
|
Chris@1015
|
274 }
|
Chris@1015
|
275
|
Chris@1028
|
276 void frame()
|
Chris@1028
|
277 {
|
Chris@1028
|
278 int frames[] = {
|
Chris@1259
|
279 0, 1, 2047, 2048, 6656,
|
Chris@1259
|
280 32767, 32768, 44100, 44101, 999999999
|
Chris@1028
|
281 };
|
Chris@1028
|
282 int n = sizeof(frames)/sizeof(frames[0]);
|
Chris@1028
|
283
|
Chris@1028
|
284 int rates[] = {
|
Chris@1028
|
285 1, 2, 8000, 22050, 44100, 44101, 192000
|
Chris@1028
|
286 };
|
Chris@1028
|
287 int m = sizeof(rates)/sizeof(rates[0]);
|
Chris@1028
|
288
|
Chris@1259
|
289 vector<vector<RealTime>> realTimes = {
|
Chris@1259
|
290 { { 0, 0 }, { 1, 0 }, { 2047, 0 }, { 2048, 0 }, { 6656, 0 }, { 32767, 0 }, { 32768, 0 }, { 44100, 0 }, { 44101, 0 }, { 999999999, 0 } },
|
Chris@1259
|
291 { { 0, 0 }, { 0, 500000000 }, { 1023, 500000000 }, { 1024, 0 }, { 3328, 0 }, { 16383, 500000000 }, { 16384, 0 }, { 22050, 0 }, { 22050, 500000000 }, { 499999999, 500000000 } },
|
Chris@1259
|
292 { { 0, 0 }, { 0, 125000 }, { 0, 255875000 }, { 0, 256000000 }, { 0, 832000000 }, { 4, 95875000 }, { 4, 96000000 }, { 5, 512500000 }, { 5, 512625000 }, { 124999, 999875000 } },
|
Chris@1259
|
293 { { 0, 0 }, { 0, 45351 }, { 0, 92834467 }, { 0, 92879819 }, { 0, 301859410 }, { 1, 486031746 }, { 1, 486077098 }, { 2, 0 }, { 2, 45351 }, { 45351, 473877551 } },
|
Chris@1259
|
294 { { 0, 0 }, { 0, 22676 }, { 0, 46417234 }, { 0, 46439909 }, { 0, 150929705 }, { 0, 743015873 }, { 0, 743038549 }, { 1, 0 }, { 1, 22676 }, { 22675, 736938776 } },
|
Chris@1259
|
295 { { 0, 0 }, { 0, 22675 }, { 0, 46416181 }, { 0, 46438856 }, { 0, 150926283 }, { 0, 742999025 }, { 0, 743021700 }, { 0, 999977325 }, { 1, 0 }, { 22675, 222761389 } },
|
Chris@1259
|
296 { { 0, 0 }, { 0, 5208 }, { 0, 10661458 }, { 0, 10666667 }, { 0, 34666667 }, { 0, 170661458 }, { 0, 170666667 }, { 0, 229687500 }, { 0, 229692708 }, { 5208, 333328125 } },
|
Chris@1259
|
297 };
|
Chris@1259
|
298
|
Chris@1028
|
299 for (int i = 0; i < n; ++i) {
|
Chris@1040
|
300 sv_frame_t frame = frames[i];
|
Chris@1028
|
301 for (int j = 0; j < m; ++j) {
|
Chris@1028
|
302 int rate = rates[j];
|
Chris@1028
|
303
|
Chris@1028
|
304 RealTime rt = RealTime::frame2RealTime(frame, rate);
|
Chris@1259
|
305 QCOMPARE(rt.sec, realTimes[j][i].sec);
|
Chris@1259
|
306 QCOMPARE(rt.nsec, realTimes[j][i].nsec);
|
Chris@1259
|
307
|
Chris@1040
|
308 sv_frame_t conv = RealTime::realTime2Frame(rt, rate);
|
Chris@1028
|
309 QCOMPARE(frame, conv);
|
Chris@1028
|
310
|
Chris@1028
|
311 rt = RealTime::frame2RealTime(-frame, rate);
|
Chris@1028
|
312 conv = RealTime::realTime2Frame(rt, rate);
|
Chris@1028
|
313 QCOMPARE(-frame, conv);
|
Chris@1028
|
314 }
|
Chris@1028
|
315 }
|
Chris@1028
|
316 }
|
Chris@1070
|
317
|
Chris@1070
|
318 void toText()
|
Chris@1070
|
319 {
|
Chris@1070
|
320 // we want to use QStrings, because then the Qt test library
|
Chris@1070
|
321 // will print out any conflicts. The compareTexts function
|
Chris@1070
|
322 // does this for us
|
Chris@1070
|
323
|
Chris@1070
|
324 int halfSec = ONE_BILLION/2; // nsec
|
Chris@1070
|
325
|
Chris@1070
|
326 RealTime rt = RealTime(0, 0);
|
Chris@1070
|
327 compareTexts(rt.toMSText(false, false), "0");
|
Chris@1070
|
328 compareTexts(rt.toMSText(true, false), "0.000");
|
Chris@1070
|
329 compareTexts(rt.toMSText(false, true), "0");
|
Chris@1070
|
330 compareTexts(rt.toMSText(true, true), "0.000");
|
Chris@1070
|
331 compareTexts(rt.toFrameText(24, false), "0:00");
|
Chris@1070
|
332 compareTexts(rt.toFrameText(24, true), "0:00");
|
Chris@1070
|
333 compareTexts(rt.toSecText(), "0s");
|
Chris@1070
|
334
|
Chris@1070
|
335 rt = RealTime(1, halfSec);
|
Chris@1070
|
336 compareTexts(rt.toMSText(false, false), "1.5");
|
Chris@1070
|
337 compareTexts(rt.toMSText(true, false), "1.500");
|
Chris@1070
|
338 compareTexts(rt.toMSText(false, true), "1.5");
|
Chris@1070
|
339 compareTexts(rt.toMSText(true, true), "1.500");
|
Chris@1070
|
340 compareTexts(rt.toFrameText(24, false), "1:12");
|
Chris@1070
|
341 compareTexts(rt.toFrameText(24, true), "1:12");
|
Chris@1070
|
342 compareTexts(rt.toFrameText(25, false), "1:12");
|
Chris@1070
|
343 compareTexts(rt.toFrameText(25, true), "1:12");
|
Chris@1070
|
344 compareTexts(rt.toSecText(), "1s");
|
Chris@1070
|
345
|
Chris@1070
|
346 rt = RealTime::fromSeconds(-1.5);
|
Chris@1070
|
347 compareTexts(rt.toMSText(false, false), "-1.5");
|
Chris@1070
|
348 compareTexts(rt.toMSText(true, false), "-1.500");
|
Chris@1070
|
349 compareTexts(rt.toMSText(false, true), "-1.5");
|
Chris@1070
|
350 compareTexts(rt.toMSText(true, true), "-1.500");
|
Chris@1070
|
351 compareTexts(rt.toFrameText(24, false), "-1:12");
|
Chris@1070
|
352 compareTexts(rt.toFrameText(24, true), "-1:12");
|
Chris@1070
|
353 compareTexts(rt.toSecText(), "-1s");
|
Chris@1070
|
354
|
Chris@1070
|
355 rt = RealTime(1, 1000);
|
Chris@1070
|
356 compareTexts(rt.toMSText(false, false), "1");
|
Chris@1070
|
357 compareTexts(rt.toFrameText(24, false), "1:00");
|
Chris@1070
|
358 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000001");
|
Chris@1070
|
359 compareTexts(rt.toSecText(), "1s");
|
Chris@1070
|
360
|
Chris@1070
|
361 rt = RealTime(1, 100000);
|
Chris@1070
|
362 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000100");
|
Chris@1070
|
363 compareTexts(rt.toSecText(), "1s");
|
Chris@1070
|
364
|
Chris@1070
|
365 rt = RealTime::fromSeconds(60);
|
Chris@1070
|
366 compareTexts(rt.toMSText(false, false), "60");
|
Chris@1070
|
367 compareTexts(rt.toMSText(true, false), "60.000");
|
Chris@1070
|
368 compareTexts(rt.toMSText(false, true), "1:00");
|
Chris@1070
|
369 compareTexts(rt.toMSText(true, true), "1:00.000");
|
Chris@1070
|
370 compareTexts(rt.toFrameText(24, false), "60:00");
|
Chris@1070
|
371 compareTexts(rt.toFrameText(24, true), "1:00:00");
|
Chris@1070
|
372 compareTexts(rt.toSecText(), "1:00");
|
Chris@1070
|
373
|
Chris@1070
|
374 rt = RealTime::fromSeconds(61.05);
|
Chris@1070
|
375 compareTexts(rt.toMSText(false, false), "61.05");
|
Chris@1070
|
376 compareTexts(rt.toMSText(true, false), "61.050");
|
Chris@1070
|
377 compareTexts(rt.toMSText(false, true), "1:01.05");
|
Chris@1070
|
378 compareTexts(rt.toMSText(true, true), "1:01.050");
|
Chris@1070
|
379 compareTexts(rt.toFrameText(24, false), "61:01");
|
Chris@1070
|
380 compareTexts(rt.toFrameText(24, true), "1:01:01");
|
Chris@1070
|
381 compareTexts(rt.toSecText(), "1:01");
|
Chris@1070
|
382
|
Chris@1070
|
383 rt = RealTime::fromSeconds(601.05);
|
Chris@1070
|
384 compareTexts(rt.toMSText(false, false), "601.05");
|
Chris@1070
|
385 compareTexts(rt.toMSText(true, false), "601.050");
|
Chris@1070
|
386 compareTexts(rt.toMSText(false, true), "10:01.05");
|
Chris@1070
|
387 compareTexts(rt.toMSText(true, true), "10:01.050");
|
Chris@1070
|
388 compareTexts(rt.toFrameText(24, false), "601:01");
|
Chris@1070
|
389 compareTexts(rt.toFrameText(24, true), "10:01:01");
|
Chris@1070
|
390 compareTexts(rt.toSecText(), "10:01");
|
Chris@1070
|
391
|
Chris@1070
|
392 rt = RealTime::fromSeconds(3600);
|
Chris@1070
|
393 compareTexts(rt.toMSText(false, false), "3600");
|
Chris@1070
|
394 compareTexts(rt.toMSText(true, false), "3600.000");
|
Chris@1070
|
395 compareTexts(rt.toMSText(false, true), "1:00:00");
|
Chris@1070
|
396 compareTexts(rt.toMSText(true, true), "1:00:00.000");
|
Chris@1070
|
397 compareTexts(rt.toFrameText(24, false), "3600:00");
|
Chris@1070
|
398 compareTexts(rt.toFrameText(24, true), "1:00:00:00");
|
Chris@1070
|
399 compareTexts(rt.toSecText(), "1:00:00");
|
Chris@1070
|
400
|
Chris@1070
|
401 // For practical reasons our time display always rounds down
|
Chris@1070
|
402 rt = RealTime(3599, ONE_BILLION-1);
|
Chris@1070
|
403 compareTexts(rt.toMSText(false, false), "3599.999");
|
Chris@1070
|
404 compareTexts(rt.toMSText(true, false), "3599.999");
|
Chris@1070
|
405 compareTexts(rt.toMSText(false, true), "59:59.999");
|
Chris@1070
|
406 compareTexts(rt.toMSText(true, true), "59:59.999");
|
Chris@1070
|
407 compareTexts(rt.toFrameText(24, false), "3599:23");
|
Chris@1070
|
408 compareTexts(rt.toFrameText(24, true), "59:59:23");
|
Chris@1070
|
409 compareTexts(rt.toSecText(), "59:59");
|
Chris@1070
|
410
|
Chris@1070
|
411 rt = RealTime::fromSeconds(3600 * 4 + 60 * 5 + 3 + 0.01);
|
Chris@1070
|
412 compareTexts(rt.toMSText(false, false), "14703.01");
|
Chris@1070
|
413 compareTexts(rt.toMSText(true, false), "14703.010");
|
Chris@1070
|
414 compareTexts(rt.toMSText(false, true), "4:05:03.01");
|
Chris@1070
|
415 compareTexts(rt.toMSText(true, true), "4:05:03.010");
|
Chris@1070
|
416 compareTexts(rt.toFrameText(24, false), "14703:00");
|
Chris@1070
|
417 compareTexts(rt.toFrameText(24, true), "4:05:03:00");
|
Chris@1070
|
418 compareTexts(rt.toSecText(), "4:05:03");
|
Chris@1070
|
419
|
Chris@1070
|
420 rt = RealTime::fromSeconds(-(3600 * 4 + 60 * 5 + 3 + 0.01));
|
Chris@1070
|
421 compareTexts(rt.toMSText(false, false), "-14703.01");
|
Chris@1070
|
422 compareTexts(rt.toMSText(true, false), "-14703.010");
|
Chris@1070
|
423 compareTexts(rt.toMSText(false, true), "-4:05:03.01");
|
Chris@1070
|
424 compareTexts(rt.toMSText(true, true), "-4:05:03.010");
|
Chris@1070
|
425 compareTexts(rt.toFrameText(24, false), "-14703:00");
|
Chris@1070
|
426 compareTexts(rt.toFrameText(24, true), "-4:05:03:00");
|
Chris@1070
|
427 compareTexts(rt.toSecText(), "-4:05:03");
|
Chris@1070
|
428 }
|
Chris@1012
|
429 };
|
Chris@1012
|
430
|
Chris@1012
|
431 #endif
|