| 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 <qtmultimediaglobal.h> |
| 32 | #include <QtTest/QtTest> |
| 33 | |
| 34 | #include "qvideowidget.h" |
| 35 | |
| 36 | #include "qmediaobject.h" |
| 37 | #include "qmediaservice.h" |
| 38 | #include <private/qpaintervideosurface_p.h> |
| 39 | #include "qvideowindowcontrol.h" |
| 40 | #include "qvideowidgetcontrol.h" |
| 41 | |
| 42 | #include "qvideorenderercontrol.h" |
| 43 | #include <qabstractvideosurface.h> |
| 44 | #include <qvideosurfaceformat.h> |
| 45 | |
| 46 | #include <QtWidgets/qapplication.h> |
| 47 | |
| 48 | QT_USE_NAMESPACE |
| 49 | class tst_QVideoWidget : public QObject |
| 50 | { |
| 51 | Q_OBJECT |
| 52 | private slots: |
| 53 | void nullObject(); |
| 54 | void nullService(); |
| 55 | void noOutputs(); |
| 56 | void serviceDestroyed(); |
| 57 | void objectDestroyed(); |
| 58 | void setMediaObject(); |
| 59 | |
| 60 | void showWindowControl(); |
| 61 | void fullScreenWindowControl(); |
| 62 | void aspectRatioWindowControl(); |
| 63 | void sizeHintWindowControl_data() { sizeHint_data(); } |
| 64 | void sizeHintWindowControl(); |
| 65 | void brightnessWindowControl_data() { color_data(); } |
| 66 | void brightnessWindowControl(); |
| 67 | void contrastWindowControl_data() { color_data(); } |
| 68 | void contrastWindowControl(); |
| 69 | void hueWindowControl_data() { color_data(); } |
| 70 | void hueWindowControl(); |
| 71 | void saturationWindowControl_data() { color_data(); } |
| 72 | void saturationWindowControl(); |
| 73 | |
| 74 | void showWidgetControl(); |
| 75 | void fullScreenWidgetControl(); |
| 76 | void aspectRatioWidgetControl(); |
| 77 | void sizeHintWidgetControl_data() { sizeHint_data(); } |
| 78 | void sizeHintWidgetControl(); |
| 79 | void brightnessWidgetControl_data() { color_data(); } |
| 80 | void brightnessWidgetControl(); |
| 81 | void contrastWidgetControl_data() { color_data(); } |
| 82 | void contrastWidgetControl(); |
| 83 | void hueWidgetControl_data() { color_data(); } |
| 84 | void hueWidgetControl(); |
| 85 | void saturationWidgetControl_data() { color_data(); } |
| 86 | void saturationWidgetControl(); |
| 87 | |
| 88 | void showRendererControl(); |
| 89 | void fullScreenRendererControl(); |
| 90 | void aspectRatioRendererControl(); |
| 91 | void sizeHintRendererControl_data(); |
| 92 | void sizeHintRendererControl(); |
| 93 | void brightnessRendererControl_data() { color_data(); } |
| 94 | void brightnessRendererControl(); |
| 95 | void contrastRendererControl_data() { color_data(); } |
| 96 | void contrastRendererControl(); |
| 97 | void hueRendererControl_data() { color_data(); } |
| 98 | void hueRendererControl(); |
| 99 | void saturationRendererControl_data() { color_data(); } |
| 100 | void saturationRendererControl(); |
| 101 | |
| 102 | void paintRendererControl(); |
| 103 | void paintSurface(); |
| 104 | |
| 105 | private: |
| 106 | void sizeHint_data(); |
| 107 | void color_data(); |
| 108 | }; |
| 109 | |
| 110 | Q_DECLARE_METATYPE(Qt::AspectRatioMode) |
| 111 | Q_DECLARE_METATYPE(const uchar *) |
| 112 | |
| 113 | class QtTestVideoWidget : public QVideoWidget |
| 114 | { |
| 115 | public: |
| 116 | QtTestVideoWidget(QWidget *parent = 0) |
| 117 | : QVideoWidget(parent) |
| 118 | { |
| 119 | setWindowFlags(Qt::X11BypassWindowManagerHint); |
| 120 | resize(w: 320, h: 240); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | class QtTestWindowControl : public QVideoWindowControl |
| 125 | { |
| 126 | public: |
| 127 | QtTestWindowControl() |
| 128 | : m_winId(0) |
| 129 | , m_repaintCount(0) |
| 130 | , m_brightness(0) |
| 131 | , m_contrast(0) |
| 132 | , m_saturation(0) |
| 133 | , m_aspectRatioMode(Qt::KeepAspectRatio) |
| 134 | , m_fullScreen(0) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | WId winId() const { return m_winId; } |
| 139 | void setWinId(WId id) { m_winId = id; } |
| 140 | |
| 141 | QRect displayRect() const { return m_displayRect; } |
| 142 | void setDisplayRect(const QRect &rect) { m_displayRect = rect; } |
| 143 | |
| 144 | bool isFullScreen() const { return m_fullScreen; } |
| 145 | void setFullScreen(bool fullScreen) { emit fullScreenChanged(fullScreen: m_fullScreen = fullScreen); } |
| 146 | |
| 147 | int repaintCount() const { return m_repaintCount; } |
| 148 | void setRepaintCount(int count) { m_repaintCount = count; } |
| 149 | void repaint() { ++m_repaintCount; } |
| 150 | |
| 151 | QSize nativeSize() const { return m_nativeSize; } |
| 152 | void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); } |
| 153 | |
| 154 | Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; } |
| 155 | void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; } |
| 156 | |
| 157 | int brightness() const { return m_brightness; } |
| 158 | void setBrightness(int brightness) { emit brightnessChanged(brightness: m_brightness = brightness); } |
| 159 | |
| 160 | int contrast() const { return m_contrast; } |
| 161 | void setContrast(int contrast) { emit contrastChanged(contrast: m_contrast = contrast); } |
| 162 | |
| 163 | int hue() const { return m_hue; } |
| 164 | void setHue(int hue) { emit hueChanged(hue: m_hue = hue); } |
| 165 | |
| 166 | int saturation() const { return m_saturation; } |
| 167 | void setSaturation(int saturation) { emit saturationChanged(saturation: m_saturation = saturation); } |
| 168 | |
| 169 | private: |
| 170 | WId m_winId; |
| 171 | int m_repaintCount; |
| 172 | int m_brightness; |
| 173 | int m_contrast; |
| 174 | int m_hue; |
| 175 | int m_saturation; |
| 176 | Qt::AspectRatioMode m_aspectRatioMode; |
| 177 | QRect m_displayRect; |
| 178 | QSize m_nativeSize; |
| 179 | bool m_fullScreen; |
| 180 | }; |
| 181 | |
| 182 | class QtTestWidgetControl : public QVideoWidgetControl |
| 183 | { |
| 184 | public: |
| 185 | QtTestWidgetControl() |
| 186 | : m_brightness(1.0) |
| 187 | , m_contrast(1.0) |
| 188 | , m_hue(1.0) |
| 189 | , m_saturation(1.0) |
| 190 | , m_aspectRatioMode(Qt::KeepAspectRatio) |
| 191 | , m_fullScreen(false) |
| 192 | { |
| 193 | } |
| 194 | |
| 195 | bool isFullScreen() const { return m_fullScreen; } |
| 196 | void setFullScreen(bool fullScreen) { emit fullScreenChanged(fullScreen: m_fullScreen = fullScreen); } |
| 197 | |
| 198 | Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; } |
| 199 | void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; } |
| 200 | |
| 201 | int brightness() const { return m_brightness; } |
| 202 | void setBrightness(int brightness) { emit brightnessChanged(brightness: m_brightness = brightness); } |
| 203 | |
| 204 | int contrast() const { return m_contrast; } |
| 205 | void setContrast(int contrast) { emit contrastChanged(contrast: m_contrast = contrast); } |
| 206 | |
| 207 | int hue() const { return m_hue; } |
| 208 | void setHue(int hue) { emit hueChanged(hue: m_hue = hue); } |
| 209 | |
| 210 | int saturation() const { return m_saturation; } |
| 211 | void setSaturation(int saturation) { emit saturationChanged(saturation: m_saturation = saturation); } |
| 212 | |
| 213 | void setSizeHint(const QSize &size) { m_widget.setSizeHint(size); } |
| 214 | |
| 215 | QWidget *videoWidget() { return &m_widget; } |
| 216 | |
| 217 | private: |
| 218 | class Widget : public QWidget |
| 219 | { |
| 220 | public: |
| 221 | QSize sizeHint() const { return m_sizeHint; } |
| 222 | void setSizeHint(const QSize &size) { m_sizeHint = size; updateGeometry(); } |
| 223 | private: |
| 224 | QSize m_sizeHint; |
| 225 | } m_widget; |
| 226 | int m_brightness; |
| 227 | int m_contrast; |
| 228 | int m_hue; |
| 229 | int m_saturation; |
| 230 | Qt::AspectRatioMode m_aspectRatioMode; |
| 231 | QSize m_sizeHint; |
| 232 | bool m_fullScreen; |
| 233 | }; |
| 234 | |
| 235 | class QtTestRendererControl : public QVideoRendererControl |
| 236 | { |
| 237 | public: |
| 238 | QtTestRendererControl() |
| 239 | : m_surface(0) |
| 240 | { |
| 241 | } |
| 242 | |
| 243 | QAbstractVideoSurface *surface() const { return m_surface; } |
| 244 | void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } |
| 245 | |
| 246 | private: |
| 247 | QAbstractVideoSurface *m_surface; |
| 248 | }; |
| 249 | |
| 250 | class QtTestVideoService : public QMediaService |
| 251 | { |
| 252 | Q_OBJECT |
| 253 | public: |
| 254 | QtTestVideoService( |
| 255 | QtTestWindowControl *window, |
| 256 | QtTestWidgetControl *widget, |
| 257 | QtTestRendererControl *renderer) |
| 258 | : QMediaService(0) |
| 259 | , windowRef(0) |
| 260 | , widgetRef(0) |
| 261 | , rendererRef(0) |
| 262 | , windowControl(window) |
| 263 | , widgetControl(widget) |
| 264 | , rendererControl(renderer) |
| 265 | { |
| 266 | } |
| 267 | |
| 268 | ~QtTestVideoService() |
| 269 | { |
| 270 | delete windowControl; |
| 271 | delete widgetControl; |
| 272 | delete rendererControl; |
| 273 | } |
| 274 | |
| 275 | QMediaControl *requestControl(const char *name) |
| 276 | { |
| 277 | if (qstrcmp(str1: name, QVideoWindowControl_iid) == 0) { |
| 278 | if (windowControl) { |
| 279 | windowRef += 1; |
| 280 | |
| 281 | return windowControl; |
| 282 | } |
| 283 | } else if (qstrcmp(str1: name, QVideoWidgetControl_iid) == 0) { |
| 284 | if (widgetControl) { |
| 285 | widgetRef += 1; |
| 286 | |
| 287 | return widgetControl; |
| 288 | } |
| 289 | } else if (qstrcmp(str1: name, QVideoRendererControl_iid) == 0) { |
| 290 | if (rendererControl) { |
| 291 | rendererRef += 1; |
| 292 | |
| 293 | return rendererControl; |
| 294 | } |
| 295 | } |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | void releaseControl(QMediaControl *control) |
| 300 | { |
| 301 | Q_ASSERT(control); |
| 302 | |
| 303 | if (control == windowControl) |
| 304 | windowRef -= 1; |
| 305 | else if (control == widgetControl) |
| 306 | widgetRef -= 1; |
| 307 | else if (control == rendererControl) |
| 308 | rendererRef -= 1; |
| 309 | } |
| 310 | |
| 311 | int windowRef; |
| 312 | int widgetRef; |
| 313 | int rendererRef; |
| 314 | |
| 315 | QtTestWindowControl *windowControl; |
| 316 | QtTestWidgetControl *widgetControl; |
| 317 | QtTestRendererControl *rendererControl; |
| 318 | }; |
| 319 | |
| 320 | class QtTestVideoObject : public QMediaObject |
| 321 | { |
| 322 | Q_OBJECT |
| 323 | public: |
| 324 | QtTestVideoObject( |
| 325 | QtTestWindowControl *window, |
| 326 | QtTestWidgetControl *widget, |
| 327 | QtTestRendererControl *renderer): |
| 328 | QMediaObject(0, new QtTestVideoService(window, widget, renderer)) |
| 329 | { |
| 330 | testService = qobject_cast<QtTestVideoService*>(object: service()); |
| 331 | } |
| 332 | |
| 333 | QtTestVideoObject(QtTestVideoService *service): |
| 334 | QMediaObject(0, service), |
| 335 | testService(service) |
| 336 | { |
| 337 | } |
| 338 | |
| 339 | ~QtTestVideoObject() |
| 340 | { |
| 341 | delete testService; |
| 342 | } |
| 343 | |
| 344 | QtTestVideoService *testService; |
| 345 | }; |
| 346 | |
| 347 | void tst_QVideoWidget::nullObject() |
| 348 | { |
| 349 | QtTestVideoWidget widget; |
| 350 | |
| 351 | QVERIFY(widget.sizeHint().isEmpty()); |
| 352 | |
| 353 | widget.show(); |
| 354 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 355 | |
| 356 | widget.setFullScreen(true); |
| 357 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 358 | QCOMPARE(widget.isFullScreen(), true); |
| 359 | |
| 360 | widget.setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 361 | QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 362 | |
| 363 | { |
| 364 | QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); |
| 365 | |
| 366 | widget.setBrightness(100); |
| 367 | QCOMPARE(widget.brightness(), 100); |
| 368 | QCOMPARE(spy.count(), 1); |
| 369 | QCOMPARE(spy.value(0).value(0).toInt(), 100); |
| 370 | |
| 371 | widget.setBrightness(100); |
| 372 | QCOMPARE(widget.brightness(), 100); |
| 373 | QCOMPARE(spy.count(), 1); |
| 374 | |
| 375 | widget.setBrightness(-120); |
| 376 | QCOMPARE(widget.brightness(), -100); |
| 377 | QCOMPARE(spy.count(), 2); |
| 378 | QCOMPARE(spy.value(1).value(0).toInt(), -100); |
| 379 | } { |
| 380 | QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); |
| 381 | |
| 382 | widget.setContrast(100); |
| 383 | QCOMPARE(widget.contrast(), 100); |
| 384 | QCOMPARE(spy.count(), 1); |
| 385 | QCOMPARE(spy.value(0).value(0).toInt(), 100); |
| 386 | |
| 387 | widget.setContrast(100); |
| 388 | QCOMPARE(widget.contrast(), 100); |
| 389 | QCOMPARE(spy.count(), 1); |
| 390 | |
| 391 | widget.setContrast(-120); |
| 392 | QCOMPARE(widget.contrast(), -100); |
| 393 | QCOMPARE(spy.count(), 2); |
| 394 | QCOMPARE(spy.value(1).value(0).toInt(), -100); |
| 395 | } { |
| 396 | QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); |
| 397 | |
| 398 | widget.setHue(100); |
| 399 | QCOMPARE(widget.hue(), 100); |
| 400 | QCOMPARE(spy.count(), 1); |
| 401 | QCOMPARE(spy.value(0).value(0).toInt(), 100); |
| 402 | |
| 403 | widget.setHue(100); |
| 404 | QCOMPARE(widget.hue(), 100); |
| 405 | QCOMPARE(spy.count(), 1); |
| 406 | |
| 407 | widget.setHue(-120); |
| 408 | QCOMPARE(widget.hue(), -100); |
| 409 | QCOMPARE(spy.count(), 2); |
| 410 | QCOMPARE(spy.value(1).value(0).toInt(), -100); |
| 411 | } { |
| 412 | QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); |
| 413 | |
| 414 | widget.setSaturation(100); |
| 415 | QCOMPARE(widget.saturation(), 100); |
| 416 | QCOMPARE(spy.count(), 1); |
| 417 | QCOMPARE(spy.value(0).value(0).toInt(), 100); |
| 418 | |
| 419 | widget.setSaturation(100); |
| 420 | QCOMPARE(widget.saturation(), 100); |
| 421 | QCOMPARE(spy.count(), 1); |
| 422 | |
| 423 | widget.setSaturation(-120); |
| 424 | QCOMPARE(widget.saturation(), -100); |
| 425 | QCOMPARE(spy.count(), 2); |
| 426 | QCOMPARE(spy.value(1).value(0).toInt(), -100); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | void tst_QVideoWidget::nullService() |
| 431 | { |
| 432 | QtTestVideoObject object(0); |
| 433 | |
| 434 | QtTestVideoWidget widget; |
| 435 | object.bind(&widget); |
| 436 | |
| 437 | QVERIFY(widget.sizeHint().isEmpty()); |
| 438 | |
| 439 | widget.show(); |
| 440 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 441 | |
| 442 | widget.setFullScreen(true); |
| 443 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 444 | QCOMPARE(widget.isFullScreen(), true); |
| 445 | |
| 446 | widget.setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 447 | QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 448 | |
| 449 | widget.setBrightness(100); |
| 450 | QCOMPARE(widget.brightness(), 100); |
| 451 | |
| 452 | widget.setContrast(100); |
| 453 | QCOMPARE(widget.contrast(), 100); |
| 454 | |
| 455 | widget.setHue(100); |
| 456 | QCOMPARE(widget.hue(), 100); |
| 457 | |
| 458 | widget.setSaturation(100); |
| 459 | QCOMPARE(widget.saturation(), 100); |
| 460 | } |
| 461 | |
| 462 | void tst_QVideoWidget::noOutputs() |
| 463 | { |
| 464 | QtTestVideoObject object(0, 0, 0); |
| 465 | |
| 466 | QtTestVideoWidget widget; |
| 467 | object.bind(&widget); |
| 468 | |
| 469 | QVERIFY(widget.sizeHint().isEmpty()); |
| 470 | |
| 471 | widget.setFullScreen(true); |
| 472 | QCOMPARE(widget.isFullScreen(), true); |
| 473 | |
| 474 | widget.setBrightness(100); |
| 475 | QCOMPARE(widget.brightness(), 100); |
| 476 | |
| 477 | widget.setContrast(100); |
| 478 | QCOMPARE(widget.contrast(), 100); |
| 479 | |
| 480 | widget.setHue(100); |
| 481 | QCOMPARE(widget.hue(), 100); |
| 482 | |
| 483 | widget.setSaturation(100); |
| 484 | QCOMPARE(widget.saturation(), 100); |
| 485 | } |
| 486 | |
| 487 | void tst_QVideoWidget::serviceDestroyed() |
| 488 | { |
| 489 | #ifdef Q_OS_MAC |
| 490 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 491 | #endif |
| 492 | |
| 493 | QtTestVideoObject object(new QtTestWindowControl, new QtTestWidgetControl, 0); |
| 494 | |
| 495 | QtTestVideoWidget widget; |
| 496 | object.bind(&widget); |
| 497 | |
| 498 | widget.show(); |
| 499 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 500 | |
| 501 | widget.setBrightness(100); |
| 502 | widget.setContrast(100); |
| 503 | widget.setHue(100); |
| 504 | widget.setSaturation(100); |
| 505 | |
| 506 | delete object.testService; |
| 507 | object.testService = 0; |
| 508 | |
| 509 | QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&object)); |
| 510 | |
| 511 | QCOMPARE(widget.brightness(), 100); |
| 512 | QCOMPARE(widget.contrast(), 100); |
| 513 | QCOMPARE(widget.hue(), 100); |
| 514 | QCOMPARE(widget.saturation(), 100); |
| 515 | |
| 516 | widget.setFullScreen(true); |
| 517 | QCOMPARE(widget.isFullScreen(), true); |
| 518 | } |
| 519 | |
| 520 | void tst_QVideoWidget::objectDestroyed() |
| 521 | { |
| 522 | #ifdef Q_OS_MAC |
| 523 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 524 | #endif |
| 525 | |
| 526 | QtTestVideoObject *object = new QtTestVideoObject( |
| 527 | new QtTestWindowControl, |
| 528 | new QtTestWidgetControl, |
| 529 | 0); |
| 530 | |
| 531 | QtTestVideoWidget widget; |
| 532 | object->bind(&widget); |
| 533 | |
| 534 | QCOMPARE(object->testService->windowRef, 0); |
| 535 | QCOMPARE(object->testService->widgetRef, 1); |
| 536 | QCOMPARE(object->testService->rendererRef, 0); |
| 537 | |
| 538 | widget.show(); |
| 539 | |
| 540 | widget.setBrightness(100); |
| 541 | widget.setContrast(100); |
| 542 | widget.setHue(100); |
| 543 | widget.setSaturation(100); |
| 544 | |
| 545 | // Delete the media object without deleting the service. |
| 546 | QtTestVideoService *service = object->testService; |
| 547 | object->testService = 0; |
| 548 | |
| 549 | delete object; |
| 550 | object = 0; |
| 551 | |
| 552 | QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(object)); |
| 553 | |
| 554 | QCOMPARE(widget.brightness(), 100); |
| 555 | QCOMPARE(widget.contrast(), 100); |
| 556 | QCOMPARE(widget.hue(), 100); |
| 557 | QCOMPARE(widget.saturation(), 100); |
| 558 | |
| 559 | widget.setFullScreen(true); |
| 560 | QCOMPARE(widget.isFullScreen(), true); |
| 561 | |
| 562 | delete service; |
| 563 | } |
| 564 | |
| 565 | void tst_QVideoWidget::setMediaObject() |
| 566 | { |
| 567 | QMediaObject *nullObject = 0; |
| 568 | QtTestVideoObject windowObject(new QtTestWindowControl, 0, 0); |
| 569 | QtTestVideoObject widgetObject(0, new QtTestWidgetControl, 0); |
| 570 | QtTestVideoObject rendererObject(0, 0, new QtTestRendererControl); |
| 571 | |
| 572 | QtTestVideoWidget widget; |
| 573 | |
| 574 | widget.show(); |
| 575 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 576 | |
| 577 | QCOMPARE(widget.mediaObject(), nullObject); |
| 578 | QCOMPARE(windowObject.testService->windowRef, 0); |
| 579 | QCOMPARE(widgetObject.testService->widgetRef, 0); |
| 580 | QCOMPARE(rendererObject.testService->rendererRef, 0); |
| 581 | |
| 582 | windowObject.bind(&widget); |
| 583 | QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&windowObject)); |
| 584 | QCOMPARE(windowObject.testService->windowRef, 1); |
| 585 | QCOMPARE(widgetObject.testService->widgetRef, 0); |
| 586 | QCOMPARE(rendererObject.testService->rendererRef, 0); |
| 587 | QVERIFY(windowObject.testService->windowControl->winId() != 0); |
| 588 | |
| 589 | |
| 590 | widgetObject.bind(&widget); |
| 591 | QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&widgetObject)); |
| 592 | QCOMPARE(windowObject.testService->windowRef, 0); |
| 593 | QCOMPARE(widgetObject.testService->widgetRef, 1); |
| 594 | QCOMPARE(rendererObject.testService->rendererRef, 0); |
| 595 | |
| 596 | QCoreApplication::processEvents(flags: QEventLoop::AllEvents); |
| 597 | QCOMPARE(widgetObject.testService->widgetControl->videoWidget()->isVisible(), true); |
| 598 | |
| 599 | QCOMPARE(windowObject.testService->windowRef, 0); |
| 600 | QCOMPARE(widgetObject.testService->widgetRef, 1); |
| 601 | QCOMPARE(rendererObject.testService->rendererRef, 0); |
| 602 | |
| 603 | rendererObject.bind(&widget); |
| 604 | QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&rendererObject)); |
| 605 | |
| 606 | QCOMPARE(windowObject.testService->windowRef, 0); |
| 607 | QCOMPARE(widgetObject.testService->widgetRef, 0); |
| 608 | QCOMPARE(rendererObject.testService->rendererRef, 1); |
| 609 | QVERIFY(rendererObject.testService->rendererControl->surface() != 0); |
| 610 | |
| 611 | rendererObject.unbind(&widget); |
| 612 | QCOMPARE(widget.mediaObject(), nullObject); |
| 613 | |
| 614 | QCOMPARE(windowObject.testService->windowRef, 0); |
| 615 | QCOMPARE(widgetObject.testService->widgetRef, 0); |
| 616 | QCOMPARE(rendererObject.testService->rendererRef, 0); |
| 617 | } |
| 618 | |
| 619 | void tst_QVideoWidget::showWindowControl() |
| 620 | { |
| 621 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 622 | object.testService->windowControl->setNativeSize(QSize(240, 180)); |
| 623 | |
| 624 | QtTestVideoWidget widget; |
| 625 | object.bind(&widget); |
| 626 | |
| 627 | widget.show(); |
| 628 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 629 | |
| 630 | QVERIFY(object.testService->windowControl->winId() != 0); |
| 631 | QVERIFY(object.testService->windowControl->repaintCount() > 0); |
| 632 | |
| 633 | widget.resize(w: 640, h: 480); |
| 634 | QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480)); |
| 635 | |
| 636 | widget.move(ax: 10, ay: 10); |
| 637 | QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480)); |
| 638 | |
| 639 | widget.hide(); |
| 640 | } |
| 641 | |
| 642 | void tst_QVideoWidget::showWidgetControl() |
| 643 | { |
| 644 | #ifdef Q_OS_MAC |
| 645 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 646 | #endif |
| 647 | |
| 648 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 649 | QtTestVideoWidget widget; |
| 650 | object.bind(&widget); |
| 651 | |
| 652 | widget.show(); |
| 653 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 654 | QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), true); |
| 655 | |
| 656 | widget.resize(w: 640, h: 480); |
| 657 | |
| 658 | widget.move(ax: 10, ay: 10); |
| 659 | |
| 660 | widget.hide(); |
| 661 | |
| 662 | QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false); |
| 663 | } |
| 664 | |
| 665 | void tst_QVideoWidget::showRendererControl() |
| 666 | { |
| 667 | #ifdef Q_OS_MAC |
| 668 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 669 | #endif |
| 670 | |
| 671 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 672 | QtTestVideoWidget widget; |
| 673 | object.bind(&widget); |
| 674 | |
| 675 | widget.show(); |
| 676 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 677 | |
| 678 | QVERIFY(object.testService->rendererControl->surface() != 0); |
| 679 | |
| 680 | widget.resize(w: 640, h: 480); |
| 681 | |
| 682 | widget.move(ax: 10, ay: 10); |
| 683 | |
| 684 | widget.hide(); |
| 685 | } |
| 686 | |
| 687 | void tst_QVideoWidget::aspectRatioWindowControl() |
| 688 | { |
| 689 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 690 | object.testService->windowControl->setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 691 | |
| 692 | QtTestVideoWidget widget; |
| 693 | object.bind(&widget); |
| 694 | |
| 695 | // Test the aspect ratio defaults to keeping the aspect ratio. |
| 696 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 697 | |
| 698 | // Test the control has been informed of the aspect ratio change, post show. |
| 699 | widget.show(); |
| 700 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 701 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 702 | QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio); |
| 703 | |
| 704 | // Test an aspect ratio change is enforced immediately while visible. |
| 705 | widget.setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 706 | QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 707 | QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 708 | |
| 709 | // Test an aspect ratio set while not visible is respected. |
| 710 | widget.hide(); |
| 711 | widget.setAspectRatioMode(Qt::KeepAspectRatio); |
| 712 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 713 | widget.show(); |
| 714 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 715 | QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio); |
| 716 | } |
| 717 | |
| 718 | void tst_QVideoWidget::aspectRatioWidgetControl() |
| 719 | { |
| 720 | #ifdef Q_OS_MAC |
| 721 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 722 | #endif |
| 723 | |
| 724 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 725 | object.testService->widgetControl->setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 726 | |
| 727 | QtTestVideoWidget widget; |
| 728 | object.bind(&widget); |
| 729 | |
| 730 | // Test the aspect ratio defaults to keeping the aspect ratio. |
| 731 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 732 | |
| 733 | // Test the control has been informed of the aspect ratio change, post show. |
| 734 | widget.show(); |
| 735 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 736 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 737 | QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio); |
| 738 | |
| 739 | // Test an aspect ratio change is enforced immediately while visible. |
| 740 | widget.setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 741 | QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 742 | QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 743 | |
| 744 | // Test an aspect ratio set while not visible is respected. |
| 745 | widget.hide(); |
| 746 | widget.setAspectRatioMode(Qt::KeepAspectRatio); |
| 747 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 748 | widget.show(); |
| 749 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 750 | QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio); |
| 751 | } |
| 752 | |
| 753 | void tst_QVideoWidget::aspectRatioRendererControl() |
| 754 | { |
| 755 | #ifdef Q_OS_MAC |
| 756 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 757 | #endif |
| 758 | |
| 759 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 760 | |
| 761 | QtTestVideoWidget widget; |
| 762 | object.bind(&widget); |
| 763 | |
| 764 | // Test the aspect ratio defaults to keeping the aspect ratio. |
| 765 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 766 | |
| 767 | // Test the control has been informed of the aspect ratio change, post show. |
| 768 | widget.show(); |
| 769 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 770 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 771 | |
| 772 | // Test an aspect ratio change is enforced immediately while visible. |
| 773 | widget.setAspectRatioMode(Qt::IgnoreAspectRatio); |
| 774 | QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); |
| 775 | |
| 776 | // Test an aspect ratio set while not visible is respected. |
| 777 | widget.hide(); |
| 778 | widget.setAspectRatioMode(Qt::KeepAspectRatio); |
| 779 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 780 | widget.show(); |
| 781 | QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); |
| 782 | } |
| 783 | |
| 784 | void tst_QVideoWidget::sizeHint_data() |
| 785 | { |
| 786 | QTest::addColumn<QSize>(name: "size" ); |
| 787 | |
| 788 | QTest::newRow(dataTag: "720x576" ) |
| 789 | << QSize(720, 576); |
| 790 | } |
| 791 | |
| 792 | void tst_QVideoWidget::sizeHintWindowControl() |
| 793 | { |
| 794 | QFETCH(QSize, size); |
| 795 | |
| 796 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 797 | QtTestVideoWidget widget; |
| 798 | object.bind(&widget); |
| 799 | widget.show(); |
| 800 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 801 | |
| 802 | QVERIFY(widget.sizeHint().isEmpty()); |
| 803 | |
| 804 | object.testService->windowControl->setNativeSize(size); |
| 805 | QCOMPARE(widget.sizeHint(), size); |
| 806 | } |
| 807 | |
| 808 | void tst_QVideoWidget::sizeHintWidgetControl() |
| 809 | { |
| 810 | #ifdef Q_OS_MAC |
| 811 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 812 | #endif |
| 813 | |
| 814 | QFETCH(QSize, size); |
| 815 | |
| 816 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 817 | QtTestVideoWidget widget; |
| 818 | object.bind(&widget); |
| 819 | widget.show(); |
| 820 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 821 | |
| 822 | QVERIFY(widget.sizeHint().isEmpty()); |
| 823 | |
| 824 | object.testService->widgetControl->setSizeHint(size); |
| 825 | QCOMPARE(widget.sizeHint(), size); |
| 826 | } |
| 827 | |
| 828 | void tst_QVideoWidget::sizeHintRendererControl_data() |
| 829 | { |
| 830 | #ifdef Q_OS_MAC |
| 831 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 832 | #endif |
| 833 | |
| 834 | QTest::addColumn<QSize>(name: "frameSize" ); |
| 835 | QTest::addColumn<QRect>(name: "viewport" ); |
| 836 | QTest::addColumn<QSize>(name: "pixelAspectRatio" ); |
| 837 | QTest::addColumn<QSize>(name: "expectedSize" ); |
| 838 | |
| 839 | QTest::newRow(dataTag: "640x480" ) |
| 840 | << QSize(640, 480) |
| 841 | << QRect(0, 0, 640, 480) |
| 842 | << QSize(1, 1) |
| 843 | << QSize(640, 480); |
| 844 | |
| 845 | QTest::newRow(dataTag: "800x600, (80,60, 640x480) viewport" ) |
| 846 | << QSize(800, 600) |
| 847 | << QRect(80, 60, 640, 480) |
| 848 | << QSize(1, 1) |
| 849 | << QSize(640, 480); |
| 850 | |
| 851 | QTest::newRow(dataTag: "800x600, (80,60, 640x480) viewport, 4:3" ) |
| 852 | << QSize(800, 600) |
| 853 | << QRect(80, 60, 640, 480) |
| 854 | << QSize(4, 3) |
| 855 | << QSize(853, 480); |
| 856 | |
| 857 | } |
| 858 | |
| 859 | void tst_QVideoWidget::sizeHintRendererControl() |
| 860 | { |
| 861 | #ifdef Q_OS_MAC |
| 862 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 863 | #endif |
| 864 | |
| 865 | QFETCH(QSize, frameSize); |
| 866 | QFETCH(QRect, viewport); |
| 867 | QFETCH(QSize, pixelAspectRatio); |
| 868 | QFETCH(QSize, expectedSize); |
| 869 | |
| 870 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 871 | QtTestVideoWidget widget; |
| 872 | object.bind(&widget); |
| 873 | |
| 874 | widget.show(); |
| 875 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 876 | |
| 877 | QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); |
| 878 | format.setViewport(viewport); |
| 879 | format.setPixelAspectRatio(pixelAspectRatio); |
| 880 | |
| 881 | QVERIFY(object.testService->rendererControl->surface()->start(format)); |
| 882 | |
| 883 | QCOMPARE(widget.sizeHint(), expectedSize); |
| 884 | } |
| 885 | |
| 886 | |
| 887 | void tst_QVideoWidget::fullScreenWindowControl() |
| 888 | { |
| 889 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 890 | QtTestVideoWidget widget; |
| 891 | object.bind(&widget); |
| 892 | widget.showNormal(); |
| 893 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 894 | |
| 895 | Qt::WindowFlags windowFlags = widget.windowFlags(); |
| 896 | |
| 897 | QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); |
| 898 | |
| 899 | // Test showing full screen with setFullScreen(true). |
| 900 | widget.setFullScreen(true); |
| 901 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 902 | QCOMPARE(object.testService->windowControl->isFullScreen(), true); |
| 903 | QCOMPARE(widget.isFullScreen(), true); |
| 904 | QCOMPARE(spy.count(), 1); |
| 905 | QCOMPARE(spy.value(0).value(0).toBool(), true); |
| 906 | |
| 907 | // Test returning to normal with setFullScreen(false). |
| 908 | widget.setFullScreen(false); |
| 909 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 910 | QCOMPARE(object.testService->windowControl->isFullScreen(), false); |
| 911 | QCOMPARE(widget.isFullScreen(), false); |
| 912 | QCOMPARE(spy.count(), 2); |
| 913 | QCOMPARE(spy.value(1).value(0).toBool(), false); |
| 914 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 915 | |
| 916 | // Test showing full screen with showFullScreen(). |
| 917 | widget.showFullScreen(); |
| 918 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 919 | QCOMPARE(object.testService->windowControl->isFullScreen(), true); |
| 920 | QCOMPARE(widget.isFullScreen(), true); |
| 921 | QCOMPARE(spy.count(), 3); |
| 922 | QCOMPARE(spy.value(2).value(0).toBool(), true); |
| 923 | |
| 924 | // Test returning to normal with showNormal(). |
| 925 | widget.showNormal(); |
| 926 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 927 | QCOMPARE(object.testService->windowControl->isFullScreen(), false); |
| 928 | QCOMPARE(widget.isFullScreen(), false); |
| 929 | QCOMPARE(spy.count(), 4); |
| 930 | QCOMPARE(spy.value(3).value(0).toBool(), false); |
| 931 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 932 | |
| 933 | // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. |
| 934 | widget.setFullScreen(false); |
| 935 | QCOMPARE(object.testService->windowControl->isFullScreen(), false); |
| 936 | QCOMPARE(widget.isFullScreen(), false); |
| 937 | QCOMPARE(spy.count(), 4); |
| 938 | widget.showNormal(); |
| 939 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 940 | QCOMPARE(object.testService->windowControl->isFullScreen(), false); |
| 941 | QCOMPARE(widget.isFullScreen(), false); |
| 942 | QCOMPARE(spy.count(), 4); |
| 943 | |
| 944 | // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. |
| 945 | widget.showFullScreen(); |
| 946 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 947 | widget.setFullScreen(true); |
| 948 | QCOMPARE(object.testService->windowControl->isFullScreen(), true); |
| 949 | QCOMPARE(widget.isFullScreen(), true); |
| 950 | QCOMPARE(spy.count(), 5); |
| 951 | widget.showFullScreen(); |
| 952 | QCOMPARE(object.testService->windowControl->isFullScreen(), true); |
| 953 | QCOMPARE(widget.isFullScreen(), true); |
| 954 | QCOMPARE(spy.count(), 5); |
| 955 | |
| 956 | // Test if the window control exits full screen mode, the widget follows suit. |
| 957 | object.testService->windowControl->setFullScreen(false); |
| 958 | QCOMPARE(widget.isFullScreen(), false); |
| 959 | QCOMPARE(spy.count(), 6); |
| 960 | QCOMPARE(spy.value(5).value(0).toBool(), false); |
| 961 | |
| 962 | // Test if the window control enters full screen mode, the widget does nothing. |
| 963 | object.testService->windowControl->setFullScreen(false); |
| 964 | QCOMPARE(widget.isFullScreen(), false); |
| 965 | QCOMPARE(spy.count(), 6); |
| 966 | } |
| 967 | |
| 968 | void tst_QVideoWidget::fullScreenWidgetControl() |
| 969 | { |
| 970 | #ifdef Q_OS_MAC |
| 971 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 972 | #endif |
| 973 | |
| 974 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 975 | QtTestVideoWidget widget; |
| 976 | object.bind(&widget); |
| 977 | widget.showNormal(); |
| 978 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 979 | |
| 980 | Qt::WindowFlags windowFlags = widget.windowFlags(); |
| 981 | |
| 982 | QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); |
| 983 | |
| 984 | // Test showing full screen with setFullScreen(true). |
| 985 | widget.setFullScreen(true); |
| 986 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 987 | QCOMPARE(object.testService->widgetControl->isFullScreen(), true); |
| 988 | QCOMPARE(widget.isFullScreen(), true); |
| 989 | QCOMPARE(spy.count(), 1); |
| 990 | QCOMPARE(spy.value(0).value(0).toBool(), true); |
| 991 | |
| 992 | // Test returning to normal with setFullScreen(false). |
| 993 | widget.setFullScreen(false); |
| 994 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 995 | QCOMPARE(object.testService->widgetControl->isFullScreen(), false); |
| 996 | QCOMPARE(widget.isFullScreen(), false); |
| 997 | QCOMPARE(spy.count(), 2); |
| 998 | QCOMPARE(spy.value(1).value(0).toBool(), false); |
| 999 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 1000 | |
| 1001 | // Test showing full screen with showFullScreen(). |
| 1002 | widget.showFullScreen(); |
| 1003 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1004 | QCOMPARE(object.testService->widgetControl->isFullScreen(), true); |
| 1005 | QCOMPARE(widget.isFullScreen(), true); |
| 1006 | QCOMPARE(spy.count(), 3); |
| 1007 | QCOMPARE(spy.value(2).value(0).toBool(), true); |
| 1008 | |
| 1009 | // Test returning to normal with showNormal(). |
| 1010 | widget.showNormal(); |
| 1011 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1012 | QCOMPARE(object.testService->widgetControl->isFullScreen(), false); |
| 1013 | QCOMPARE(widget.isFullScreen(), false); |
| 1014 | QCOMPARE(spy.count(), 4); |
| 1015 | QCOMPARE(spy.value(3).value(0).toBool(), false); |
| 1016 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 1017 | |
| 1018 | // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. |
| 1019 | widget.setFullScreen(false); |
| 1020 | QCOMPARE(object.testService->widgetControl->isFullScreen(), false); |
| 1021 | QCOMPARE(widget.isFullScreen(), false); |
| 1022 | QCOMPARE(spy.count(), 4); |
| 1023 | widget.showNormal(); |
| 1024 | QCOMPARE(object.testService->widgetControl->isFullScreen(), false); |
| 1025 | QCOMPARE(widget.isFullScreen(), false); |
| 1026 | QCOMPARE(spy.count(), 4); |
| 1027 | |
| 1028 | // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. |
| 1029 | widget.showFullScreen(); |
| 1030 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1031 | widget.setFullScreen(true); |
| 1032 | QCOMPARE(object.testService->widgetControl->isFullScreen(), true); |
| 1033 | QCOMPARE(widget.isFullScreen(), true); |
| 1034 | QCOMPARE(spy.count(), 5); |
| 1035 | widget.showFullScreen(); |
| 1036 | QCOMPARE(object.testService->widgetControl->isFullScreen(), true); |
| 1037 | QCOMPARE(widget.isFullScreen(), true); |
| 1038 | QCOMPARE(spy.count(), 5); |
| 1039 | |
| 1040 | // Test if the window control exits full screen mode, the widget follows suit. |
| 1041 | object.testService->widgetControl->setFullScreen(false); |
| 1042 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1043 | QCOMPARE(widget.isFullScreen(), false); |
| 1044 | QCOMPARE(spy.count(), 6); |
| 1045 | QCOMPARE(spy.value(5).value(0).toBool(), false); |
| 1046 | |
| 1047 | // Test if the window control enters full screen mode, the widget does nothing. |
| 1048 | object.testService->widgetControl->setFullScreen(false); |
| 1049 | QCOMPARE(widget.isFullScreen(), false); |
| 1050 | QCOMPARE(spy.count(), 6); |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | void tst_QVideoWidget::fullScreenRendererControl() |
| 1055 | { |
| 1056 | #ifdef Q_OS_MAC |
| 1057 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1058 | #endif |
| 1059 | |
| 1060 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1061 | QtTestVideoWidget widget; |
| 1062 | object.bind(&widget); |
| 1063 | widget.showNormal(); |
| 1064 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1065 | |
| 1066 | Qt::WindowFlags windowFlags = widget.windowFlags(); |
| 1067 | |
| 1068 | QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); |
| 1069 | |
| 1070 | // Test showing full screen with setFullScreen(true). |
| 1071 | widget.setFullScreen(true); |
| 1072 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1073 | QCOMPARE(widget.isFullScreen(), true); |
| 1074 | QCOMPARE(spy.count(), 1); |
| 1075 | QCOMPARE(spy.value(0).value(0).toBool(), true); |
| 1076 | |
| 1077 | // Test returning to normal with setFullScreen(false). |
| 1078 | widget.setFullScreen(false); |
| 1079 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1080 | QCOMPARE(widget.isFullScreen(), false); |
| 1081 | QCOMPARE(spy.count(), 2); |
| 1082 | QCOMPARE(spy.value(1).value(0).toBool(), false); |
| 1083 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 1084 | |
| 1085 | // Test showing full screen with showFullScreen(). |
| 1086 | widget.showFullScreen(); |
| 1087 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1088 | QCOMPARE(widget.isFullScreen(), true); |
| 1089 | QCOMPARE(spy.count(), 3); |
| 1090 | QCOMPARE(spy.value(2).value(0).toBool(), true); |
| 1091 | |
| 1092 | // Test returning to normal with showNormal(). |
| 1093 | widget.showNormal(); |
| 1094 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1095 | QCOMPARE(widget.isFullScreen(), false); |
| 1096 | QCOMPARE(spy.count(), 4); |
| 1097 | QCOMPARE(spy.value(3).value(0).toBool(), false); |
| 1098 | QCOMPARE(widget.windowFlags(), windowFlags); |
| 1099 | |
| 1100 | // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. |
| 1101 | widget.setFullScreen(false); |
| 1102 | QCOMPARE(widget.isFullScreen(), false); |
| 1103 | QCOMPARE(spy.count(), 4); |
| 1104 | widget.showNormal(); |
| 1105 | QCOMPARE(widget.isFullScreen(), false); |
| 1106 | QCOMPARE(spy.count(), 4); |
| 1107 | |
| 1108 | // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. |
| 1109 | widget.showFullScreen(); |
| 1110 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1111 | widget.setFullScreen(true); |
| 1112 | QCOMPARE(widget.isFullScreen(), true); |
| 1113 | QCOMPARE(spy.count(), 5); |
| 1114 | widget.showFullScreen(); |
| 1115 | QCOMPARE(widget.isFullScreen(), true); |
| 1116 | QCOMPARE(spy.count(), 5); |
| 1117 | } |
| 1118 | |
| 1119 | |
| 1120 | void tst_QVideoWidget::color_data() |
| 1121 | { |
| 1122 | QTest::addColumn<int>(name: "controlValue" ); |
| 1123 | QTest::addColumn<int>(name: "value" ); |
| 1124 | QTest::addColumn<int>(name: "expectedValue" ); |
| 1125 | |
| 1126 | QTest::newRow(dataTag: "12" ) |
| 1127 | << 0 |
| 1128 | << 12 |
| 1129 | << 12; |
| 1130 | QTest::newRow(dataTag: "-56" ) |
| 1131 | << 87 |
| 1132 | << -56 |
| 1133 | << -56; |
| 1134 | QTest::newRow(dataTag: "100" ) |
| 1135 | << 32 |
| 1136 | << 100 |
| 1137 | << 100; |
| 1138 | QTest::newRow(dataTag: "1294" ) |
| 1139 | << 0 |
| 1140 | << 1294 |
| 1141 | << 100; |
| 1142 | QTest::newRow(dataTag: "-102" ) |
| 1143 | << 34 |
| 1144 | << -102 |
| 1145 | << -100; |
| 1146 | } |
| 1147 | |
| 1148 | void tst_QVideoWidget::brightnessWindowControl() |
| 1149 | { |
| 1150 | QFETCH(int, controlValue); |
| 1151 | QFETCH(int, value); |
| 1152 | QFETCH(int, expectedValue); |
| 1153 | |
| 1154 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 1155 | object.testService->windowControl->setBrightness(controlValue); |
| 1156 | |
| 1157 | QtTestVideoWidget widget; |
| 1158 | object.bind(&widget); |
| 1159 | widget.show(); |
| 1160 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1161 | |
| 1162 | // Test the video widget resets the controls starting brightness to the default. |
| 1163 | QCOMPARE(widget.brightness(), 0); |
| 1164 | |
| 1165 | QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); |
| 1166 | |
| 1167 | // Test the video widget sets the brightness value, bounded if necessary and emits a changed |
| 1168 | // signal. |
| 1169 | widget.setBrightness(value); |
| 1170 | QCOMPARE(widget.brightness(), expectedValue); |
| 1171 | QCOMPARE(object.testService->windowControl->brightness(), expectedValue); |
| 1172 | QCOMPARE(spy.count(), 1); |
| 1173 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1174 | |
| 1175 | // Test the changed signal isn't emitted if the value is unchanged. |
| 1176 | widget.setBrightness(value); |
| 1177 | QCOMPARE(widget.brightness(), expectedValue); |
| 1178 | QCOMPARE(object.testService->windowControl->brightness(), expectedValue); |
| 1179 | QCOMPARE(spy.count(), 1); |
| 1180 | |
| 1181 | // Test the changed signal is emitted if the brightness is changed internally. |
| 1182 | object.testService->windowControl->setBrightness(controlValue); |
| 1183 | QCOMPARE(widget.brightness(), controlValue); |
| 1184 | QCOMPARE(spy.count(), 2); |
| 1185 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1186 | } |
| 1187 | |
| 1188 | void tst_QVideoWidget::brightnessWidgetControl() |
| 1189 | { |
| 1190 | #ifdef Q_OS_MAC |
| 1191 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1192 | #endif |
| 1193 | |
| 1194 | QFETCH(int, controlValue); |
| 1195 | QFETCH(int, value); |
| 1196 | QFETCH(int, expectedValue); |
| 1197 | |
| 1198 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 1199 | object.testService->widgetControl->setBrightness(controlValue); |
| 1200 | |
| 1201 | QtTestVideoWidget widget; |
| 1202 | object.bind(&widget); |
| 1203 | |
| 1204 | QCOMPARE(widget.brightness(), 0); |
| 1205 | |
| 1206 | widget.show(); |
| 1207 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1208 | |
| 1209 | QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); |
| 1210 | |
| 1211 | widget.setBrightness(value); |
| 1212 | QCOMPARE(widget.brightness(), expectedValue); |
| 1213 | QCOMPARE(object.testService->widgetControl->brightness(), expectedValue); |
| 1214 | QCOMPARE(spy.count(), 1); |
| 1215 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1216 | |
| 1217 | widget.setBrightness(value); |
| 1218 | QCOMPARE(widget.brightness(), expectedValue); |
| 1219 | QCOMPARE(object.testService->widgetControl->brightness(), expectedValue); |
| 1220 | QCOMPARE(spy.count(), 1); |
| 1221 | |
| 1222 | object.testService->widgetControl->setBrightness(controlValue); |
| 1223 | QCOMPARE(widget.brightness(), controlValue); |
| 1224 | QCOMPARE(spy.count(), 2); |
| 1225 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1226 | } |
| 1227 | |
| 1228 | void tst_QVideoWidget::brightnessRendererControl() |
| 1229 | { |
| 1230 | #ifdef Q_OS_MAC |
| 1231 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1232 | #endif |
| 1233 | |
| 1234 | QFETCH(int, value); |
| 1235 | QFETCH(int, expectedValue); |
| 1236 | |
| 1237 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1238 | |
| 1239 | QtTestVideoWidget widget; |
| 1240 | object.bind(&widget); |
| 1241 | widget.show(); |
| 1242 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1243 | |
| 1244 | QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); |
| 1245 | |
| 1246 | widget.setBrightness(value); |
| 1247 | QCOMPARE(widget.brightness(), expectedValue); |
| 1248 | QCOMPARE(spy.count(), 1); |
| 1249 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1250 | |
| 1251 | widget.setBrightness(value); |
| 1252 | QCOMPARE(widget.brightness(), expectedValue); |
| 1253 | QCOMPARE(spy.count(), 1); |
| 1254 | } |
| 1255 | |
| 1256 | void tst_QVideoWidget::contrastWindowControl() |
| 1257 | { |
| 1258 | QFETCH(int, controlValue); |
| 1259 | QFETCH(int, value); |
| 1260 | QFETCH(int, expectedValue); |
| 1261 | |
| 1262 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 1263 | object.testService->windowControl->setContrast(controlValue); |
| 1264 | |
| 1265 | QtTestVideoWidget widget; |
| 1266 | object.bind(&widget); |
| 1267 | |
| 1268 | QCOMPARE(widget.contrast(), 0); |
| 1269 | |
| 1270 | widget.show(); |
| 1271 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1272 | QCOMPARE(widget.contrast(), 0); |
| 1273 | |
| 1274 | QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); |
| 1275 | |
| 1276 | widget.setContrast(value); |
| 1277 | QCOMPARE(widget.contrast(), expectedValue); |
| 1278 | QCOMPARE(object.testService->windowControl->contrast(), expectedValue); |
| 1279 | QCOMPARE(spy.count(), 1); |
| 1280 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1281 | |
| 1282 | widget.setContrast(value); |
| 1283 | QCOMPARE(widget.contrast(), expectedValue); |
| 1284 | QCOMPARE(object.testService->windowControl->contrast(), expectedValue); |
| 1285 | QCOMPARE(spy.count(), 1); |
| 1286 | |
| 1287 | object.testService->windowControl->setContrast(controlValue); |
| 1288 | QCOMPARE(widget.contrast(), controlValue); |
| 1289 | QCOMPARE(spy.count(), 2); |
| 1290 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1291 | } |
| 1292 | |
| 1293 | void tst_QVideoWidget::contrastWidgetControl() |
| 1294 | { |
| 1295 | #ifdef Q_OS_MAC |
| 1296 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1297 | #endif |
| 1298 | |
| 1299 | QFETCH(int, controlValue); |
| 1300 | QFETCH(int, value); |
| 1301 | QFETCH(int, expectedValue); |
| 1302 | |
| 1303 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 1304 | object.testService->widgetControl->setContrast(controlValue); |
| 1305 | |
| 1306 | QtTestVideoWidget widget; |
| 1307 | object.bind(&widget); |
| 1308 | QCOMPARE(widget.contrast(), 0); |
| 1309 | |
| 1310 | widget.show(); |
| 1311 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1312 | QCOMPARE(widget.contrast(), 0); |
| 1313 | |
| 1314 | QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); |
| 1315 | |
| 1316 | widget.setContrast(value); |
| 1317 | QCOMPARE(widget.contrast(), expectedValue); |
| 1318 | QCOMPARE(object.testService->widgetControl->contrast(), expectedValue); |
| 1319 | QCOMPARE(spy.count(), 1); |
| 1320 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1321 | |
| 1322 | widget.setContrast(value); |
| 1323 | QCOMPARE(widget.contrast(), expectedValue); |
| 1324 | QCOMPARE(object.testService->widgetControl->contrast(), expectedValue); |
| 1325 | QCOMPARE(spy.count(), 1); |
| 1326 | |
| 1327 | object.testService->widgetControl->setContrast(controlValue); |
| 1328 | QCOMPARE(widget.contrast(), controlValue); |
| 1329 | QCOMPARE(spy.count(), 2); |
| 1330 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1331 | } |
| 1332 | |
| 1333 | void tst_QVideoWidget::contrastRendererControl() |
| 1334 | { |
| 1335 | #ifdef Q_OS_MAC |
| 1336 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1337 | #endif |
| 1338 | |
| 1339 | QFETCH(int, value); |
| 1340 | QFETCH(int, expectedValue); |
| 1341 | |
| 1342 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1343 | |
| 1344 | QtTestVideoWidget widget; |
| 1345 | object.bind(&widget); |
| 1346 | widget.show(); |
| 1347 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1348 | |
| 1349 | QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); |
| 1350 | |
| 1351 | widget.setContrast(value); |
| 1352 | QCOMPARE(widget.contrast(), expectedValue); |
| 1353 | QCOMPARE(spy.count(), 1); |
| 1354 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1355 | |
| 1356 | widget.setContrast(value); |
| 1357 | QCOMPARE(widget.contrast(), expectedValue); |
| 1358 | QCOMPARE(spy.count(), 1); |
| 1359 | } |
| 1360 | |
| 1361 | void tst_QVideoWidget::hueWindowControl() |
| 1362 | { |
| 1363 | QFETCH(int, controlValue); |
| 1364 | QFETCH(int, value); |
| 1365 | QFETCH(int, expectedValue); |
| 1366 | |
| 1367 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 1368 | object.testService->windowControl->setHue(controlValue); |
| 1369 | |
| 1370 | QtTestVideoWidget widget; |
| 1371 | object.bind(&widget); |
| 1372 | QCOMPARE(widget.hue(), 0); |
| 1373 | |
| 1374 | widget.show(); |
| 1375 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1376 | QCOMPARE(widget.hue(), 0); |
| 1377 | |
| 1378 | QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); |
| 1379 | |
| 1380 | widget.setHue(value); |
| 1381 | QCOMPARE(widget.hue(), expectedValue); |
| 1382 | QCOMPARE(object.testService->windowControl->hue(), expectedValue); |
| 1383 | QCOMPARE(spy.count(), 1); |
| 1384 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1385 | |
| 1386 | widget.setHue(value); |
| 1387 | QCOMPARE(widget.hue(), expectedValue); |
| 1388 | QCOMPARE(object.testService->windowControl->hue(), expectedValue); |
| 1389 | QCOMPARE(spy.count(), 1); |
| 1390 | |
| 1391 | object.testService->windowControl->setHue(controlValue); |
| 1392 | QCOMPARE(widget.hue(), controlValue); |
| 1393 | QCOMPARE(spy.count(), 2); |
| 1394 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1395 | } |
| 1396 | |
| 1397 | void tst_QVideoWidget::hueWidgetControl() |
| 1398 | { |
| 1399 | #ifdef Q_OS_MAC |
| 1400 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1401 | #endif |
| 1402 | |
| 1403 | QFETCH(int, controlValue); |
| 1404 | QFETCH(int, value); |
| 1405 | QFETCH(int, expectedValue); |
| 1406 | |
| 1407 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 1408 | object.testService->widgetControl->setHue(controlValue); |
| 1409 | |
| 1410 | QtTestVideoWidget widget; |
| 1411 | object.bind(&widget); |
| 1412 | QCOMPARE(widget.hue(), 0); |
| 1413 | |
| 1414 | widget.show(); |
| 1415 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1416 | QCOMPARE(widget.hue(), 0); |
| 1417 | |
| 1418 | QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); |
| 1419 | |
| 1420 | widget.setHue(value); |
| 1421 | QCOMPARE(widget.hue(), expectedValue); |
| 1422 | QCOMPARE(object.testService->widgetControl->hue(), expectedValue); |
| 1423 | QCOMPARE(spy.count(), 1); |
| 1424 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1425 | |
| 1426 | widget.setHue(value); |
| 1427 | QCOMPARE(widget.hue(), expectedValue); |
| 1428 | QCOMPARE(object.testService->widgetControl->hue(), expectedValue); |
| 1429 | QCOMPARE(spy.count(), 1); |
| 1430 | |
| 1431 | object.testService->widgetControl->setHue(controlValue); |
| 1432 | QCOMPARE(widget.hue(), controlValue); |
| 1433 | QCOMPARE(spy.count(), 2); |
| 1434 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1435 | } |
| 1436 | |
| 1437 | void tst_QVideoWidget::hueRendererControl() |
| 1438 | { |
| 1439 | #ifdef Q_OS_MAC |
| 1440 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1441 | #endif |
| 1442 | |
| 1443 | QFETCH(int, value); |
| 1444 | QFETCH(int, expectedValue); |
| 1445 | |
| 1446 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1447 | |
| 1448 | QtTestVideoWidget widget; |
| 1449 | object.bind(&widget); |
| 1450 | widget.show(); |
| 1451 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1452 | |
| 1453 | QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); |
| 1454 | |
| 1455 | widget.setHue(value); |
| 1456 | QCOMPARE(widget.hue(), expectedValue); |
| 1457 | QCOMPARE(spy.count(), 1); |
| 1458 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1459 | |
| 1460 | widget.setHue(value); |
| 1461 | QCOMPARE(widget.hue(), expectedValue); |
| 1462 | QCOMPARE(spy.count(), 1); |
| 1463 | } |
| 1464 | |
| 1465 | void tst_QVideoWidget::saturationWindowControl() |
| 1466 | { |
| 1467 | QFETCH(int, controlValue); |
| 1468 | QFETCH(int, value); |
| 1469 | QFETCH(int, expectedValue); |
| 1470 | |
| 1471 | QtTestVideoObject object(new QtTestWindowControl, 0, 0); |
| 1472 | object.testService->windowControl->setSaturation(controlValue); |
| 1473 | |
| 1474 | QtTestVideoWidget widget; |
| 1475 | object.bind(&widget); |
| 1476 | QCOMPARE(widget.saturation(), 0); |
| 1477 | widget.show(); |
| 1478 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1479 | QCOMPARE(widget.saturation(), 0); |
| 1480 | |
| 1481 | QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); |
| 1482 | |
| 1483 | widget.setSaturation(value); |
| 1484 | QCOMPARE(widget.saturation(), expectedValue); |
| 1485 | QCOMPARE(object.testService->windowControl->saturation(), expectedValue); |
| 1486 | QCOMPARE(spy.count(), 1); |
| 1487 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1488 | |
| 1489 | widget.setSaturation(value); |
| 1490 | QCOMPARE(widget.saturation(), expectedValue); |
| 1491 | QCOMPARE(object.testService->windowControl->saturation(), expectedValue); |
| 1492 | QCOMPARE(spy.count(), 1); |
| 1493 | |
| 1494 | object.testService->windowControl->setSaturation(controlValue); |
| 1495 | QCOMPARE(widget.saturation(), controlValue); |
| 1496 | QCOMPARE(spy.count(), 2); |
| 1497 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1498 | } |
| 1499 | |
| 1500 | void tst_QVideoWidget::saturationWidgetControl() |
| 1501 | { |
| 1502 | #ifdef Q_OS_MAC |
| 1503 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1504 | #endif |
| 1505 | |
| 1506 | QFETCH(int, controlValue); |
| 1507 | QFETCH(int, value); |
| 1508 | QFETCH(int, expectedValue); |
| 1509 | |
| 1510 | QtTestVideoObject object(0, new QtTestWidgetControl, 0); |
| 1511 | object.testService->widgetControl->setSaturation(controlValue); |
| 1512 | |
| 1513 | QtTestVideoWidget widget; |
| 1514 | object.bind(&widget); |
| 1515 | |
| 1516 | QCOMPARE(widget.saturation(), 0); |
| 1517 | widget.show(); |
| 1518 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1519 | QCOMPARE(widget.saturation(), 0); |
| 1520 | |
| 1521 | QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); |
| 1522 | |
| 1523 | widget.setSaturation(value); |
| 1524 | QCOMPARE(widget.saturation(), expectedValue); |
| 1525 | QCOMPARE(object.testService->widgetControl->saturation(), expectedValue); |
| 1526 | QCOMPARE(spy.count(), 1); |
| 1527 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1528 | |
| 1529 | widget.setSaturation(value); |
| 1530 | QCOMPARE(widget.saturation(), expectedValue); |
| 1531 | QCOMPARE(object.testService->widgetControl->saturation(), expectedValue); |
| 1532 | QCOMPARE(spy.count(), 1); |
| 1533 | |
| 1534 | object.testService->widgetControl->setSaturation(controlValue); |
| 1535 | QCOMPARE(widget.saturation(), controlValue); |
| 1536 | QCOMPARE(spy.count(), 2); |
| 1537 | QCOMPARE(spy.value(1).value(0).toInt(), controlValue); |
| 1538 | |
| 1539 | } |
| 1540 | |
| 1541 | void tst_QVideoWidget::saturationRendererControl() |
| 1542 | { |
| 1543 | #ifdef Q_OS_MAC |
| 1544 | QSKIP("QTBUG-26481 - Crashes on Mac" ); |
| 1545 | #endif |
| 1546 | |
| 1547 | QFETCH(int, value); |
| 1548 | QFETCH(int, expectedValue); |
| 1549 | |
| 1550 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1551 | |
| 1552 | QtTestVideoWidget widget; |
| 1553 | object.bind(&widget); |
| 1554 | widget.show(); |
| 1555 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1556 | QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); |
| 1557 | |
| 1558 | widget.setSaturation(value); |
| 1559 | QCOMPARE(widget.saturation(), expectedValue); |
| 1560 | QCOMPARE(spy.count(), 1); |
| 1561 | QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); |
| 1562 | |
| 1563 | widget.setSaturation(value); |
| 1564 | QCOMPARE(widget.saturation(), expectedValue); |
| 1565 | QCOMPARE(spy.count(), 1); |
| 1566 | } |
| 1567 | |
| 1568 | static const uchar rgb32ImageData[] = |
| 1569 | { |
| 1570 | 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, |
| 1571 | 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 |
| 1572 | }; |
| 1573 | |
| 1574 | void tst_QVideoWidget::paintRendererControl() |
| 1575 | { |
| 1576 | QtTestVideoObject object(0, 0, new QtTestRendererControl); |
| 1577 | |
| 1578 | QtTestVideoWidget widget; |
| 1579 | object.bind(&widget); |
| 1580 | widget.resize(w: 640,h: 480); |
| 1581 | widget.show(); |
| 1582 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1583 | |
| 1584 | QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>( |
| 1585 | object: object.testService->rendererControl->surface()); |
| 1586 | |
| 1587 | QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); |
| 1588 | |
| 1589 | QVERIFY(surface->start(format)); |
| 1590 | QCOMPARE(surface->isActive(), true); |
| 1591 | QCOMPARE(surface->isReady(), true); |
| 1592 | |
| 1593 | QCoreApplication::processEvents(flags: QEventLoop::AllEvents); |
| 1594 | |
| 1595 | QCOMPARE(surface->isActive(), true); |
| 1596 | QCOMPARE(surface->isReady(), true); |
| 1597 | |
| 1598 | QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); |
| 1599 | |
| 1600 | frame.map(mode: QAbstractVideoBuffer::WriteOnly); |
| 1601 | memcpy(dest: frame.bits(), src: rgb32ImageData, n: frame.mappedBytes()); |
| 1602 | frame.unmap(); |
| 1603 | |
| 1604 | QVERIFY(surface->present(frame)); |
| 1605 | QCOMPARE(surface->isActive(), true); |
| 1606 | QCOMPARE(surface->isReady(), false); |
| 1607 | |
| 1608 | QTRY_COMPARE(surface->isReady(), true); |
| 1609 | QCOMPARE(surface->isActive(), true); |
| 1610 | QCOMPARE(surface->isReady(), true); |
| 1611 | } |
| 1612 | |
| 1613 | void tst_QVideoWidget::paintSurface() |
| 1614 | { |
| 1615 | QtTestVideoWidget widget; |
| 1616 | widget.resize(w: 640,h: 480); |
| 1617 | widget.show(); |
| 1618 | QVERIFY(QTest::qWaitForWindowExposed(&widget)); |
| 1619 | |
| 1620 | QVERIFY(widget.videoSurface()); |
| 1621 | auto surface = qobject_cast<QPainterVideoSurface *>( |
| 1622 | object: widget.videoSurface()); |
| 1623 | QVERIFY(surface); |
| 1624 | |
| 1625 | QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); |
| 1626 | QVERIFY(surface->start(format)); |
| 1627 | QCOMPARE(surface->isActive(), true); |
| 1628 | |
| 1629 | QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); |
| 1630 | frame.map(mode: QAbstractVideoBuffer::WriteOnly); |
| 1631 | memcpy(dest: frame.bits(), src: rgb32ImageData, n: frame.mappedBytes()); |
| 1632 | frame.unmap(); |
| 1633 | |
| 1634 | QVERIFY(surface->present(frame)); |
| 1635 | QCOMPARE(surface->isReady(), false); |
| 1636 | QTRY_COMPARE(surface->isReady(), true); |
| 1637 | QCOMPARE(surface->isActive(), true); |
| 1638 | QCOMPARE(surface->isReady(), true); |
| 1639 | } |
| 1640 | |
| 1641 | QTEST_MAIN(tst_QVideoWidget) |
| 1642 | |
| 1643 | #include "tst_qvideowidget.moc" |
| 1644 | |