void tst_QMediaTimeRange::testIntervalContains() { QMediaTimeInterval time(20,50); /* start() <= time <= end(). Returns true if the time interval contains the specified time. */ QVERIFY(!time.contains(10)); QVERIFY(time.contains(20)); QVERIFY(time.contains(30)); QVERIFY(time.contains(50)); QVERIFY(!time.contains(60)); QMediaTimeInterval x(20, 10); // denormal // Check denormal ranges QVERIFY(!x.contains(5)); QVERIFY(x.contains(10)); QVERIFY(x.contains(15)); QVERIFY(x.contains(20)); QVERIFY(!x.contains(25)); QMediaTimeInterval y = x.normalized(); QVERIFY(!y.contains(5)); QVERIFY(y.contains(10)); QVERIFY(y.contains(15)); QVERIFY(y.contains(20)); QVERIFY(!y.contains(25)); }
void tst_QMediaTimeRange::testIntervalNormalize() { QMediaTimeInterval x(20, 10); QVERIFY(!x.isNormal()); QVERIFY(x.start() == 20); QVERIFY(x.end() == 10); QMediaTimeInterval y = x.normalized(); QVERIFY(y.isNormal()); QVERIFY(y.start() == 10); QVERIFY(y.end() == 20); QVERIFY(x != y); }
void QMediaTimeRangePrivate::removeInterval(const QMediaTimeInterval &interval) { // Handle normalized intervals only if(!interval.isNormal()) return; for (int i = 0; i < intervals.count(); i++) { QMediaTimeInterval r = intervals[i]; if (r.e < interval.s) { // Before the removal interval continue; } else if (interval.e < r.s) { // After the removal interval - stop here break; } else if (r.s < interval.s && interval.e < r.e) { // Split case - a single range has a chunk removed intervals[i].e = interval.s -1; addInterval(QMediaTimeInterval(interval.e + 1, r.e)); break; } else if (r.s < interval.s) { // Trimming Tail Case intervals[i].e = interval.s - 1; } else if (interval.e < r.e) { // Trimming Head Case - we can stop after this intervals[i].s = interval.e + 1; break; } else { // Complete coverage case intervals.removeAt(i); --i; } } }
void QMediaTimeRangePrivate::addInterval(const QMediaTimeInterval &interval) { // Handle normalized intervals only if(!interval.isNormal()) return; // Find a place to insert the interval int i; for (i = 0; i < intervals.count(); i++) { // Insert before this element if(interval.s < intervals[i].s) { intervals.insert(i, interval); break; } } // Interval needs to be added to the end of the list if (i == intervals.count()) intervals.append(interval); // Do we need to correct the element before us? if(i > 0 && intervals[i - 1].e >= interval.s - 1) i--; // Merge trailing ranges while (i < intervals.count() - 1 && intervals[i].e >= intervals[i + 1].s - 1) { intervals[i].e = qMax(intervals[i].e, intervals[i + 1].e); intervals.removeAt(i + 1); } }
void tst_QMediaTimeRange::testIntervalCtor() { //Default Ctor for Time Interval /* create an instance for the time interval and verify the default cases */ QMediaTimeInterval tInter; QVERIFY(tInter.isNormal()); QVERIFY(tInter.start() == 0); QVERIFY(tInter.end() == 0); // (qint, qint) Ctor time interval /* create an instace of QMediaTimeInterval passing start and end times and verify the all possible scenario's*/ QMediaTimeInterval time(20,50); QVERIFY(time.isNormal()); QVERIFY(time.start() == 20); QVERIFY(time.end() == 50); // Copy Ctor Time interval QMediaTimeInterval other(time); QVERIFY(other.isNormal() == time.isNormal()); QVERIFY(other.start() == time.start()); QVERIFY(other.end() == time.end()); QVERIFY(other.contains(20) == time.contains(20)); QVERIFY(other == time); }
QMediaTimeRangePrivate::QMediaTimeRangePrivate(const QMediaTimeInterval &interval) : QSharedData() { if(interval.isNormal()) intervals << interval; }
/*! \fn operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) \relates QMediaTimeRange Returns true if \a a is not exactly equal to \a b. \since 1.0 */ bool operator!=(const QMediaTimeInterval &a, const QMediaTimeInterval &b) { return a.start() != b.start() || a.end() != b.end(); }
/*! \fn operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) \relates QMediaTimeRange Returns true if \a a is exactly equal to \a b. \since 1.0 */ bool operator==(const QMediaTimeInterval &a, const QMediaTimeInterval &b) { return a.start() == b.start() && a.end() == b.end(); }