annotate base/test/TestVampRealTime.h @ 1356:39ce813e185c 3.0-integration

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