| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | //TESTED_COMPONENT=src/multimedia |
| 30 | |
| 31 | #include <QtTest/QtTest> |
| 32 | #include <QtCore/qdebug.h> |
| 33 | #include <QtCore/qbuffer.h> |
| 34 | #include <QtNetwork/qnetworkconfiguration.h> |
| 35 | |
| 36 | #include <qgraphicsvideoitem.h> |
| 37 | #include <qabstractvideosurface.h> |
| 38 | #include <qmediaplayer.h> |
| 39 | #include <qmediaplayercontrol.h> |
| 40 | |
| 41 | #include "mockmediaserviceprovider.h" |
| 42 | #include "mockmediaplayerservice.h" |
| 43 | #include "mockvideosurface.h" |
| 44 | |
| 45 | QT_USE_NAMESPACE |
| 46 | |
| 47 | class tst_QMediaPlayerWidgets: public QObject |
| 48 | { |
| 49 | Q_OBJECT |
| 50 | |
| 51 | public slots: |
| 52 | void initTestCase(); |
| 53 | void cleanupTestCase(); |
| 54 | void init(); |
| 55 | void cleanup(); |
| 56 | |
| 57 | private slots: |
| 58 | void testSetVideoOutput(); |
| 59 | void testSetVideoOutputNoService(); |
| 60 | void testSetVideoOutputNoControl(); |
| 61 | |
| 62 | private: |
| 63 | MockMediaServiceProvider *provider; |
| 64 | MockMediaPlayerService *mockService; |
| 65 | }; |
| 66 | |
| 67 | void tst_QMediaPlayerWidgets::initTestCase() |
| 68 | { |
| 69 | provider = new MockMediaServiceProvider; |
| 70 | QMediaServiceProvider::setDefaultServiceProvider(provider); |
| 71 | } |
| 72 | |
| 73 | void tst_QMediaPlayerWidgets::cleanupTestCase() |
| 74 | { |
| 75 | delete provider; |
| 76 | } |
| 77 | |
| 78 | void tst_QMediaPlayerWidgets::init() |
| 79 | { |
| 80 | mockService = new MockMediaPlayerService; |
| 81 | provider->service = mockService; |
| 82 | } |
| 83 | |
| 84 | void tst_QMediaPlayerWidgets::cleanup() |
| 85 | { |
| 86 | } |
| 87 | |
| 88 | void tst_QMediaPlayerWidgets::testSetVideoOutput() |
| 89 | { |
| 90 | QVideoWidget widget; |
| 91 | QGraphicsVideoItem item; |
| 92 | MockVideoSurface surface; |
| 93 | |
| 94 | QMediaPlayer player; |
| 95 | |
| 96 | player.setVideoOutput(&widget); |
| 97 | QVERIFY(widget.mediaObject() == &player); |
| 98 | |
| 99 | player.setVideoOutput(&item); |
| 100 | QVERIFY(widget.mediaObject() == 0); |
| 101 | QVERIFY(item.mediaObject() == &player); |
| 102 | |
| 103 | player.setVideoOutput(reinterpret_cast<QVideoWidget *>(0)); |
| 104 | QVERIFY(item.mediaObject() == 0); |
| 105 | |
| 106 | player.setVideoOutput(&widget); |
| 107 | QVERIFY(widget.mediaObject() == &player); |
| 108 | |
| 109 | player.setVideoOutput(reinterpret_cast<QGraphicsVideoItem *>(0)); |
| 110 | QVERIFY(widget.mediaObject() == 0); |
| 111 | |
| 112 | player.setVideoOutput(&surface); |
| 113 | QVERIFY(mockService->rendererControl->surface() == &surface); |
| 114 | |
| 115 | player.setVideoOutput(reinterpret_cast<QAbstractVideoSurface *>(0)); |
| 116 | QVERIFY(mockService->rendererControl->surface() == 0); |
| 117 | |
| 118 | player.setVideoOutput(&surface); |
| 119 | QVERIFY(mockService->rendererControl->surface() == &surface); |
| 120 | |
| 121 | player.setVideoOutput(&widget); |
| 122 | QVERIFY(mockService->rendererControl->surface() == 0); |
| 123 | QVERIFY(widget.mediaObject() == &player); |
| 124 | |
| 125 | player.setVideoOutput(&surface); |
| 126 | QVERIFY(mockService->rendererControl->surface() == &surface); |
| 127 | QVERIFY(widget.mediaObject() == 0); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | void tst_QMediaPlayerWidgets::testSetVideoOutputNoService() |
| 132 | { |
| 133 | QVideoWidget widget; |
| 134 | QGraphicsVideoItem item; |
| 135 | MockVideoSurface surface; |
| 136 | |
| 137 | provider->service = 0; |
| 138 | QMediaPlayer player; |
| 139 | |
| 140 | player.setVideoOutput(&widget); |
| 141 | QVERIFY(widget.mediaObject() == 0); |
| 142 | |
| 143 | player.setVideoOutput(&item); |
| 144 | QVERIFY(item.mediaObject() == 0); |
| 145 | |
| 146 | player.setVideoOutput(&surface); |
| 147 | // Nothing we can verify here other than it doesn't assert. |
| 148 | } |
| 149 | |
| 150 | void tst_QMediaPlayerWidgets::testSetVideoOutputNoControl() |
| 151 | { |
| 152 | QVideoWidget widget; |
| 153 | QGraphicsVideoItem item; |
| 154 | MockVideoSurface surface; |
| 155 | |
| 156 | MockMediaPlayerService service; |
| 157 | service.rendererRef = 1; |
| 158 | service.windowRef = 1; |
| 159 | |
| 160 | provider->service = &service; |
| 161 | |
| 162 | QMediaPlayer player; |
| 163 | |
| 164 | player.setVideoOutput(&widget); |
| 165 | QVERIFY(widget.mediaObject() == 0); |
| 166 | |
| 167 | player.setVideoOutput(&item); |
| 168 | QVERIFY(item.mediaObject() == 0); |
| 169 | |
| 170 | player.setVideoOutput(&surface); |
| 171 | QVERIFY(service.rendererControl->surface() == 0); |
| 172 | } |
| 173 | |
| 174 | QTEST_MAIN(tst_QMediaPlayerWidgets) |
| 175 | #include "tst_qmediaplayerwidgets.moc" |
| 176 |
