void tst_QMediaTimeRange::testCtor()
{
    // Default Ctor
    QMediaTimeRange a;
    QVERIFY(a.isEmpty());

    // (qint, qint) Ctor
    QMediaTimeRange b(10, 20);

    QVERIFY(!b.isEmpty());
    QVERIFY(b.isContinuous());
    QVERIFY(b.earliestTime() == 10);
    QVERIFY(b.latestTime() == 20);

    // Interval Ctor
    QMediaTimeRange c(QMediaTimeInterval(30, 40));

    QVERIFY(!c.isEmpty());
    QVERIFY(c.isContinuous());
    QVERIFY(c.earliestTime() == 30);
    QVERIFY(c.latestTime() == 40);

    // Abnormal Interval Ctor
    QMediaTimeRange d(QMediaTimeInterval(20, 10));

    QVERIFY(d.isEmpty());

    // Copy Ctor
    QMediaTimeRange e(b);

    QVERIFY(!e.isEmpty());
    QVERIFY(e.isContinuous());
    QVERIFY(e.earliestTime() == 10);
    QVERIFY(e.latestTime() == 20);
}
예제 #2
0
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;
        }
    }
}
예제 #3
0
/*!
    \fn QMediaTimeInterval::normalized() const

    Returns a normalized version of this interval.

    If the start() time of the interval is greater than the end() time,
    then the returned interval has the start and end times swapped.
    \since 1.0
*/
QMediaTimeInterval QMediaTimeInterval::normalized() const
{
    if(s > e)
        return QMediaTimeInterval(e, s);

    return *this;
}
void tst_QMediaTimeRange::testAssignment()
{
    QMediaTimeRange x;

    // Range Assignment
    x = QMediaTimeRange(10, 20);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 20);

    // Interval Assignment
    x = QMediaTimeInterval(30, 40);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 30);
    QVERIFY(x.latestTime() == 40);

    // Shared Data Check
    QMediaTimeRange y;

    y = x;
    y.addInterval(10, 20);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 30);
    QVERIFY(x.latestTime() == 40);
}
void tst_QMediaTimeRange::testComparisons()
{
    // Interval equality
    QVERIFY(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 20));
    QVERIFY(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 30));
    QVERIFY(!(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 20)));
    QVERIFY(!(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 30)));

    // Time range equality - Single Interval
    QMediaTimeRange a(10, 20), b(20, 30), c(10, 20);

    QVERIFY(a == c);
    QVERIFY(!(a == b));
    QVERIFY(a != b);
    QVERIFY(!(a != c));

    // Time Range Equality - Multiple Intervals
    QMediaTimeRange x, y, z;

    x.addInterval(10, 20);
    x.addInterval(30, 40);
    x.addInterval(50, 60);

    y.addInterval(10, 20);
    y.addInterval(35, 45);
    y.addInterval(50, 60);

    z.addInterval(10, 20);
    z.addInterval(30, 40);
    z.addInterval(50, 60);

    QVERIFY(x == z);
    QVERIFY(!(x == y));
    QVERIFY(x != y);
    QVERIFY(!(x != z));
}
예제 #6
0
/*!
    \fn QMediaTimeRange::removeInterval(qint64 start, qint64 end)
    \overload

    Removes the interval specified by \a start and \a end
    from the time range.

    \since 1.0
    \sa removeInterval()
*/
void QMediaTimeRange::removeInterval(qint64 start, qint64 end)
{
    d->removeInterval(QMediaTimeInterval(start, end));
}
예제 #7
0
/*!
    \fn QMediaTimeRange::addInterval(qint64 start, qint64 end)
    \overload

    Adds the interval specified by \a start and \a end
    to the time range.

    \since 1.0
    \sa addInterval()
*/
void QMediaTimeRange::addInterval(qint64 start, qint64 end)
{
    d->addInterval(QMediaTimeInterval(start, end));
}
예제 #8
0
/*!
    \fn QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end)

    Constructs a time range that contains an initial interval from
    \a start to \a end inclusive.

    If the interval is not \l{QMediaTimeInterval::isNormal()}{normal},
    the resulting time range will be empty.

    \since 1.0
    \sa addInterval()
*/
QMediaTimeRange::QMediaTimeRange(qint64 start, qint64 end)
    : d(new QMediaTimeRangePrivate(QMediaTimeInterval(start, end)))
{

}
예제 #9
0
/*!
    \fn QMediaTimeInterval::translated(qint64 offset) const

    Returns a copy of this time interval, translated by a value of \a offset.
    An interval can be moved forward through time with a positive offset, or backward
    through time with a negative offset.
    \since 1.0
*/
QMediaTimeInterval QMediaTimeInterval::translated(qint64 offset) const
{
    return QMediaTimeInterval(s + offset, e + offset);
}
void tst_QMediaTimeRange::testArithmetic()
{
    QMediaTimeRange a(10, 20), b(20, 30);

    // Test +=
    a += b;

    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 30);

    // Test -=
    a -= b;

    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 19);

    // Test += and -= on intervals
    a -= QMediaTimeInterval(10, 20);
    a += QMediaTimeInterval(40, 50);

    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 40);
    QVERIFY(a.latestTime() == 50);

    // Test Interval + Interval
    a = QMediaTimeInterval(10, 20) + QMediaTimeInterval(20, 30);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 30);

    // Test Range + Interval
    a = a + QMediaTimeInterval(30, 40);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 40);

    // Test Interval + Range
    a = QMediaTimeInterval(40, 50) + a;
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 50);

    // Test Range + Range
    a = a + QMediaTimeRange(50, 60);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 60);

    // Test Range - Interval
    a = a - QMediaTimeInterval(50, 60);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 49);

    // Test Range - Range
    a = a - QMediaTimeRange(40, 50);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 39);

    // Test Interval - Range
    b = QMediaTimeInterval(0, 20) - a;
    QVERIFY(b.isContinuous());
    QVERIFY(b.earliestTime() == 0);
    QVERIFY(b.latestTime() == 9);

    // Test Interval - Interval
    a = QMediaTimeInterval(10, 20) - QMediaTimeInterval(15, 30);
    QVERIFY(a.isContinuous());
    QVERIFY(a.earliestTime() == 10);
    QVERIFY(a.latestTime() == 14);
}
void tst_QMediaTimeRange::testRemoveInterval()
{
    // Removing an interval, causing a split
    QMediaTimeRange x;
    x.addInterval(10, 50);
    x.removeInterval(20, 40);

    QVERIFY(!x.isEmpty());
    QVERIFY(!x.isContinuous());
    QVERIFY(x.intervals().count() == 2);
    QVERIFY(x.intervals()[0].start() == 10);
    QVERIFY(x.intervals()[0].end() == 19);
    QVERIFY(x.intervals()[1].start() == 41);
    QVERIFY(x.intervals()[1].end() == 50);

    // Removing an interval, causing a deletion
    x = QMediaTimeRange();
    x.addInterval(20, 30);
    x.removeInterval(10, 40);

    QVERIFY(x.isEmpty());

    // Removing an interval, causing a tail trim
    x = QMediaTimeRange();
    x.addInterval(20, 40);
    x.removeInterval(30, 50);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 20);
    QVERIFY(x.latestTime() == 29);

    // Removing an interval, causing a head trim
    x = QMediaTimeRange();
    x.addInterval(20, 40);
    x.removeInterval(10, 30);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 31);
    QVERIFY(x.latestTime() == 40);

    // Identical Remove
    x = QMediaTimeRange();
    x.addInterval(10, 20);
    x.removeInterval(10, 20);

    QVERIFY(x.isEmpty());

    // Multi-Trim
    x = QMediaTimeRange();
    x.addInterval(10, 20);
    x.addInterval(30, 40);
    x.removeInterval(15, 35);

    QVERIFY(!x.isEmpty());
    QVERIFY(!x.isContinuous());
    QVERIFY(x.intervals().count() == 2);
    QVERIFY(x.intervals()[0].start() == 10);
    QVERIFY(x.intervals()[0].end() == 14);
    QVERIFY(x.intervals()[1].start() == 36);
    QVERIFY(x.intervals()[1].end() == 40);

    // Multi-Delete
    x = QMediaTimeRange();
    x.addInterval(10, 20);
    x.addInterval(30, 40);
    x.addInterval(50, 60);
    x.removeInterval(10, 60);

    QVERIFY(x.isEmpty());

    // Interval Parameter - Removing an interval, causing a split
    x = QMediaTimeRange();
    x.addInterval(10, 50);
    x.removeInterval(QMediaTimeInterval(20, 40));

    QVERIFY(!x.isEmpty());
    QVERIFY(!x.isContinuous());
    QVERIFY(x.intervals().count() == 2);
    QVERIFY(x.intervals()[0].start() == 10);
    QVERIFY(x.intervals()[0].end() == 19);
    QVERIFY(x.intervals()[1].start() == 41);
    QVERIFY(x.intervals()[1].end() == 50);

    // Interval Parameter - Abnormal Interval
    x = QMediaTimeRange();
    x.addInterval(10, 40);
    x.removeInterval(QMediaTimeInterval(30, 20));

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 40);
}
void tst_QMediaTimeRange::testAddInterval()
{
    // All intervals Overlap
    QMediaTimeRange x;
    x.addInterval(10, 40);
    x.addInterval(30, 50);
    x.addInterval(20, 60);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 60);

    // 1 adjacent interval, 1 encompassed interval
    x = QMediaTimeRange();
    x.addInterval(10, 40);
    x.addInterval(20, 30);
    x.addInterval(41, 50);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 50);

    // 1 overlapping interval, 1 disjoint interval
    x = QMediaTimeRange();
    x.addInterval(10, 30);
    x.addInterval(20, 40);
    x.addInterval(50, 60);

    QVERIFY(!x.isEmpty());
    QVERIFY(!x.isContinuous());
    QVERIFY(x.intervals().count() == 2);
    QVERIFY(x.intervals()[0].start() == 10);
    QVERIFY(x.intervals()[0].end() == 40);
    QVERIFY(x.intervals()[1].start() == 50);
    QVERIFY(x.intervals()[1].end() == 60);

    // Identical Add
    x = QMediaTimeRange();
    x.addInterval(10, 20);
    x.addInterval(10, 20);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 20);

    // Multi-Merge
    x = QMediaTimeRange();
    x.addInterval(10, 20);
    x.addInterval(30, 40);
    x.addInterval(50, 60);
    x.addInterval(15, 55);

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 60);

    // Interval Parameter - All intervals Overlap
    x = QMediaTimeRange();
    x.addInterval(QMediaTimeInterval(10, 40));
    x.addInterval(QMediaTimeInterval(30, 50));
    x.addInterval(QMediaTimeInterval(20, 60));

    QVERIFY(!x.isEmpty());
    QVERIFY(x.isContinuous());
    QVERIFY(x.earliestTime() == 10);
    QVERIFY(x.latestTime() == 60);

    // Interval Parameter - Abnormal Interval
    x = QMediaTimeRange();
    x.addInterval(QMediaTimeInterval(20, 10));

    QVERIFY(x.isEmpty());
}