qtmobility/tests/auto/qvideowidget/tst_qvideowidget.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    42 #include <qmobilityglobal.h>
    42 #include <qmobilityglobal.h>
    43 #include <QtTest/QtTest>
    43 #include <QtTest/QtTest>
    44 
    44 
    45 #include "../../../src/multimedia/qvideowidget.h"
    45 #include "../../../src/multimedia/qvideowidget.h"
    46 
    46 
    47 #include "../../../src/multimedia/qmediaobject.h"
    47 #include "qmediaobject.h"
    48 #include "../../../src/multimedia/qmediaservice.h"
    48 #include "qmediaservice.h"
    49 #include "../../../src/multimedia/qpaintervideosurface_p.h"
    49 #include "qpaintervideosurface_p.h"
    50 #include "../../../src/multimedia/qvideooutputcontrol.h"
    50 #include "qvideowindowcontrol.h"
    51 #include "../../../src/multimedia/qvideowindowcontrol.h"
    51 #include "qvideowidgetcontrol.h"
    52 #include "../../../src/multimedia/qvideowidgetcontrol.h"
    52 
    53 
    53 #include "qvideorenderercontrol.h"
    54 #include "../../../src/multimedia/qvideorenderercontrol.h"
    54 #include <qabstractvideosurface.h>
    55 #include <QtMultimedia/qabstractvideosurface.h>
    55 #include <qvideosurfaceformat.h>
    56 #include <QtMultimedia/qvideosurfaceformat.h>
       
    57 
    56 
    58 #include <QtGui/qapplication.h>
    57 #include <QtGui/qapplication.h>
    59 
    58 
    60 QT_USE_NAMESPACE
    59 QT_USE_NAMESPACE
    61 class tst_QVideoWidget : public QObject
    60 class tst_QVideoWidget : public QObject
    62 {
    61 {
    63     Q_OBJECT
    62     Q_OBJECT
    64 private slots:
    63 private slots:
    65     void nullObject();
    64     void nullObject();
    66     void nullService();
    65     void nullService();
    67     void nullOutputControl();
       
    68     void noOutputs();
    66     void noOutputs();
    69     void serviceDestroyed();
    67     void serviceDestroyed();
    70     void objectDestroyed();
    68     void objectDestroyed();
    71     void setMediaObject();
    69     void setMediaObject();
    72 
    70 
   119     void color_data();
   117     void color_data();
   120 };
   118 };
   121 
   119 
   122 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
   120 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
   123 Q_DECLARE_METATYPE(const uchar *)
   121 Q_DECLARE_METATYPE(const uchar *)
   124 
       
   125 class QtTestOutputControl : public QVideoOutputControl
       
   126 {
       
   127 public:
       
   128     QtTestOutputControl() : m_output(NoOutput) {}
       
   129 
       
   130     QList<Output> availableOutputs() const { return m_outputs; }
       
   131     void setAvailableOutputs(const QList<Output> outputs) { m_outputs = outputs; }
       
   132 
       
   133     Output output() const { return m_output; }
       
   134     virtual void setOutput(Output output) { m_output = output; }
       
   135 
       
   136 private:
       
   137     Output m_output;
       
   138     QList<Output> m_outputs;
       
   139 };
       
   140 
   122 
   141 class QtTestWindowControl : public QVideoWindowControl
   123 class QtTestWindowControl : public QVideoWindowControl
   142 {
   124 {
   143 public:
   125 public:
   144     QtTestWindowControl()
   126     QtTestWindowControl()
   267 class QtTestVideoService : public QMediaService
   249 class QtTestVideoService : public QMediaService
   268 {
   250 {
   269     Q_OBJECT
   251     Q_OBJECT
   270 public:
   252 public:
   271     QtTestVideoService(
   253     QtTestVideoService(
   272             QtTestOutputControl *output,
       
   273             QtTestWindowControl *window,
   254             QtTestWindowControl *window,
   274             QtTestWidgetControl *widget,
   255             QtTestWidgetControl *widget,
   275             QtTestRendererControl *renderer)
   256             QtTestRendererControl *renderer)
   276         : QMediaService(0)
   257         : QMediaService(0)
   277         , outputControl(output)
   258         , windowRef(0)
       
   259         , widgetRef(0)
       
   260         , rendererRef(0)
   278         , windowControl(window)
   261         , windowControl(window)
   279         , widgetControl(widget)
   262         , widgetControl(widget)
   280         , rendererControl(renderer)
   263         , rendererControl(renderer)
   281     {
   264     {
   282     }
   265     }
   283 
   266 
   284     ~QtTestVideoService()
   267     ~QtTestVideoService()
   285     {
   268     {
   286         delete outputControl;
       
   287         delete windowControl;
   269         delete windowControl;
   288         delete widgetControl;
   270         delete widgetControl;
   289         delete rendererControl;
   271         delete rendererControl;
   290     }
   272     }
   291 
   273 
   292     QMediaControl *control(const char *name) const
   274     QMediaControl *requestControl(const char *name)
   293     {
   275     {
   294         if (qstrcmp(name, QVideoOutputControl_iid) == 0)
   276         if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
   295             return outputControl;
   277             if (windowControl) {
   296         else if (qstrcmp(name, QVideoWindowControl_iid) == 0)
   278                 windowRef += 1;
   297             return windowControl;
   279 
   298         else if (qstrcmp(name, QVideoWidgetControl_iid) == 0)
   280                 return windowControl;
   299             return widgetControl;
   281             }
   300         else if (qstrcmp(name, QVideoRendererControl_iid) == 0)
   282         } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
   301             return rendererControl;
   283             if (widgetControl) {
   302         else
   284                 widgetRef += 1;
   303             return 0;
   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;
   304     }
   296     }
   305 
   297 
   306     QtTestOutputControl *outputControl;
   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 
   307     QtTestWindowControl *windowControl;
   314     QtTestWindowControl *windowControl;
   308     QtTestWidgetControl *widgetControl;
   315     QtTestWidgetControl *widgetControl;
   309     QtTestRendererControl *rendererControl;
   316     QtTestRendererControl *rendererControl;
   310 };
   317 };
   311 
   318 
   315 public:
   322 public:
   316     QtTestVideoObject(
   323     QtTestVideoObject(
   317             QtTestWindowControl *window,
   324             QtTestWindowControl *window,
   318             QtTestWidgetControl *widget,
   325             QtTestWidgetControl *widget,
   319             QtTestRendererControl *renderer):
   326             QtTestRendererControl *renderer):
   320         QMediaObject(0, new QtTestVideoService(new QtTestOutputControl, window, widget, renderer))
   327         QMediaObject(0, new QtTestVideoService(window, widget, renderer))
   321     {
   328     {
   322         testService = qobject_cast<QtTestVideoService*>(service());
   329         testService = qobject_cast<QtTestVideoService*>(service());
   323         QList<QVideoOutputControl::Output> outputs;
       
   324 
       
   325         if (window)
       
   326             outputs.append(QVideoOutputControl::WindowOutput);
       
   327         if (widget)
       
   328             outputs.append(QVideoOutputControl::WidgetOutput);
       
   329         if (renderer)
       
   330             outputs.append(QVideoOutputControl::RendererOutput);
       
   331 
       
   332         testService->outputControl->setAvailableOutputs(outputs);
       
   333     }
   330     }
   334 
   331 
   335     QtTestVideoObject(QtTestVideoService *service):
   332     QtTestVideoObject(QtTestVideoService *service):
   336         QMediaObject(0, service),
   333         QMediaObject(0, service),
   337         testService(service)
   334         testService(service)
   430 void tst_QVideoWidget::nullService()
   427 void tst_QVideoWidget::nullService()
   431 {
   428 {
   432     QtTestVideoObject object(0);
   429     QtTestVideoObject object(0);
   433 
   430 
   434     QVideoWidget widget;
   431     QVideoWidget widget;
   435     widget.setMediaObject(&object);
   432     object.bind(&widget);
   436 
   433 
   437     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   434     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   438 
   435 
   439     QVERIFY(widget.sizeHint().isEmpty());
   436     QVERIFY(widget.sizeHint().isEmpty());
   440 
   437 
   456 
   453 
   457     widget.setSaturation(100);
   454     widget.setSaturation(100);
   458     QCOMPARE(widget.saturation(), 100);
   455     QCOMPARE(widget.saturation(), 100);
   459 }
   456 }
   460 
   457 
   461 void tst_QVideoWidget::nullOutputControl()
   458 void tst_QVideoWidget::noOutputs()
   462 {
   459 {
   463     QtTestVideoObject object(new QtTestVideoService(0, 0, 0, 0));
   460     QtTestVideoObject object(0, 0, 0);
   464 
   461 
   465     QVideoWidget widget;
   462     QVideoWidget widget;
   466     widget.setMediaObject(&object);
   463     object.bind(&widget);
   467     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   464     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   468 
   465 
   469     QVERIFY(widget.sizeHint().isEmpty());
   466     QVERIFY(widget.sizeHint().isEmpty());
   470 
   467 
   471     widget.setFullScreen(true);
   468     widget.setFullScreen(true);
   472     QTest::qWaitForWindowShown(&widget);
       
   473     QCOMPARE(widget.isFullScreen(), true);
   469     QCOMPARE(widget.isFullScreen(), true);
   474 
   470 
   475     widget.setBrightness(100);
   471     widget.setBrightness(100);
   476     QCOMPARE(widget.brightness(), 100);
   472     QCOMPARE(widget.brightness(), 100);
   477 
   473 
   483 
   479 
   484     widget.setSaturation(100);
   480     widget.setSaturation(100);
   485     QCOMPARE(widget.saturation(), 100);
   481     QCOMPARE(widget.saturation(), 100);
   486 }
   482 }
   487 
   483 
   488 void tst_QVideoWidget::noOutputs()
       
   489 {
       
   490     QtTestVideoObject object(0, 0, 0);
       
   491 
       
   492     QVideoWidget widget;
       
   493     widget.setMediaObject(&object);
       
   494     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
       
   495 
       
   496     QVERIFY(widget.sizeHint().isEmpty());
       
   497 
       
   498     widget.setFullScreen(true);
       
   499     QCOMPARE(widget.isFullScreen(), true);
       
   500 
       
   501     widget.setBrightness(100);
       
   502     QCOMPARE(widget.brightness(), 100);
       
   503 
       
   504     widget.setContrast(100);
       
   505     QCOMPARE(widget.contrast(), 100);
       
   506 
       
   507     widget.setHue(100);
       
   508     QCOMPARE(widget.hue(), 100);
       
   509 
       
   510     widget.setSaturation(100);
       
   511     QCOMPARE(widget.saturation(), 100);
       
   512 }
       
   513 
       
   514 void tst_QVideoWidget::serviceDestroyed()
   484 void tst_QVideoWidget::serviceDestroyed()
   515 {
   485 {
   516     QtTestVideoObject object(new QtTestWindowControl, new QtTestWidgetControl, 0);
   486     QtTestVideoObject object(new QtTestWindowControl, new QtTestWidgetControl, 0);
   517 
   487 
   518     QVideoWidget widget;
   488     QVideoWidget widget;
   519     widget.setMediaObject(&object);
   489     object.bind(&widget);
   520     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   490     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   521 
   491 
   522     widget.show();
   492     widget.show();
   523     QTest::qWaitForWindowShown(&widget);
   493     QTest::qWaitForWindowShown(&widget);
   524 
   494 
   547             new QtTestWindowControl,
   517             new QtTestWindowControl,
   548             new QtTestWidgetControl,
   518             new QtTestWidgetControl,
   549             0);
   519             0);
   550 
   520 
   551     QVideoWidget widget;
   521     QVideoWidget widget;
   552     widget.setMediaObject(object);
   522     object->bind(&widget);
   553     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   523     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
       
   524 
       
   525     QCOMPARE(object->testService->windowRef, 0);
       
   526     QCOMPARE(object->testService->widgetRef, 1);
       
   527     QCOMPARE(object->testService->rendererRef, 0);
   554 
   528 
   555     widget.show();
   529     widget.show();
   556     QTest::qWaitForWindowShown(&widget);
   530     QTest::qWaitForWindowShown(&widget);
   557 
   531 
   558     widget.setBrightness(100);
   532     widget.setBrightness(100);
   567     delete object;
   541     delete object;
   568     object = 0;
   542     object = 0;
   569 
   543 
   570     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(object));
   544     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(object));
   571 
   545 
   572     QCOMPARE(service->outputControl->output(), QVideoOutputControl::NoOutput);
       
   573 
       
   574     QCOMPARE(widget.brightness(), 100);
   546     QCOMPARE(widget.brightness(), 100);
   575     QCOMPARE(widget.contrast(), 100);
   547     QCOMPARE(widget.contrast(), 100);
   576     QCOMPARE(widget.hue(), 100);
   548     QCOMPARE(widget.hue(), 100);
   577     QCOMPARE(widget.saturation(), 100);
   549     QCOMPARE(widget.saturation(), 100);
   578 
   550 
   594 
   566 
   595     widget.show();
   567     widget.show();
   596     QTest::qWaitForWindowShown(&widget);
   568     QTest::qWaitForWindowShown(&widget);
   597 
   569 
   598     QCOMPARE(widget.mediaObject(), nullObject);
   570     QCOMPARE(widget.mediaObject(), nullObject);
   599     QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   571     QCOMPARE(windowObject.testService->windowRef, 0);
   600     QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   572     QCOMPARE(widgetObject.testService->widgetRef, 0);
   601     QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   573     QCOMPARE(rendererObject.testService->rendererRef, 0);
   602 
   574 
   603     widget.setMediaObject(&windowObject);
   575     windowObject.bind(&widget);
   604     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&windowObject));
   576     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&windowObject));
   605     QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
   577     QCOMPARE(windowObject.testService->windowRef, 1);
       
   578     QCOMPARE(widgetObject.testService->widgetRef, 0);
       
   579     QCOMPARE(rendererObject.testService->rendererRef, 0);
   606     QVERIFY(windowObject.testService->windowControl->winId() != 0);
   580     QVERIFY(windowObject.testService->windowControl->winId() != 0);
   607 
   581 
   608 
   582 
   609     widget.setMediaObject(&widgetObject);
   583     widgetObject.bind(&widget);
   610     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&widgetObject));
   584     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&widgetObject));
   611     QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
   585     QCOMPARE(windowObject.testService->windowRef, 0);
       
   586     QCOMPARE(widgetObject.testService->widgetRef, 1);
       
   587     QCOMPARE(rendererObject.testService->rendererRef, 0);
   612 
   588 
   613     QCoreApplication::processEvents(QEventLoop::AllEvents);
   589     QCoreApplication::processEvents(QEventLoop::AllEvents);
   614     QCOMPARE(widgetObject.testService->widgetControl->videoWidget()->isVisible(), true);
   590     QCOMPARE(widgetObject.testService->widgetControl->videoWidget()->isVisible(), true);
   615 
   591 
   616     QCOMPARE(windowObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   592     QCOMPARE(windowObject.testService->windowRef, 0);
   617 
   593     QCOMPARE(widgetObject.testService->widgetRef, 1);
   618     widget.setMediaObject(&rendererObject);
   594     QCOMPARE(rendererObject.testService->rendererRef, 0);
       
   595 
       
   596     rendererObject.bind(&widget);
   619     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&rendererObject));
   597     QCOMPARE(widget.mediaObject(), static_cast<QMediaObject *>(&rendererObject));
   620     QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
   598 
       
   599     QCOMPARE(windowObject.testService->windowRef, 0);
       
   600     QCOMPARE(widgetObject.testService->widgetRef, 0);
       
   601     QCOMPARE(rendererObject.testService->rendererRef, 1);
   621     QVERIFY(rendererObject.testService->rendererControl->surface() != 0);
   602     QVERIFY(rendererObject.testService->rendererControl->surface() != 0);
   622 
   603 
   623     QCOMPARE(widgetObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   604     rendererObject.unbind(&widget);
   624 
       
   625     widget.setMediaObject(0);
       
   626     QCOMPARE(widget.mediaObject(), nullObject);
   605     QCOMPARE(widget.mediaObject(), nullObject);
   627 
   606 
   628     QCOMPARE(rendererObject.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   607     QCOMPARE(windowObject.testService->windowRef, 0);
       
   608     QCOMPARE(widgetObject.testService->widgetRef, 0);
       
   609     QCOMPARE(rendererObject.testService->rendererRef, 0);
   629 }
   610 }
   630 
   611 
   631 void tst_QVideoWidget::showWindowControl()
   612 void tst_QVideoWidget::showWindowControl()
   632 {
   613 {
   633     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   614     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   634     object.testService->windowControl->setNativeSize(QSize(240, 180));
   615     object.testService->windowControl->setNativeSize(QSize(240, 180));
   635 
   616 
   636     QVideoWidget widget;
   617     QVideoWidget widget;
   637     widget.setMediaObject(&object);
   618     object.bind(&widget);
   638     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   619     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   639 
   620 
   640     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   621     widget.show();
   641 
   622     QTest::qWaitForWindowShown(&widget);
   642     widget.show();
   623 
   643     QTest::qWaitForWindowShown(&widget);
       
   644 
       
   645     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
       
   646     QVERIFY(object.testService->windowControl->winId() != 0);
   624     QVERIFY(object.testService->windowControl->winId() != 0);
   647 
       
   648     QVERIFY(object.testService->windowControl->repaintCount() > 0);
   625     QVERIFY(object.testService->windowControl->repaintCount() > 0);
   649 
   626 
   650     widget.resize(640, 480);
   627     widget.resize(640, 480);
   651     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   628     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   652 
   629 
   653     widget.move(10, 10);
   630     widget.move(10, 10);
   654     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   631     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   655 
   632 
   656     widget.hide();
   633     widget.hide();
   657 
       
   658     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
       
   659 }
   634 }
   660 
   635 
   661 void tst_QVideoWidget::showWidgetControl()
   636 void tst_QVideoWidget::showWidgetControl()
   662 {
   637 {
   663     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   638     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   664     QVideoWidget widget;
   639     QVideoWidget widget;
   665     widget.setMediaObject(&object);
   640     object.bind(&widget);
   666     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   641     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   667 
   642 
   668     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   643     widget.show();
   669 
   644     QTest::qWaitForWindowShown(&widget);
   670     widget.show();
       
   671     QTest::qWaitForWindowShown(&widget);
       
   672 
       
   673     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
       
   674     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), true);
   645     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), true);
   675 
   646 
   676     widget.resize(640, 480);
   647     widget.resize(640, 480);
   677 
   648 
   678     widget.move(10, 10);
   649     widget.move(10, 10);
   679 
   650 
   680     widget.hide();
   651     widget.hide();
   681 
   652 
   682     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
       
   683     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false);
   653     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false);
   684 }
   654 }
   685 
   655 
   686 void tst_QVideoWidget::showRendererControl()
   656 void tst_QVideoWidget::showRendererControl()
   687 {
   657 {
   688     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   658     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   689     QVideoWidget widget;
   659     QVideoWidget widget;
   690     widget.setMediaObject(&object);
   660     object.bind(&widget);
   691     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   661     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   692 
   662 
   693     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   663     widget.show();
   694 
   664     QTest::qWaitForWindowShown(&widget);
   695     widget.show();
   665 
   696     QTest::qWaitForWindowShown(&widget);
       
   697 
       
   698     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
       
   699     QVERIFY(object.testService->rendererControl->surface() != 0);
   666     QVERIFY(object.testService->rendererControl->surface() != 0);
   700 
   667 
   701     widget.resize(640, 480);
   668     widget.resize(640, 480);
   702 
   669 
   703     widget.move(10, 10);
   670     widget.move(10, 10);
   704 
   671 
   705     widget.hide();
   672     widget.hide();
   706 
       
   707     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
       
   708 }
   673 }
   709 
   674 
   710 void tst_QVideoWidget::aspectRatioWindowControl()
   675 void tst_QVideoWidget::aspectRatioWindowControl()
   711 {
   676 {
   712     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   677     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   713     object.testService->windowControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   678     object.testService->windowControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   714 
   679 
   715     QVideoWidget widget;
   680     QVideoWidget widget;
   716     widget.setMediaObject(&object);
   681     object.bind(&widget);
   717     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   682     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   718 
   683 
   719     // Test the aspect ratio defaults to keeping the aspect ratio.
   684     // Test the aspect ratio defaults to keeping the aspect ratio.
   720     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   685     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   721 
   686 
   743 {
   708 {
   744     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   709     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   745     object.testService->widgetControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   710     object.testService->widgetControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   746 
   711 
   747     QVideoWidget widget;
   712     QVideoWidget widget;
   748     widget.setMediaObject(&object);
   713     object.bind(&widget);
   749     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   714     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   750 
   715 
   751     // Test the aspect ratio defaults to keeping the aspect ratio.
   716     // Test the aspect ratio defaults to keeping the aspect ratio.
   752     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   717     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   753 
   718 
   774 void tst_QVideoWidget::aspectRatioRendererControl()
   739 void tst_QVideoWidget::aspectRatioRendererControl()
   775 {
   740 {
   776     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   741     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   777 
   742 
   778     QVideoWidget widget;
   743     QVideoWidget widget;
   779     widget.setMediaObject(&object);
   744     object.bind(&widget);
   780     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   745     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   781 
   746 
   782     // Test the aspect ratio defaults to keeping the aspect ratio.
   747     // Test the aspect ratio defaults to keeping the aspect ratio.
   783     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   748     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   784 
   749 
   811 {
   776 {
   812     QFETCH(QSize, size);
   777     QFETCH(QSize, size);
   813 
   778 
   814     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   779     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   815     QVideoWidget widget;
   780     QVideoWidget widget;
   816     widget.setMediaObject(&object);
   781     object.bind(&widget);
   817     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   782     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   818     widget.show();
   783     widget.show();
   819     QTest::qWaitForWindowShown(&widget);
   784     QTest::qWaitForWindowShown(&widget);
   820 
   785 
   821     QVERIFY(widget.sizeHint().isEmpty());
   786     QVERIFY(widget.sizeHint().isEmpty());
   828 {
   793 {
   829     QFETCH(QSize, size);
   794     QFETCH(QSize, size);
   830 
   795 
   831     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   796     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   832     QVideoWidget widget;
   797     QVideoWidget widget;
   833     widget.setMediaObject(&object);
   798     object.bind(&widget);
   834     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   799     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   835     widget.show();
   800     widget.show();
   836     QTest::qWaitForWindowShown(&widget);
   801     QTest::qWaitForWindowShown(&widget);
   837 
   802 
   838     QVERIFY(widget.sizeHint().isEmpty());
   803     QVERIFY(widget.sizeHint().isEmpty());
   875     QFETCH(QSize, pixelAspectRatio);
   840     QFETCH(QSize, pixelAspectRatio);
   876     QFETCH(QSize, expectedSize);
   841     QFETCH(QSize, expectedSize);
   877 
   842 
   878     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   843     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   879     QVideoWidget widget;
   844     QVideoWidget widget;
   880     widget.setMediaObject(&object);
   845     object.bind(&widget);
   881     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   846     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   882 
   847 
   883     widget.show();
   848     widget.show();
   884     QTest::qWaitForWindowShown(&widget);
   849     QTest::qWaitForWindowShown(&widget);
   885 
   850 
   895 
   860 
   896 void tst_QVideoWidget::fullScreenWindowControl()
   861 void tst_QVideoWidget::fullScreenWindowControl()
   897 {
   862 {
   898     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   863     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   899     QVideoWidget widget;
   864     QVideoWidget widget;
   900     widget.setMediaObject(&object);
   865     object.bind(&widget);
   901     widget.show();
   866     widget.show();
   902     QTest::qWaitForWindowShown(&widget);
   867     QTest::qWaitForWindowShown(&widget);
   903 
   868 
   904     Qt::WindowFlags windowFlags = widget.windowFlags();
   869     Qt::WindowFlags windowFlags = widget.windowFlags();
   905 
   870 
   976 
   941 
   977 void tst_QVideoWidget::fullScreenWidgetControl()
   942 void tst_QVideoWidget::fullScreenWidgetControl()
   978 {
   943 {
   979     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   944     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   980     QVideoWidget widget;
   945     QVideoWidget widget;
   981     widget.setMediaObject(&object);
   946     object.bind(&widget);
   982     widget.show();
   947     widget.show();
   983     QTest::qWaitForWindowShown(&widget);
   948     QTest::qWaitForWindowShown(&widget);
   984 
   949 
   985     Qt::WindowFlags windowFlags = widget.windowFlags();
   950     Qt::WindowFlags windowFlags = widget.windowFlags();
   986 
   951 
  1058 
  1023 
  1059 void tst_QVideoWidget::fullScreenRendererControl()
  1024 void tst_QVideoWidget::fullScreenRendererControl()
  1060 {
  1025 {
  1061     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1026     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1062     QVideoWidget widget;
  1027     QVideoWidget widget;
  1063     widget.setMediaObject(&object);
  1028     object.bind(&widget);
  1064     widget.show();
  1029     widget.show();
  1065     QTest::qWaitForWindowShown(&widget);
  1030     QTest::qWaitForWindowShown(&widget);
  1066 
  1031 
  1067     Qt::WindowFlags windowFlags = widget.windowFlags();
  1032     Qt::WindowFlags windowFlags = widget.windowFlags();
  1068 
  1033 
  1154 
  1119 
  1155     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1120     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1156     object.testService->windowControl->setBrightness(controlValue);
  1121     object.testService->windowControl->setBrightness(controlValue);
  1157 
  1122 
  1158     QVideoWidget widget;
  1123     QVideoWidget widget;
  1159     widget.setMediaObject(&object);
  1124     object.bind(&widget);
  1160     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1125     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1161     widget.show();
  1126     widget.show();
  1162     QTest::qWaitForWindowShown(&widget);
  1127     QTest::qWaitForWindowShown(&widget);
  1163 
  1128 
  1164     // Test the video widget resets the controls starting brightness to the default.
  1129     // Test the video widget resets the controls starting brightness to the default.
  1195 
  1160 
  1196     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1161     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1197     object.testService->widgetControl->setBrightness(controlValue);
  1162     object.testService->widgetControl->setBrightness(controlValue);
  1198 
  1163 
  1199     QVideoWidget widget;
  1164     QVideoWidget widget;
  1200     widget.setMediaObject(&object);
  1165     object.bind(&widget);
  1201     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1166     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1202 
  1167 
  1203     QCOMPARE(widget.brightness(), 0);
  1168     QCOMPARE(widget.brightness(), 0);
  1204 
  1169 
  1205     widget.show();
  1170     widget.show();
  1230     QFETCH(int, expectedValue);
  1195     QFETCH(int, expectedValue);
  1231 
  1196 
  1232     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1197     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1233 
  1198 
  1234     QVideoWidget widget;
  1199     QVideoWidget widget;
  1235     widget.setMediaObject(&object);
  1200     object.bind(&widget);
  1236     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1201     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1237     widget.show();
  1202     widget.show();
  1238     QTest::qWaitForWindowShown(&widget);
  1203     QTest::qWaitForWindowShown(&widget);
  1239 
  1204 
  1240     QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
  1205     QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
  1257 
  1222 
  1258     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1223     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1259     object.testService->windowControl->setContrast(controlValue);
  1224     object.testService->windowControl->setContrast(controlValue);
  1260 
  1225 
  1261     QVideoWidget widget;
  1226     QVideoWidget widget;
  1262     widget.setMediaObject(&object);
  1227     object.bind(&widget);
  1263     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1228     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1264 
  1229 
  1265     QCOMPARE(widget.contrast(), 0);
  1230     QCOMPARE(widget.contrast(), 0);
  1266 
  1231 
  1267     widget.show();
  1232     widget.show();
  1295 
  1260 
  1296     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1261     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1297     object.testService->widgetControl->setContrast(controlValue);
  1262     object.testService->widgetControl->setContrast(controlValue);
  1298 
  1263 
  1299     QVideoWidget widget;
  1264     QVideoWidget widget;
  1300     widget.setMediaObject(&object);
  1265     object.bind(&widget);
  1301     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1266     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1302     QCOMPARE(widget.contrast(), 0);
  1267     QCOMPARE(widget.contrast(), 0);
  1303 
  1268 
  1304     widget.show();
  1269     widget.show();
  1305     QTest::qWaitForWindowShown(&widget);
  1270     QTest::qWaitForWindowShown(&widget);
  1330     QFETCH(int, expectedValue);
  1295     QFETCH(int, expectedValue);
  1331 
  1296 
  1332     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1297     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1333 
  1298 
  1334     QVideoWidget widget;
  1299     QVideoWidget widget;
  1335     widget.setMediaObject(&object);
  1300     object.bind(&widget);
  1336     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1301     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1337     widget.show();
  1302     widget.show();
  1338     QTest::qWaitForWindowShown(&widget);
  1303     QTest::qWaitForWindowShown(&widget);
  1339 
  1304 
  1340     QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
  1305     QSignalSpy spy(&widget, SIGNAL(contrastChanged(int)));
  1357 
  1322 
  1358     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1323     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1359     object.testService->windowControl->setHue(controlValue);
  1324     object.testService->windowControl->setHue(controlValue);
  1360 
  1325 
  1361     QVideoWidget widget;
  1326     QVideoWidget widget;
  1362     widget.setMediaObject(&object);
  1327     object.bind(&widget);
  1363     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1328     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1364     QCOMPARE(widget.hue(), 0);
  1329     QCOMPARE(widget.hue(), 0);
  1365 
  1330 
  1366     widget.show();
  1331     widget.show();
  1367     QTest::qWaitForWindowShown(&widget);
  1332     QTest::qWaitForWindowShown(&widget);
  1394 
  1359 
  1395     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1360     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1396     object.testService->widgetControl->setHue(controlValue);
  1361     object.testService->widgetControl->setHue(controlValue);
  1397 
  1362 
  1398     QVideoWidget widget;
  1363     QVideoWidget widget;
  1399     widget.setMediaObject(&object);
  1364     object.bind(&widget);
  1400     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1365     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1401     QCOMPARE(widget.hue(), 0);
  1366     QCOMPARE(widget.hue(), 0);
  1402 
  1367 
  1403     widget.show();
  1368     widget.show();
  1404     QTest::qWaitForWindowShown(&widget);
  1369     QTest::qWaitForWindowShown(&widget);
  1429     QFETCH(int, expectedValue);
  1394     QFETCH(int, expectedValue);
  1430 
  1395 
  1431     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1396     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1432 
  1397 
  1433     QVideoWidget widget;
  1398     QVideoWidget widget;
  1434     widget.setMediaObject(&object);
  1399     object.bind(&widget);
  1435     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1400     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1436     widget.show();
  1401     widget.show();
  1437     QTest::qWaitForWindowShown(&widget);
  1402     QTest::qWaitForWindowShown(&widget);
  1438 
  1403 
  1439     QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
  1404     QSignalSpy spy(&widget, SIGNAL(hueChanged(int)));
  1456 
  1421 
  1457     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1422     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
  1458     object.testService->windowControl->setSaturation(controlValue);
  1423     object.testService->windowControl->setSaturation(controlValue);
  1459 
  1424 
  1460     QVideoWidget widget;
  1425     QVideoWidget widget;
  1461     widget.setMediaObject(&object);
  1426     object.bind(&widget);
  1462     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1427     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1463     QCOMPARE(widget.saturation(), 0);
  1428     QCOMPARE(widget.saturation(), 0);
  1464     widget.show();
  1429     widget.show();
  1465     QTest::qWaitForWindowShown(&widget);
  1430     QTest::qWaitForWindowShown(&widget);
  1466     QCOMPARE(widget.saturation(), 0);
  1431     QCOMPARE(widget.saturation(), 0);
  1492 
  1457 
  1493     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1458     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
  1494     object.testService->widgetControl->setSaturation(controlValue);
  1459     object.testService->widgetControl->setSaturation(controlValue);
  1495 
  1460 
  1496     QVideoWidget widget;
  1461     QVideoWidget widget;
  1497     widget.setMediaObject(&object);
  1462     object.bind(&widget);
  1498     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1463     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1499 
  1464 
  1500     QCOMPARE(widget.saturation(), 0);
  1465     QCOMPARE(widget.saturation(), 0);
  1501     widget.show();
  1466     widget.show();
  1502     QTest::qWaitForWindowShown(&widget);
  1467     QTest::qWaitForWindowShown(&widget);
  1528     QFETCH(int, expectedValue);
  1493     QFETCH(int, expectedValue);
  1529 
  1494 
  1530     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1495     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1531 
  1496 
  1532     QVideoWidget widget;
  1497     QVideoWidget widget;
  1533     widget.setMediaObject(&object);
  1498     object.bind(&widget);
  1534     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1499     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1535     widget.show();
  1500     widget.show();
  1536     QTest::qWaitForWindowShown(&widget);
  1501     QTest::qWaitForWindowShown(&widget);
  1537     QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
  1502     QSignalSpy spy(&widget, SIGNAL(saturationChanged(int)));
  1538 
  1503 
  1555 void tst_QVideoWidget::paintRendererControl()
  1520 void tst_QVideoWidget::paintRendererControl()
  1556 {
  1521 {
  1557     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1522     QtTestVideoObject object(0, 0, new QtTestRendererControl);
  1558 
  1523 
  1559     QVideoWidget widget;
  1524     QVideoWidget widget;
  1560     widget.setMediaObject(&object);
  1525     object.bind(&widget);
  1561     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
  1526     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
       
  1527     widget.resize(640,480);
  1562     widget.show();
  1528     widget.show();
  1563     QTest::qWaitForWindowShown(&widget);
  1529     QTest::qWaitForWindowShown(&widget);
  1564 
  1530 
  1565     QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>(
  1531     QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>(
  1566             object.testService->rendererControl->surface());
  1532             object.testService->rendererControl->surface());
  1584 
  1550 
  1585     QVERIFY(surface->present(frame));
  1551     QVERIFY(surface->present(frame));
  1586     QCOMPARE(surface->isActive(), true);
  1552     QCOMPARE(surface->isActive(), true);
  1587     QCOMPARE(surface->isReady(), false);
  1553     QCOMPARE(surface->isReady(), false);
  1588 
  1554 
  1589     QCoreApplication::processEvents(QEventLoop::AllEvents);
  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);
  1590 
  1558 
  1591     QCOMPARE(surface->isActive(), true);
  1559     QCOMPARE(surface->isActive(), true);
  1592     QCOMPARE(surface->isReady(), true);
  1560     QCOMPARE(surface->isReady(), true);
  1593 }
  1561 }
  1594 
  1562