annotate base/test/TestRealTime.h @ 1258:200c60de27ca 3.0-integration

More timings and cache hit counts
author Chris Cannam
date Thu, 10 Nov 2016 09:58:28 +0000
parents b8a788c9a6f1
children a4554bf41367
rev   line source
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@1028 279 0, 1, 2047, 2048, 6656, 32767, 32768, 44100, 44101, 999999999
Chris@1028 280 };
Chris@1028 281 int n = sizeof(frames)/sizeof(frames[0]);
Chris@1028 282
Chris@1028 283 int rates[] = {
Chris@1028 284 1, 2, 8000, 22050, 44100, 44101, 192000
Chris@1028 285 };
Chris@1028 286 int m = sizeof(rates)/sizeof(rates[0]);
Chris@1028 287
Chris@1028 288 for (int i = 0; i < n; ++i) {
Chris@1040 289 sv_frame_t frame = frames[i];
Chris@1028 290 for (int j = 0; j < m; ++j) {
Chris@1028 291 int rate = rates[j];
Chris@1028 292
Chris@1028 293 RealTime rt = RealTime::frame2RealTime(frame, rate);
Chris@1040 294 sv_frame_t conv = RealTime::realTime2Frame(rt, rate);
Chris@1028 295 QCOMPARE(frame, conv);
Chris@1028 296
Chris@1028 297 rt = RealTime::frame2RealTime(-frame, rate);
Chris@1028 298 conv = RealTime::realTime2Frame(rt, rate);
Chris@1028 299 QCOMPARE(-frame, conv);
Chris@1028 300 }
Chris@1028 301 }
Chris@1028 302 }
Chris@1070 303
Chris@1070 304 void toText()
Chris@1070 305 {
Chris@1070 306 // we want to use QStrings, because then the Qt test library
Chris@1070 307 // will print out any conflicts. The compareTexts function
Chris@1070 308 // does this for us
Chris@1070 309
Chris@1070 310 int halfSec = ONE_BILLION/2; // nsec
Chris@1070 311
Chris@1070 312 RealTime rt = RealTime(0, 0);
Chris@1070 313 compareTexts(rt.toMSText(false, false), "0");
Chris@1070 314 compareTexts(rt.toMSText(true, false), "0.000");
Chris@1070 315 compareTexts(rt.toMSText(false, true), "0");
Chris@1070 316 compareTexts(rt.toMSText(true, true), "0.000");
Chris@1070 317 compareTexts(rt.toFrameText(24, false), "0:00");
Chris@1070 318 compareTexts(rt.toFrameText(24, true), "0:00");
Chris@1070 319 compareTexts(rt.toSecText(), "0s");
Chris@1070 320
Chris@1070 321 rt = RealTime(1, halfSec);
Chris@1070 322 compareTexts(rt.toMSText(false, false), "1.5");
Chris@1070 323 compareTexts(rt.toMSText(true, false), "1.500");
Chris@1070 324 compareTexts(rt.toMSText(false, true), "1.5");
Chris@1070 325 compareTexts(rt.toMSText(true, true), "1.500");
Chris@1070 326 compareTexts(rt.toFrameText(24, false), "1:12");
Chris@1070 327 compareTexts(rt.toFrameText(24, true), "1:12");
Chris@1070 328 compareTexts(rt.toFrameText(25, false), "1:12");
Chris@1070 329 compareTexts(rt.toFrameText(25, true), "1:12");
Chris@1070 330 compareTexts(rt.toSecText(), "1s");
Chris@1070 331
Chris@1070 332 rt = RealTime::fromSeconds(-1.5);
Chris@1070 333 compareTexts(rt.toMSText(false, false), "-1.5");
Chris@1070 334 compareTexts(rt.toMSText(true, false), "-1.500");
Chris@1070 335 compareTexts(rt.toMSText(false, true), "-1.5");
Chris@1070 336 compareTexts(rt.toMSText(true, true), "-1.500");
Chris@1070 337 compareTexts(rt.toFrameText(24, false), "-1:12");
Chris@1070 338 compareTexts(rt.toFrameText(24, true), "-1:12");
Chris@1070 339 compareTexts(rt.toSecText(), "-1s");
Chris@1070 340
Chris@1070 341 rt = RealTime(1, 1000);
Chris@1070 342 compareTexts(rt.toMSText(false, false), "1");
Chris@1070 343 compareTexts(rt.toFrameText(24, false), "1:00");
Chris@1070 344 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000001");
Chris@1070 345 compareTexts(rt.toSecText(), "1s");
Chris@1070 346
Chris@1070 347 rt = RealTime(1, 100000);
Chris@1070 348 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000100");
Chris@1070 349 compareTexts(rt.toSecText(), "1s");
Chris@1070 350
Chris@1070 351 rt = RealTime::fromSeconds(60);
Chris@1070 352 compareTexts(rt.toMSText(false, false), "60");
Chris@1070 353 compareTexts(rt.toMSText(true, false), "60.000");
Chris@1070 354 compareTexts(rt.toMSText(false, true), "1:00");
Chris@1070 355 compareTexts(rt.toMSText(true, true), "1:00.000");
Chris@1070 356 compareTexts(rt.toFrameText(24, false), "60:00");
Chris@1070 357 compareTexts(rt.toFrameText(24, true), "1:00:00");
Chris@1070 358 compareTexts(rt.toSecText(), "1:00");
Chris@1070 359
Chris@1070 360 rt = RealTime::fromSeconds(61.05);
Chris@1070 361 compareTexts(rt.toMSText(false, false), "61.05");
Chris@1070 362 compareTexts(rt.toMSText(true, false), "61.050");
Chris@1070 363 compareTexts(rt.toMSText(false, true), "1:01.05");
Chris@1070 364 compareTexts(rt.toMSText(true, true), "1:01.050");
Chris@1070 365 compareTexts(rt.toFrameText(24, false), "61:01");
Chris@1070 366 compareTexts(rt.toFrameText(24, true), "1:01:01");
Chris@1070 367 compareTexts(rt.toSecText(), "1:01");
Chris@1070 368
Chris@1070 369 rt = RealTime::fromSeconds(601.05);
Chris@1070 370 compareTexts(rt.toMSText(false, false), "601.05");
Chris@1070 371 compareTexts(rt.toMSText(true, false), "601.050");
Chris@1070 372 compareTexts(rt.toMSText(false, true), "10:01.05");
Chris@1070 373 compareTexts(rt.toMSText(true, true), "10:01.050");
Chris@1070 374 compareTexts(rt.toFrameText(24, false), "601:01");
Chris@1070 375 compareTexts(rt.toFrameText(24, true), "10:01:01");
Chris@1070 376 compareTexts(rt.toSecText(), "10:01");
Chris@1070 377
Chris@1070 378 rt = RealTime::fromSeconds(3600);
Chris@1070 379 compareTexts(rt.toMSText(false, false), "3600");
Chris@1070 380 compareTexts(rt.toMSText(true, false), "3600.000");
Chris@1070 381 compareTexts(rt.toMSText(false, true), "1:00:00");
Chris@1070 382 compareTexts(rt.toMSText(true, true), "1:00:00.000");
Chris@1070 383 compareTexts(rt.toFrameText(24, false), "3600:00");
Chris@1070 384 compareTexts(rt.toFrameText(24, true), "1:00:00:00");
Chris@1070 385 compareTexts(rt.toSecText(), "1:00:00");
Chris@1070 386
Chris@1070 387 // For practical reasons our time display always rounds down
Chris@1070 388 rt = RealTime(3599, ONE_BILLION-1);
Chris@1070 389 compareTexts(rt.toMSText(false, false), "3599.999");
Chris@1070 390 compareTexts(rt.toMSText(true, false), "3599.999");
Chris@1070 391 compareTexts(rt.toMSText(false, true), "59:59.999");
Chris@1070 392 compareTexts(rt.toMSText(true, true), "59:59.999");
Chris@1070 393 compareTexts(rt.toFrameText(24, false), "3599:23");
Chris@1070 394 compareTexts(rt.toFrameText(24, true), "59:59:23");
Chris@1070 395 compareTexts(rt.toSecText(), "59:59");
Chris@1070 396
Chris@1070 397 rt = RealTime::fromSeconds(3600 * 4 + 60 * 5 + 3 + 0.01);
Chris@1070 398 compareTexts(rt.toMSText(false, false), "14703.01");
Chris@1070 399 compareTexts(rt.toMSText(true, false), "14703.010");
Chris@1070 400 compareTexts(rt.toMSText(false, true), "4:05:03.01");
Chris@1070 401 compareTexts(rt.toMSText(true, true), "4:05:03.010");
Chris@1070 402 compareTexts(rt.toFrameText(24, false), "14703:00");
Chris@1070 403 compareTexts(rt.toFrameText(24, true), "4:05:03:00");
Chris@1070 404 compareTexts(rt.toSecText(), "4:05:03");
Chris@1070 405
Chris@1070 406 rt = RealTime::fromSeconds(-(3600 * 4 + 60 * 5 + 3 + 0.01));
Chris@1070 407 compareTexts(rt.toMSText(false, false), "-14703.01");
Chris@1070 408 compareTexts(rt.toMSText(true, false), "-14703.010");
Chris@1070 409 compareTexts(rt.toMSText(false, true), "-4:05:03.01");
Chris@1070 410 compareTexts(rt.toMSText(true, true), "-4:05:03.010");
Chris@1070 411 compareTexts(rt.toFrameText(24, false), "-14703:00");
Chris@1070 412 compareTexts(rt.toFrameText(24, true), "-4:05:03:00");
Chris@1070 413 compareTexts(rt.toSecText(), "-4:05:03");
Chris@1070 414 }
Chris@1012 415 };
Chris@1012 416
Chris@1012 417 #endif