qtmobility/tests/auto/qvideowidget/tst_qvideowidget.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include <qmobilityglobal.h>
    42 #include <qmobilityglobal.h>
    43 #include <QtTest/QtTest>
    43 #include <QtTest/QtTest>
    44 
    44 
    45 #include "qvideowidget.h"
    45 #include "../../../src/multimedia/qvideowidget.h"
    46 
    46 
    47 #include "qmediaobject.h"
    47 #include "../../../src/multimedia/qmediaobject.h"
    48 #include "qmediaservice.h"
    48 #include "../../../src/multimedia/qmediaservice.h"
    49 #include "qpaintervideosurface_p.h"
    49 #include "../../../src/multimedia/qpaintervideosurface_p.h"
    50 #include "qvideooutputcontrol.h"
    50 #include "../../../src/multimedia/qvideooutputcontrol.h"
    51 #include "qvideowindowcontrol.h"
    51 #include "../../../src/multimedia/qvideowindowcontrol.h"
    52 #include "qvideowidgetcontrol.h"
    52 #include "../../../src/multimedia/qvideowidgetcontrol.h"
    53 
    53 
    54 #include "qvideorenderercontrol.h"
    54 #include "../../../src/multimedia/qvideorenderercontrol.h"
    55 #include <QtMultimedia/qabstractvideosurface.h>
    55 #include <QtMultimedia/qabstractvideosurface.h>
    56 #include <QtMultimedia/qvideosurfaceformat.h>
    56 #include <QtMultimedia/qvideosurfaceformat.h>
    57 
    57 
    58 #include <QtGui/qapplication.h>
    58 #include <QtGui/qapplication.h>
    59 
    59 
   117 private:
   117 private:
   118     void sizeHint_data();
   118     void sizeHint_data();
   119     void color_data();
   119     void color_data();
   120 };
   120 };
   121 
   121 
   122 Q_DECLARE_METATYPE(QVideoWidget::AspectRatioMode)
   122 Q_DECLARE_METATYPE(Qt::AspectRatioMode)
   123 Q_DECLARE_METATYPE(const uchar *)
   123 Q_DECLARE_METATYPE(const uchar *)
   124 
   124 
   125 class QtTestOutputControl : public QVideoOutputControl
   125 class QtTestOutputControl : public QVideoOutputControl
   126 {
   126 {
   127 public:
   127 public:
   145         : m_winId(0)
   145         : m_winId(0)
   146         , m_repaintCount(0)
   146         , m_repaintCount(0)
   147         , m_brightness(0)
   147         , m_brightness(0)
   148         , m_contrast(0)
   148         , m_contrast(0)
   149         , m_saturation(0)
   149         , m_saturation(0)
   150         , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
   150         , m_aspectRatioMode(Qt::KeepAspectRatio)
   151         , m_fullScreen(0)
   151         , m_fullScreen(0)
   152     {
   152     {
   153     }
   153     }
   154 
   154 
   155     WId winId() const { return m_winId; }
   155     WId winId() const { return m_winId; }
   166     void repaint() { ++m_repaintCount; }
   166     void repaint() { ++m_repaintCount; }
   167 
   167 
   168     QSize nativeSize() const { return m_nativeSize; }
   168     QSize nativeSize() const { return m_nativeSize; }
   169     void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); }
   169     void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); }
   170 
   170 
   171     QVideoWidget::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
   171     Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
   172     void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) { m_aspectRatioMode = mode; }
   172     void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; }
   173 
   173 
   174     int brightness() const { return m_brightness; }
   174     int brightness() const { return m_brightness; }
   175     void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
   175     void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
   176 
   176 
   177     int contrast() const { return m_contrast; }
   177     int contrast() const { return m_contrast; }
   188     int m_repaintCount;
   188     int m_repaintCount;
   189     int m_brightness;
   189     int m_brightness;
   190     int m_contrast;
   190     int m_contrast;
   191     int m_hue;
   191     int m_hue;
   192     int m_saturation;
   192     int m_saturation;
   193     QVideoWidget::AspectRatioMode m_aspectRatioMode;
   193     Qt::AspectRatioMode m_aspectRatioMode;
   194     QRect m_displayRect;
   194     QRect m_displayRect;
   195     QSize m_nativeSize;
   195     QSize m_nativeSize;
   196     bool m_fullScreen;
   196     bool m_fullScreen;
   197 };
   197 };
   198 
   198 
   202     QtTestWidgetControl()
   202     QtTestWidgetControl()
   203         : m_brightness(1.0)
   203         : m_brightness(1.0)
   204         , m_contrast(1.0)
   204         , m_contrast(1.0)
   205         , m_hue(1.0)
   205         , m_hue(1.0)
   206         , m_saturation(1.0)
   206         , m_saturation(1.0)
   207         , m_aspectRatioMode(QVideoWidget::KeepAspectRatio)
   207         , m_aspectRatioMode(Qt::KeepAspectRatio)
   208         , m_fullScreen(false)
   208         , m_fullScreen(false)
   209     {
   209     {
   210     }
   210     }
   211 
   211 
   212     bool isFullScreen() const { return m_fullScreen; }
   212     bool isFullScreen() const { return m_fullScreen; }
   213     void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); }
   213     void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); }
   214 
   214 
   215     QVideoWidget::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
   215     Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; }
   216     void setAspectRatioMode(QVideoWidget::AspectRatioMode mode) { m_aspectRatioMode = mode; }
   216     void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; }
   217 
   217 
   218     int brightness() const { return m_brightness; }
   218     int brightness() const { return m_brightness; }
   219     void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
   219     void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); }
   220 
   220 
   221     int contrast() const { return m_contrast; }
   221     int contrast() const { return m_contrast; }
   242     } m_widget;
   242     } m_widget;
   243     int m_brightness;
   243     int m_brightness;
   244     int m_contrast;
   244     int m_contrast;
   245     int m_hue;
   245     int m_hue;
   246     int m_saturation;
   246     int m_saturation;
   247     QVideoWidget::AspectRatioMode m_aspectRatioMode;
   247     Qt::AspectRatioMode m_aspectRatioMode;
   248     QSize m_sizeHint;
   248     QSize m_sizeHint;
   249     bool m_fullScreen;
   249     bool m_fullScreen;
   250 };
   250 };
   251 
   251 
   252 class QtTestRendererControl : public QVideoRendererControl
   252 class QtTestRendererControl : public QVideoRendererControl
   355 
   355 
   356     widget.setFullScreen(true);
   356     widget.setFullScreen(true);
   357     QTest::qWaitForWindowShown(&widget);
   357     QTest::qWaitForWindowShown(&widget);
   358     QCOMPARE(widget.isFullScreen(), true);
   358     QCOMPARE(widget.isFullScreen(), true);
   359 
   359 
   360     widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   360     widget.setAspectRatioMode(Qt::IgnoreAspectRatio);
   361     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   361     QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio);
   362 
   362 
   363     {
   363     {
   364         QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
   364         QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int)));
   365 
   365 
   366         widget.setBrightness(100);
   366         widget.setBrightness(100);
   440 
   440 
   441     widget.setFullScreen(true);
   441     widget.setFullScreen(true);
   442     QTest::qWaitForWindowShown(&widget);
   442     QTest::qWaitForWindowShown(&widget);
   443     QCOMPARE(widget.isFullScreen(), true);
   443     QCOMPARE(widget.isFullScreen(), true);
   444 
   444 
   445     widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   445     widget.setAspectRatioMode(Qt::IgnoreAspectRatio);
   446     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   446     QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio);
   447 
   447 
   448     widget.setBrightness(100);
   448     widget.setBrightness(100);
   449     QCOMPARE(widget.brightness(), 100);
   449     QCOMPARE(widget.brightness(), 100);
   450 
   450 
   451     widget.setContrast(100);
   451     widget.setContrast(100);
   653     widget.move(10, 10);
   653     widget.move(10, 10);
   654     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   654     QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480));
   655 
   655 
   656     widget.hide();
   656     widget.hide();
   657 
   657 
   658     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   658     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WindowOutput);
   659 }
   659 }
   660 
   660 
   661 void tst_QVideoWidget::showWidgetControl()
   661 void tst_QVideoWidget::showWidgetControl()
   662 {
   662 {
   663     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   663     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   677 
   677 
   678     widget.move(10, 10);
   678     widget.move(10, 10);
   679 
   679 
   680     widget.hide();
   680     widget.hide();
   681 
   681 
   682     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   682     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::WidgetOutput);
   683     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false);
   683     QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false);
   684 }
   684 }
   685 
   685 
   686 void tst_QVideoWidget::showRendererControl()
   686 void tst_QVideoWidget::showRendererControl()
   687 {
   687 {
   702 
   702 
   703     widget.move(10, 10);
   703     widget.move(10, 10);
   704 
   704 
   705     widget.hide();
   705     widget.hide();
   706 
   706 
   707     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::NoOutput);
   707     QCOMPARE(object.testService->outputControl->output(), QVideoOutputControl::RendererOutput);
   708 }
   708 }
   709 
   709 
   710 void tst_QVideoWidget::aspectRatioWindowControl()
   710 void tst_QVideoWidget::aspectRatioWindowControl()
   711 {
   711 {
   712     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   712     QtTestVideoObject object(new QtTestWindowControl, 0, 0);
   713     object.testService->windowControl->setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   713     object.testService->windowControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   714 
   714 
   715     QVideoWidget widget;
   715     QVideoWidget widget;
   716     widget.setMediaObject(&object);
   716     widget.setMediaObject(&object);
   717     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   717     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   718 
   718 
   719     // Test the aspect ratio defaults to keeping the aspect ratio.
   719     // Test the aspect ratio defaults to keeping the aspect ratio.
   720     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   720     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   721 
   721 
   722     // Test the control has been informed of the aspect ratio change, post show.
   722     // Test the control has been informed of the aspect ratio change, post show.
   723     widget.show();
   723     widget.show();
   724     QTest::qWaitForWindowShown(&widget);
   724     QTest::qWaitForWindowShown(&widget);
   725     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   725     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   726     QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   726     QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio);
   727 
   727 
   728     // Test an aspect ratio change is enforced immediately while visible.
   728     // Test an aspect ratio change is enforced immediately while visible.
   729     widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   729     widget.setAspectRatioMode(Qt::IgnoreAspectRatio);
   730     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   730     QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio);
   731     QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   731     QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::IgnoreAspectRatio);
   732 
   732 
   733     // Test an aspect ratio set while not visible is respected.
   733     // Test an aspect ratio set while not visible is respected.
   734     widget.hide();
   734     widget.hide();
   735     widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
   735     widget.setAspectRatioMode(Qt::KeepAspectRatio);
   736     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   736     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   737     widget.show();
   737     widget.show();
   738     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   738     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   739     QCOMPARE(object.testService->windowControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   739     QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio);
   740 }
   740 }
   741 
   741 
   742 void tst_QVideoWidget::aspectRatioWidgetControl()
   742 void tst_QVideoWidget::aspectRatioWidgetControl()
   743 {
   743 {
   744     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   744     QtTestVideoObject object(0, new QtTestWidgetControl, 0);
   745     object.testService->widgetControl->setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   745     object.testService->widgetControl->setAspectRatioMode(Qt::IgnoreAspectRatio);
   746 
   746 
   747     QVideoWidget widget;
   747     QVideoWidget widget;
   748     widget.setMediaObject(&object);
   748     widget.setMediaObject(&object);
   749     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   749     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   750 
   750 
   751     // Test the aspect ratio defaults to keeping the aspect ratio.
   751     // Test the aspect ratio defaults to keeping the aspect ratio.
   752     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   752     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   753 
   753 
   754     // Test the control has been informed of the aspect ratio change, post show.
   754     // Test the control has been informed of the aspect ratio change, post show.
   755     widget.show();
   755     widget.show();
   756     QTest::qWaitForWindowShown(&widget);
   756     QTest::qWaitForWindowShown(&widget);
   757     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   757     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   758     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   758     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio);
   759 
   759 
   760     // Test an aspect ratio change is enforced immediately while visible.
   760     // Test an aspect ratio change is enforced immediately while visible.
   761     widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   761     widget.setAspectRatioMode(Qt::IgnoreAspectRatio);
   762     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   762     QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio);
   763     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   763     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::IgnoreAspectRatio);
   764 
   764 
   765     // Test an aspect ratio set while not visible is respected.
   765     // Test an aspect ratio set while not visible is respected.
   766     widget.hide();
   766     widget.hide();
   767     widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
   767     widget.setAspectRatioMode(Qt::KeepAspectRatio);
   768     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   768     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   769     widget.show();
   769     widget.show();
   770     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   770     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   771     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   771     QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio);
   772 }
   772 }
   773 
   773 
   774 void tst_QVideoWidget::aspectRatioRendererControl()
   774 void tst_QVideoWidget::aspectRatioRendererControl()
   775 {
   775 {
   776     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   776     QtTestVideoObject object(0, 0, new QtTestRendererControl);
   778     QVideoWidget widget;
   778     QVideoWidget widget;
   779     widget.setMediaObject(&object);
   779     widget.setMediaObject(&object);
   780     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   780     widget.setWindowFlags(Qt::X11BypassWindowManagerHint);
   781 
   781 
   782     // Test the aspect ratio defaults to keeping the aspect ratio.
   782     // Test the aspect ratio defaults to keeping the aspect ratio.
   783     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   783     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   784 
   784 
   785     // Test the control has been informed of the aspect ratio change, post show.
   785     // Test the control has been informed of the aspect ratio change, post show.
   786     widget.show();
   786     widget.show();
   787     QTest::qWaitForWindowShown(&widget);
   787     QTest::qWaitForWindowShown(&widget);
   788     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   788     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   789 
   789 
   790     // Test an aspect ratio change is enforced immediately while visible.
   790     // Test an aspect ratio change is enforced immediately while visible.
   791     widget.setAspectRatioMode(QVideoWidget::IgnoreAspectRatio);
   791     widget.setAspectRatioMode(Qt::IgnoreAspectRatio);
   792     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::IgnoreAspectRatio);
   792     QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio);
   793 
   793 
   794     // Test an aspect ratio set while not visible is respected.
   794     // Test an aspect ratio set while not visible is respected.
   795     widget.hide();
   795     widget.hide();
   796     widget.setAspectRatioMode(QVideoWidget::KeepAspectRatio);
   796     widget.setAspectRatioMode(Qt::KeepAspectRatio);
   797     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   797     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   798     widget.show();
   798     widget.show();
   799     QCOMPARE(widget.aspectRatioMode(), QVideoWidget::KeepAspectRatio);
   799     QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio);
   800 }
   800 }
   801 
   801 
   802 void tst_QVideoWidget::sizeHint_data()
   802 void tst_QVideoWidget::sizeHint_data()
   803 {
   803 {
   804     QTest::addColumn<QSize>("size");
   804     QTest::addColumn<QSize>("size");