| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #include <QtTest/QtTest> | 
| 30 | #include <QtNetwork/qnetworkrequest.h> | 
| 31 |  | 
| 32 | #include <qmediacontent.h> | 
| 33 | #include <qmediaplaylist.h> | 
| 34 |  | 
| 35 | //TESTED_COMPONENT=src/multimedia | 
| 36 |  | 
| 37 | QT_USE_NAMESPACE | 
| 38 | class tst_QMediaContent : public QObject | 
| 39 | { | 
| 40 |     Q_OBJECT | 
| 41 |  | 
| 42 | private slots: | 
| 43 |     void testNull(); | 
| 44 |     void testUrlCtor(); | 
| 45 |     void testRequestCtor(); | 
| 46 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 47 |     void testResourceCtor(); | 
| 48 |     void testResourceListCtor(); | 
| 49 | #endif | 
| 50 |     void testCopy(); | 
| 51 |     void testAssignment(); | 
| 52 |     void testEquality(); | 
| 53 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 54 |     void testResources(); | 
| 55 | #endif | 
| 56 |     void testPlaylist(); | 
| 57 | }; | 
| 58 |  | 
| 59 | void tst_QMediaContent::testNull() | 
| 60 | { | 
| 61 |     QMediaContent media; | 
| 62 |  | 
| 63 |     QCOMPARE(media.isNull(), true); | 
| 64 |     QCOMPARE(media.request().url(), QUrl()); | 
| 65 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 66 |     QCOMPARE(media.canonicalUrl(), QUrl()); | 
| 67 |     QCOMPARE(media.canonicalResource(), QMediaResource()); | 
| 68 |     QCOMPARE(media.resources(), QMediaResourceList()); | 
| 69 | #endif | 
| 70 | } | 
| 71 |  | 
| 72 | void tst_QMediaContent::testUrlCtor() | 
| 73 | { | 
| 74 |     QMediaContent media(QUrl("http://example.com/movie.mov" )); | 
| 75 |     QCOMPARE(media.request().url(), QUrl("http://example.com/movie.mov" )); | 
| 76 |  | 
| 77 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 78 |     QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov" )); | 
| 79 |     QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov" )); | 
| 80 | #endif | 
| 81 | } | 
| 82 |  | 
| 83 | void tst_QMediaContent::testRequestCtor() | 
| 84 | { | 
| 85 |     QNetworkRequest request(QUrl("http://example.com/movie.mov" )); | 
| 86 |     request.setAttribute(code: QNetworkRequest::User, value: QVariant(1234)); | 
| 87 |  | 
| 88 |     QMediaContent media(request); | 
| 89 |     QCOMPARE(media.request().url(), QUrl("http://example.com/movie.mov" )); | 
| 90 |     QCOMPARE(media.request(), request); | 
| 91 |  | 
| 92 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 93 |     QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov" )); | 
| 94 |     QCOMPARE(media.canonicalRequest(),request); | 
| 95 |     QCOMPARE(media.canonicalResource().request(), request); | 
| 96 |     QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov" )); | 
| 97 | #endif | 
| 98 | } | 
| 99 |  | 
| 100 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 101 | void tst_QMediaContent::testResourceCtor() | 
| 102 | { | 
| 103 |     QMediaContent media(QMediaResource(QUrl("http://example.com/movie.mov" ))); | 
| 104 |  | 
| 105 |     QCOMPARE(media.canonicalResource(), QMediaResource(QUrl("http://example.com/movie.mov" ))); | 
| 106 | } | 
| 107 |  | 
| 108 | void tst_QMediaContent::testResourceListCtor() | 
| 109 | { | 
| 110 |     QMediaResourceList  resourceList; | 
| 111 |     resourceList << QMediaResource(QUrl("http://example.com/movie.mov" )); | 
| 112 |  | 
| 113 |     QMediaContent media(resourceList); | 
| 114 |  | 
| 115 |     QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov" )); | 
| 116 |     QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov" )); | 
| 117 | } | 
| 118 | #endif | 
| 119 |  | 
| 120 | void tst_QMediaContent::testCopy() | 
| 121 | { | 
| 122 |     QMediaContent media1(QUrl("http://example.com/movie.mov" )); | 
| 123 |     QMediaContent media2(media1); | 
| 124 |  | 
| 125 |     QVERIFY(media1 == media2); | 
| 126 | } | 
| 127 |  | 
| 128 | void tst_QMediaContent::testAssignment() | 
| 129 | { | 
| 130 |     QMediaContent media1(QUrl("http://example.com/movie.mov" )); | 
| 131 |     QMediaContent media2; | 
| 132 |     QMediaContent media3; | 
| 133 |  | 
| 134 |     media2 = media1; | 
| 135 |     QVERIFY(media2 == media1); | 
| 136 |  | 
| 137 |     media2 = media3; | 
| 138 |     QVERIFY(media2 == media3); | 
| 139 | } | 
| 140 |  | 
| 141 | void tst_QMediaContent::testEquality() | 
| 142 | { | 
| 143 |     QMediaContent media1; | 
| 144 |     QMediaContent media2; | 
| 145 |     QMediaContent media3(QUrl("http://example.com/movie.mov" )); | 
| 146 |     QMediaContent media4(QUrl("http://example.com/movie.mov" )); | 
| 147 |     QMediaContent media5(QUrl("file:///some/where/over/the/rainbow.mp3" )); | 
| 148 |  | 
| 149 |     // null == null | 
| 150 |     QCOMPARE(media1 == media2, true); | 
| 151 |     QCOMPARE(media1 != media2, false); | 
| 152 |  | 
| 153 |     // null != something | 
| 154 |     QCOMPARE(media1 == media3, false); | 
| 155 |     QCOMPARE(media1 != media3, true); | 
| 156 |  | 
| 157 |     // equiv | 
| 158 |     QCOMPARE(media3 == media4, true); | 
| 159 |     QCOMPARE(media3 != media4, false); | 
| 160 |  | 
| 161 |     // not equiv | 
| 162 |     QCOMPARE(media4 == media5, false); | 
| 163 |     QCOMPARE(media4 != media5, true); | 
| 164 | } | 
| 165 |  | 
| 166 | #if QT_DEPRECATED_SINCE(6, 0) | 
| 167 | void tst_QMediaContent::testResources() | 
| 168 | { | 
| 169 |     QMediaResourceList  resourceList; | 
| 170 |  | 
| 171 |     resourceList << QMediaResource(QUrl("http://example.com/movie-main.mov" )); | 
| 172 |     resourceList << QMediaResource(QUrl("http://example.com/movie-big.mov" )); | 
| 173 |     QMediaContent    media(resourceList); | 
| 174 |  | 
| 175 |     QMediaResourceList  res = media.resources(); | 
| 176 |     QCOMPARE(res.size(), 2); | 
| 177 |     QCOMPARE(res[0], QMediaResource(QUrl("http://example.com/movie-main.mov" ))); | 
| 178 |     QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov" ))); | 
| 179 | } | 
| 180 | #endif | 
| 181 |  | 
| 182 | void tst_QMediaContent::testPlaylist() | 
| 183 | { | 
| 184 |     QMediaContent media(QUrl("http://example.com/movie.mov" )); | 
| 185 |     QVERIFY(media.request().url().isValid()); | 
| 186 |     QVERIFY(!media.playlist()); | 
| 187 |  | 
| 188 |     { | 
| 189 |         QPointer<QMediaPlaylist> playlist(new QMediaPlaylist); | 
| 190 |         media = QMediaContent(playlist.data(), QUrl("http://example.com/sample.m3u" ), true); | 
| 191 |         QVERIFY(media.request().url().isValid()); | 
| 192 |         QCOMPARE(media.playlist(), playlist.data()); | 
| 193 |         media = QMediaContent(); | 
| 194 |         // Make sure playlist is destroyed by QMediaContent | 
| 195 |         QTRY_VERIFY(!playlist); | 
| 196 |     } | 
| 197 |  | 
| 198 |     { | 
| 199 |         QMediaPlaylist *playlist = new QMediaPlaylist; | 
| 200 |         media = QMediaContent(playlist, QUrl("http://example.com/sample.m3u" ), true); | 
| 201 |         // Delete playlist outside QMediaContent | 
| 202 |         delete playlist; | 
| 203 |         QVERIFY(!media.playlist()); | 
| 204 |         media = QMediaContent(); | 
| 205 |     } | 
| 206 |  | 
| 207 |     { | 
| 208 |         QPointer<QMediaPlaylist> playlist(new QMediaPlaylist); | 
| 209 |         media = QMediaContent(playlist.data(), QUrl(), false); | 
| 210 |         QVERIFY(!media.request().url().isValid()); | 
| 211 |         QCOMPARE(media.playlist(), playlist.data()); | 
| 212 |         media = QMediaContent(); | 
| 213 |         QVERIFY(playlist); | 
| 214 |         delete playlist.data(); | 
| 215 |     } | 
| 216 | } | 
| 217 |  | 
| 218 | QTEST_MAIN(tst_QMediaContent) | 
| 219 |  | 
| 220 | #include "tst_qmediacontent.moc" | 
| 221 |  |