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