1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29//TESTED_COMPONENT=src/multimedia
30
31#include <QtTest/QtTest>
32#include <QtCore/qdebug.h>
33
34#include <qmediatimerange.h>
35#include <qmediatimerange.h>
36
37QT_USE_NAMESPACE
38
39class tst_QMediaTimeRange: public QObject
40{
41 Q_OBJECT
42
43public slots:
44
45private slots:
46 void testCtor();
47 void testIntervalCtor();
48 void testGetters();
49 void testAssignment();
50 void testIntervalNormalize();
51 void testIntervalTranslate();
52 void testIntervalContains();
53 void testEarliestLatest();
54 void testContains();
55 void testAddInterval();
56 void testAddTimeRange();
57 void testRemoveInterval();
58 void testRemoveTimeRange();
59 void testClear();
60 void testComparisons();
61 void testArithmetic();
62};
63
64void tst_QMediaTimeRange::testIntervalCtor()
65{
66 //Default Ctor for Time Interval
67 /* create an instance for the time interval and verify the default cases */
68 QMediaTimeInterval tInter;
69 QVERIFY(tInter.isNormal());
70 QVERIFY(tInter.start() == 0);
71 QVERIFY(tInter.end() == 0);
72
73 // (qint, qint) Ctor time interval
74 /* create an instace of QMediaTimeInterval passing start and end times and verify the all possible scenario's*/
75 QMediaTimeInterval time(20,50);
76 QVERIFY(time.isNormal());
77 QVERIFY(time.start() == 20);
78 QVERIFY(time.end() == 50);
79
80 // Copy Ctor Time interval
81 QMediaTimeInterval other(time);
82 QVERIFY(other.isNormal() == time.isNormal());
83 QVERIFY(other.start() == time.start());
84 QVERIFY(other.end() == time.end());
85 QVERIFY(other.contains(20) == time.contains(20));
86 QVERIFY(other == time);
87}
88
89void tst_QMediaTimeRange::testIntervalContains()
90{
91 QMediaTimeInterval time(20,50);
92
93 /* start() <= time <= end(). Returns true if the time interval contains the specified time. */
94 QVERIFY(!time.contains(10));
95 QVERIFY(time.contains(20));
96 QVERIFY(time.contains(30));
97 QVERIFY(time.contains(50));
98 QVERIFY(!time.contains(60));
99
100 QMediaTimeInterval x(20, 10); // denormal
101
102 // Check denormal ranges
103 QVERIFY(!x.contains(5));
104 QVERIFY(x.contains(10));
105 QVERIFY(x.contains(15));
106 QVERIFY(x.contains(20));
107 QVERIFY(!x.contains(25));
108
109 QMediaTimeInterval y = x.normalized();
110 QVERIFY(!y.contains(5));
111 QVERIFY(y.contains(10));
112 QVERIFY(y.contains(15));
113 QVERIFY(y.contains(20));
114 QVERIFY(!y.contains(25));
115}
116
117void tst_QMediaTimeRange::testCtor()
118{
119 // Default Ctor
120 QMediaTimeRange a;
121 QVERIFY(a.isEmpty());
122
123 // (qint, qint) Ctor
124 QMediaTimeRange b(10, 20);
125
126 QVERIFY(!b.isEmpty());
127 QVERIFY(b.isContinuous());
128 QVERIFY(b.earliestTime() == 10);
129 QVERIFY(b.latestTime() == 20);
130
131 // Interval Ctor
132 QMediaTimeRange c(QMediaTimeInterval(30, 40));
133
134 QVERIFY(!c.isEmpty());
135 QVERIFY(c.isContinuous());
136 QVERIFY(c.earliestTime() == 30);
137 QVERIFY(c.latestTime() == 40);
138
139 // Abnormal Interval Ctor
140 QMediaTimeRange d(QMediaTimeInterval(20, 10));
141
142 QVERIFY(d.isEmpty());
143
144 // Copy Ctor
145 QMediaTimeRange e(b);
146
147 QVERIFY(!e.isEmpty());
148 QVERIFY(e.isContinuous());
149 QVERIFY(e.earliestTime() == 10);
150 QVERIFY(e.latestTime() == 20);
151
152 QVERIFY(e == b);
153}
154
155void tst_QMediaTimeRange::testGetters()
156{
157 QMediaTimeRange x;
158
159 // isEmpty
160 QVERIFY(x.isEmpty());
161
162 x.addInterval(start: 10, end: 20);
163
164 // isEmpty + isContinuous
165 QVERIFY(!x.isEmpty());
166 QVERIFY(x.isContinuous());
167
168 x.addInterval(start: 30, end: 40);
169
170 // isEmpty + isContinuous + intervals + start + end
171 QVERIFY(!x.isEmpty());
172 QVERIFY(!x.isContinuous());
173 QVERIFY(x.intervals().count() == 2);
174 QVERIFY(x.intervals()[0].start() == 10);
175 QVERIFY(x.intervals()[0].end() == 20);
176 QVERIFY(x.intervals()[1].start() == 30);
177 QVERIFY(x.intervals()[1].end() == 40);
178}
179
180void tst_QMediaTimeRange::testAssignment()
181{
182 QMediaTimeRange x;
183
184 // Range Assignment
185 x = QMediaTimeRange(10, 20);
186
187 QVERIFY(!x.isEmpty());
188 QVERIFY(x.isContinuous());
189 QVERIFY(x.earliestTime() == 10);
190 QVERIFY(x.latestTime() == 20);
191
192 // Interval Assignment
193 x = QMediaTimeInterval(30, 40);
194
195 QVERIFY(!x.isEmpty());
196 QVERIFY(x.isContinuous());
197 QVERIFY(x.earliestTime() == 30);
198 QVERIFY(x.latestTime() == 40);
199
200 // Shared Data Check
201 QMediaTimeRange y;
202
203 y = x;
204 y.addInterval(start: 10, end: 20);
205
206 QVERIFY(!x.isEmpty());
207 QVERIFY(x.isContinuous());
208 QVERIFY(x.earliestTime() == 30);
209 QVERIFY(x.latestTime() == 40);
210}
211
212void tst_QMediaTimeRange::testIntervalNormalize()
213{
214 QMediaTimeInterval x(20, 10);
215
216 QVERIFY(!x.isNormal());
217 QVERIFY(x.start() == 20);
218 QVERIFY(x.end() == 10);
219
220 QMediaTimeInterval y = x.normalized();
221
222 QVERIFY(y.isNormal());
223 QVERIFY(y.start() == 10);
224 QVERIFY(y.end() == 20);
225 QVERIFY(x != y);
226}
227
228void tst_QMediaTimeRange::testIntervalTranslate()
229{
230 QMediaTimeInterval x(10, 20);
231 x = x.translated(offset: 10);
232
233 QVERIFY(x.start() == 20);
234 QVERIFY(x.end() == 30);
235
236 /* verifying the backward through time with a negative offset.*/
237 x = x.translated(offset: -10);
238
239 QVERIFY(x.start() == 10);
240 QVERIFY(x.end() == 20);
241}
242
243void tst_QMediaTimeRange::testEarliestLatest()
244{
245 // Test over a single interval
246 QMediaTimeRange x(30, 40);
247
248 QVERIFY(x.earliestTime() == 30);
249 QVERIFY(x.latestTime() == 40);
250
251 // Test over multiple intervals
252 x.addInterval(start: 50, end: 60);
253
254 QVERIFY(x.earliestTime() == 30);
255 QVERIFY(x.latestTime() == 60);
256}
257
258void tst_QMediaTimeRange::testContains()
259{
260 // Test over a single interval
261 QMediaTimeRange x(10, 20);
262
263 QVERIFY(!x.isEmpty());
264 QVERIFY(x.isContinuous());
265 QVERIFY(x.contains(15));
266 QVERIFY(x.contains(10));
267 QVERIFY(x.contains(20));
268 QVERIFY(!x.contains(25));
269
270 // Test over multiple intervals
271 x.addInterval(start: 40, end: 50);
272
273 QVERIFY(!x.isEmpty());
274 QVERIFY(!x.isContinuous());
275 QVERIFY(x.contains(15));
276 QVERIFY(x.contains(45));
277 QVERIFY(!x.contains(30));
278
279 // Test over a concrete interval
280 QMediaTimeInterval y(10, 20);
281 QVERIFY(y.contains(15));
282 QVERIFY(y.contains(10));
283 QVERIFY(y.contains(20));
284 QVERIFY(!y.contains(25));
285}
286
287void tst_QMediaTimeRange::testAddInterval()
288{
289 // All intervals Overlap
290 QMediaTimeRange x;
291 x.addInterval(start: 10, end: 40);
292 x.addInterval(start: 30, end: 50);
293 x.addInterval(start: 20, end: 60);
294
295 QVERIFY(!x.isEmpty());
296 QVERIFY(x.isContinuous());
297 QVERIFY(x.earliestTime() == 10);
298 QVERIFY(x.latestTime() == 60);
299
300 // 1 adjacent interval, 1 encompassed interval
301 x = QMediaTimeRange();
302 x.addInterval(start: 10, end: 40);
303 x.addInterval(start: 20, end: 30);
304 x.addInterval(start: 41, end: 50);
305
306 QVERIFY(!x.isEmpty());
307 QVERIFY(x.isContinuous());
308 QVERIFY(x.earliestTime() == 10);
309 QVERIFY(x.latestTime() == 50);
310
311 // 1 overlapping interval, 1 disjoint interval
312 x = QMediaTimeRange();
313 x.addInterval(start: 10, end: 30);
314 x.addInterval(start: 20, end: 40);
315 x.addInterval(start: 50, end: 60);
316
317 QVERIFY(!x.isEmpty());
318 QVERIFY(!x.isContinuous());
319 QVERIFY(x.intervals().count() == 2);
320 QVERIFY(x.intervals()[0].start() == 10);
321 QVERIFY(x.intervals()[0].end() == 40);
322 QVERIFY(x.intervals()[1].start() == 50);
323 QVERIFY(x.intervals()[1].end() == 60);
324
325 // Identical Add
326 x = QMediaTimeRange();
327 x.addInterval(start: 10, end: 20);
328 x.addInterval(start: 10, end: 20);
329
330 QVERIFY(!x.isEmpty());
331 QVERIFY(x.isContinuous());
332 QVERIFY(x.earliestTime() == 10);
333 QVERIFY(x.latestTime() == 20);
334
335 // Multi-Merge
336 x = QMediaTimeRange();
337 x.addInterval(start: 10, end: 20);
338 x.addInterval(start: 30, end: 40);
339 x.addInterval(start: 50, end: 60);
340 x.addInterval(start: 15, end: 55);
341
342 QVERIFY(!x.isEmpty());
343 QVERIFY(x.isContinuous());
344 QVERIFY(x.earliestTime() == 10);
345 QVERIFY(x.latestTime() == 60);
346
347 // Interval Parameter - All intervals Overlap
348 x = QMediaTimeRange();
349 x.addInterval(interval: QMediaTimeInterval(10, 40));
350 x.addInterval(interval: QMediaTimeInterval(30, 50));
351 x.addInterval(interval: QMediaTimeInterval(20, 60));
352
353 QVERIFY(!x.isEmpty());
354 QVERIFY(x.isContinuous());
355 QVERIFY(x.earliestTime() == 10);
356 QVERIFY(x.latestTime() == 60);
357
358 // Interval Parameter - Abnormal Interval
359 x = QMediaTimeRange();
360 x.addInterval(interval: QMediaTimeInterval(20, 10));
361
362 QVERIFY(x.isEmpty());
363}
364
365void tst_QMediaTimeRange::testAddTimeRange()
366{
367 // Add Time Range uses Add Interval internally,
368 // so in this test the focus is on combinations of number
369 // of intervals added, rather than the different types of
370 // merges which can occur.
371 QMediaTimeRange a, b;
372
373 // Add Single into Single
374 a = QMediaTimeRange(10, 30);
375 b = QMediaTimeRange(20, 40);
376
377 b.addTimeRange(a);
378
379 QVERIFY(!b.isEmpty());
380 QVERIFY(b.isContinuous());
381 QVERIFY(b.earliestTime() == 10);
382 QVERIFY(b.latestTime() == 40);
383
384 // Add Multiple into Single
385 a = QMediaTimeRange();
386 a.addInterval(start: 10, end: 30);
387 a.addInterval(start: 40, end: 60);
388
389 b = QMediaTimeRange(20, 50);
390
391 b.addTimeRange(a);
392
393 QVERIFY(!b.isEmpty());
394 QVERIFY(b.isContinuous());
395 QVERIFY(b.earliestTime() == 10);
396 QVERIFY(b.latestTime() == 60);
397
398 // Add Single into Multiple
399 a = QMediaTimeRange(20, 50);
400
401 b = QMediaTimeRange();
402 b.addInterval(start: 10, end: 30);
403 b.addInterval(start: 40, end: 60);
404
405 b.addTimeRange(a);
406
407 QVERIFY(!b.isEmpty());
408 QVERIFY(b.isContinuous());
409 QVERIFY(b.earliestTime() == 10);
410 QVERIFY(b.latestTime() == 60);
411
412 // Add Multiple into Multiple
413 a = QMediaTimeRange();
414 a.addInterval(start: 10, end: 30);
415 a.addInterval(start: 40, end: 70);
416 a.addInterval(start: 80, end: 100);
417
418 b = QMediaTimeRange();
419 b.addInterval(start: 20, end: 50);
420 b.addInterval(start: 60, end: 90);
421
422 b.addTimeRange(a);
423
424 QVERIFY(!b.isEmpty());
425 QVERIFY(b.isContinuous());
426 QVERIFY(b.earliestTime() == 10);
427 QVERIFY(b.latestTime() == 100);
428
429 // Add Nothing to Single
430 a = QMediaTimeRange();
431 b = QMediaTimeRange(10, 20);
432
433 b.addTimeRange(a);
434
435 QVERIFY(!b.isEmpty());
436 QVERIFY(b.isContinuous());
437 QVERIFY(b.earliestTime() == 10);
438 QVERIFY(b.latestTime() == 20);
439
440 // Add Single to Nothing
441 a = QMediaTimeRange(10, 20);
442 b = QMediaTimeRange();
443
444 b.addTimeRange(a);
445
446 QVERIFY(!b.isEmpty());
447 QVERIFY(b.isContinuous());
448 QVERIFY(b.earliestTime() == 10);
449 QVERIFY(b.latestTime() == 20);
450
451 // Add Nothing to Nothing
452 a = QMediaTimeRange();
453 b = QMediaTimeRange();
454
455 b.addTimeRange(a);
456
457 QVERIFY(b.isEmpty());
458}
459
460void tst_QMediaTimeRange::testRemoveInterval()
461{
462 // Removing an interval, causing a split
463 QMediaTimeRange x;
464 x.addInterval(start: 10, end: 50);
465 x.removeInterval(start: 20, end: 40);
466
467 QVERIFY(!x.isEmpty());
468 QVERIFY(!x.isContinuous());
469 QVERIFY(x.intervals().count() == 2);
470 QVERIFY(x.intervals()[0].start() == 10);
471 QVERIFY(x.intervals()[0].end() == 19);
472 QVERIFY(x.intervals()[1].start() == 41);
473 QVERIFY(x.intervals()[1].end() == 50);
474
475 // Removing an interval, causing a deletion
476 x = QMediaTimeRange();
477 x.addInterval(start: 20, end: 30);
478 x.removeInterval(start: 10, end: 40);
479
480 QVERIFY(x.isEmpty());
481
482 // Removing an interval, causing a tail trim
483 x = QMediaTimeRange();
484 x.addInterval(start: 20, end: 40);
485 x.removeInterval(start: 30, end: 50);
486
487 QVERIFY(!x.isEmpty());
488 QVERIFY(x.isContinuous());
489 QVERIFY(x.earliestTime() == 20);
490 QVERIFY(x.latestTime() == 29);
491
492 // Removing an interval, causing a head trim
493 x = QMediaTimeRange();
494 x.addInterval(start: 20, end: 40);
495 x.removeInterval(start: 10, end: 30);
496
497 QVERIFY(!x.isEmpty());
498 QVERIFY(x.isContinuous());
499 QVERIFY(x.earliestTime() == 31);
500 QVERIFY(x.latestTime() == 40);
501
502 // Identical Remove
503 x = QMediaTimeRange();
504 x.addInterval(start: 10, end: 20);
505 x.removeInterval(start: 10, end: 20);
506
507 QVERIFY(x.isEmpty());
508
509 // Multi-Trim
510 x = QMediaTimeRange();
511 x.addInterval(start: 10, end: 20);
512 x.addInterval(start: 30, end: 40);
513 x.removeInterval(start: 15, end: 35);
514
515 QVERIFY(!x.isEmpty());
516 QVERIFY(!x.isContinuous());
517 QVERIFY(x.intervals().count() == 2);
518 QVERIFY(x.intervals()[0].start() == 10);
519 QVERIFY(x.intervals()[0].end() == 14);
520 QVERIFY(x.intervals()[1].start() == 36);
521 QVERIFY(x.intervals()[1].end() == 40);
522
523 // Multi-Delete
524 x = QMediaTimeRange();
525 x.addInterval(start: 10, end: 20);
526 x.addInterval(start: 30, end: 40);
527 x.addInterval(start: 50, end: 60);
528 x.removeInterval(start: 10, end: 60);
529
530 QVERIFY(x.isEmpty());
531
532 // Interval Parameter - Removing an interval, causing a split
533 x = QMediaTimeRange();
534 x.addInterval(start: 10, end: 50);
535 x.removeInterval(interval: QMediaTimeInterval(20, 40));
536
537 QVERIFY(!x.isEmpty());
538 QVERIFY(!x.isContinuous());
539 QVERIFY(x.intervals().count() == 2);
540 QVERIFY(x.intervals()[0].start() == 10);
541 QVERIFY(x.intervals()[0].end() == 19);
542 QVERIFY(x.intervals()[1].start() == 41);
543 QVERIFY(x.intervals()[1].end() == 50);
544
545 // Interval Parameter - Abnormal Interval
546 x = QMediaTimeRange();
547 x.addInterval(start: 10, end: 40);
548 x.removeInterval(interval: QMediaTimeInterval(30, 20));
549
550 QVERIFY(!x.isEmpty());
551 QVERIFY(x.isContinuous());
552 QVERIFY(x.earliestTime() == 10);
553 QVERIFY(x.latestTime() == 40);
554}
555
556void tst_QMediaTimeRange::testRemoveTimeRange()
557{
558 // Remove Time Range uses Remove Interval internally,
559 // so in this test the focus is on combinations of number
560 // of intervals removed, rather than the different types of
561 // deletions which can occur.
562 QMediaTimeRange a, b;
563
564 // Remove Single from Single
565 a = QMediaTimeRange(10, 30);
566 b = QMediaTimeRange(20, 40);
567
568 b.removeTimeRange(a);
569
570 QVERIFY(!b.isEmpty());
571 QVERIFY(b.isContinuous());
572 QVERIFY(b.earliestTime() == 31);
573 QVERIFY(b.latestTime() == 40);
574
575 // Remove Multiple from Single
576 a = QMediaTimeRange();
577 a.addInterval(start: 10, end: 30);
578 a.addInterval(start: 40, end: 60);
579
580 b = QMediaTimeRange(20, 50);
581
582 b.removeTimeRange(a);
583
584 QVERIFY(!b.isEmpty());
585 QVERIFY(b.isContinuous());
586 QVERIFY(b.earliestTime() == 31);
587 QVERIFY(b.latestTime() == 39);
588
589 // Remove Single from Multiple
590 a = QMediaTimeRange(20, 50);
591
592 b = QMediaTimeRange();
593 b.addInterval(start: 10, end: 30);
594 b.addInterval(start: 40, end: 60);
595
596 b.removeTimeRange(a);
597
598 QVERIFY(!b.isEmpty());
599 QVERIFY(!b.isContinuous());
600 QVERIFY(b.intervals().count() == 2);
601 QVERIFY(b.intervals()[0].start() == 10);
602 QVERIFY(b.intervals()[0].end() == 19);
603 QVERIFY(b.intervals()[1].start() == 51);
604 QVERIFY(b.intervals()[1].end() == 60);
605
606 // Remove Multiple from Multiple
607 a = QMediaTimeRange();
608 a.addInterval(start: 20, end: 50);
609 a.addInterval(start: 50, end: 90);
610
611
612 b = QMediaTimeRange();
613 b.addInterval(start: 10, end: 30);
614 b.addInterval(start: 40, end: 70);
615 b.addInterval(start: 80, end: 100);
616
617 b.removeTimeRange(a);
618
619 QVERIFY(!b.isEmpty());
620 QVERIFY(!b.isContinuous());
621 QVERIFY(b.intervals().count() == 2);
622 QVERIFY(b.intervals()[0].start() == 10);
623 QVERIFY(b.intervals()[0].end() == 19);
624 QVERIFY(b.intervals()[1].start() == 91);
625 QVERIFY(b.intervals()[1].end() == 100);
626
627 // Remove Nothing from Single
628 a = QMediaTimeRange();
629 b = QMediaTimeRange(10, 20);
630
631 b.removeTimeRange(a);
632
633 QVERIFY(!b.isEmpty());
634 QVERIFY(b.isContinuous());
635 QVERIFY(b.earliestTime() == 10);
636 QVERIFY(b.latestTime() == 20);
637
638 // Remove Single from Nothing
639 a = QMediaTimeRange(10, 20);
640 b = QMediaTimeRange();
641
642 b.removeTimeRange(a);
643
644 QVERIFY(b.isEmpty());
645
646 // Remove Nothing from Nothing
647 a = QMediaTimeRange();
648 b = QMediaTimeRange();
649
650 b.removeTimeRange(a);
651
652 QVERIFY(b.isEmpty());
653}
654
655void tst_QMediaTimeRange::testClear()
656{
657 QMediaTimeRange x;
658
659 // Clear Nothing
660 x.clear();
661
662 QVERIFY(x.isEmpty());
663
664 // Clear Single
665 x = QMediaTimeRange(10, 20);
666 x.clear();
667
668 QVERIFY(x.isEmpty());
669
670 // Clear Multiple
671 x = QMediaTimeRange();
672 x.addInterval(start: 10, end: 20);
673 x.addInterval(start: 30, end: 40);
674 x.clear();
675
676 QVERIFY(x.isEmpty());
677}
678
679void tst_QMediaTimeRange::testComparisons()
680{
681 // Interval equality
682 QVERIFY(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 20));
683 QVERIFY(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 30));
684 QVERIFY(!(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 20)));
685 QVERIFY(!(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 30)));
686
687 // Time range equality - Single Interval
688 QMediaTimeRange a(10, 20), b(20, 30), c(10, 20);
689
690 QVERIFY(a == c);
691 QVERIFY(!(a == b));
692 QVERIFY(a != b);
693 QVERIFY(!(a != c));
694
695 // Time Range Equality - Multiple Intervals
696 QMediaTimeRange x, y, z;
697
698 x.addInterval(start: 10, end: 20);
699 x.addInterval(start: 30, end: 40);
700 x.addInterval(start: 50, end: 60);
701
702 y.addInterval(start: 10, end: 20);
703 y.addInterval(start: 35, end: 45);
704 y.addInterval(start: 50, end: 60);
705
706 z.addInterval(start: 10, end: 20);
707 z.addInterval(start: 30, end: 40);
708 z.addInterval(start: 50, end: 60);
709
710 QVERIFY(x == z);
711 QVERIFY(!(x == y));
712 QVERIFY(x != y);
713 QVERIFY(!(x != z));
714}
715
716void tst_QMediaTimeRange::testArithmetic()
717{
718 QMediaTimeRange a(10, 20), b(20, 30);
719
720 // Test +=
721 a += b;
722
723 QVERIFY(a.isContinuous());
724 QVERIFY(a.earliestTime() == 10);
725 QVERIFY(a.latestTime() == 30);
726
727 // Test -=
728 a -= b;
729
730 QVERIFY(a.isContinuous());
731 QVERIFY(a.earliestTime() == 10);
732 QVERIFY(a.latestTime() == 19);
733
734 // Test += and -= on intervals
735 a -= QMediaTimeInterval(10, 20);
736 a += QMediaTimeInterval(40, 50);
737
738 QVERIFY(a.isContinuous());
739 QVERIFY(a.earliestTime() == 40);
740 QVERIFY(a.latestTime() == 50);
741
742 // Test Interval + Interval
743 a = QMediaTimeInterval(10, 20) + QMediaTimeInterval(20, 30);
744 QVERIFY(a.isContinuous());
745 QVERIFY(a.earliestTime() == 10);
746 QVERIFY(a.latestTime() == 30);
747
748 // Test Range + Interval
749 a = a + QMediaTimeInterval(30, 40);
750 QVERIFY(a.isContinuous());
751 QVERIFY(a.earliestTime() == 10);
752 QVERIFY(a.latestTime() == 40);
753
754 // Test Interval + Range
755 a = QMediaTimeInterval(40, 50) + a;
756 QVERIFY(a.isContinuous());
757 QVERIFY(a.earliestTime() == 10);
758 QVERIFY(a.latestTime() == 50);
759
760 // Test Range + Range
761 a = a + QMediaTimeRange(50, 60);
762 QVERIFY(a.isContinuous());
763 QVERIFY(a.earliestTime() == 10);
764 QVERIFY(a.latestTime() == 60);
765
766 // Test Range - Interval
767 a = a - QMediaTimeInterval(50, 60);
768 QVERIFY(a.isContinuous());
769 QVERIFY(a.earliestTime() == 10);
770 QVERIFY(a.latestTime() == 49);
771
772 // Test Range - Range
773 a = a - QMediaTimeRange(40, 50);
774 QVERIFY(a.isContinuous());
775 QVERIFY(a.earliestTime() == 10);
776 QVERIFY(a.latestTime() == 39);
777
778 // Test Interval - Range
779 b = QMediaTimeInterval(0, 20) - a;
780 QVERIFY(b.isContinuous());
781 QVERIFY(b.earliestTime() == 0);
782 QVERIFY(b.latestTime() == 9);
783
784 // Test Interval - Interval
785 a = QMediaTimeInterval(10, 20) - QMediaTimeInterval(15, 30);
786 QVERIFY(a.isContinuous());
787 QVERIFY(a.earliestTime() == 10);
788 QVERIFY(a.latestTime() == 14);
789}
790
791QTEST_MAIN(tst_QMediaTimeRange)
792
793#include "tst_qmediatimerange.moc"
794

source code of qtmultimedia/tests/auto/unit/qmediatimerange/tst_qmediatimerange.cpp