summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/auto.pro11
-rw-r--r--tests/auto/qmediacontent/qmediacontent.pro6
-rw-r--r--tests/auto/qmediacontent/tst_qmediacontent.cpp160
-rw-r--r--tests/auto/qmediaobject/qmediaobject.pro4
-rw-r--r--tests/auto/qmediaobject/tst_qmediaobject.cpp549
-rw-r--r--tests/auto/qmediaplayer/qmediaplayer.pro6
-rw-r--r--tests/auto/qmediaplayer/tst_qmediaplayer.cpp1011
-rw-r--r--tests/auto/qmediaplaylist/qmediaplaylist.pro6
-rw-r--r--tests/auto/qmediaplaylist/tmp.unsupported_format0
-rw-r--r--tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp622
-rw-r--r--tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro6
-rw-r--r--tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp316
-rw-r--r--tests/auto/qmediapluginloader/qmediapluginloader.pro6
-rw-r--r--tests/auto/qmediapluginloader/tst_qmediapluginloader.cpp121
-rw-r--r--tests/auto/qmediaresource/qmediaresource.pro6
-rw-r--r--tests/auto/qmediaresource/tst_qmediaresource.cpp471
-rw-r--r--tests/auto/qmediaservice/qmediaservice.pro6
-rw-r--r--tests/auto/qmediaservice/tst_qmediaservice.cpp211
-rw-r--r--tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro6
-rw-r--r--tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp458
-rw-r--r--tests/auto/qmediatimerange/qmediatimerange.pro6
-rw-r--r--tests/auto/qmediatimerange/tst_qmediatimerange.cpp735
-rw-r--r--tests/auto/qvideowidget/qvideowidget.pro6
-rw-r--r--tests/auto/qvideowidget/tst_qvideowidget.cpp1595
-rw-r--r--tests/auto/tests.xml11
25 files changed, 6335 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 4215e97..50ab902 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -294,6 +294,17 @@ SUBDIRS += \
qaudioformat \
qaudiooutput \
qaudioinput \
+ qmediacontent \
+ qmediaobject \
+ qmediaplayer \
+ qmediaplaylist \
+ qmediaplaylistnavigator \
+ qmediapluginloader \
+ qmediaresource \
+ qmediaservice \
+ qmediaserviceprovider \
+ qmediatimerange \
+ qvideowidget \
qspinbox \
qsplitter \
qsql \
diff --git a/tests/auto/qmediacontent/qmediacontent.pro b/tests/auto/qmediacontent/qmediacontent.pro
new file mode 100644
index 0000000..f7884f6
--- /dev/null
+++ b/tests/auto/qmediacontent/qmediacontent.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES += tst_qmediacontent.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediacontent/tst_qmediacontent.cpp b/tests/auto/qmediacontent/tst_qmediacontent.cpp
new file mode 100644
index 0000000..4857672
--- /dev/null
+++ b/tests/auto/qmediacontent/tst_qmediacontent.cpp
@@ -0,0 +1,160 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtMultimedia/qmediacontent.h>
+
+
+class tst_QMediaContent : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testNull();
+ void testUrlCtor();
+ void testResourceCtor();
+ void testResourceListCtor();
+ void testCopy();
+ void testAssignment();
+ void testEquality();
+ void testResources();
+};
+
+void tst_QMediaContent::testNull()
+{
+ QMediaContent media;
+
+ QCOMPARE(media.isNull(), true);
+ QCOMPARE(media.canonicalUrl(), QUrl());
+ QCOMPARE(media.canonicalResource(), QMediaResource());
+ QCOMPARE(media.resources(), QMediaResourceList());
+}
+
+void tst_QMediaContent::testUrlCtor()
+{
+ QMediaContent media(QUrl("http://example.com/movie.mov"));
+
+ QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov"));
+ QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov"));
+}
+
+void tst_QMediaContent::testResourceCtor()
+{
+ QMediaContent media(QMediaResource(QUrl("http://example.com/movie.mov")));
+
+ QCOMPARE(media.canonicalResource(), QMediaResource(QUrl("http://example.com/movie.mov")));
+}
+
+void tst_QMediaContent::testResourceListCtor()
+{
+ QMediaResourceList resourceList;
+ resourceList << QMediaResource(QUrl("http://example.com/movie.mov"));
+
+ QMediaContent media(resourceList);
+
+ QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov"));
+ QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov"));
+}
+
+void tst_QMediaContent::testCopy()
+{
+ QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov")));
+ QMediaContent media2(media1);
+
+ QVERIFY(media1 == media2);
+}
+
+void tst_QMediaContent::testAssignment()
+{
+ QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov")));
+ QMediaContent media2;
+ QMediaContent media3;
+
+ media2 = media1;
+ QVERIFY(media2 == media1);
+
+ media2 = media3;
+ QVERIFY(media2 == media3);
+}
+
+void tst_QMediaContent::testEquality()
+{
+ QMediaContent media1;
+ QMediaContent media2;
+ QMediaContent media3(QMediaResource(QUrl("http://example.com/movie.mov")));
+ QMediaContent media4(QMediaResource(QUrl("http://example.com/movie.mov")));
+ QMediaContent media5(QMediaResource(QUrl("file:///some/where/over/the/rainbow.mp3")));
+
+ // null == null
+ QCOMPARE(media1 == media2, true);
+ QCOMPARE(media1 != media2, false);
+
+ // null != something
+ QCOMPARE(media1 == media3, false);
+ QCOMPARE(media1 != media3, true);
+
+ // equiv
+ QCOMPARE(media3 == media4, true);
+ QCOMPARE(media3 != media4, false);
+
+ // not equiv
+ QCOMPARE(media4 == media5, false);
+ QCOMPARE(media4 != media5, true);
+}
+
+void tst_QMediaContent::testResources()
+{
+ QMediaResourceList resourceList;
+
+ resourceList << QMediaResource(QUrl("http://example.com/movie-main.mov"));
+ resourceList << QMediaResource(QUrl("http://example.com/movie-big.mov"));
+ QMediaContent media(resourceList);
+
+ QMediaResourceList res = media.resources();
+ QCOMPARE(res.size(), 2);
+ QCOMPARE(res[0], QMediaResource(QUrl("http://example.com/movie-main.mov")));
+ QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov")));
+}
+
+QTEST_MAIN(tst_QMediaContent)
+
+#include "tst_qmediacontent.moc"
diff --git a/tests/auto/qmediaobject/qmediaobject.pro b/tests/auto/qmediaobject/qmediaobject.pro
new file mode 100644
index 0000000..e59bfdc
--- /dev/null
+++ b/tests/auto/qmediaobject/qmediaobject.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+
+SOURCES += tst_qmediaobject.cpp
+QT = core multimedia
diff --git a/tests/auto/qmediaobject/tst_qmediaobject.cpp b/tests/auto/qmediaobject/tst_qmediaobject.cpp
new file mode 100644
index 0000000..0370fff
--- /dev/null
+++ b/tests/auto/qmediaobject/tst_qmediaobject.cpp
@@ -0,0 +1,549 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qtimer.h>
+
+#include <QtMultimedia/qmediaobject.h>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/qmetadatacontrol.h>
+
+
+class tst_QMediaObject : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void propertyWatch();
+ void notifySignals_data();
+ void notifySignals();
+ void notifyInterval_data();
+ void notifyInterval();
+
+ void nullMetaDataControl();
+ void isMetaDataAvailable();
+ void isWritable();
+ void metaDataChanged();
+ void metaData_data();
+ void metaData();
+ void setMetaData_data();
+ void setMetaData();
+ void extendedMetaData_data() { metaData_data(); }
+ void extendedMetaData();
+ void setExtendedMetaData_data() { extendedMetaData_data(); }
+ void setExtendedMetaData();
+
+
+private:
+ void setupNotifyTests();
+};
+
+class QtTestMetaDataProvider : public QMetaDataControl
+{
+ Q_OBJECT
+public:
+ QtTestMetaDataProvider(QObject *parent = 0)
+ : QMetaDataControl(parent)
+ , m_available(false)
+ , m_writable(false)
+ {
+ }
+
+ bool isMetaDataAvailable() const { return m_available; }
+ void setMetaDataAvailable(bool available) {
+ if (m_available != available)
+ emit metaDataAvailableChanged(m_available = available);
+ }
+ QList<QtMedia::MetaData> availableMetaData() const { return m_data.keys(); }
+
+ bool isWritable() const { return m_writable; }
+ void setWritable(bool writable) { emit writableChanged(m_writable = writable); }
+
+ QVariant metaData(QtMedia::MetaData key) const { return m_data.value(key); }
+ void setMetaData(QtMedia::MetaData key, const QVariant &value) {
+ m_data.insert(key, value); }
+
+ QVariant extendedMetaData(const QString &key) const { return m_extendedData.value(key); }
+ void setExtendedMetaData(const QString &key, const QVariant &value) {
+ m_extendedData.insert(key, value); }
+
+ QStringList availableExtendedMetaData() const { return m_extendedData.keys(); }
+
+ using QMetaDataControl::metaDataChanged;
+
+ void populateMetaData()
+ {
+ m_available = true;
+ }
+
+ bool m_available;
+ bool m_writable;
+ QMap<QtMedia::MetaData, QVariant> m_data;
+ QMap<QString, QVariant> m_extendedData;
+};
+
+class QtTestMetaDataService : public QMediaService
+{
+ Q_OBJECT
+public:
+ QtTestMetaDataService(QObject *parent = 0):QMediaService(parent), hasMetaData(true)
+ {
+ }
+
+ QMediaControl *control(const char *iid) const
+ {
+ if (hasMetaData && qstrcmp(iid, QMetaDataControl_iid) == 0)
+ return const_cast<QtTestMetaDataProvider *>(&metaData);
+ else
+ return 0;
+ }
+
+ QtTestMetaDataProvider metaData;
+ bool hasMetaData;
+};
+
+
+class QtTestMediaObject : public QMediaObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int a READ a WRITE setA NOTIFY aChanged)
+ Q_PROPERTY(int b READ b WRITE setB NOTIFY bChanged)
+ Q_PROPERTY(int c READ c WRITE setC NOTIFY cChanged)
+ Q_PROPERTY(int d READ d WRITE setD)
+public:
+ QtTestMediaObject(QMediaService *service = 0): QMediaObject(0, service), m_a(0), m_b(0), m_c(0), m_d(0) {}
+
+ using QMediaObject::addPropertyWatch;
+ using QMediaObject::removePropertyWatch;
+
+ int a() const { return m_a; }
+ void setA(int a) { m_a = a; }
+
+ int b() const { return m_b; }
+ void setB(int b) { m_b = b; }
+
+ int c() const { return m_c; }
+ void setC(int c) { m_c = c; }
+
+ int d() const { return m_d; }
+ void setD(int d) { m_d = d; }
+
+Q_SIGNALS:
+ void aChanged(int a);
+ void bChanged(int b);
+ void cChanged(int c);
+
+private:
+ int m_a;
+ int m_b;
+ int m_c;
+ int m_d;
+};
+
+void tst_QMediaObject::propertyWatch()
+{
+ QtTestMediaObject object;
+ object.setNotifyInterval(0);
+
+ QEventLoop loop;
+ connect(&object, SIGNAL(aChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&object, SIGNAL(bChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&object, SIGNAL(cChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ QSignalSpy aSpy(&object, SIGNAL(aChanged(int)));
+ QSignalSpy bSpy(&object, SIGNAL(bChanged(int)));
+ QSignalSpy cSpy(&object, SIGNAL(cChanged(int)));
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(aSpy.count(), 0);
+ QCOMPARE(bSpy.count(), 0);
+ QCOMPARE(cSpy.count(), 0);
+
+ int aCount = 0;
+ int bCount = 0;
+ int cCount = 0;
+
+ object.addPropertyWatch("a");
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QVERIFY(aSpy.count() > aCount);
+ QCOMPARE(bSpy.count(), 0);
+ QCOMPARE(cSpy.count(), 0);
+ QCOMPARE(aSpy.last().value(0).toInt(), 0);
+
+ aCount = aSpy.count();
+
+ object.setA(54);
+ object.setB(342);
+ object.setC(233);
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QVERIFY(aSpy.count() > aCount);
+ QCOMPARE(bSpy.count(), 0);
+ QCOMPARE(cSpy.count(), 0);
+ QCOMPARE(aSpy.last().value(0).toInt(), 54);
+
+ aCount = aSpy.count();
+
+ object.addPropertyWatch("b");
+ object.addPropertyWatch("d");
+ object.removePropertyWatch("e");
+ object.setA(43);
+ object.setB(235);
+ object.setC(90);
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QVERIFY(aSpy.count() > aCount);
+ QVERIFY(bSpy.count() > bCount);
+ QCOMPARE(cSpy.count(), 0);
+ QCOMPARE(aSpy.last().value(0).toInt(), 43);
+ QCOMPARE(bSpy.last().value(0).toInt(), 235);
+
+ aCount = aSpy.count();
+ bCount = bSpy.count();
+
+ object.removePropertyWatch("a");
+ object.addPropertyWatch("c");
+ object.addPropertyWatch("e");
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(aSpy.count(), aCount);
+ QVERIFY(bSpy.count() > bCount);
+ QVERIFY(cSpy.count() > cCount);
+ QCOMPARE(bSpy.last().value(0).toInt(), 235);
+ QCOMPARE(cSpy.last().value(0).toInt(), 90);
+
+ bCount = bSpy.count();
+ cCount = cSpy.count();
+
+ object.setA(435);
+ object.setC(9845);
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(aSpy.count(), aCount);
+ QVERIFY(bSpy.count() > bCount);
+ QVERIFY(cSpy.count() > cCount);
+ QCOMPARE(bSpy.last().value(0).toInt(), 235);
+ QCOMPARE(cSpy.last().value(0).toInt(), 9845);
+
+ bCount = bSpy.count();
+ cCount = cSpy.count();
+
+ object.setA(8432);
+ object.setB(324);
+ object.setC(443);
+ object.removePropertyWatch("c");
+ object.removePropertyWatch("d");
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(aSpy.count(), aCount);
+ QVERIFY(bSpy.count() > bCount);
+ QCOMPARE(cSpy.count(), cCount);
+ QCOMPARE(bSpy.last().value(0).toInt(), 324);
+ QCOMPARE(cSpy.last().value(0).toInt(), 9845);
+
+ bCount = bSpy.count();
+
+ object.removePropertyWatch("b");
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(aSpy.count(), aCount);
+ QCOMPARE(bSpy.count(), bCount);
+ QCOMPARE(cSpy.count(), cCount);
+}
+
+void tst_QMediaObject::setupNotifyTests()
+{
+ QTest::addColumn<int>("interval");
+ QTest::addColumn<int>("count");
+
+ QTest::newRow("single 750ms")
+ << 750
+ << 1;
+ QTest::newRow("single 600ms")
+ << 600
+ << 1;
+ QTest::newRow("x3 300ms")
+ << 300
+ << 3;
+ QTest::newRow("x5 180ms")
+ << 180
+ << 5;
+}
+
+void tst_QMediaObject::notifySignals_data()
+{
+ setupNotifyTests();
+}
+
+void tst_QMediaObject::notifySignals()
+{
+ QFETCH(int, interval);
+ QFETCH(int, count);
+
+ QtTestMediaObject object;
+ object.setNotifyInterval(interval);
+ object.addPropertyWatch("a");
+
+ QSignalSpy spy(&object, SIGNAL(aChanged(int)));
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ QCOMPARE(spy.count(), count);
+}
+
+void tst_QMediaObject::notifyInterval_data()
+{
+ setupNotifyTests();
+}
+
+void tst_QMediaObject::notifyInterval()
+{
+ QFETCH(int, interval);
+
+ QtTestMediaObject object;
+ QSignalSpy spy(&object, SIGNAL(notifyIntervalChanged(int)));
+
+ object.setNotifyInterval(interval);
+ QCOMPARE(object.notifyInterval(), interval);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.last().value(0).toInt(), interval);
+
+ object.setNotifyInterval(interval);
+ QCOMPARE(object.notifyInterval(), interval);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QMediaObject::nullMetaDataControl()
+{
+ const QString titleKey(QLatin1String("Title"));
+ const QString title(QLatin1String("Host of Seraphim"));
+
+ QtTestMetaDataService service;
+ service.hasMetaData = false;
+
+ QtTestMediaObject object(&service);
+
+ QSignalSpy spy(&object, SIGNAL(metaDataChanged()));
+
+ QCOMPARE(object.isMetaDataAvailable(), false);
+ QCOMPARE(object.isMetaDataWritable(), false);
+
+ object.setMetaData(QtMedia::Title, title);
+ object.setExtendedMetaData(titleKey, title);
+
+ QCOMPARE(object.metaData(QtMedia::Title).toString(), QString());
+ QCOMPARE(object.extendedMetaData(titleKey).toString(), QString());
+ QCOMPARE(object.availableMetaData(), QList<QtMedia::MetaData>());
+ QCOMPARE(object.availableExtendedMetaData(), QStringList());
+ QCOMPARE(spy.count(), 0);
+}
+
+void tst_QMediaObject::isMetaDataAvailable()
+{
+ QtTestMetaDataService service;
+ service.metaData.setMetaDataAvailable(false);
+
+ QtTestMediaObject object(&service);
+ QCOMPARE(object.isMetaDataAvailable(), false);
+
+ QSignalSpy spy(&object, SIGNAL(metaDataAvailableChanged(bool)));
+ service.metaData.setMetaDataAvailable(true);
+
+ QCOMPARE(object.isMetaDataAvailable(), true);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.at(0).at(0).toBool(), true);
+
+ service.metaData.setMetaDataAvailable(false);
+
+ QCOMPARE(object.isMetaDataAvailable(), false);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.at(1).at(0).toBool(), false);
+}
+
+void tst_QMediaObject::isWritable()
+{
+ QtTestMetaDataService service;
+ service.metaData.setWritable(false);
+
+ QtTestMediaObject object(&service);
+
+ QSignalSpy spy(&object, SIGNAL(metaDataWritableChanged(bool)));
+
+ QCOMPARE(object.isMetaDataWritable(), false);
+
+ service.metaData.setWritable(true);
+
+ QCOMPARE(object.isMetaDataWritable(), true);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.at(0).at(0).toBool(), true);
+
+ service.metaData.setWritable(false);
+
+ QCOMPARE(object.isMetaDataWritable(), false);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.at(1).at(0).toBool(), false);
+}
+
+void tst_QMediaObject::metaDataChanged()
+{
+ QtTestMetaDataService service;
+ QtTestMediaObject object(&service);
+
+ QSignalSpy spy(&object, SIGNAL(metaDataChanged()));
+
+ service.metaData.metaDataChanged();
+ QCOMPARE(spy.count(), 1);
+
+ service.metaData.metaDataChanged();
+ QCOMPARE(spy.count(), 2);
+}
+
+void tst_QMediaObject::metaData_data()
+{
+ QTest::addColumn<QString>("artist");
+ QTest::addColumn<QString>("title");
+ QTest::addColumn<QString>("genre");
+
+ QTest::newRow("")
+ << QString::fromLatin1("Dead Can Dance")
+ << QString::fromLatin1("Host of Seraphim")
+ << QString::fromLatin1("Awesome");
+}
+
+void tst_QMediaObject::metaData()
+{
+ QFETCH(QString, artist);
+ QFETCH(QString, title);
+ QFETCH(QString, genre);
+
+ QtTestMetaDataService service;
+ service.metaData.populateMetaData();
+
+ QtTestMediaObject object(&service);
+ QVERIFY(object.availableMetaData().isEmpty());
+
+ service.metaData.m_data.insert(QtMedia::AlbumArtist, artist);
+ service.metaData.m_data.insert(QtMedia::Title, title);
+ service.metaData.m_data.insert(QtMedia::Genre, genre);
+
+ QCOMPARE(object.metaData(QtMedia::AlbumArtist).toString(), artist);
+ QCOMPARE(object.metaData(QtMedia::Title).toString(), title);
+
+ QList<QtMedia::MetaData> metaDataKeys = object.availableMetaData();
+ QCOMPARE(metaDataKeys.size(), 3);
+ QVERIFY(metaDataKeys.contains(QtMedia::AlbumArtist));
+ QVERIFY(metaDataKeys.contains(QtMedia::Title));
+ QVERIFY(metaDataKeys.contains(QtMedia::Genre));
+}
+
+void tst_QMediaObject::setMetaData_data()
+{
+ QTest::addColumn<QString>("title");
+
+ QTest::newRow("")
+ << QString::fromLatin1("In the Kingdom of the Blind the One eyed are Kings");
+}
+
+void tst_QMediaObject::setMetaData()
+{
+ QFETCH(QString, title);
+
+ QtTestMetaDataService service;
+ service.metaData.populateMetaData();
+
+ QtTestMediaObject object(&service);
+
+ object.setMetaData(QtMedia::Title, title);
+ QCOMPARE(object.metaData(QtMedia::Title).toString(), title);
+ QCOMPARE(service.metaData.m_data.value(QtMedia::Title).toString(), title);
+}
+
+void tst_QMediaObject::extendedMetaData()
+{
+ QFETCH(QString, artist);
+ QFETCH(QString, title);
+ QFETCH(QString, genre);
+
+ QtTestMetaDataService service;
+ QtTestMediaObject object(&service);
+ QVERIFY(object.availableExtendedMetaData().isEmpty());
+
+ service.metaData.m_extendedData.insert(QLatin1String("Artist"), artist);
+ service.metaData.m_extendedData.insert(QLatin1String("Title"), title);
+ service.metaData.m_extendedData.insert(QLatin1String("Genre"), genre);
+
+ QCOMPARE(object.extendedMetaData(QLatin1String("Artist")).toString(), artist);
+ QCOMPARE(object.extendedMetaData(QLatin1String("Title")).toString(), title);
+
+ QStringList extendedKeys = object.availableExtendedMetaData();
+ QCOMPARE(extendedKeys.size(), 3);
+ QVERIFY(extendedKeys.contains(QLatin1String("Artist")));
+ QVERIFY(extendedKeys.contains(QLatin1String("Title")));
+ QVERIFY(extendedKeys.contains(QLatin1String("Genre")));
+}
+
+void tst_QMediaObject::setExtendedMetaData()
+{
+ QtTestMetaDataService service;
+ service.metaData.populateMetaData();
+
+ QtTestMediaObject object(&service);
+
+ QString title(QLatin1String("In the Kingdom of the Blind the One eyed are Kings"));
+
+ object.setExtendedMetaData(QLatin1String("Title"), title);
+ QCOMPARE(object.extendedMetaData(QLatin1String("Title")).toString(), title);
+ QCOMPARE(service.metaData.m_extendedData.value(QLatin1String("Title")).toString(), title);
+}
+
+QTEST_MAIN(tst_QMediaObject)
+
+#include "tst_qmediaobject.moc"
diff --git a/tests/auto/qmediaplayer/qmediaplayer.pro b/tests/auto/qmediaplayer/qmediaplayer.pro
new file mode 100644
index 0000000..21008f9
--- /dev/null
+++ b/tests/auto/qmediaplayer/qmediaplayer.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES += tst_qmediaplayer.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/qmediaplayer/tst_qmediaplayer.cpp
new file mode 100644
index 0000000..a3cba3f
--- /dev/null
+++ b/tests/auto/qmediaplayer/tst_qmediaplayer.cpp
@@ -0,0 +1,1011 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/qdebug.h>
+#include <QtCore/qbuffer.h>
+
+#include <QtMultimedia/qmediaplayer.h>
+#include <QtMultimedia/qmediaplayercontrol.h>
+#include <QtMultimedia/qmediaplaylist.h>
+#include <QtMultimedia/qmediaservice.h>
+
+
+
+class AutoConnection
+{
+public:
+ AutoConnection(QObject *sender, const char *signal, QObject *receiver, const char *method)
+ : sender(sender), signal(signal), receiver(receiver), method(method)
+ {
+ QObject::connect(sender, signal, receiver, method);
+ }
+
+ ~AutoConnection()
+ {
+ QObject::disconnect(sender, signal, receiver, method);
+ }
+
+private:
+ QObject *sender;
+ const char *signal;
+ QObject *receiver;
+ const char *method;
+};
+
+
+class MockPlayerControl : public QMediaPlayerControl
+{
+ friend class MockPlayerService;
+
+public:
+ MockPlayerControl():QMediaPlayerControl(0) {}
+
+ QMediaPlayer::State state() const { return _state; }
+ QMediaPlayer::MediaStatus mediaStatus() const { return _mediaStatus; }
+
+ qint64 duration() const { return _duration; }
+
+ qint64 position() const { return _position; }
+
+ void setPosition(qint64 position) { if (position != _position) emit positionChanged(_position = position); }
+
+ int volume() const { return _volume; }
+ void setVolume(int volume) { emit volumeChanged(_volume = volume); }
+
+ bool isMuted() const { return _muted; }
+ void setMuted(bool muted) { if (muted != _muted) emit mutedChanged(_muted = muted); }
+
+ int bufferStatus() const { return _bufferStatus; }
+
+ bool isVideoAvailable() const { return _videoAvailable; }
+
+ bool isSeekable() const { return _isSeekable; }
+ QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(_seekRange.first, _seekRange.second); }
+ void setSeekRange(qint64 minimum, qint64 maximum) { _seekRange = qMakePair(minimum, maximum); }
+
+ qreal playbackRate() const { return _playbackRate; }
+ void setPlaybackRate(qreal rate) { if (rate != _playbackRate) emit playbackRateChanged(_playbackRate = rate); }
+
+ QMediaContent media() const { return _media; }
+ void setMedia(const QMediaContent &content, QIODevice *stream)
+ {
+ _stream = stream;
+ _media = content;
+ if (_state != QMediaPlayer::StoppedState) {
+ _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia;
+ emit stateChanged(_state = QMediaPlayer::StoppedState);
+ emit mediaStatusChanged(_mediaStatus);
+ }
+ emit mediaChanged(_media = content);
+ }
+ QIODevice *mediaStream() const { return _stream; }
+
+ void play() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PlayingState) emit stateChanged(_state = QMediaPlayer::PlayingState); }
+ void pause() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PausedState) emit stateChanged(_state = QMediaPlayer::PausedState); }
+ void stop() { if (_state != QMediaPlayer::StoppedState) emit stateChanged(_state = QMediaPlayer::StoppedState); }
+
+ QMediaPlayer::State _state;
+ QMediaPlayer::MediaStatus _mediaStatus;
+ QMediaPlayer::Error _error;
+ qint64 _duration;
+ qint64 _position;
+ int _volume;
+ bool _muted;
+ int _bufferStatus;
+ bool _videoAvailable;
+ bool _isSeekable;
+ QPair<qint64, qint64> _seekRange;
+ qreal _playbackRate;
+ QMediaContent _media;
+ QIODevice *_stream;
+ bool _isValid;
+ QString _errorString;
+};
+
+
+class MockPlayerService : public QMediaService
+{
+ Q_OBJECT
+
+public:
+ MockPlayerService():QMediaService(0)
+ {
+ mockControl = new MockPlayerControl;
+ }
+
+ ~MockPlayerService()
+ {
+ delete mockControl;
+ }
+
+ QMediaControl* control(const char *iid) const
+ {
+ if (qstrcmp(iid, QMediaPlayerControl_iid) == 0)
+ return mockControl;
+
+ return 0;
+ }
+
+ void setState(QMediaPlayer::State state) { emit mockControl->stateChanged(mockControl->_state = state); }
+ void setState(QMediaPlayer::State state, QMediaPlayer::MediaStatus status) {
+ mockControl->_state = state;
+ mockControl->_mediaStatus = status;
+ emit mockControl->mediaStatusChanged(status);
+ emit mockControl->stateChanged(state);
+ }
+ void setMediaStatus(QMediaPlayer::MediaStatus status) { emit mockControl->mediaStatusChanged(mockControl->_mediaStatus = status); }
+ void setIsValid(bool isValid) { mockControl->_isValid = isValid; }
+ void setMedia(QMediaContent media) { mockControl->_media = media; }
+ void setDuration(qint64 duration) { mockControl->_duration = duration; }
+ void setPosition(qint64 position) { mockControl->_position = position; }
+ void setSeekable(bool seekable) { mockControl->_isSeekable = seekable; }
+ void setVolume(int volume) { mockControl->_volume = volume; }
+ void setMuted(bool muted) { mockControl->_muted = muted; }
+ void setVideoAvailable(bool videoAvailable) { mockControl->_videoAvailable = videoAvailable; }
+ void setBufferStatus(int bufferStatus) { mockControl->_bufferStatus = bufferStatus; }
+ void setPlaybackRate(qreal playbackRate) { mockControl->_playbackRate = playbackRate; }
+ void setError(QMediaPlayer::Error error) { mockControl->_error = error; emit mockControl->error(mockControl->_error, mockControl->_errorString); }
+ void setErrorString(QString errorString) { mockControl->_errorString = errorString; emit mockControl->error(mockControl->_error, mockControl->_errorString); }
+
+ void reset()
+ {
+ mockControl->_state = QMediaPlayer::StoppedState;
+ mockControl->_mediaStatus = QMediaPlayer::UnknownMediaStatus;
+ mockControl->_error = QMediaPlayer::NoError;
+ mockControl->_duration = 0;
+ mockControl->_position = 0;
+ mockControl->_volume = 0;
+ mockControl->_muted = false;
+ mockControl->_bufferStatus = 0;
+ mockControl->_videoAvailable = false;
+ mockControl->_isSeekable = false;
+ mockControl->_playbackRate = 0.0;
+ mockControl->_media = QMediaContent();
+ mockControl->_stream = 0;
+ mockControl->_isValid = false;
+ mockControl->_errorString = QString();
+ }
+
+ MockPlayerControl *mockControl;
+};
+
+class MockProvider : public QMediaServiceProvider
+{
+public:
+ MockProvider(MockPlayerService *service):mockService(service) {}
+ QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &)
+ {
+ return mockService;
+ }
+
+ void releaseService(QMediaService *service) { delete service; }
+
+ MockPlayerService *mockService;
+};
+
+class tst_QMediaPlayer: public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase_data();
+ void initTestCase();
+ void cleanupTestCase();
+ void init();
+ void cleanup();
+
+private slots:
+ void testNullService();
+ void testValid();
+ void testMedia();
+ void testDuration();
+ void testPosition();
+ void testVolume();
+ void testMuted();
+ void testVideoAvailable();
+ void testBufferStatus();
+ void testSeekable();
+ void testPlaybackRate();
+ void testError();
+ void testErrorString();
+ void testService();
+ void testPlay();
+ void testPause();
+ void testStop();
+ void testMediaStatus();
+ void testPlaylist();
+
+private:
+ MockProvider *mockProvider;
+ MockPlayerService *mockService;
+ QMediaPlayer *player;
+};
+
+void tst_QMediaPlayer::initTestCase_data()
+{
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<QMediaPlayer::State>("state");
+ QTest::addColumn<QMediaPlayer::MediaStatus>("status");
+ QTest::addColumn<QMediaContent>("mediaContent");
+ QTest::addColumn<qint64>("duration");
+ QTest::addColumn<qint64>("position");
+ QTest::addColumn<bool>("seekable");
+ QTest::addColumn<int>("volume");
+ QTest::addColumn<bool>("muted");
+ QTest::addColumn<bool>("videoAvailable");
+ QTest::addColumn<int>("bufferStatus");
+ QTest::addColumn<qreal>("playbackRate");
+ QTest::addColumn<QMediaPlayer::Error>("error");
+ QTest::addColumn<QString>("errorString");
+
+ QTest::newRow("invalid") << false << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus <<
+ QMediaContent() << qint64(0) << qint64(0) << false << 0 << false << false << 0 <<
+ qreal(0) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valid+null") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus <<
+ QMediaContent() << qint64(0) << qint64(0) << false << 0 << false << false << 50 <<
+ qreal(0) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valid+content+stopped") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus <<
+ QMediaContent(QUrl("file:///some.mp3")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 <<
+ qreal(1) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valid+content+playing") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia <<
+ QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 <<
+ qreal(1) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valid+content+paused") << true << QMediaPlayer::PausedState << QMediaPlayer::LoadedMedia <<
+ QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 <<
+ qreal(1) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valud+streaming") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia <<
+ QMediaContent(QUrl("http://example.com/stream")) << qint64(10000) << qint64(10000) << false << 50 << false << true << 0 <<
+ qreal(1) << QMediaPlayer::NoError << QString();
+ QTest::newRow("valid+error") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus <<
+ QMediaContent(QUrl("http://example.com/stream")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 <<
+ qreal(0) << QMediaPlayer::ResourceError << QString("Resource unavailable");
+}
+
+void tst_QMediaPlayer::initTestCase()
+{
+ qRegisterMetaType<QMediaPlayer::State>("QMediaPlayer::State");
+ qRegisterMetaType<QMediaPlayer::Error>("QMediaPlayer::Error");
+ qRegisterMetaType<QMediaPlayer::MediaStatus>("QMediaPlayer::MediaStatus");
+ qRegisterMetaType<QMediaContent>("QMediaContent");
+
+ mockService = new MockPlayerService;
+ mockProvider = new MockProvider(mockService);
+ player = new QMediaPlayer(0, 0, mockProvider);
+}
+
+void tst_QMediaPlayer::cleanupTestCase()
+{
+ delete player;
+}
+
+void tst_QMediaPlayer::init()
+{
+ mockService->reset();
+}
+
+void tst_QMediaPlayer::cleanup()
+{
+}
+
+void tst_QMediaPlayer::testNullService()
+{
+ MockProvider provider(0);
+ QMediaPlayer player(0, 0, &provider);
+
+ const QIODevice *nullDevice = 0;
+
+ QCOMPARE(player.media(), QMediaContent());
+ QCOMPARE(player.mediaStream(), nullDevice);
+ QCOMPARE(player.state(), QMediaPlayer::StoppedState);
+ QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus);
+ QCOMPARE(player.duration(), qint64(-1));
+ QCOMPARE(player.position(), qint64(0));
+ QCOMPARE(player.volume(), 0);
+ QCOMPARE(player.isMuted(), false);
+ QCOMPARE(player.isVideoAvailable(), false);
+ QCOMPARE(player.bufferStatus(), 0);
+ QCOMPARE(player.isSeekable(), false);
+ QCOMPARE(player.playbackRate(), qreal(0));
+ QCOMPARE(player.error(), QMediaPlayer::ServiceMissingError);
+
+ {
+ QFETCH_GLOBAL(QMediaContent, mediaContent);
+
+ QSignalSpy spy(&player, SIGNAL(mediaChanged(QMediaContent)));
+ QFile file;
+
+ player.setMedia(mediaContent, &file);
+ QCOMPARE(player.media(), QMediaContent());
+ QCOMPARE(player.mediaStream(), nullDevice);
+ QCOMPARE(spy.count(), 0);
+ } {
+ QSignalSpy stateSpy(&player, SIGNAL(stateChanged(QMediaPlayer::State)));
+ QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
+
+ player.play();
+ QCOMPARE(player.state(), QMediaPlayer::StoppedState);
+ QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus);
+ QCOMPARE(stateSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+
+ player.pause();
+ QCOMPARE(player.state(), QMediaPlayer::StoppedState);
+ QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus);
+ QCOMPARE(stateSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+
+ player.stop();
+ QCOMPARE(player.state(), QMediaPlayer::StoppedState);
+ QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus);
+ QCOMPARE(stateSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+ } {
+ QFETCH_GLOBAL(int, volume);
+ QFETCH_GLOBAL(bool, muted);
+
+ QSignalSpy volumeSpy(&player, SIGNAL(volumeChanged(int)));
+ QSignalSpy mutingSpy(&player, SIGNAL(mutedChanged(bool)));
+
+ player.setVolume(volume);
+ QCOMPARE(player.volume(), 0);
+ QCOMPARE(volumeSpy.count(), 0);
+
+ player.setMuted(muted);
+ QCOMPARE(player.isMuted(), false);
+ QCOMPARE(mutingSpy.count(), 0);
+ } {
+ QFETCH_GLOBAL(qint64, position);
+
+ QSignalSpy spy(&player, SIGNAL(positionChanged(qint64)));
+
+ player.setPosition(position);
+ QCOMPARE(player.position(), qint64(0));
+ QCOMPARE(spy.count(), 0);
+ } {
+ QFETCH_GLOBAL(qreal, playbackRate);
+
+ QSignalSpy spy(&player, SIGNAL(playbackRateChanged(qreal)));
+
+ player.setPlaybackRate(playbackRate);
+ QCOMPARE(player.playbackRate(), qreal(0));
+ QCOMPARE(spy.count(), 0);
+ } {
+ QMediaPlaylist playlist;
+ playlist.setMediaObject(&player);
+
+ QSignalSpy mediaSpy(&player, SIGNAL(mediaChanged(QMediaContent)));
+ QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
+
+ playlist.addMedia(QUrl("http://example.com/stream"));
+ playlist.addMedia(QUrl("file:///some.mp3"));
+
+ playlist.setCurrentIndex(0);
+ QCOMPARE(playlist.currentIndex(), 0);
+ QCOMPARE(player.media(), QMediaContent());
+ QCOMPARE(mediaSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+
+ playlist.next();
+ QCOMPARE(playlist.currentIndex(), 1);
+ QCOMPARE(player.media(), QMediaContent());
+ QCOMPARE(mediaSpy.count(), 0);
+ QCOMPARE(statusSpy.count(), 0);
+ }
+}
+
+void tst_QMediaPlayer::testValid()
+{
+ /*
+ QFETCH_GLOBAL(bool, valid);
+
+ mockService->setIsValid(valid);
+ QCOMPARE(player->isValid(), valid);
+ */
+}
+
+void tst_QMediaPlayer::testMedia()
+{
+ QFETCH_GLOBAL(QMediaContent, mediaContent);
+
+ mockService->setMedia(mediaContent);
+ QCOMPARE(player->media(), mediaContent);
+
+ QBuffer stream;
+ player->setMedia(mediaContent, &stream);
+ QCOMPARE(player->media(), mediaContent);
+ QCOMPARE((QBuffer*)player->mediaStream(), &stream);
+}
+
+void tst_QMediaPlayer::testDuration()
+{
+ QFETCH_GLOBAL(qint64, duration);
+
+ mockService->setDuration(duration);
+ QVERIFY(player->duration() == duration);
+}
+
+void tst_QMediaPlayer::testPosition()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(bool, seekable);
+ QFETCH_GLOBAL(qint64, position);
+ QFETCH_GLOBAL(qint64, duration);
+
+ mockService->setIsValid(valid);
+ mockService->setSeekable(seekable);
+ mockService->setPosition(position);
+ mockService->setDuration(duration);
+ QVERIFY(player->isSeekable() == seekable);
+ QVERIFY(player->position() == position);
+ QVERIFY(player->duration() == duration);
+
+ if (seekable) {
+ { QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(position);
+ QCOMPARE(player->position(), position);
+ QCOMPARE(spy.count(), 0); }
+
+ mockService->setPosition(position);
+ { QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(0);
+ QCOMPARE(player->position(), qint64(0));
+ QCOMPARE(spy.count(), position == 0 ? 0 : 1); }
+
+ mockService->setPosition(position);
+ { QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(duration);
+ QCOMPARE(player->position(), duration);
+ QCOMPARE(spy.count(), position == duration ? 0 : 1); }
+
+ mockService->setPosition(position);
+ { QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(-1);
+ QCOMPARE(player->position(), qint64(0));
+ QCOMPARE(spy.count(), position == 0 ? 0 : 1); }
+
+ mockService->setPosition(position);
+ { QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(duration + 1);
+ QCOMPARE(player->position(), duration);
+ QCOMPARE(spy.count(), position == duration ? 0 : 1); }
+ }
+ else {
+ QSignalSpy spy(player, SIGNAL(positionChanged(qint64)));
+ player->setPosition(position);
+
+ QCOMPARE(player->position(), position);
+ QCOMPARE(spy.count(), 0);
+ }
+}
+
+void tst_QMediaPlayer::testVolume()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(int, volume);
+
+ mockService->setVolume(volume);
+ QVERIFY(player->volume() == volume);
+
+ if (valid) {
+ { QSignalSpy spy(player, SIGNAL(volumeChanged(int)));
+ player->setVolume(10);
+ QCOMPARE(player->volume(), 10);
+ QCOMPARE(spy.count(), 1); }
+
+ { QSignalSpy spy(player, SIGNAL(volumeChanged(int)));
+ player->setVolume(-1000);
+ QCOMPARE(player->volume(), 0);
+ QCOMPARE(spy.count(), 1); }
+
+ { QSignalSpy spy(player, SIGNAL(volumeChanged(int)));
+ player->setVolume(100);
+ QCOMPARE(player->volume(), 100);
+ QCOMPARE(spy.count(), 1); }
+
+ { QSignalSpy spy(player, SIGNAL(volumeChanged(int)));
+ player->setVolume(1000);
+ QCOMPARE(player->volume(), 100);
+ QCOMPARE(spy.count(), 0); }
+ }
+}
+
+void tst_QMediaPlayer::testMuted()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(bool, muted);
+ QFETCH_GLOBAL(int, volume);
+
+ if (valid) {
+ mockService->setMuted(muted);
+ mockService->setVolume(volume);
+ QVERIFY(player->isMuted() == muted);
+
+ QSignalSpy spy(player, SIGNAL(mutedChanged(bool)));
+ player->setMuted(!muted);
+ QCOMPARE(player->isMuted(), !muted);
+ QCOMPARE(player->volume(), volume);
+ QCOMPARE(spy.count(), 1);
+ }
+}
+
+void tst_QMediaPlayer::testVideoAvailable()
+{
+ QFETCH_GLOBAL(bool, videoAvailable);
+
+ mockService->setVideoAvailable(videoAvailable);
+ QVERIFY(player->isVideoAvailable() == videoAvailable);
+}
+
+void tst_QMediaPlayer::testBufferStatus()
+{
+ QFETCH_GLOBAL(int, bufferStatus);
+
+ mockService->setBufferStatus(bufferStatus);
+ QVERIFY(player->bufferStatus() == bufferStatus);
+}
+
+void tst_QMediaPlayer::testSeekable()
+{
+ QFETCH_GLOBAL(bool, seekable);
+
+ mockService->setSeekable(seekable);
+ QVERIFY(player->isSeekable() == seekable);
+}
+
+void tst_QMediaPlayer::testPlaybackRate()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(qreal, playbackRate);
+
+ if (valid) {
+ mockService->setPlaybackRate(playbackRate);
+ QVERIFY(player->playbackRate() == playbackRate);
+
+ QSignalSpy spy(player, SIGNAL(playbackRateChanged(qreal)));
+ player->setPlaybackRate(playbackRate + 0.5f);
+ QCOMPARE(player->playbackRate(), playbackRate + 0.5f);
+ QCOMPARE(spy.count(), 1);
+ }
+}
+
+void tst_QMediaPlayer::testError()
+{
+ QFETCH_GLOBAL(QMediaPlayer::Error, error);
+
+ mockService->setError(error);
+ QVERIFY(player->error() == error);
+}
+
+void tst_QMediaPlayer::testErrorString()
+{
+ QFETCH_GLOBAL(QString, errorString);
+
+ mockService->setErrorString(errorString);
+ QVERIFY(player->errorString() == errorString);
+}
+
+void tst_QMediaPlayer::testService()
+{
+ /*
+ QFETCH_GLOBAL(bool, valid);
+
+ mockService->setIsValid(valid);
+
+ if (valid)
+ QVERIFY(player->service() != 0);
+ else
+ QVERIFY(player->service() == 0);
+ */
+}
+
+void tst_QMediaPlayer::testPlay()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(QMediaContent, mediaContent);
+ QFETCH_GLOBAL(QMediaPlayer::State, state);
+
+ mockService->setIsValid(valid);
+ mockService->setState(state);
+ mockService->setMedia(mediaContent);
+ QVERIFY(player->state() == state);
+ QVERIFY(player->media() == mediaContent);
+
+ QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State)));
+
+ player->play();
+
+ if (!valid || mediaContent.isNull()) {
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(spy.count(), 0);
+ }
+ else {
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(spy.count(), state == QMediaPlayer::PlayingState ? 0 : 1);
+ }
+}
+
+void tst_QMediaPlayer::testPause()
+{
+ QFETCH_GLOBAL(bool, valid);
+ QFETCH_GLOBAL(QMediaContent, mediaContent);
+ QFETCH_GLOBAL(QMediaPlayer::State, state);
+
+ mockService->setIsValid(valid);
+ mockService->setState(state);
+ mockService->setMedia(mediaContent);
+ QVERIFY(player->state() == state);
+ QVERIFY(player->media() == mediaContent);
+
+ QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State)));
+
+ player->pause();
+
+ if (!valid || mediaContent.isNull()) {
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(spy.count(), 0);
+ }
+ else {
+ QCOMPARE(player->state(), QMediaPlayer::PausedState);
+ QCOMPARE(spy.count(), state == QMediaPlayer::PausedState ? 0 : 1);
+ }
+}
+
+void tst_QMediaPlayer::testStop()
+{
+ QFETCH_GLOBAL(QMediaContent, mediaContent);
+ QFETCH_GLOBAL(QMediaPlayer::State, state);
+
+ mockService->setState(state);
+ mockService->setMedia(mediaContent);
+ QVERIFY(player->state() == state);
+ QVERIFY(player->media() == mediaContent);
+
+ QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State)));
+
+ player->stop();
+
+ if (mediaContent.isNull() || state == QMediaPlayer::StoppedState) {
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(spy.count(), 0);
+ }
+ else {
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(spy.count(), 1);
+ }
+}
+
+void tst_QMediaPlayer::testMediaStatus()
+{
+ QFETCH_GLOBAL(int, bufferStatus);
+ int bufferSignals = 0;
+
+ player->setNotifyInterval(10);
+
+ mockService->setMediaStatus(QMediaPlayer::NoMedia);
+ mockService->setBufferStatus(bufferStatus);
+
+ AutoConnection connection(
+ player, SIGNAL(bufferStatusChanged(int)),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ QSignalSpy statusSpy(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)));
+ QSignalSpy bufferSpy(player, SIGNAL(bufferStatusChanged(int)));
+
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::NoMedia);
+
+ mockService->setMediaStatus(QMediaPlayer::LoadingMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::LoadingMedia);
+ QCOMPARE(statusSpy.count(), 1);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::LoadingMedia);
+
+ mockService->setMediaStatus(QMediaPlayer::LoadedMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::LoadedMedia);
+ QCOMPARE(statusSpy.count(), 2);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::LoadedMedia);
+
+ // Verify the bufferStatusChanged() signal isn't being emitted.
+ QTestEventLoop::instance().enterLoop(1);
+ QCOMPARE(bufferSpy.count(), 0);
+
+ mockService->setMediaStatus(QMediaPlayer::StalledMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::StalledMedia);
+ QCOMPARE(statusSpy.count(), 3);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::StalledMedia);
+
+ // Verify the bufferStatusChanged() signal is being emitted.
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(bufferSpy.count() > bufferSignals);
+ QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus);
+ bufferSignals = bufferSpy.count();
+
+ mockService->setMediaStatus(QMediaPlayer::BufferingMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::BufferingMedia);
+ QCOMPARE(statusSpy.count(), 4);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::BufferingMedia);
+
+ // Verify the bufferStatusChanged() signal is being emitted.
+ QTestEventLoop::instance().enterLoop(1);
+ QVERIFY(bufferSpy.count() > bufferSignals);
+ QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus);
+ bufferSignals = bufferSpy.count();
+
+ mockService->setMediaStatus(QMediaPlayer::BufferedMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::BufferedMedia);
+ QCOMPARE(statusSpy.count(), 5);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::BufferedMedia);
+
+ // Verify the bufferStatusChanged() signal isn't being emitted.
+ QTestEventLoop::instance().enterLoop(1);
+ QCOMPARE(bufferSpy.count(), bufferSignals);
+
+ mockService->setMediaStatus(QMediaPlayer::EndOfMedia);
+ QCOMPARE(player->mediaStatus(), QMediaPlayer::EndOfMedia);
+ QCOMPARE(statusSpy.count(), 6);
+
+#ifdef QTM_NAMESPACE
+ //looks like the correct value is emited, but QSignalSpy doesn't work correctly with QtMobility namespace
+ QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue);
+#endif
+ QCOMPARE(qvariant_cast<QMediaPlayer::MediaStatus>(statusSpy.last().value(0)),
+ QMediaPlayer::EndOfMedia);
+}
+
+void tst_QMediaPlayer::testPlaylist()
+{
+ QMediaContent content0(QUrl(QLatin1String("test://audio/song1.mp3")));
+ QMediaContent content1(QUrl(QLatin1String("test://audio/song2.mp3")));
+ QMediaContent content2(QUrl(QLatin1String("test://video/movie1.mp4")));
+ QMediaContent content3(QUrl(QLatin1String("test://video/movie2.mp4")));
+ QMediaContent content4(QUrl(QLatin1String("test://image/photo.jpg")));
+
+ mockService->setIsValid(true);
+ mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::NoMedia);
+
+ QMediaPlaylist *playlist = new QMediaPlaylist;
+ playlist->setMediaObject(player);
+
+ QSignalSpy stateSpy(player, SIGNAL(stateChanged(QMediaPlayer::State)));
+ QSignalSpy mediaSpy(player, SIGNAL(mediaChanged(QMediaContent)));
+
+ // Test the player does nothing with an empty playlist attached.
+ player->play();
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(player->media(), QMediaContent());
+ QCOMPARE(stateSpy.count(), 0);
+ QCOMPARE(mediaSpy.count(), 0);
+
+ playlist->addMedia(content0);
+ playlist->addMedia(content1);
+ playlist->addMedia(content2);
+ playlist->addMedia(content3);
+
+ // Test changing the playlist position, changes the current media, but not the playing state.
+ playlist->setCurrentIndex(1);
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 0);
+ QCOMPARE(mediaSpy.count(), 1);
+
+ // Test playing starts with the current media.
+ player->play();
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 1);
+ QCOMPARE(mediaSpy.count(), 1);
+
+ // Test pausing doesn't change the current media.
+ player->pause();
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::PausedState);
+ QCOMPARE(stateSpy.count(), 2);
+ QCOMPARE(mediaSpy.count(), 1);
+
+ // Test stopping doesn't change the current media.
+ player->stop();
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 3);
+ QCOMPARE(mediaSpy.count(), 1);
+
+ // Test when the player service reaches the end of the current media, the player moves onto
+ // the next item without stopping.
+ player->play();
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 4);
+ QCOMPARE(mediaSpy.count(), 1);
+
+ mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia);
+ QCOMPARE(player->media(), content2);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 4);
+ QCOMPARE(mediaSpy.count(), 2);
+
+ // Test skipping the current media doesn't change the state.
+ playlist->next();
+ QCOMPARE(player->media(), content3);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 4);
+ QCOMPARE(mediaSpy.count(), 3);
+
+ // Test changing the current media while paused doesn't change the state.
+ player->pause();
+ mockService->setMediaStatus(QMediaPlayer::BufferedMedia);
+ QCOMPARE(player->media(), content3);
+ QCOMPARE(player->state(), QMediaPlayer::PausedState);
+ QCOMPARE(stateSpy.count(), 5);
+ QCOMPARE(mediaSpy.count(), 3);
+
+ playlist->previous();
+ QCOMPARE(player->media(), content2);
+ QCOMPARE(player->state(), QMediaPlayer::PausedState);
+ QCOMPARE(stateSpy.count(), 5);
+ QCOMPARE(mediaSpy.count(), 4);
+
+ // Test changing the current media while stopped doesn't change the state.
+ player->stop();
+ mockService->setMediaStatus(QMediaPlayer::LoadedMedia);
+ QCOMPARE(player->media(), content2);
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 6);
+ QCOMPARE(mediaSpy.count(), 4);
+
+ playlist->next();
+ QCOMPARE(player->media(), content3);
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 6);
+ QCOMPARE(mediaSpy.count(), 5);
+
+ // Test the player is stopped and the current media cleared when it reaches the end of the last
+ // item in the playlist.
+ player->play();
+ QCOMPARE(player->media(), content3);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 7);
+ QCOMPARE(mediaSpy.count(), 5);
+
+ // Double up the signals to ensure some noise doesn't destabalize things.
+ mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia);
+ mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia);
+ QCOMPARE(player->media(), QMediaContent());
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 8);
+ QCOMPARE(mediaSpy.count(), 6);
+
+ // Test starts playing from the start of the playlist if there is no current media selected.
+ player->play();
+ QCOMPARE(player->media(), content0);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 9);
+ QCOMPARE(mediaSpy.count(), 7);
+
+ // Test deleting the playlist stops the player and clears the media it set.
+ delete playlist;
+ QCOMPARE(player->media(), QMediaContent());
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 10);
+ QCOMPARE(mediaSpy.count(), 8);
+
+ // Test the player works as normal with the playlist removed.
+ player->play();
+ QCOMPARE(player->media(), QMediaContent());
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+ QCOMPARE(stateSpy.count(), 10);
+ QCOMPARE(mediaSpy.count(), 8);
+
+ player->setMedia(content1);
+ player->play();
+
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::PlayingState);
+ QCOMPARE(stateSpy.count(), 11);
+ QCOMPARE(mediaSpy.count(), 9);
+
+ // Test the player can bind to playlist again
+ playlist = new QMediaPlaylist;
+ playlist->setMediaObject(player);
+ QCOMPARE(playlist->mediaObject(), qobject_cast<QMediaObject*>(player));
+
+ QCOMPARE(player->media(), QMediaContent());
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+
+ playlist->addMedia(content0);
+ playlist->addMedia(content1);
+ playlist->addMedia(content2);
+ playlist->addMedia(content3);
+
+ playlist->setCurrentIndex(1);
+ QCOMPARE(player->media(), content1);
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+
+ // Test attaching the new playlist,
+ // player should detach the current one
+ QMediaPlaylist *playlist2 = new QMediaPlaylist;
+ playlist2->addMedia(content1);
+ playlist2->addMedia(content2);
+ playlist2->addMedia(content3);
+ playlist2->setCurrentIndex(2);
+
+ player->play();
+ playlist2->setMediaObject(player);
+ QCOMPARE(playlist2->mediaObject(), qobject_cast<QMediaObject*>(player));
+ QVERIFY(playlist->mediaObject() == 0);
+ QCOMPARE(player->media(), playlist2->currentMedia());
+ QCOMPARE(player->state(), QMediaPlayer::StoppedState);
+
+ playlist2->setCurrentIndex(1);
+ QCOMPARE(player->media(), playlist2->currentMedia());
+}
+
+QTEST_MAIN(tst_QMediaPlayer)
+
+#include "tst_qmediaplayer.moc"
diff --git a/tests/auto/qmediaplaylist/qmediaplaylist.pro b/tests/auto/qmediaplaylist/qmediaplaylist.pro
new file mode 100644
index 0000000..b114bda
--- /dev/null
+++ b/tests/auto/qmediaplaylist/qmediaplaylist.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediaplaylist.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediaplaylist/tmp.unsupported_format b/tests/auto/qmediaplaylist/tmp.unsupported_format
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/auto/qmediaplaylist/tmp.unsupported_format
diff --git a/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp
new file mode 100644
index 0000000..88a2f31
--- /dev/null
+++ b/tests/auto/qmediaplaylist/tst_qmediaplaylist.cpp
@@ -0,0 +1,622 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/qmediaplaylist.h>
+#include <QtMultimedia/qmediaplaylistcontrol.h>
+#include <QtMultimedia/qmediaplaylistnavigator.h>
+#include <QtMultimedia/private/qmediapluginloader_p.h>
+
+
+class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider
+{
+ Q_OBJECT
+public:
+ MockReadOnlyPlaylistProvider(QObject *parent)
+ :QMediaPlaylistProvider(parent)
+ {
+ m_items.append(QMediaContent(QUrl(QLatin1String("file:///1"))));
+ m_items.append(QMediaContent(QUrl(QLatin1String("file:///2"))));
+ m_items.append(QMediaContent(QUrl(QLatin1String("file:///3"))));
+ }
+
+ int mediaCount() const { return m_items.size(); }
+ QMediaContent media(int index) const
+ {
+ return index >=0 && index < mediaCount() ? m_items.at(index) : QMediaContent();
+ }
+
+private:
+ QList<QMediaContent> m_items;
+};
+
+class MockPlaylistControl : public QMediaPlaylistControl
+{
+ Q_OBJECT
+public:
+ MockPlaylistControl(QObject *parent) : QMediaPlaylistControl(parent)
+ {
+ m_navigator = new QMediaPlaylistNavigator(new MockReadOnlyPlaylistProvider(this), this);
+ }
+
+ ~MockPlaylistControl()
+ {
+ }
+
+ QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); }
+ bool setPlaylistProvider(QMediaPlaylistProvider *playlist) { m_navigator->setPlaylist(playlist); return true; }
+
+ int currentIndex() const { return m_navigator->currentIndex(); }
+ void setCurrentIndex(int position) { m_navigator->jump(position); }
+ int nextIndex(int steps) const { return m_navigator->nextIndex(steps); }
+ int previousIndex(int steps) const { return m_navigator->previousIndex(steps); }
+
+ void next() { m_navigator->next(); }
+ void previous() { m_navigator->previous(); }
+
+ QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); }
+ void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) { m_navigator->setPlaybackMode(mode); }
+
+private:
+ QMediaPlaylistNavigator *m_navigator;
+};
+
+class MockPlaylistService : public QMediaService
+{
+ Q_OBJECT
+
+public:
+ MockPlaylistService():QMediaService(0)
+ {
+ mockControl = new MockPlaylistControl(this);
+ }
+
+ ~MockPlaylistService()
+ {
+ }
+
+ QMediaControl* control(const char *iid) const
+ {
+ if (qstrcmp(iid, QMediaPlaylistControl_iid) == 0)
+ return mockControl;
+ return 0;
+ }
+
+ MockPlaylistControl *mockControl;
+};
+
+class MockReadOnlyPlaylistObject : public QMediaObject
+{
+ Q_OBJECT
+public:
+ MockReadOnlyPlaylistObject(QObject *parent = 0)
+ :QMediaObject(parent, new MockPlaylistService)
+ {
+ }
+};
+
+
+class tst_QMediaPlaylist : public QObject
+{
+ Q_OBJECT
+public slots:
+ void init();
+ void cleanup();
+ void initTestCase();
+
+private slots:
+ void construction();
+ void append();
+ void insert();
+ void clear();
+ void removeMedia();
+ void currentItem();
+ void saveAndLoad();
+ void playbackMode();
+ void playbackMode_data();
+ void shuffle();
+ void readOnlyPlaylist();
+ void setMediaObject();
+
+private:
+ QMediaContent content1;
+ QMediaContent content2;
+ QMediaContent content3;
+};
+
+void tst_QMediaPlaylist::init()
+{
+}
+
+void tst_QMediaPlaylist::initTestCase()
+{
+ content1 = QMediaContent(QUrl(QLatin1String("file:///1")));
+ content2 = QMediaContent(QUrl(QLatin1String("file:///2")));
+ content3 = QMediaContent(QUrl(QLatin1String("file:///3")));
+}
+
+void tst_QMediaPlaylist::cleanup()
+{
+}
+
+void tst_QMediaPlaylist::construction()
+{
+ QMediaPlaylist playlist;
+ QCOMPARE(playlist.mediaCount(), 0);
+ QVERIFY(playlist.isEmpty());
+}
+
+void tst_QMediaPlaylist::append()
+{
+ QMediaPlaylist playlist;
+ QVERIFY(!playlist.isReadOnly());
+
+ playlist.addMedia(content1);
+ QCOMPARE(playlist.mediaCount(), 1);
+ QCOMPARE(playlist.media(0), content1);
+
+ QSignalSpy aboutToBeInsertedSignalSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int,int)));
+ QSignalSpy insertedSignalSpy(&playlist, SIGNAL(mediaInserted(int,int)));
+ playlist.addMedia(content2);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.media(1), content2);
+
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy.first()[1].toInt(), 1);
+
+ QCOMPARE(insertedSignalSpy.count(), 1);
+ QCOMPARE(insertedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(insertedSignalSpy.first()[1].toInt(), 1);
+
+ aboutToBeInsertedSignalSpy.clear();
+ insertedSignalSpy.clear();
+
+ QMediaContent content4(QUrl(QLatin1String("file:///4")));
+ QMediaContent content5(QUrl(QLatin1String("file:///5")));
+ playlist.addMedia(QList<QMediaContent>() << content3 << content4 << content5);
+ QCOMPARE(playlist.mediaCount(), 5);
+ QCOMPARE(playlist.media(2), content3);
+ QCOMPARE(playlist.media(3), content4);
+ QCOMPARE(playlist.media(4), content5);
+
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy[0][0].toInt(), 2);
+ QCOMPARE(aboutToBeInsertedSignalSpy[0][1].toInt(), 4);
+
+ QCOMPARE(insertedSignalSpy.count(), 1);
+ QCOMPARE(insertedSignalSpy[0][0].toInt(), 2);
+ QCOMPARE(insertedSignalSpy[0][1].toInt(), 4);
+
+ aboutToBeInsertedSignalSpy.clear();
+ insertedSignalSpy.clear();
+
+ playlist.addMedia(QList<QMediaContent>());
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 0);
+ QCOMPARE(insertedSignalSpy.count(), 0);
+}
+
+void tst_QMediaPlaylist::insert()
+{
+ QMediaPlaylist playlist;
+ QVERIFY(!playlist.isReadOnly());
+
+ playlist.addMedia(content1);
+ QCOMPARE(playlist.mediaCount(), 1);
+ QCOMPARE(playlist.media(0), content1);
+
+ playlist.addMedia(content2);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.media(1), content2);
+
+ QSignalSpy aboutToBeInsertedSignalSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int,int)));
+ QSignalSpy insertedSignalSpy(&playlist, SIGNAL(mediaInserted(int,int)));
+
+ playlist.insertMedia(1, content3);
+ QCOMPARE(playlist.mediaCount(), 3);
+ QCOMPARE(playlist.media(0), content1);
+ QCOMPARE(playlist.media(1), content3);
+ QCOMPARE(playlist.media(2), content2);
+
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy.first()[1].toInt(), 1);
+
+ QCOMPARE(insertedSignalSpy.count(), 1);
+ QCOMPARE(insertedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(insertedSignalSpy.first()[1].toInt(), 1);
+
+ aboutToBeInsertedSignalSpy.clear();
+ insertedSignalSpy.clear();
+
+ QMediaContent content4(QUrl(QLatin1String("file:///4")));
+ QMediaContent content5(QUrl(QLatin1String("file:///5")));
+ playlist.insertMedia(1, QList<QMediaContent>() << content4 << content5);
+
+ QCOMPARE(playlist.media(0), content1);
+ QCOMPARE(playlist.media(1), content4);
+ QCOMPARE(playlist.media(2), content5);
+ QCOMPARE(playlist.media(3), content3);
+ QCOMPARE(playlist.media(4), content2);
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy[0][0].toInt(), 1);
+ QCOMPARE(aboutToBeInsertedSignalSpy[0][1].toInt(), 2);
+
+ QCOMPARE(insertedSignalSpy.count(), 1);
+ QCOMPARE(insertedSignalSpy[0][0].toInt(), 1);
+ QCOMPARE(insertedSignalSpy[0][1].toInt(), 2);
+
+ aboutToBeInsertedSignalSpy.clear();
+ insertedSignalSpy.clear();
+
+ playlist.insertMedia(1, QList<QMediaContent>());
+ QCOMPARE(aboutToBeInsertedSignalSpy.count(), 0);
+ QCOMPARE(insertedSignalSpy.count(), 0);
+}
+
+
+void tst_QMediaPlaylist::currentItem()
+{
+ QMediaPlaylist playlist;
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.currentMedia(), QMediaContent());
+
+ QCOMPARE(playlist.nextIndex(), 0);
+ QCOMPARE(playlist.nextIndex(2), 1);
+ QCOMPARE(playlist.previousIndex(), 1);
+ QCOMPARE(playlist.previousIndex(2), 0);
+
+ playlist.setCurrentIndex(0);
+ QCOMPARE(playlist.currentIndex(), 0);
+ QCOMPARE(playlist.currentMedia(), content1);
+
+ QCOMPARE(playlist.nextIndex(), 1);
+ QCOMPARE(playlist.nextIndex(2), -1);
+ QCOMPARE(playlist.previousIndex(), -1);
+ QCOMPARE(playlist.previousIndex(2), -1);
+
+ playlist.setCurrentIndex(1);
+ QCOMPARE(playlist.currentIndex(), 1);
+ QCOMPARE(playlist.currentMedia(), content2);
+
+ QCOMPARE(playlist.nextIndex(), -1);
+ QCOMPARE(playlist.nextIndex(2), -1);
+ QCOMPARE(playlist.previousIndex(), 0);
+ QCOMPARE(playlist.previousIndex(2), -1);
+
+ QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range ");
+ playlist.setCurrentIndex(2);
+
+ QCOMPARE(playlist.currentIndex(), -1);
+ QCOMPARE(playlist.currentMedia(), QMediaContent());
+}
+
+void tst_QMediaPlaylist::clear()
+{
+ QMediaPlaylist playlist;
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+
+ playlist.clear();
+ QVERIFY(playlist.isEmpty());
+ QCOMPARE(playlist.mediaCount(), 0);
+}
+
+void tst_QMediaPlaylist::removeMedia()
+{
+ QMediaPlaylist playlist;
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+ playlist.addMedia(content3);
+
+ QSignalSpy aboutToBeRemovedSignalSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int,int)));
+ QSignalSpy removedSignalSpy(&playlist, SIGNAL(mediaRemoved(int,int)));
+ playlist.removeMedia(1);
+ QCOMPARE(playlist.mediaCount(), 2);
+ QCOMPARE(playlist.media(1), content3);
+
+ QCOMPARE(aboutToBeRemovedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeRemovedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(aboutToBeRemovedSignalSpy.first()[1].toInt(), 1);
+
+ QCOMPARE(removedSignalSpy.count(), 1);
+ QCOMPARE(removedSignalSpy.first()[0].toInt(), 1);
+ QCOMPARE(removedSignalSpy.first()[1].toInt(), 1);
+
+ aboutToBeRemovedSignalSpy.clear();
+ removedSignalSpy.clear();
+
+ playlist.removeMedia(0,1);
+ QVERIFY(playlist.isEmpty());
+
+ QCOMPARE(aboutToBeRemovedSignalSpy.count(), 1);
+ QCOMPARE(aboutToBeRemovedSignalSpy.first()[0].toInt(), 0);
+ QCOMPARE(aboutToBeRemovedSignalSpy.first()[1].toInt(), 1);
+
+ QCOMPARE(removedSignalSpy.count(), 1);
+ QCOMPARE(removedSignalSpy.first()[0].toInt(), 0);
+ QCOMPARE(removedSignalSpy.first()[1].toInt(), 1);
+
+
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+ playlist.addMedia(content3);
+
+ playlist.removeMedia(0,1);
+ QCOMPARE(playlist.mediaCount(), 1);
+ QCOMPARE(playlist.media(0), content3);
+}
+
+void tst_QMediaPlaylist::saveAndLoad()
+{
+ QMediaPlaylist playlist;
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+ playlist.addMedia(content3);
+
+ QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
+ QVERIFY(playlist.errorString().isEmpty());
+
+ QBuffer buffer;
+ buffer.open(QBuffer::ReadWrite);
+
+ QTest::ignoreMessage(QtWarningMsg, "Load static plugins for \"/playlistformats/\" ");
+ bool res = playlist.save(&buffer, "unsupported_format");
+ QVERIFY(!res);
+ QVERIFY(playlist.error() != QMediaPlaylist::NoError);
+ QVERIFY(!playlist.errorString().isEmpty());
+
+ QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed()));
+ playlist.load(&buffer, "unsupported_format");
+ QCOMPARE(errorSignal.size(), 1);
+ QVERIFY(playlist.error() != QMediaPlaylist::NoError);
+ QVERIFY(!playlist.errorString().isEmpty());
+
+ res = playlist.save(QUrl(QLatin1String("tmp.unsupported_format")), "unsupported_format");
+ QVERIFY(!res);
+ QVERIFY(playlist.error() != QMediaPlaylist::NoError);
+ QVERIFY(!playlist.errorString().isEmpty());
+
+ errorSignal.clear();
+ playlist.load(QUrl(QLatin1String("tmp.unsupported_format")), "unsupported_format");
+ QCOMPARE(errorSignal.size(), 1);
+ QVERIFY(playlist.error() != QMediaPlaylist::NoError);
+ QVERIFY(!playlist.errorString().isEmpty());
+
+ res = playlist.save(&buffer, "m3u");
+
+ QVERIFY(res);
+ QVERIFY(buffer.pos() > 0);
+ buffer.seek(0);
+
+ QMediaPlaylist playlist2;
+ playlist2.load(&buffer, "m3u");
+ QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
+
+ QCOMPARE(playlist.mediaCount(), playlist2.mediaCount());
+ QCOMPARE(playlist.media(0), playlist2.media(0));
+ QCOMPARE(playlist.media(1), playlist2.media(1));
+ QCOMPARE(playlist.media(3), playlist2.media(3));
+
+ res = playlist.save(QUrl(QLatin1String("tmp.m3u")), "m3u");
+ QVERIFY(res);
+
+ playlist2.clear();
+ QVERIFY(playlist2.isEmpty());
+ playlist2.load(QUrl(QLatin1String("tmp.m3u")), "m3u");
+ QCOMPARE(playlist.error(), QMediaPlaylist::NoError);
+
+ QCOMPARE(playlist.mediaCount(), playlist2.mediaCount());
+ QCOMPARE(playlist.media(0), playlist2.media(0));
+ QCOMPARE(playlist.media(1), playlist2.media(1));
+ QCOMPARE(playlist.media(3), playlist2.media(3));
+}
+
+void tst_QMediaPlaylist::playbackMode_data()
+{
+ QTest::addColumn<QMediaPlaylist::PlaybackMode>("playbackMode");
+ QTest::addColumn<int>("expectedPrevious");
+ QTest::addColumn<int>("pos");
+ QTest::addColumn<int>("expectedNext");
+
+ QTest::newRow("Linear, 0") << QMediaPlaylist::Linear << -1 << 0 << 1;
+ QTest::newRow("Linear, 1") << QMediaPlaylist::Linear << 0 << 1 << 2;
+ QTest::newRow("Linear, 2") << QMediaPlaylist::Linear << 1 << 2 << -1;
+
+ QTest::newRow("Loop, 0") << QMediaPlaylist::Loop << 2 << 0 << 1;
+ QTest::newRow("Loop, 1") << QMediaPlaylist::Loop << 0 << 1 << 2;
+ QTest::newRow("Lopp, 2") << QMediaPlaylist::Loop << 1 << 2 << 0;
+
+ QTest::newRow("ItemOnce, 1") << QMediaPlaylist::CurrentItemOnce << -1 << 1 << -1;
+ QTest::newRow("ItemInLoop, 1") << QMediaPlaylist::CurrentItemInLoop << 1 << 1 << 1;
+
+}
+
+void tst_QMediaPlaylist::playbackMode()
+{
+ QFETCH(QMediaPlaylist::PlaybackMode, playbackMode);
+ QFETCH(int, expectedPrevious);
+ QFETCH(int, pos);
+ QFETCH(int, expectedNext);
+
+ QMediaPlaylist playlist;
+ playlist.addMedia(content1);
+ playlist.addMedia(content2);
+ playlist.addMedia(content3);
+
+ QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Linear);
+ QCOMPARE(playlist.currentIndex(), -1);
+
+ playlist.setPlaybackMode(playbackMode);
+ QCOMPARE(playlist.playbackMode(), playbackMode);
+
+ playlist.setCurrentIndex(pos);
+ QCOMPARE(playlist.currentIndex(), pos);
+ QCOMPARE(playlist.nextIndex(), expectedNext);
+ QCOMPARE(playlist.previousIndex(), expectedPrevious);
+
+ playlist.next();
+ QCOMPARE(playlist.currentIndex(), expectedNext);
+
+ playlist.setCurrentIndex(pos);
+ playlist.previous();
+ QCOMPARE(playlist.currentIndex(), expectedPrevious);
+}
+
+void tst_QMediaPlaylist::shuffle()
+{
+ QMediaPlaylist playlist;
+ QList<QMediaContent> contentList;
+
+ for (int i=0; i<100; i++) {
+ QMediaContent content(QUrl(QString::number(i)));
+ contentList.append(content);
+ playlist.addMedia(content);
+ }
+
+ playlist.shuffle();
+
+ QList<QMediaContent> shuffledContentList;
+ for (int i=0; i<playlist.mediaCount(); i++)
+ shuffledContentList.append(playlist.media(i));
+
+ QVERIFY(contentList != shuffledContentList);
+
+}
+
+void tst_QMediaPlaylist::readOnlyPlaylist()
+{
+ MockReadOnlyPlaylistObject mediaObject;
+ QMediaPlaylist playlist;
+ playlist.setMediaObject(&mediaObject);
+
+ QVERIFY(playlist.isReadOnly());
+ QVERIFY(!playlist.isEmpty());
+ QCOMPARE(playlist.mediaCount(), 3);
+
+ QCOMPARE(playlist.media(0), content1);
+ QCOMPARE(playlist.media(1), content2);
+ QCOMPARE(playlist.media(2), content3);
+ QCOMPARE(playlist.media(3), QMediaContent());
+
+ //it's a read only playlist, so all the modification should fail
+ QVERIFY(!playlist.addMedia(content1));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.addMedia(QList<QMediaContent>() << content1 << content2));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.insertMedia(1, content1));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.insertMedia(1, QList<QMediaContent>() << content1 << content2));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.removeMedia(1));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.removeMedia(0,2));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(!playlist.clear());
+ QCOMPARE(playlist.mediaCount(), 3);
+
+ //but it is still allowed to append/insert an empty list
+ QVERIFY(playlist.addMedia(QList<QMediaContent>()));
+ QVERIFY(playlist.insertMedia(1, QList<QMediaContent>()));
+
+ playlist.shuffle();
+ //it's still the same
+ QCOMPARE(playlist.media(0), content1);
+ QCOMPARE(playlist.media(1), content2);
+ QCOMPARE(playlist.media(2), content3);
+ QCOMPARE(playlist.media(3), QMediaContent());
+
+
+ //load to read only playlist should fail,
+ //unless underlaying provider supports it
+ QBuffer buffer;
+ buffer.open(QBuffer::ReadWrite);
+ buffer.write(QByteArray("file:///1\nfile:///2"));
+ buffer.seek(0);
+
+ QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed()));
+ playlist.load(&buffer, "m3u");
+ QCOMPARE(errorSignal.size(), 1);
+ QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError);
+ QVERIFY(!playlist.errorString().isEmpty());
+ QCOMPARE(playlist.mediaCount(), 3);
+
+ errorSignal.clear();
+ playlist.load(QUrl(QLatin1String("tmp.m3u")), "m3u");
+
+ QCOMPARE(errorSignal.size(), 1);
+ QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError);
+ QVERIFY(!playlist.errorString().isEmpty());
+ QCOMPARE(playlist.mediaCount(), 3);
+}
+
+void tst_QMediaPlaylist::setMediaObject()
+{
+ MockReadOnlyPlaylistObject mediaObject;
+
+ QMediaPlaylist playlist;
+ QVERIFY(playlist.mediaObject() == 0);
+ QVERIFY(!playlist.isReadOnly());
+
+ playlist.setMediaObject(&mediaObject);
+ QCOMPARE(playlist.mediaObject(), qobject_cast<QMediaObject*>(&mediaObject));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(playlist.isReadOnly());
+
+ playlist.setMediaObject(0);
+ QVERIFY(playlist.mediaObject() == 0);
+ QCOMPARE(playlist.mediaCount(), 0);
+ QVERIFY(!playlist.isReadOnly());
+
+ playlist.setMediaObject(&mediaObject);
+ QCOMPARE(playlist.mediaObject(), qobject_cast<QMediaObject*>(&mediaObject));
+ QCOMPARE(playlist.mediaCount(), 3);
+ QVERIFY(playlist.isReadOnly());
+}
+
+QTEST_MAIN(tst_QMediaPlaylist)
+#include "tst_qmediaplaylist.moc"
+
diff --git a/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro b/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro
new file mode 100644
index 0000000..ea9bc0f
--- /dev/null
+++ b/tests/auto/qmediaplaylistnavigator/qmediaplaylistnavigator.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediaplaylistnavigator.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp b/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp
new file mode 100644
index 0000000..a5eb3fe
--- /dev/null
+++ b/tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+#include <QtMultimedia/qlocalmediaplaylistprovider.h>
+#include <QtMultimedia/qmediaplaylistnavigator.h>
+
+
+class tst_QMediaPlaylistNavigator : public QObject
+{
+ Q_OBJECT
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setPlaylist();
+ void linearPlayback();
+ void loopPlayback();
+ void currentItemOnce();
+ void currentItemInLoop();
+ void randomPlayback();
+};
+
+void tst_QMediaPlaylistNavigator::init()
+{
+}
+
+void tst_QMediaPlaylistNavigator::cleanup()
+{
+}
+
+void tst_QMediaPlaylistNavigator::construction()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QCOMPARE(playlist.mediaCount(), 0);
+
+ QMediaPlaylistNavigator navigator(&playlist);
+ QVERIFY(navigator.currentItem().isNull());
+ QCOMPARE(navigator.currentIndex(), -1);
+}
+
+void tst_QMediaPlaylistNavigator::setPlaylist()
+{
+ QMediaPlaylistNavigator navigator(0);
+ QVERIFY(navigator.playlist() != 0);
+ QCOMPARE(navigator.playlist()->mediaCount(), 0);
+ QCOMPARE(navigator.playlist()->media(0), QMediaContent());
+ QVERIFY(navigator.playlist()->isReadOnly() );
+
+ QLocalMediaPlaylistProvider playlist;
+ QCOMPARE(playlist.mediaCount(), 0);
+
+ navigator.setPlaylist(&playlist);
+ QCOMPARE(navigator.playlist(), (QMediaPlaylistProvider*)&playlist);
+ QCOMPARE(navigator.playlist()->mediaCount(), 0);
+ QVERIFY(!navigator.playlist()->isReadOnly() );
+}
+
+void tst_QMediaPlaylistNavigator::linearPlayback()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QMediaPlaylistNavigator navigator(&playlist);
+
+ navigator.setPlaybackMode(QMediaPlaylist::Linear);
+ QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range ");
+ navigator.jump(0);//it's ok to have warning here
+ QVERIFY(navigator.currentItem().isNull());
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ QMediaContent content1(QUrl(QLatin1String("file:///1")));
+ playlist.addMedia(content1);
+ navigator.jump(0);
+ QVERIFY(!navigator.currentItem().isNull());
+
+ QCOMPARE(navigator.currentIndex(), 0);
+ QCOMPARE(navigator.currentItem(), content1);
+ QCOMPARE(navigator.nextItem(), QMediaContent());
+ QCOMPARE(navigator.nextItem(2), QMediaContent());
+ QCOMPARE(navigator.previousItem(), QMediaContent());
+ QCOMPARE(navigator.previousItem(2), QMediaContent());
+
+ QMediaContent content2(QUrl(QLatin1String("file:///2")));
+ playlist.addMedia(content2);
+ QCOMPARE(navigator.currentIndex(), 0);
+ QCOMPARE(navigator.currentItem(), content1);
+ QCOMPARE(navigator.nextItem(), content2);
+ QCOMPARE(navigator.nextItem(2), QMediaContent());
+ QCOMPARE(navigator.previousItem(), QMediaContent());
+ QCOMPARE(navigator.previousItem(2), QMediaContent());
+
+ navigator.jump(1);
+ QCOMPARE(navigator.currentIndex(), 1);
+ QCOMPARE(navigator.currentItem(), content2);
+ QCOMPARE(navigator.nextItem(), QMediaContent());
+ QCOMPARE(navigator.nextItem(2), QMediaContent());
+ QCOMPARE(navigator.previousItem(), content1);
+ QCOMPARE(navigator.previousItem(2), QMediaContent());
+
+ navigator.jump(0);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.next();//jump to the first item
+ QCOMPARE(navigator.currentIndex(), 0);
+
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.previous();//jump to the last item
+ QCOMPARE(navigator.currentIndex(), 1);
+}
+
+void tst_QMediaPlaylistNavigator::loopPlayback()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QMediaPlaylistNavigator navigator(&playlist);
+
+ navigator.setPlaybackMode(QMediaPlaylist::Loop);
+ QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range ");
+ navigator.jump(0);
+ QVERIFY(navigator.currentItem().isNull());
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ QMediaContent content1(QUrl(QLatin1String("file:///1")));
+ playlist.addMedia(content1);
+ navigator.jump(0);
+ QVERIFY(!navigator.currentItem().isNull());
+
+ QCOMPARE(navigator.currentIndex(), 0);
+ QCOMPARE(navigator.currentItem(), content1);
+ QCOMPARE(navigator.nextItem(), content1);
+ QCOMPARE(navigator.nextItem(2), content1);
+ QCOMPARE(navigator.previousItem(), content1);
+ QCOMPARE(navigator.previousItem(2), content1);
+
+ QMediaContent content2(QUrl(QLatin1String("file:///2")));
+ playlist.addMedia(content2);
+ QCOMPARE(navigator.currentIndex(), 0);
+ QCOMPARE(navigator.currentItem(), content1);
+ QCOMPARE(navigator.nextItem(), content2);
+ QCOMPARE(navigator.nextItem(2), content1); //loop over end of the list
+ QCOMPARE(navigator.previousItem(), content2);
+ QCOMPARE(navigator.previousItem(2), content1);
+
+ navigator.jump(1);
+ QCOMPARE(navigator.currentIndex(), 1);
+ QCOMPARE(navigator.currentItem(), content2);
+ QCOMPARE(navigator.nextItem(), content1);
+ QCOMPARE(navigator.nextItem(2), content2);
+ QCOMPARE(navigator.previousItem(), content1);
+ QCOMPARE(navigator.previousItem(2), content2);
+
+ navigator.jump(0);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), 0);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), 0);
+}
+
+void tst_QMediaPlaylistNavigator::currentItemOnce()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QMediaPlaylistNavigator navigator(&playlist);
+
+ navigator.setPlaybackMode(QMediaPlaylist::CurrentItemOnce);
+
+ QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemOnce);
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3"))));
+
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ navigator.jump(1);
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.jump(1);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), -1);
+}
+
+void tst_QMediaPlaylistNavigator::currentItemInLoop()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QMediaPlaylistNavigator navigator(&playlist);
+
+ navigator.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
+
+ QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemInLoop);
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3"))));
+
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.jump(1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), 1);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), 1);
+}
+
+void tst_QMediaPlaylistNavigator::randomPlayback()
+{
+ QLocalMediaPlaylistProvider playlist;
+ QMediaPlaylistNavigator navigator(&playlist);
+
+ navigator.setPlaybackMode(QMediaPlaylist::Random);
+
+ QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random);
+ QCOMPARE(navigator.currentIndex(), -1);
+
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2"))));
+ playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3"))));
+
+ playlist.shuffle();
+
+ QCOMPARE(navigator.currentIndex(), -1);
+ navigator.next();
+ int pos1 = navigator.currentIndex();
+ navigator.next();
+ int pos2 = navigator.currentIndex();
+ navigator.next();
+ int pos3 = navigator.currentIndex();
+
+ QVERIFY(pos1 != -1);
+ QVERIFY(pos2 != -1);
+ QVERIFY(pos3 != -1);
+
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), pos2);
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), pos3);
+ navigator.next();
+ int pos4 = navigator.currentIndex();
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), pos3);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), pos2);
+ navigator.previous();
+ QCOMPARE(navigator.currentIndex(), pos1);
+ navigator.previous();
+ int pos0 = navigator.currentIndex();
+ QVERIFY(pos0 != -1);
+ navigator.next();
+ navigator.next();
+ navigator.next();
+ navigator.next();
+ QCOMPARE(navigator.currentIndex(), pos4);
+
+}
+
+QTEST_MAIN(tst_QMediaPlaylistNavigator)
+#include "tst_qmediaplaylistnavigator.moc"
diff --git a/tests/auto/qmediapluginloader/qmediapluginloader.pro b/tests/auto/qmediapluginloader/qmediapluginloader.pro
new file mode 100644
index 0000000..66950e9
--- /dev/null
+++ b/tests/auto/qmediapluginloader/qmediapluginloader.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediapluginloader.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediapluginloader/tst_qmediapluginloader.cpp b/tests/auto/qmediapluginloader/tst_qmediapluginloader.cpp
new file mode 100644
index 0000000..1ed23a0
--- /dev/null
+++ b/tests/auto/qmediapluginloader/tst_qmediapluginloader.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+
+#include <QtMultimedia/private/qmediapluginloader_p.h>
+#include <QtMultimedia/qmediaserviceproviderplugin.h>
+
+
+
+class tst_QMediaPluginLoader : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+private slots:
+ void testInstance();
+ void testInstances();
+ void testInvalidKey();
+
+private:
+ QMediaPluginLoader *loader;
+};
+
+void tst_QMediaPluginLoader::initTestCase()
+{
+ loader = new QMediaPluginLoader(QMediaServiceProviderFactoryInterface_iid,
+ QLatin1String("/mediaservice"),
+ Qt::CaseInsensitive);
+}
+
+void tst_QMediaPluginLoader::cleanupTestCase()
+{
+ delete loader;
+}
+
+void tst_QMediaPluginLoader::testInstance()
+{
+ const QStringList keys = loader->keys();
+
+ if (keys.isEmpty()) // Test is invalidated, skip.
+ QSKIP("No plug-ins available", SkipAll);
+
+ foreach (const QString &key, keys)
+ QVERIFY(loader->instance(key) != 0);
+}
+
+void tst_QMediaPluginLoader::testInstances()
+{
+ const QStringList keys = loader->keys();
+
+ if (keys.isEmpty()) // Test is invalidated, skip.
+ QSKIP("No plug-ins available", SkipAll);
+
+ foreach (const QString &key, keys)
+ QVERIFY(loader->instances(key).size() > 0);
+}
+
+// Last so as to not interfere with the other tests if there is a failure.
+void tst_QMediaPluginLoader::testInvalidKey()
+{
+ const QString key(QLatin1String("invalid-key"));
+
+ // This test assumes there is no 'invalid-key' in the key list, verify that.
+ if (loader->keys().contains(key))
+ QSKIP("a plug-in includes the invalid key", SkipAll);
+
+ QVERIFY(loader->instance(key) == 0);
+
+ // Test looking up the key hasn't inserted it into the list. See QMap::operator[].
+ QVERIFY(!loader->keys().contains(key));
+
+ QVERIFY(loader->instances(key).isEmpty());
+ QVERIFY(!loader->keys().contains(key));
+}
+
+QTEST_MAIN(tst_QMediaPluginLoader)
+
+#include "tst_qmediapluginloader.moc"
diff --git a/tests/auto/qmediaresource/qmediaresource.pro b/tests/auto/qmediaresource/qmediaresource.pro
new file mode 100644
index 0000000..2741608
--- /dev/null
+++ b/tests/auto/qmediaresource/qmediaresource.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediaresource.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediaresource/tst_qmediaresource.cpp b/tests/auto/qmediaresource/tst_qmediaresource.cpp
new file mode 100644
index 0000000..55ddcab
--- /dev/null
+++ b/tests/auto/qmediaresource/tst_qmediaresource.cpp
@@ -0,0 +1,471 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtMultimedia/qmediaresource.h>
+
+
+class tst_QMediaResource : public QObject
+{
+ Q_OBJECT
+private slots:
+ void constructNull();
+ void construct_data();
+ void construct();
+ void setResolution();
+ void equality();
+ void copy();
+ void assign();
+};
+
+void tst_QMediaResource::constructNull()
+{
+ QMediaResource resource;
+
+ QCOMPARE(resource.isNull(), true);
+ QCOMPARE(resource.url(), QUrl());
+ QCOMPARE(resource.mimeType(), QString());
+ QCOMPARE(resource.language(), QString());
+ QCOMPARE(resource.audioCodec(), QString());
+ QCOMPARE(resource.videoCodec(), QString());
+ QCOMPARE(resource.dataSize(), qint64(0));
+ QCOMPARE(resource.audioBitRate(), 0);
+ QCOMPARE(resource.sampleRate(), 0);
+ QCOMPARE(resource.channelCount(), 0);
+ QCOMPARE(resource.videoBitRate(), 0);
+ QCOMPARE(resource.resolution(), QSize());
+}
+
+void tst_QMediaResource::construct_data()
+{
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("mimeType");
+ QTest::addColumn<QString>("language");
+ QTest::addColumn<QString>("audioCodec");
+ QTest::addColumn<QString>("videoCodec");
+ QTest::addColumn<qint64>("dataSize");
+ QTest::addColumn<int>("audioBitRate");
+ QTest::addColumn<int>("sampleRate");
+ QTest::addColumn<int>("channelCount");
+ QTest::addColumn<int>("videoBitRate");
+ QTest::addColumn<QSize>("resolution");
+
+ QTest::newRow("audio content")
+ << QUrl(QString::fromLatin1("http:://test.com/test.mp3"))
+ << QString::fromLatin1("audio/mpeg")
+ << QString::fromLatin1("eng")
+ << QString::fromLatin1("mp3")
+ << QString()
+ << qint64(5465433)
+ << 128000
+ << 44100
+ << 2
+ << 0
+ << QSize();
+ QTest::newRow("image content")
+ << QUrl(QString::fromLatin1("http:://test.com/test.jpg"))
+ << QString::fromLatin1("image/jpeg")
+ << QString()
+ << QString()
+ << QString()
+ << qint64(23600)
+ << 0
+ << 0
+ << 0
+ << 0
+ << QSize(640, 480);
+ QTest::newRow("video content")
+ << QUrl(QString::fromLatin1("http:://test.com/test.mp4"))
+ << QString::fromLatin1("video/mp4")
+ << QString()
+ << QString::fromLatin1("aac")
+ << QString::fromLatin1("h264")
+ << qint64(36245851)
+ << 96000
+ << 44000
+ << 5
+ << 750000
+ << QSize(720, 576);
+ QTest::newRow("thumbnail")
+ << QUrl(QString::fromLatin1("file::///thumbs/test.png"))
+ << QString::fromLatin1("image/png")
+ << QString()
+ << QString()
+ << QString()
+ << qint64(2360)
+ << 0
+ << 0
+ << 0
+ << 0
+ << QSize(128, 128);
+}
+
+void tst_QMediaResource::construct()
+{
+ QFETCH(QUrl, url);
+ QFETCH(QString, mimeType);
+ QFETCH(QString, language);
+ QFETCH(QString, audioCodec);
+ QFETCH(QString, videoCodec);
+ QFETCH(qint64, dataSize);
+ QFETCH(int, audioBitRate);
+ QFETCH(int, sampleRate);
+ QFETCH(int, channelCount);
+ QFETCH(int, videoBitRate);
+ QFETCH(QSize, resolution);
+
+ {
+ QMediaResource resource(url);
+
+ QCOMPARE(resource.isNull(), false);
+ QCOMPARE(resource.url(), url);
+ QCOMPARE(resource.mimeType(), QString());
+ QCOMPARE(resource.language(), QString());
+ QCOMPARE(resource.audioCodec(), QString());
+ QCOMPARE(resource.videoCodec(), QString());
+ QCOMPARE(resource.dataSize(), qint64(0));
+ QCOMPARE(resource.audioBitRate(), 0);
+ QCOMPARE(resource.sampleRate(), 0);
+ QCOMPARE(resource.channelCount(), 0);
+ QCOMPARE(resource.videoBitRate(), 0);
+ QCOMPARE(resource.resolution(), QSize());
+ }
+ {
+ QMediaResource resource(url, mimeType);
+
+ QCOMPARE(resource.isNull(), false);
+ QCOMPARE(resource.url(), url);
+ QCOMPARE(resource.mimeType(), mimeType);
+ QCOMPARE(resource.language(), QString());
+ QCOMPARE(resource.audioCodec(), QString());
+ QCOMPARE(resource.videoCodec(), QString());
+ QCOMPARE(resource.dataSize(), qint64(0));
+ QCOMPARE(resource.audioBitRate(), 0);
+ QCOMPARE(resource.sampleRate(), 0);
+ QCOMPARE(resource.channelCount(), 0);
+ QCOMPARE(resource.videoBitRate(), 0);
+ QCOMPARE(resource.resolution(), QSize());
+
+ resource.setLanguage(language);
+ resource.setAudioCodec(audioCodec);
+ resource.setVideoCodec(videoCodec);
+ resource.setDataSize(dataSize);
+ resource.setAudioBitRate(audioBitRate);
+ resource.setSampleRate(sampleRate);
+ resource.setChannelCount(channelCount);
+ resource.setVideoBitRate(videoBitRate);
+ resource.setResolution(resolution);
+
+ QCOMPARE(resource.language(), language);
+ QCOMPARE(resource.audioCodec(), audioCodec);
+ QCOMPARE(resource.videoCodec(), videoCodec);
+ QCOMPARE(resource.dataSize(), dataSize);
+ QCOMPARE(resource.audioBitRate(), audioBitRate);
+ QCOMPARE(resource.sampleRate(), sampleRate);
+ QCOMPARE(resource.channelCount(), channelCount);
+ QCOMPARE(resource.videoBitRate(), videoBitRate);
+ QCOMPARE(resource.resolution(), resolution);
+ }
+}
+
+void tst_QMediaResource::setResolution()
+{
+ QMediaResource resource(
+ QUrl(QString::fromLatin1("file::///thumbs/test.png")),
+ QString::fromLatin1("image/png"));
+
+ QCOMPARE(resource.resolution(), QSize());
+
+ resource.setResolution(QSize(120, 80));
+ QCOMPARE(resource.resolution(), QSize(120, 80));
+
+ resource.setResolution(QSize(-1, 23));
+ QCOMPARE(resource.resolution(), QSize(-1, 23));
+
+ resource.setResolution(QSize(-43, 34));
+ QCOMPARE(resource.resolution(), QSize(-43, 34));
+
+ resource.setResolution(QSize(64, -1));
+ QCOMPARE(resource.resolution(), QSize(64, -1));
+
+ resource.setResolution(QSize(64, -83));
+ QCOMPARE(resource.resolution(), QSize(64, -83));
+
+ resource.setResolution(QSize(-12, -83));
+ QCOMPARE(resource.resolution(), QSize(-12, -83));
+
+ resource.setResolution(QSize());
+ QCOMPARE(resource.resolution(), QSize(-1, -1));
+
+ resource.setResolution(120, 80);
+ QCOMPARE(resource.resolution(), QSize(120, 80));
+
+ resource.setResolution(-1, 23);
+ QCOMPARE(resource.resolution(), QSize(-1, 23));
+
+ resource.setResolution(-43, 34);
+ QCOMPARE(resource.resolution(), QSize(-43, 34));
+
+ resource.setResolution(64, -1);
+ QCOMPARE(resource.resolution(), QSize(64, -1));
+
+ resource.setResolution(64, -83);
+ QCOMPARE(resource.resolution(), QSize(64, -83));
+
+ resource.setResolution(-12, -83);
+ QCOMPARE(resource.resolution(), QSize(-12, -83));
+
+ resource.setResolution(-1, -1);
+ QCOMPARE(resource.resolution(), QSize());
+}
+
+void tst_QMediaResource::equality()
+{
+ QMediaResource resource1(
+ QUrl(QString::fromLatin1("http://test.com/test.mp4")),
+ QString::fromLatin1("video/mp4"));
+ QMediaResource resource2(
+ QUrl(QString::fromLatin1("http://test.com/test.mp4")),
+ QString::fromLatin1("video/mp4"));
+ QMediaResource resource3(
+ QUrl(QString::fromLatin1("file:///thumbs/test.jpg")));
+ QMediaResource resource4(
+ QUrl(QString::fromLatin1("file:///thumbs/test.jpg")));
+ QMediaResource resource5(
+ QUrl(QString::fromLatin1("http://test.com/test.mp3")),
+ QString::fromLatin1("audio/mpeg"));
+
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ QCOMPARE(resource3 == resource4, true);
+ QCOMPARE(resource3 != resource4, false);
+
+ QCOMPARE(resource1 == resource3, false);
+ QCOMPARE(resource1 != resource3, true);
+
+ QCOMPARE(resource1 == resource5, false);
+ QCOMPARE(resource1 != resource5, true);
+
+ resource1.setAudioCodec(QString::fromLatin1("mp3"));
+ resource2.setAudioCodec(QString::fromLatin1("aac"));
+
+ // Not equal differing audio codecs.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource1.setAudioCodec(QString::fromLatin1("aac"));
+
+ // Equal.
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setVideoCodec(QString());
+
+ // Equal.
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setVideoCodec(QString::fromLatin1("h264"));
+
+ // Not equal differing video codecs.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource2.setVideoCodec(QString::fromLatin1("h264"));
+
+ // Equal.
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource2.setDataSize(0);
+
+ // Equal.
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setDataSize(546423);
+
+ // Not equal differing video codecs.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource2.setDataSize(546423);
+
+ // Equal.
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setAudioBitRate(96000);
+ resource1.setSampleRate(48000);
+ resource2.setSampleRate(44100);
+ resource1.setChannelCount(0);
+ resource1.setVideoBitRate(900000);
+ resource2.setLanguage(QString::fromLatin1("eng"));
+
+ // Not equal, audio bit rate, sample rate, video bit rate, and
+ // language.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource2.setAudioBitRate(96000);
+ resource1.setSampleRate(44100);
+
+ // Not equal, differing video bit rate, and language.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource2.setVideoBitRate(900000);
+ resource1.setLanguage(QString::fromLatin1("eng"));
+
+ // Equal
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setResolution(QSize());
+
+ // Equal
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource2.setResolution(-1, -1);
+
+ // Equal
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+
+ resource1.setResolution(QSize(-640, -480));
+
+ // Not equal, differing resolution.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+ resource1.setResolution(QSize(640, 480));
+ resource2.setResolution(QSize(800, 600));
+
+ // Not equal, differing resolution.
+ QCOMPARE(resource1 == resource2, false);
+ QCOMPARE(resource1 != resource2, true);
+
+ resource1.setResolution(800, 600);
+
+ // Equal
+ QCOMPARE(resource1 == resource2, true);
+ QCOMPARE(resource1 != resource2, false);
+}
+
+void tst_QMediaResource::copy()
+{
+ const QUrl url(QString::fromLatin1("http://test.com/test.mp4"));
+ const QString mimeType(QLatin1String("video/mp4"));
+ const QString amrCodec(QLatin1String("amr"));
+ const QString mp3Codec(QLatin1String("mp3"));
+ const QString aacCodec(QLatin1String("aac"));
+ const QString h264Codec(QLatin1String("h264"));
+
+ QMediaResource original(url, mimeType);
+ original.setAudioCodec(amrCodec);
+
+ QMediaResource copy(original);
+
+ QCOMPARE(copy.url(), url);
+ QCOMPARE(copy.mimeType(), mimeType);
+ QCOMPARE(copy.audioCodec(), amrCodec);
+
+ QCOMPARE(original == copy, true);
+ QCOMPARE(original != copy, false);
+
+ original.setAudioCodec(mp3Codec);
+
+ QCOMPARE(copy.audioCodec(), amrCodec);
+ QCOMPARE(original == copy, false);
+ QCOMPARE(original != copy, true);
+
+ copy.setAudioCodec(aacCodec);
+ copy.setVideoCodec(h264Codec);
+
+ QCOMPARE(copy.url(), url);
+ QCOMPARE(copy.mimeType(), mimeType);
+
+ QCOMPARE(original.audioCodec(), mp3Codec);
+}
+
+void tst_QMediaResource::assign()
+{
+ const QUrl url(QString::fromLatin1("http://test.com/test.mp4"));
+ const QString mimeType(QLatin1String("video/mp4"));
+ const QString amrCodec(QLatin1String("amr"));
+ const QString mp3Codec(QLatin1String("mp3"));
+ const QString aacCodec(QLatin1String("aac"));
+ const QString h264Codec(QLatin1String("h264"));
+
+ QMediaResource copy(QUrl(QString::fromLatin1("file:///thumbs/test.jpg")));
+
+ QMediaResource original(url, mimeType);
+ original.setAudioCodec(amrCodec);
+
+ copy = original;
+
+ QCOMPARE(copy.url(), url);
+ QCOMPARE(copy.mimeType(), mimeType);
+ QCOMPARE(copy.audioCodec(), amrCodec);
+
+ QCOMPARE(original == copy, true);
+ QCOMPARE(original != copy, false);
+
+ original.setAudioCodec(mp3Codec);
+
+ QCOMPARE(copy.audioCodec(), amrCodec);
+ QCOMPARE(original == copy, false);
+ QCOMPARE(original != copy, true);
+
+ copy.setAudioCodec(aacCodec);
+ copy.setVideoCodec(h264Codec);
+
+ QCOMPARE(copy.url(), url);
+ QCOMPARE(copy.mimeType(), mimeType);
+
+ QCOMPARE(original.audioCodec(), mp3Codec);
+}
+
+QTEST_MAIN(tst_QMediaResource)
+
+#include "tst_qmediaresource.moc"
diff --git a/tests/auto/qmediaservice/qmediaservice.pro b/tests/auto/qmediaservice/qmediaservice.pro
new file mode 100644
index 0000000..f877665
--- /dev/null
+++ b/tests/auto/qmediaservice/qmediaservice.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediaservice.cpp
+
+QT = core gui multimedia
+
diff --git a/tests/auto/qmediaservice/tst_qmediaservice.cpp b/tests/auto/qmediaservice/tst_qmediaservice.cpp
new file mode 100644
index 0000000..3c3684a
--- /dev/null
+++ b/tests/auto/qmediaservice/tst_qmediaservice.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtMultimedia/qvideodevicecontrol.h>
+#include <QtMultimedia/qmediacontrol.h>
+#include <QtMultimedia/qmediaservice.h>
+
+#include <QtGui/qapplication.h>
+#include <QtGui/qstyle.h>
+
+class QtTestMediaService;
+
+
+class tst_QMediaService : public QObject
+{
+ Q_OBJECT
+private slots:
+ void initTestCase();
+
+ void control_iid();
+ void control();
+};
+
+
+class QtTestMediaControlA : public QMediaControl
+{
+ Q_OBJECT
+};
+
+
+#define QtTestMediaControlA_iid "com.nokia.QtTestMediaControlA"
+Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlA, QtTestMediaControlA_iid)
+
+
+class QtTestMediaControlB : public QMediaControl
+{
+ Q_OBJECT
+};
+
+#define QtTestMediaControlB_iid "com.nokia.QtTestMediaControlB"
+Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlB, QtTestMediaControlB_iid)
+
+
+class QtTestMediaControlC : public QMediaControl
+{
+ Q_OBJECT
+};
+
+#define QtTestMediaControlC_iid "com.nokia.QtTestMediaControlC"
+Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlC, QtTestMediaControlA_iid) // Yes A.
+
+class QtTestMediaControlD : public QMediaControl
+{
+ Q_OBJECT
+};
+
+#define QtTestMediaControlD_iid "com.nokia.QtTestMediaControlD"
+Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlD, QtTestMediaControlD_iid)
+
+class QtTestMediaControlE : public QMediaControl
+{
+ Q_OBJECT
+};
+
+struct QtTestDevice
+{
+ QtTestDevice() {}
+ QtTestDevice(const QString &name, const QString &description, const QIcon &icon)
+ : name(name), description(description), icon(icon)
+ {
+ }
+
+ QString name;
+ QString description;
+ QIcon icon;
+};
+
+class QtTestVideoDeviceControl : public QVideoDeviceControl
+{
+public:
+ QtTestVideoDeviceControl(QObject *parent = 0)
+ : QVideoDeviceControl(parent)
+ , m_selectedDevice(-1)
+ , m_defaultDevice(-1)
+ {
+ }
+
+ int deviceCount() const { return devices.count(); }
+
+ QString deviceName(int index) const { return devices.value(index).name; }
+ QString deviceDescription(int index) const { return devices.value(index).description; }
+ QIcon deviceIcon(int index) const { return devices.value(index).icon; }
+
+ int defaultDevice() const { return m_defaultDevice; }
+ void setDefaultDevice(int index) { m_defaultDevice = index; }
+
+ int selectedDevice() const { return m_selectedDevice; }
+ void setSelectedDevice(int index)
+ {
+ emit selectedDeviceChanged(m_selectedDevice = index);
+ emit selectedDeviceChanged(devices.value(index).name);
+ }
+
+ QList<QtTestDevice> devices;
+
+private:
+ int m_selectedDevice;
+ int m_defaultDevice;
+};
+
+class QtTestMediaService : public QMediaService
+{
+ Q_OBJECT
+public:
+ QtTestMediaService()
+ : QMediaService(0)
+ , hasDeviceControls(false)
+ {
+ }
+
+ QMediaControl* control(const char *name) const
+ {
+ if (strcmp(name, QtTestMediaControlA_iid) == 0)
+ return const_cast<QtTestMediaControlA *>(&controlA);
+ else if (strcmp(name, QtTestMediaControlB_iid) == 0)
+ return const_cast<QtTestMediaControlB *>(&controlB);
+ else if (strcmp(name, QtTestMediaControlC_iid) == 0)
+ return const_cast<QtTestMediaControlC *>(&controlC);
+ else if (hasDeviceControls && strcmp(name, QVideoDeviceControl_iid) == 0)
+ return const_cast<QtTestVideoDeviceControl *>(&videoDeviceControl);
+ else
+ return 0;
+ }
+
+ using QMediaService::control;
+
+ QtTestMediaControlA controlA;
+ QtTestMediaControlB controlB;
+ QtTestMediaControlC controlC;
+ QtTestVideoDeviceControl videoDeviceControl;
+ bool hasDeviceControls;
+};
+
+void tst_QMediaService::initTestCase()
+{
+}
+
+void tst_QMediaService::control_iid()
+{
+ const char *nullString = 0;
+
+ // Default implementation.
+ QCOMPARE(qmediacontrol_iid<QtTestMediaControlE *>(), nullString);
+
+ // Partial template.
+ QVERIFY(qstrcmp(qmediacontrol_iid<QtTestMediaControlA *>(), QtTestMediaControlA_iid) == 0);
+}
+
+void tst_QMediaService::control()
+{
+ QtTestMediaService service;
+
+ QCOMPARE(service.control<QtTestMediaControlA *>(), &service.controlA);
+ QCOMPARE(service.control<QtTestMediaControlB *>(), &service.controlB);
+ QVERIFY(!service.control<QtTestMediaControlC *>()); // Faulty implementation returns A.
+ QVERIFY(!service.control<QtTestMediaControlD *>()); // No control of that type.
+}
+
+QTEST_MAIN(tst_QMediaService)
+
+#include "tst_qmediaservice.moc"
diff --git a/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro b/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro
new file mode 100644
index 0000000..9aaa9e5
--- /dev/null
+++ b/tests/auto/qmediaserviceprovider/qmediaserviceprovider.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediaserviceprovider.cpp
+
+QT = core gui multimedia
+
diff --git a/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp b/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
new file mode 100644
index 0000000..a2c1be5
--- /dev/null
+++ b/tests/auto/qmediaserviceprovider/tst_qmediaserviceprovider.cpp
@@ -0,0 +1,458 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+#include <QStringList>
+
+#include <QtMultimedia/qmediaserviceprovider.h>
+#include <QtMultimedia/qmediaserviceproviderplugin.h>
+#include <QtMultimedia/private/qmediapluginloader_p.h>
+#include <QtMultimedia/qmediaobject.h>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/qmediaplayer.h>
+
+class MockMediaService : public QMediaService
+{
+ Q_OBJECT
+public:
+ MockMediaService(const QString& name, QObject *parent = 0) : QMediaService(parent)
+ { setObjectName(name); }
+ ~MockMediaService() {}
+
+ QMediaControl* control(const char *) const {return 0;}
+};
+
+class MockServicePlugin1 : public QMediaServiceProviderPlugin,
+ public QMediaServiceSupportedFormatsInterface,
+ public QMediaServiceSupportedDevicesInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
+ Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+public:
+ QStringList keys() const
+ {
+ return QStringList() <<
+ QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) <<
+ QLatin1String(Q_MEDIASERVICE_CAMERA);
+ }
+
+ QMediaService* create(QString const& key)
+ {
+ if (keys().contains(key))
+ return new MockMediaService("MockServicePlugin1");
+ else
+ return 0;
+ }
+
+ void release(QMediaService *service)
+ {
+ delete service;
+ }
+
+ QtMedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
+ {
+ if (codecs.contains(QLatin1String("mpeg4")))
+ return QtMedia::NotSupported;
+
+ if (mimeType == "audio/ogg") {
+ return QtMedia::ProbablySupported;
+ }
+
+ return QtMedia::MaybeSupported;
+ }
+
+ QStringList supportedMimeTypes() const
+ {
+ return QStringList("audio/ogg");
+ }
+
+ QList<QByteArray> devices(const QByteArray &service) const
+ {
+ QList<QByteArray> res;
+ if (service == QByteArray(Q_MEDIASERVICE_CAMERA))
+ res << "camera1" << "camera2";
+ return res;
+ }
+
+ QString deviceDescription(const QByteArray &service, const QByteArray &device)
+ {
+ if (devices(service).contains(device))
+ return QString(device)+" description";
+ else
+ return QString();
+ }
+};
+
+class MockServicePlugin2 : public QMediaServiceProviderPlugin,
+ public QMediaServiceSupportedFormatsInterface,
+ public QMediaServiceFeaturesInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QMediaServiceSupportedFormatsInterface)
+ Q_INTERFACES(QMediaServiceFeaturesInterface)
+public:
+ QStringList keys() const
+ {
+ return QStringList() << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER);
+ }
+
+ QMediaService* create(QString const& key)
+ {
+ if (keys().contains(key))
+ return new MockMediaService("MockServicePlugin2");
+ else
+ return 0;
+ }
+
+ void release(QMediaService *service)
+ {
+ delete service;
+ }
+
+ QtMedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const
+ {
+ Q_UNUSED(codecs);
+
+ if (mimeType == "audio/wav")
+ return QtMedia::PreferedService;
+
+ return QtMedia::NotSupported;
+ }
+
+ QStringList supportedMimeTypes() const
+ {
+ return QStringList("audio/wav");
+ }
+
+ QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const
+ {
+ if (service == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER))
+ return QMediaServiceProviderHint::LowLatencyPlayback;
+ else
+ return 0;
+ }
+};
+
+
+class MockServicePlugin3 : public QMediaServiceProviderPlugin,
+ public QMediaServiceSupportedDevicesInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
+public:
+ QStringList keys() const
+ {
+ return QStringList() <<
+ QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) <<
+ QLatin1String(Q_MEDIASERVICE_CAMERA) <<
+ QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE);
+ }
+
+ QMediaService* create(QString const& key)
+ {
+ if (keys().contains(key))
+ return new MockMediaService("MockServicePlugin3");
+ else
+ return 0;
+ }
+
+ void release(QMediaService *service)
+ {
+ delete service;
+ }
+
+ QList<QByteArray> devices(const QByteArray &service) const
+ {
+ QList<QByteArray> res;
+ if (service == QByteArray(Q_MEDIASERVICE_CAMERA))
+ res << "camera3" << "camera4";
+ else if (service == QByteArray(Q_MEDIASERVICE_AUDIOSOURCE))
+ res << "audiosource1" << "audiosource2";
+
+ return res;
+ }
+
+ QString deviceDescription(const QByteArray &service, const QByteArray &device)
+ {
+ if (devices(service).contains(device))
+ return QString(device)+" description";
+ else
+ return QString();
+ }
+};
+
+
+
+class MockMediaServiceProvider : public QMediaServiceProvider
+{
+ QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &)
+ {
+ Q_UNUSED(type);
+ return 0;
+ }
+
+ void releaseService(QMediaService *service)
+ {
+ Q_UNUSED(service);
+ }
+};
+
+
+class tst_QMediaServiceProvider : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+
+private slots:
+ void testDefaultProviderAvailable();
+ void testObtainService();
+ void testHasSupport();
+ void testSupportedMimeTypes();
+ void testDevices();
+ void testProviderHints();
+
+private:
+ QObjectList plugins;
+};
+
+void tst_QMediaServiceProvider::initTestCase()
+{
+ plugins << new MockServicePlugin1;
+ plugins << new MockServicePlugin2;
+ plugins << new MockServicePlugin3;
+
+ QMediaPluginLoader::setStaticPlugins(QLatin1String("/mediaservice"), plugins);
+}
+
+void tst_QMediaServiceProvider::testDefaultProviderAvailable()
+{
+ // Must always be a default provider available
+ QVERIFY(QMediaServiceProvider::defaultServiceProvider() != 0);
+}
+
+void tst_QMediaServiceProvider::testObtainService()
+{
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider", SkipSingle);
+
+ QMediaService *service = 0;
+
+ QTest::ignoreMessage(QtWarningMsg, "Load static plugins for \"/mediaservice/\" ");
+ // Player
+ service = provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER);
+ QVERIFY(service != 0);
+ provider->releaseService(service);
+}
+
+void tst_QMediaServiceProvider::testHasSupport()
+{
+ MockMediaServiceProvider mockProvider;
+ QCOMPARE(mockProvider.hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
+ QtMedia::MaybeSupported);
+
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider", SkipSingle);
+
+ QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()),
+ QtMedia::MaybeSupported);
+
+ QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/ogg", QStringList()),
+ QtMedia::ProbablySupported);
+
+ //while the service returns PreferredService, provider should return ProbablySupported
+ QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/wav", QStringList()),
+ QtMedia::ProbablySupported);
+
+ //even while all the plugins with "hasSupport" returned NotSupported,
+ //MockServicePlugin3 has no "hasSupport" interface, so MaybeSupported
+ QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/avi",
+ QStringList() << "mpeg4"),
+ QtMedia::MaybeSupported);
+
+ QCOMPARE(provider->hasSupport(QByteArray("non existing service"), "video/ogv", QStringList()),
+ QtMedia::NotSupported);
+
+ QCOMPARE(QMediaPlayer::hasSupport("video/ogv"), QtMedia::MaybeSupported);
+ QCOMPARE(QMediaPlayer::hasSupport("audio/ogg"), QtMedia::ProbablySupported);
+ QCOMPARE(QMediaPlayer::hasSupport("audio/wav"), QtMedia::ProbablySupported);
+
+ //ensure the correct media player plugin is choosen for mime type
+ QMediaPlayer simplePlayer(0, QMediaPlayer::LowLatency);
+ QCOMPARE(simplePlayer.service()->objectName(), QLatin1String("MockServicePlugin2"));
+
+ QMediaPlayer mediaPlayer;
+ QVERIFY(mediaPlayer.service()->objectName() != QLatin1String("MockServicePlugin2"));
+}
+
+void tst_QMediaServiceProvider::testSupportedMimeTypes()
+{
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ if (provider == 0)
+ QSKIP("No default provider", SkipSingle);
+
+ QVERIFY(provider->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)).contains("audio/ogg"));
+ QVERIFY(!provider->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)).contains("audio/mp3"));
+}
+
+void tst_QMediaServiceProvider::testDevices()
+{
+ MockMediaServiceProvider mockProvider;
+ QVERIFY(mockProvider.devices(QByteArray(Q_MEDIASERVICE_CAMERA)).isEmpty());
+ QVERIFY(mockProvider.deviceDescription(QByteArray(Q_MEDIASERVICE_CAMERA),
+ QByteArray()).isEmpty());
+
+ QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider();
+
+ QList<QByteArray> cameraDevices = provider->devices(QByteArray(Q_MEDIASERVICE_CAMERA));
+ QCOMPARE(cameraDevices.count(), 4);
+ QVERIFY(cameraDevices.contains(QByteArray("camera1")));
+ QVERIFY(cameraDevices.contains(QByteArray("camera2")));
+ QVERIFY(cameraDevices.contains(QByteArray("camera3")));
+ QVERIFY(cameraDevices.contains(QByteArray("camera4")));
+
+ /*
+ //ensure the right plugin is choosen for a device
+ QCamera camera1(QByteArray("camera1"));
+ QCOMPARE( camera1.service()->objectName(), QLatin1String("MockServicePlugin1") );
+ QCamera camera2(QByteArray("camera2"));
+ QCOMPARE( camera2.service()->objectName(), QLatin1String("MockServicePlugin1") );
+ QCamera camera3(QByteArray("camera3"));
+ QCOMPARE( camera3.service()->objectName(), QLatin1String("MockServicePlugin3") );
+ QCamera camera4(QByteArray("camera4"));
+ QCOMPARE( camera4.service()->objectName(), QLatin1String("MockServicePlugin3") );
+
+ QList<QByteArray> audioSourceDevices = provider->devices(QByteArray(Q_MEDIASERVICE_AUDIOSOURCE));
+ QCOMPARE(audioSourceDevices.count(), 2);
+ QVERIFY(audioSourceDevices.contains(QByteArray("audiosource1")));
+ QVERIFY(audioSourceDevices.contains(QByteArray("audiosource2")));
+
+ QVERIFY(provider->devices(QByteArray("non existing service")).isEmpty());
+ */
+}
+
+
+
+
+void tst_QMediaServiceProvider::testProviderHints()
+{
+ {
+ QMediaServiceProviderHint hint;
+ QVERIFY(hint.isNull());
+ QCOMPARE(hint.type(), QMediaServiceProviderHint::Null);
+ QVERIFY(hint.device().isEmpty());
+ QVERIFY(hint.mimeType().isEmpty());
+ QVERIFY(hint.codecs().isEmpty());
+ QCOMPARE(hint.features(), 0);
+ }
+
+ {
+ QByteArray deviceName(QByteArray("testDevice"));
+ QMediaServiceProviderHint hint(deviceName);
+ QVERIFY(!hint.isNull());
+ QCOMPARE(hint.type(), QMediaServiceProviderHint::Device);
+ QCOMPARE(hint.device(), deviceName);
+ QVERIFY(hint.mimeType().isEmpty());
+ QVERIFY(hint.codecs().isEmpty());
+ QCOMPARE(hint.features(), 0);
+ }
+
+ {
+ QMediaServiceProviderHint hint(QMediaServiceProviderHint::LowLatencyPlayback);
+ QVERIFY(!hint.isNull());
+ QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures);
+ QVERIFY(hint.device().isEmpty());
+ QVERIFY(hint.mimeType().isEmpty());
+ QVERIFY(hint.codecs().isEmpty());
+ QCOMPARE(hint.features(), QMediaServiceProviderHint::LowLatencyPlayback);
+ }
+
+ {
+ QString mimeType(QLatin1String("video/ogg"));
+ QStringList codecs;
+ codecs << "theora" << "vorbis";
+
+ QMediaServiceProviderHint hint(mimeType,codecs);
+ QVERIFY(!hint.isNull());
+ QCOMPARE(hint.type(), QMediaServiceProviderHint::ContentType);
+ QVERIFY(hint.device().isEmpty());
+ QCOMPARE(hint.mimeType(), mimeType);
+ QCOMPARE(hint.codecs(), codecs);
+
+ QMediaServiceProviderHint hint2(hint);
+
+ QVERIFY(!hint2.isNull());
+ QCOMPARE(hint2.type(), QMediaServiceProviderHint::ContentType);
+ QVERIFY(hint2.device().isEmpty());
+ QCOMPARE(hint2.mimeType(), mimeType);
+ QCOMPARE(hint2.codecs(), codecs);
+
+ QMediaServiceProviderHint hint3;
+ QVERIFY(hint3.isNull());
+ hint3 = hint;
+ QVERIFY(!hint3.isNull());
+ QCOMPARE(hint3.type(), QMediaServiceProviderHint::ContentType);
+ QVERIFY(hint3.device().isEmpty());
+ QCOMPARE(hint3.mimeType(), mimeType);
+ QCOMPARE(hint3.codecs(), codecs);
+
+ QCOMPARE(hint, hint2);
+ QCOMPARE(hint3, hint2);
+
+ QMediaServiceProviderHint hint4(mimeType,codecs);
+ QCOMPARE(hint, hint4);
+
+ QMediaServiceProviderHint hint5(mimeType,QStringList());
+ QVERIFY(hint != hint5);
+ }
+}
+
+QTEST_MAIN(tst_QMediaServiceProvider)
+
+#include "tst_qmediaserviceprovider.moc"
diff --git a/tests/auto/qmediatimerange/qmediatimerange.pro b/tests/auto/qmediatimerange/qmediatimerange.pro
new file mode 100644
index 0000000..b1b436e
--- /dev/null
+++ b/tests/auto/qmediatimerange/qmediatimerange.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qmediatimerange.cpp
+
+QT = core multimedia
+
diff --git a/tests/auto/qmediatimerange/tst_qmediatimerange.cpp b/tests/auto/qmediatimerange/tst_qmediatimerange.cpp
new file mode 100644
index 0000000..a8c58db
--- /dev/null
+++ b/tests/auto/qmediatimerange/tst_qmediatimerange.cpp
@@ -0,0 +1,735 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/qdebug.h>
+
+#include <QtMultimedia/qmediatimerange.h>
+
+class tst_QMediaTimeRange: public QObject
+{
+ Q_OBJECT
+
+public slots:
+
+private slots:
+ void testCtor();
+ void testGetters();
+ void testAssignment();
+ void testNormalize();
+ void testTranslated();
+ void testEarliestLatest();
+ void testContains();
+ void testAddInterval();
+ void testAddTimeRange();
+ void testRemoveInterval();
+ void testRemoveTimeRange();
+ void testClear();
+ void testComparisons();
+ void testArithmetic();
+};
+
+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);
+}
+
+void tst_QMediaTimeRange::testGetters()
+{
+ QMediaTimeRange x;
+
+ // isEmpty
+ QVERIFY(x.isEmpty());
+
+ x.addInterval(10, 20);
+
+ // isEmpty + isContinuous
+ QVERIFY(!x.isEmpty());
+ QVERIFY(x.isContinuous());
+
+ x.addInterval(30, 40);
+
+ // isEmpty + isContinuous + intervals + start + end
+ QVERIFY(!x.isEmpty());
+ QVERIFY(!x.isContinuous());
+ QVERIFY(x.intervals().count() == 2);
+ QVERIFY(x.intervals()[0].start() == 10);
+ QVERIFY(x.intervals()[0].end() == 20);
+ QVERIFY(x.intervals()[1].start() == 30);
+ QVERIFY(x.intervals()[1].end() == 40);
+}
+
+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::testNormalize()
+{
+ QMediaTimeInterval x(20, 10);
+
+ QVERIFY(!x.isNormal());
+
+ x = x.normalized();
+
+ QVERIFY(x.isNormal());
+ QVERIFY(x.start() == 10);
+ QVERIFY(x.end() == 20);
+}
+
+void tst_QMediaTimeRange::testTranslated()
+{
+ QMediaTimeInterval x(10, 20);
+ x = x.translated(10);
+
+ QVERIFY(x.start() == 20);
+ QVERIFY(x.end() == 30);
+}
+
+void tst_QMediaTimeRange::testEarliestLatest()
+{
+ // Test over a single interval
+ QMediaTimeRange x(30, 40);
+
+ QVERIFY(x.earliestTime() == 30);
+ QVERIFY(x.latestTime() == 40);
+
+ // Test over multiple intervals
+ x.addInterval(50, 60);
+
+ QVERIFY(x.earliestTime() == 30);
+ QVERIFY(x.latestTime() == 60);
+}
+
+void tst_QMediaTimeRange::testContains()
+{
+ // Test over a single interval
+ QMediaTimeRange x(10, 20);
+
+ QVERIFY(!x.isEmpty());
+ QVERIFY(x.isContinuous());
+ QVERIFY(x.contains(15));
+ QVERIFY(x.contains(10));
+ QVERIFY(x.contains(20));
+ QVERIFY(!x.contains(25));
+
+ // Test over multiple intervals
+ x.addInterval(40, 50);
+
+ QVERIFY(!x.isEmpty());
+ QVERIFY(!x.isContinuous());
+ QVERIFY(x.contains(15));
+ QVERIFY(x.contains(45));
+ QVERIFY(!x.contains(30));
+
+ // Test over a concrete interval
+ QMediaTimeInterval y(10, 20);
+ QVERIFY(y.contains(15));
+ QVERIFY(y.contains(10));
+ QVERIFY(y.contains(20));
+ QVERIFY(!y.contains(25));
+}
+
+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());
+}
+
+void tst_QMediaTimeRange::testAddTimeRange()
+{
+ // Add Time Range uses Add Interval internally,
+ // so in this test the focus is on combinations of number
+ // of intervals added, rather than the different types of
+ // merges which can occur.
+ QMediaTimeRange a, b;
+
+ // Add Single into Single
+ a = QMediaTimeRange(10, 30);
+ b = QMediaTimeRange(20, 40);
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 40);
+
+ // Add Multiple into Single
+ a = QMediaTimeRange();
+ a.addInterval(10, 30);
+ a.addInterval(40, 60);
+
+ b = QMediaTimeRange(20, 50);
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 60);
+
+ // Add Single into Multiple
+ a = QMediaTimeRange(20, 50);
+
+ b = QMediaTimeRange();
+ b.addInterval(10, 30);
+ b.addInterval(40, 60);
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 60);
+
+ // Add Multiple into Multiple
+ a = QMediaTimeRange();
+ a.addInterval(10, 30);
+ a.addInterval(40, 70);
+ a.addInterval(80, 100);
+
+ b = QMediaTimeRange();
+ b.addInterval(20, 50);
+ b.addInterval(60, 90);
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 100);
+
+ // Add Nothing to Single
+ a = QMediaTimeRange();
+ b = QMediaTimeRange(10, 20);
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 20);
+
+ // Add Single to Nothing
+ a = QMediaTimeRange(10, 20);
+ b = QMediaTimeRange();
+
+ b.addTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 20);
+
+ // Add Nothing to Nothing
+ a = QMediaTimeRange();
+ b = QMediaTimeRange();
+
+ b.addTimeRange(a);
+
+ QVERIFY(b.isEmpty());
+}
+
+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::testRemoveTimeRange()
+{
+ // Remove Time Range uses Remove Interval internally,
+ // so in this test the focus is on combinations of number
+ // of intervals removed, rather than the different types of
+ // deletions which can occur.
+ QMediaTimeRange a, b;
+
+ // Remove Single from Single
+ a = QMediaTimeRange(10, 30);
+ b = QMediaTimeRange(20, 40);
+
+ b.removeTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 31);
+ QVERIFY(b.latestTime() == 40);
+
+ // Remove Multiple from Single
+ a = QMediaTimeRange();
+ a.addInterval(10, 30);
+ a.addInterval(40, 60);
+
+ b = QMediaTimeRange(20, 50);
+
+ b.removeTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 31);
+ QVERIFY(b.latestTime() == 39);
+
+ // Remove Single from Multiple
+ a = QMediaTimeRange(20, 50);
+
+ b = QMediaTimeRange();
+ b.addInterval(10, 30);
+ b.addInterval(40, 60);
+
+ b.removeTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(!b.isContinuous());
+ QVERIFY(b.intervals().count() == 2);
+ QVERIFY(b.intervals()[0].start() == 10);
+ QVERIFY(b.intervals()[0].end() == 19);
+ QVERIFY(b.intervals()[1].start() == 51);
+ QVERIFY(b.intervals()[1].end() == 60);
+
+ // Remove Multiple from Multiple
+ a = QMediaTimeRange();
+ a.addInterval(20, 50);
+ a.addInterval(50, 90);
+
+
+ b = QMediaTimeRange();
+ b.addInterval(10, 30);
+ b.addInterval(40, 70);
+ b.addInterval(80, 100);
+
+ b.removeTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(!b.isContinuous());
+ QVERIFY(b.intervals().count() == 2);
+ QVERIFY(b.intervals()[0].start() == 10);
+ QVERIFY(b.intervals()[0].end() == 19);
+ QVERIFY(b.intervals()[1].start() == 91);
+ QVERIFY(b.intervals()[1].end() == 100);
+
+ // Remove Nothing from Single
+ a = QMediaTimeRange();
+ b = QMediaTimeRange(10, 20);
+
+ b.removeTimeRange(a);
+
+ QVERIFY(!b.isEmpty());
+ QVERIFY(b.isContinuous());
+ QVERIFY(b.earliestTime() == 10);
+ QVERIFY(b.latestTime() == 20);
+
+ // Remove Single from Nothing
+ a = QMediaTimeRange(10, 20);
+ b = QMediaTimeRange();
+
+ b.removeTimeRange(a);
+
+ QVERIFY(b.isEmpty());
+
+ // Remove Nothing from Nothing
+ a = QMediaTimeRange();
+ b = QMediaTimeRange();
+
+ b.removeTimeRange(a);
+
+ QVERIFY(b.isEmpty());
+}
+
+void tst_QMediaTimeRange::testClear()
+{
+ QMediaTimeRange x;
+
+ // Clear Nothing
+ x.clear();
+
+ QVERIFY(x.isEmpty());
+
+ // Clear Single
+ x = QMediaTimeRange(10, 20);
+ x.clear();
+
+ QVERIFY(x.isEmpty());
+
+ // Clear Multiple
+ x = QMediaTimeRange();
+ x.addInterval(10, 20);
+ x.addInterval(30, 40);
+ x.clear();
+
+ QVERIFY(x.isEmpty());
+}
+
+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));
+}
+
+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);
+}
+
+QTEST_MAIN(tst_QMediaTimeRange)
+
+#include "tst_qmediatimerange.moc"
diff --git a/tests/auto/qvideowidget/qvideowidget.pro b/tests/auto/qvideowidget/qvideowidget.pro
new file mode 100644
index 0000000..ca0fc24
--- /dev/null
+++ b/tests/auto/qvideowidget/qvideowidget.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES = tst_qvideowidget.cpp
+
+QT = core gui multimedia
+
diff --git a/tests/auto/qvideowidget/tst_qvideowidget.cpp b/tests/auto/qvideowidget/tst_qvideowidget.cpp
new file mode 100644
index 0000000..37676cf
--- /dev/null
+++ b/tests/auto/qvideowidget/tst_qvideowidget.cpp
@@ -0,0 +1,1595 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtMultimedia/qvideowidget.h>
+
+#include <QtMultimedia/qmediaobject.h>
+#include <QtMultimedia/qmediaservice.h>
+#include <QtMultimedia/private/qpaintervideosurface_p.h>
+#include <QtMultimedia/qvideooutputcontrol.h>
+#include <QtMultimedia/qvideowindowcontrol.h>
+#include <QtMultimedia/qvideowidgetcontrol.h>
+#include <QtMultimedia/qvideorenderercontrol.h>
+#include <QtMultimedia/qabstractvideosurface.h>
+#include <QtMultimedia/qvideosurfaceformat.h>
+
+#include <QtGui/qapplication.h>
+
+
+class tst_QVideoWidget : public QObject
+{
+ Q_OBJECT
+private slots:
+ void nullObject();
+ void nullService();
+ void nullOutputControl();
+ void noOutputs();
+ void serviceDestroyed();
+ void objectDestroyed();
+ void setMediaObject();
+
+ void showWindowControl();
+ void fullScreenWindowControl();
+ void aspectRatioWindowControl();
+ void sizeHintWindowControl_data() { sizeHint_data(); }
+ void sizeHintWindowControl();
+ void brightnessWindowControl_data() { color_data(); }
+ void brightnessWindowControl();
+ void contrastWindowControl_data() { color_data(); }
+ void contrastWindowControl();
+ void hueWindowControl_data() { color_data(); }
+ void hueWindowControl();
+ void saturationWindowControl_data() { color_data(); }
+ void saturationWindowControl();
+
+ void showWidgetControl();
+ void fullScreenWidgetControl();
+ void aspectRatioWidgetControl();
+ void sizeHintWidgetControl_data() { sizeHint_data(); }
+ void sizeHintWidgetControl();
+ void brightnessWidgetControl_data() { color_data(); }
+ void brightnessWidgetControl();
+ void contrastWidgetControl_data() { color_data(); }
+ void contrastWidgetControl();
+ void hueWidgetControl_data() { color_data(); }
+ void hueWidgetControl();
+ void saturationWidgetControl_data() { color_data(); }
+ void saturationWidgetControl();
+
+ void showRendererControl();
+ void fullScreenRendererControl();
+ void aspectRatioRendererControl();
+ void sizeHintRendererControl_data();
+ void sizeHintRendererControl();
+ void brightnessRendererControl_data() { color_data(); }
+ void brightnessRendererControl();
+ void contrastRendererControl_data() { color_data(); }
+ void contrastRendererControl();
+ void hueRendererControl_data() { color_data(); }
+ void hueRendererControl();
+ void saturationRendererControl_data() { color_data(); }
+ void saturationRendererControl();
+
+ void paintRendererControl();
+
+private:
+ void sizeHint_data();
+ void color_data();
+};
+
+Q_DECLARE_METATYPE(QVideoWidget::AspectRatioMode)
+Q_DECLARE_METATYPE(const uchar *)
+
+class QtTestOutputControl : public QVideoOutputControl
+{
+public:
+ QtTestOutputControl() : m_output(NoOutput) {}
+
+ QList<Output> availableOutputs() const { return m_outputs; }
+ void setAvailableOutputs(const QList<Output> outputs) { m_outputs = outputs; }
+
+ Output output() const { return m_output; }
+ virtual void setOutput(Output output) { m_output = output; }
+
+private:
+ Output m_output;
+ QList<Output> m_outputs;
+};
+
+class QtTestWindowControl : public QVideoWindowControl
+{
+public:
+ QtTestWindowControl()
+ : m_winId(0)
+ , m_repaintCount(0)
+ , m_brightness(0)
+ , m_contrast(0)
+ , m_saturation(0)
+ , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
+ , m_fullScreen(0)
+ {
+ }
+
+ WId winId() const { return m_winId; }
+ void setWinId(WId id) { m_winId = id; }
+
+ QRect displayRect() const { return m_displayRect; }
+ void setDisplayRect(const QRect &rect) { m_displayRect = rect; }
+
+ bool isFullScreen() const { return m_fullScreen; }
+ void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); }
+
+ int repaintCount() const { return m_repaintCount; }
+ void setRepaintCount(int count) { m_repaintCount = count; }
+ void repaint() { ++m_repaintCount; }
+
+ QSize nativeSize() const { return m_nativeSize; }
+ void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); }
+
+ QVideoWidget::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
+ void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) { m_aspectRatioMode = mode; }
+
+ int brightness() const { return m_brightness; }
+ void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
+
+ int contrast() const { return m_contrast; }
+ void setContrast(int contrast) { emit contrastChanged(m_contrast = contrast); }
+
+ int hue() const { return m_hue; }
+ void setHue(int hue) { emit hueChanged(m_hue = hue); }
+
+ int saturation() const { return m_saturation; }
+ void setSaturation(int saturation) { emit saturationChanged(m_saturation = saturation); }
+
+private:
+ WId m_winId;
+ int m_repaintCount;
+ int m_brightness;
+ int m_contrast;
+ int m_hue;
+ int m_saturation;
+ QVideoWidget::AspectRatioMode m_aspectRatioMode;
+ QRect m_displayRect;
+ QSize m_nativeSize;
+ bool m_fullScreen;
+};
+
+class QtTestWidgetControl : public QVideoWidgetControl
+{
+public:
+ QtTestWidgetControl()
+ : m_brightness(1.0)
+ , m_contrast(1.0)
+ , m_hue(1.0)
+ , m_saturation(1.0)
+ , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
+ , m_fullScreen(false)
+ {
+ }
+
+ bool isFullScreen() const { return m_fullScreen; }
+ void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); }
+
+ QVideoWidget::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
+ void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) { m_aspectRatioMode = mode; }
+
+ int brightness() const { return m_brightness; }
+ void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
+
+ int contrast() const { return m_contrast; }
+ void setContrast(int contrast) { emit contrastChanged(m_contrast = contrast); }
+
+ int hue() const { return m_hue; }
+ void setHue(int hue) { emit hueChanged(m_hue = hue); }
+
+ int saturation() const { return m_saturation; }
+ void setSaturation(int saturation) { emit saturationChanged(m_saturation = saturation); }
+
+ void setSizeHint(const QSize &size) { m_widget.setSizeHint(size); }
+
+ QWidget *videoWidget() { return &m_widget; }
+
+private:
+ class Widget : public QWidget
+ {
+ public:
+ QSize sizeHint() const { return m_sizeHint; }
+ void setSizeHint(const QSize &size) { m_sizeHint = size; updateGeometry(); }
+ private:
+ QSize m_sizeHint;
+ } m_widget;
+ int m_brightness;
+ int m_contrast;
+ int m_hue;
+ int m_saturation;
+ QVideoWidget::AspectRatioMode m_aspectRatioMode;
+ QSize m_sizeHint;
+ bool m_fullScreen;
+};
+
+class QtTestRendererControl : public QVideoRendererControl
+{
+public:
+ QtTestRendererControl()
+ : m_surface(0)
+ {
+ }
+
+ QAbstractVideoSurface *surface() const { return m_surface; }
+ void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; }
+
+private:
+ QAbstractVideoSurface *m_surface;
+};
+
+class QtTestVideoService : public QMediaService
+{
+ Q_OBJECT
+public:
+ QtTestVideoService(
+ QtTestOutputControl *output,
+ QtTestWindowControl *window,
+ QtTestWidgetControl *widget,
+ QtTestRendererControl *renderer)
+ : QMediaService(0)
+ , outputControl(output)
+ , windowControl(window)
+ , widgetControl(widget)
+ , rendererControl(renderer)
+ {
+ }
+
+ ~QtTestVideoService()
+ {
+ delete outputControl;
+ delete windowControl;
+ delete widgetControl;
+ delete rendererControl;
+ }
+
+ QMediaControl *control(const char *name) const
+ {
+ if (qstrcmp(name, QVideoOutputControl_iid) == 0)
+ return outputControl;
+ else if (qstrcmp(name, QVideoWindowControl_iid) == 0)
+ return windowControl;
+ else if (qstrcmp(name, QVideoWidgetControl_iid) == 0)
+ return widgetControl;
+ else if (qstrcmp(name, QVideoRendererControl_iid) == 0)
+ return rendererControl;
+ else
+ return 0;
+ }
+
+ QtTestOutputControl *outputControl;
+ QtTestWindowControl *windowControl;
+ QtTestWidgetControl *widgetControl;
+ QtTestRendererControl *rendererControl;
+};
+
+class QtTestVideoObject : public QMediaObject
+{
+ Q_OBJECT
+public:
+ QtTestVideoObject(
+ QtTestWindowControl *window,
+ QtTestWidgetControl *widget,
+ QtTestRendererControl *renderer):
+ QMediaObject(0, new QtTestVideoService(new QtTestOutputControl, window, widget, renderer))
+ {
+ testService = qobject_cast<QtTestVideoService*>(service());
+ QList<QVideoOutputControl::Output> outputs;
+
+ if (window)
+ outputs.append(QVideoOutputControl::WindowOutput);
+ if (widget)
+ outputs.append(QVideoOutputControl::WidgetOutput);
+ if (renderer)
+ outputs.append(QVideoOutputControl::RendererOutput);
+
+ testService->outputControl->setAvailableOutputs(outputs);
+ }
+
+ QtTestVideoObject(QtTestVideoService *service):
+ QMediaObject(0, service),
+ testService(service)
+ {
+ }
+
+ ~QtTestVideoObject()
+ {
+ delete testService;
+ }
+
+ QtTestVideoService *testService;
+};
+
+void tst_QVideoWidget::nullObject()
+{
+ QVideoWidget widget;
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), true);
+
+ widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+
+ {
+ QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
+
+ widget.setBrightness(100);
+ QCOMPARE(widget.brightness(), 100);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), 100);
+
+ widget.setBrightness(100);
+ QCOMPARE(widget.brightness(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ widget.setBrightness(-120);
+ QCOMPARE(widget.brightness(), -100);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), -100);
+ } {
+ QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
+
+ widget.setContrast(100);
+ QCOMPARE(widget.contrast(), 100);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), 100);
+
+ widget.setContrast(100);
+ QCOMPARE(widget.contrast(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ widget.setContrast(-120);
+ QCOMPARE(widget.contrast(), -100);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), -100);
+ } {
+ QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
+
+ widget.setHue(100);
+ QCOMPARE(widget.hue(), 100);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), 100);
+
+ widget.setHue(100);
+ QCOMPARE(widget.hue(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ widget.setHue(-120);
+ QCOMPARE(widget.hue(), -100);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), -100);
+ } {
+ QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
+
+ widget.setSaturation(100);
+ QCOMPARE(widget.saturation(), 100);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), 100);
+
+ widget.setSaturation(100);
+ QCOMPARE(widget.saturation(), 100);
+ QCOMPARE(spy.count(), 1);
+
+ widget.setSaturation(-120);
+ QCOMPARE(widget.saturation(), -100);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), -100);
+ }
+}
+
+void tst_QVideoWidget::nullService()
+{
+ QtTestVideoObject object(0);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), true);
+
+ widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+
+ widget.setBrightness(100);
+ QCOMPARE(widget.brightness(), 100);
+
+ widget.setContrast(100);
+ QCOMPARE(widget.contrast(), 100);
+
+ widget.setHue(100);
+ QCOMPARE(widget.hue(), 100);
+
+ widget.setSaturation(100);
+ QCOMPARE(widget.saturation(), 100);
+}
+
+void tst_QVideoWidget::nullOutputControl()
+{
+ QtTestVideoObject object(new QtTestVideoService(0, 0, 0, 0));
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), true);
+
+ widget.setBrightness(100);
+ QCOMPARE(widget.brightness(), 100);
+
+ widget.setContrast(100);
+ QCOMPARE(widget.contrast(), 100);
+
+ widget.setHue(100);
+ QCOMPARE(widget.hue(), 100);
+
+ widget.setSaturation(100);
+ QCOMPARE(widget.saturation(), 100);
+}
+
+void tst_QVideoWidget::noOutputs()
+{
+ QtTestVideoObject object(0, 0, 0);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ widget.setFullScreen(true);
+ QCOMPARE(widget.isFullScreen(), true);
+
+ widget.setBrightness(100);
+ QCOMPARE(widget.brightness(), 100);
+
+ widget.setContrast(100);
+ QCOMPARE(widget.contrast(), 100);
+
+ widget.setHue(100);
+ QCOMPARE(widget.hue(), 100);
+
+ widget.setSaturation(100);
+ QCOMPARE(widget.saturation(), 100);
+}
+
+void tst_QVideoWidget::serviceDestroyed()
+{
+ QtTestVideoObject object(new QtTestWindowControl, new QtTestWidgetControl, 0);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ widget.setBrightness(100);
+ widget.setContrast(100);
+ widget.setHue(100);
+ widget.setSaturation(100);
+
+ delete object.testService;
+ object.testService = 0;
+
+ QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&object));
+
+ QCOMPARE(widget.brightness(), 100);
+ QCOMPARE(widget.contrast(), 100);
+ QCOMPARE(widget.hue(), 100);
+ QCOMPARE(widget.saturation(), 100);
+
+ widget.setFullScreen(true);
+ QCOMPARE(widget.isFullScreen(), true);
+}
+
+void tst_QVideoWidget::objectDestroyed()
+{
+ QtTestVideoObject *object = new QtTestVideoObject(
+ new QtTestWindowControl,
+ new QtTestWidgetControl,
+ 0);
+
+ QVideoWidget widget;
+ widget.setMediaObject(object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ widget.setBrightness(100);
+ widget.setContrast(100);
+ widget.setHue(100);
+ widget.setSaturation(100);
+
+ // Delete the media object without deleting the service.
+ QtTestVideoService *service = object->testService;
+ object->testService = 0;
+
+ delete object;
+ object = 0;
+
+ QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(object));
+
+ QCOMPARE(service->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ QCOMPARE(widget.brightness(), 100);
+ QCOMPARE(widget.contrast(), 100);
+ QCOMPARE(widget.hue(), 100);
+ QCOMPARE(widget.saturation(), 100);
+
+ widget.setFullScreen(true);
+ QCOMPARE(widget.isFullScreen(), true);
+
+ delete service;
+}
+
+void tst_QVideoWidget::setMediaObject()
+{
+ QMediaObject *nullObject = 0;
+ QtTestVideoObject windowObject(new QtTestWindowControl, 0, 0);
+ QtTestVideoObject widgetObject(0, new QtTestWidgetControl, 0);
+ QtTestVideoObject rendererObject(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QCOMPARE(widget.mediaObject(), nullObject);
+ QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+ QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+ QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.setMediaObject(&windowObject);
+ QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&windowObject));
+ QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
+ QVERIFY(windowObject.testService->windowControl->winId() != 0);
+
+
+ widget.setMediaObject(&widgetObject);
+ QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&widgetObject));
+ QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
+
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+ QCOMPARE(widgetObject.testService->widgetControl->videoWidget()->isVisible(), true);
+
+ QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.setMediaObject(&rendererObject);
+ QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&rendererObject));
+ QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
+ QVERIFY(rendererObject.testService->rendererControl->surface() != 0);
+
+ QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.setMediaObject(0);
+ QCOMPARE(widget.mediaObject(), nullObject);
+
+ QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+}
+
+void tst_QVideoWidget::showWindowControl()
+{
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setNativeSize(QSize(240, 180));
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
+ QVERIFY(object.testService->windowControl->winId() != 0);
+
+ QVERIFY(object.testService->windowControl->repaintCount() > 0);
+
+ widget.resize(640, 480);
+ QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
+
+ widget.move(10, 10);
+ QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
+
+ widget.hide();
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+}
+
+void tst_QVideoWidget::showWidgetControl()
+{
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
+ QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), true);
+
+ widget.resize(640, 480);
+
+ widget.move(10, 10);
+
+ widget.hide();
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+ QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false);
+}
+
+void tst_QVideoWidget::showRendererControl()
+{
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
+ QVERIFY(object.testService->rendererControl->surface() != 0);
+
+ widget.resize(640, 480);
+
+ widget.move(10, 10);
+
+ widget.hide();
+
+ QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
+}
+
+void tst_QVideoWidget::aspectRatioWindowControl()
+{
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ // Test the aspect ratio defaults to keeping the aspect ratio.
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test the control has been informed of the aspect ratio change, post show.
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test an aspect ratio change is enforced immediately while visible.
+ widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+
+ // Test an aspect ratio set while not visible is respected.
+ widget.hide();
+ widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ widget.show();
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+}
+
+void tst_QVideoWidget::aspectRatioWidgetControl()
+{
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ object.testService->widgetControl->setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ // Test the aspect ratio defaults to keeping the aspect ratio.
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test the control has been informed of the aspect ratio change, post show.
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test an aspect ratio change is enforced immediately while visible.
+ widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+
+ // Test an aspect ratio set while not visible is respected.
+ widget.hide();
+ widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ widget.show();
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+}
+
+void tst_QVideoWidget::aspectRatioRendererControl()
+{
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ // Test the aspect ratio defaults to keeping the aspect ratio.
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test the control has been informed of the aspect ratio change, post show.
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+
+ // Test an aspect ratio change is enforced immediately while visible.
+ widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
+
+ // Test an aspect ratio set while not visible is respected.
+ widget.hide();
+ widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+ widget.show();
+ QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
+}
+
+void tst_QVideoWidget::sizeHint_data()
+{
+ QTest::addColumn<QSize>("size");
+
+ QTest::newRow("720x576")
+ << QSize(720, 576);
+}
+
+void tst_QVideoWidget::sizeHintWindowControl()
+{
+ QFETCH(QSize, size);
+
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ object.testService->windowControl->setNativeSize(size);
+ QCOMPARE(widget.sizeHint(), size);
+}
+
+void tst_QVideoWidget::sizeHintWidgetControl()
+{
+ QFETCH(QSize, size);
+
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QVERIFY(widget.sizeHint().isEmpty());
+
+ object.testService->widgetControl->setSizeHint(size);
+ QCOMPARE(widget.sizeHint(), size);
+}
+
+void tst_QVideoWidget::sizeHintRendererControl_data()
+{
+ QTest::addColumn<QSize>("frameSize");
+ QTest::addColumn<QRect>("viewport");
+ QTest::addColumn<QSize>("pixelAspectRatio");
+ QTest::addColumn<QSize>("expectedSize");
+
+ QTest::newRow("640x480")
+ << QSize(640, 480)
+ << QRect(0, 0, 640, 480)
+ << QSize(1, 1)
+ << QSize(640, 480);
+
+ QTest::newRow("800x600, (80,60, 640x480) viewport")
+ << QSize(800, 600)
+ << QRect(80, 60, 640, 480)
+ << QSize(1, 1)
+ << QSize(640, 480);
+
+ QTest::newRow("800x600, (80,60, 640x480) viewport, 4:3")
+ << QSize(800, 600)
+ << QRect(80, 60, 640, 480)
+ << QSize(4, 3)
+ << QSize(853, 480);
+
+}
+
+void tst_QVideoWidget::sizeHintRendererControl()
+{
+ QFETCH(QSize, frameSize);
+ QFETCH(QRect, viewport);
+ QFETCH(QSize, pixelAspectRatio);
+ QFETCH(QSize, expectedSize);
+
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32);
+ format.setViewport(viewport);
+ format.setPixelAspectRatio(pixelAspectRatio);
+
+ QVERIFY(object.testService->rendererControl->surface()->start(format));
+
+ QCOMPARE(widget.sizeHint(), expectedSize);
+}
+
+
+void tst_QVideoWidget::fullScreenWindowControl()
+{
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ Qt::WindowFlags windowFlags = widget.windowFlags();
+
+ QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool)));
+
+ // Test showing full screen with setFullScreen(true).
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toBool(), true);
+
+ // Test returning to normal with setFullScreen(false).
+ widget.setFullScreen(false);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test showing full screen with showFullScreen().
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.value(2).value(0).toBool(), true);
+
+ // Test returning to normal with showNormal().
+ widget.showNormal();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ QCOMPARE(spy.value(3).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false.
+ widget.setFullScreen(false);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ widget.showNormal();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+
+ // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true.
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ widget.setFullScreen(true);
+ QCOMPARE(object.testService->windowControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+ widget.showFullScreen();
+ QCOMPARE(object.testService->windowControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+
+ // Test if the window control exits full screen mode, the widget follows suit.
+ object.testService->windowControl->setFullScreen(false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 6);
+ QCOMPARE(spy.value(5).value(0).toBool(), false);
+
+ // Test if the window control enters full screen mode, the widget does nothing.
+ object.testService->windowControl->setFullScreen(false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 6);
+}
+
+void tst_QVideoWidget::fullScreenWidgetControl()
+{
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ Qt::WindowFlags windowFlags = widget.windowFlags();
+
+ QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool)));
+
+ // Test showing full screen with setFullScreen(true).
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toBool(), true);
+
+ // Test returning to normal with setFullScreen(false).
+ widget.setFullScreen(false);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test showing full screen with showFullScreen().
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.value(2).value(0).toBool(), true);
+
+ // Test returning to normal with showNormal().
+ widget.showNormal();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ QCOMPARE(spy.value(3).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false.
+ widget.setFullScreen(false);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ widget.showNormal();
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+
+ // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true.
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ widget.setFullScreen(true);
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+ widget.showFullScreen();
+ QCOMPARE(object.testService->widgetControl->isFullScreen(), true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+
+ // Test if the window control exits full screen mode, the widget follows suit.
+ object.testService->widgetControl->setFullScreen(false);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 6);
+ QCOMPARE(spy.value(5).value(0).toBool(), false);
+
+ // Test if the window control enters full screen mode, the widget does nothing.
+ object.testService->widgetControl->setFullScreen(false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 6);
+}
+
+
+void tst_QVideoWidget::fullScreenRendererControl()
+{
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ Qt::WindowFlags windowFlags = widget.windowFlags();
+
+ QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool)));
+
+ // Test showing full screen with setFullScreen(true).
+ widget.setFullScreen(true);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toBool(), true);
+
+ // Test returning to normal with setFullScreen(false).
+ widget.setFullScreen(false);
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test showing full screen with showFullScreen().
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.value(2).value(0).toBool(), true);
+
+ // Test returning to normal with showNormal().
+ widget.showNormal();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ QCOMPARE(spy.value(3).value(0).toBool(), false);
+ QCOMPARE(widget.windowFlags(), windowFlags);
+
+ // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false.
+ widget.setFullScreen(false);
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+ widget.showNormal();
+ QCOMPARE(widget.isFullScreen(), false);
+ QCOMPARE(spy.count(), 4);
+
+ // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true.
+ widget.showFullScreen();
+ QTest::qWaitForWindowShown(&widget);
+ widget.setFullScreen(true);
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+ widget.showFullScreen();
+ QCOMPARE(widget.isFullScreen(), true);
+ QCOMPARE(spy.count(), 5);
+}
+
+
+void tst_QVideoWidget::color_data()
+{
+ QTest::addColumn<int>("controlValue");
+ QTest::addColumn<int>("value");
+ QTest::addColumn<int>("expectedValue");
+
+ QTest::newRow("12")
+ << 0
+ << 12
+ << 12;
+ QTest::newRow("-56")
+ << 87
+ << -56
+ << -56;
+ QTest::newRow("100")
+ << 32
+ << 100
+ << 100;
+ QTest::newRow("1294")
+ << 0
+ << 1294
+ << 100;
+ QTest::newRow("-102")
+ << 34
+ << -102
+ << -100;
+}
+
+void tst_QVideoWidget::brightnessWindowControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setBrightness(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ // Test the video widget resets the controls starting brightness to the default.
+ QCOMPARE(widget.brightness(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
+
+ // Test the video widget sets the brightness value, bounded if necessary and emits a changed
+ // signal.
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(object.testService->windowControl->brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ // Test the changed signal isn't emitted if the value is unchanged.
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(object.testService->windowControl->brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ // Test the changed signal is emitted if the brightness is changed internally.
+ object.testService->windowControl->setBrightness(controlValue);
+ QCOMPARE(widget.brightness(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::brightnessWidgetControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ object.testService->widgetControl->setBrightness(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(widget.brightness(), 0);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
+
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->widgetControl->setBrightness(controlValue);
+ QCOMPARE(widget.brightness(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::brightnessRendererControl()
+{
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
+
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setBrightness(value);
+ QCOMPARE(widget.brightness(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QVideoWidget::contrastWindowControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setContrast(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(widget.contrast(), 0);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.contrast(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(object.testService->windowControl->contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(object.testService->windowControl->contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->windowControl->setContrast(controlValue);
+ QCOMPARE(widget.contrast(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::contrastWidgetControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ object.testService->widgetControl->setContrast(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ QCOMPARE(widget.contrast(), 0);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.contrast(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->widgetControl->setContrast(controlValue);
+ QCOMPARE(widget.contrast(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::contrastRendererControl()
+{
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setContrast(value);
+ QCOMPARE(widget.contrast(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QVideoWidget::hueWindowControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setHue(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ QCOMPARE(widget.hue(), 0);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.hue(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(object.testService->windowControl->hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(object.testService->windowControl->hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->windowControl->setHue(controlValue);
+ QCOMPARE(widget.hue(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::hueWidgetControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ object.testService->widgetControl->setHue(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ QCOMPARE(widget.hue(), 0);
+
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.hue(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->widgetControl->setHue(controlValue);
+ QCOMPARE(widget.hue(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::hueRendererControl()
+{
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setHue(value);
+ QCOMPARE(widget.hue(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+}
+
+void tst_QVideoWidget::saturationWindowControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(new QtTestWindowControl, 0, 0);
+ object.testService->windowControl->setSaturation(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ QCOMPARE(widget.saturation(), 0);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.saturation(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(object.testService->windowControl->saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(object.testService->windowControl->saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->windowControl->setSaturation(controlValue);
+ QCOMPARE(widget.saturation(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+}
+
+void tst_QVideoWidget::saturationWidgetControl()
+{
+ QFETCH(int, controlValue);
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, new QtTestWidgetControl, 0);
+ object.testService->widgetControl->setSaturation(controlValue);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+
+ QCOMPARE(widget.saturation(), 0);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QCOMPARE(widget.saturation(), 0);
+
+ QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(object.testService->widgetControl->saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+
+ object.testService->widgetControl->setSaturation(controlValue);
+ QCOMPARE(widget.saturation(), controlValue);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.value(1).value(0).toInt(), controlValue);
+
+}
+
+void tst_QVideoWidget::saturationRendererControl()
+{
+ QFETCH(int, value);
+ QFETCH(int, expectedValue);
+
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.value(0).value(0).toInt(), expectedValue);
+
+ widget.setSaturation(value);
+ QCOMPARE(widget.saturation(), expectedValue);
+ QCOMPARE(spy.count(), 1);
+}
+
+static const uchar rgb32ImageData[] =
+{
+ 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00
+};
+
+void tst_QVideoWidget::paintRendererControl()
+{
+ QtTestVideoObject object(0, 0, new QtTestRendererControl);
+
+ QVideoWidget widget;
+ widget.setMediaObject(&object);
+ widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+
+ QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>(
+ object.testService->rendererControl->surface());
+
+ QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32);
+
+ QVERIFY(surface->start(format));
+ QCOMPARE(surface->isActive(), true);
+ QCOMPARE(surface->isReady(), true);
+
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+
+ QCOMPARE(surface->isActive(), true);
+ QCOMPARE(surface->isReady(), true);
+
+ QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32);
+
+ frame.map(QAbstractVideoBuffer::WriteOnly);
+ memcpy(frame.bits(), rgb32ImageData, frame.mappedBytes());
+ frame.unmap();
+
+ QVERIFY(surface->present(frame));
+ QCOMPARE(surface->isActive(), true);
+ QCOMPARE(surface->isReady(), false);
+
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+
+ QCOMPARE(surface->isActive(), true);
+ QCOMPARE(surface->isReady(), true);
+}
+
+QTEST_MAIN(tst_QVideoWidget)
+
+#include "tst_qvideowidget.moc"
diff --git a/tests/auto/tests.xml b/tests/auto/tests.xml
index f197de0..96c3094 100644
--- a/tests/auto/tests.xml
+++ b/tests/auto/tests.xml
@@ -276,6 +276,17 @@
<Test name="qaudioformat" location="tests/auto/qaudioformat/tst_qaudioformat" />
<Test name="qaudiooutput" location="tests/auto/qaudiooutput/tst_qaudiooutput" />
<Test name="qaudioinput" location="tests/auto/qaudioinput/tst_qaudioinput" />
+ <Test name="qmediacontent" location="tests/auto/qmediacontent/tst_qmediacontent" />
+ <Test name="qmediaobject" location="tests/auto/qmediaobject/tst_qmediaobject" />
+ <Test name="qmediaplayer" location="tests/auto/qmediaplayer/tst_qmediaplayer" />
+ <Test name="qmediaplaylist" location="tests/auto/qmediaplaylist/tst_qmediaplaylist" />
+ <Test name="qmediaplaylistnavigator" location="tests/auto/qmediaplaylistnavigator/tst_qmediaplaylistnavigator" />
+ <Test name="qmediapluginloader" location="tests/auto/qmediapluginloader/tst_qmediapluginloader" />
+ <Test name="qmediaresource" location="tests/auto/qmediaresource/tst_qmediaresource" />
+ <Test name="qmediaservice" location="tests/auto/qmediaservice/tst_qmediaservice" />
+ <Test name="qmediaserviceprovider" location="tests/auto/qmedia/tst_qmediaserviceprovider" />
+ <Test name="qmediatimerange" location="tests/auto/qmediatimerange/tst_qmediatimerange" />
+ <Test name="qvideowidget" location="tests/auto/qvideowidget/tst_qvideowidget" />
<Test name="qsourcelocation" location="tests/auto/qsourcelocation/tst_qsourcelocation" />
<Test name="qspinbox" location="tests/auto/qspinbox/tst_qspinbox" />
<Test name="qsplitter" location="tests/auto/qsplitter/tst_qsplitter" />