comparison base/test/TestRealTime.h @ 1070:b8a788c9a6f1

Fixes to, and tests for, RealTime-to-text methods
author Chris Cannam
date Tue, 12 May 2015 16:19:45 +0100
parents a1cd5abcb38b
children a4554bf41367
comparison
equal deleted inserted replaced
1069:32ab6c48efaa 1070:b8a788c9a6f1
26 using namespace std; 26 using namespace std;
27 27
28 class TestRealTime : public QObject 28 class TestRealTime : public QObject
29 { 29 {
30 Q_OBJECT 30 Q_OBJECT
31
32 void compareTexts(string s, const char *e) {
33 QCOMPARE(QString(s.c_str()), QString(e));
34 }
31 35
32 private slots: 36 private slots:
33 37
34 #define ONE_MILLION 1000000 38 #define ONE_MILLION 1000000
35 #define ONE_BILLION 1000000000 39 #define ONE_BILLION 1000000000
294 conv = RealTime::realTime2Frame(rt, rate); 298 conv = RealTime::realTime2Frame(rt, rate);
295 QCOMPARE(-frame, conv); 299 QCOMPARE(-frame, conv);
296 } 300 }
297 } 301 }
298 } 302 }
303
304 void toText()
305 {
306 // we want to use QStrings, because then the Qt test library
307 // will print out any conflicts. The compareTexts function
308 // does this for us
309
310 int halfSec = ONE_BILLION/2; // nsec
311
312 RealTime rt = RealTime(0, 0);
313 compareTexts(rt.toMSText(false, false), "0");
314 compareTexts(rt.toMSText(true, false), "0.000");
315 compareTexts(rt.toMSText(false, true), "0");
316 compareTexts(rt.toMSText(true, true), "0.000");
317 compareTexts(rt.toFrameText(24, false), "0:00");
318 compareTexts(rt.toFrameText(24, true), "0:00");
319 compareTexts(rt.toSecText(), "0s");
320
321 rt = RealTime(1, halfSec);
322 compareTexts(rt.toMSText(false, false), "1.5");
323 compareTexts(rt.toMSText(true, false), "1.500");
324 compareTexts(rt.toMSText(false, true), "1.5");
325 compareTexts(rt.toMSText(true, true), "1.500");
326 compareTexts(rt.toFrameText(24, false), "1:12");
327 compareTexts(rt.toFrameText(24, true), "1:12");
328 compareTexts(rt.toFrameText(25, false), "1:12");
329 compareTexts(rt.toFrameText(25, true), "1:12");
330 compareTexts(rt.toSecText(), "1s");
331
332 rt = RealTime::fromSeconds(-1.5);
333 compareTexts(rt.toMSText(false, false), "-1.5");
334 compareTexts(rt.toMSText(true, false), "-1.500");
335 compareTexts(rt.toMSText(false, true), "-1.5");
336 compareTexts(rt.toMSText(true, true), "-1.500");
337 compareTexts(rt.toFrameText(24, false), "-1:12");
338 compareTexts(rt.toFrameText(24, true), "-1:12");
339 compareTexts(rt.toSecText(), "-1s");
340
341 rt = RealTime(1, 1000);
342 compareTexts(rt.toMSText(false, false), "1");
343 compareTexts(rt.toFrameText(24, false), "1:00");
344 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000001");
345 compareTexts(rt.toSecText(), "1s");
346
347 rt = RealTime(1, 100000);
348 compareTexts(rt.toFrameText(ONE_MILLION, false), "1:000100");
349 compareTexts(rt.toSecText(), "1s");
350
351 rt = RealTime::fromSeconds(60);
352 compareTexts(rt.toMSText(false, false), "60");
353 compareTexts(rt.toMSText(true, false), "60.000");
354 compareTexts(rt.toMSText(false, true), "1:00");
355 compareTexts(rt.toMSText(true, true), "1:00.000");
356 compareTexts(rt.toFrameText(24, false), "60:00");
357 compareTexts(rt.toFrameText(24, true), "1:00:00");
358 compareTexts(rt.toSecText(), "1:00");
359
360 rt = RealTime::fromSeconds(61.05);
361 compareTexts(rt.toMSText(false, false), "61.05");
362 compareTexts(rt.toMSText(true, false), "61.050");
363 compareTexts(rt.toMSText(false, true), "1:01.05");
364 compareTexts(rt.toMSText(true, true), "1:01.050");
365 compareTexts(rt.toFrameText(24, false), "61:01");
366 compareTexts(rt.toFrameText(24, true), "1:01:01");
367 compareTexts(rt.toSecText(), "1:01");
368
369 rt = RealTime::fromSeconds(601.05);
370 compareTexts(rt.toMSText(false, false), "601.05");
371 compareTexts(rt.toMSText(true, false), "601.050");
372 compareTexts(rt.toMSText(false, true), "10:01.05");
373 compareTexts(rt.toMSText(true, true), "10:01.050");
374 compareTexts(rt.toFrameText(24, false), "601:01");
375 compareTexts(rt.toFrameText(24, true), "10:01:01");
376 compareTexts(rt.toSecText(), "10:01");
377
378 rt = RealTime::fromSeconds(3600);
379 compareTexts(rt.toMSText(false, false), "3600");
380 compareTexts(rt.toMSText(true, false), "3600.000");
381 compareTexts(rt.toMSText(false, true), "1:00:00");
382 compareTexts(rt.toMSText(true, true), "1:00:00.000");
383 compareTexts(rt.toFrameText(24, false), "3600:00");
384 compareTexts(rt.toFrameText(24, true), "1:00:00:00");
385 compareTexts(rt.toSecText(), "1:00:00");
386
387 // For practical reasons our time display always rounds down
388 rt = RealTime(3599, ONE_BILLION-1);
389 compareTexts(rt.toMSText(false, false), "3599.999");
390 compareTexts(rt.toMSText(true, false), "3599.999");
391 compareTexts(rt.toMSText(false, true), "59:59.999");
392 compareTexts(rt.toMSText(true, true), "59:59.999");
393 compareTexts(rt.toFrameText(24, false), "3599:23");
394 compareTexts(rt.toFrameText(24, true), "59:59:23");
395 compareTexts(rt.toSecText(), "59:59");
396
397 rt = RealTime::fromSeconds(3600 * 4 + 60 * 5 + 3 + 0.01);
398 compareTexts(rt.toMSText(false, false), "14703.01");
399 compareTexts(rt.toMSText(true, false), "14703.010");
400 compareTexts(rt.toMSText(false, true), "4:05:03.01");
401 compareTexts(rt.toMSText(true, true), "4:05:03.010");
402 compareTexts(rt.toFrameText(24, false), "14703:00");
403 compareTexts(rt.toFrameText(24, true), "4:05:03:00");
404 compareTexts(rt.toSecText(), "4:05:03");
405
406 rt = RealTime::fromSeconds(-(3600 * 4 + 60 * 5 + 3 + 0.01));
407 compareTexts(rt.toMSText(false, false), "-14703.01");
408 compareTexts(rt.toMSText(true, false), "-14703.010");
409 compareTexts(rt.toMSText(false, true), "-4:05:03.01");
410 compareTexts(rt.toMSText(true, true), "-4:05:03.010");
411 compareTexts(rt.toFrameText(24, false), "-14703:00");
412 compareTexts(rt.toFrameText(24, true), "-4:05:03:00");
413 compareTexts(rt.toSecText(), "-4:05:03");
414 }
299 }; 415 };
300 416
301 #endif 417 #endif