| 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 | //TESTED_COMPONENT=src/multimedia |
| 30 | |
| 31 | #include <QtTest/QtTest> |
| 32 | |
| 33 | #include "qmediaresource.h" |
| 34 | |
| 35 | QT_USE_NAMESPACE |
| 36 | class tst_QMediaResource : public QObject |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | private slots: |
| 40 | #if QT_DEPRECATED_SINCE(6, 0) |
| 41 | void constructNull(); |
| 42 | void construct_data(); |
| 43 | void construct(); |
| 44 | void setResolution(); |
| 45 | void equality(); |
| 46 | void copy(); |
| 47 | void assign(); |
| 48 | |
| 49 | void constructorRequest(); |
| 50 | void copyConstructor(); |
| 51 | #else |
| 52 | void initTestCase() |
| 53 | { |
| 54 | QSKIP("Skipping this test, QMediaResource is deprecated." ); |
| 55 | } |
| 56 | #endif |
| 57 | }; |
| 58 | |
| 59 | #if QT_DEPRECATED_SINCE(6, 0) |
| 60 | void tst_QMediaResource::constructNull() |
| 61 | { |
| 62 | QMediaResource resource; |
| 63 | |
| 64 | QCOMPARE(resource.isNull(), true); |
| 65 | QCOMPARE(resource.url(), QUrl()); |
| 66 | QCOMPARE(resource.request(), QNetworkRequest()); |
| 67 | QCOMPARE(resource.mimeType(), QString()); |
| 68 | QCOMPARE(resource.language(), QString()); |
| 69 | QCOMPARE(resource.audioCodec(), QString()); |
| 70 | QCOMPARE(resource.videoCodec(), QString()); |
| 71 | QCOMPARE(resource.dataSize(), qint64(0)); |
| 72 | QCOMPARE(resource.audioBitRate(), 0); |
| 73 | QCOMPARE(resource.sampleRate(), 0); |
| 74 | QCOMPARE(resource.channelCount(), 0); |
| 75 | QCOMPARE(resource.videoBitRate(), 0); |
| 76 | QCOMPARE(resource.resolution(), QSize()); |
| 77 | } |
| 78 | |
| 79 | void tst_QMediaResource::construct_data() |
| 80 | { |
| 81 | QTest::addColumn<QUrl>(name: "url" ); |
| 82 | QTest::addColumn<QNetworkRequest>(name: "request" ); |
| 83 | QTest::addColumn<QString>(name: "mimeType" ); |
| 84 | QTest::addColumn<QString>(name: "language" ); |
| 85 | QTest::addColumn<QString>(name: "audioCodec" ); |
| 86 | QTest::addColumn<QString>(name: "videoCodec" ); |
| 87 | QTest::addColumn<qint64>(name: "dataSize" ); |
| 88 | QTest::addColumn<int>(name: "audioBitRate" ); |
| 89 | QTest::addColumn<int>(name: "sampleRate" ); |
| 90 | QTest::addColumn<int>(name: "channelCount" ); |
| 91 | QTest::addColumn<int>(name: "videoBitRate" ); |
| 92 | QTest::addColumn<QSize>(name: "resolution" ); |
| 93 | |
| 94 | QTest::newRow(dataTag: "audio content" ) |
| 95 | << QUrl(QString::fromLatin1(str: "http:://test.com/test.mp3" )) |
| 96 | << QNetworkRequest(QUrl(QString::fromLatin1(str: "http:://test.com/test.mp3" ))) |
| 97 | << QString::fromLatin1(str: "audio/mpeg" ) |
| 98 | << QString::fromLatin1(str: "eng" ) |
| 99 | << QString::fromLatin1(str: "mp3" ) |
| 100 | << QString() |
| 101 | << qint64(5465433) |
| 102 | << 128000 |
| 103 | << 44100 |
| 104 | << 2 |
| 105 | << 0 |
| 106 | << QSize(); |
| 107 | QTest::newRow(dataTag: "image content" ) |
| 108 | << QUrl(QString::fromLatin1(str: "http:://test.com/test.jpg" )) |
| 109 | << QNetworkRequest(QUrl(QString::fromLatin1(str: "http:://test.com/test.jpg" ))) |
| 110 | << QString::fromLatin1(str: "image/jpeg" ) |
| 111 | << QString() |
| 112 | << QString() |
| 113 | << QString() |
| 114 | << qint64(23600) |
| 115 | << 0 |
| 116 | << 0 |
| 117 | << 0 |
| 118 | << 0 |
| 119 | << QSize(640, 480); |
| 120 | QTest::newRow(dataTag: "video content" ) |
| 121 | << QUrl(QString::fromLatin1(str: "http:://test.com/test.mp4" )) |
| 122 | << QNetworkRequest(QUrl(QString::fromLatin1(str: "http:://test.com/test.mp4" ))) |
| 123 | << QString::fromLatin1(str: "video/mp4" ) |
| 124 | << QString() |
| 125 | << QString::fromLatin1(str: "aac" ) |
| 126 | << QString::fromLatin1(str: "h264" ) |
| 127 | << qint64(36245851) |
| 128 | << 96000 |
| 129 | << 44000 |
| 130 | << 5 |
| 131 | << 750000 |
| 132 | << QSize(720, 576); |
| 133 | QTest::newRow(dataTag: "thumbnail" ) |
| 134 | << QUrl(QString::fromLatin1(str: "file::///thumbs/test.png" )) |
| 135 | << QNetworkRequest(QUrl(QString::fromLatin1(str: "file::///thumbs/test.png" ))) |
| 136 | << QString::fromLatin1(str: "image/png" ) |
| 137 | << QString() |
| 138 | << QString() |
| 139 | << QString() |
| 140 | << qint64(2360) |
| 141 | << 0 |
| 142 | << 0 |
| 143 | << 0 |
| 144 | << 0 |
| 145 | << QSize(128, 128); |
| 146 | } |
| 147 | |
| 148 | void tst_QMediaResource::construct() |
| 149 | { |
| 150 | QFETCH(QUrl, url); |
| 151 | QFETCH(QNetworkRequest, request); |
| 152 | QFETCH(QString, mimeType); |
| 153 | QFETCH(QString, language); |
| 154 | QFETCH(QString, audioCodec); |
| 155 | QFETCH(QString, videoCodec); |
| 156 | QFETCH(qint64, dataSize); |
| 157 | QFETCH(int, audioBitRate); |
| 158 | QFETCH(int, sampleRate); |
| 159 | QFETCH(int, channelCount); |
| 160 | QFETCH(int, videoBitRate); |
| 161 | QFETCH(QSize, resolution); |
| 162 | |
| 163 | { |
| 164 | QMediaResource resource(url); |
| 165 | |
| 166 | QCOMPARE(resource.isNull(), false); |
| 167 | QCOMPARE(resource.url(), url); |
| 168 | QCOMPARE(resource.mimeType(), QString()); |
| 169 | QCOMPARE(resource.language(), QString()); |
| 170 | QCOMPARE(resource.audioCodec(), QString()); |
| 171 | QCOMPARE(resource.videoCodec(), QString()); |
| 172 | QCOMPARE(resource.dataSize(), qint64(0)); |
| 173 | QCOMPARE(resource.audioBitRate(), 0); |
| 174 | QCOMPARE(resource.sampleRate(), 0); |
| 175 | QCOMPARE(resource.channelCount(), 0); |
| 176 | QCOMPARE(resource.videoBitRate(), 0); |
| 177 | QCOMPARE(resource.resolution(), QSize()); |
| 178 | } |
| 179 | { |
| 180 | QMediaResource resource(url, mimeType); |
| 181 | |
| 182 | QCOMPARE(resource.isNull(), false); |
| 183 | QCOMPARE(resource.url(), url); |
| 184 | QCOMPARE(resource.request(), request); |
| 185 | QCOMPARE(resource.mimeType(), mimeType); |
| 186 | QCOMPARE(resource.language(), QString()); |
| 187 | QCOMPARE(resource.audioCodec(), QString()); |
| 188 | QCOMPARE(resource.videoCodec(), QString()); |
| 189 | QCOMPARE(resource.dataSize(), qint64(0)); |
| 190 | QCOMPARE(resource.audioBitRate(), 0); |
| 191 | QCOMPARE(resource.sampleRate(), 0); |
| 192 | QCOMPARE(resource.channelCount(), 0); |
| 193 | QCOMPARE(resource.videoBitRate(), 0); |
| 194 | QCOMPARE(resource.resolution(), QSize()); |
| 195 | |
| 196 | resource.setLanguage(language); |
| 197 | resource.setAudioCodec(audioCodec); |
| 198 | resource.setVideoCodec(videoCodec); |
| 199 | resource.setDataSize(dataSize); |
| 200 | resource.setAudioBitRate(audioBitRate); |
| 201 | resource.setSampleRate(sampleRate); |
| 202 | resource.setChannelCount(channelCount); |
| 203 | resource.setVideoBitRate(videoBitRate); |
| 204 | resource.setResolution(resolution); |
| 205 | |
| 206 | QCOMPARE(resource.language(), language); |
| 207 | QCOMPARE(resource.audioCodec(), audioCodec); |
| 208 | QCOMPARE(resource.videoCodec(), videoCodec); |
| 209 | QCOMPARE(resource.dataSize(), dataSize); |
| 210 | QCOMPARE(resource.audioBitRate(), audioBitRate); |
| 211 | QCOMPARE(resource.sampleRate(), sampleRate); |
| 212 | QCOMPARE(resource.channelCount(), channelCount); |
| 213 | QCOMPARE(resource.videoBitRate(), videoBitRate); |
| 214 | QCOMPARE(resource.resolution(), resolution); |
| 215 | } |
| 216 | { |
| 217 | QMediaResource resource(request, mimeType); |
| 218 | |
| 219 | QCOMPARE(resource.isNull(), false); |
| 220 | QCOMPARE(resource.url(), url); |
| 221 | QCOMPARE(resource.request(), request); |
| 222 | QCOMPARE(resource.mimeType(), mimeType); |
| 223 | QCOMPARE(resource.language(), QString()); |
| 224 | QCOMPARE(resource.audioCodec(), QString()); |
| 225 | QCOMPARE(resource.videoCodec(), QString()); |
| 226 | QCOMPARE(resource.dataSize(), qint64(0)); |
| 227 | QCOMPARE(resource.audioBitRate(), 0); |
| 228 | QCOMPARE(resource.sampleRate(), 0); |
| 229 | QCOMPARE(resource.channelCount(), 0); |
| 230 | QCOMPARE(resource.videoBitRate(), 0); |
| 231 | QCOMPARE(resource.resolution(), QSize()); |
| 232 | |
| 233 | resource.setLanguage(language); |
| 234 | resource.setAudioCodec(audioCodec); |
| 235 | resource.setVideoCodec(videoCodec); |
| 236 | resource.setDataSize(dataSize); |
| 237 | resource.setAudioBitRate(audioBitRate); |
| 238 | resource.setSampleRate(sampleRate); |
| 239 | resource.setChannelCount(channelCount); |
| 240 | resource.setVideoBitRate(videoBitRate); |
| 241 | resource.setResolution(resolution); |
| 242 | |
| 243 | QCOMPARE(resource.language(), language); |
| 244 | QCOMPARE(resource.audioCodec(), audioCodec); |
| 245 | QCOMPARE(resource.videoCodec(), videoCodec); |
| 246 | QCOMPARE(resource.dataSize(), dataSize); |
| 247 | QCOMPARE(resource.audioBitRate(), audioBitRate); |
| 248 | QCOMPARE(resource.sampleRate(), sampleRate); |
| 249 | QCOMPARE(resource.channelCount(), channelCount); |
| 250 | QCOMPARE(resource.videoBitRate(), videoBitRate); |
| 251 | QCOMPARE(resource.resolution(), resolution); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void tst_QMediaResource::setResolution() |
| 256 | { |
| 257 | QMediaResource resource( |
| 258 | QUrl(QString::fromLatin1(str: "file::///thumbs/test.png" )), |
| 259 | QString::fromLatin1(str: "image/png" )); |
| 260 | |
| 261 | QCOMPARE(resource.resolution(), QSize()); |
| 262 | |
| 263 | resource.setResolution(QSize(120, 80)); |
| 264 | QCOMPARE(resource.resolution(), QSize(120, 80)); |
| 265 | |
| 266 | resource.setResolution(QSize(-1, 23)); |
| 267 | QCOMPARE(resource.resolution(), QSize(-1, 23)); |
| 268 | |
| 269 | resource.setResolution(QSize(-43, 34)); |
| 270 | QCOMPARE(resource.resolution(), QSize(-43, 34)); |
| 271 | |
| 272 | resource.setResolution(QSize(64, -1)); |
| 273 | QCOMPARE(resource.resolution(), QSize(64, -1)); |
| 274 | |
| 275 | resource.setResolution(QSize(64, -83)); |
| 276 | QCOMPARE(resource.resolution(), QSize(64, -83)); |
| 277 | |
| 278 | resource.setResolution(QSize(-12, -83)); |
| 279 | QCOMPARE(resource.resolution(), QSize(-12, -83)); |
| 280 | |
| 281 | resource.setResolution(QSize()); |
| 282 | QCOMPARE(resource.resolution(), QSize(-1, -1)); |
| 283 | |
| 284 | resource.setResolution(width: 120, height: 80); |
| 285 | QCOMPARE(resource.resolution(), QSize(120, 80)); |
| 286 | |
| 287 | resource.setResolution(width: -1, height: 23); |
| 288 | QCOMPARE(resource.resolution(), QSize(-1, 23)); |
| 289 | |
| 290 | resource.setResolution(width: -43, height: 34); |
| 291 | QCOMPARE(resource.resolution(), QSize(-43, 34)); |
| 292 | |
| 293 | resource.setResolution(width: 64, height: -1); |
| 294 | QCOMPARE(resource.resolution(), QSize(64, -1)); |
| 295 | |
| 296 | resource.setResolution(width: 64, height: -83); |
| 297 | QCOMPARE(resource.resolution(), QSize(64, -83)); |
| 298 | |
| 299 | resource.setResolution(width: -12, height: -83); |
| 300 | QCOMPARE(resource.resolution(), QSize(-12, -83)); |
| 301 | |
| 302 | resource.setResolution(width: -1, height: -1); |
| 303 | QCOMPARE(resource.resolution(), QSize()); |
| 304 | } |
| 305 | |
| 306 | void tst_QMediaResource::equality() |
| 307 | { |
| 308 | QMediaResource resource1( |
| 309 | QUrl(QString::fromLatin1(str: "http://test.com/test.mp4" )), |
| 310 | QString::fromLatin1(str: "video/mp4" )); |
| 311 | QMediaResource resource2( |
| 312 | QUrl(QString::fromLatin1(str: "http://test.com/test.mp4" )), |
| 313 | QString::fromLatin1(str: "video/mp4" )); |
| 314 | QMediaResource resource3( |
| 315 | QUrl(QString::fromLatin1(str: "file:///thumbs/test.jpg" ))); |
| 316 | QMediaResource resource4( |
| 317 | QUrl(QString::fromLatin1(str: "file:///thumbs/test.jpg" ))); |
| 318 | QMediaResource resource5( |
| 319 | QUrl(QString::fromLatin1(str: "http://test.com/test.mp3" )), |
| 320 | QString::fromLatin1(str: "audio/mpeg" )); |
| 321 | |
| 322 | QNetworkRequest request(QUrl("http://test.com/test.mp3" )); |
| 323 | QString requestMimeType("audio/mp3" ); |
| 324 | |
| 325 | QMediaResource requestResource1(request, requestMimeType); |
| 326 | QMediaResource requestResource2(request, requestMimeType); |
| 327 | |
| 328 | QCOMPARE(requestResource1 == requestResource2, true); |
| 329 | QCOMPARE(requestResource1 != requestResource2, false); |
| 330 | QCOMPARE(requestResource1 != resource5, true); |
| 331 | |
| 332 | QCOMPARE(resource1 == resource2, true); |
| 333 | QCOMPARE(resource1 != resource2, false); |
| 334 | |
| 335 | QCOMPARE(resource3 == resource4, true); |
| 336 | QCOMPARE(resource3 != resource4, false); |
| 337 | |
| 338 | QCOMPARE(resource1 == resource3, false); |
| 339 | QCOMPARE(resource1 != resource3, true); |
| 340 | |
| 341 | QCOMPARE(resource1 == resource5, false); |
| 342 | QCOMPARE(resource1 != resource5, true); |
| 343 | |
| 344 | resource1.setAudioCodec(QString::fromLatin1(str: "mp3" )); |
| 345 | resource2.setAudioCodec(QString::fromLatin1(str: "aac" )); |
| 346 | |
| 347 | // Not equal differing audio codecs. |
| 348 | QCOMPARE(resource1 == resource2, false); |
| 349 | QCOMPARE(resource1 != resource2, true); |
| 350 | |
| 351 | resource1.setAudioCodec(QString::fromLatin1(str: "aac" )); |
| 352 | |
| 353 | // Equal. |
| 354 | QCOMPARE(resource1 == resource2, true); |
| 355 | QCOMPARE(resource1 != resource2, false); |
| 356 | |
| 357 | resource1.setVideoCodec(QString()); |
| 358 | |
| 359 | // Equal. |
| 360 | QCOMPARE(resource1 == resource2, true); |
| 361 | QCOMPARE(resource1 != resource2, false); |
| 362 | |
| 363 | resource1.setVideoCodec(QString::fromLatin1(str: "h264" )); |
| 364 | |
| 365 | // Not equal differing video codecs. |
| 366 | QCOMPARE(resource1 == resource2, false); |
| 367 | QCOMPARE(resource1 != resource2, true); |
| 368 | |
| 369 | resource2.setVideoCodec(QString::fromLatin1(str: "h264" )); |
| 370 | |
| 371 | // Equal. |
| 372 | QCOMPARE(resource1 == resource2, true); |
| 373 | QCOMPARE(resource1 != resource2, false); |
| 374 | |
| 375 | resource2.setDataSize(0); |
| 376 | |
| 377 | // Equal. |
| 378 | QCOMPARE(resource1 == resource2, true); |
| 379 | QCOMPARE(resource1 != resource2, false); |
| 380 | |
| 381 | resource1.setDataSize(546423); |
| 382 | |
| 383 | // Not equal differing video codecs. |
| 384 | QCOMPARE(resource1 == resource2, false); |
| 385 | QCOMPARE(resource1 != resource2, true); |
| 386 | |
| 387 | resource2.setDataSize(546423); |
| 388 | |
| 389 | // Equal. |
| 390 | QCOMPARE(resource1 == resource2, true); |
| 391 | QCOMPARE(resource1 != resource2, false); |
| 392 | |
| 393 | resource1.setAudioBitRate(96000); |
| 394 | resource1.setSampleRate(48000); |
| 395 | resource2.setSampleRate(44100); |
| 396 | resource1.setChannelCount(0); |
| 397 | resource1.setVideoBitRate(900000); |
| 398 | resource2.setLanguage(QString::fromLatin1(str: "eng" )); |
| 399 | |
| 400 | // Not equal, audio bit rate, sample rate, video bit rate, and |
| 401 | // language. |
| 402 | QCOMPARE(resource1 == resource2, false); |
| 403 | QCOMPARE(resource1 != resource2, true); |
| 404 | |
| 405 | resource2.setAudioBitRate(96000); |
| 406 | resource1.setSampleRate(44100); |
| 407 | |
| 408 | // Not equal, differing video bit rate, and language. |
| 409 | QCOMPARE(resource1 == resource2, false); |
| 410 | QCOMPARE(resource1 != resource2, true); |
| 411 | |
| 412 | resource2.setVideoBitRate(900000); |
| 413 | resource1.setLanguage(QString::fromLatin1(str: "eng" )); |
| 414 | |
| 415 | // Equal |
| 416 | QCOMPARE(resource1 == resource2, true); |
| 417 | QCOMPARE(resource1 != resource2, false); |
| 418 | |
| 419 | resource1.setResolution(QSize()); |
| 420 | |
| 421 | // Equal |
| 422 | QCOMPARE(resource1 == resource2, true); |
| 423 | QCOMPARE(resource1 != resource2, false); |
| 424 | |
| 425 | resource2.setResolution(width: -1, height: -1); |
| 426 | |
| 427 | // Equal |
| 428 | QCOMPARE(resource1 == resource2, true); |
| 429 | QCOMPARE(resource1 != resource2, false); |
| 430 | |
| 431 | resource1.setResolution(QSize(-640, -480)); |
| 432 | |
| 433 | // Not equal, differing resolution. |
| 434 | QCOMPARE(resource1 == resource2, false); |
| 435 | QCOMPARE(resource1 != resource2, true); |
| 436 | resource1.setResolution(QSize(640, 480)); |
| 437 | resource2.setResolution(QSize(800, 600)); |
| 438 | |
| 439 | // Not equal, differing resolution. |
| 440 | QCOMPARE(resource1 == resource2, false); |
| 441 | QCOMPARE(resource1 != resource2, true); |
| 442 | |
| 443 | resource1.setResolution(width: 800, height: 600); |
| 444 | |
| 445 | // Equal |
| 446 | QCOMPARE(resource1 == resource2, true); |
| 447 | QCOMPARE(resource1 != resource2, false); |
| 448 | |
| 449 | /* equality tests for constructor of QMediaresource(QNetworkrequest,mimeType)*/ |
| 450 | QNetworkRequest request2(QUrl(QString::fromLatin1(str: "http://test.com/test.mp4" ))); |
| 451 | QUrl url(QString::fromLatin1(str: "http://test.com/test.mp4" )); |
| 452 | QString mimeType(QLatin1String("video/mp4" )); |
| 453 | |
| 454 | QMediaResource resource6(request2,mimeType); |
| 455 | QMediaResource resource7(request2,mimeType); |
| 456 | |
| 457 | |
| 458 | QVERIFY(resource6.request()==request2); |
| 459 | QVERIFY(resource6.mimeType()==mimeType); |
| 460 | |
| 461 | |
| 462 | QVERIFY(resource7.request()==request2); |
| 463 | QVERIFY(resource7.mimeType()==mimeType); |
| 464 | |
| 465 | QVERIFY(resource6.request()==resource7.request()); |
| 466 | QVERIFY(resource6.mimeType()==resource7.mimeType()); |
| 467 | |
| 468 | QVERIFY(resource6==resource7); |
| 469 | |
| 470 | /*for copy constructor*/ |
| 471 | QMediaResource resource8(resource7); |
| 472 | |
| 473 | QVERIFY(resource8.request()==request2); |
| 474 | QVERIFY(resource8.mimeType()==mimeType); |
| 475 | |
| 476 | |
| 477 | QVERIFY(resource7.request()==request2); |
| 478 | QVERIFY(resource7.mimeType()==mimeType); |
| 479 | |
| 480 | QVERIFY(resource8.request()==resource7.request()); |
| 481 | QVERIFY(resource8.mimeType()==resource7.mimeType()); |
| 482 | |
| 483 | |
| 484 | QVERIFY(resource8==resource7); |
| 485 | |
| 486 | /*for assign constructor*/ |
| 487 | |
| 488 | QMediaResource resource9(request2,mimeType); |
| 489 | |
| 490 | QMediaResource resource10=resource9; |
| 491 | |
| 492 | QVERIFY(resource10.request()==request2); |
| 493 | QVERIFY(resource10.mimeType()==mimeType); |
| 494 | |
| 495 | |
| 496 | QVERIFY(resource9.request()==request2); |
| 497 | QVERIFY(resource9.mimeType()==mimeType); |
| 498 | |
| 499 | QVERIFY(resource8.request()==resource7.request()); |
| 500 | QVERIFY(resource8.mimeType()==resource7.mimeType()); |
| 501 | |
| 502 | QVERIFY(resource8==resource7); |
| 503 | } |
| 504 | |
| 505 | void tst_QMediaResource::copy() |
| 506 | { |
| 507 | const QUrl url(QString::fromLatin1(str: "http://test.com/test.mp4" )); |
| 508 | const QString mimeType(QLatin1String("video/mp4" )); |
| 509 | const QString amrCodec(QLatin1String("amr" )); |
| 510 | const QString mp3Codec(QLatin1String("mp3" )); |
| 511 | const QString aacCodec(QLatin1String("aac" )); |
| 512 | const QString h264Codec(QLatin1String("h264" )); |
| 513 | |
| 514 | QMediaResource original(url, mimeType); |
| 515 | original.setAudioCodec(amrCodec); |
| 516 | |
| 517 | QMediaResource copy(original); |
| 518 | |
| 519 | QCOMPARE(copy.url(), url); |
| 520 | QCOMPARE(copy.mimeType(), mimeType); |
| 521 | QCOMPARE(copy.audioCodec(), amrCodec); |
| 522 | |
| 523 | QCOMPARE(original == copy, true); |
| 524 | QCOMPARE(original != copy, false); |
| 525 | |
| 526 | original.setAudioCodec(mp3Codec); |
| 527 | |
| 528 | QCOMPARE(copy.audioCodec(), amrCodec); |
| 529 | QCOMPARE(original == copy, false); |
| 530 | QCOMPARE(original != copy, true); |
| 531 | |
| 532 | copy.setAudioCodec(aacCodec); |
| 533 | copy.setVideoCodec(h264Codec); |
| 534 | |
| 535 | QCOMPARE(copy.url(), url); |
| 536 | QCOMPARE(copy.mimeType(), mimeType); |
| 537 | |
| 538 | QCOMPARE(original.audioCodec(), mp3Codec); |
| 539 | } |
| 540 | |
| 541 | void tst_QMediaResource::assign() |
| 542 | { |
| 543 | const QUrl url(QString::fromLatin1(str: "http://test.com/test.mp4" )); |
| 544 | const QString mimeType(QLatin1String("video/mp4" )); |
| 545 | const QString amrCodec(QLatin1String("amr" )); |
| 546 | const QString mp3Codec(QLatin1String("mp3" )); |
| 547 | const QString aacCodec(QLatin1String("aac" )); |
| 548 | const QString h264Codec(QLatin1String("h264" )); |
| 549 | |
| 550 | QNetworkRequest request(QUrl(QString::fromLatin1(str: "http://test.com/test.mp4" ))); |
| 551 | const qint64 dataSize(23600); |
| 552 | int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; |
| 553 | QSize resolution(QSize(640, 480)); |
| 554 | QString language("eng" ); |
| 555 | |
| 556 | QMediaResource copy(QUrl(QString::fromLatin1(str: "file:///thumbs/test.jpg" ))); |
| 557 | |
| 558 | QMediaResource original(url, mimeType); |
| 559 | original.setAudioCodec(amrCodec); |
| 560 | |
| 561 | copy = original; |
| 562 | |
| 563 | QCOMPARE(copy.url(), url); |
| 564 | QCOMPARE(copy.mimeType(), mimeType); |
| 565 | QCOMPARE(copy.audioCodec(), amrCodec); |
| 566 | |
| 567 | QCOMPARE(original == copy, true); |
| 568 | QCOMPARE(original != copy, false); |
| 569 | |
| 570 | original.setAudioCodec(mp3Codec); |
| 571 | |
| 572 | QCOMPARE(copy.audioCodec(), amrCodec); |
| 573 | QCOMPARE(original == copy, false); |
| 574 | QCOMPARE(original != copy, true); |
| 575 | |
| 576 | copy.setAudioCodec(aacCodec); |
| 577 | copy.setVideoCodec(h264Codec); |
| 578 | |
| 579 | QCOMPARE(copy.url(), url); |
| 580 | QCOMPARE(copy.mimeType(), mimeType); |
| 581 | |
| 582 | QCOMPARE(original.audioCodec(), mp3Codec); |
| 583 | |
| 584 | /* for constructor of QMediaresource(QNetworkrequest,mimeType)*/ |
| 585 | |
| 586 | QMediaResource copy1(QNetworkRequest(QUrl(QString::fromLatin1(str: "file:///thumbs/test.jpg" )))); |
| 587 | |
| 588 | QMediaResource original1(request, mimeType); |
| 589 | |
| 590 | original1.setAudioCodec(amrCodec); |
| 591 | original1.setLanguage(QString("eng" )); |
| 592 | original1.setVideoCodec(h264Codec); |
| 593 | original1.setDataSize(dataSize); |
| 594 | original1.setAudioBitRate(audioBitRate); |
| 595 | original1.setSampleRate(sampleRate); |
| 596 | original1.setChannelCount(channelCount); |
| 597 | original1.setVideoBitRate(videoBitRate); |
| 598 | original1.setResolution(resolution); |
| 599 | |
| 600 | copy1 = original1; |
| 601 | |
| 602 | QCOMPARE(original1 == copy1, true); |
| 603 | } |
| 604 | |
| 605 | // Constructor for request without passing mimetype. |
| 606 | void tst_QMediaResource::constructorRequest() |
| 607 | { |
| 608 | //Initialise the request and url. |
| 609 | QNetworkRequest request(QUrl(QString::fromLatin1(str: "http:://test.com/test.mp3" ))); |
| 610 | QUrl url(QString::fromLatin1(str: "http:://test.com/test.mp3" )); |
| 611 | |
| 612 | // Create the instance with request as parameter. |
| 613 | QMediaResource resource(request); |
| 614 | |
| 615 | // Verify all the parameters of objects. |
| 616 | QCOMPARE(resource.isNull(), false); |
| 617 | QCOMPARE(resource.url(), url); |
| 618 | QCOMPARE(resource.request(), request); |
| 619 | QCOMPARE(resource.mimeType(), QString()); |
| 620 | QCOMPARE(resource.language(), QString()); |
| 621 | QCOMPARE(resource.audioCodec(), QString()); |
| 622 | QCOMPARE(resource.videoCodec(), QString()); |
| 623 | QCOMPARE(resource.dataSize(), qint64(0)); |
| 624 | QCOMPARE(resource.audioBitRate(), 0); |
| 625 | QCOMPARE(resource.sampleRate(), 0); |
| 626 | QCOMPARE(resource.channelCount(), 0); |
| 627 | QCOMPARE(resource.videoBitRate(), 0); |
| 628 | QCOMPARE(resource.resolution(), QSize()); |
| 629 | } |
| 630 | |
| 631 | // Copy constructor with all the parameter and copy constructor for constructor with request and mimetype as parameter. |
| 632 | void tst_QMediaResource::copyConstructor() |
| 633 | { |
| 634 | // Initialise all the parameters. |
| 635 | const QUrl url(QString::fromLatin1(str: "http://test.com/test.mp4" )); |
| 636 | const QString mimeType(QLatin1String("video/mp4" )); |
| 637 | const QString amrCodec(QLatin1String("amr" )); |
| 638 | const QString h264Codec(QLatin1String("h264" )); |
| 639 | |
| 640 | const qint64 dataSize(23600); |
| 641 | int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; |
| 642 | QSize resolution(QSize(640, 480)); |
| 643 | QString language("eng" ); |
| 644 | |
| 645 | // Create the instance with url and mimetype. |
| 646 | QMediaResource original(url, mimeType); |
| 647 | |
| 648 | // Set all the parameters. |
| 649 | original.setAudioCodec(amrCodec); |
| 650 | original.setLanguage(QString("eng" )); |
| 651 | original.setVideoCodec(h264Codec); |
| 652 | original.setDataSize(dataSize); |
| 653 | original.setAudioBitRate(audioBitRate); |
| 654 | original.setSampleRate(sampleRate); |
| 655 | original.setChannelCount(channelCount); |
| 656 | original.setVideoBitRate(videoBitRate); |
| 657 | original.setResolution(resolution); |
| 658 | |
| 659 | // Copy the instance to new object. |
| 660 | QMediaResource copy(original); |
| 661 | |
| 662 | // Verify all the parameters of the copied object. |
| 663 | QCOMPARE(copy.url(), url); |
| 664 | QCOMPARE(copy.mimeType(), mimeType); |
| 665 | QCOMPARE(copy.audioCodec(), amrCodec); |
| 666 | QCOMPARE(copy.language(), language ); |
| 667 | QCOMPARE(copy.videoCodec(), h264Codec); |
| 668 | QCOMPARE(copy.dataSize(), dataSize); |
| 669 | QCOMPARE(copy.audioBitRate(), audioBitRate); |
| 670 | QCOMPARE(copy.sampleRate(), sampleRate); |
| 671 | QCOMPARE(copy.channelCount(), channelCount); |
| 672 | QCOMPARE(copy.videoBitRate(), videoBitRate); |
| 673 | QCOMPARE(copy.resolution(), resolution); |
| 674 | |
| 675 | // Compare both the objects are equal. |
| 676 | QCOMPARE(original == copy, true); |
| 677 | QCOMPARE(original != copy, false); |
| 678 | |
| 679 | // Initialise the request parameter. |
| 680 | QNetworkRequest request1(QUrl(QString::fromLatin1(str: "http://test.com/test.mp4" ))); |
| 681 | |
| 682 | // Constructor with rerquest and mimetype. |
| 683 | QMediaResource original1(request1, mimeType); |
| 684 | |
| 685 | // Copy the object and verify if both are eqaul or not. |
| 686 | QMediaResource copy1(original1); |
| 687 | QCOMPARE(copy1.url(), url); |
| 688 | QCOMPARE(copy1.mimeType(), mimeType); |
| 689 | QCOMPARE(copy1.request(), request1); |
| 690 | QCOMPARE(original1 == copy1, true); |
| 691 | } |
| 692 | |
| 693 | #endif // QT_DEPRECATED_SINCE(6, 0) |
| 694 | |
| 695 | QTEST_MAIN(tst_QMediaResource) |
| 696 | |
| 697 | #include "tst_qmediaresource.moc" |
| 698 | |