From e3a8c165eabe139d71a762089ab396e5b492c70b Mon Sep 17 00:00:00 2001 From: Michael Goddard Date: Fri, 4 Nov 2011 13:38:44 +1000 Subject: Rearrange the automatic tests. Split them into unit and integration tests. Integration tests really need to be run on the real platform (not in a VM etc) since they are somewhat unstable or nonfunctional otherwise. A few tests were previously broken by QUrl changes and they were repaired. Removed one test since it was not providing a lot of value. There are still a number of tests that rely on Q_AUTOTEST_EXPORT symbols. Change-Id: Ic402abf0af946baa5945075d975b3f584f9ef280 Reviewed-by: Kalle Lehtonen --- tests/auto/unit/multimedia.pro | 41 + tests/auto/unit/multimediawidgets.pro | 17 + .../qabstractvideobuffer/qabstractvideobuffer.pro | 8 + .../tst_qabstractvideobuffer.cpp | 178 ++ .../qabstractvideosurface.pro | 8 + .../tst_qabstractvideosurface.cpp | 409 ++++ .../qaudiocapturesource/qaudiocapturesource.pro | 11 + .../tst_qaudiocapturesource.cpp | 204 ++ .../unit/qaudiodeviceinfo/qaudiodeviceinfo.pro | 10 + .../unit/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp | 277 +++ tests/auto/unit/qaudioformat/qaudioformat.pro | 8 + tests/auto/unit/qaudioformat/tst_qaudioformat.cpp | 271 +++ .../auto/unit/qaudionamespace/qaudionamespace.pro | 8 + .../unit/qaudionamespace/tst_qaudionamespace.cpp | 127 ++ tests/auto/unit/qcamera/qcamera.pro | 10 + tests/auto/unit/qcamera/tst_qcamera.cpp | 1956 ++++++++++++++++++++ .../qcameraimagecapture/qcameraimagecapture.pro | 11 + .../tst_qcameraimagecapture.cpp | 432 +++++ .../unit/qcameraviewfinder/qcameraviewfinder.pro | 11 + .../qcameraviewfinder/tst_qcameraviewfinder.cpp | 113 ++ tests/auto/unit/qcamerawidgets/qcamerawidgets.pro | 13 + .../unit/qcamerawidgets/tst_qcamerawidgets.cpp | 318 ++++ .../unit/qdeclarativeaudio/qdeclarativeaudio.pro | 17 + .../qdeclarativeaudio/tst_qdeclarativeaudio.cpp | 1301 +++++++++++++ .../unit/qdeclarativevideo/qdeclarativevideo.pro | 18 + .../qdeclarativevideo/tst_qdeclarativevideo.cpp | 991 ++++++++++ .../unit/qgraphicsvideoitem/qgraphicsvideoitem.pro | 11 + .../qgraphicsvideoitem/tst_qgraphicsvideoitem.cpp | 675 +++++++ .../qmediabindableinterface.pro | 11 + .../tst_qmediabindableinterface.cpp | 137 ++ .../qmediacontainercontrol.pro | 10 + .../tst_qmediacontainercontrol.cpp | 79 + tests/auto/unit/qmediacontent/qmediacontent.pro | 7 + .../auto/unit/qmediacontent/tst_qmediacontent.cpp | 177 ++ tests/auto/unit/qmediaimageviewer/images.qrc | 9 + .../unit/qmediaimageviewer/images/coverart.png | Bin 0 -> 230 bytes tests/auto/unit/qmediaimageviewer/images/image.jpg | Bin 0 -> 2045 bytes tests/auto/unit/qmediaimageviewer/images/image.png | Bin 0 -> 230 bytes .../auto/unit/qmediaimageviewer/images/invalid.png | 2 + .../auto/unit/qmediaimageviewer/images/poster.png | Bin 0 -> 230 bytes .../unit/qmediaimageviewer/qmediaimageviewer.pro | 16 + .../qmediaimageviewer/tst_qmediaimageviewer.cpp | 1044 +++++++++++ .../auto/unit/qmediaimageviewerwidgets/images.qrc | 5 + .../unit/qmediaimageviewerwidgets/images/image.png | Bin 0 -> 230 bytes .../qmediaimageviewerwidgets.pro | 17 + .../tst_qmediaimageviewerwidgets.cpp | 142 ++ tests/auto/unit/qmediaobject/main.cpp | 53 + tests/auto/unit/qmediaobject/qmediaobject.pro | 11 + tests/auto/unit/qmediaobject/tst_qmediaobject.cpp | 403 ++++ tests/auto/unit/qmediaobject/tst_qmediaobject.h | 147 ++ tests/auto/unit/qmediaplayer/main.cpp | 53 + tests/auto/unit/qmediaplayer/qmediaplayer.pro | 11 + tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp | 1050 +++++++++++ tests/auto/unit/qmediaplayer/tst_qmediaplayer.h | 133 ++ tests/auto/unit/qmediaplayerwidgets/main.cpp | 53 + .../qmediaplayerwidgets/qmediaplayerwidgets.pro | 11 + .../tst_qmediaplayerwidgets.cpp | 162 ++ .../qmediaplayerwidgets/tst_qmediaplayerwidgets.h | 79 + tests/auto/unit/qmediaplaylist/qmediaplaylist.pro | 18 + tests/auto/unit/qmediaplaylist/testdata/test.m3u | 11 + tests/auto/unit/qmediaplaylist/testdata/testfile | 0 .../unit/qmediaplaylist/testdata/testfile2#suffix | 0 .../unit/qmediaplaylist/tst_qmediaplaylist.cpp | 783 ++++++++ .../qmediaplaylistnavigator.pro | 8 + .../tst_qmediaplaylistnavigator.cpp | 525 ++++++ .../unit/qmediapluginloader/qmediapluginloader.pro | 14 + .../qmediapluginloader/tst_qmediapluginloader.cpp | 123 ++ tests/auto/unit/qmediarecorder/main.cpp | 53 + tests/auto/unit/qmediarecorder/qmediarecorder.pro | 12 + .../unit/qmediarecorder/tst_qmediarecorder.cpp | 1286 +++++++++++++ .../auto/unit/qmediarecorder/tst_qmediarecorder.h | 127 ++ tests/auto/unit/qmediaresource/qmediaresource.pro | 8 + .../unit/qmediaresource/tst_qmediaresource.cpp | 700 +++++++ tests/auto/unit/qmediaservice/qmediaservice.pro | 7 + .../auto/unit/qmediaservice/tst_qmediaservice.cpp | 280 +++ .../qmediaserviceprovider.pro | 8 + .../tst_qmediaserviceprovider.cpp | 499 +++++ .../auto/unit/qmediatimerange/qmediatimerange.pro | 8 + .../unit/qmediatimerange/tst_qmediatimerange.cpp | 806 ++++++++ .../qmetadatareadercontrol.pro | 10 + .../tst_qmetadatareadercontrol.cpp | 143 ++ .../qmetadatawritercontrol.pro | 9 + .../tst_qmetadatawritercontrol.cpp | 89 + tests/auto/unit/qmultimedia_common/mock.pri | 7 + .../qmultimedia_common/mockaudioencodercontrol.h | 127 ++ .../qmultimedia_common/mockaudioendpointselector.h | 117 ++ tests/auto/unit/qmultimedia_common/mockcamera.pri | 22 + .../mockcameracapturebuffercontrol.h | 83 + .../mockcameracapturedestinationcontrol.h | 80 + .../unit/qmultimedia_common/mockcameracontrol.h | 145 ++ .../qmultimedia_common/mockcameraexposurecontrol.h | 282 +++ .../qmultimedia_common/mockcameraflashcontrol.h | 89 + .../qmultimedia_common/mockcamerafocuscontrol.h | 199 ++ .../mockcameraimagecapturecontrol.h | 130 ++ .../mockcameraimageprocessingcontrol.h | 156 ++ .../qmultimedia_common/mockcameralockscontrol.h | 144 ++ .../unit/qmultimedia_common/mockcameraservice.h | 196 ++ .../auto/unit/qmultimedia_common/mockcontainer.pri | 7 + .../qmultimedia_common/mockimageencodercontrol.h | 103 ++ .../qmultimedia_common/mockmediacontainercontrol.h | 97 + .../mockmedianetworkaccesscontrol.h | 83 + .../auto/unit/qmultimedia_common/mockmediaobject.h | 57 + .../qmultimedia_common/mockmediaplayercontrol.h | 118 ++ .../qmultimedia_common/mockmediaplayerservice.h | 176 ++ .../qmultimedia_common/mockmediaplaylistcontrol.h | 112 ++ .../mockmediaplaylistsourcecontrol.h | 74 + .../qmultimedia_common/mockmediarecordercontrol.h | 125 ++ .../qmultimedia_common/mockmediarecorderservice.h | 101 + .../unit/qmultimedia_common/mockmediaservice.h | 66 + .../qmultimedia_common/mockmediaserviceprovider.h | 74 + .../qmultimedia_common/mockmediastreamscontrol.h | 78 + .../qmultimedia_common/mockmetadatareadercontrol.h | 98 + .../qmultimedia_common/mockmetadatawritercontrol.h | 107 ++ tests/auto/unit/qmultimedia_common/mockplayer.pri | 12 + .../auto/unit/qmultimedia_common/mockplaylist.pri | 8 + .../unit/qmultimedia_common/mockplaylistservice.h | 77 + tests/auto/unit/qmultimedia_common/mockradio.pri | 8 + .../unit/qmultimedia_common/mockradiodatacontrol.h | 157 ++ .../qmultimedia_common/mockradiotunercontrol.h | 275 +++ .../mockreadonlyplaylistprovider.h | 69 + .../auto/unit/qmultimedia_common/mockrecorder.pri | 14 + tests/auto/unit/qmultimedia_common/mockvideo.pri | 14 + .../qmultimedia_common/mockvideoencodercontrol.h | 112 ++ .../qmultimedia_common/mockvideorenderercontrol.h | 58 + .../unit/qmultimedia_common/mockvideosurface.h | 59 + .../qmultimedia_common/mockvideowindowcontrol.h | 74 + .../qpaintervideosurface/qpaintervideosurface.pro | 18 + .../tst_qpaintervideosurface.cpp | 1249 +++++++++++++ tests/auto/unit/qradiodata/main.cpp | 53 + tests/auto/unit/qradiodata/qradiodata.pro | 11 + tests/auto/unit/qradiodata/tst_qradiodata.cpp | 148 ++ tests/auto/unit/qradiodata/tst_qradiodata.h | 80 + tests/auto/unit/qradiotuner/main.cpp | 53 + tests/auto/unit/qradiotuner/qradiotuner.pro | 11 + tests/auto/unit/qradiotuner/tst_qradiotuner.cpp | 336 ++++ tests/auto/unit/qradiotuner/tst_qradiotuner.h | 87 + .../qvideoencodercontrol/qvideoencodercontrol.pro | 9 + .../tst_qvideoencodercontrol.cpp | 139 ++ tests/auto/unit/qvideoframe/qvideoframe.pro | 8 + tests/auto/unit/qvideoframe/tst_qvideoframe.cpp | 1126 +++++++++++ .../qvideosurfaceformat/qvideosurfaceformat.pro | 8 + .../tst_qvideosurfaceformat.cpp | 1031 +++++++++++ tests/auto/unit/qvideowidget/qvideowidget.pro | 11 + tests/auto/unit/qvideowidget/tst_qvideowidget.cpp | 1567 ++++++++++++++++ .../data/corrupt_datadesc_1_16_8000.le.wav | Bin 0 -> 4044 bytes .../data/corrupt_fmtdesc_1_16_8000.le.wav | Bin 0 -> 4044 bytes .../data/corrupt_fmtstring_1_16_8000.le.wav | Bin 0 -> 4044 bytes tests/auto/unit/qwavedecoder/data/empty.wav | 0 tests/auto/unit/qwavedecoder/data/gendata.sh | 68 + .../qwavedecoder/data/isawav_1_16_44100_le.wav | Bin 0 -> 22094 bytes .../unit/qwavedecoder/data/isawav_1_16_8000_le.wav | Bin 0 -> 4044 bytes .../qwavedecoder/data/isawav_1_32_44100_le.wav | Bin 0 -> 44180 bytes .../unit/qwavedecoder/data/isawav_1_32_8000_le.wav | Bin 0 -> 8080 bytes .../unit/qwavedecoder/data/isawav_1_8_44100.wav | Bin 0 -> 11069 bytes .../unit/qwavedecoder/data/isawav_1_8_8000.wav | Bin 0 -> 2044 bytes .../qwavedecoder/data/isawav_2_16_44100_be.wav | Bin 0 -> 44144 bytes .../unit/qwavedecoder/data/isawav_2_16_8000_be.wav | Bin 0 -> 8044 bytes .../qwavedecoder/data/isawav_2_32_44100_be.wav | Bin 0 -> 88280 bytes .../unit/qwavedecoder/data/isawav_2_32_8000_be.wav | Bin 0 -> 16080 bytes .../unit/qwavedecoder/data/isawav_2_8_44100.wav | Bin 0 -> 22094 bytes .../unit/qwavedecoder/data/isawav_2_8_8000.wav | Bin 0 -> 4044 bytes tests/auto/unit/qwavedecoder/data/nosampledata.wav | Bin 0 -> 44 bytes tests/auto/unit/qwavedecoder/data/notawav.wav | 1 + tests/auto/unit/qwavedecoder/data/onebyte.wav | 1 + tests/auto/unit/qwavedecoder/qwavedecoder.pro | 12 + tests/auto/unit/qwavedecoder/tst_qwavedecoder.cpp | 326 ++++ tests/auto/unit/unit.pro | 4 + 167 files changed, 27350 insertions(+) create mode 100644 tests/auto/unit/multimedia.pro create mode 100644 tests/auto/unit/multimediawidgets.pro create mode 100644 tests/auto/unit/qabstractvideobuffer/qabstractvideobuffer.pro create mode 100644 tests/auto/unit/qabstractvideobuffer/tst_qabstractvideobuffer.cpp create mode 100644 tests/auto/unit/qabstractvideosurface/qabstractvideosurface.pro create mode 100644 tests/auto/unit/qabstractvideosurface/tst_qabstractvideosurface.cpp create mode 100644 tests/auto/unit/qaudiocapturesource/qaudiocapturesource.pro create mode 100644 tests/auto/unit/qaudiocapturesource/tst_qaudiocapturesource.cpp create mode 100644 tests/auto/unit/qaudiodeviceinfo/qaudiodeviceinfo.pro create mode 100644 tests/auto/unit/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp create mode 100644 tests/auto/unit/qaudioformat/qaudioformat.pro create mode 100644 tests/auto/unit/qaudioformat/tst_qaudioformat.cpp create mode 100644 tests/auto/unit/qaudionamespace/qaudionamespace.pro create mode 100644 tests/auto/unit/qaudionamespace/tst_qaudionamespace.cpp create mode 100644 tests/auto/unit/qcamera/qcamera.pro create mode 100644 tests/auto/unit/qcamera/tst_qcamera.cpp create mode 100644 tests/auto/unit/qcameraimagecapture/qcameraimagecapture.pro create mode 100644 tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp create mode 100644 tests/auto/unit/qcameraviewfinder/qcameraviewfinder.pro create mode 100644 tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp create mode 100644 tests/auto/unit/qcamerawidgets/qcamerawidgets.pro create mode 100644 tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp create mode 100644 tests/auto/unit/qdeclarativeaudio/qdeclarativeaudio.pro create mode 100644 tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp create mode 100644 tests/auto/unit/qdeclarativevideo/qdeclarativevideo.pro create mode 100644 tests/auto/unit/qdeclarativevideo/tst_qdeclarativevideo.cpp create mode 100644 tests/auto/unit/qgraphicsvideoitem/qgraphicsvideoitem.pro create mode 100644 tests/auto/unit/qgraphicsvideoitem/tst_qgraphicsvideoitem.cpp create mode 100644 tests/auto/unit/qmediabindableinterface/qmediabindableinterface.pro create mode 100644 tests/auto/unit/qmediabindableinterface/tst_qmediabindableinterface.cpp create mode 100644 tests/auto/unit/qmediacontainercontrol/qmediacontainercontrol.pro create mode 100644 tests/auto/unit/qmediacontainercontrol/tst_qmediacontainercontrol.cpp create mode 100644 tests/auto/unit/qmediacontent/qmediacontent.pro create mode 100644 tests/auto/unit/qmediacontent/tst_qmediacontent.cpp create mode 100644 tests/auto/unit/qmediaimageviewer/images.qrc create mode 100644 tests/auto/unit/qmediaimageviewer/images/coverart.png create mode 100644 tests/auto/unit/qmediaimageviewer/images/image.jpg create mode 100644 tests/auto/unit/qmediaimageviewer/images/image.png create mode 100644 tests/auto/unit/qmediaimageviewer/images/invalid.png create mode 100644 tests/auto/unit/qmediaimageviewer/images/poster.png create mode 100644 tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro create mode 100644 tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp create mode 100644 tests/auto/unit/qmediaimageviewerwidgets/images.qrc create mode 100644 tests/auto/unit/qmediaimageviewerwidgets/images/image.png create mode 100644 tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro create mode 100644 tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp create mode 100644 tests/auto/unit/qmediaobject/main.cpp create mode 100644 tests/auto/unit/qmediaobject/qmediaobject.pro create mode 100644 tests/auto/unit/qmediaobject/tst_qmediaobject.cpp create mode 100644 tests/auto/unit/qmediaobject/tst_qmediaobject.h create mode 100755 tests/auto/unit/qmediaplayer/main.cpp create mode 100644 tests/auto/unit/qmediaplayer/qmediaplayer.pro create mode 100644 tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp create mode 100755 tests/auto/unit/qmediaplayer/tst_qmediaplayer.h create mode 100755 tests/auto/unit/qmediaplayerwidgets/main.cpp create mode 100644 tests/auto/unit/qmediaplayerwidgets/qmediaplayerwidgets.pro create mode 100644 tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp create mode 100755 tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.h create mode 100644 tests/auto/unit/qmediaplaylist/qmediaplaylist.pro create mode 100644 tests/auto/unit/qmediaplaylist/testdata/test.m3u create mode 100644 tests/auto/unit/qmediaplaylist/testdata/testfile create mode 100644 tests/auto/unit/qmediaplaylist/testdata/testfile2#suffix create mode 100644 tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp create mode 100644 tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro create mode 100644 tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp create mode 100644 tests/auto/unit/qmediapluginloader/qmediapluginloader.pro create mode 100644 tests/auto/unit/qmediapluginloader/tst_qmediapluginloader.cpp create mode 100755 tests/auto/unit/qmediarecorder/main.cpp create mode 100644 tests/auto/unit/qmediarecorder/qmediarecorder.pro create mode 100644 tests/auto/unit/qmediarecorder/tst_qmediarecorder.cpp create mode 100755 tests/auto/unit/qmediarecorder/tst_qmediarecorder.h create mode 100644 tests/auto/unit/qmediaresource/qmediaresource.pro create mode 100644 tests/auto/unit/qmediaresource/tst_qmediaresource.cpp create mode 100644 tests/auto/unit/qmediaservice/qmediaservice.pro create mode 100644 tests/auto/unit/qmediaservice/tst_qmediaservice.cpp create mode 100644 tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro create mode 100644 tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp create mode 100644 tests/auto/unit/qmediatimerange/qmediatimerange.pro create mode 100644 tests/auto/unit/qmediatimerange/tst_qmediatimerange.cpp create mode 100644 tests/auto/unit/qmetadatareadercontrol/qmetadatareadercontrol.pro create mode 100644 tests/auto/unit/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp create mode 100644 tests/auto/unit/qmetadatawritercontrol/qmetadatawritercontrol.pro create mode 100644 tests/auto/unit/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp create mode 100644 tests/auto/unit/qmultimedia_common/mock.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockaudioencodercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockaudioendpointselector.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcamera.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockcameracapturebuffercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameracapturedestinationcontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameracontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameraexposurecontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameraflashcontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcamerafocuscontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameraimagecapturecontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameraimageprocessingcontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameralockscontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcameraservice.h create mode 100644 tests/auto/unit/qmultimedia_common/mockcontainer.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockimageencodercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediacontainercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmedianetworkaccesscontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaobject.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaplayerservice.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaplaylistsourcecontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediarecordercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediarecorderservice.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaservice.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmediastreamscontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmetadatareadercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockmetadatawritercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockplayer.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockplaylist.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockplaylistservice.h create mode 100644 tests/auto/unit/qmultimedia_common/mockradio.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockradiodatacontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockradiotunercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h create mode 100644 tests/auto/unit/qmultimedia_common/mockrecorder.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockvideo.pri create mode 100644 tests/auto/unit/qmultimedia_common/mockvideoencodercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockvideorenderercontrol.h create mode 100644 tests/auto/unit/qmultimedia_common/mockvideosurface.h create mode 100644 tests/auto/unit/qmultimedia_common/mockvideowindowcontrol.h create mode 100644 tests/auto/unit/qpaintervideosurface/qpaintervideosurface.pro create mode 100644 tests/auto/unit/qpaintervideosurface/tst_qpaintervideosurface.cpp create mode 100755 tests/auto/unit/qradiodata/main.cpp create mode 100644 tests/auto/unit/qradiodata/qradiodata.pro create mode 100644 tests/auto/unit/qradiodata/tst_qradiodata.cpp create mode 100644 tests/auto/unit/qradiodata/tst_qradiodata.h create mode 100755 tests/auto/unit/qradiotuner/main.cpp create mode 100644 tests/auto/unit/qradiotuner/qradiotuner.pro create mode 100644 tests/auto/unit/qradiotuner/tst_qradiotuner.cpp create mode 100644 tests/auto/unit/qradiotuner/tst_qradiotuner.h create mode 100644 tests/auto/unit/qvideoencodercontrol/qvideoencodercontrol.pro create mode 100644 tests/auto/unit/qvideoencodercontrol/tst_qvideoencodercontrol.cpp create mode 100644 tests/auto/unit/qvideoframe/qvideoframe.pro create mode 100644 tests/auto/unit/qvideoframe/tst_qvideoframe.cpp create mode 100644 tests/auto/unit/qvideosurfaceformat/qvideosurfaceformat.pro create mode 100644 tests/auto/unit/qvideosurfaceformat/tst_qvideosurfaceformat.cpp create mode 100644 tests/auto/unit/qvideowidget/qvideowidget.pro create mode 100644 tests/auto/unit/qvideowidget/tst_qvideowidget.cpp create mode 100644 tests/auto/unit/qwavedecoder/data/corrupt_datadesc_1_16_8000.le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/corrupt_fmtdesc_1_16_8000.le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/corrupt_fmtstring_1_16_8000.le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/empty.wav create mode 100755 tests/auto/unit/qwavedecoder/data/gendata.sh create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_16_8000_le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_32_44100_le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_32_8000_le.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_8_44100.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_1_8_8000.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_16_44100_be.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_16_8000_be.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_32_44100_be.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_32_8000_be.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_8_44100.wav create mode 100644 tests/auto/unit/qwavedecoder/data/isawav_2_8_8000.wav create mode 100644 tests/auto/unit/qwavedecoder/data/nosampledata.wav create mode 100644 tests/auto/unit/qwavedecoder/data/notawav.wav create mode 100644 tests/auto/unit/qwavedecoder/data/onebyte.wav create mode 100644 tests/auto/unit/qwavedecoder/qwavedecoder.pro create mode 100644 tests/auto/unit/qwavedecoder/tst_qwavedecoder.cpp create mode 100644 tests/auto/unit/unit.pro (limited to 'tests/auto/unit') diff --git a/tests/auto/unit/multimedia.pro b/tests/auto/unit/multimedia.pro new file mode 100644 index 000000000..4dbe2b9a5 --- /dev/null +++ b/tests/auto/unit/multimedia.pro @@ -0,0 +1,41 @@ + +TEMPLATE = subdirs +SUBDIRS += \ + qabstractvideobuffer \ + qabstractvideosurface \ + qaudiocapturesource \ + qaudiodeviceinfo \ + qaudioformat \ + qaudionamespace \ + qcamera \ + qcameraimagecapture \ + qmediabindableinterface \ + qmediacontainercontrol \ + qmediacontent \ + qmediaobject \ + qmediaplayer \ + qmediaplaylistnavigator \ + qmediarecorder \ + qmediaresource \ + qmediaservice \ + qmediatimerange \ + qmetadatareadercontrol \ + qmetadatawritercontrol \ + qradiodata \ + qradiotuner \ + qvideoencodercontrol \ + qvideoframe \ + qvideosurfaceformat \ + qwavedecoder + +# Tests depending on private interfaces should only be built if +# these interfaces are exported. +contains (QT_CONFIG, private_tests) { + # These depend on controlling the set of plugins loaded (in qmediapluginloader) + SUBDIRS += \ + qdeclarativeaudio \ + qmediaplaylist \ + qmediapluginloader \ + qmediaimageviewer \ + qmediaserviceprovider +} diff --git a/tests/auto/unit/multimediawidgets.pro b/tests/auto/unit/multimediawidgets.pro new file mode 100644 index 000000000..0105e3ed7 --- /dev/null +++ b/tests/auto/unit/multimediawidgets.pro @@ -0,0 +1,17 @@ + +TEMPLATE = subdirs +SUBDIRS += \ + qcameraviewfinder \ + qcamerawidgets \ + qmediaplayerwidgets \ + +# Tests depending on private interfaces should only be built if +# these interfaces are exported. +contains (QT_CONFIG, private_tests) { + SUBDIRS += \ + qgraphicsvideoitem \ + qpaintervideosurface \ + qmediaimageviewerwidgets \ + qvideowidget \ +} + diff --git a/tests/auto/unit/qabstractvideobuffer/qabstractvideobuffer.pro b/tests/auto/unit/qabstractvideobuffer/qabstractvideobuffer.pro new file mode 100644 index 000000000..dfb7e5d7b --- /dev/null +++ b/tests/auto/unit/qabstractvideobuffer/qabstractvideobuffer.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qabstractvideobuffer + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qabstractvideobuffer.cpp + diff --git a/tests/auto/unit/qabstractvideobuffer/tst_qabstractvideobuffer.cpp b/tests/auto/unit/qabstractvideobuffer/tst_qabstractvideobuffer.cpp new file mode 100644 index 000000000..fc33bf5a9 --- /dev/null +++ b/tests/auto/unit/qabstractvideobuffer/tst_qabstractvideobuffer.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include + +// Adds an enum, and the stringized version +#define ADD_ENUM_TEST(x) \ + QTest::newRow(#x) \ + << QAbstractVideoBuffer::x \ + << QString(QLatin1String(#x)); + +class tst_QAbstractVideoBuffer : public QObject +{ + Q_OBJECT +public: + tst_QAbstractVideoBuffer(); + ~tst_QAbstractVideoBuffer(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void handleType_data(); + void handleType(); + void handle(); + void mapMode(); + void mapModeDebug_data(); + void mapModeDebug(); +}; + +class QtTestVideoBuffer : public QAbstractVideoBuffer +{ +public: + QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) : QAbstractVideoBuffer(type) {} + + MapMode mapMode() const { return QAbstractVideoBuffer::ReadWrite; } + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} +}; + +tst_QAbstractVideoBuffer::tst_QAbstractVideoBuffer() +{ +} + +tst_QAbstractVideoBuffer::~tst_QAbstractVideoBuffer() +{ +} + +void tst_QAbstractVideoBuffer::initTestCase() +{ +} + +void tst_QAbstractVideoBuffer::cleanupTestCase() +{ +} + +void tst_QAbstractVideoBuffer::init() +{ +} + +void tst_QAbstractVideoBuffer::cleanup() +{ +} + +void tst_QAbstractVideoBuffer::handleType_data() +{ + QTest::addColumn("type"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(NoHandle); + ADD_ENUM_TEST(GLTextureHandle); + ADD_ENUM_TEST(XvShmImageHandle); + ADD_ENUM_TEST(QPixmapHandle); + ADD_ENUM_TEST(CoreImageHandle); + + // User handles are different + + QTest::newRow("user1") + << QAbstractVideoBuffer::UserHandle << QString::fromAscii("UserHandle(1000)"); + QTest::newRow("user2") + << QAbstractVideoBuffer::HandleType(QAbstractVideoBuffer::UserHandle + 1) << QString::fromAscii("UserHandle(1001)"); +} + +void tst_QAbstractVideoBuffer::handleType() +{ + QFETCH(QAbstractVideoBuffer::HandleType, type); + QFETCH(QString, stringized); + + QtTestVideoBuffer buffer(type); + + QCOMPARE(buffer.handleType(), type); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << type; +} + +void tst_QAbstractVideoBuffer::handle() +{ + QtTestVideoBuffer buffer(QAbstractVideoBuffer::NoHandle); + + QVERIFY(buffer.handle().isNull()); +} + +void tst_QAbstractVideoBuffer::mapMode() +{ + QtTestVideoBuffer maptest(QAbstractVideoBuffer::NoHandle); + QVERIFY2(maptest.mapMode() == QAbstractVideoBuffer::ReadWrite, "ReadWrite Failed"); +} + +void tst_QAbstractVideoBuffer::mapModeDebug_data() +{ + QTest::addColumn("mapMode"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(NotMapped); + ADD_ENUM_TEST(ReadOnly); + ADD_ENUM_TEST(WriteOnly); + ADD_ENUM_TEST(ReadWrite); +} + +void tst_QAbstractVideoBuffer::mapModeDebug() +{ + QFETCH(QAbstractVideoBuffer::MapMode, mapMode); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << mapMode; +} + +QTEST_MAIN(tst_QAbstractVideoBuffer) + +#include "tst_qabstractvideobuffer.moc" diff --git a/tests/auto/unit/qabstractvideosurface/qabstractvideosurface.pro b/tests/auto/unit/qabstractvideosurface/qabstractvideosurface.pro new file mode 100644 index 000000000..c1718a683 --- /dev/null +++ b/tests/auto/unit/qabstractvideosurface/qabstractvideosurface.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qabstractvideosurface + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qabstractvideosurface.cpp + diff --git a/tests/auto/unit/qabstractvideosurface/tst_qabstractvideosurface.cpp b/tests/auto/unit/qabstractvideosurface/tst_qabstractvideosurface.cpp new file mode 100644 index 000000000..1f3cdea06 --- /dev/null +++ b/tests/auto/unit/qabstractvideosurface/tst_qabstractvideosurface.cpp @@ -0,0 +1,409 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include +#include + +class tst_QAbstractVideoSurface : public QObject +{ + Q_OBJECT +public: + tst_QAbstractVideoSurface(); + ~tst_QAbstractVideoSurface(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void setError(); + void isFormatSupported_data(); + void isFormatSupported(); + void nearestFormat_data(); + void nearestFormat(); + void start_data(); + void start(); + void nativeResolution(); + void supportedFormatsChanged(); +}; + +typedef QMap SupportedFormatMap; + +Q_DECLARE_METATYPE(SupportedFormatMap) + +class QtTestVideoSurface : public QAbstractVideoSurface +{ + Q_OBJECT +public: + explicit QtTestVideoSurface(QObject *parent = 0) : QAbstractVideoSurface(parent) {} + explicit QtTestVideoSurface(SupportedFormatMap formats, QObject *parent = 0) + : QAbstractVideoSurface(parent), supportedFormats(formats) {} + + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const + { + return supportedFormats.values(handleType); + } + + bool present(const QVideoFrame &) { return false; } + + using QAbstractVideoSurface::setError; + + /* adding protected setNativeResolution*/ + using QAbstractVideoSurface::setNativeResolution; + + /* fun to generate supportedFormatsChanged signal */ + QList supportedPixelFormatsChange(QList formats) + { + supportedFormats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32); + QList supportedFormats = supportedPixelFormats(); + if (supportedFormats.count() != formats.count()) { + emit supportedFormatsChanged(); + } + return supportedFormats; + } + +private: + SupportedFormatMap supportedFormats; +}; + +tst_QAbstractVideoSurface::tst_QAbstractVideoSurface() +{ +} + +tst_QAbstractVideoSurface::~tst_QAbstractVideoSurface() +{ +} + +void tst_QAbstractVideoSurface::initTestCase() +{ +} + +void tst_QAbstractVideoSurface::cleanupTestCase() +{ +} + +void tst_QAbstractVideoSurface::init() +{ +} + +void tst_QAbstractVideoSurface::cleanup() +{ +} + +void tst_QAbstractVideoSurface::setError() +{ + qRegisterMetaType(); + + QtTestVideoSurface surface; + + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + QTest::ignoreMessage(QtDebugMsg, "NoError"); + qDebug() << QAbstractVideoSurface::NoError; + + surface.setError(QAbstractVideoSurface::StoppedError); + QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); + QTest::ignoreMessage(QtDebugMsg, "StoppedError"); + qDebug() << QAbstractVideoSurface::StoppedError; + + surface.setError(QAbstractVideoSurface::ResourceError); + QCOMPARE(surface.error(), QAbstractVideoSurface::ResourceError); + QTest::ignoreMessage(QtDebugMsg, "ResourceError"); + qDebug() << QAbstractVideoSurface::ResourceError; + + surface.setError(QAbstractVideoSurface::NoError); + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + QTest::ignoreMessage(QtDebugMsg, "NoError"); + qDebug() << QAbstractVideoSurface::NoError; + + surface.setError(QAbstractVideoSurface::UnsupportedFormatError); + QCOMPARE(surface.error(), QAbstractVideoSurface::UnsupportedFormatError); + QTest::ignoreMessage(QtDebugMsg, "UnsupportedFormatError"); + qDebug() << QAbstractVideoSurface::UnsupportedFormatError; + + surface.setError(QAbstractVideoSurface::IncorrectFormatError); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); + QTest::ignoreMessage(QtDebugMsg, "IncorrectFormatError"); + qDebug() << QAbstractVideoSurface::IncorrectFormatError; +} + +void tst_QAbstractVideoSurface::isFormatSupported_data() +{ + QTest::addColumn("supportedFormats"); + QTest::addColumn("format"); + QTest::addColumn("supported"); + + SupportedFormatMap formats; + + QTest::newRow("no formats: rgb32") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) + << false; + QTest::newRow("no formats: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << false; + QTest::newRow("no formats: rgb32 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle) + << false; + QTest::newRow("no formats: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << false; + + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32); + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24); + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YUV444); + formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB32); + + QTest::newRow("supported: rgb32") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) + << true; + QTest::newRow("supported: rgb24") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB24) + << true; + QTest::newRow("unsupported: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << false; + QTest::newRow("supported: rgb32 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle) + << true; + QTest::newRow("unsupported: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << false; + QTest::newRow("unsupported: yv12 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_YV12, + QAbstractVideoBuffer::GLTextureHandle) + << false; + + formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YV12); + formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB24); + + QTest::newRow("supported: yv12") + << formats + << QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) + << true; + QTest::newRow("supported: rgb24 gl") + << formats + << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB24, + QAbstractVideoBuffer::GLTextureHandle) + << true; +} + +void tst_QAbstractVideoSurface::isFormatSupported() +{ + QFETCH(SupportedFormatMap, supportedFormats); + QFETCH(QVideoSurfaceFormat, format); + QFETCH(bool, supported); + + QtTestVideoSurface surface(supportedFormats); + + QCOMPARE(surface.isFormatSupported(format), supported); +} + +void tst_QAbstractVideoSurface::nearestFormat_data() +{ + isFormatSupported_data(); +} + +void tst_QAbstractVideoSurface::nearestFormat() +{ + QFETCH(SupportedFormatMap, supportedFormats); + QFETCH(QVideoSurfaceFormat, format); + QFETCH(bool, supported); + + QtTestVideoSurface surface(supportedFormats); + + QCOMPARE(surface.nearestFormat(format) == format, supported); +} + +void tst_QAbstractVideoSurface::start_data() +{ + QTest::addColumn("format"); + + QTest::newRow("rgb32") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32); + QTest::newRow("yv12") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_YV12); + QTest::newRow("rgb32 gl") << QVideoSurfaceFormat( + QSize(800, 600), + QVideoFrame::Format_RGB32, + QAbstractVideoBuffer::GLTextureHandle); +} + +void tst_QAbstractVideoSurface::start() +{ + QFETCH(QVideoSurfaceFormat, format); + + QtTestVideoSurface surface; + surface.setError(QAbstractVideoSurface::ResourceError); + + QSignalSpy formatSpy(&surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat))); + QSignalSpy activeSpy(&surface, SIGNAL(activeChanged(bool))); + + QVERIFY(!surface.isActive()); + QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); + + QVERIFY(surface.start(format)); + + QVERIFY(surface.isActive()); + QCOMPARE(surface.surfaceFormat(), format); + + QCOMPARE(formatSpy.count(), 1); + QCOMPARE(qvariant_cast(formatSpy.last().at(0)), format); + + QCOMPARE(activeSpy.count(), 1); + QCOMPARE(activeSpy.last().at(0).toBool(), true); + + // Starting twice won't change active + // XXX should this also not emit surfaceFormatChanged? + QVERIFY(surface.start(format)); + QCOMPARE(activeSpy.count(), 1); + QVERIFY(surface.isActive()); + + // error() is reset on a successful start. + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + surface.stop(); + + QVERIFY(!surface.isActive()); + QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); + + QCOMPARE(formatSpy.count(), 3); + QCOMPARE(qvariant_cast(formatSpy.last().at(0)), QVideoSurfaceFormat()); + + QCOMPARE(activeSpy.count(), 2); + QCOMPARE(activeSpy.last().at(0).toBool(), false); + + // Stopping a stopped surface shouldn't hurt + surface.stop(); + + QVERIFY(!surface.isActive()); + QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); + + QCOMPARE(formatSpy.count(), 3); + QCOMPARE(qvariant_cast(formatSpy.last().at(0)), QVideoSurfaceFormat()); + + QCOMPARE(activeSpy.count(), 2); + QCOMPARE(activeSpy.last().at(0).toBool(), false); +} + +// Test nativeResolution property +void tst_QAbstractVideoSurface::nativeResolution() +{ + QtTestVideoSurface surface; + QSignalSpy spy(&surface, SIGNAL(nativeResolutionChanged(QSize))); + QSize size1 = surface.nativeResolution(); + QVERIFY(size1.width() == -1); + QVERIFY(size1.height() == -1); + QVERIFY(spy.count() == 0); + + QSize res(100,150); + surface.setNativeResolution(res); + QVERIFY(spy.count() == 1); + + QSize size2 = qvariant_cast(spy.at(0).at(0)); + QVERIFY(size2.width() == 100); + QVERIFY(size2.height() == 150); + + // Setting again should not emit + surface.setNativeResolution(res); + QVERIFY(spy.count() == 1); + + size2 = qvariant_cast(spy.at(0).at(0)); + QVERIFY(size2.width() == 100); + QVERIFY(size2.height() == 150); + + spy.clear(); +} + +// QAbstractVideoSurface's supported Formats Changed Signal +void tst_QAbstractVideoSurface::supportedFormatsChanged() +{ + SupportedFormatMap formatMap; + formatMap.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24); + QtTestVideoSurface surface(formatMap); + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + QList formats = surface.supportedPixelFormats(); + QVERIFY(formats.count() == 1); + QVERIFY(spy.count() == 0); + + // user defined implementation for generation of supportedFormatsChanged signal + QList newFormats = surface.supportedPixelFormatsChange(formats); + QVERIFY(newFormats.count() == (formats.count() + 1)); + QVERIFY(spy.count() == 1); + spy.clear(); +} + +QTEST_MAIN(tst_QAbstractVideoSurface) + +#include "tst_qabstractvideosurface.moc" diff --git a/tests/auto/unit/qaudiocapturesource/qaudiocapturesource.pro b/tests/auto/unit/qaudiocapturesource/qaudiocapturesource.pro new file mode 100644 index 000000000..1d0c2e294 --- /dev/null +++ b/tests/auto/unit/qaudiocapturesource/qaudiocapturesource.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qaudiocapturesource + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qaudiocapturesource.cpp + +include (../qmultimedia_common/mockrecorder.pri) +include (../qmultimedia_common/mock.pri) + diff --git a/tests/auto/unit/qaudiocapturesource/tst_qaudiocapturesource.cpp b/tests/auto/unit/qaudiocapturesource/tst_qaudiocapturesource.cpp new file mode 100644 index 000000000..d2620b8eb --- /dev/null +++ b/tests/auto/unit/qaudiocapturesource/tst_qaudiocapturesource.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +//TESTED_COMPONENT=src/multimedia + +#include "mockmediaserviceprovider.h" +#include "mockmediarecorderservice.h" + +QT_USE_NAMESPACE + +class tst_QAudioCaptureSource: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + //void testNullService(); + //void testNullControl(); + void testAudioSource(); + void testOptions(); + void testDevices(); + void testAvailability(); + void testAvailableAudioInputChangedSignal(); + +private: + QAudioCaptureSource *audiosource; + MockMediaRecorderService *mockMediaRecorderService; + MockMediaServiceProvider *mockProvider; +}; + +void tst_QAudioCaptureSource::initTestCase() +{ + mockMediaRecorderService = new MockMediaRecorderService; + mockProvider = new MockMediaServiceProvider(mockMediaRecorderService); +} + +void tst_QAudioCaptureSource::cleanupTestCase() +{ + delete audiosource; + delete mockProvider; + audiosource = 0; +} +/* +void tst_QAudioCaptureSource::testNullService() +{ + MockProvider provider(0); + QAudioCaptureSource source(0, &provider); + + QCOMPARE(source.audioInputs().size(), 0); + QCOMPARE(source.defaultAudioInput(), QString()); + QCOMPARE(source.activeAudioInput(), QString()); +} +*/ +/* +void tst_QAudioCaptureSource::testNullControl() +{ + MockRecorderService service; + service.hasAudioDeviceControl = false; + MockProvider provider(&service); + QAudioCaptureSource source(0, &provider); + + QCOMPARE(source.audioInputs().size(), 0); + QCOMPARE(source.defaultAudioInput(), QString()); + QCOMPARE(source.activeAudioInput(), QString()); + + QCOMPARE(source.audioDescription("blah"), QString()); + + QSignalSpy deviceNameSpy(&source, SIGNAL(activeAudioInputChanged(QString))); + + source.setAudioInput("blah"); + QCOMPARE(deviceNameSpy.count(), 0); +} +*/ +void tst_QAudioCaptureSource::testAudioSource() +{ + audiosource = new QAudioCaptureSource(0, mockProvider); + + QCOMPARE(audiosource->service(),(QMediaService *) mockMediaRecorderService); +} + +void tst_QAudioCaptureSource::testOptions() +{ + const QString codec(QLatin1String("audio/mpeg")); + + QStringList options = mockMediaRecorderService->mockAudioEncoderControl->supportedEncodingOptions(codec); + QCOMPARE(options.count(), 4); + mockMediaRecorderService->mockAudioEncoderControl->setEncodingOption(codec, options.first(),8000); + QVERIFY(mockMediaRecorderService->mockAudioEncoderControl->encodingOption(codec, options.first()).toInt() == 8000); +} + +void tst_QAudioCaptureSource::testDevices() +{ + audiosource = new QAudioCaptureSource(0,mockProvider); + QList devices = audiosource->audioInputs(); + QVERIFY(devices.size() > 0); + QVERIFY(devices.at(0).compare("device1") == 0); + QVERIFY(audiosource->audioDescription("device1").compare("dev1 comment") == 0); + QVERIFY(audiosource->defaultAudioInput() == "device1"); + QVERIFY(audiosource->isAvailable() == true); + + QSignalSpy checkSignal(audiosource, SIGNAL(activeAudioInputChanged(QString))); + audiosource->setAudioInput("device2"); + QVERIFY(audiosource->activeAudioInput().compare("device2") == 0); + QVERIFY(checkSignal.count() == 1); + QVERIFY(audiosource->isAvailable() == true); +} + +void tst_QAudioCaptureSource::testAvailability() +{ + MockMediaRecorderService service; + service.hasControls = false; + MockMediaServiceProvider provider(&service); + QAudioCaptureSource source(0, &provider); + + QVERIFY(source.isAvailable() == false); + QVERIFY(source.availabilityError() == QtMultimedia::ServiceMissingError); + + service.hasControls = true; + MockMediaServiceProvider provider2(&service); + QAudioCaptureSource source2(0, &provider2); + + QVERIFY(source2.isAvailable() == true); + QVERIFY(source2.availabilityError() == QtMultimedia::NoError); +} + +void tst_QAudioCaptureSource::testAvailableAudioInputChangedSignal() +{ + // The availabilityChangedSignal is implemented in QAudioCaptureSource. SO using it to test the signal. + audiosource = new QAudioCaptureSource(0, mockProvider); + + /* Spy the signal availableEndpointChanged and audioInputchanged */ + QSignalSpy changed(mockMediaRecorderService->mockAudioEndpointSelector, SIGNAL(availableEndpointsChanged())); + QSignalSpy audioInputchange(audiosource, SIGNAL(availableAudioInputsChanged())); + + /* Add the end points and verify if the available end point changed signal is emitted. */ + QMetaObject::invokeMethod(mockMediaRecorderService->mockAudioEndpointSelector, "addEndpoints"); + QVERIFY(changed.count() == 1); + QVERIFY(audioInputchange.count() == 1); + + /* Now try removes */ + changed.clear(); + audioInputchange.clear(); + QMetaObject::invokeMethod(mockMediaRecorderService->mockAudioEndpointSelector, "removeEndpoints"); + QVERIFY(changed.count() == 1); + QVERIFY(audioInputchange.count() == 1); +} + +QTEST_MAIN(tst_QAudioCaptureSource) + +#include "tst_qaudiocapturesource.moc" diff --git a/tests/auto/unit/qaudiodeviceinfo/qaudiodeviceinfo.pro b/tests/auto/unit/qaudiodeviceinfo/qaudiodeviceinfo.pro new file mode 100644 index 000000000..ffe9829bd --- /dev/null +++ b/tests/auto/unit/qaudiodeviceinfo/qaudiodeviceinfo.pro @@ -0,0 +1,10 @@ +TARGET = tst_qaudiodeviceinfo + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +# This is more of a system test +# CONFIG += testcase + +SOURCES += tst_qaudiodeviceinfo.cpp + diff --git a/tests/auto/unit/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp b/tests/auto/unit/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp new file mode 100644 index 000000000..f459a7449 --- /dev/null +++ b/tests/auto/unit/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include + +#include +#include + +//TESTED_COMPONENT=src/multimedia + +class tst_QAudioDeviceInfo : public QObject +{ + Q_OBJECT +public: + tst_QAudioDeviceInfo(QObject* parent=0) : QObject(parent) {} + +private slots: + void initTestCase(); + void checkAvailableDefaultInput(); + void checkAvailableDefaultOutput(); + void outputList(); + void codecs(); + void channels(); + void sampleSizes(); + void byteOrders(); + void sampleTypes(); + void frequencies(); + void isFormatSupported(); + void preferred(); + void nearest(); + void supportedChannelCounts(); + void supportedSampleRates(); + void assignOperator(); + void deviceName(); + void defaultConstructor(); + +private: + bool available; + QAudioDeviceInfo* device; +}; + +void tst_QAudioDeviceInfo::initTestCase() +{ + // Only perform tests if audio output device exists! + QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + if (devices.size() > 0) + available = true; + else { + qWarning()<<"NOTE: no audio output device found, no test will be performed"; + available = false; + } +} + +void tst_QAudioDeviceInfo::checkAvailableDefaultInput() +{ + // Only perform tests if audio input device exists! + bool storeAvailable = available; + QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); + if (devices.size() > 0) + available = true; + else { + qWarning()<<"NOTE: no audio input device found, no test will be performed"; + available = false; + } + if (available) + QVERIFY(!QAudioDeviceInfo::defaultInputDevice().isNull()); + available = storeAvailable; +} + +void tst_QAudioDeviceInfo::checkAvailableDefaultOutput() +{ + if (available) + QVERIFY(!QAudioDeviceInfo::defaultOutputDevice().isNull()); +} + +void tst_QAudioDeviceInfo::outputList() +{ + if (available) { + QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + QVERIFY(devices.size() > 0); + device = new QAudioDeviceInfo(devices.at(0)); + } +} + +void tst_QAudioDeviceInfo::codecs() +{ + if (available) { + QStringList avail = device->supportedCodecs(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::channels() +{ + if (available) { + QList avail = device->supportedChannels(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::sampleSizes() +{ + if (available) { + QList avail = device->supportedSampleSizes(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::byteOrders() +{ + if (available) { + QList avail = device->supportedByteOrders(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::sampleTypes() +{ + if (available) { + QList avail = device->supportedSampleTypes(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::frequencies() +{ + if (available) { + QList avail = device->supportedFrequencies(); + QVERIFY(avail.size() > 0); + } +} + +void tst_QAudioDeviceInfo::isFormatSupported() +{ + if (available) { + QAudioFormat format; + format.setFrequency(44100); + format.setChannels(2); + format.setSampleType(QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + + // Should always be true for these format + QVERIFY(device->isFormatSupported(format)); + } +} + +void tst_QAudioDeviceInfo::preferred() +{ + if (available) { + QAudioFormat format = device->preferredFormat(); + QVERIFY(format.isValid()); + } +} + +// Returns closest QAudioFormat to settings that system audio supports. +void tst_QAudioDeviceInfo::nearest() +{ + if (available) { + /* + QAudioFormat format1, format2; + format1.setFrequency(8000); + format2 = device->nearestFormat(format1); + QVERIFY(format2.frequency() == 44100); + */ + QAudioFormat format; + format.setFrequency(44100); + format.setChannels(2); + format.setSampleType(QAudioFormat::SignedInt); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleSize(16); + format.setCodec("audio/pcm"); + + QAudioFormat format2 = device->nearestFormat(format); + + // This is definitely dependent on platform support (but isFormatSupported tests that above) + QVERIFY(format2.frequency() == 44100); + } +} + +// Returns a list of supported channel counts. +void tst_QAudioDeviceInfo::supportedChannelCounts() +{ + if (available) { + QList avail = device->supportedChannelCounts(); + QVERIFY(avail.size() > 0); + } +} + +// Returns a list of supported sample rates. +void tst_QAudioDeviceInfo::supportedSampleRates() +{ + if (available) { + QList avail = device->supportedSampleRates(); + QVERIFY(avail.size() > 0); + } +} + +// QAudioDeviceInfo's assignOperator method +void tst_QAudioDeviceInfo::assignOperator() +{ + QAudioDeviceInfo dev; + QVERIFY(dev.deviceName() == NULL); + QVERIFY(dev.isNull() == true); + + if (available) { + QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + QVERIFY(devices.size() > 0); + QAudioDeviceInfo dev1(devices.at(0)); + dev = dev1; + QVERIFY(dev.isNull() == false); + QVERIFY(dev.deviceName() == dev1.deviceName()); + } +} + +// Returns human readable name of audio device +void tst_QAudioDeviceInfo::deviceName() +{ + if (available) { + QVERIFY(device->deviceName() != NULL); + QVERIFY(device->deviceName() == QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).at(0).deviceName()); + } +} + +// QAudioDeviceInfo's defaultConstructor method +void tst_QAudioDeviceInfo::defaultConstructor() +{ + QAudioDeviceInfo dev; + QVERIFY(dev.isNull() == true); + QVERIFY(dev.deviceName() == NULL); +} + +QTEST_MAIN(tst_QAudioDeviceInfo) + +#include "tst_qaudiodeviceinfo.moc" diff --git a/tests/auto/unit/qaudioformat/qaudioformat.pro b/tests/auto/unit/qaudioformat/qaudioformat.pro new file mode 100644 index 000000000..59ba5c38f --- /dev/null +++ b/tests/auto/unit/qaudioformat/qaudioformat.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qaudioformat + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qaudioformat.cpp + diff --git a/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp new file mode 100644 index 000000000..cdfa4766c --- /dev/null +++ b/tests/auto/unit/qaudioformat/tst_qaudioformat.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include + +#include +#include + +//TESTED_COMPONENT=src/multimedia + +class tst_QAudioFormat : public QObject +{ + Q_OBJECT + +public: + tst_QAudioFormat(QObject* parent=0) : QObject(parent) {} + +private slots: + void checkNull(); + void checkFrequency(); + void checkSampleSize(); + void checkCodec(); + void checkByteOrder(); + void checkSampleType(); + void checkEquality(); + void checkAssignment(); + void checkSampleRate(); + void checkChannelCount(); + + void debugOperator(); + void debugOperator_data(); +}; + +void tst_QAudioFormat::checkNull() +{ + // Default constructed QAudioFormat is invalid. + QAudioFormat audioFormat0; + QVERIFY(!audioFormat0.isValid()); + + // validity is transferred + QAudioFormat audioFormat1(audioFormat0); + QVERIFY(!audioFormat1.isValid()); + + audioFormat0.setFrequency(44100); + audioFormat0.setChannels(2); + audioFormat0.setSampleSize(16); + audioFormat0.setCodec("audio/pcm"); + audioFormat0.setSampleType(QAudioFormat::SignedInt); + QVERIFY(audioFormat0.isValid()); +} + +void tst_QAudioFormat::checkFrequency() +{ + QAudioFormat audioFormat; + audioFormat.setFrequency(44100); + QVERIFY(audioFormat.frequency() == 44100); +} + +void tst_QAudioFormat::checkSampleSize() +{ + QAudioFormat audioFormat; + audioFormat.setSampleSize(16); + QVERIFY(audioFormat.sampleSize() == 16); +} + +void tst_QAudioFormat::checkCodec() +{ + QAudioFormat audioFormat; + audioFormat.setCodec(QString::fromLatin1("audio/pcm")); + QVERIFY(audioFormat.codec() == QString::fromLatin1("audio/pcm")); +} + +void tst_QAudioFormat::checkByteOrder() +{ + QAudioFormat audioFormat; + audioFormat.setByteOrder(QAudioFormat::LittleEndian); + QVERIFY(audioFormat.byteOrder() == QAudioFormat::LittleEndian); + + QTest::ignoreMessage(QtDebugMsg, "LittleEndian"); + qDebug() << QAudioFormat::LittleEndian; + + audioFormat.setByteOrder(QAudioFormat::BigEndian); + QVERIFY(audioFormat.byteOrder() == QAudioFormat::BigEndian); + + QTest::ignoreMessage(QtDebugMsg, "BigEndian"); + qDebug() << QAudioFormat::BigEndian; +} + +void tst_QAudioFormat::checkSampleType() +{ + QAudioFormat audioFormat; + audioFormat.setSampleType(QAudioFormat::SignedInt); + QVERIFY(audioFormat.sampleType() == QAudioFormat::SignedInt); + QTest::ignoreMessage(QtDebugMsg, "SignedInt"); + qDebug() << QAudioFormat::SignedInt; + + audioFormat.setSampleType(QAudioFormat::Unknown); + QVERIFY(audioFormat.sampleType() == QAudioFormat::Unknown); + QTest::ignoreMessage(QtDebugMsg, "Unknown"); + qDebug() << QAudioFormat::Unknown; + + audioFormat.setSampleType(QAudioFormat::UnSignedInt); + QVERIFY(audioFormat.sampleType() == QAudioFormat::UnSignedInt); + QTest::ignoreMessage(QtDebugMsg, "UnSignedInt"); + qDebug() << QAudioFormat::UnSignedInt; + + audioFormat.setSampleType(QAudioFormat::Float); + QVERIFY(audioFormat.sampleType() == QAudioFormat::Float); + QTest::ignoreMessage(QtDebugMsg, "Float"); + qDebug() << QAudioFormat::Float; +} + +void tst_QAudioFormat::checkEquality() +{ + QAudioFormat audioFormat0; + QAudioFormat audioFormat1; + + // Null formats are equivalent + QVERIFY(audioFormat0 == audioFormat1); + QVERIFY(!(audioFormat0 != audioFormat1)); + + // on filled formats + audioFormat0.setFrequency(8000); + audioFormat0.setChannels(1); + audioFormat0.setSampleSize(8); + audioFormat0.setCodec("audio/pcm"); + audioFormat0.setByteOrder(QAudioFormat::LittleEndian); + audioFormat0.setSampleType(QAudioFormat::UnSignedInt); + + audioFormat1.setFrequency(8000); + audioFormat1.setChannels(1); + audioFormat1.setSampleSize(8); + audioFormat1.setCodec("audio/pcm"); + audioFormat1.setByteOrder(QAudioFormat::LittleEndian); + audioFormat1.setSampleType(QAudioFormat::UnSignedInt); + + QVERIFY(audioFormat0 == audioFormat1); + QVERIFY(!(audioFormat0 != audioFormat1)); + + audioFormat0.setFrequency(44100); + QVERIFY(audioFormat0 != audioFormat1); + QVERIFY(!(audioFormat0 == audioFormat1)); +} + +void tst_QAudioFormat::checkAssignment() +{ + QAudioFormat audioFormat0; + QAudioFormat audioFormat1; + + audioFormat0.setFrequency(8000); + audioFormat0.setChannels(1); + audioFormat0.setSampleSize(8); + audioFormat0.setCodec("audio/pcm"); + audioFormat0.setByteOrder(QAudioFormat::LittleEndian); + audioFormat0.setSampleType(QAudioFormat::UnSignedInt); + + audioFormat1 = audioFormat0; + QVERIFY(audioFormat1 == audioFormat0); + + QAudioFormat audioFormat2(audioFormat0); + QVERIFY(audioFormat2 == audioFormat0); +} + +/* sampleRate() API property test. */ +void tst_QAudioFormat::checkSampleRate() +{ + QAudioFormat audioFormat; + QVERIFY(audioFormat.sampleRate() == -1); + + audioFormat.setSampleRate(123); + QVERIFY(audioFormat.sampleRate() == 123); +} + +/* channelCount() API property test. */ +void tst_QAudioFormat::checkChannelCount() +{ + // channels is the old name for channelCount, so + // they should always be equal + QAudioFormat audioFormat; + QVERIFY(audioFormat.channelCount() == -1); + QVERIFY(audioFormat.channels() == -1); + + audioFormat.setChannelCount(123); + QVERIFY(audioFormat.channelCount() == 123); + QVERIFY(audioFormat.channels() == 123); + + audioFormat.setChannels(5); + QVERIFY(audioFormat.channelCount() == 5); + QVERIFY(audioFormat.channels() == 5); +} + +void tst_QAudioFormat::debugOperator_data() +{ + QTest::addColumn("format"); + QTest::addColumn("stringized"); + + // A small sampling + QAudioFormat f; + QTest::newRow("plain") << f << QString::fromLatin1("QAudioFormat(-1Hz, -1bit, channelCount=-1, sampleType=Unknown, byteOrder=LittleEndian, codec=\"\") "); + + f.setSampleRate(22050); + f.setByteOrder(QAudioFormat::LittleEndian); + f.setChannelCount(4); + f.setCodec("audio/pcm"); + f.setSampleType(QAudioFormat::Float); + + QTest::newRow("float") << f << QString::fromLatin1("QAudioFormat(22050Hz, -1bit, channelCount=4, sampleType=Float, byteOrder=LittleEndian, codec=\"audio/pcm\") "); + + f.setSampleType(QAudioFormat::UnSignedInt); + QTest::newRow("unsigned") << f << QString::fromLatin1("QAudioFormat(22050Hz, -1bit, channelCount=4, sampleType=UnSignedInt, byteOrder=LittleEndian, codec=\"audio/pcm\") "); + + f.setSampleRate(44100); + QTest::newRow("44.1 unsigned") << f << QString::fromLatin1("QAudioFormat(44100Hz, -1bit, channelCount=4, sampleType=UnSignedInt, byteOrder=LittleEndian, codec=\"audio/pcm\") "); + + f.setByteOrder(QAudioFormat::BigEndian); + QTest::newRow("44.1 big unsigned") << f << QString::fromLatin1("QAudioFormat(44100Hz, -1bit, channelCount=4, sampleType=UnSignedInt, byteOrder=BigEndian, codec=\"audio/pcm\") "); +} + +void tst_QAudioFormat::debugOperator() +{ + QFETCH(QAudioFormat, format); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << format; +} + +QTEST_MAIN(tst_QAudioFormat) + +#include "tst_qaudioformat.moc" diff --git a/tests/auto/unit/qaudionamespace/qaudionamespace.pro b/tests/auto/unit/qaudionamespace/qaudionamespace.pro new file mode 100644 index 000000000..30052ce3f --- /dev/null +++ b/tests/auto/unit/qaudionamespace/qaudionamespace.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qaudionamespace + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qaudionamespace.cpp + diff --git a/tests/auto/unit/qaudionamespace/tst_qaudionamespace.cpp b/tests/auto/unit/qaudionamespace/tst_qaudionamespace.cpp new file mode 100644 index 000000000..1140e5520 --- /dev/null +++ b/tests/auto/unit/qaudionamespace/tst_qaudionamespace.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include "qaudio.h" + +// Adds an enum, and the stringized version +#define ADD_ENUM_TEST(x) \ + QTest::newRow(#x) \ + << QAudio::x \ + << QString(QLatin1String(#x)); + +class tst_QAudioNamespace : public QObject +{ + Q_OBJECT + +private slots: + void debugError(); + void debugError_data(); + void debugState(); + void debugState_data(); + void debugMode(); + void debugMode_data(); +}; + +void tst_QAudioNamespace::debugError_data() +{ + QTest::addColumn("error"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(NoError); + ADD_ENUM_TEST(OpenError); + ADD_ENUM_TEST(IOError); + ADD_ENUM_TEST(UnderrunError); + ADD_ENUM_TEST(FatalError); +} + +void tst_QAudioNamespace::debugError() +{ + QFETCH(QAudio::Error, error); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << error; +} + +void tst_QAudioNamespace::debugState_data() +{ + QTest::addColumn("state"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(ActiveState); + ADD_ENUM_TEST(SuspendedState); + ADD_ENUM_TEST(StoppedState); + ADD_ENUM_TEST(IdleState); +} + +void tst_QAudioNamespace::debugState() +{ + QFETCH(QAudio::State, state); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << state; +} + +void tst_QAudioNamespace::debugMode_data() +{ + QTest::addColumn("mode"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(AudioInput); + ADD_ENUM_TEST(AudioOutput); +} + +void tst_QAudioNamespace::debugMode() +{ + QFETCH(QAudio::Mode, mode); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << mode; +} +QTEST_MAIN(tst_QAudioNamespace) + +#include "tst_qaudionamespace.moc" diff --git a/tests/auto/unit/qcamera/qcamera.pro b/tests/auto/unit/qcamera/qcamera.pro new file mode 100644 index 000000000..095349d81 --- /dev/null +++ b/tests/auto/unit/qcamera/qcamera.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qcamera + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + +SOURCES += tst_qcamera.cpp diff --git a/tests/auto/unit/qcamera/tst_qcamera.cpp b/tests/auto/unit/qcamera/tst_qcamera.cpp new file mode 100644 index 000000000..de44ae0d8 --- /dev/null +++ b/tests/auto/unit/qcamera/tst_qcamera.cpp @@ -0,0 +1,1956 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mockcameraservice.h" + +#include "mockmediaserviceprovider.h" +#include "mockvideosurface.h" +#include "mockvideorenderercontrol.h" +#include "mockvideowindowcontrol.h" + +QT_USE_NAMESPACE + + +class tst_QCamera: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testAvailableDevices(); + void testDeviceDescription(); + void testCtorWithDevice(); + void testSimpleCamera(); + void testSimpleCameraWhiteBalance(); + void testSimpleCameraExposure(); + void testSimpleCameraFocus(); + void testSimpleCameraCapture(); + void testSimpleCameraLock(); + void testSimpleCaptureDestination(); + void testSimpleCaptureFormat(); + + void testCameraWhiteBalance(); + void testCameraExposure(); + void testCameraFocus(); + void testCameraCapture(); + void testCameraCaptureMetadata(); + void testImageSettings(); + void testCameraLock(); + void testCameraLockCancel(); + void testCameraEncodingProperyChange(); + void testCaptureDestination(); + void testCaptureFormat(); + + void testConstructorWithDefaultProvider(); + void testCaptureMode(); + void testIsCaptureModeSupported(); + void testRequestedLocks(); + void testSupportedLocks(); + void testQCameraIsAvailable(); + void testAvailabilityError(); + void testSearchAndLockWithLockTypes(); + void testSetCaptureMode(); + void testUnlockWithType(); + void testCaptureModeChangedSignal(); + void testLockStatusChangedWithTypesSignal(); + void testErrorSignal(); + void testError(); + void testErrorString(); + void testStatus(); + void testLockType(); + void testLockChangeReason(); + + + // Test cases to for QCameraFocus + void testCameraFocusIsAvailable(); + void testFocusModes(); + void testOpticalAndDigitalZoomChanged(); + void testMaxOpticalZoomChangedSignal(); + void testMaxDigitalZoomChangedSignal(); + void testfocusZonesChangedSignal(); + + // Test cases for QCameraControl class. + void testCameraControl(); + void testCaptureModeChanged_signal(); + void testEnumsOfQCameraControl(); + + // Test case for QCameraImageProcessing class + void testContrast(); + void testDenoisingLevel(); + void testIsAvailable(); + void testSaturation(); + void testSharpeningLevel(); + void testEnumOfQCameraImageProcessing(); + + void testSetVideoOutput(); + void testSetVideoOutputNoService(); + void testSetVideoOutputNoControl(); + void testSetVideoOutputDestruction(); + + void testEnumDebug(); + + // constructor for QCameraImageProceesing + void testImageProcessingControl(); + + // Signals test cases for QCameraExposure + void testSignalApertureChanged(); + void testSignalExposureCompensationChanged(); + void testSignalIsoSensitivityChanged(); + void testSignalShutterSpeedChanged(); + void testSignalFlashReady(); + + // test constructor + void testExposureControlConstructor(); + +private: + MockSimpleCameraService *mockSimpleCameraService; + MockMediaServiceProvider *provider; +}; + +void tst_QCamera::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockSimpleCameraService = new MockSimpleCameraService; + provider->service = mockSimpleCameraService; + qRegisterMetaType("QtMultimedia::MetaData"); +} + +void tst_QCamera::cleanupTestCase() +{ + delete mockSimpleCameraService; + delete provider; +} + +void tst_QCamera::testAvailableDevices() +{ + int deviceCount = QMediaServiceProvider::defaultServiceProvider()->devices(QByteArray(Q_MEDIASERVICE_CAMERA)).count(); + + QVERIFY(QCamera::availableDevices().count() == deviceCount); +} + +void tst_QCamera::testDeviceDescription() +{ + int deviceCount = QMediaServiceProvider::defaultServiceProvider()->devices(QByteArray(Q_MEDIASERVICE_CAMERA)).count(); + + if (deviceCount == 0) + QVERIFY(QCamera::deviceDescription(QByteArray("random")).isNull()); + else { + foreach (const QByteArray &device, QCamera::availableDevices()) + QVERIFY(QCamera::deviceDescription(device).length() > 0); + } +} + +void tst_QCamera::testCtorWithDevice() +{ + int deviceCount = QMediaServiceProvider::defaultServiceProvider()->devices(QByteArray(Q_MEDIASERVICE_CAMERA)).count(); + QCamera *camera = 0; + + if (deviceCount == 0) { + camera = new QCamera("random"); + QVERIFY(camera->error() == QCamera::ServiceMissingError); + } + else { + camera = new QCamera(QCamera::availableDevices().first()); + QVERIFY(camera->error() == QCamera::NoError); + } + + delete camera; +} + +void tst_QCamera::testSimpleCamera() +{ + QCamera camera(0, provider); + QCOMPARE(camera.service(), (QMediaService*)mockSimpleCameraService); + + QCOMPARE(camera.state(), QCamera::UnloadedState); + camera.start(); + QCOMPARE(camera.state(), QCamera::ActiveState); + camera.stop(); + QCOMPARE(camera.state(), QCamera::LoadedState); + camera.unload(); + QCOMPARE(camera.state(), QCamera::UnloadedState); + camera.load(); + QCOMPARE(camera.state(), QCamera::LoadedState); +} + +void tst_QCamera::testSimpleCameraWhiteBalance() +{ + QCamera camera(0, provider); + + //only WhiteBalanceAuto is supported + QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); + QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); + QCOMPARE(camera.imageProcessing()->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceAuto); + camera.imageProcessing()->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceCloudy); + QCOMPARE(camera.imageProcessing()->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceAuto); + QCOMPARE(camera.imageProcessing()->manualWhiteBalance(), 0); + camera.imageProcessing()->setManualWhiteBalance(5000); + QCOMPARE(camera.imageProcessing()->manualWhiteBalance(), 0); +} + +void tst_QCamera::testSimpleCameraExposure() +{ + QCamera camera(0, provider); + QCameraExposure *cameraExposure = camera.exposure(); + QVERIFY(cameraExposure != 0); + + QVERIFY(!cameraExposure->isExposureModeSupported(QCameraExposure::ExposureAuto)); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); + cameraExposure->setExposureMode(QCameraExposure::ExposureManual);//should be ignored + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); + + QVERIFY(!cameraExposure->isFlashModeSupported(QCameraExposure::FlashOff)); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOff); + QCOMPARE(cameraExposure->isFlashReady(), false); + cameraExposure->setFlashMode(QCameraExposure::FlashOn); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOff); + + QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringAverage)); + QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringSpot)); + QVERIFY(!cameraExposure->isMeteringModeSupported(QCameraExposure::MeteringMatrix)); + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); + cameraExposure->setMeteringMode(QCameraExposure::MeteringSpot); + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); + + QCOMPARE(cameraExposure->exposureCompensation(), 0.0); + cameraExposure->setExposureCompensation(2.0); + QCOMPARE(cameraExposure->exposureCompensation(), 0.0); + + QCOMPARE(cameraExposure->isoSensitivity(), -1); + QVERIFY(cameraExposure->supportedIsoSensitivities().isEmpty()); + cameraExposure->setManualIsoSensitivity(100); + QCOMPARE(cameraExposure->isoSensitivity(), -1); + cameraExposure->setAutoIsoSensitivity(); + QCOMPARE(cameraExposure->isoSensitivity(), -1); + + QVERIFY(cameraExposure->aperture() < 0); + QVERIFY(cameraExposure->supportedApertures().isEmpty()); + cameraExposure->setAutoAperture(); + QVERIFY(cameraExposure->aperture() < 0); + cameraExposure->setManualAperture(5.6); + QVERIFY(cameraExposure->aperture() < 0); + + QVERIFY(cameraExposure->shutterSpeed() < 0); + QVERIFY(cameraExposure->supportedShutterSpeeds().isEmpty()); + cameraExposure->setAutoShutterSpeed(); + QVERIFY(cameraExposure->shutterSpeed() < 0); + cameraExposure->setManualShutterSpeed(1/128.0); + QVERIFY(cameraExposure->shutterSpeed() < 0); +} + +void tst_QCamera::testSimpleCameraFocus() +{ + QCamera camera(0, provider); + + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::AutoFocus)); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::ContinuousFocus)); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::InfinityFocus)); + + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + QTest::ignoreMessage(QtWarningMsg, "Focus points mode selection is not supported"); + cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + + QCOMPARE(cameraFocus->maximumOpticalZoom(), 1.0); + QCOMPARE(cameraFocus->maximumDigitalZoom(), 1.0); + QCOMPARE(cameraFocus->opticalZoom(), 1.0); + QCOMPARE(cameraFocus->digitalZoom(), 1.0); + + QTest::ignoreMessage(QtWarningMsg, "The camera doesn't support zooming."); + cameraFocus->zoomTo(100.0, 100.0); + QCOMPARE(cameraFocus->opticalZoom(), 1.0); + QCOMPARE(cameraFocus->digitalZoom(), 1.0); + + + QVERIFY(!cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointAuto)); + QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); + + + cameraFocus->setFocusPointMode( QCameraFocus::FocusPointCenter ); + QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); + + QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); + QTest::ignoreMessage(QtWarningMsg, "Focus points selection is not supported"); + cameraFocus->setCustomFocusPoint(QPointF(1.0, 1.0)); + QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); +} + +void tst_QCamera::testSimpleCameraCapture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QVERIFY(!imageCapture.isReadyForCapture()); + QVERIFY(!imageCapture.isAvailable()); + + QCOMPARE(imageCapture.error(), QCameraImageCapture::NoError); + QVERIFY(imageCapture.errorString().isEmpty()); + + QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int, QCameraImageCapture::Error,QString))); + imageCapture.capture(QString::fromLatin1("/dev/null")); + QCOMPARE(errorSignal.size(), 1); + QCOMPARE(imageCapture.error(), QCameraImageCapture::NotSupportedFeatureError); + QVERIFY(!imageCapture.errorString().isEmpty()); +} + +void tst_QCamera::testSimpleCameraLock() +{ + QCamera camera(0, provider); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Unlocked); + + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + + camera.searchAndLock(); + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Locked); + QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Locked); + QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + + camera.unlock(); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockExposure), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockFocus), QCamera::Unlocked); + QCOMPARE(camera.lockStatus(QCamera::LockWhiteBalance), QCamera::Unlocked); + + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); +} + +void tst_QCamera::testSimpleCaptureDestination() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); + QVERIFY(!imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer)); + QVERIFY(!imageCapture.isCaptureDestinationSupported( + QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile)); + + QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); + imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer); + QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); +} + +void tst_QCamera::testSimpleCaptureFormat() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Invalid); + QVERIFY(imageCapture.supportedBufferFormats().isEmpty()); + + imageCapture.setBufferFormat(QVideoFrame::Format_AdobeDng); + QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Invalid); +} + +void tst_QCamera::testCaptureDestination() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToFile)); + QVERIFY(imageCapture.isCaptureDestinationSupported(QCameraImageCapture::CaptureToBuffer)); + QVERIFY(!imageCapture.isCaptureDestinationSupported( + QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile)); + + QSignalSpy destinationChangedSignal(&imageCapture, SIGNAL(captureDestinationChanged(QCameraImageCapture::CaptureDestinations))); + + QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToFile); + imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer); + QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToBuffer); + QCOMPARE(destinationChangedSignal.size(), 1); + QCOMPARE(destinationChangedSignal.first().first().value(), + QCameraImageCapture::CaptureToBuffer); + + //not supported combination + imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToBuffer | QCameraImageCapture::CaptureToFile); + QCOMPARE(imageCapture.captureDestination(), QCameraImageCapture::CaptureToBuffer); + QCOMPARE(destinationChangedSignal.size(), 1); +} + +void tst_QCamera::testCaptureFormat() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QSignalSpy formatChangedSignal(&imageCapture, SIGNAL(bufferFormatChanged(QVideoFrame::PixelFormat))); + + QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_Jpeg); + QCOMPARE(imageCapture.supportedBufferFormats().size(), 3); + + imageCapture.setBufferFormat(QVideoFrame::Format_AdobeDng); + QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_AdobeDng); + + QCOMPARE(formatChangedSignal.size(), 1); + QCOMPARE(formatChangedSignal.first().first().value(), + QVideoFrame::Format_AdobeDng); + + imageCapture.setBufferFormat(QVideoFrame::Format_Y16); + QCOMPARE(imageCapture.bufferFormat(), QVideoFrame::Format_AdobeDng); + + QCOMPARE(formatChangedSignal.size(), 1); +} + + +void tst_QCamera::testCameraCapture() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QVERIFY(!imageCapture.isReadyForCapture()); + + QSignalSpy capturedSignal(&imageCapture, SIGNAL(imageCaptured(int,QImage))); + QSignalSpy errorSignal(&imageCapture, SIGNAL(error(int, QCameraImageCapture::Error,QString))); + + imageCapture.capture(QString::fromLatin1("/dev/null")); + QCOMPARE(capturedSignal.size(), 0); + QCOMPARE(errorSignal.size(), 1); + QCOMPARE(imageCapture.error(), QCameraImageCapture::NotReadyError); + + errorSignal.clear(); + + camera.start(); + QVERIFY(imageCapture.isReadyForCapture()); + QCOMPARE(errorSignal.size(), 0); + + imageCapture.capture(QString::fromLatin1("/dev/null")); + + for (int i=0; i<100 && capturedSignal.isEmpty(); i++) + QTest::qWait(10); + + QCOMPARE(capturedSignal.size(), 1); + QCOMPARE(errorSignal.size(), 0); + QCOMPARE(imageCapture.error(), QCameraImageCapture::NoError); +} + +void tst_QCamera::testCameraCaptureMetadata() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QSignalSpy metadataSignal(&imageCapture, SIGNAL(imageMetadataAvailable(int,QtMultimedia::MetaData,QVariant))); + QSignalSpy extendedMetadataSignal(&imageCapture, SIGNAL(imageMetadataAvailable(int,QString,QVariant))); + QSignalSpy savedSignal(&imageCapture, SIGNAL(imageSaved(int,QString))); + + camera.start(); + int id = imageCapture.capture(QString::fromLatin1("/dev/null")); + + for (int i=0; i<100 && savedSignal.isEmpty(); i++) + QTest::qWait(10); + + QCOMPARE(savedSignal.size(), 1); + + QCOMPARE(metadataSignal.size(), 2); + + QVariantList metadata = metadataSignal[0]; + QCOMPARE(metadata[0].toInt(), id); + QCOMPARE(metadata[1].value(), QtMultimedia::FocalLengthIn35mmFilm); + QCOMPARE(metadata[2].value().toInt(), 50); + + metadata = metadataSignal[1]; + QCOMPARE(metadata[0].toInt(), id); + QCOMPARE(metadata[1].value(), QtMultimedia::DateTimeOriginal); + QDateTime captureTime = metadata[2].value().value(); + QVERIFY(qAbs(captureTime.secsTo(QDateTime::currentDateTime()) < 5)); //it should not takes more than 5 seconds for signal to arrive here + + QCOMPARE(extendedMetadataSignal.size(), 1); + metadata = extendedMetadataSignal.first(); + QCOMPARE(metadata[0].toInt(), id); + QCOMPARE(metadata[1].toString(), QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything")); + QCOMPARE(metadata[2].value().toInt(), 42); +} + + +void tst_QCamera::testCameraWhiteBalance() +{ + QSet whiteBalanceModes; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceAuto; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFlash; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceTungsten; + + MockCameraService service; + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFlash); + service.mockImageProcessingControl->setSupportedWhiteBalanceModes(whiteBalanceModes); + service.mockImageProcessingControl->setProcessingParameter( + QCameraImageProcessingControl::ColorTemperature, + QVariant(34)); + + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + + QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceFlash); + QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); + QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)); + QVERIFY(camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)); + QVERIFY(!camera.imageProcessing()->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); + + cameraImageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceTungsten); + QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceTungsten); + + cameraImageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceManual); + QCOMPARE(cameraImageProcessing->whiteBalanceMode(), QCameraImageProcessing::WhiteBalanceManual); + QCOMPARE(cameraImageProcessing->manualWhiteBalance(), 34); + + cameraImageProcessing->setManualWhiteBalance(432); + QCOMPARE(cameraImageProcessing->manualWhiteBalance(), 432); +} + +void tst_QCamera::testCameraExposure() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCameraExposure *cameraExposure = camera.exposure(); + QVERIFY(cameraExposure != 0); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureAuto)); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureAuto); + + // Test Cases For QCameraExposure + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureManual)); + cameraExposure->setExposureMode(QCameraExposure::ExposureManual); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureManual); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureNight)); + cameraExposure->setExposureMode(QCameraExposure::ExposureNight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureNight); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBacklight)); + cameraExposure->setExposureMode(QCameraExposure::ExposureBacklight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBacklight); + + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSpotlight )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSpotlight); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSpotlight); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSports )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSports); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSports); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSnow )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSnow); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSnow); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureBeach )); + cameraExposure->setExposureMode(QCameraExposure::ExposureBeach); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureBeach); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureLargeAperture )); + cameraExposure->setExposureMode(QCameraExposure::ExposureLargeAperture); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureLargeAperture); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureSmallAperture )); + cameraExposure->setExposureMode(QCameraExposure::ExposureSmallAperture); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureSmallAperture); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposurePortrait )); + cameraExposure->setExposureMode(QCameraExposure::ExposurePortrait); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposurePortrait); + + QVERIFY(cameraExposure->isExposureModeSupported(QCameraExposure::ExposureModeVendor )); + cameraExposure->setExposureMode(QCameraExposure::ExposureModeVendor); + QCOMPARE(cameraExposure->exposureMode(), QCameraExposure::ExposureModeVendor); + + + cameraExposure->setFlashMode(QCameraExposure::FlashAuto); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashAuto); + QCOMPARE(cameraExposure->isFlashReady(), true); + cameraExposure->setFlashMode(QCameraExposure::FlashRedEyeReduction); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashRedEyeReduction); + cameraExposure->setFlashMode(QCameraExposure::FlashOn); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashOn); + cameraExposure->setFlashMode(QCameraExposure::FlashFill); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashFill); + cameraExposure->setFlashMode(QCameraExposure::FlashTorch); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashTorch); + cameraExposure->setFlashMode(QCameraExposure::FlashSlowSyncFrontCurtain); + QCOMPARE(cameraExposure->flashMode(), QCameraExposure::FlashSlowSyncFrontCurtain); + + + cameraExposure->setMeteringMode(QCameraExposure::MeteringMatrix); + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringMatrix); + cameraExposure->setMeteringMode(QCameraExposure::MeteringAverage); + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringAverage); + cameraExposure->setMeteringMode(QCameraExposure::MeteringSpot); + QCOMPARE(cameraExposure->meteringMode(), QCameraExposure::MeteringSpot); + + QCOMPARE(cameraExposure->exposureCompensation(), 0.0); + cameraExposure->setExposureCompensation(2.0); + QCOMPARE(cameraExposure->exposureCompensation(), 2.0); + + int minIso = cameraExposure->supportedIsoSensitivities().first(); + int maxIso = cameraExposure->supportedIsoSensitivities().last(); + QVERIFY(cameraExposure->isoSensitivity() > 0); + QVERIFY(minIso > 0); + QVERIFY(maxIso > 0); + cameraExposure->setManualIsoSensitivity(minIso); + QCOMPARE(cameraExposure->isoSensitivity(), minIso); + cameraExposure->setManualIsoSensitivity(maxIso*10); + QCOMPARE(cameraExposure->isoSensitivity(), maxIso); + cameraExposure->setManualIsoSensitivity(-10); + QCOMPARE(cameraExposure->isoSensitivity(), minIso); + cameraExposure->setAutoIsoSensitivity(); + QCOMPARE(cameraExposure->isoSensitivity(), 100); + + qreal minAperture = cameraExposure->supportedApertures().first(); + qreal maxAperture = cameraExposure->supportedApertures().last(); + QVERIFY(minAperture > 0); + QVERIFY(maxAperture > 0); + QVERIFY(cameraExposure->aperture() >= minAperture); + QVERIFY(cameraExposure->aperture() <= maxAperture); + + cameraExposure->setAutoAperture(); + QVERIFY(cameraExposure->aperture() >= minAperture); + QVERIFY(cameraExposure->aperture() <= maxAperture); + + cameraExposure->setManualAperture(0); + QCOMPARE(cameraExposure->aperture(), minAperture); + + cameraExposure->setManualAperture(10000); + QCOMPARE(cameraExposure->aperture(), maxAperture); + + + qreal minShutterSpeed = cameraExposure->supportedShutterSpeeds().first(); + qreal maxShutterSpeed = cameraExposure->supportedShutterSpeeds().last(); + QVERIFY(minShutterSpeed > 0); + QVERIFY(maxShutterSpeed > 0); + QVERIFY(cameraExposure->shutterSpeed() >= minShutterSpeed); + QVERIFY(cameraExposure->shutterSpeed() <= maxShutterSpeed); + + cameraExposure->setAutoShutterSpeed(); + QVERIFY(cameraExposure->shutterSpeed() >= minShutterSpeed); + QVERIFY(cameraExposure->shutterSpeed() <= maxShutterSpeed); + + cameraExposure->setManualShutterSpeed(0); + QCOMPARE(cameraExposure->shutterSpeed(), minShutterSpeed); + + cameraExposure->setManualShutterSpeed(10000); + QCOMPARE(cameraExposure->shutterSpeed(), maxShutterSpeed); +} + +void tst_QCamera::testCameraFocus() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + + QVERIFY(cameraFocus->isFocusModeSupported(QCameraFocus::AutoFocus)); + QVERIFY(cameraFocus->isFocusModeSupported(QCameraFocus::ContinuousFocus)); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::InfinityFocus)); + + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::ManualFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::ContinuousFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::ContinuousFocus); + + QVERIFY(cameraFocus->maximumOpticalZoom() >= 1.0); + QVERIFY(cameraFocus->maximumDigitalZoom() >= 1.0); + QCOMPARE(cameraFocus->opticalZoom(), 1.0); + QCOMPARE(cameraFocus->digitalZoom(), 1.0); + cameraFocus->zoomTo(0.5, 1.0); + QCOMPARE(cameraFocus->opticalZoom(), 1.0); + QCOMPARE(cameraFocus->digitalZoom(), 1.0); + cameraFocus->zoomTo(2.0, 0.5); + QCOMPARE(cameraFocus->opticalZoom(), 2.0); + QCOMPARE(cameraFocus->digitalZoom(), 1.0); + cameraFocus->zoomTo(2.0, 2.5); + QCOMPARE(cameraFocus->opticalZoom(), 2.0); + QCOMPARE(cameraFocus->digitalZoom(), 2.5); + cameraFocus->zoomTo(2000000.0, 1000000.0); + QVERIFY(qFuzzyCompare(cameraFocus->opticalZoom(), cameraFocus->maximumOpticalZoom())); + QVERIFY(qFuzzyCompare(cameraFocus->digitalZoom(), cameraFocus->maximumDigitalZoom())); + + QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointAuto)); + QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointCenter)); + QVERIFY(cameraFocus->isFocusPointModeSupported(QCameraFocus::FocusPointCustom)); + QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointAuto); + + cameraFocus->setFocusPointMode( QCameraFocus::FocusPointCenter ); + QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointCenter); + + cameraFocus->setFocusPointMode( QCameraFocus::FocusPointFaceDetection ); + QCOMPARE(cameraFocus->focusPointMode(), QCameraFocus::FocusPointCenter); + + QCOMPARE(cameraFocus->customFocusPoint(), QPointF(0.5, 0.5)); + cameraFocus->setCustomFocusPoint(QPointF(1.0, 1.0)); + QCOMPARE(cameraFocus->customFocusPoint(), QPointF(1.0, 1.0)); +} + +void tst_QCamera::testImageSettings() +{ + QImageEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QImageEncoderSettings()); + + QCOMPARE(settings.codec(), QString()); + settings.setCodec(QLatin1String("codecName")); + QCOMPARE(settings.codec(), QLatin1String("codecName")); + QVERIFY(!settings.isNull()); + QVERIFY(settings != QImageEncoderSettings()); + + settings = QImageEncoderSettings(); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + settings.setQuality(QtMultimedia::HighQuality); + QCOMPARE(settings.quality(), QtMultimedia::HighQuality); + QVERIFY(!settings.isNull()); + + settings = QImageEncoderSettings(); + QCOMPARE(settings.resolution(), QSize()); + settings.setResolution(QSize(320,240)); + QCOMPARE(settings.resolution(), QSize(320,240)); + settings.setResolution(800,600); + QCOMPARE(settings.resolution(), QSize(800,600)); + QVERIFY(!settings.isNull()); + + settings = QImageEncoderSettings(); + QVERIFY(settings.isNull()); + QCOMPARE(settings.codec(), QString()); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + QCOMPARE(settings.resolution(), QSize()); + + { + QImageEncoderSettings settings1; + QImageEncoderSettings settings2; + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + { + QImageEncoderSettings settings1; + QImageEncoderSettings settings2(settings1); + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + QImageEncoderSettings settings1; + QImageEncoderSettings settings2; + + settings1 = QImageEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QImageEncoderSettings(); + settings2.setResolution(QSize(800,600)); + QVERIFY(settings1 == settings2); + settings2.setResolution(QSize(400,300)); + QVERIFY(settings1 != settings2); + + settings1 = QImageEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QImageEncoderSettings(); + settings2.setCodec("codec1"); + QVERIFY(settings1 == settings2); + settings2.setCodec("codec2"); + QVERIFY(settings1 != settings2); + + settings1 = QImageEncoderSettings(); + settings1.setQuality(QtMultimedia::NormalQuality); + settings2 = QImageEncoderSettings(); + settings2.setQuality(QtMultimedia::NormalQuality); + QVERIFY(settings1 == settings2); + settings2.setQuality(QtMultimedia::LowQuality); + QVERIFY(settings1 != settings2); +} + +void tst_QCamera::testCameraLock() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + camera.focus()->setFocusMode(QCameraFocus::AutoFocus); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus,QCamera::LockChangeReason))); + + camera.searchAndLock(); + QCOMPARE(camera.lockStatus(), QCamera::Searching); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + + for (int i=0; i<200 && camera.lockStatus() == QCamera::Searching; i++) + QTest::qWait(10); + + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + + camera.searchAndLock(); + QCOMPARE(camera.lockStatus(), QCamera::Searching); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + + camera.unlock(); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); +} + +void tst_QCamera::testCameraLockCancel() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + camera.focus()->setFocusMode(QCameraFocus::AutoFocus); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + camera.searchAndLock(); + QCOMPARE(camera.lockStatus(), QCamera::Searching); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + + camera.unlock(); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); +} + +void tst_QCamera::testCameraEncodingProperyChange() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); + QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status))); + + camera.start(); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + + QCOMPARE(stateChangedSignal.count(), 1); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + + camera.setCaptureMode(QCamera::CaptureVideo); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //backens should not be stopped since the capture mode is Video + imageCapture.setEncodingSettings(QImageEncoderSettings()); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 0); + + camera.setCaptureMode(QCamera::CaptureStillImage); + QTest::qWait(10); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start + imageCapture.setEncodingSettings(QImageEncoderSettings()); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start only once + camera.setCaptureMode(QCamera::CaptureVideo); + camera.setCaptureMode(QCamera::CaptureStillImage); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); +} + +void tst_QCamera::testSetVideoOutput() +{ + MockVideoSurface surface; + + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + QCamera camera(0, &provider); + + camera.setViewfinder(reinterpret_cast(0)); + + camera.setViewfinder(reinterpret_cast(0)); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + camera.setViewfinder(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + camera.setViewfinder(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); +} + + +void tst_QCamera::testSetVideoOutputNoService() +{ + MockVideoSurface surface; + + MockMediaServiceProvider provider; + provider.service = 0; + QCamera camera(0, &provider); + + camera.setViewfinder(&surface); + // Nothing we can verify here other than it doesn't assert. +} + +void tst_QCamera::testSetVideoOutputNoControl() +{ + MockVideoSurface surface; + + MockCameraService service; + service.rendererRef = 1; + + MockMediaServiceProvider provider; + provider.service = &service; + QCamera camera(0, &provider); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == 0); +} + +void tst_QCamera::testSetVideoOutputDestruction() +{ + MockVideoSurface surface; + + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + { + QCamera camera(0, &provider); + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + QCOMPARE(service.rendererRef, 1); + } + QVERIFY(service.rendererControl->surface() == 0); + QCOMPARE(service.rendererRef, 0); +} + +void tst_QCamera::testEnumDebug() +{ + QTest::ignoreMessage(QtDebugMsg, "QCamera::ActiveState "); + qDebug() << QCamera::ActiveState; + QTest::ignoreMessage(QtDebugMsg, "QCamera::ActiveStatus "); + qDebug() << QCamera::ActiveStatus; + QTest::ignoreMessage(QtDebugMsg, "QCamera::CaptureVideo "); + qDebug() << QCamera::CaptureVideo; + QTest::ignoreMessage(QtDebugMsg, "QCamera::CameraError "); + qDebug() << QCamera::CameraError; + QTest::ignoreMessage(QtDebugMsg, "QCamera::Unlocked "); + qDebug() << QCamera::Unlocked; + QTest::ignoreMessage(QtDebugMsg, "QCamera::LockAcquired "); + qDebug() << QCamera::LockAcquired; + QTest::ignoreMessage(QtDebugMsg, "QCamera::NoLock "); + qDebug() << QCamera::NoLock; + QTest::ignoreMessage(QtDebugMsg, "QCamera::LockExposure "); + qDebug() << QCamera::LockExposure; +} + +void tst_QCamera::testCameraControl() +{ + MockCameraControl *m_cameraControl=new MockCameraControl(this); + QVERIFY(m_cameraControl != NULL); +} + +/* Test case for constructor with default provider */ +void tst_QCamera::testConstructorWithDefaultProvider() +{ + QCamera *camera = new QCamera(0); + QVERIFY(camera != NULL); + QCOMPARE(camera->state(), QCamera::UnloadedState); + delete camera; +} + +/* captureModeChanged Signal test case. */ +void tst_QCamera::testCaptureModeChanged_signal() +{ + MockCameraControl *m_cameraControl= new MockCameraControl(this); + QSignalSpy spy(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureMode))); + QVERIFY(spy.size() == 0); + + m_cameraControl->setCaptureMode(QCamera::CaptureVideo); + QVERIFY(spy.size() == 1); + + m_cameraControl->setCaptureMode(QCamera::CaptureStillImage); + QVERIFY(spy.size() == 2); +} + +/* Test case for captureMode */ +void tst_QCamera::testCaptureMode() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); + + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); +} + +/* Test case for isCaptureModeSupported */ +void tst_QCamera::testIsCaptureModeSupported() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureStillImage) == true); + QVERIFY(camera.isCaptureModeSupported(QCamera::CaptureVideo) == true); +} + +/* Test case for requestedLocks. LockType is stored in OR combination so all + types of combinations are verified here.*/ +void tst_QCamera::testRequestedLocks() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.requestedLocks(),QCamera::NoLock); + + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure); + + camera.unlock(); + camera.searchAndLock(QCamera::LockFocus); + QCOMPARE(camera.requestedLocks(),QCamera::LockFocus ); + + camera.unlock(); + camera.searchAndLock(QCamera::LockWhiteBalance); + QCOMPARE(camera.requestedLocks(),QCamera::LockWhiteBalance); + + camera.unlock(); + camera.searchAndLock(QCamera::LockExposure |QCamera::LockFocus ); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus ); + camera.searchAndLock(QCamera::LockWhiteBalance); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure |QCamera::LockFocus|QCamera::LockWhiteBalance ); + camera.unlock(QCamera::LockExposure); + QCOMPARE(camera.requestedLocks(),QCamera::LockFocus|QCamera::LockWhiteBalance ); + camera.unlock(QCamera::LockFocus); + camera.searchAndLock(QCamera::LockExposure |QCamera::LockWhiteBalance ); + QCOMPARE(camera.requestedLocks(),QCamera::LockExposure|QCamera::LockWhiteBalance ); +} + +/* Test case for supportedLocks() */ +void tst_QCamera::testSupportedLocks() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.supportedLocks(),QCamera::LockExposure | QCamera::LockFocus); +} + +/* Test case for isAvailable */ +void tst_QCamera::testQCameraIsAvailable() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.isAvailable()); + + QCamera *camera1 = new QCamera("random"); + + QVERIFY(camera1->error() == QCamera::ServiceMissingError); + QVERIFY(!camera1->isAvailable()); + delete camera1; +} + +/* Test case for availabilityError */ +void tst_QCamera::testAvailabilityError() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.availabilityError() == QtMultimedia::NoError); + + QCamera *camera1 = new QCamera("random"); + QVERIFY(camera1->availabilityError() == QtMultimedia::ServiceMissingError); + delete camera1; +} + +/* Test case for searchAndLock ( QCamera::LockTypes locks ) */ +void tst_QCamera::testSearchAndLockWithLockTypes() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signals */ + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* search and lock the camera with QCamera::LockExposure and verify if the signal is emitted correctly */ + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); +} + +/* Test case for setCaptureMode() */ +void tst_QCamera::testSetCaptureMode() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the capture mode and verify if it set correctly */ + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); + + camera.setCaptureMode(QCamera::CaptureStillImage); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); +} + +/* Test case for unlock (QCamera::LockTypes) */ +void tst_QCamera::testUnlockWithType() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signal */ + QSignalSpy lockedSignal(&camera, SIGNAL(locked())); + QSignalSpy lockFailedSignal(&camera, SIGNAL(lockFailed())); + QSignalSpy lockStatusChangedSignal(&camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason))); + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* lock the camera with QCamera::LockExposure and Verify if the signal is emitted correctly */ + camera.searchAndLock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockedSignal.count(), 1); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + + /* Clear the signal */ + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera and verify if the signal is emitted correctly */ + camera.unlock(QCamera::LockExposure); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockType lockType = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(0)); + QCamera::LockStatus lockStatus = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Unlocked); + + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Lock the camera with QCamera::LockFocus */ + camera.searchAndLock(QCamera::LockFocus); + lockedSignal.clear(); + lockFailedSignal.clear(); + lockStatusChangedSignal.clear(); + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera and Verify if the signal is emitted correctly */ + camera.unlock(QCamera::LockFocus); + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockedSignal.count(), 0); + QCOMPARE(lockFailedSignal.count(), 0); + QCOMPARE(lockStatusChangedSignal.count(), 1); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + lockType = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(0)); + lockStatus = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockFocus); + QVERIFY(lockStatus == QCamera::Unlocked); +} + +/* Test case for signal captureModeChanged(QCamera::CaptureMode) */ +void tst_QCamera::testCaptureModeChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QVERIFY(camera.captureMode() == QCamera::CaptureStillImage); + + qRegisterMetaType("QCamera::CaptureMode"); + + /* Spy the signal */ + QSignalSpy lockCaptureModeChangedSignal(&camera, SIGNAL(captureModeChanged(QCamera::CaptureMode))); + + /* set the capture mode and Verify if the signal is emitted */ + camera.setCaptureMode(QCamera::CaptureVideo); + QVERIFY(camera.captureMode() == QCamera::CaptureVideo); + QCOMPARE(lockCaptureModeChangedSignal.count(), 1); + QCamera::CaptureMode lockCaptureMode = qvariant_cast(lockCaptureModeChangedSignal.at(0).at(0)); + QVERIFY(lockCaptureMode == QCamera::CaptureVideo); +} + +/* Test case for signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ +void tst_QCamera::testLockStatusChangedWithTypesSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + + /* Spy the signal lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason) */ + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* Lock the camera with type QCamera::LockExposure */ + camera.searchAndLock(QCamera::LockExposure); + + /* Verify if the signal is emitted and lock status is set correclty */ + QCOMPARE(camera.lockStatus(), QCamera::Locked); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockType lockType = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(0)); + QCamera::LockStatus lockStatus = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Locked); + + lockStatusChangedSignalWithType.clear(); + + /* Unlock the camera */ + camera.unlock(); + + /* Verify if the signal is emitted and lock status is set correclty */ + QCOMPARE(camera.lockStatus(), QCamera::Unlocked); + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + lockType = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(0)); + lockStatus = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(1)); + QVERIFY(lockType == QCamera::LockExposure); + QVERIFY(lockStatus == QCamera::Unlocked); +} + +/* Test case for verifying if error signal generated correctly */ +void tst_QCamera::testErrorSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QSignalSpy spyError(&camera, SIGNAL(error(QCamera::Error))); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + + QVERIFY(spyError.count() == 1); + QCamera::Error err = qvariant_cast(spyError.at(0).at(0)); + QVERIFY(err == QCamera::CameraError); + + spyError.clear(); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(spyError.count() == 1); + err = qvariant_cast(spyError.at(0).at(0)); + QVERIFY(err == QCamera::InvalidRequestError); + + spyError.clear(); + + /* Set the QCameraControl error and verify if the signal is emitted correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(spyError.count() == 1); + err = qvariant_cast(spyError.at(0).at(0)); + QVERIFY(err == QCamera::NotSupportedFeatureError); + +} + +/* Test case for verifying the QCamera error */ +void tst_QCamera::testError() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + QVERIFY(camera.error() == QCamera::CameraError); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(camera.error() == QCamera::InvalidRequestError); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(camera.error() == QCamera::NotSupportedFeatureError); + +} + +/* Test the error strings for QCamera class */ +void tst_QCamera::testErrorString() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::CameraError,QString("Camera Error")); + QVERIFY(camera.errorString() == QString("Camera Error")); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::InvalidRequestError,QString("InvalidRequestError Error")); + QVERIFY(camera.errorString() == QString("InvalidRequestError Error")); + + /* Set the QCameraControl error and verify if it is set correctly in QCamera */ + service.mockControl->setError(QCamera::NotSupportedFeatureError,QString("NotSupportedFeatureError Error")); + QVERIFY(camera.errorString() == QString("NotSupportedFeatureError Error")); +} + +/* Test case for verifying Status of QCamera. */ +void tst_QCamera::testStatus() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::StartingStatus); + QVERIFY(camera.status() == QCamera::StartingStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::StandbyStatus); + QVERIFY(camera.status() == QCamera::StandbyStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::LoadingStatus); + QVERIFY(camera.status() == QCamera::LoadingStatus); + + /* Set the QCameraControl status and verify if it is set correctly in QCamera */ + service.mockControl->setStatus(QCamera::UnavailableStatus); + QVERIFY(camera.status() == QCamera::UnavailableStatus); +} + +/* Test case for verifying default locktype QCamera::NoLock */ +void tst_QCamera::testLockType() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QCOMPARE(camera.requestedLocks(),QCamera::NoLock); +} + +/* Test case for QCamera::LockChangeReason with QCamera::LockAcquired */ +void tst_QCamera::testLockChangeReason() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + + QSignalSpy lockStatusChangedSignalWithType(&camera, SIGNAL(lockStatusChanged(QCamera::LockType,QCamera::LockStatus, QCamera::LockChangeReason))); + + /* Set the lockChangeReason */ + service.mockLocksControl->setLockChangeReason(QCamera::LockAcquired); + + /* Verify if lockChangeReson is eqaul toQCamera::LockAcquired */ + QCOMPARE(lockStatusChangedSignalWithType.count(), 1); + QCamera::LockChangeReason LockChangeReason = qvariant_cast(lockStatusChangedSignalWithType.at(0).at(2)); + QVERIFY(LockChangeReason == QCamera::LockAcquired); + +} +/* All the enums test case for QCameraControl class*/ +void tst_QCamera::testEnumsOfQCameraControl() +{ + MockCameraControl *m_cameraControl = new MockCameraControl(this); + bool result; + + // In still mode, can't change much + QVERIFY(m_cameraControl->captureMode() == QCamera::CaptureStillImage); + result = m_cameraControl->canChangeProperty(MockCameraControl::CaptureMode, QCamera::ActiveStatus); + QVERIFY(!result); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(!result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(!result); + + // In video mode can change image encoding settings + m_cameraControl->setCaptureMode(QCamera::CaptureVideo); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(!result); + + // Flip the allow everything bit + m_cameraControl->m_propertyChangesSupported = true; + result = m_cameraControl->canChangeProperty(MockCameraControl::CaptureMode, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::ImageEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::VideoEncodingSettings, QCamera::ActiveStatus); + QVERIFY(result); + result = m_cameraControl->canChangeProperty(MockCameraControl::Viewfinder, QCamera::ActiveStatus); + QVERIFY(result); +} + +// Test case for QCameraImageProcessing class +void tst_QCamera::testContrast() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->contrast() ==0); + + cameraImageProcessing->setContrast(123); + QVERIFY(cameraImageProcessing->contrast() ==123); + + cameraImageProcessing->setContrast(4.56); + QVERIFY(cameraImageProcessing->contrast() ==4); +} + +void tst_QCamera::testDenoisingLevel() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + + if (cameraImageProcessing->isDenoisingSupported()) + { + QVERIFY(cameraImageProcessing->denoisingLevel() == -1); + + cameraImageProcessing->setDenoisingLevel(0); + QVERIFY(cameraImageProcessing->denoisingLevel() == 0); + + cameraImageProcessing->setDenoisingLevel(12); + QVERIFY(cameraImageProcessing->denoisingLevel() == 12); + } + else + QVERIFY(cameraImageProcessing->denoisingLevel() == -1); +} + +void tst_QCamera::testIsAvailable() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->isAvailable() == true); +} + +void tst_QCamera::testSaturation() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->saturation() == 0); + + cameraImageProcessing->setSaturation(50); + QVERIFY(cameraImageProcessing->saturation() == 50); + + cameraImageProcessing->setSaturation(-50); + QVERIFY(cameraImageProcessing->saturation() == -50); + + cameraImageProcessing->setSaturation(100); + QVERIFY(cameraImageProcessing->saturation() == 100); + + cameraImageProcessing->setSaturation(-100); + QVERIFY(cameraImageProcessing->saturation() == -100); +} + +void tst_QCamera::testSharpeningLevel() +{ + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + + QCamera camera(0, &provider); + QCameraImageProcessing *cameraImageProcessing = camera.imageProcessing(); + QVERIFY(cameraImageProcessing->isSharpeningSupported()); + QVERIFY(cameraImageProcessing->sharpeningLevel() == -1); + + cameraImageProcessing->setSharpeningLevel(123); + QVERIFY(cameraImageProcessing->sharpeningLevel() == 123); + + cameraImageProcessing->setSharpeningLevel(4.67); + QVERIFY(cameraImageProcessing->sharpeningLevel() == 4); +} + +void tst_QCamera::testEnumOfQCameraImageProcessing() +{ + QSet whiteBalanceModes; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceManual; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceAuto; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunlight; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceCloudy; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceShade; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceTungsten; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFluorescent; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceFlash; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceSunset; + whiteBalanceModes << QCameraImageProcessing::WhiteBalanceVendor; + + MockCameraService service; + service.mockImageProcessingControl->setSupportedWhiteBalanceModes(whiteBalanceModes); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceManual); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceManual)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceManual); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceAuto); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceAuto)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceAuto); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunlight); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunlight)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunlight); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceCloudy); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceCloudy)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceCloudy); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceShade); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceShade)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceShade); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceTungsten); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceTungsten)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceTungsten); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFluorescent)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFluorescent); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFlash); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceFlash)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceFlash); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceSunset); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceSunset)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceSunset); + + service.mockImageProcessingControl->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceVendor); + QVERIFY(service.mockImageProcessingControl->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceVendor)); + QVERIFY(service.mockImageProcessingControl->whiteBalanceMode() == QCameraImageProcessing::WhiteBalanceVendor); +} + +//Added test cases for QCameraFocus +void tst_QCamera::testCameraFocusIsAvailable() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QVERIFY(cameraFocus->isAvailable()); +} + +//Added this code to cover QCameraFocus::HyperfocalFocus and QCameraFocus::MacroFocus +//As the HyperfocalFocus and MacroFocus are not supported we can not set the focus mode to these Focus Modes +void tst_QCamera::testFocusModes() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::HyperfocalFocus)); + QVERIFY(!cameraFocus->isFocusModeSupported(QCameraFocus::MacroFocus)); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::HyperfocalFocus); + QVERIFY(cameraFocus->focusMode()!= QCameraFocus::HyperfocalFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); + cameraFocus->setFocusMode(QCameraFocus::MacroFocus); + QVERIFY(cameraFocus->focusMode()!= QCameraFocus::MacroFocus); + QCOMPARE(cameraFocus->focusMode(), QCameraFocus::AutoFocus); +} + +void tst_QCamera::testOpticalAndDigitalZoomChanged() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy1(cameraFocus,SIGNAL(digitalZoomChanged(qreal))); + QSignalSpy spy2(cameraFocus,SIGNAL(opticalZoomChanged(qreal))); + QVERIFY(spy1.count() == 0); + QVERIFY(spy2.count() == 0); + cameraFocus->zoomTo(2.0,3.0); + QVERIFY(spy1.count() == 1); + QVERIFY(spy2.count() == 1); +} + +void tst_QCamera::testMaxDigitalZoomChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy(cameraFocus,SIGNAL(maximumDigitalZoomChanged(qreal))); + QVERIFY(spy.count() == 0); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +void tst_QCamera::testMaxOpticalZoomChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + QSignalSpy spy(cameraFocus,SIGNAL(maximumOpticalZoomChanged(qreal))); + QVERIFY(spy.count() == 0); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +void tst_QCamera::testfocusZonesChangedSignal() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraFocus *cameraFocus = camera.focus(); + QVERIFY(cameraFocus != 0); + + QSignalSpy spy(cameraFocus,SIGNAL(focusZonesChanged())); + cameraFocus->zoomTo(5.0,6.0); + QVERIFY(spy.count() == 1); +} + +// test constructor for abstract class of ImageProcessingControl +void tst_QCamera :: testImageProcessingControl() +{ + QObject parent; + MockImageProcessingControl processCtrl(&parent); +} + +void tst_QCamera::testSignalApertureChanged() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyApertureChanged(cameraExposure , SIGNAL(apertureChanged(qreal))); + QSignalSpy spyApertureRangeChanged(cameraExposure , SIGNAL(apertureRangeChanged())); + + + QVERIFY(spyApertureChanged.count() ==0); + cameraExposure->setManualAperture(10.0);//set the ManualAperture to 10.0 + + QTest::qWait(100); + QVERIFY(spyApertureChanged.count() ==1); + QVERIFY(spyApertureRangeChanged.count() ==1); +} + +void tst_QCamera::testSignalExposureCompensationChanged() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyExposureCompensationChanged(cameraExposure , SIGNAL(exposureCompensationChanged(qreal))); + + QVERIFY(spyExposureCompensationChanged.count() ==0); + + QVERIFY(cameraExposure->exposureCompensation() != 800); + cameraExposure->setExposureCompensation(2.0); + + QTest::qWait(100); + + QVERIFY(cameraExposure->exposureCompensation() == 2.0); + + QCOMPARE(spyExposureCompensationChanged.count(),1); + + // Setting the same should not result in a signal + cameraExposure->setExposureCompensation(2.0); + QTest::qWait(100); + + QVERIFY(cameraExposure->exposureCompensation() == 2.0); + QCOMPARE(spyExposureCompensationChanged.count(),1); +} + +void tst_QCamera::testSignalIsoSensitivityChanged() +{ + + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spyisoSensitivityChanged(cameraExposure , SIGNAL(isoSensitivityChanged(int))); + + QVERIFY(spyisoSensitivityChanged.count() ==0); + + cameraExposure->setManualIsoSensitivity(800); //set the manualiso sentivity to 800 + QTest::qWait(100); + QVERIFY(spyisoSensitivityChanged.count() ==1); + +} +void tst_QCamera::testSignalShutterSpeedChanged() +{ + + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + QSignalSpy spySignalShutterSpeedChanged(cameraExposure , SIGNAL(shutterSpeedChanged(qreal))); + QSignalSpy spySignalShutterSpeedRangeChanged(cameraExposure , SIGNAL(shutterSpeedRangeChanged())); + + QVERIFY(spySignalShutterSpeedChanged.count() ==0); + + cameraExposure->setManualShutterSpeed(2.0);//set the ManualShutterSpeed to 2.0 + QTest::qWait(100); + + QVERIFY(spySignalShutterSpeedChanged.count() ==1); + QVERIFY(spySignalShutterSpeedRangeChanged.count() ==1); +} + +void tst_QCamera::testSignalFlashReady() +{ + MockMediaServiceProvider provider1; + MockCameraService service; + provider1.service = &service; + QCamera camera(0, &provider1); + + QCameraExposure *cameraExposure = camera.exposure(); //create camera expose instance + QVERIFY(cameraExposure != 0); + + + QSignalSpy spyflashReady(cameraExposure,SIGNAL(flashReady(bool))); + + QVERIFY(spyflashReady.count() ==0); + + QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashAuto); + + cameraExposure->setFlashMode(QCameraExposure::FlashOff);//set theFlashMode to QCameraExposure::FlashOff + + QVERIFY(cameraExposure->flashMode() ==QCameraExposure::FlashOff); + + QVERIFY(spyflashReady.count() ==1); +} + +// test constructor +void tst_QCamera::testExposureControlConstructor() +{ + // To check changes in abstract classes's pure virtual functions + MockCameraExposureControl obj; +} + +QTEST_MAIN(tst_QCamera) + +#include "tst_qcamera.moc" diff --git a/tests/auto/unit/qcameraimagecapture/qcameraimagecapture.pro b/tests/auto/unit/qcameraimagecapture/qcameraimagecapture.pro new file mode 100644 index 000000000..fdd2cf501 --- /dev/null +++ b/tests/auto/unit/qcameraimagecapture/qcameraimagecapture.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qcameraimagecapture + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += \ + tst_qcameraimagecapture.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) diff --git a/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp b/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp new file mode 100644 index 000000000..e842cbb83 --- /dev/null +++ b/tests/auto/unit/qcameraimagecapture/tst_qcameraimagecapture.cpp @@ -0,0 +1,432 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/**************************************************************************** +Author : Vijay/Avinash + +Reviewer Name Date Coverage ( Full / Test Case IDs ). +--------------------------------------------------------------------------- + Initial review of test cases. +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mockcameraservice.h" +#include "mockmediaserviceprovider.h" + +QT_USE_NAMESPACE + +class NullService: public QMediaService +{ + Q_OBJECT + +public: + NullService(): QMediaService(0) + { + + } + + ~NullService() + { + + } + + QMediaControl* requestControl(const char *iid) + { + Q_UNUSED(iid); + return 0; + } + + void releaseControl(QMediaControl*) {} + +}; + +class tst_QCameraImageCapture: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void constructor(); + void mediaObject(); + void deleteMediaObject(); + void isReadyForCapture(); + void capture(); + void cancelCapture(); + void encodingSettings(); + void errors(); + void error(); + void imageCaptured(); + void imageExposed(); + void imageSaved(); + void readyForCaptureChanged(); + void supportedResolutions(); + void imageCodecDescription(); + void supportedImageCodecs(); + void cameraImageCaptureControl(); + +private: + MockCameraService *mockcameraservice; + MockMediaServiceProvider *provider; +}; + +void tst_QCameraImageCapture::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockcameraservice = new MockCameraService; + provider->service = mockcameraservice; +} + +void tst_QCameraImageCapture::cleanupTestCase() +{ + delete mockcameraservice; + delete provider; +} + +//MaemoAPI-1823:test QCameraImageCapture Constructor +void tst_QCameraImageCapture::constructor() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); +} + +//MaemoAPI-1824:test mediaObject +void tst_QCameraImageCapture::mediaObject() +{ + MockMediaServiceProvider provider1; + NullService mymockcameraservice ; + provider1.service = &mymockcameraservice; + QCamera camera(0, &provider1); + QCameraImageCapture imageCapture(&camera); + QMediaObject *medobj = imageCapture.mediaObject(); + QVERIFY(medobj == NULL); + + QCamera camera1(0, provider); + QCameraImageCapture imageCapture1(&camera1); + QMediaObject *medobj1 = imageCapture1.mediaObject(); + QCOMPARE(medobj1, &camera1); +} + +void tst_QCameraImageCapture::deleteMediaObject() +{ + MockMediaServiceProvider *provider = new MockMediaServiceProvider; + provider->service = new MockCameraService; + + QCamera *camera = new QCamera(0, provider); + QCameraImageCapture *capture = new QCameraImageCapture(camera); + + QVERIFY(capture->mediaObject() == camera); + QVERIFY(capture->isAvailable()); + + delete camera; + delete provider->service; + delete provider; + + //capture should detach from camera + QVERIFY(capture->mediaObject() == 0); + QVERIFY(!capture->isAvailable()); + + capture->capture(); + delete capture; +} + +//MaemoAPI-1825:test isReadyForCapture +void tst_QCameraImageCapture::isReadyForCapture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + camera.stop(); +} + +//MaemoAPI-1826:test capture +void tst_QCameraImageCapture::capture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + QVERIFY(imageCapture.capture() == -1); + camera.start(); + QVERIFY(imageCapture.isReadyForCapture() == true); + QTest::qWait(300); + QVERIFY(imageCapture.capture() != -1); + camera.stop(); +} + +//MaemoAPI-1827:test cancelCapture +void tst_QCameraImageCapture::cancelCapture() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); + QSignalSpy spy1(&imageCapture, SIGNAL(imageSaved(int,QString))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + QVERIFY(spy.count() == 1 && spy1.count() == 1); + spy.clear(); + spy1.clear(); + camera.stop(); + + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + imageCapture.cancelCapture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + QVERIFY(spy.count() == 0 && spy1.count() == 0); + camera.stop(); +} + +//MaemoAPI-1828:test encodingSettings +//MaemoAPI-1829:test set encodingSettings +void tst_QCameraImageCapture::encodingSettings() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.encodingSettings() == QImageEncoderSettings()); + QImageEncoderSettings settings; + settings.setCodec("JPEG"); + settings.setQuality(QtMultimedia::NormalQuality); + imageCapture.setEncodingSettings(settings); + QVERIFY(!imageCapture.encodingSettings().isNull()); + QVERIFY(imageCapture.encodingSettings().codec() == "JPEG"); + QVERIFY(imageCapture.encodingSettings().quality() == QtMultimedia::NormalQuality); +} + +//MaemoAPI-1838:test supportedImageCodecs +void tst_QCameraImageCapture::supportedImageCodecs() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(!imageCapture.supportedImageCodecs().isEmpty()); +} + +//MaemoAPI-1836:test supportedResolutions +void tst_QCameraImageCapture::supportedResolutions() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.supportedResolutions().count() == 2); + QImageEncoderSettings settings1; + settings1.setCodec("PNG");; + settings1.setResolution(320, 240); + int result = imageCapture.supportedResolutions(settings1).count(); + QVERIFY(result == 1); +} + +//MaemoAPI-1837:test imageCodecDescription +void tst_QCameraImageCapture::imageCodecDescription() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.imageCodecDescription(" ").isNull()); + QVERIFY(imageCapture.imageCodecDescription("PNG").isNull() == false); +} + +//MaemoAPI-1830:test errors +void tst_QCameraImageCapture::errors() +{ + MockMediaServiceProvider provider1 ; + MockSimpleCameraService mockSimpleCameraService ; + provider1.service = &mockSimpleCameraService; + + QCamera camera1(0, &provider1); + QCameraImageCapture imageCapture1(&camera1); + QVERIFY(imageCapture1.isAvailable() == false); + imageCapture1.capture(QString::fromLatin1("/dev/null")); + QVERIFY(imageCapture1.error() == QCameraImageCapture::NotSupportedFeatureError); + QVERIFY2(!imageCapture1.errorString().isEmpty(), "Device does not support images capture"); + QVERIFY(imageCapture1.availabilityError() == QtMultimedia::ServiceMissingError); + + + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.error() == QCameraImageCapture::NoError); + QVERIFY(imageCapture.errorString().isEmpty()); + QVERIFY(imageCapture.availabilityError() == QtMultimedia::NoError); + + imageCapture.capture(); + QVERIFY(imageCapture.error() == QCameraImageCapture::NotReadyError); + QVERIFY2(!imageCapture.errorString().isEmpty(), "Could not capture in stopped state"); + QVERIFY(imageCapture.availabilityError() == QtMultimedia::NoError); +} + +//MaemoAPI-1831:test error +void tst_QCameraImageCapture::error() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(error(int,QCameraImageCapture::Error,QString))); + imageCapture.capture(); + QTest::qWait(30); + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast(spy.at(0).at(0)) == -1); + QVERIFY(qvariant_cast(spy.at(0).at(1)) == QCameraImageCapture::NotReadyError); + QVERIFY(qvariant_cast(spy.at(0).at(2)) == "Could not capture in stopped state"); + spy.clear(); +} + +//MaemoAPI-1832:test imageCaptured +void tst_QCameraImageCapture::imageCaptured() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageCaptured(int,QImage))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast(spy.at(0).at(0)) > 0); + QImage image = qvariant_cast(spy.at(0).at(1)); + QVERIFY(image.isNull() == true); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1833:test imageExposed +void tst_QCameraImageCapture::imageExposed() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageExposed(int))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast(spy.at(0).at(0)) > 0); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1834:test imageSaved +void tst_QCameraImageCapture::imageSaved() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(imageSaved(int,QString))); + QVERIFY(imageCapture.isAvailable() == true); + QVERIFY(imageCapture.isReadyForCapture() == false); + camera.start(); + imageCapture.capture(QString::fromLatin1("/usr/share")); + QTest::qWait(300); + QVERIFY(imageCapture.isReadyForCapture() == true); + + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast(spy.at(0).at(0)) > 0); + QVERIFY(qvariant_cast(spy.at(0).at(1)) == "/usr/share"); + spy.clear(); + camera.stop(); +} + +//MaemoAPI-1835:test readyForCaptureChanged +void tst_QCameraImageCapture::readyForCaptureChanged() +{ + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + QSignalSpy spy(&imageCapture, SIGNAL(readyForCaptureChanged(bool))); + QVERIFY(imageCapture.isReadyForCapture() == false); + imageCapture.capture(); + QTest::qWait(100); + QVERIFY(spy.count() == 0); + QVERIFY2(!imageCapture.errorString().isEmpty(),"Could not capture in stopped state" ); + camera.start(); + QTest::qWait(100); + imageCapture.capture(); + QTest::qWait(100); + QVERIFY(spy.count() == 2); + QVERIFY(spy.at(0).at(0).toBool() == false); + QVERIFY(spy.at(1).at(0).toBool() == true); + camera.stop(); + spy.clear(); +} + +//MaemoAPI-1853:test cameraImageCapture control constructor +void tst_QCameraImageCapture::cameraImageCaptureControl() +{ + MockCameraControl ctrl; + MockCaptureControl capctrl(&ctrl); +} + +QTEST_MAIN(tst_QCameraImageCapture) + +#include "tst_qcameraimagecapture.moc" diff --git a/tests/auto/unit/qcameraviewfinder/qcameraviewfinder.pro b/tests/auto/unit/qcameraviewfinder/qcameraviewfinder.pro new file mode 100644 index 000000000..a53729a4f --- /dev/null +++ b/tests/auto/unit/qcameraviewfinder/qcameraviewfinder.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qcameraviewfinder + +QT += multimedia-private multimediawidgets-private testlib +CONFIG += no_private_qt_headers_warning + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + +SOURCES += tst_qcameraviewfinder.cpp +QT+=widgets diff --git a/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp b/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp new file mode 100644 index 000000000..106a87bc7 --- /dev/null +++ b/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + + +#include +#include + +#include "qcameraviewfinder.h" +#include "qcamera.h" +#include "qmediaobject.h" + +#include "mockcameraservice.h" +#include "mockmediaserviceprovider.h" + +class tst_QCameraViewFinder : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testConstructor(); + void testMediaObject(); + +private: + MockCameraService *mockcameraservice; + MockMediaServiceProvider *provider; + QCamera *camera; + QCameraViewfinder *viewFinder; +}; + +void tst_QCameraViewFinder::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockcameraservice = new MockCameraService; + provider->service = mockcameraservice; + + camera = new QCamera(0, provider); + viewFinder = new QCameraViewfinder(); +} + +void tst_QCameraViewFinder::cleanupTestCase() +{ + delete mockcameraservice; + delete provider; +} + +void tst_QCameraViewFinder::testConstructor() +{ + /* Verify whether the object is created or not */ + QVERIFY(viewFinder != NULL); + QCOMPARE(viewFinder->isVisible(),false); + QCOMPARE(viewFinder->isEnabled(),true); + viewFinder->show(); +} + +void tst_QCameraViewFinder::testMediaObject() +{ + QVERIFY(viewFinder != NULL); + viewFinder->show(); + /* Sets the QVideoWidget based camera viewfinder.*/ + camera->setViewfinder(viewFinder); + QCOMPARE(viewFinder->isVisible(),true); + + /* Return the currently attached media object.*/ + QMediaObject *media = viewFinder->mediaObject(); + + /* Verifying the object */ + QCOMPARE(media, camera); +} + +QTEST_MAIN(tst_QCameraViewFinder) +#include "tst_qcameraviewfinder.moc" diff --git a/tests/auto/unit/qcamerawidgets/qcamerawidgets.pro b/tests/auto/unit/qcamerawidgets/qcamerawidgets.pro new file mode 100644 index 000000000..f8de4af50 --- /dev/null +++ b/tests/auto/unit/qcamerawidgets/qcamerawidgets.pro @@ -0,0 +1,13 @@ +CONFIG += testcase +TARGET = tst_qcamerawidgets + +QT += multimedia-private multimediawidgets-private testlib +CONFIG += no_private_qt_headers_warning + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + +SOURCES += tst_qcamerawidgets.cpp + +maemo*:CONFIG += insignificant_test +QT+=widgets diff --git a/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp b/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp new file mode 100644 index 000000000..92cafda6e --- /dev/null +++ b/tests/auto/unit/qcamerawidgets/tst_qcamerawidgets.cpp @@ -0,0 +1,318 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mockcameraservice.h" + +#include "mockmediaserviceprovider.h" +#include "mockvideosurface.h" +#include "mockvideorenderercontrol.h" +#include "mockvideowindowcontrol.h" + +QT_USE_NAMESPACE + + +class tst_QCameraWidgets: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testCameraEncodingProperyChange(); + void testSetVideoOutput(); + void testSetVideoOutputNoService(); + void testSetVideoOutputNoControl(); + +private: + MockSimpleCameraService *mockSimpleCameraService; + MockMediaServiceProvider *provider; +}; + +void tst_QCameraWidgets::initTestCase() +{ + provider = new MockMediaServiceProvider; + mockSimpleCameraService = new MockSimpleCameraService; + provider->service = mockSimpleCameraService; + qRegisterMetaType("QtMultimedia::MetaData"); +} + +void tst_QCameraWidgets::cleanupTestCase() +{ + delete mockSimpleCameraService; + delete provider; +} + +void tst_QCameraWidgets::testCameraEncodingProperyChange() +{ + MockCameraService service; + provider->service = &service; + QCamera camera(0, provider); + QCameraImageCapture imageCapture(&camera); + + QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); + QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status))); + + camera.start(); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + + QCOMPARE(stateChangedSignal.count(), 1); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + + camera.setCaptureMode(QCamera::CaptureVideo); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //backens should not be stopped since the capture mode is Video + imageCapture.setEncodingSettings(QImageEncoderSettings()); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 0); + + camera.setCaptureMode(QCamera::CaptureStillImage); + QTest::qWait(10); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start + imageCapture.setEncodingSettings(QImageEncoderSettings()); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start only once + camera.setCaptureMode(QCamera::CaptureVideo); + camera.setCaptureMode(QCamera::CaptureStillImage); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QTest::qWait(10); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //setting the viewfinder should also trigger backend to be restarted: + camera.setViewfinder(new QGraphicsVideoItem()); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + + QTest::qWait(10); + + service.mockControl->m_propertyChangesSupported = true; + //the changes to encoding settings, + //capture mode and encoding parameters should not trigger service restart + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + camera.setCaptureMode(QCamera::CaptureVideo); + camera.setCaptureMode(QCamera::CaptureStillImage); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + imageCapture.setEncodingSettings(QImageEncoderSettings()); + camera.setViewfinder(new QGraphicsVideoItem()); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 0); +} + +void tst_QCameraWidgets::testSetVideoOutput() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockCameraService service; + MockMediaServiceProvider provider; + provider.service = &service; + QCamera camera(0, &provider); + + camera.setViewfinder(&widget); + qDebug() << widget.mediaObject(); + QVERIFY(widget.mediaObject() == &camera); + + camera.setViewfinder(&item); + QVERIFY(widget.mediaObject() == 0); + QVERIFY(item.mediaObject() == &camera); + + camera.setViewfinder(reinterpret_cast(0)); + QVERIFY(item.mediaObject() == 0); + + camera.setViewfinder(&widget); + QVERIFY(widget.mediaObject() == &camera); + + camera.setViewfinder(reinterpret_cast(0)); + QVERIFY(widget.mediaObject() == 0); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + camera.setViewfinder(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + camera.setViewfinder(&widget); + QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(widget.mediaObject() == &camera); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(widget.mediaObject() == 0); +} + + +void tst_QCameraWidgets::testSetVideoOutputNoService() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockMediaServiceProvider provider; + provider.service = 0; + QCamera camera(0, &provider); + + camera.setViewfinder(&widget); + QVERIFY(widget.mediaObject() == 0); + + camera.setViewfinder(&item); + QVERIFY(item.mediaObject() == 0); + + camera.setViewfinder(&surface); + // Nothing we can verify here other than it doesn't assert. +} + +void tst_QCameraWidgets::testSetVideoOutputNoControl() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockCameraService service; + service.rendererRef = 1; + service.windowRef = 1; + + MockMediaServiceProvider provider; + provider.service = &service; + QCamera camera(0, &provider); + + camera.setViewfinder(&widget); + QVERIFY(widget.mediaObject() == 0); + + camera.setViewfinder(&item); + QVERIFY(item.mediaObject() == 0); + + camera.setViewfinder(&surface); + QVERIFY(service.rendererControl->surface() == 0); +} + +QTEST_MAIN(tst_QCameraWidgets) + +#include "tst_qcamerawidgets.moc" diff --git a/tests/auto/unit/qdeclarativeaudio/qdeclarativeaudio.pro b/tests/auto/unit/qdeclarativeaudio/qdeclarativeaudio.pro new file mode 100644 index 000000000..35f11735c --- /dev/null +++ b/tests/auto/unit/qdeclarativeaudio/qdeclarativeaudio.pro @@ -0,0 +1,17 @@ +CONFIG += testcase +TARGET = tst_qdeclarativeaudio + +QT += multimedia-private declarative testlib +CONFIG += no_private_qt_headers_warning + +HEADERS += \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativeaudio_p.h \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase_p.h \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediametadata_p.h + +SOURCES += \ + tst_qdeclarativeaudio.cpp \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativeaudio.cpp \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase.cpp + +INCLUDEPATH += $$QT.multimedia.sources/../imports/multimedia diff --git a/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp b/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp new file mode 100644 index 000000000..ef538b665 --- /dev/null +++ b/tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp @@ -0,0 +1,1301 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=plugins/declarative/multimedia + +#include + +#include "qdeclarativeaudio_p.h" +#include "qdeclarativemediametadata_p.h" + +#include +#include +#include +#include + +#include + +class tst_QDeclarativeAudio : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + +private slots: + void nullPlayerControl(); + void nullMetaDataControl(); + void nullService(); + + void source(); + void autoLoad(); + void playing(); + void paused(); + void duration(); + void position(); + void volume(); + void muted(); + void bufferProgress(); + void seekable(); + void playbackRate(); + void status(); + void metaData_data(); + void metaData(); + void error(); + void loops(); +}; + +Q_DECLARE_METATYPE(QDeclarativeAudio::Error); + +class QtTestMediaPlayerControl : public QMediaPlayerControl +{ + Q_OBJECT +public: + QtTestMediaPlayerControl(QObject *parent = 0) + : QMediaPlayerControl(parent) + , m_state(QMediaPlayer::StoppedState) + , m_mediaStatus(QMediaPlayer::NoMedia) + , m_duration(0) + , m_position(0) + , m_playbackRate(1.0) + , m_volume(100) + , m_bufferStatus(0) + , m_muted(false) + , m_audioAvailable(false) + , m_videoAvailable(false) + , m_seekable(false) + { + } + + QMediaPlayer::State state() const { return m_state; } + void updateState(QMediaPlayer::State state) { emit stateChanged(m_state = state); } + + QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; } + void updateMediaStatus(QMediaPlayer::MediaStatus status) { + emit mediaStatusChanged(m_mediaStatus = status); } + void updateMediaStatus(QMediaPlayer::MediaStatus status, QMediaPlayer::State state) + { + m_mediaStatus = status; + m_state = state; + + emit mediaStatusChanged(m_mediaStatus); + emit stateChanged(m_state); + } + + qint64 duration() const { return m_duration; } + void setDuration(qint64 duration) { emit durationChanged(m_duration = duration); } + + qint64 position() const { return m_position; } + void setPosition(qint64 position) { emit positionChanged(m_position = position); } + + int volume() const { return m_volume; } + void setVolume(int volume) { emit volumeChanged(m_volume = volume); } + + bool isMuted() const { return m_muted; } + void setMuted(bool muted) { emit mutedChanged(m_muted = muted); } + + int bufferStatus() const { return m_bufferStatus; } + void setBufferStatus(int status) { emit bufferStatusChanged(m_bufferStatus = status); } + + bool isAudioAvailable() const { return m_audioAvailable; } + void setAudioAvailable(bool available) { + emit audioAvailableChanged(m_audioAvailable = available); } + bool isVideoAvailable() const { return m_videoAvailable; } + void setVideoAvailable(bool available) { + emit videoAvailableChanged(m_videoAvailable = available); } + + bool isSeekable() const { return m_seekable; } + void setSeekable(bool seekable) { emit seekableChanged(m_seekable = seekable); } + + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); } + + qreal playbackRate() const { return m_playbackRate; } + void setPlaybackRate(qreal rate) { emit playbackRateChanged(m_playbackRate = rate); } + + QMediaContent media() const { return m_media; } + const QIODevice *mediaStream() const { return 0; } + void setMedia(const QMediaContent &media, QIODevice *) + { + m_media = media; + + m_mediaStatus = m_media.isNull() + ? QMediaPlayer::NoMedia + : QMediaPlayer::LoadingMedia; + + emit mediaChanged(m_media); + emit mediaStatusChanged(m_mediaStatus); + } + + void play() + { + m_state = QMediaPlayer::PlayingState; + if (m_mediaStatus == QMediaPlayer::EndOfMedia) + updateMediaStatus(QMediaPlayer::LoadedMedia); + emit stateChanged(m_state); + } + void pause() { emit stateChanged(m_state = QMediaPlayer::PausedState); } + void stop() { emit stateChanged(m_state = QMediaPlayer::StoppedState); } + + void emitError(QMediaPlayer::Error err, const QString &errorString) { + emit error(err, errorString); } + +private: + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_mediaStatus; + qint64 m_duration; + qint64 m_position; + qreal m_playbackRate; + int m_volume; + int m_bufferStatus; + bool m_muted; + bool m_audioAvailable; + bool m_videoAvailable; + bool m_seekable; + QMediaContent m_media; +}; + +class QtTestMetaDataControl : public QMetaDataReaderControl +{ + Q_OBJECT +public: + QtTestMetaDataControl(QObject *parent = 0) + : QMetaDataReaderControl(parent) + { + } + + bool isMetaDataAvailable() const { return true; } + + QVariant metaData(QtMultimedia::MetaData key) const { return m_metaData.value(key); } + void setMetaData(QtMultimedia::MetaData key, const QVariant &value) { + m_metaData.insert(key, value); emit metaDataChanged(); } + + QList availableMetaData() const { return m_metaData.keys(); } + + QVariant extendedMetaData(const QString &) const { return QVariant(); } + QStringList availableExtendedMetaData() const { return QStringList(); } + +private: + QMap m_metaData; +}; + +class QtTestMediaService : public QMediaService +{ + Q_OBJECT +public: + QtTestMediaService( + QtTestMediaPlayerControl *playerControl, + QtTestMetaDataControl *metaDataControl, + QObject *parent) + : QMediaService(parent) + , playerControl(playerControl) + , metaDataControl(metaDataControl) + { + } + + QMediaControl *requestControl(const char *name) + { + if (qstrcmp(name, QMediaPlayerControl_iid) == 0) + return playerControl; + else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) + return metaDataControl; + else + return 0; + } + + void releaseControl(QMediaControl *) {} + + QtTestMediaPlayerControl *playerControl; + QtTestMetaDataControl *metaDataControl; +}; + +class QtTestMediaServiceProvider : public QMediaServiceProvider +{ + Q_OBJECT +public: + QtTestMediaServiceProvider() + : service(new QtTestMediaService( + new QtTestMediaPlayerControl(this), new QtTestMetaDataControl(this), this)) + { + setDefaultServiceProvider(this); + } + + QtTestMediaServiceProvider(QtTestMediaService *service) + : service(service) + { + setDefaultServiceProvider(this); + } + + QtTestMediaServiceProvider( + QtTestMediaPlayerControl *playerControl, QtTestMetaDataControl *metaDataControl) + : service(new QtTestMediaService(playerControl, metaDataControl, this)) + { + setDefaultServiceProvider(this); + } + + ~QtTestMediaServiceProvider() + { + setDefaultServiceProvider(0); + } + + QMediaService *requestService( + const QByteArray &type, + const QMediaServiceProviderHint & = QMediaServiceProviderHint()) + { + requestedService = type; + + return service; + } + + void releaseService(QMediaService *) {} + + inline QtTestMediaPlayerControl *playerControl() { return service->playerControl; } + inline QtTestMetaDataControl *metaDataControl() { return service->metaDataControl; } + + QtTestMediaService *service; + QByteArray requestedService; +}; + +void tst_QDeclarativeAudio::initTestCase() +{ + qRegisterMetaType(); +} + +void tst_QDeclarativeAudio::nullPlayerControl() +{ + QtTestMetaDataControl metaDataControl; + QtTestMediaServiceProvider provider(0, &metaDataControl); + + QDeclarativeAudio audio; + audio.classBegin(); + + QCOMPARE(audio.source(), QUrl()); + audio.setSource(QUrl("http://example.com")); + QCOMPARE(audio.source(), QUrl("http://example.com")); + + QCOMPARE(audio.isPlaying(), false); + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + audio.setPlaying(false); + audio.play(); + QCOMPARE(audio.isPlaying(), false); + + QCOMPARE(audio.isPaused(), false); + audio.pause(); + QCOMPARE(audio.isPaused(), false); + audio.setPaused(true); + QCOMPARE(audio.isPaused(), true); + + QCOMPARE(audio.duration(), 0); + + QCOMPARE(audio.position(), 0); + audio.setPosition(10000); + QCOMPARE(audio.position(), 10000); + + QCOMPARE(audio.volume(), qreal(1.0)); + audio.setVolume(0.5); + QCOMPARE(audio.volume(), qreal(0.5)); + + QCOMPARE(audio.isMuted(), false); + audio.setMuted(true); + QCOMPARE(audio.isMuted(), true); + + QCOMPARE(audio.bufferProgress(), qreal(0)); + + QCOMPARE(audio.isSeekable(), false); + + QCOMPARE(audio.playbackRate(), qreal(1.0)); + + QCOMPARE(audio.status(), QDeclarativeAudio::NoMedia); + + QCOMPARE(audio.error(), QDeclarativeAudio::ServiceMissing); +} + +void tst_QDeclarativeAudio::nullMetaDataControl() +{ + QtTestMediaPlayerControl playerControl; + QtTestMediaServiceProvider provider(&playerControl, 0); + + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QVERIFY(audio.metaData()); +} + +void tst_QDeclarativeAudio::nullService() +{ + QtTestMediaServiceProvider provider(0); + + QDeclarativeAudio audio; + audio.classBegin(); + + QCOMPARE(audio.source(), QUrl()); + audio.setSource(QUrl("http://example.com")); + QCOMPARE(audio.source(), QUrl("http://example.com")); + + QCOMPARE(audio.isPlaying(), false); + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + audio.setPlaying(false); + audio.play(); + QCOMPARE(audio.isPlaying(), false); + + QCOMPARE(audio.isPaused(), false); + audio.pause(); + QCOMPARE(audio.isPaused(), false); + audio.setPaused(true); + QCOMPARE(audio.isPaused(), true); + + QCOMPARE(audio.duration(), 0); + + QCOMPARE(audio.position(), 0); + audio.setPosition(10000); + QCOMPARE(audio.position(), 10000); + + QCOMPARE(audio.volume(), qreal(1.0)); + audio.setVolume(0.5); + QCOMPARE(audio.volume(), qreal(0.5)); + + QCOMPARE(audio.isMuted(), false); + audio.setMuted(true); + QCOMPARE(audio.isMuted(), true); + + QCOMPARE(audio.bufferProgress(), qreal(0)); + + QCOMPARE(audio.isSeekable(), false); + + QCOMPARE(audio.playbackRate(), qreal(1.0)); + + QCOMPARE(audio.status(), QDeclarativeAudio::NoMedia); + + QCOMPARE(audio.error(), QDeclarativeAudio::ServiceMissing); + + QVERIFY(audio.metaData()); +} + +void tst_QDeclarativeAudio::source() +{ + const QUrl url1("http://example.com"); + const QUrl url2("file:///local/path"); + const QUrl url3; + + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(sourceChanged())); + + audio.setSource(url1); + QCOMPARE(audio.source(), url1); + QCOMPARE(provider.playerControl()->media().canonicalUrl(), url1); + QCOMPARE(spy.count(), 1); + + audio.setSource(url2); + QCOMPARE(audio.source(), url2); + QCOMPARE(provider.playerControl()->media().canonicalUrl(), url2); + QCOMPARE(spy.count(), 2); + + audio.setSource(url3); + QCOMPARE(audio.source(), url3); + QCOMPARE(provider.playerControl()->media().canonicalUrl(), url3); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeAudio::autoLoad() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(autoLoadChanged())); + + QCOMPARE(audio.isAutoLoad(), true); + + audio.setAutoLoad(false); + QCOMPARE(audio.isAutoLoad(), false); + QCOMPARE(spy.count(), 1); + + audio.setSource(QUrl("http://example.com")); + QCOMPARE(audio.source(), QUrl("http://example.com")); + audio.play(); + QCOMPARE(audio.isPlaying(), true); + audio.stop(); + + audio.setAutoLoad(true); + audio.setSource(QUrl("http://example.com")); + audio.setPaused(true); + QCOMPARE(spy.count(), 2); + QCOMPARE(audio.isPaused(), true); +} + +void tst_QDeclarativeAudio::playing() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + + QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged())); + QSignalSpy startedSpy(&audio, SIGNAL(started())); + QSignalSpy stoppedSpy(&audio, SIGNAL(stopped())); + + int playingChanged = 0; + int started = 0; + int stopped = 0; + + audio.componentComplete(); + audio.setSource(QUrl("http://example.com")); + + QCOMPARE(audio.isPlaying(), false); + + // setPlaying(true) when stopped. + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when playing. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // play() when stopped. + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when playing. + audio.stop(); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // stop() when stopped. + audio.stop(); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when stopped. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(true) when playing. + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + // play() when playing. + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); +} + +void tst_QDeclarativeAudio::paused() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + + QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged())); + QSignalSpy pausedChangedSpy(&audio, SIGNAL(pausedChanged())); + QSignalSpy startedSpy(&audio, SIGNAL(started())); + QSignalSpy pausedSpy(&audio, SIGNAL(paused())); + QSignalSpy resumedSpy(&audio, SIGNAL(resumed())); + QSignalSpy stoppedSpy(&audio, SIGNAL(stopped())); + + int playingChanged = 0; + int pausedChanged = 0; + int started = 0; + int paused = 0; + int resumed = 0; + int stopped = 0; + + audio.componentComplete(); + audio.setSource(QUrl("http://example.com")); + + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), false); + + // setPlaying(true) when stopped. + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when playing. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when paused. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when paused. + audio.pause(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when paused. + audio.setPaused(false); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), ++resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when playing. + audio.setPaused(false); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when playing. + audio.pause(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // setPaused(true) when stopped and paused. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when stopped and paused. + audio.setPaused(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when stopped. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(true) when stopped and paused. + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // play() when paused. + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), ++resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when playing. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when paused. + audio.stop(); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // setPaused(true) when stopped. + audio.setPaused(true); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when stopped and paused. + audio.stop(); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when stopped. + audio.pause(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // pause() when stopped and paused. + audio.pause(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(audio.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // play() when stopped and paused. + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(audio.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); +} + +void tst_QDeclarativeAudio::duration() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(durationChanged())); + + QCOMPARE(audio.duration(), 0); + + provider.playerControl()->setDuration(4040); + QCOMPARE(audio.duration(), 4040); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setDuration(-129); + QCOMPARE(audio.duration(), -129); + QCOMPARE(spy.count(), 2); + + provider.playerControl()->setDuration(0); + QCOMPARE(audio.duration(), 0); + QCOMPARE(spy.count(), 3); + + // Unnecessary duration changed signals aren't filtered. + provider.playerControl()->setDuration(0); + QCOMPARE(audio.duration(), 0); + QCOMPARE(spy.count(), 4); +} + +void tst_QDeclarativeAudio::position() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(positionChanged())); + + QCOMPARE(audio.position(), 0); + + // QDeclarativeAudio won't bound set positions to the duration. A media service may though. + QCOMPARE(audio.duration(), 0); + + audio.setPosition(450); + QCOMPARE(audio.position(), 450); + QCOMPARE(provider.playerControl()->position(), qint64(450)); + QCOMPARE(spy.count(), 1); + + audio.setPosition(-5403); + QCOMPARE(audio.position(), -5403); + QCOMPARE(provider.playerControl()->position(), qint64(-5403)); + QCOMPARE(spy.count(), 2); + + audio.setPosition(-5403); + QCOMPARE(audio.position(), -5403); + QCOMPARE(provider.playerControl()->position(), qint64(-5403)); + QCOMPARE(spy.count(), 2); + + // Check the signal change signal is emitted if the change originates from the media service. + provider.playerControl()->setPosition(0); + QCOMPARE(audio.position(), 0); + QCOMPARE(spy.count(), 3); + + connect(&audio, SIGNAL(positionChanged()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + provider.playerControl()->updateState(QMediaPlayer::PlayingState); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(spy.count() > 3 && spy.count() < 6); // 4 or 5 + + provider.playerControl()->updateState(QMediaPlayer::PausedState); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(spy.count() < 6); +} + +void tst_QDeclarativeAudio::volume() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(volumeChanged())); + + QCOMPARE(audio.volume(), qreal(1.0)); + + audio.setVolume(0.7); + QCOMPARE(audio.volume(), qreal(0.7)); + QCOMPARE(provider.playerControl()->volume(), 70); + QCOMPARE(spy.count(), 1); + + audio.setVolume(0.7); + QCOMPARE(audio.volume(), qreal(0.7)); + QCOMPARE(provider.playerControl()->volume(), 70); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setVolume(30); + QCOMPARE(audio.volume(), qreal(0.3)); + QCOMPARE(spy.count(), 2); +} + +void tst_QDeclarativeAudio::muted() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(mutedChanged())); + + QCOMPARE(audio.isMuted(), false); + + audio.setMuted(true); + QCOMPARE(audio.isMuted(), true); + QCOMPARE(provider.playerControl()->isMuted(), true); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setMuted(false); + QCOMPARE(audio.isMuted(), false); + QCOMPARE(spy.count(), 2); + + audio.setMuted(false); + QCOMPARE(audio.isMuted(), false); + QCOMPARE(provider.playerControl()->isMuted(), false); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeAudio::bufferProgress() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(bufferProgressChanged())); + + QCOMPARE(audio.bufferProgress(), qreal(0.0)); + + provider.playerControl()->setBufferStatus(20); + QCOMPARE(audio.bufferProgress(), qreal(0.2)); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setBufferStatus(20); + QCOMPARE(audio.bufferProgress(), qreal(0.2)); + QCOMPARE(spy.count(), 2); + + provider.playerControl()->setBufferStatus(40); + QCOMPARE(audio.bufferProgress(), qreal(0.4)); + QCOMPARE(spy.count(), 3); + + connect(&audio, SIGNAL(positionChanged()), &QTestEventLoop::instance(), SLOT(exitLoop())); + + provider.playerControl()->updateMediaStatus( + QMediaPlayer::BufferingMedia, QMediaPlayer::PlayingState); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(spy.count() > 3 && spy.count() < 6); // 4 or 5 + + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(spy.count() < 6); +} + +void tst_QDeclarativeAudio::seekable() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(seekableChanged())); + + QCOMPARE(audio.isSeekable(), false); + + provider.playerControl()->setSeekable(true); + QCOMPARE(audio.isSeekable(), true); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setSeekable(true); + QCOMPARE(audio.isSeekable(), true); + QCOMPARE(spy.count(), 2); + + provider.playerControl()->setSeekable(false); + QCOMPARE(audio.isSeekable(), false); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeAudio::playbackRate() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(&audio, SIGNAL(playbackRateChanged())); + + QCOMPARE(audio.playbackRate(), qreal(1.0)); + + audio.setPlaybackRate(0.5); + QCOMPARE(audio.playbackRate(), qreal(0.5)); + QCOMPARE(provider.playerControl()->playbackRate(), qreal(0.5)); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setPlaybackRate(2.0); + QCOMPARE(provider.playerControl()->playbackRate(), qreal(2.0)); + QCOMPARE(spy.count(), 2); + + audio.setPlaybackRate(2.0); + QCOMPARE(audio.playbackRate(), qreal(2.0)); + QCOMPARE(provider.playerControl()->playbackRate(), qreal(2.0)); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeAudio::status() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy statusChangedSpy(&audio, SIGNAL(statusChanged())); + + QCOMPARE(audio.status(), QDeclarativeAudio::NoMedia); + + // Set media, start loading. + provider.playerControl()->updateMediaStatus(QMediaPlayer::LoadingMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Loading); + QCOMPARE(statusChangedSpy.count(), 1); + + // Finish loading. + provider.playerControl()->updateMediaStatus(QMediaPlayer::LoadedMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Loaded); + QCOMPARE(statusChangedSpy.count(), 2); + + // Play, start buffering. + provider.playerControl()->updateMediaStatus( + QMediaPlayer::StalledMedia, QMediaPlayer::PlayingState); + QCOMPARE(audio.status(), QDeclarativeAudio::Stalled); + QCOMPARE(statusChangedSpy.count(), 3); + + // Enough data buffered to proceed. + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Buffering); + QCOMPARE(statusChangedSpy.count(), 4); + + // Errant second buffering status changed. + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Buffering); + QCOMPARE(statusChangedSpy.count(), 4); + + // Buffer full. + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Buffered); + QCOMPARE(statusChangedSpy.count(), 5); + + // Buffer getting low. + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferingMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Buffering); + QCOMPARE(statusChangedSpy.count(), 6); + + // Buffer full. + provider.playerControl()->updateMediaStatus(QMediaPlayer::BufferedMedia); + QCOMPARE(audio.status(), QDeclarativeAudio::Buffered); + QCOMPARE(statusChangedSpy.count(), 7); + + // Finished. + provider.playerControl()->updateMediaStatus( + QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + QCOMPARE(audio.status(), QDeclarativeAudio::EndOfMedia); + QCOMPARE(statusChangedSpy.count(), 8); +} + +void tst_QDeclarativeAudio::metaData_data() +{ + QTest::addColumn("propertyName"); + QTest::addColumn("propertyKey"); + QTest::addColumn("value"); + + QTest::newRow("title") + << QByteArray("title") + << QtMultimedia::Title + << QVariant(QString::fromLatin1("This is a title")); + + QTest::newRow("genre") + << QByteArray("genre") + << QtMultimedia::Genre + << QVariant(QString::fromLatin1("rock")); + + QTest::newRow("trackNumber") + << QByteArray("trackNumber") + << QtMultimedia::TrackNumber + << QVariant(8); +} + +void tst_QDeclarativeAudio::metaData() +{ + QFETCH(QByteArray, propertyName); + QFETCH(QtMultimedia::MetaData, propertyKey); + QFETCH(QVariant, value); + + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy spy(audio.metaData(), SIGNAL(metaDataChanged())); + + const int index = audio.metaData()->metaObject()->indexOfProperty(propertyName.constData()); + QVERIFY(index != -1); + + QMetaProperty property = audio.metaData()->metaObject()->property(index); + QCOMPARE(property.read(&audio), QVariant()); + + property.write(audio.metaData(), value); + QCOMPARE(property.read(audio.metaData()), QVariant()); + QCOMPARE(provider.metaDataControl()->metaData(propertyKey), QVariant()); + QCOMPARE(spy.count(), 0); + + provider.metaDataControl()->setMetaData(propertyKey, value); + QCOMPARE(property.read(audio.metaData()), value); + QCOMPARE(spy.count(), 1); +} + +void tst_QDeclarativeAudio::error() +{ + const QString errorString = QLatin1String("Failed to open device."); + + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + audio.classBegin(); + audio.componentComplete(); + + QSignalSpy errorSpy(&audio, SIGNAL(error(QDeclarativeAudio::Error,QString))); + QSignalSpy errorChangedSpy(&audio, SIGNAL(errorChanged())); + + QCOMPARE(audio.error(), QDeclarativeAudio::NoError); + QCOMPARE(audio.errorString(), QString()); + + provider.playerControl()->emitError(QMediaPlayer::ResourceError, errorString); + + QCOMPARE(audio.error(), QDeclarativeAudio::ResourceError); + QCOMPARE(audio.errorString(), errorString); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 1); + + // Changing the source resets the error properties. + audio.setSource(QUrl("http://example.com")); + QCOMPARE(audio.error(), QDeclarativeAudio::NoError); + QCOMPARE(audio.errorString(), QString()); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 2); + + // But isn't noisy. + audio.setSource(QUrl("file:///file/path")); + QCOMPARE(audio.error(), QDeclarativeAudio::NoError); + QCOMPARE(audio.errorString(), QString()); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 2); +} + +void tst_QDeclarativeAudio::loops() +{ + QtTestMediaServiceProvider provider; + QDeclarativeAudio audio; + + QSignalSpy loopsChangedSpy(&audio, SIGNAL(loopCountChanged())); + QSignalSpy playingChangedSpy(&audio, SIGNAL(playingChanged())); + QSignalSpy stoppedSpy(&audio, SIGNAL(stopped())); + + int playingChanged = 0; + int stopped = 0; + int loopsChanged = 0; + + audio.classBegin(); + audio.componentComplete(); + + QCOMPARE(audio.isPlaying(), false); + + //setLoopCount(3) when stopped. + audio.setLoopCount(3); + QCOMPARE(audio.loopCount(), 3); + QCOMPARE(loopsChangedSpy.count(), ++loopsChanged); + + //play till end + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + + // setPlaying(true) when playing. + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(stoppedSpy.count(), stopped); + + provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + + //play to end + provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + //play to end + provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // stop when playing + audio.play(); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + audio.stop(); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(stoppedSpy.count(), ++stopped); + + //setPlaying(true) with infinite loop + audio.setLoopCount(-1); + QCOMPARE(audio.loopCount(), -1); + QCOMPARE(loopsChangedSpy.count(), ++loopsChanged); + audio.setPlaying(true); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + provider.playerControl()->updateMediaStatus(QMediaPlayer::EndOfMedia, QMediaPlayer::StoppedState); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + + // play() when playing. + audio.play(); + QCOMPARE(audio.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when playing in infinite loop. + audio.setPlaying(false); + QCOMPARE(audio.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(stoppedSpy.count(), ++stopped); +} + +QTEST_MAIN(tst_QDeclarativeAudio) + +#include "tst_qdeclarativeaudio.moc" diff --git a/tests/auto/unit/qdeclarativevideo/qdeclarativevideo.pro b/tests/auto/unit/qdeclarativevideo/qdeclarativevideo.pro new file mode 100644 index 000000000..cd1c615cf --- /dev/null +++ b/tests/auto/unit/qdeclarativevideo/qdeclarativevideo.pro @@ -0,0 +1,18 @@ +CONFIG += testcase +TARGET = tst_qdeclarativevideo + +QT += multimedia-private declarative testlib +CONFIG += no_private_qt_headers_warning + +HEADERS += \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativevideo_p.h \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase_p.h \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediametadata_p.h + +SOURCES += \ + tst_qdeclarativevideo.cpp \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativevideo.cpp \ + $$QT.multimedia.sources/../imports/multimedia/qdeclarativemediabase.cpp + +INCLUDEPATH += $$QT.multimedia.sources/../imports/multimedia +QT+=widgets diff --git a/tests/auto/unit/qdeclarativevideo/tst_qdeclarativevideo.cpp b/tests/auto/unit/qdeclarativevideo/tst_qdeclarativevideo.cpp new file mode 100644 index 000000000..5a0dce318 --- /dev/null +++ b/tests/auto/unit/qdeclarativevideo/tst_qdeclarativevideo.cpp @@ -0,0 +1,991 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=plugins/declarative/multimedia + +#include + +#include "qdeclarativevideo_p.h" + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class tst_QDeclarativeVideo : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + +private slots: + void nullPlayerControl(); + void nullService(); + + void playing(); + void paused(); + void error(); + + void hasAudio(); + void hasVideo(); + void fillMode(); + void geometry(); +}; + +Q_DECLARE_METATYPE(QDeclarativeVideo::Error); + +class QtTestMediaPlayerControl : public QMediaPlayerControl +{ + Q_OBJECT +public: + QtTestMediaPlayerControl(QObject *parent = 0) + : QMediaPlayerControl(parent) + , m_state(QMediaPlayer::StoppedState) + , m_mediaStatus(QMediaPlayer::NoMedia) + , m_duration(0) + , m_position(0) + , m_playbackRate(1.0) + , m_volume(50) + , m_bufferStatus(0) + , m_muted(false) + , m_audioAvailable(false) + , m_videoAvailable(false) + , m_seekable(false) + { + } + + QMediaPlayer::State state() const { return m_state; } + void updateState(QMediaPlayer::State state) { emit stateChanged(m_state = state); } + + QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; } + void updateMediaStatus(QMediaPlayer::MediaStatus status) { + emit mediaStatusChanged(m_mediaStatus = status); } + void updateMediaStatus(QMediaPlayer::MediaStatus status, QMediaPlayer::State state) + { + m_mediaStatus = status; + m_state = state; + + emit mediaStatusChanged(m_mediaStatus); + emit stateChanged(m_state); + } + + qint64 duration() const { return m_duration; } + void setDuration(qint64 duration) { emit durationChanged(m_duration = duration); } + + qint64 position() const { return m_position; } + void setPosition(qint64 position) { emit positionChanged(m_position = position); } + + int volume() const { return m_volume; } + void setVolume(int volume) { emit volumeChanged(m_volume = volume); } + + bool isMuted() const { return m_muted; } + void setMuted(bool muted) { emit mutedChanged(m_muted = muted); } + + int bufferStatus() const { return m_bufferStatus; } + void setBufferStatus(int status) { emit bufferStatusChanged(m_bufferStatus = status); } + + bool isAudioAvailable() const { return m_audioAvailable; } + void setAudioAvailable(bool available) { + emit audioAvailableChanged(m_audioAvailable = available); } + bool isVideoAvailable() const { return m_videoAvailable; } + void setVideoAvailable(bool available) { + emit videoAvailableChanged(m_videoAvailable = available); } + + bool isSeekable() const { return m_seekable; } + void setSeekable(bool seekable) { emit seekableChanged(m_seekable = seekable); } + + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); } + + qreal playbackRate() const { return m_playbackRate; } + void setPlaybackRate(qreal rate) { emit playbackRateChanged(m_playbackRate = rate); } + + QMediaContent media() const { return m_media; } + const QIODevice *mediaStream() const { return 0; } + void setMedia(const QMediaContent &media, QIODevice *) + { + m_media = media; + + m_mediaStatus = m_media.isNull() + ? QMediaPlayer::NoMedia + : QMediaPlayer::LoadingMedia; + + emit mediaChanged(m_media); + emit mediaStatusChanged(m_mediaStatus); + } + + void play() { emit stateChanged(m_state = QMediaPlayer::PlayingState); } + void pause() { emit stateChanged(m_state = QMediaPlayer::PausedState); } + void stop() { emit stateChanged(m_state = QMediaPlayer::StoppedState); } + + void emitError(QMediaPlayer::Error err, const QString &errorString) { + emit error(err, errorString); } + +private: + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_mediaStatus; + qint64 m_duration; + qint64 m_position; + qreal m_playbackRate; + int m_volume; + int m_bufferStatus; + bool m_muted; + bool m_audioAvailable; + bool m_videoAvailable; + bool m_seekable; + QMediaContent m_media; +}; + +class QtTestRendererControl : public QVideoRendererControl +{ +public: + QtTestRendererControl(QObject *parent ) : QVideoRendererControl(parent), m_surface(0) {} + + QAbstractVideoSurface *surface() const { return m_surface; } + void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } + +private: + QAbstractVideoSurface *m_surface; +}; + +class QtTestWindowControl : public QVideoWindowControl +{ +public: + QtTestWindowControl(QObject *parent) + : QVideoWindowControl(parent) + , m_winId(0) + , m_repaintCount(0) + , m_brightness(0) + , m_contrast(0) + , m_saturation(0) + , m_aspectRatioMode(Qt::KeepAspectRatio) + , m_fullScreen(0) + { + } + + WId winId() const { return m_winId; } + void setWinId(WId id) { m_winId = id; } + + QRect displayRect() const { return m_displayRect; } + void setDisplayRect(const QRect &rect) { m_displayRect = rect; } + + bool isFullScreen() const { return m_fullScreen; } + void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); } + + int repaintCount() const { return m_repaintCount; } + void setRepaintCount(int count) { m_repaintCount = count; } + void repaint() { ++m_repaintCount; } + + QSize nativeSize() const { return m_nativeSize; } + void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); } + + Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; } + void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; } + + int brightness() const { return m_brightness; } + void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); } + + int contrast() const { return m_contrast; } + void setContrast(int contrast) { emit contrastChanged(m_contrast = contrast); } + + int hue() const { return m_hue; } + void setHue(int hue) { emit hueChanged(m_hue = hue); } + + int saturation() const { return m_saturation; } + void setSaturation(int saturation) { emit saturationChanged(m_saturation = saturation); } + +private: + WId m_winId; + int m_repaintCount; + int m_brightness; + int m_contrast; + int m_hue; + int m_saturation; + Qt::AspectRatioMode m_aspectRatioMode; + QRect m_displayRect; + QSize m_nativeSize; + bool m_fullScreen; +}; + +class QtTestMediaService : public QMediaService +{ + Q_OBJECT +public: + QtTestMediaService( + QtTestMediaPlayerControl *playerControl, + QtTestRendererControl *rendererControl, + QtTestWindowControl *windowControl, + QObject *parent) + : QMediaService(parent) + , playerControl(playerControl) + , rendererControl(rendererControl) + , windowControl(windowControl) + { + } + + QMediaControl *requestControl(const char *name) + { + if (qstrcmp(name, QMediaPlayerControl_iid) == 0) + return playerControl; + else if (qstrcmp(name, QVideoRendererControl_iid) == 0) + return rendererControl; + else if (qstrcmp(name, QVideoWindowControl_iid) == 0) + return windowControl; + else + return 0; + } + + void releaseControl(QMediaControl *) {} + + QtTestMediaPlayerControl *playerControl; + QtTestRendererControl *rendererControl; + QtTestWindowControl *windowControl; +}; + +class QtTestMediaServiceProvider : public QMediaServiceProvider +{ + Q_OBJECT +public: + QtTestMediaServiceProvider() + : service( + new QtTestMediaService( + new QtTestMediaPlayerControl(this), + new QtTestRendererControl(this), + new QtTestWindowControl(this), + this)) + { + setDefaultServiceProvider(this); + } + + QtTestMediaServiceProvider(QtTestMediaService *service) + : service(service) + { + setDefaultServiceProvider(this); + } + + QtTestMediaServiceProvider( + QtTestMediaPlayerControl *playerControl, + QtTestRendererControl *rendererControl, + QtTestWindowControl *windowControl) + : service(new QtTestMediaService(playerControl, rendererControl, windowControl, this)) + { + setDefaultServiceProvider(this); + } + + ~QtTestMediaServiceProvider() + { + setDefaultServiceProvider(0); + } + + QMediaService *requestService( + const QByteArray &type, + const QMediaServiceProviderHint & = QMediaServiceProviderHint()) + { + requestedService = type; + + return service; + } + + void releaseService(QMediaService *) {} + + inline QtTestMediaPlayerControl *playerControl() { return service->playerControl; } + inline QtTestRendererControl *rendererControl() { return service->rendererControl; } + + QtTestMediaService *service; + QByteArray requestedService; +}; + + +void tst_QDeclarativeVideo::initTestCase() +{ + qRegisterMetaType(); +} + +void tst_QDeclarativeVideo::nullPlayerControl() +{ + QtTestMediaServiceProvider provider(0, 0, 0); + + QDeclarativeVideo video; + video.classBegin(); + + QCOMPARE(video.source(), QUrl()); + video.setSource(QUrl("http://example.com")); + QCOMPARE(video.source(), QUrl("http://example.com")); + + QCOMPARE(video.isPlaying(), false); + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + video.setPlaying(false); + video.play(); + QCOMPARE(video.isPlaying(), false); + + QCOMPARE(video.isPaused(), false); + video.pause(); + QCOMPARE(video.isPaused(), false); + video.setPaused(true); + QCOMPARE(video.isPaused(), true); + + QCOMPARE(video.duration(), 0); + + QCOMPARE(video.position(), 0); + video.setPosition(10000); + QCOMPARE(video.position(), 10000); + + QCOMPARE(video.volume(), qreal(1.0)); + video.setVolume(0.5); + QCOMPARE(video.volume(), qreal(0.5)); + + QCOMPARE(video.isMuted(), false); + video.setMuted(true); + QCOMPARE(video.isMuted(), true); + + QCOMPARE(video.bufferProgress(), qreal(0)); + + QCOMPARE(video.isSeekable(), false); + + QCOMPARE(video.playbackRate(), qreal(1.0)); + + QCOMPARE(video.hasAudio(), false); + QCOMPARE(video.hasVideo(), false); + + QCOMPARE(video.status(), QDeclarativeVideo::NoMedia); + + QCOMPARE(video.error(), QDeclarativeVideo::ServiceMissing); +} + +void tst_QDeclarativeVideo::nullService() +{ + QtTestMediaServiceProvider provider(0); + + QDeclarativeVideo video; + video.classBegin(); + + QCOMPARE(video.source(), QUrl()); + video.setSource(QUrl("http://example.com")); + QCOMPARE(video.source(), QUrl("http://example.com")); + + QCOMPARE(video.isPlaying(), false); + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + video.setPlaying(false); + video.play(); + QCOMPARE(video.isPlaying(), false); + + QCOMPARE(video.isPaused(), false); + video.pause(); + QCOMPARE(video.isPaused(), false); + video.setPaused(true); + QCOMPARE(video.isPaused(), true); + + QCOMPARE(video.duration(), 0); + + QCOMPARE(video.position(), 0); + video.setPosition(10000); + QCOMPARE(video.position(), 10000); + + QCOMPARE(video.volume(), qreal(1.0)); + video.setVolume(0.5); + QCOMPARE(video.volume(), qreal(0.5)); + + QCOMPARE(video.isMuted(), false); + video.setMuted(true); + QCOMPARE(video.isMuted(), true); + + QCOMPARE(video.bufferProgress(), qreal(0)); + + QCOMPARE(video.isSeekable(), false); + + QCOMPARE(video.playbackRate(), qreal(1.0)); + + QCOMPARE(video.hasAudio(), false); + QCOMPARE(video.hasVideo(), false); + + QCOMPARE(video.status(), QDeclarativeVideo::NoMedia); + + QCOMPARE(video.error(), QDeclarativeVideo::ServiceMissing); + + QCOMPARE(video.metaObject()->indexOfProperty("title"), -1); + QCOMPARE(video.metaObject()->indexOfProperty("genre"), -1); + QCOMPARE(video.metaObject()->indexOfProperty("description"), -1); +} + +void tst_QDeclarativeVideo::playing() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + video.setSource(QUrl("http://example.com")); + + QSignalSpy playingChangedSpy(&video, SIGNAL(playingChanged())); + QSignalSpy startedSpy(&video, SIGNAL(started())); + QSignalSpy stoppedSpy(&video, SIGNAL(stopped())); + + int playingChanged = 0; + int started = 0; + int stopped = 0; + + QCOMPARE(video.isPlaying(), false); + + // setPlaying(true) when stopped. + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when playing. + video.setPlaying(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // play() when stopped. + video.play(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when playing. + video.stop(); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // stop() when stopped. + video.stop(); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when stopped. + video.setPlaying(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(true) when playing. + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); + + // play() when playing. + video.play(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(stoppedSpy.count(), stopped); +} + +void tst_QDeclarativeVideo::paused() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + video.setSource(QUrl("http://example.com")); + + QSignalSpy playingChangedSpy(&video, SIGNAL(playingChanged())); + QSignalSpy pausedChangedSpy(&video, SIGNAL(pausedChanged())); + QSignalSpy startedSpy(&video, SIGNAL(started())); + QSignalSpy pausedSpy(&video, SIGNAL(paused())); + QSignalSpy resumedSpy(&video, SIGNAL(resumed())); + QSignalSpy stoppedSpy(&video, SIGNAL(stopped())); + + int playingChanged = 0; + int pausedChanged = 0; + int started = 0; + int paused = 0; + int resumed = 0; + int stopped = 0; + + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), false); + + // setPlaying(true) when stopped. + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when playing. + video.setPaused(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when paused. + video.setPaused(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when paused. + video.pause(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when paused. + video.setPaused(false); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), ++resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when playing. + video.setPaused(false); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when playing. + video.pause(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + video.setPlaying(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // setPaused(true) when stopped and paused. + video.setPaused(true); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(false) when stopped and paused. + video.setPaused(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when stopped. + video.setPaused(true); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(true) when stopped and paused. + video.setPlaying(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // play() when paused. + video.play(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), ++resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPaused(true) when playing. + video.setPaused(true); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when paused. + video.stop(); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // setPaused(true) when stopped. + video.setPaused(true); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // stop() when stopped and paused. + video.stop(); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // pause() when stopped. + video.pause(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + video.setPlaying(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // pause() when stopped and paused. + video.pause(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PausedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), ++paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); + + // setPlaying(false) when paused. + video.setPlaying(false); + QCOMPARE(video.isPlaying(), false); + QCOMPARE(video.isPaused(), true); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::StoppedState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), pausedChanged); + QCOMPARE(startedSpy.count(), started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), ++stopped); + + // play() when stopped and paused. + video.play(); + QCOMPARE(video.isPlaying(), true); + QCOMPARE(video.isPaused(), false); + QCOMPARE(provider.playerControl()->state(), QMediaPlayer::PlayingState); + QCOMPARE(playingChangedSpy.count(), ++playingChanged); + QCOMPARE(pausedChangedSpy.count(), ++pausedChanged); + QCOMPARE(startedSpy.count(), ++started); + QCOMPARE(pausedSpy.count(), paused); + QCOMPARE(resumedSpy.count(), resumed); + QCOMPARE(stoppedSpy.count(), stopped); +} + +void tst_QDeclarativeVideo::error() +{ + const QString errorString = QLatin1String("Failed to open device."); + + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + + QSignalSpy errorSpy(&video, SIGNAL(error(QDeclarativeVideo::Error,QString))); + QSignalSpy errorChangedSpy(&video, SIGNAL(errorChanged())); + + QCOMPARE(video.error(), QDeclarativeVideo::NoError); + QCOMPARE(video.errorString(), QString()); + + provider.playerControl()->emitError(QMediaPlayer::ResourceError, errorString); + + QCOMPARE(video.error(), QDeclarativeVideo::ResourceError); + QCOMPARE(video.errorString(), errorString); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 1); + + // Changing the source resets the error properties. + video.setSource(QUrl("http://example.com")); + QCOMPARE(video.error(), QDeclarativeVideo::NoError); + QCOMPARE(video.errorString(), QString()); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 2); + + // But isn't noisy. + video.setSource(QUrl("file:///file/path")); + QCOMPARE(video.error(), QDeclarativeVideo::NoError); + QCOMPARE(video.errorString(), QString()); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorChangedSpy.count(), 2); +} + + +void tst_QDeclarativeVideo::hasAudio() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + + QSignalSpy spy(&video, SIGNAL(hasAudioChanged())); + + QCOMPARE(video.hasAudio(), false); + + provider.playerControl()->setAudioAvailable(true); + QCOMPARE(video.hasAudio(), true); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setAudioAvailable(true); + QCOMPARE(video.hasAudio(), true); + QCOMPARE(spy.count(), 2); + + provider.playerControl()->setAudioAvailable(false); + QCOMPARE(video.hasAudio(), false); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeVideo::hasVideo() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + + QSignalSpy spy(&video, SIGNAL(hasVideoChanged())); + + QCOMPARE(video.hasVideo(), false); + + provider.playerControl()->setVideoAvailable(true); + QCOMPARE(video.hasVideo(), true); + QCOMPARE(spy.count(), 1); + + provider.playerControl()->setVideoAvailable(true); + QCOMPARE(video.hasVideo(), true); + QCOMPARE(spy.count(), 2); + + provider.playerControl()->setVideoAvailable(false); + QCOMPARE(video.hasVideo(), false); + QCOMPARE(spy.count(), 3); +} + +void tst_QDeclarativeVideo::fillMode() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + + QList children = video.childItems(); + QCOMPARE(children.count(), 1); + QGraphicsVideoItem *videoItem = qgraphicsitem_cast(children.first()); + QVERIFY(videoItem != 0); + + QCOMPARE(video.fillMode(), QDeclarativeVideo::PreserveAspectFit); + + video.setFillMode(QDeclarativeVideo::PreserveAspectCrop); + QCOMPARE(video.fillMode(), QDeclarativeVideo::PreserveAspectCrop); + QCOMPARE(videoItem->aspectRatioMode(), Qt::KeepAspectRatioByExpanding); + + video.setFillMode(QDeclarativeVideo::Stretch); + QCOMPARE(video.fillMode(), QDeclarativeVideo::Stretch); + QCOMPARE(videoItem->aspectRatioMode(), Qt::IgnoreAspectRatio); + + video.setFillMode(QDeclarativeVideo::PreserveAspectFit); + QCOMPARE(video.fillMode(), QDeclarativeVideo::PreserveAspectFit); + QCOMPARE(videoItem->aspectRatioMode(), Qt::KeepAspectRatio); +} + +void tst_QDeclarativeVideo::geometry() +{ + QtTestMediaServiceProvider provider; + QDeclarativeVideo video; + video.classBegin(); + video.componentComplete(); + + QList children = video.childItems(); + QCOMPARE(children.count(), 1); + QGraphicsVideoItem *videoItem = qgraphicsitem_cast(children.first()); + QVERIFY(videoItem != 0); + + { // Surface setup is deferred until after the first paint. + QImage image(320, 240, QImage::Format_RGB32); + QPainter painter(&image); + + videoItem->paint(&painter, 0); + } + + QAbstractVideoSurface *surface = provider.rendererControl()->surface(); + + //video item can use overlay, QAbstractVideoSurface is not used than. + if (surface) { + QVideoSurfaceFormat format(QSize(640, 480), QVideoFrame::Format_RGB32); + + QVERIFY(surface->start(format)); + QCoreApplication::processEvents(); + + QCOMPARE(video.implicitWidth(), qreal(640)); + QCOMPARE(video.implicitHeight(), qreal(480)); + } + + video.setWidth(560); + video.setHeight(328); + + QCOMPARE(videoItem->size().width(), qreal(560)); + QCOMPARE(videoItem->size().height(), qreal(328)); +} + +QTEST_MAIN(tst_QDeclarativeVideo) + +#include "tst_qdeclarativevideo.moc" diff --git a/tests/auto/unit/qgraphicsvideoitem/qgraphicsvideoitem.pro b/tests/auto/unit/qgraphicsvideoitem/qgraphicsvideoitem.pro new file mode 100644 index 000000000..eac437632 --- /dev/null +++ b/tests/auto/unit/qgraphicsvideoitem/qgraphicsvideoitem.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qgraphicsvideoitem + +QT += multimedia-private multimediawidgets-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qgraphicsvideoitem.cpp + +# QPA minimal crashes with this test in QBackingStore +CONFIG += insignificant_test +QT+=widgets diff --git a/tests/auto/unit/qgraphicsvideoitem/tst_qgraphicsvideoitem.cpp b/tests/auto/unit/qgraphicsvideoitem/tst_qgraphicsvideoitem.cpp new file mode 100644 index 000000000..393ac7a49 --- /dev/null +++ b/tests/auto/unit/qgraphicsvideoitem/tst_qgraphicsvideoitem.cpp @@ -0,0 +1,675 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include "qgraphicsvideoitem.h" +#include +#include "qmediaobject.h" +#include "qmediaservice.h" +#include +#include "qvideorenderercontrol.h" + +#include +#include + +#include +#include +#include + +QT_USE_NAMESPACE +class tst_QGraphicsVideoItem : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + +private slots: + void nullObject(); + void nullService(); + void noOutputs(); + void serviceDestroyed(); + void mediaObjectDestroyed(); + void setMediaObject(); + + void show(); + + void aspectRatioMode(); + void offset(); + void size(); + void nativeSize_data(); + void nativeSize(); + + void boundingRect_data(); + void boundingRect(); + + void paint(); +}; + +Q_DECLARE_METATYPE(const uchar *) +Q_DECLARE_METATYPE(Qt::AspectRatioMode) + +class QtTestRendererControl : public QVideoRendererControl +{ +public: + QtTestRendererControl() + : m_surface(0) + { + } + + QAbstractVideoSurface *surface() const { return m_surface; } + void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } + +private: + QAbstractVideoSurface *m_surface; +}; + +class QtTestVideoService : public QMediaService +{ + Q_OBJECT +public: + QtTestVideoService( + QtTestRendererControl *renderer) + : QMediaService(0) + , rendererRef(0) + , rendererControl(renderer) + { + } + + ~QtTestVideoService() + { + delete rendererControl; + } + + QMediaControl *requestControl(const char *name) + { + if (qstrcmp(name, QVideoRendererControl_iid) == 0 && rendererControl) { + rendererRef += 1; + + return rendererControl; + } else { + return 0; + } + } + + void releaseControl(QMediaControl *control) + { + Q_ASSERT(control); + + if (control == rendererControl) { + rendererRef -= 1; + + if (rendererRef == 0) + rendererControl->setSurface(0); + } + } + + int rendererRef; + QtTestRendererControl *rendererControl; +}; + +class QtTestVideoObject : public QMediaObject +{ + Q_OBJECT +public: + QtTestVideoObject(QtTestRendererControl *renderer) + : QMediaObject(0, new QtTestVideoService(renderer)) + { + testService = qobject_cast(service()); + } + + QtTestVideoObject(QtTestVideoService *service): + QMediaObject(0, service), + testService(service) + { + } + + ~QtTestVideoObject() + { + delete testService; + } + + QtTestVideoService *testService; +}; + +class QtTestGraphicsVideoItem : public QGraphicsVideoItem +{ +public: + QtTestGraphicsVideoItem(QGraphicsItem *parent = 0) + : QGraphicsVideoItem(parent) + , m_paintCount(0) + { + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + ++m_paintCount; + + QTestEventLoop::instance().exitLoop(); + + QGraphicsVideoItem::paint(painter, option, widget); + } + + bool waitForPaint(int secs) + { + const int paintCount = m_paintCount; + + QTestEventLoop::instance().enterLoop(secs); + + return m_paintCount != paintCount; + } + + int paintCount() const + { + return m_paintCount; + } + +private: + int m_paintCount; +}; + +void tst_QGraphicsVideoItem::initTestCase() +{ + qRegisterMetaType(); +} + +void tst_QGraphicsVideoItem::nullObject() +{ + QGraphicsVideoItem item(0); + + QVERIFY(item.boundingRect().isEmpty()); +} + +void tst_QGraphicsVideoItem::nullService() +{ + QtTestVideoService *service = 0; + + QtTestVideoObject object(service); + + QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; + object.bind(item); + + QVERIFY(item->boundingRect().isEmpty()); + + item->hide(); + item->show(); + + QGraphicsScene graphicsScene; + graphicsScene.addItem(item); + QGraphicsView graphicsView(&graphicsScene); + graphicsView.show(); +} + +void tst_QGraphicsVideoItem::noOutputs() +{ + QtTestRendererControl *control = 0; + QtTestVideoObject object(control); + + QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; + object.bind(item); + + QVERIFY(item->boundingRect().isEmpty()); + + item->hide(); + item->show(); + + QGraphicsScene graphicsScene; + graphicsScene.addItem(item); + QGraphicsView graphicsView(&graphicsScene); + graphicsView.show(); +} + +void tst_QGraphicsVideoItem::serviceDestroyed() +{ + QtTestVideoObject object(new QtTestRendererControl); + + QGraphicsVideoItem item; + object.bind(&item); + + QCOMPARE(object.testService->rendererRef, 1); + + QtTestVideoService *service = object.testService; + object.testService = 0; + + delete service; + + QCOMPARE(item.mediaObject(), static_cast(&object)); + QVERIFY(item.boundingRect().isEmpty()); +} + +void tst_QGraphicsVideoItem::mediaObjectDestroyed() +{ + QtTestVideoObject *object = new QtTestVideoObject(new QtTestRendererControl); + + QGraphicsVideoItem item; + object->bind(&item); + + QCOMPARE(object->testService->rendererRef, 1); + + delete object; + object = 0; + + QCOMPARE(item.mediaObject(), static_cast(object)); + QVERIFY(item.boundingRect().isEmpty()); +} + +void tst_QGraphicsVideoItem::setMediaObject() +{ + QMediaObject *nullObject = 0; + QtTestVideoObject object(new QtTestRendererControl); + + QGraphicsVideoItem item; + + QCOMPARE(item.mediaObject(), nullObject); + QCOMPARE(object.testService->rendererRef, 0); + + object.bind(&item); + QCOMPARE(item.mediaObject(), static_cast(&object)); + QCOMPARE(object.testService->rendererRef, 1); + QVERIFY(object.testService->rendererControl->surface() == 0); + + { // Surface setup is deferred until after the first paint. + QImage image(320, 240, QImage::Format_RGB32); + QPainter painter(&image); + + item.paint(&painter, 0); + } + QVERIFY(object.testService->rendererControl->surface() != 0); + + object.unbind(&item); + QCOMPARE(item.mediaObject(), nullObject); + + QCOMPARE(object.testService->rendererRef, 0); + QVERIFY(object.testService->rendererControl->surface() == 0); + + item.setVisible(false); + + object.bind(&item); + QCOMPARE(item.mediaObject(), static_cast(&object)); + QCOMPARE(object.testService->rendererRef, 1); + QVERIFY(object.testService->rendererControl->surface() != 0); +} + +void tst_QGraphicsVideoItem::show() +{ + QtTestVideoObject object(new QtTestRendererControl); + QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; + object.bind(item); + + // Graphics items are visible by default + QCOMPARE(object.testService->rendererRef, 1); + QVERIFY(object.testService->rendererControl->surface() == 0); + + item->hide(); + QCOMPARE(object.testService->rendererRef, 1); + + item->show(); + QCOMPARE(object.testService->rendererRef, 1); + QVERIFY(object.testService->rendererControl->surface() == 0); + + QGraphicsScene graphicsScene; + graphicsScene.addItem(item); + QGraphicsView graphicsView(&graphicsScene); + graphicsView.show(); + + QVERIFY(item->paintCount() || item->waitForPaint(1)); + QVERIFY(object.testService->rendererControl->surface() != 0); + + QVERIFY(item->boundingRect().isEmpty()); + + QVideoSurfaceFormat format(QSize(320,240),QVideoFrame::Format_RGB32); + QVERIFY(object.testService->rendererControl->surface()->start(format)); + + QCoreApplication::processEvents(); + QVERIFY(!item->boundingRect().isEmpty()); +} + +void tst_QGraphicsVideoItem::aspectRatioMode() +{ + QGraphicsVideoItem item; + + QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatio); + + item.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(item.aspectRatioMode(), Qt::IgnoreAspectRatio); + + item.setAspectRatioMode(Qt::KeepAspectRatioByExpanding); + QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatioByExpanding); + + item.setAspectRatioMode(Qt::KeepAspectRatio); + QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatio); +} + +void tst_QGraphicsVideoItem::offset() +{ + QGraphicsVideoItem item; + + QCOMPARE(item.offset(), QPointF(0, 0)); + + item.setOffset(QPointF(-32.4, 43.0)); + QCOMPARE(item.offset(), QPointF(-32.4, 43.0)); + + item.setOffset(QPointF(1, 1)); + QCOMPARE(item.offset(), QPointF(1, 1)); + + item.setOffset(QPointF(12, -30.4)); + QCOMPARE(item.offset(), QPointF(12, -30.4)); + + item.setOffset(QPointF(-90.4, -75)); + QCOMPARE(item.offset(), QPointF(-90.4, -75)); +} + +void tst_QGraphicsVideoItem::size() +{ + QGraphicsVideoItem item; + + QCOMPARE(item.size(), QSizeF(320, 240)); + + item.setSize(QSizeF(542.5, 436.3)); + QCOMPARE(item.size(), QSizeF(542.5, 436.3)); + + item.setSize(QSizeF(-43, 12)); + QCOMPARE(item.size(), QSizeF(0, 0)); + + item.setSize(QSizeF(54, -9)); + QCOMPARE(item.size(), QSizeF(0, 0)); + + item.setSize(QSizeF(-90, -65)); + QCOMPARE(item.size(), QSizeF(0, 0)); + + item.setSize(QSizeF(1000, 1000)); + QCOMPARE(item.size(), QSizeF(1000, 1000)); +} + +void tst_QGraphicsVideoItem::nativeSize_data() +{ + QTest::addColumn("frameSize"); + QTest::addColumn("viewport"); + QTest::addColumn("pixelAspectRatio"); + QTest::addColumn("nativeSize"); + + QTest::newRow("640x480") + << QSize(640, 480) + << QRect(0, 0, 640, 480) + << QSize(1, 1) + << QSizeF(640, 480); + + QTest::newRow("800x600, (80,60, 640x480) viewport") + << QSize(800, 600) + << QRect(80, 60, 640, 480) + << QSize(1, 1) + << QSizeF(640, 480); + + QTest::newRow("800x600, (80,60, 640x480) viewport, 4:3") + << QSize(800, 600) + << QRect(80, 60, 640, 480) + << QSize(4, 3) + << QSizeF(853, 480); +} + +void tst_QGraphicsVideoItem::nativeSize() +{ + QFETCH(QSize, frameSize); + QFETCH(QRect, viewport); + QFETCH(QSize, pixelAspectRatio); + QFETCH(QSizeF, nativeSize); + + QtTestVideoObject object(new QtTestRendererControl); + QGraphicsVideoItem item; + object.bind(&item); + + QCOMPARE(item.nativeSize(), QSizeF()); + + QSignalSpy spy(&item, SIGNAL(nativeSizeChanged(QSizeF))); + + QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); + format.setViewport(viewport); + format.setPixelAspectRatio(pixelAspectRatio); + + { // Surface setup is deferred until after the first paint. + QImage image(320, 240, QImage::Format_RGB32); + QPainter painter(&image); + + item.paint(&painter, 0); + } + QVERIFY(object.testService->rendererControl->surface() != 0); + QVERIFY(object.testService->rendererControl->surface()->start(format)); + + QCoreApplication::processEvents(); + QCOMPARE(item.nativeSize(), nativeSize); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().first().toSizeF(), nativeSize); + + object.testService->rendererControl->surface()->stop(); + + QCoreApplication::processEvents(); + QVERIFY(item.nativeSize().isEmpty()); + QCOMPARE(spy.count(), 2); + QVERIFY(spy.last().first().toSizeF().isEmpty()); +} + +void tst_QGraphicsVideoItem::boundingRect_data() +{ + QTest::addColumn("frameSize"); + QTest::addColumn("offset"); + QTest::addColumn("size"); + QTest::addColumn("aspectRatioMode"); + QTest::addColumn("expectedRect"); + + + QTest::newRow("640x480: (0,0 640x480), Keep") + << QSize(640, 480) + << QPointF(0, 0) + << QSizeF(640, 480) + << Qt::KeepAspectRatio + << QRectF(0, 0, 640, 480); + + QTest::newRow("800x600, (0,0, 640x480), Keep") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(640, 480) + << Qt::KeepAspectRatio + << QRectF(0, 0, 640, 480); + + QTest::newRow("800x600, (0,0, 640x480), KeepByExpanding") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(640, 480) + << Qt::KeepAspectRatioByExpanding + << QRectF(0, 0, 640, 480); + + QTest::newRow("800x600, (0,0, 640x480), Ignore") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(640, 480) + << Qt::IgnoreAspectRatio + << QRectF(0, 0, 640, 480); + + QTest::newRow("800x600, (100,100, 640x480), Keep") + << QSize(800, 600) + << QPointF(100, 100) + << QSizeF(640, 480) + << Qt::KeepAspectRatio + << QRectF(100, 100, 640, 480); + + QTest::newRow("800x600, (100,-100, 640x480), KeepByExpanding") + << QSize(800, 600) + << QPointF(100, -100) + << QSizeF(640, 480) + << Qt::KeepAspectRatioByExpanding + << QRectF(100, -100, 640, 480); + + QTest::newRow("800x600, (-100,-100, 640x480), Ignore") + << QSize(800, 600) + << QPointF(-100, -100) + << QSizeF(640, 480) + << Qt::IgnoreAspectRatio + << QRectF(-100, -100, 640, 480); + + QTest::newRow("800x600, (0,0, 1920x1024), Keep") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(1920, 1024) + << Qt::KeepAspectRatio + << QRectF(832.0 / 3, 0, 4096.0 / 3, 1024); + + QTest::newRow("800x600, (0,0, 1920x1024), KeepByExpanding") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(1920, 1024) + << Qt::KeepAspectRatioByExpanding + << QRectF(0, 0, 1920, 1024); + + QTest::newRow("800x600, (0,0, 1920x1024), Ignore") + << QSize(800, 600) + << QPointF(0, 0) + << QSizeF(1920, 1024) + << Qt::IgnoreAspectRatio + << QRectF(0, 0, 1920, 1024); + + QTest::newRow("800x600, (100,100, 1920x1024), Keep") + << QSize(800, 600) + << QPointF(100, 100) + << QSizeF(1920, 1024) + << Qt::KeepAspectRatio + << QRectF(100 + 832.0 / 3, 100, 4096.0 / 3, 1024); + + QTest::newRow("800x600, (100,-100, 1920x1024), KeepByExpanding") + << QSize(800, 600) + << QPointF(100, -100) + << QSizeF(1920, 1024) + << Qt::KeepAspectRatioByExpanding + << QRectF(100, -100, 1920, 1024); + + QTest::newRow("800x600, (-100,-100, 1920x1024), Ignore") + << QSize(800, 600) + << QPointF(-100, -100) + << QSizeF(1920, 1024) + << Qt::IgnoreAspectRatio + << QRectF(-100, -100, 1920, 1024); +} + +void tst_QGraphicsVideoItem::boundingRect() +{ + QFETCH(QSize, frameSize); + QFETCH(QPointF, offset); + QFETCH(QSizeF, size); + QFETCH(Qt::AspectRatioMode, aspectRatioMode); + QFETCH(QRectF, expectedRect); + + QtTestVideoObject object(new QtTestRendererControl); + QGraphicsVideoItem item; + object.bind(&item); + + item.setOffset(offset); + item.setSize(size); + item.setAspectRatioMode(aspectRatioMode); + + QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); + + { // Surface setup is deferred until after the first paint. + QImage image(320, 240, QImage::Format_RGB32); + QPainter painter(&image); + + item.paint(&painter, 0); + } + QVERIFY(object.testService->rendererControl->surface() != 0); + QVERIFY(object.testService->rendererControl->surface()->start(format)); + + QCoreApplication::processEvents(); + QCOMPARE(item.boundingRect(), expectedRect); +} + +static const uchar rgb32ImageData[] = +{ + 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 +}; + +void tst_QGraphicsVideoItem::paint() +{ + QtTestVideoObject object(new QtTestRendererControl); + QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; + object.bind(item); + + QGraphicsScene graphicsScene; + graphicsScene.addItem(item); + QGraphicsView graphicsView(&graphicsScene); + graphicsView.show(); + QVERIFY(item->waitForPaint(1)); + + QPainterVideoSurface *surface = qobject_cast( + object.testService->rendererControl->surface()); + if (!surface) + QSKIP("QGraphicsVideoItem is not QPainterVideoSurface based", SkipAll); + + QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); + + QVERIFY(surface->start(format)); + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); + + QVERIFY(item->waitForPaint(1)); + + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); + + QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); + + frame.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frame.bits(), rgb32ImageData, frame.mappedBytes()); + frame.unmap(); + + QVERIFY(surface->present(frame)); + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), false); + + QVERIFY(item->waitForPaint(1)); + + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); +} + + +QTEST_MAIN(tst_QGraphicsVideoItem) + +#include "tst_qgraphicsvideoitem.moc" diff --git a/tests/auto/unit/qmediabindableinterface/qmediabindableinterface.pro b/tests/auto/unit/qmediabindableinterface/qmediabindableinterface.pro new file mode 100644 index 000000000..366a4e6f0 --- /dev/null +++ b/tests/auto/unit/qmediabindableinterface/qmediabindableinterface.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qmediabindableinterface + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += \ + tst_qmediabindableinterface.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockrecorder.pri) diff --git a/tests/auto/unit/qmediabindableinterface/tst_qmediabindableinterface.cpp b/tests/auto/unit/qmediabindableinterface/tst_qmediabindableinterface.cpp new file mode 100644 index 000000000..d7f06db8a --- /dev/null +++ b/tests/auto/unit/qmediabindableinterface/tst_qmediabindableinterface.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mockmediacontainercontrol.h" +#include "mockmetadatawritercontrol.h" +#include "mockmediarecordercontrol.h" +#include "mockmediaobject.h" + +QT_USE_NAMESPACE + +class TestBindableService : public QMediaService +{ + Q_OBJECT +public: + TestBindableService(QObject *parent, QMediaControl *control): + QMediaService(parent), + mockControl(control), + hasControls(true) + { + mockContainerControl = new MockMediaContainerControl(parent); //Creating the object for Media + mockMetaDataControl = new MockMetaDataWriterControl(parent); //Creating the object for MetaData + } + + QMediaControl* requestControl(const char *name) + { + if (hasControls && qstrcmp(name,QMediaRecorderControl_iid) == 0) + return mockControl; + if (hasControls && qstrcmp(name,QMediaContainerControl_iid) == 0) + return mockContainerControl; + if (hasControls && qstrcmp(name, QMetaDataWriterControl_iid) == 0) + return mockMetaDataControl; + + return 0; + } + + void releaseControl(QMediaControl*) {} + //Initialising the objects for the media + QMediaControl *mockControl; + QMediaContainerControl *mockContainerControl; + MockMetaDataWriterControl *mockMetaDataControl; + bool hasControls; +}; + +class tst_QMediaBindableInterface:public QObject +{ + Q_OBJECT +private slots: + void init() + { + + } + + void cleanup() + { + + } + + void testMediaObject() //Verifying the mediaobject api + { + MockMediaRecorderControl recorderControl(0); + TestBindableService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QMediaObject *obj = recorder.mediaObject(); + QVERIFY(obj != NULL); + QVERIFY(obj->isAvailable()); + } + + void testDestructor() //Invoking the destructor + { + MockMediaRecorderControl recorderControl(0); + TestBindableService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + MockMediaObject object(0, &service); + QMediaRecorder *recorder = new QMediaRecorder(&object); + QVERIFY(recorder->isAvailable()); + delete recorder; + recorder = NULL; + } +}; + +QTEST_MAIN(tst_QMediaBindableInterface) +#include "tst_qmediabindableinterface.moc" diff --git a/tests/auto/unit/qmediacontainercontrol/qmediacontainercontrol.pro b/tests/auto/unit/qmediacontainercontrol/qmediacontainercontrol.pro new file mode 100644 index 000000000..90dcbf82e --- /dev/null +++ b/tests/auto/unit/qmediacontainercontrol/qmediacontainercontrol.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qmediacontainercontrol + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediacontainercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) + diff --git a/tests/auto/unit/qmediacontainercontrol/tst_qmediacontainercontrol.cpp b/tests/auto/unit/qmediacontainercontrol/tst_qmediacontainercontrol.cpp new file mode 100644 index 000000000..e5dabd12d --- /dev/null +++ b/tests/auto/unit/qmediacontainercontrol/tst_qmediacontainercontrol.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include "qmediacontainercontrol.h" +#include "qmediarecorder.h" + +#include "../qmultimedia_common/mockmediacontainercontrol.h" + +//MaemoAPI- +class tst_QMediaContainerControl :public QObject +{ + Q_OBJECT + +private slots: + //to test the constructor + void tst_mediacontainercontrol() + { + + QObject obj; + MockMediaContainerControl control(&obj); + QStringList strlist=control.supportedContainers(); + QStringList strlist1; + strlist1 << "wav" << "mp3" << "mov"; + QVERIFY(strlist[0]==strlist1[0]); //checking with "wav" mime type + QVERIFY(strlist[1]==strlist1[1]); //checking with "mp3" mime type + QVERIFY(strlist[2]==strlist1[2]); //checking with "mov" mime type + + control.setContainerMimeType("wav"); + const QString str("wav"); + QVERIFY2(control.containerMimeType() == str,"Failed"); + + const QString str1("WAV format"); + QVERIFY2(control.containerDescription("wav") == str1,"FAILED"); + } +}; + +QTEST_MAIN(tst_QMediaContainerControl); +#include "tst_qmediacontainercontrol.moc" diff --git a/tests/auto/unit/qmediacontent/qmediacontent.pro b/tests/auto/unit/qmediacontent/qmediacontent.pro new file mode 100644 index 000000000..d55218dd5 --- /dev/null +++ b/tests/auto/unit/qmediacontent/qmediacontent.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TARGET = tst_qmediacontent + +QT += multimedia-private network testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediacontent.cpp diff --git a/tests/auto/unit/qmediacontent/tst_qmediacontent.cpp b/tests/auto/unit/qmediacontent/tst_qmediacontent.cpp new file mode 100644 index 000000000..a215b479c --- /dev/null +++ b/tests/auto/unit/qmediacontent/tst_qmediacontent.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +//TESTED_COMPONENT=src/multimedia + +QT_USE_NAMESPACE +class tst_QMediaContent : public QObject +{ + Q_OBJECT + +private slots: + void testNull(); + void testUrlCtor(); + void testRequestCtor(); + void testResourceCtor(); + void testResourceListCtor(); + void testCopy(); + void testAssignment(); + void testEquality(); + void testResources(); +}; + +void tst_QMediaContent::testNull() +{ + QMediaContent media; + + QCOMPARE(media.isNull(), true); + QCOMPARE(media.canonicalUrl(), QUrl()); + QCOMPARE(media.canonicalResource(), QMediaResource()); + QCOMPARE(media.resources(), QMediaResourceList()); +} + +void tst_QMediaContent::testUrlCtor() +{ + QMediaContent media(QUrl("http://example.com/movie.mov")); + + QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); + QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); +} + +void tst_QMediaContent::testRequestCtor() +{ + QNetworkRequest request(QUrl("http://example.com/movie.mov")); + request.setAttribute(QNetworkRequest::User, QVariant(1234)); + + QMediaContent media(request); + + QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); + QCOMPARE(media.canonicalRequest(),request); + QCOMPARE(media.canonicalResource().request(), request); + QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); +} + +void tst_QMediaContent::testResourceCtor() +{ + QMediaContent media(QMediaResource(QUrl("http://example.com/movie.mov"))); + + QCOMPARE(media.canonicalResource(), QMediaResource(QUrl("http://example.com/movie.mov"))); +} + +void tst_QMediaContent::testResourceListCtor() +{ + QMediaResourceList resourceList; + resourceList << QMediaResource(QUrl("http://example.com/movie.mov")); + + QMediaContent media(resourceList); + + QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); + QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); +} + +void tst_QMediaContent::testCopy() +{ + QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov"))); + QMediaContent media2(media1); + + QVERIFY(media1 == media2); +} + +void tst_QMediaContent::testAssignment() +{ + QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov"))); + QMediaContent media2; + QMediaContent media3; + + media2 = media1; + QVERIFY(media2 == media1); + + media2 = media3; + QVERIFY(media2 == media3); +} + +void tst_QMediaContent::testEquality() +{ + QMediaContent media1; + QMediaContent media2; + QMediaContent media3(QMediaResource(QUrl("http://example.com/movie.mov"))); + QMediaContent media4(QMediaResource(QUrl("http://example.com/movie.mov"))); + QMediaContent media5(QMediaResource(QUrl("file:///some/where/over/the/rainbow.mp3"))); + + // null == null + QCOMPARE(media1 == media2, true); + QCOMPARE(media1 != media2, false); + + // null != something + QCOMPARE(media1 == media3, false); + QCOMPARE(media1 != media3, true); + + // equiv + QCOMPARE(media3 == media4, true); + QCOMPARE(media3 != media4, false); + + // not equiv + QCOMPARE(media4 == media5, false); + QCOMPARE(media4 != media5, true); +} + +void tst_QMediaContent::testResources() +{ + QMediaResourceList resourceList; + + resourceList << QMediaResource(QUrl("http://example.com/movie-main.mov")); + resourceList << QMediaResource(QUrl("http://example.com/movie-big.mov")); + QMediaContent media(resourceList); + + QMediaResourceList res = media.resources(); + QCOMPARE(res.size(), 2); + QCOMPARE(res[0], QMediaResource(QUrl("http://example.com/movie-main.mov"))); + QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov"))); +} + +QTEST_MAIN(tst_QMediaContent) + +#include "tst_qmediacontent.moc" diff --git a/tests/auto/unit/qmediaimageviewer/images.qrc b/tests/auto/unit/qmediaimageviewer/images.qrc new file mode 100644 index 000000000..508de1369 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewer/images.qrc @@ -0,0 +1,9 @@ + + + images/coverart.png + images/image.jpg + images/image.png + images/invalid.png + images/poster.png + + diff --git a/tests/auto/unit/qmediaimageviewer/images/coverart.png b/tests/auto/unit/qmediaimageviewer/images/coverart.png new file mode 100644 index 000000000..a24db1b13 Binary files /dev/null and b/tests/auto/unit/qmediaimageviewer/images/coverart.png differ diff --git a/tests/auto/unit/qmediaimageviewer/images/image.jpg b/tests/auto/unit/qmediaimageviewer/images/image.jpg new file mode 100644 index 000000000..8771224cb Binary files /dev/null and b/tests/auto/unit/qmediaimageviewer/images/image.jpg differ diff --git a/tests/auto/unit/qmediaimageviewer/images/image.png b/tests/auto/unit/qmediaimageviewer/images/image.png new file mode 100644 index 000000000..a24db1b13 Binary files /dev/null and b/tests/auto/unit/qmediaimageviewer/images/image.png differ diff --git a/tests/auto/unit/qmediaimageviewer/images/invalid.png b/tests/auto/unit/qmediaimageviewer/images/invalid.png new file mode 100644 index 000000000..3aba327ee --- /dev/null +++ b/tests/auto/unit/qmediaimageviewer/images/invalid.png @@ -0,0 +1,2 @@ +This is not really a PNG file. + diff --git a/tests/auto/unit/qmediaimageviewer/images/poster.png b/tests/auto/unit/qmediaimageviewer/images/poster.png new file mode 100644 index 000000000..a24db1b13 Binary files /dev/null and b/tests/auto/unit/qmediaimageviewer/images/poster.png differ diff --git a/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro b/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro new file mode 100644 index 000000000..4724f6141 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewer/qmediaimageviewer.pro @@ -0,0 +1,16 @@ +CONFIG += testcase +TARGET = tst_qmediaimageviewer + +QT += multimedia-private network testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaimageviewer.cpp + +RESOURCES += \ + images.qrc + +!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG + +wince* { + !contains(QT_CONFIG, no-jpeg): DEPLOYMENT_PLUGIN += qjpeg +} diff --git a/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp b/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp new file mode 100644 index 000000000..00cfe8549 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewer/tst_qmediaimageviewer.cpp @@ -0,0 +1,1044 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +QT_USE_NAMESPACE +class QtTestNetworkAccessManager; + +class tst_QMediaImageViewer : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + + void isValid(); + void timeout(); + void setMedia_data(); + void setMedia(); + void setConsecutiveMedia(); + void setInvalidMedia(); + void playlist(); + void multiplePlaylists(); + void invalidPlaylist(); + void elapsedTime(); + void rendererControl(); + void setVideoOutput(); + void debugEnums(); + + void mediaChanged_signal(); + +public: + tst_QMediaImageViewer() : m_network(0) {} + +private: + QUrl imageUrl(const char *fileName) const { + return QUrl(QLatin1String("qrc:///images/") + QLatin1String(fileName)); } + QString imageFileName(const char *fileName) { + return QLatin1String(":/images/") + QLatin1String(fileName); } + + QtTestNetworkAccessManager *m_network; + QString m_fileProtocol; +}; + +class QtTestVideoSurface : public QAbstractVideoSurface +{ +public: + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const { + QList formats; + if (handleType == QAbstractVideoBuffer::NoHandle) { + formats << QVideoFrame::Format_RGB32; + } + return formats; + } + + QVideoFrame frame() const { return m_frame; } + + bool present(const QVideoFrame &frame) { m_frame = frame; return true; } + +private: + QVideoFrame m_frame; +}; + +class QtTestNetworkReply : public QNetworkReply +{ +public: + QtTestNetworkReply( + const QNetworkRequest &request, + const QByteArray &mimeType, + QObject *parent) + : QNetworkReply(parent) + { + setRequest(request); + setOperation(QNetworkAccessManager::HeadOperation); + setRawHeader("content-type", mimeType); + + QCoreApplication::postEvent(this, new QEvent(QEvent::User)); + } + + QtTestNetworkReply( + const QNetworkRequest &request, + const QByteArray &mimeType, + const QString &fileName, + QObject *parent) + : QNetworkReply(parent) + , m_file(fileName) + { + setRequest(request); + setOperation(QNetworkAccessManager::GetOperation); + setRawHeader("content-type", mimeType); + + if (m_file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { + setOpenMode(QIODevice::ReadOnly); + } + + QCoreApplication::postEvent(this, new QEvent(QEvent::User)); + } + + void abort() { m_file.close(); } + + bool atEnd () const { return m_file.atEnd(); } + qint64 bytesAvailable() const { return m_file.bytesAvailable() + QIODevice::bytesAvailable(); } + void close() { m_file.close(); setOpenMode(QIODevice::NotOpen); } + bool isSequential() const { return true; } + bool open(OpenMode) { return false; } + qint64 pos() const { return 0; } + bool seek(qint64) { return false; } + qint64 size() const { return m_file.size(); } + qint64 readData(char * data, qint64 maxSize) { return m_file.read(data, maxSize); } + qint64 writeData(const char *, qint64) { return -1; } + +protected: + void customEvent(QEvent *event) + { + if (event->type() == QEvent::User) { + event->accept(); + emit finished(); + } + } + +private: + QFile m_file; +}; + +class QtTestNetworkAccessManager : public QNetworkAccessManager +{ +public: + QtTestNetworkAccessManager(QObject *parent = 0) + : QNetworkAccessManager(parent) + { + } + + void appendDocument(const QUrl &url, const QByteArray &mimeType, const QString &fileName) + { + m_documents.append(Document(url, mimeType, fileName)); + } + +protected: + QNetworkReply *createRequest( + Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) + { + foreach (const Document &document, m_documents) { + if (document.url == request.url()) { + if (op == GetOperation) { + return new QtTestNetworkReply( + request, document.mimeType, document.fileName, this); + } else if (op == HeadOperation) { + return new QtTestNetworkReply(request, document.mimeType, this); + } + } + } + return QNetworkAccessManager::createRequest(op, request, outgoingData); + } + +private: + struct Document + { + Document(const QUrl url, const QByteArray mimeType, const QString &fileName) + : url(url), mimeType(mimeType), fileName(fileName) + { + } + + QUrl url; + QByteArray mimeType; + QString fileName; + }; + + QList m_documents; +}; + +void tst_QMediaImageViewer::initTestCase() +{ + qRegisterMetaType(); + qRegisterMetaType(); + + m_network = new QtTestNetworkAccessManager(this); + + m_network->appendDocument( + QUrl(QLatin1String("test://image/png?id=1")), + "image/png", + imageFileName("image.png")); + m_network->appendDocument( + QUrl(QLatin1String("test://image/png?id=2")), + QByteArray(), + imageFileName("image.png")); + m_network->appendDocument( + QUrl(QLatin1String("test://image/invalid?id=1")), + "image/png", + imageFileName("invalid.png")); + m_network->appendDocument( + QUrl(QLatin1String("test://image/invalid?id=2")), + QByteArray(), + imageFileName("invalid.png")); +#ifdef QTEST_HAVE_JPEG + m_network->appendDocument( + QUrl(QLatin1String("test://image/jpeg?id=1")), + "image/jpeg", + imageFileName("image.jpg")); +#endif + m_network->appendDocument( + QUrl(QLatin1String("test://music/songs/mp3?id=1")), + "audio/mpeg", + QString()); + m_network->appendDocument( + QUrl(QLatin1String("test://music/covers/small?id=1")), + "image/png", + imageFileName("coverart.png")); + m_network->appendDocument( + QUrl(QLatin1String("test://music/covers/large?id=1")), + "image/png", + imageFileName("coverart.png")); + m_network->appendDocument( + QUrl(QLatin1String("test://video/movies/mp4?id=1")), + "video/mp4", + QString()); + m_network->appendDocument( + QUrl(QLatin1String("test://video/posters/png?id=1")), + "image/png", + imageFileName("poster.png")); +} + +void tst_QMediaImageViewer::isValid() +{ + QMediaImageViewer viewer; + + QVERIFY(viewer.service() != 0); +} + +void tst_QMediaImageViewer::timeout() +{ + QMediaImageViewer viewer; + + QCOMPARE(viewer.timeout(), 3000); + + viewer.setTimeout(0); + QCOMPARE(viewer.timeout(), 0); + + viewer.setTimeout(45); + QCOMPARE(viewer.timeout(), 45); + + viewer.setTimeout(-3000); + QCOMPARE(viewer.timeout(), 0); +} + +void tst_QMediaImageViewer::setMedia_data() +{ + QTest::addColumn("media"); + + { + QMediaContent media(imageUrl("image.png")); + + QTest::newRow("file: png image") + << media; + } { + QMediaContent media(QUrl(QLatin1String("test://image/png?id=1"))); + + QTest::newRow("network: png image") + << media; + } { + QMediaContent media(QMediaResource( + QUrl(QLatin1String("test://image/png?id=1")), QLatin1String("image/png"))); + + QTest::newRow("network: png image, explicit mime type") + << media; + } { + QMediaContent media(QUrl(QLatin1String("test://image/png?id=2"))); + + QTest::newRow("network: png image, no mime type") + << media; +#ifdef QTEST_HAVE_JPEG + } { + QMediaContent media(imageUrl("image.jpg")); + + QTest::newRow("file: jpg image") + << media; + } { + QMediaContent media(QUrl(QLatin1String("test://image/jpeg?id=1"))); + + QTest::newRow("network: jpg image") + << media; +#endif + } +} + +void tst_QMediaImageViewer::setMedia() +{ + QFETCH(QMediaContent, media); + + QMediaImageViewer viewer; + + QMediaImageViewerService *service = qobject_cast(viewer.service()); + service->setNetworkManager(m_network); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + viewer.setMedia(media); + QCOMPARE(viewer.media(), media); + + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); +} + +void tst_QMediaImageViewer::setConsecutiveMedia() +{ + QMediaContent fileMedia1(imageUrl("image.png")); + QMediaContent fileMedia2(imageUrl("coverart.png")); + QMediaContent networkMedia1(QUrl(QLatin1String("test://image/png?id=1"))); + QMediaContent networkMedia2(QUrl(QLatin1String("test://image/png?id=2"))); + + QMediaImageViewer viewer; + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + viewer.setMedia(fileMedia1); + viewer.setMedia(fileMedia2); + + QCOMPARE(viewer.media(), fileMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), fileMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + QMediaImageViewerService *service = qobject_cast(viewer.service()); + service->setNetworkManager(m_network); + + viewer.setMedia(networkMedia2); + viewer.setMedia(networkMedia1); + + QCOMPARE(viewer.media(), networkMedia1); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), networkMedia1); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + viewer.setMedia(fileMedia1); + viewer.setMedia(networkMedia2); + + QCOMPARE(viewer.media(), networkMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), networkMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + viewer.setMedia(fileMedia1); + viewer.setMedia(networkMedia2); + + QCOMPARE(viewer.media(), networkMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), networkMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + viewer.setMedia(networkMedia1); + viewer.setMedia(fileMedia2); + + QCOMPARE(viewer.media(), fileMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.media(), fileMedia2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); +} + +void tst_QMediaImageViewer::setInvalidMedia() +{ + QMediaImageViewer viewer; + viewer.setTimeout(250); + + QMediaImageViewerService *service = qobject_cast(viewer.service()); + service->setNetworkManager(m_network); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + { + QMediaContent media(imageUrl("invalid.png")); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaContent media(imageUrl("deleted.png")); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaResource invalidResource(imageUrl("invalid.png")); + QMediaResource deletedResource(imageUrl("deleted.png")); + QMediaContent media(QMediaResourceList() << invalidResource << deletedResource); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaResource resource(imageUrl("image.png"), QLatin1String("audio/mpeg")); + QMediaContent media(resource); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaResource audioResource(imageUrl("image.png"), QLatin1String("audio/mpeg")); + QMediaResource invalidResource(imageUrl("invalid.png")); + QMediaContent media(QMediaResourceList() << audioResource << invalidResource); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=1"))); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=2"))); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } { + QMediaContent media(QUrl(QLatin1String("test://image/invalid?id=3"))); + + viewer.setMedia(media); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::InvalidMedia); + QCOMPARE(viewer.media(), media); + } +} + +void tst_QMediaImageViewer::playlist() +{ + QMediaContent imageMedia(imageUrl("image.png")); + QMediaContent posterMedia(imageUrl("poster.png")); + QMediaContent coverArtMedia(imageUrl("coverart.png")); + + QMediaImageViewer viewer; + viewer.setTimeout(250); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + QSignalSpy stateSpy(&viewer, SIGNAL(stateChanged(QMediaImageViewer::State))); + + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + + // No playlist so can't exit stopped state. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 0); + viewer.pause(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 0); + + QMediaPlaylist playlist; + viewer.setPlaylist(&playlist); + + // Empty playlist so can't exit stopped state. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 0); + viewer.pause(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 0); + + playlist.addMedia(imageMedia); + playlist.addMedia(posterMedia); + playlist.addMedia(coverArtMedia); + + // Play progresses immediately to the first image and starts loading. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(stateSpy.count(), 1); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(viewer.media(), imageMedia); + + // Image is loaded asynchronously. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 0); + + // Time out causes progression to second image, which starts loading. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(playlist.currentIndex(), 1); + QCOMPARE(viewer.media(), posterMedia); + + // Image is loaded asynchronously. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 1); + + // Pausing stops progression at current image. + viewer.pause(); + QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); + QCOMPARE(stateSpy.count(), 2); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::PausedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 1); + + // No time out. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 1); + + // Resuming playback does not immediately progress to the next item + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 1); + + // Time out causes progression to next image, which starts loading. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(playlist.currentIndex(), 2); + QCOMPARE(viewer.media(), coverArtMedia); + + // Image is loaded asynchronously. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 2); + + // Time out causes progression to end of list + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 4); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::StoppedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(viewer.media(), QMediaContent()); + + // Stopped, no time out. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); + QCOMPARE(playlist.currentIndex(), -1); + + // Play progresses immediately to the first image and starts loading. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(stateSpy.count(), 5); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(viewer.media(), imageMedia); + + // Image is loaded asynchronously. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 0); + + // Stop ends progress, but retains current index. + viewer.stop(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 6); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::StoppedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(viewer.media(), imageMedia); + + // Stoppped, No time out. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(viewer.media(), imageMedia); + + // Stop when already stopped doesn't emit additional signals. + viewer.stop(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 6); + + viewer.play(); + QCOMPARE(stateSpy.count(), 7); + + // Play when already playing doesn't emit additional signals. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(stateSpy.count(), 7); + + playlist.next(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + // Pausing while loading, doesn't stop loading. + viewer.pause(); + QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); + QCOMPARE(stateSpy.count(), 8); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadedMedia); + + // Pause while paused doesn't emit additional signals. + viewer.pause(); + QCOMPARE(viewer.state(), QMediaImageViewer::PausedState); + QCOMPARE(stateSpy.count(), 8); + + // Calling setMedia stops the playlist. + viewer.setMedia(imageMedia); + QCOMPARE(viewer.media(), imageMedia); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(stateSpy.count(), 9); + QCOMPARE(qvariant_cast(stateSpy.last().value(0)), + QMediaImageViewer::StoppedState); + +} + +void tst_QMediaImageViewer::multiplePlaylists() +{ + QMediaContent imageMedia(imageUrl("image.png")); + QMediaContent posterMedia(imageUrl("poster.png")); + QMediaContent coverArtMedia(imageUrl("coverart.png")); + + QMediaImageViewer viewer; + + QMediaPlaylist *playlist1 = new QMediaPlaylist; + viewer.setPlaylist(playlist1); + playlist1->addMedia(imageMedia); + playlist1->addMedia(posterMedia); + + playlist1->setCurrentIndex(0); + QCOMPARE(viewer.media(), imageMedia); + + QMediaPlaylist *playlist2 = new QMediaPlaylist; + + viewer.setPlaylist(playlist2); + playlist2->addMedia(coverArtMedia); + + QVERIFY(viewer.media().isNull()); + + playlist2->setCurrentIndex(0); + QCOMPARE(viewer.media(), coverArtMedia); + + delete playlist2; + QVERIFY(viewer.media().isNull()); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + + viewer.setPlaylist(playlist1); + playlist1->setCurrentIndex(0); + QCOMPARE(viewer.media(), imageMedia); + + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + + delete playlist1; + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); +} + + +void tst_QMediaImageViewer::invalidPlaylist() +{ + QMediaContent imageMedia(imageUrl("image.png")); + QMediaContent invalidMedia(imageUrl("invalid.png")); + + QMediaImageViewer viewer; + viewer.setTimeout(250); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + QSignalSpy stateSpy(&viewer, SIGNAL(stateChanged(QMediaImageViewer::State))); + QSignalSpy statusSpy(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus))); + + QMediaPlaylist playlist; + viewer.setPlaylist(&playlist); + playlist.addMedia(invalidMedia); + playlist.addMedia(imageMedia); + playlist.addMedia(invalidMedia); + + // Test play initially tries to load the first invalid image. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(viewer.media(), invalidMedia); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(statusSpy.count(), 1); + QCOMPARE(qvariant_cast(statusSpy.value(0).value(0)), + QMediaImageViewer::LoadingMedia); + + // Test status is changed to InvalidMedia, and loading of the next image is started immediately. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::LoadingMedia); + QCOMPARE(viewer.media(), imageMedia); + QCOMPARE(playlist.currentIndex(), 1); + QCOMPARE(statusSpy.count(), 3); + QCOMPARE(qvariant_cast(statusSpy.value(1).value(0)), + QMediaImageViewer::InvalidMedia); + QCOMPARE(qvariant_cast(statusSpy.value(2).value(0)), + QMediaImageViewer::LoadingMedia); + + // Test if the last image is invalid, the image viewer is stopped. + playlist.next(); + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(stateSpy.count(), 2); + + playlist.setCurrentIndex(2); + QTestEventLoop::instance().enterLoop(2); + + // Test play immediately moves to the next item if the current one is invalid, and no state + // change signals are emitted if the viewer never effectively moves from the StoppedState. + viewer.play(); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + QCOMPARE(viewer.mediaStatus(), QMediaImageViewer::NoMedia); + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(stateSpy.count(), 2); +} + +void tst_QMediaImageViewer::elapsedTime() +{ + QMediaContent imageMedia(imageUrl("image.png")); + + QMediaImageViewer viewer; + viewer.setTimeout(250); + viewer.setNotifyInterval(150); + + QSignalSpy spy(&viewer, SIGNAL(elapsedTimeChanged(int))); + + connect(&viewer, SIGNAL(elapsedTimeChanged(int)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + + QMediaPlaylist playlist; + viewer.setPlaylist(&playlist); + playlist.addMedia(imageMedia); + + QCOMPARE(viewer.elapsedTime(), 0); + + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(spy.count(), 0); + + viewer.play(); + QCOMPARE(viewer.elapsedTime(), 0); + + // Emits an initial elapsed time at 0 milliseconds signal when the image is loaded. + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().value(0).toInt(), 0); + + // Emits a scheduled signal after the notify interval is up. The exact time will be a little + // fuzzy. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(spy.count(), 2); + QVERIFY(spy.last().value(0).toInt() != 0); + + // Pausing will emit a signal with the elapsed time when paused. + viewer.pause(); + QCOMPARE(spy.count(), 3); + QCOMPARE(viewer.elapsedTime(), spy.last().value(0).toInt()); + + // No elapsed time signals will be emitted while paused. + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(spy.count(), 3); + + // Stopping a paused viewer resets the elapsed time to 0 with signals emitted. + viewer.stop(); + QCOMPARE(viewer.elapsedTime(), 0); + QCOMPARE(spy.count(), 4); + QCOMPARE(spy.last().value(0).toInt(), 0); + + disconnect(&viewer, SIGNAL(elapsedTimeChanged(int)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + // Play until end. + viewer.play(); + QTestEventLoop::instance().enterLoop(2); + + // Verify at least two more signals are emitted. + // The second to last at the instant the timeout expired, and the last as it's reset when the + // current media is cleared. + QVERIFY(spy.count() >= 5); + QCOMPARE(spy.value(spy.count() - 2).value(0).toInt(), 250); + QCOMPARE(spy.value(spy.count() - 1).value(0).toInt(), 0); + + viewer.play(); + QTestEventLoop::instance().enterLoop(2); + + // Test extending the timeout applies to an already loaded image. + viewer.setTimeout(10000); + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::PlayingState); + + // Test reducing the timeout applies to an already loaded image. + viewer.setTimeout(1000); + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(viewer.state(), QMediaImageViewer::StoppedState); + +} + +void tst_QMediaImageViewer::rendererControl() +{ + QtTestVideoSurface surfaceA; + QtTestVideoSurface surfaceB; + QAbstractVideoSurface *nullSurface = 0; + + QMediaImageViewer viewer; + + QMediaService *service = viewer.service(); + if (service == 0) + QSKIP("Image viewer object has no service.", SkipSingle); + + QMediaControl *mediaControl = service->requestControl(QVideoRendererControl_iid); + QVERIFY(mediaControl != 0); + + QVideoRendererControl *rendererControl = qobject_cast(mediaControl); + QVERIFY(rendererControl != 0); + + rendererControl->setSurface(&surfaceA); + QCOMPARE(rendererControl->surface(), (QAbstractVideoSurface *)&surfaceA); + + // Load an image so the viewer has some dimensions to work with. + viewer.setMedia(QMediaContent(imageUrl("image.png"))); + + connect(&viewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(2); + + if (viewer.mediaStatus() != QMediaImageViewer::LoadedMedia) + QSKIP("failed to load test image", SkipSingle); + + QCOMPARE(surfaceA.isActive(), true); + + { + QVideoSurfaceFormat format = surfaceA.surfaceFormat(); + QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(format.frameSize(), QSize(75, 50)); + + QVideoFrame frame = surfaceA.frame(); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(frame.size(), QSize(75, 50)); + } + // Test clearing the output stops the video surface. + service->releaseControl(rendererControl); + QCOMPARE(surfaceA.isActive(), false); + + // Test reseting the output restarts it. + mediaControl = service->requestControl(QVideoRendererControl_iid); + QVERIFY(mediaControl != 0); + + rendererControl = qobject_cast(mediaControl); + rendererControl->setSurface(&surfaceA); + QVERIFY(rendererControl != 0); + { + QVideoSurfaceFormat format = surfaceA.surfaceFormat(); + QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(format.frameSize(), QSize(75, 50)); + + QVideoFrame frame = surfaceA.frame(); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(frame.size(), QSize(75, 50)); + } + + // Test changing the surface while viewing an image stops the old surface and starts + // the new one and presents the image. + rendererControl->setSurface(&surfaceB); + QCOMPARE(rendererControl->surface(), (QAbstractVideoSurface*)&surfaceB); + + QCOMPARE(surfaceA.isActive(), false); + QCOMPARE(surfaceB.isActive(), true); + + QVideoSurfaceFormat format = surfaceB.surfaceFormat(); + QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(format.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(format.frameSize(), QSize(75, 50)); + + QVideoFrame frame = surfaceB.frame(); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_RGB32); + QCOMPARE(frame.size(), QSize(75, 50)); + + // Test setting null media stops the surface. + viewer.setMedia(QMediaContent()); + QCOMPARE(surfaceB.isActive(), false); + + // Test the renderer control accepts a null surface. + rendererControl->setSurface(0); + QCOMPARE(rendererControl->surface(), nullSurface); +} + +void tst_QMediaImageViewer::setVideoOutput() +{ + QMediaImageViewer imageViewer; + imageViewer.setMedia(QMediaContent(imageUrl("image.png"))); + + connect(&imageViewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(2); + + if (imageViewer.mediaStatus() != QMediaImageViewer::LoadedMedia) + QSKIP("failed to load test image", SkipSingle); + + QtTestVideoSurface surface; + + imageViewer.setVideoOutput(reinterpret_cast(0)); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + QVERIFY(!surface.isActive()); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + QVERIFY(!surface.isActive()); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); +} + +void tst_QMediaImageViewer::debugEnums() +{ + QTest::ignoreMessage(QtDebugMsg, "QMediaImageViewer::PlayingState "); + qDebug() << QMediaImageViewer::PlayingState; + QTest::ignoreMessage(QtDebugMsg, "QMediaImageViewer::NoMedia "); + qDebug() << QMediaImageViewer::NoMedia; +} + +void tst_QMediaImageViewer::mediaChanged_signal() +{ + QMediaContent imageMedia(imageUrl("image.png")); + QMediaImageViewer viewer; + viewer.setTimeout(250); + viewer.setNotifyInterval(150); + + QSignalSpy spy(&viewer, SIGNAL(mediaChanged(QMediaContent))); + QVERIFY(spy.size() == 0); + + viewer.setMedia(imageMedia); + QVERIFY(spy.size() == 1); +} + +QTEST_MAIN(tst_QMediaImageViewer) + +#include "tst_qmediaimageviewer.moc" diff --git a/tests/auto/unit/qmediaimageviewerwidgets/images.qrc b/tests/auto/unit/qmediaimageviewerwidgets/images.qrc new file mode 100644 index 000000000..1d4edce17 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewerwidgets/images.qrc @@ -0,0 +1,5 @@ + + + images/image.png + + diff --git a/tests/auto/unit/qmediaimageviewerwidgets/images/image.png b/tests/auto/unit/qmediaimageviewerwidgets/images/image.png new file mode 100644 index 000000000..a24db1b13 Binary files /dev/null and b/tests/auto/unit/qmediaimageviewerwidgets/images/image.png differ diff --git a/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro b/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro new file mode 100644 index 000000000..a37ae8832 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewerwidgets/qmediaimageviewerwidgets.pro @@ -0,0 +1,17 @@ +CONFIG += testcase +TARGET = tst_qmediaimageviewerwidgets + +QT += multimedia-private multimediawidgets-private network testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaimageviewerwidgets.cpp + +RESOURCES += \ + images.qrc + +!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG + +wince* { + !contains(QT_CONFIG, no-jpeg): DEPLOYMENT_PLUGIN += qjpeg +} +QT+=widgets diff --git a/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp b/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp new file mode 100644 index 000000000..80c745fe0 --- /dev/null +++ b/tests/auto/unit/qmediaimageviewerwidgets/tst_qmediaimageviewerwidgets.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +QT_USE_NAMESPACE + +class tst_QMediaImageViewerWidgets : public QObject +{ + Q_OBJECT +private slots: + void setVideoOutput(); +}; + +class QtTestVideoSurface : public QAbstractVideoSurface +{ +public: + QList supportedPixelFormats( + QAbstractVideoBuffer::HandleType handleType) const { + QList formats; + if (handleType == QAbstractVideoBuffer::NoHandle) { + formats << QVideoFrame::Format_RGB32; + } + return formats; + } + + QVideoFrame frame() const { return m_frame; } + + bool present(const QVideoFrame &frame) { m_frame = frame; return true; } + +private: + QVideoFrame m_frame; +}; + +void tst_QMediaImageViewerWidgets::setVideoOutput() +{ + QMediaImageViewer imageViewer; + imageViewer.setMedia(QMediaContent(QUrl("qrc:///images/image.png"))); + + connect(&imageViewer, SIGNAL(mediaStatusChanged(QMediaImageViewer::MediaStatus)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(2); + + if (imageViewer.mediaStatus() != QMediaImageViewer::LoadedMedia) + QSKIP("failed to load test image", SkipSingle); + + QVideoWidget widget; + QGraphicsVideoItem item; + QtTestVideoSurface surface; + + imageViewer.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == &imageViewer); + + imageViewer.setVideoOutput(&item); + QVERIFY(widget.mediaObject() == 0); + QVERIFY(item.mediaObject() == &imageViewer); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + QVERIFY(item.mediaObject() == 0); + + imageViewer.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == &imageViewer); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + QVERIFY(widget.mediaObject() == 0); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); + + imageViewer.setVideoOutput(reinterpret_cast(0)); + QVERIFY(!surface.isActive()); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); + + imageViewer.setVideoOutput(&widget); + QVERIFY(!surface.isActive()); + QVERIFY(widget.mediaObject() == &imageViewer); + + imageViewer.setVideoOutput(&surface); + QVERIFY(surface.isActive()); + QVERIFY(widget.mediaObject() == 0); +} + +QTEST_MAIN(tst_QMediaImageViewerWidgets) + +#include "tst_qmediaimageviewerwidgets.moc" diff --git a/tests/auto/unit/qmediaobject/main.cpp b/tests/auto/unit/qmediaobject/main.cpp new file mode 100644 index 000000000..5e822768d --- /dev/null +++ b/tests/auto/unit/qmediaobject/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qmediaobject.h" + +int main(int argc, char**argv) +{ + QCoreApplication app(argc,argv); + int ret; + tst_QMediaObject test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qmediaobject/qmediaobject.pro b/tests/auto/unit/qmediaobject/qmediaobject.pro new file mode 100644 index 000000000..01ee43e04 --- /dev/null +++ b/tests/auto/unit/qmediaobject/qmediaobject.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qmediaobject + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +include (../qmultimedia_common/mockrecorder.pri) + +HEADERS+= tst_qmediaobject.h +SOURCES += main.cpp tst_qmediaobject.cpp + diff --git a/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp new file mode 100644 index 000000000..dde293634 --- /dev/null +++ b/tests/auto/unit/qmediaobject/tst_qmediaobject.cpp @@ -0,0 +1,403 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qmediaobject.h" + +#include "mockmediarecorderservice.h" +#include "mockmediaserviceprovider.h" + +QT_USE_NAMESPACE + +void tst_QMediaObject::propertyWatch() +{ + QtTestMediaObject object; + object.setNotifyInterval(0); + + QEventLoop loop; + connect(&object, SIGNAL(aChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&object, SIGNAL(bChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + connect(&object, SIGNAL(cChanged(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + + QSignalSpy aSpy(&object, SIGNAL(aChanged(int))); + QSignalSpy bSpy(&object, SIGNAL(bChanged(int))); + QSignalSpy cSpy(&object, SIGNAL(cChanged(int))); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(aSpy.count(), 0); + QCOMPARE(bSpy.count(), 0); + QCOMPARE(cSpy.count(), 0); + + int aCount = 0; + int bCount = 0; + int cCount = 0; + + object.addPropertyWatch("a"); + + QTestEventLoop::instance().enterLoop(1); + + QVERIFY(aSpy.count() > aCount); + QCOMPARE(bSpy.count(), 0); + QCOMPARE(cSpy.count(), 0); + QCOMPARE(aSpy.last().value(0).toInt(), 0); + + aCount = aSpy.count(); + + object.setA(54); + object.setB(342); + object.setC(233); + + QTestEventLoop::instance().enterLoop(1); + + QVERIFY(aSpy.count() > aCount); + QCOMPARE(bSpy.count(), 0); + QCOMPARE(cSpy.count(), 0); + QCOMPARE(aSpy.last().value(0).toInt(), 54); + + aCount = aSpy.count(); + + object.addPropertyWatch("b"); + object.addPropertyWatch("d"); + object.removePropertyWatch("e"); + object.setA(43); + object.setB(235); + object.setC(90); + + QTestEventLoop::instance().enterLoop(1); + + QVERIFY(aSpy.count() > aCount); + QVERIFY(bSpy.count() > bCount); + QCOMPARE(cSpy.count(), 0); + QCOMPARE(aSpy.last().value(0).toInt(), 43); + QCOMPARE(bSpy.last().value(0).toInt(), 235); + + aCount = aSpy.count(); + bCount = bSpy.count(); + + object.removePropertyWatch("a"); + object.addPropertyWatch("c"); + object.addPropertyWatch("e"); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(aSpy.count(), aCount); + QVERIFY(bSpy.count() > bCount); + QVERIFY(cSpy.count() > cCount); + QCOMPARE(bSpy.last().value(0).toInt(), 235); + QCOMPARE(cSpy.last().value(0).toInt(), 90); + + bCount = bSpy.count(); + cCount = cSpy.count(); + + object.setA(435); + object.setC(9845); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(aSpy.count(), aCount); + QVERIFY(bSpy.count() > bCount); + QVERIFY(cSpy.count() > cCount); + QCOMPARE(bSpy.last().value(0).toInt(), 235); + QCOMPARE(cSpy.last().value(0).toInt(), 9845); + + bCount = bSpy.count(); + cCount = cSpy.count(); + + object.setA(8432); + object.setB(324); + object.setC(443); + object.removePropertyWatch("c"); + object.removePropertyWatch("d"); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(aSpy.count(), aCount); + QVERIFY(bSpy.count() > bCount); + QCOMPARE(cSpy.count(), cCount); + QCOMPARE(bSpy.last().value(0).toInt(), 324); + QCOMPARE(cSpy.last().value(0).toInt(), 9845); + + bCount = bSpy.count(); + + object.removePropertyWatch("b"); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(aSpy.count(), aCount); + QCOMPARE(bSpy.count(), bCount); + QCOMPARE(cSpy.count(), cCount); +} + +void tst_QMediaObject::setupNotifyTests() +{ + QTest::addColumn("interval"); + QTest::addColumn("count"); + + QTest::newRow("single 750ms") + << 750 + << 1; + QTest::newRow("single 600ms") + << 600 + << 1; + QTest::newRow("x3 300ms") + << 300 + << 3; + QTest::newRow("x5 180ms") + << 180 + << 5; +} + +void tst_QMediaObject::notifySignals_data() +{ + setupNotifyTests(); +} + +void tst_QMediaObject::notifySignals() +{ + QFETCH(int, interval); + QFETCH(int, count); + + QtTestMediaObject object; + object.setNotifyInterval(interval); + object.addPropertyWatch("a"); + + QSignalSpy spy(&object, SIGNAL(aChanged(int))); + + QTestEventLoop::instance().enterLoop(1); + + QCOMPARE(spy.count(), count); +} + +void tst_QMediaObject::notifyInterval_data() +{ + setupNotifyTests(); +} + +void tst_QMediaObject::notifyInterval() +{ + QFETCH(int, interval); + + QtTestMediaObject object; + QSignalSpy spy(&object, SIGNAL(notifyIntervalChanged(int))); + + object.setNotifyInterval(interval); + QCOMPARE(object.notifyInterval(), interval); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().value(0).toInt(), interval); + + object.setNotifyInterval(interval); + QCOMPARE(object.notifyInterval(), interval); + QCOMPARE(spy.count(), 1); +} + +void tst_QMediaObject::nullMetaDataControl() +{ + const QString titleKey(QLatin1String("Title")); + const QString title(QLatin1String("Host of Seraphim")); + + QtTestMetaDataService service; + service.hasMetaData = false; + + QtTestMediaObject object(&service); + + QSignalSpy spy(&object, SIGNAL(metaDataChanged())); + + QCOMPARE(object.isMetaDataAvailable(), false); + + QCOMPARE(object.metaData(QtMultimedia::Title).toString(), QString()); + QCOMPARE(object.extendedMetaData(titleKey).toString(), QString()); + QCOMPARE(object.availableMetaData(), QList()); + QCOMPARE(object.availableExtendedMetaData(), QStringList()); + QCOMPARE(spy.count(), 0); +} + +void tst_QMediaObject::isMetaDataAvailable() +{ + QtTestMetaDataService service; + service.metaData.setMetaDataAvailable(false); + + QtTestMediaObject object(&service); + QCOMPARE(object.isMetaDataAvailable(), false); + + QSignalSpy spy(&object, SIGNAL(metaDataAvailableChanged(bool))); + service.metaData.setMetaDataAvailable(true); + + QCOMPARE(object.isMetaDataAvailable(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), true); + + service.metaData.setMetaDataAvailable(false); + + QCOMPARE(object.isMetaDataAvailable(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.at(1).at(0).toBool(), false); +} + +void tst_QMediaObject::metaDataChanged() +{ + QtTestMetaDataService service; + QtTestMediaObject object(&service); + + QSignalSpy spy(&object, SIGNAL(metaDataChanged())); + + service.metaData.metaDataChanged(); + QCOMPARE(spy.count(), 1); + + service.metaData.metaDataChanged(); + QCOMPARE(spy.count(), 2); +} + +void tst_QMediaObject::metaData_data() +{ + QTest::addColumn("artist"); + QTest::addColumn("title"); + QTest::addColumn("genre"); + + QTest::newRow("") + << QString::fromLatin1("Dead Can Dance") + << QString::fromLatin1("Host of Seraphim") + << QString::fromLatin1("Awesome"); +} + +void tst_QMediaObject::metaData() +{ + QFETCH(QString, artist); + QFETCH(QString, title); + QFETCH(QString, genre); + + QtTestMetaDataService service; + service.metaData.populateMetaData(); + + QtTestMediaObject object(&service); + QVERIFY(object.availableMetaData().isEmpty()); + + service.metaData.m_data.insert(QtMultimedia::AlbumArtist, artist); + service.metaData.m_data.insert(QtMultimedia::Title, title); + service.metaData.m_data.insert(QtMultimedia::Genre, genre); + + QCOMPARE(object.metaData(QtMultimedia::AlbumArtist).toString(), artist); + QCOMPARE(object.metaData(QtMultimedia::Title).toString(), title); + + QList metaDataKeys = object.availableMetaData(); + QCOMPARE(metaDataKeys.size(), 3); + QVERIFY(metaDataKeys.contains(QtMultimedia::AlbumArtist)); + QVERIFY(metaDataKeys.contains(QtMultimedia::Title)); + QVERIFY(metaDataKeys.contains(QtMultimedia::Genre)); +} + +void tst_QMediaObject::extendedMetaData() +{ + QFETCH(QString, artist); + QFETCH(QString, title); + QFETCH(QString, genre); + + QtTestMetaDataService service; + QtTestMediaObject object(&service); + QVERIFY(object.availableExtendedMetaData().isEmpty()); + + service.metaData.m_extendedData.insert(QLatin1String("Artist"), artist); + service.metaData.m_extendedData.insert(QLatin1String("Title"), title); + service.metaData.m_extendedData.insert(QLatin1String("Genre"), genre); + + QCOMPARE(object.extendedMetaData(QLatin1String("Artist")).toString(), artist); + QCOMPARE(object.extendedMetaData(QLatin1String("Title")).toString(), title); + + QStringList extendedKeys = object.availableExtendedMetaData(); + QCOMPARE(extendedKeys.size(), 3); + QVERIFY(extendedKeys.contains(QLatin1String("Artist"))); + QVERIFY(extendedKeys.contains(QLatin1String("Title"))); + QVERIFY(extendedKeys.contains(QLatin1String("Genre"))); +} + +void tst_QMediaObject::availability() +{ + QtTestMediaObject nullObject(0); + QCOMPARE(nullObject.isAvailable(), false); + QCOMPARE(nullObject.availabilityError(), QtMultimedia::ServiceMissingError); + + QtTestMetaDataService service; + QtTestMediaObject object(&service); + QCOMPARE(object.isAvailable(), true); + QCOMPARE(object.availabilityError(), QtMultimedia::NoError); +} + + void tst_QMediaObject::service() + { + // Create the mediaobject with service. + QtTestMetaDataService service; + QtTestMediaObject mediaObject1(&service); + + // Get service and Compare if it equal to the service passed as an argument in mediaObject1. + QMediaService *service1 = mediaObject1.service(); + QVERIFY(service1 != NULL); + QCOMPARE(service1,&service); + + // Create the mediaobject with empty service and verify that service() returns NULL. + QtTestMediaObject mediaObject2; + QMediaService *service2 = mediaObject2.service(); + QVERIFY(service2 == NULL); + } + + void tst_QMediaObject::availabilityChangedSignal() + { + // The availabilityChangedSignal is implemented in QAudioCaptureSource. So using it to test the signal. + MockMediaRecorderService *mockAudioSourceService = new MockMediaRecorderService; + MockMediaServiceProvider *mockProvider = new MockMediaServiceProvider(mockAudioSourceService); + QAudioCaptureSource *audiosource = new QAudioCaptureSource(0, mockProvider); + + QSignalSpy spy(audiosource, SIGNAL(availabilityChanged(bool))); + + // Add the end points and verify if the availablity changed signal emitted with argument true. + QMetaObject::invokeMethod(mockAudioSourceService->mockAudioEndpointSelector, "addEndpoints"); + QVERIFY(spy.count() == 1); + bool available = qvariant_cast(spy.at(0).at(0)); + QVERIFY(available == true); + + spy.clear(); + + // Remove all endpoints and verify if the signal is emitted with argument false. + QMetaObject::invokeMethod(mockAudioSourceService->mockAudioEndpointSelector, "removeEndpoints"); + QVERIFY(spy.count() == 1); + available = qvariant_cast(spy.at(0).at(0)); + QVERIFY(available == false); + } diff --git a/tests/auto/unit/qmediaobject/tst_qmediaobject.h b/tests/auto/unit/qmediaobject/tst_qmediaobject.h new file mode 100644 index 000000000..5bc70c4a4 --- /dev/null +++ b/tests/auto/unit/qmediaobject/tst_qmediaobject.h @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QMEDIAOBJECT_H +#define TST_QMEDIAOBJECT_H + +#include + +#include + +#include +#include +#include +#include +#include + +//TESTED_COMPONENT=src/multimedia + +#include "mockmetadatareadercontrol.h" + +class QtTestMetaDataService : public QMediaService +{ + Q_OBJECT +public: + QtTestMetaDataService(QObject *parent = 0):QMediaService(parent), metaDataRef(0), hasMetaData(true) + { + } + + QMediaControl *requestControl(const char *iid) + { + if (hasMetaData && qstrcmp(iid, QMetaDataReaderControl_iid) == 0) + return &metaData; + else + return 0; + } + + void releaseControl(QMediaControl *) + { + } + + MockMetaDataReaderControl metaData; + int metaDataRef; + bool hasMetaData; +}; + +QT_USE_NAMESPACE +class tst_QMediaObject : public QObject +{ + Q_OBJECT + +private slots: + void propertyWatch(); + void notifySignals_data(); + void notifySignals(); + void notifyInterval_data(); + void notifyInterval(); + + void nullMetaDataControl(); + void isMetaDataAvailable(); + void metaDataChanged(); + void metaData_data(); + void metaData(); + void availability(); + void extendedMetaData_data() { metaData_data(); } + void extendedMetaData(); + + void service(); + void availabilityChangedSignal(); + +private: + void setupNotifyTests(); +}; + +class QtTestMediaObject : public QMediaObject +{ + Q_OBJECT + Q_PROPERTY(int a READ a WRITE setA NOTIFY aChanged) + Q_PROPERTY(int b READ b WRITE setB NOTIFY bChanged) + Q_PROPERTY(int c READ c WRITE setC NOTIFY cChanged) + Q_PROPERTY(int d READ d WRITE setD) +public: + QtTestMediaObject(QMediaService *service = 0): QMediaObject(0, service), m_a(0), m_b(0), m_c(0), m_d(0) {} + + using QMediaObject::addPropertyWatch; + using QMediaObject::removePropertyWatch; + + int a() const { return m_a; } + void setA(int a) { m_a = a; } + + int b() const { return m_b; } + void setB(int b) { m_b = b; } + + int c() const { return m_c; } + void setC(int c) { m_c = c; } + + int d() const { return m_d; } + void setD(int d) { m_d = d; } + +Q_SIGNALS: + void aChanged(int a); + void bChanged(int b); + void cChanged(int c); + +private: + int m_a; + int m_b; + int m_c; + int m_d; +}; +#endif //TST_QMEDIAOBJECT_H diff --git a/tests/auto/unit/qmediaplayer/main.cpp b/tests/auto/unit/qmediaplayer/main.cpp new file mode 100755 index 000000000..417dcd3f1 --- /dev/null +++ b/tests/auto/unit/qmediaplayer/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qmediaplayer.h" + +int main(int argc, char**argv) +{ + QCoreApplication app(argc,argv); + int ret; + tst_QMediaPlayer test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qmediaplayer/qmediaplayer.pro b/tests/auto/unit/qmediaplayer/qmediaplayer.pro new file mode 100644 index 000000000..f770f1e07 --- /dev/null +++ b/tests/auto/unit/qmediaplayer/qmediaplayer.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qmediaplayer + +QT += network multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +HEADERS += tst_qmediaplayer.h +SOURCES += main.cpp tst_qmediaplayer.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockplayer.pri) diff --git a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp new file mode 100644 index 000000000..383a4c4f3 --- /dev/null +++ b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.cpp @@ -0,0 +1,1050 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qmediaplayer.h" + +#include + +// Encouraging successful diversity through copy and paste. +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + +#ifndef QTRY_VERIFY +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) +#endif + +QT_USE_NAMESPACE + +#include "mockvideosurface.h" + +void tst_QMediaPlayer::initTestCase_data() +{ + QTest::addColumn("valid"); + QTest::addColumn("state"); + QTest::addColumn("status"); + QTest::addColumn("mediaContent"); + QTest::addColumn("duration"); + QTest::addColumn("position"); + QTest::addColumn("seekable"); + QTest::addColumn("volume"); + QTest::addColumn("muted"); + QTest::addColumn("videoAvailable"); + QTest::addColumn("bufferStatus"); + QTest::addColumn("playbackRate"); + QTest::addColumn("error"); + QTest::addColumn("errorString"); + + QTest::newRow("invalid") << false << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << + QMediaContent() << qint64(0) << qint64(0) << false << 0 << false << false << 0 << + qreal(0) << QMediaPlayer::NoError << QString(); + QTest::newRow("valid+null") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << + QMediaContent() << qint64(0) << qint64(0) << false << 0 << false << false << 50 << + qreal(0) << QMediaPlayer::NoError << QString(); + QTest::newRow("valid+content+stopped") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << + QMediaContent(QUrl("file:///some.mp3")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 << + qreal(1) << QMediaPlayer::NoError << QString(); + QTest::newRow("valid+content+playing") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia << + QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 << + qreal(1) << QMediaPlayer::NoError << QString(); + QTest::newRow("valid+content+paused") << true << QMediaPlayer::PausedState << QMediaPlayer::LoadedMedia << + QMediaContent(QUrl("file:///some.mp3")) << qint64(10000) << qint64(10) << true << 50 << true << false << 0 << + qreal(1) << QMediaPlayer::NoError << QString(); + QTest::newRow("valud+streaming") << true << QMediaPlayer::PlayingState << QMediaPlayer::LoadedMedia << + QMediaContent(QUrl("http://example.com/stream")) << qint64(10000) << qint64(10000) << false << 50 << false << true << 0 << + qreal(1) << QMediaPlayer::NoError << QString(); + QTest::newRow("valid+error") << true << QMediaPlayer::StoppedState << QMediaPlayer::UnknownMediaStatus << + QMediaContent(QUrl("http://example.com/stream")) << qint64(0) << qint64(0) << false << 50 << false << false << 0 << + qreal(0) << QMediaPlayer::ResourceError << QString("Resource unavailable"); +} + +void tst_QMediaPlayer::initTestCase() +{ + qRegisterMetaType("QMediaPlayer::State"); + qRegisterMetaType("QMediaPlayer::Error"); + qRegisterMetaType("QMediaPlayer::MediaStatus"); + qRegisterMetaType("QMediaContent"); + + mockService = new MockMediaPlayerService; + mockProvider = new MockMediaServiceProvider(mockService, true); + player = new QMediaPlayer(0, 0, mockProvider); +} + +void tst_QMediaPlayer::cleanupTestCase() +{ + delete player; +} + +void tst_QMediaPlayer::init() +{ + mockService->reset(); +} + +void tst_QMediaPlayer::cleanup() +{ +} + +void tst_QMediaPlayer::testNullService() +{ + MockMediaServiceProvider provider(0); + QMediaPlayer player(0, 0, &provider); + + const QIODevice *nullDevice = 0; + + QCOMPARE(player.media(), QMediaContent()); + QCOMPARE(player.mediaStream(), nullDevice); + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); + QCOMPARE(player.duration(), qint64(-1)); + QCOMPARE(player.position(), qint64(0)); + QCOMPARE(player.volume(), 0); + QCOMPARE(player.isMuted(), false); + QCOMPARE(player.isVideoAvailable(), false); + QCOMPARE(player.bufferStatus(), 0); + QCOMPARE(player.isSeekable(), false); + QCOMPARE(player.playbackRate(), qreal(0)); + QCOMPARE(player.error(), QMediaPlayer::ServiceMissingError); + QCOMPARE(player.isAvailable(), false); + QCOMPARE(player.availabilityError(), QtMultimedia::ServiceMissingError); + + { + QFETCH_GLOBAL(QMediaContent, mediaContent); + + QSignalSpy spy(&player, SIGNAL(mediaChanged(QMediaContent))); + QFile file; + + player.setMedia(mediaContent, &file); + QCOMPARE(player.media(), QMediaContent()); + QCOMPARE(player.mediaStream(), nullDevice); + QCOMPARE(spy.count(), 0); + } { + QSignalSpy stateSpy(&player, SIGNAL(stateChanged(QMediaPlayer::State))); + QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + + player.play(); + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + + player.pause(); + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + + player.stop(); + QCOMPARE(player.state(), QMediaPlayer::StoppedState); + QCOMPARE(player.mediaStatus(), QMediaPlayer::UnknownMediaStatus); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + } { + QFETCH_GLOBAL(int, volume); + QFETCH_GLOBAL(bool, muted); + + QSignalSpy volumeSpy(&player, SIGNAL(volumeChanged(int))); + QSignalSpy mutingSpy(&player, SIGNAL(mutedChanged(bool))); + + player.setVolume(volume); + QCOMPARE(player.volume(), 0); + QCOMPARE(volumeSpy.count(), 0); + + player.setMuted(muted); + QCOMPARE(player.isMuted(), false); + QCOMPARE(mutingSpy.count(), 0); + } { + QFETCH_GLOBAL(qint64, position); + + QSignalSpy spy(&player, SIGNAL(positionChanged(qint64))); + + player.setPosition(position); + QCOMPARE(player.position(), qint64(0)); + QCOMPARE(spy.count(), 0); + } { + QFETCH_GLOBAL(qreal, playbackRate); + + QSignalSpy spy(&player, SIGNAL(playbackRateChanged(qreal))); + + player.setPlaybackRate(playbackRate); + QCOMPARE(player.playbackRate(), qreal(0)); + QCOMPARE(spy.count(), 0); + } { + QMediaPlaylist playlist; + player.setPlaylist(&playlist); + + QSignalSpy mediaSpy(&player, SIGNAL(mediaChanged(QMediaContent))); + QSignalSpy statusSpy(&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + + playlist.addMedia(QUrl("http://example.com/stream")); + playlist.addMedia(QUrl("file:///some.mp3")); + + playlist.setCurrentIndex(0); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(player.media(), QMediaContent()); + QCOMPARE(mediaSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + + playlist.next(); + QCOMPARE(playlist.currentIndex(), 1); + QCOMPARE(player.media(), QMediaContent()); + QCOMPARE(mediaSpy.count(), 0); + QCOMPARE(statusSpy.count(), 0); + } +} + +void tst_QMediaPlayer::testValid() +{ + /* + QFETCH_GLOBAL(bool, valid); + + mockService->setIsValid(valid); + QCOMPARE(player->isValid(), valid); + */ +} + +void tst_QMediaPlayer::testMedia() +{ + QFETCH_GLOBAL(QMediaContent, mediaContent); + + mockService->setMedia(mediaContent); + QCOMPARE(player->media(), mediaContent); + + QBuffer stream; + player->setMedia(mediaContent, &stream); + QCOMPARE(player->media(), mediaContent); + QCOMPARE((QBuffer*)player->mediaStream(), &stream); +} + +void tst_QMediaPlayer::testDuration() +{ + QFETCH_GLOBAL(qint64, duration); + + mockService->setDuration(duration); + QVERIFY(player->duration() == duration); +} + +void tst_QMediaPlayer::testPosition() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(bool, seekable); + QFETCH_GLOBAL(qint64, position); + QFETCH_GLOBAL(qint64, duration); + + mockService->setIsValid(valid); + mockService->setSeekable(seekable); + mockService->setPosition(position); + mockService->setDuration(duration); + QVERIFY(player->isSeekable() == seekable); + QVERIFY(player->position() == position); + QVERIFY(player->duration() == duration); + + if (seekable) { + { QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(position); + QCOMPARE(player->position(), position); + QCOMPARE(spy.count(), 0); } + + mockService->setPosition(position); + { QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(0); + QCOMPARE(player->position(), qint64(0)); + QCOMPARE(spy.count(), position == 0 ? 0 : 1); } + + mockService->setPosition(position); + { QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(duration); + QCOMPARE(player->position(), duration); + QCOMPARE(spy.count(), position == duration ? 0 : 1); } + + mockService->setPosition(position); + { QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(-1); + QCOMPARE(player->position(), qint64(0)); + QCOMPARE(spy.count(), position == 0 ? 0 : 1); } + + mockService->setPosition(position); + { QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(duration + 1); + QCOMPARE(player->position(), duration); + QCOMPARE(spy.count(), position == duration ? 0 : 1); } + } + else { + QSignalSpy spy(player, SIGNAL(positionChanged(qint64))); + player->setPosition(position); + + QCOMPARE(player->position(), position); + QCOMPARE(spy.count(), 0); + } +} + +void tst_QMediaPlayer::testVolume() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(int, volume); + + mockService->setVolume(volume); + QVERIFY(player->volume() == volume); + + if (valid) { + { QSignalSpy spy(player, SIGNAL(volumeChanged(int))); + player->setVolume(10); + QCOMPARE(player->volume(), 10); + QCOMPARE(spy.count(), 1); } + + { QSignalSpy spy(player, SIGNAL(volumeChanged(int))); + player->setVolume(-1000); + QCOMPARE(player->volume(), 0); + QCOMPARE(spy.count(), 1); } + + { QSignalSpy spy(player, SIGNAL(volumeChanged(int))); + player->setVolume(100); + QCOMPARE(player->volume(), 100); + QCOMPARE(spy.count(), 1); } + + { QSignalSpy spy(player, SIGNAL(volumeChanged(int))); + player->setVolume(1000); + QCOMPARE(player->volume(), 100); + QCOMPARE(spy.count(), 0); } + } +} + +void tst_QMediaPlayer::testMuted() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(bool, muted); + QFETCH_GLOBAL(int, volume); + + if (valid) { + mockService->setMuted(muted); + mockService->setVolume(volume); + QVERIFY(player->isMuted() == muted); + + QSignalSpy spy(player, SIGNAL(mutedChanged(bool))); + player->setMuted(!muted); + QCOMPARE(player->isMuted(), !muted); + QCOMPARE(player->volume(), volume); + QCOMPARE(spy.count(), 1); + } +} + +void tst_QMediaPlayer::testVideoAvailable() +{ + QFETCH_GLOBAL(bool, videoAvailable); + + mockService->setVideoAvailable(videoAvailable); + QVERIFY(player->isVideoAvailable() == videoAvailable); +} + +void tst_QMediaPlayer::testBufferStatus() +{ + QFETCH_GLOBAL(int, bufferStatus); + + mockService->setBufferStatus(bufferStatus); + QVERIFY(player->bufferStatus() == bufferStatus); +} + +void tst_QMediaPlayer::testSeekable() +{ + QFETCH_GLOBAL(bool, seekable); + + mockService->setSeekable(seekable); + QVERIFY(player->isSeekable() == seekable); +} + +void tst_QMediaPlayer::testPlaybackRate() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(qreal, playbackRate); + + if (valid) { + mockService->setPlaybackRate(playbackRate); + QVERIFY(player->playbackRate() == playbackRate); + + QSignalSpy spy(player, SIGNAL(playbackRateChanged(qreal))); + player->setPlaybackRate(playbackRate + 0.5f); + QCOMPARE(player->playbackRate(), playbackRate + 0.5f); + QCOMPARE(spy.count(), 1); + } +} + +void tst_QMediaPlayer::testError() +{ + QFETCH_GLOBAL(QMediaPlayer::Error, error); + + mockService->setError(error); + QVERIFY(player->error() == error); +} + +void tst_QMediaPlayer::testErrorString() +{ + QFETCH_GLOBAL(QString, errorString); + + mockService->setErrorString(errorString); + QVERIFY(player->errorString() == errorString); +} + +void tst_QMediaPlayer::testIsAvailable() +{ + QCOMPARE(player->isAvailable(), true); + QCOMPARE(player->availabilityError(), QtMultimedia::NoError); +} + +void tst_QMediaPlayer::testService() +{ + /* + QFETCH_GLOBAL(bool, valid); + + mockService->setIsValid(valid); + + if (valid) + QVERIFY(player->service() != 0); + else + QVERIFY(player->service() == 0); + */ +} + +void tst_QMediaPlayer::testPlay() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(QMediaContent, mediaContent); + QFETCH_GLOBAL(QMediaPlayer::State, state); + + mockService->setIsValid(valid); + mockService->setState(state); + mockService->setMedia(mediaContent); + QVERIFY(player->state() == state); + QVERIFY(player->media() == mediaContent); + + QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State))); + + player->play(); + + if (!valid || mediaContent.isNull()) { + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(spy.count(), 0); + } + else { + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(spy.count(), state == QMediaPlayer::PlayingState ? 0 : 1); + } +} + +void tst_QMediaPlayer::testPause() +{ + QFETCH_GLOBAL(bool, valid); + QFETCH_GLOBAL(QMediaContent, mediaContent); + QFETCH_GLOBAL(QMediaPlayer::State, state); + + mockService->setIsValid(valid); + mockService->setState(state); + mockService->setMedia(mediaContent); + QVERIFY(player->state() == state); + QVERIFY(player->media() == mediaContent); + + QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State))); + + player->pause(); + + if (!valid || mediaContent.isNull()) { + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(spy.count(), 0); + } + else { + QCOMPARE(player->state(), QMediaPlayer::PausedState); + QCOMPARE(spy.count(), state == QMediaPlayer::PausedState ? 0 : 1); + } +} + +void tst_QMediaPlayer::testStop() +{ + QFETCH_GLOBAL(QMediaContent, mediaContent); + QFETCH_GLOBAL(QMediaPlayer::State, state); + + mockService->setState(state); + mockService->setMedia(mediaContent); + QVERIFY(player->state() == state); + QVERIFY(player->media() == mediaContent); + + QSignalSpy spy(player, SIGNAL(stateChanged(QMediaPlayer::State))); + + player->stop(); + + if (mediaContent.isNull() || state == QMediaPlayer::StoppedState) { + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(spy.count(), 0); + } + else { + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(spy.count(), 1); + } +} + +void tst_QMediaPlayer::testMediaStatus() +{ + QFETCH_GLOBAL(int, bufferStatus); + int bufferSignals = 0; + + player->setNotifyInterval(10); + + mockService->setMediaStatus(QMediaPlayer::NoMedia); + mockService->setBufferStatus(bufferStatus); + + AutoConnection connection( + player, SIGNAL(bufferStatusChanged(int)), + &QTestEventLoop::instance(), SLOT(exitLoop())); + + QSignalSpy statusSpy(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + QSignalSpy bufferSpy(player, SIGNAL(bufferStatusChanged(int))); + + QCOMPARE(player->mediaStatus(), QMediaPlayer::NoMedia); + + mockService->setMediaStatus(QMediaPlayer::LoadingMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::LoadingMedia); + QCOMPARE(statusSpy.count(), 1); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::LoadingMedia); + + mockService->setMediaStatus(QMediaPlayer::LoadedMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::LoadedMedia); + QCOMPARE(statusSpy.count(), 2); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::LoadedMedia); + + // Verify the bufferStatusChanged() signal isn't being emitted. + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(bufferSpy.count(), 0); + + mockService->setMediaStatus(QMediaPlayer::StalledMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::StalledMedia); + QCOMPARE(statusSpy.count(), 3); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::StalledMedia); + + // Verify the bufferStatusChanged() signal is being emitted. + QTestEventLoop::instance().enterLoop(1); + QVERIFY(bufferSpy.count() > bufferSignals); + QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus); + bufferSignals = bufferSpy.count(); + + mockService->setMediaStatus(QMediaPlayer::BufferingMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::BufferingMedia); + QCOMPARE(statusSpy.count(), 4); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::BufferingMedia); + + // Verify the bufferStatusChanged() signal is being emitted. + QTestEventLoop::instance().enterLoop(1); + QVERIFY(bufferSpy.count() > bufferSignals); + QCOMPARE(bufferSpy.last().value(0).toInt(), bufferStatus); + bufferSignals = bufferSpy.count(); + + mockService->setMediaStatus(QMediaPlayer::BufferedMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::BufferedMedia); + QCOMPARE(statusSpy.count(), 5); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::BufferedMedia); + + // Verify the bufferStatusChanged() signal isn't being emitted. + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(bufferSpy.count(), bufferSignals); + + mockService->setMediaStatus(QMediaPlayer::EndOfMedia); + QCOMPARE(player->mediaStatus(), QMediaPlayer::EndOfMedia); + QCOMPARE(statusSpy.count(), 6); + + QCOMPARE(qvariant_cast(statusSpy.last().value(0)), + QMediaPlayer::EndOfMedia); +} + +void tst_QMediaPlayer::testPlaylist() +{ + QMediaContent content0(QUrl(QLatin1String("test://audio/song1.mp3"))); + QMediaContent content1(QUrl(QLatin1String("test://audio/song2.mp3"))); + QMediaContent content2(QUrl(QLatin1String("test://video/movie1.mp4"))); + QMediaContent content3(QUrl(QLatin1String("test://video/movie2.mp4"))); + QMediaContent content4(QUrl(QLatin1String("test://image/photo.jpg"))); + + mockService->setIsValid(true); + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::NoMedia); + + QMediaPlaylist *playlist = new QMediaPlaylist; + player->setPlaylist(playlist); + + QSignalSpy stateSpy(player, SIGNAL(stateChanged(QMediaPlayer::State))); + QSignalSpy mediaSpy(player, SIGNAL(mediaChanged(QMediaContent))); + + // Test the player does nothing with an empty playlist attached. + player->play(); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(player->media(), QMediaContent()); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(mediaSpy.count(), 0); + + playlist->addMedia(content0); + playlist->addMedia(content1); + playlist->addMedia(content2); + playlist->addMedia(content3); + + // Test changing the playlist position, changes the current media, but not the playing state. + playlist->setCurrentIndex(1); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 0); + QCOMPARE(mediaSpy.count(), 1); + + // Test playing starts with the current media. + player->play(); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 1); + QCOMPARE(mediaSpy.count(), 1); + + // Test pausing doesn't change the current media. + player->pause(); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::PausedState); + QCOMPARE(stateSpy.count(), 2); + QCOMPARE(mediaSpy.count(), 1); + + // Test stopping doesn't change the current media. + player->stop(); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 3); + QCOMPARE(mediaSpy.count(), 1); + + // Test when the player service reaches the end of the current media, the player moves onto + // the next item without stopping. + player->play(); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 4); + QCOMPARE(mediaSpy.count(), 1); + + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); + QCOMPARE(player->media(), content2); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 4); + QCOMPARE(mediaSpy.count(), 2); + + // Test skipping the current media doesn't change the state. + playlist->next(); + QCOMPARE(player->media(), content3); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 4); + QCOMPARE(mediaSpy.count(), 3); + + // Test changing the current media while paused doesn't change the state. + player->pause(); + mockService->setMediaStatus(QMediaPlayer::BufferedMedia); + QCOMPARE(player->media(), content3); + QCOMPARE(player->state(), QMediaPlayer::PausedState); + QCOMPARE(stateSpy.count(), 5); + QCOMPARE(mediaSpy.count(), 3); + + playlist->previous(); + QCOMPARE(player->media(), content2); + QCOMPARE(player->state(), QMediaPlayer::PausedState); + QCOMPARE(stateSpy.count(), 5); + QCOMPARE(mediaSpy.count(), 4); + + // Test changing the current media while stopped doesn't change the state. + player->stop(); + mockService->setMediaStatus(QMediaPlayer::LoadedMedia); + QCOMPARE(player->media(), content2); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 6); + QCOMPARE(mediaSpy.count(), 4); + + playlist->next(); + QCOMPARE(player->media(), content3); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 6); + QCOMPARE(mediaSpy.count(), 5); + + // Test the player is stopped and the current media cleared when it reaches the end of the last + // item in the playlist. + player->play(); + QCOMPARE(player->media(), content3); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 7); + QCOMPARE(mediaSpy.count(), 5); + + // Double up the signals to ensure some noise doesn't destabalize things. + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::EndOfMedia); + QCOMPARE(player->media(), QMediaContent()); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 8); + QCOMPARE(mediaSpy.count(), 6); + + // Test starts playing from the start of the playlist if there is no current media selected. + player->play(); + QCOMPARE(player->media(), content0); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 9); + QCOMPARE(mediaSpy.count(), 7); + + // Test deleting the playlist stops the player and clears the media it set. + delete playlist; + QCOMPARE(player->media(), QMediaContent()); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 10); + QCOMPARE(mediaSpy.count(), 8); + + // Test the player works as normal with the playlist removed. + player->play(); + QCOMPARE(player->media(), QMediaContent()); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + QCOMPARE(stateSpy.count(), 10); + QCOMPARE(mediaSpy.count(), 8); + + player->setMedia(content1); + player->play(); + + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(stateSpy.count(), 11); + QCOMPARE(mediaSpy.count(), 9); + + // Test the player can bind to playlist again + playlist = new QMediaPlaylist; + player->setPlaylist(playlist); + + QCOMPARE(player->media(), QMediaContent()); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + + playlist->addMedia(content0); + playlist->addMedia(content1); + playlist->addMedia(content2); + playlist->addMedia(content3); + + playlist->setCurrentIndex(1); + QCOMPARE(player->media(), content1); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + + // Test attaching the new playlist, + // player should detach the current one + QMediaPlaylist *playlist2 = new QMediaPlaylist; + playlist2->addMedia(content1); + playlist2->addMedia(content2); + playlist2->addMedia(content3); + playlist2->setCurrentIndex(2); + + player->play(); + player->setPlaylist(playlist2); + QCOMPARE(player->media(), playlist2->currentMedia()); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + + playlist2->setCurrentIndex(1); + QCOMPARE(player->media(), playlist2->currentMedia()); + + { + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + playlist.addMedia(content3); + playlist.setCurrentIndex(1); + + player->setPlaylist(&playlist); + QCOMPARE(player->playlist(), &playlist); + QCOMPARE(player->media(), content2); + } //playlist should be detached now + + QVERIFY(player->playlist() == 0); + QCOMPARE(player->media(), QMediaContent()); + + // Test when the player service encounters an invalid media, the player moves onto + // the next item without stopping + { + QSignalSpy ss(player, SIGNAL(stateChanged(QMediaPlayer::State))); + QSignalSpy ms(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + + player->setPlaylist(playlist); + player->play(); + QCOMPARE(ss.count(), 1); + + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::InvalidMedia); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QCOMPARE(player->mediaStatus(), QMediaPlayer::InvalidMedia); + QCOMPARE(ss.count(), 1); + QCOMPARE(ms.count(), 1); + + // NOTE: status should begin transitioning through to BufferedMedia. + QCOMPARE(player->media(), content2); + } + +} + +void tst_QMediaPlayer::testPlayerFlags() +{ + MockMediaServiceProvider provider(0, true); + QMediaPlayer::Flag flags = QMediaPlayer::LowLatency; + + QMediaPlayer player(0, flags, &provider); + QMediaServiceProviderHint::Feature feature; + + if (flags & QMediaPlayer::LowLatency) + { + /* if the flag is low latency set the low latency play back for the service provider */ + feature = QMediaServiceProviderHint::LowLatencyPlayback; + const QByteArray service(Q_MEDIASERVICE_MEDIAPLAYER); + const QMediaServiceProviderHint providerHint(feature); + /* request service for the service provider */ + provider.requestService(service,providerHint); + + /* Constructs a SupportedFeatures media service provider hint. */ + QMediaServiceProviderHint servicepro(feature); + + /* compare the flag value */ + QVERIFY(servicepro.features() == QMediaServiceProviderHint::LowLatencyPlayback); + } + + /* The player is expected to play QIODevice based streams. + If passed to QMediaPlayer constructor, + the service supporting streams playback will be chosen. */ + flags = QMediaPlayer::StreamPlayback; + /* Construct a QMediaPlayer that uses the playback service from provider, + parented to parent and with flags.*/ + QMediaPlayer player2(0,flags , &provider); + + if (flags & QMediaPlayer::StreamPlayback) + { + /* if the flag is stream play back set the stream play back for the service provider */ + feature = QMediaServiceProviderHint::StreamPlayback; + const QByteArray service(Q_MEDIASERVICE_MEDIAPLAYER); + const QMediaServiceProviderHint providerHint(feature); + + /* request service for the service provider */ + provider.requestService(service,providerHint); + + /* Constructs a SupportedFeatures media service provider hint. */ + QMediaServiceProviderHint servicepro(feature); + + /* compare the flag value */ + QVERIFY(servicepro.features() == QMediaServiceProviderHint::StreamPlayback); + } +} + +void tst_QMediaPlayer::testDestructor() +{ + /* create an object for player */ + QMediaPlayer *player = new QMediaPlayer; + + /* check whether the object is created */ + QVERIFY(player); + + /* delete the instance */ + delete player; +} + +void tst_QMediaPlayer::testNetworkAccess() +{ + QNetworkConfigurationManager manager; + QList configs = manager.allConfigurations(); + + if (configs.count() >= 1) { + QSignalSpy spy(player, SIGNAL(networkConfigurationChanged(QNetworkConfiguration))); + int index = qFloor((configs.count())/2); + player->setNetworkConfigurations(configs); + mockService->selectCurrentConfiguration(configs.at(index)); + + QVERIFY(spy.count() == 1); + QList args = spy.takeFirst(); + QNetworkConfiguration config = args.at(0).value(); + QCOMPARE(config.identifier() , configs.at(index).identifier()); + QCOMPARE(player->currentNetworkConfiguration().identifier() , config.identifier()); + } + + // invalidate current network configuration + QSignalSpy spy(player, SIGNAL(networkConfigurationChanged(QNetworkConfiguration))); + mockService->selectCurrentConfiguration(QNetworkConfiguration()); + QVERIFY(spy.count() == 1); + QList args = spy.takeFirst(); + QNetworkConfiguration config = args.at(0).value(); + QVERIFY(config.isValid() == false); + QVERIFY(player->currentNetworkConfiguration().isValid() == false); +} + +void tst_QMediaPlayer::testSetVideoOutput() +{ + MockVideoSurface surface; + + MockMediaPlayerService service; + MockMediaServiceProvider provider(&service); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(reinterpret_cast(0)); + player.setVideoOutput(reinterpret_cast(0)); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + player.setVideoOutput(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + player.setVideoOutput(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); +} + + +void tst_QMediaPlayer::testSetVideoOutputNoService() +{ + MockVideoSurface surface; + + MockMediaServiceProvider provider(0, true); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(&surface); + // Nothing we can verify here other than it doesn't assert. +} + +void tst_QMediaPlayer::testSetVideoOutputNoControl() +{ + MockVideoSurface surface; + + MockMediaPlayerService service; + service.rendererRef = 1; + + MockMediaServiceProvider provider(&service); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == 0); +} + +void tst_QMediaPlayer::testSetVideoOutputDestruction() +{ + MockVideoSurface surface; + + MockMediaPlayerService service; + MockMediaServiceProvider provider(&service); + + { + QMediaPlayer player(0, 0, &provider); + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + QCOMPARE(service.rendererRef, 1); + } + QVERIFY(service.rendererControl->surface() == 0); + QCOMPARE(service.rendererRef, 0); +} + +void tst_QMediaPlayer::testPositionPropertyWatch() +{ + QMediaContent content0(QUrl(QLatin1String("test://audio/song1.mp3"))); + QMediaContent content1(QUrl(QLatin1String("test://audio/song2.mp3"))); + + mockService->setIsValid(true); + mockService->setState(QMediaPlayer::StoppedState, QMediaPlayer::NoMedia); + + QMediaPlaylist *playlist = new QMediaPlaylist; + + playlist->addMedia(content0); + playlist->addMedia(content1); + + player->setPlaylist(playlist); + player->setNotifyInterval(5); + + player->play(); + QSignalSpy positionSpy(player, SIGNAL(positionChanged(qint64))); + playlist->next(); + QCOMPARE(player->state(), QMediaPlayer::PlayingState); + QTRY_VERIFY(positionSpy.count() > 0); + + playlist->next(); + QCOMPARE(player->state(), QMediaPlayer::StoppedState); + + positionSpy.clear(); + QTRY_COMPARE(positionSpy.count(), 0); +} + +void tst_QMediaPlayer::debugEnums() +{ + QTest::ignoreMessage(QtDebugMsg, "QMediaPlayer::PlayingState "); + qDebug() << QMediaPlayer::PlayingState; + QTest::ignoreMessage(QtDebugMsg, "QMediaPlayer::NoMedia "); + qDebug() << QMediaPlayer::NoMedia; + QTest::ignoreMessage(QtDebugMsg, "QMediaPlayer::NetworkError "); + qDebug() << QMediaPlayer::NetworkError; +} + +void tst_QMediaPlayer::testSupportedMimeTypes() +{ + QStringList mimeList = QMediaPlayer::supportedMimeTypes(QMediaPlayer::LowLatency); + + // This is empty on some platforms, and not on others, so can't test something here at the moment. +} diff --git a/tests/auto/unit/qmediaplayer/tst_qmediaplayer.h b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.h new file mode 100755 index 000000000..76a94cccf --- /dev/null +++ b/tests/auto/unit/qmediaplayer/tst_qmediaplayer.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QMEDIAPLAYER_H +#define TST_QMEDIAPLAYER_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mockmediaserviceprovider.h" +#include "mockmediaplayerservice.h" + +QT_USE_NAMESPACE + +class AutoConnection +{ +public: + AutoConnection(QObject *sender, const char *signal, QObject *receiver, const char *method) + : sender(sender), signal(signal), receiver(receiver), method(method) + { + QObject::connect(sender, signal, receiver, method); + } + + ~AutoConnection() + { + QObject::disconnect(sender, signal, receiver, method); + } + +private: + QObject *sender; + const char *signal; + QObject *receiver; + const char *method; +}; + +class tst_QMediaPlayer: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase_data(); + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void testNullService(); + void testValid(); + void testMedia(); + void testDuration(); + void testPosition(); + void testVolume(); + void testMuted(); + void testIsAvailable(); + void testVideoAvailable(); + void testBufferStatus(); + void testSeekable(); + void testPlaybackRate(); + void testError(); + void testErrorString(); + void testService(); + void testPlay(); + void testPause(); + void testStop(); + void testMediaStatus(); + void testPlaylist(); + void testNetworkAccess(); + void testSetVideoOutput(); + void testSetVideoOutputNoService(); + void testSetVideoOutputNoControl(); + void testSetVideoOutputDestruction(); + void testPositionPropertyWatch(); + void debugEnums(); + void testPlayerFlags(); + void testDestructor(); + void testSupportedMimeTypes(); + +private: + MockMediaServiceProvider *mockProvider; + MockMediaPlayerService *mockService; + QMediaPlayer *player; +}; + +#endif //TST_QMEDIAPLAYER_H diff --git a/tests/auto/unit/qmediaplayerwidgets/main.cpp b/tests/auto/unit/qmediaplayerwidgets/main.cpp new file mode 100755 index 000000000..e7614c975 --- /dev/null +++ b/tests/auto/unit/qmediaplayerwidgets/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qmediaplayerwidgets.h" + +int main(int argc, char**argv) +{ + QApplication app(argc,argv); + int ret; + tst_QMediaPlayerWidgets test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qmediaplayerwidgets/qmediaplayerwidgets.pro b/tests/auto/unit/qmediaplayerwidgets/qmediaplayerwidgets.pro new file mode 100644 index 000000000..c5c602938 --- /dev/null +++ b/tests/auto/unit/qmediaplayerwidgets/qmediaplayerwidgets.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qmediaplayerwidgets + +QT += network multimedia-private multimediawidgets-private testlib widgets +CONFIG += no_private_qt_headers_warning + +HEADERS += tst_qmediaplayerwidgets.h +SOURCES += main.cpp tst_qmediaplayerwidgets.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockplayer.pri) diff --git a/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp new file mode 100644 index 000000000..ac9ffa0ce --- /dev/null +++ b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qmediaplayerwidgets.h" +#include "mockvideosurface.h" +#include + +QT_USE_NAMESPACE + +void tst_QMediaPlayerWidgets::initTestCase() +{ + qRegisterMetaType("QMediaPlayer::State"); + qRegisterMetaType("QMediaPlayer::Error"); + qRegisterMetaType("QMediaPlayer::MediaStatus"); + qRegisterMetaType("QMediaContent"); + + mockService = new MockMediaPlayerService; + mockProvider = new MockMediaServiceProvider(mockService, true); + player = new QMediaPlayer(0, 0, mockProvider); +} + +void tst_QMediaPlayerWidgets::cleanupTestCase() +{ + delete player; +} + +void tst_QMediaPlayerWidgets::init() +{ + mockService->reset(); +} + +void tst_QMediaPlayerWidgets::cleanup() +{ +} + +void tst_QMediaPlayerWidgets::testSetVideoOutput() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockMediaPlayerService service; + MockMediaServiceProvider provider(&service); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == &player); + + player.setVideoOutput(&item); + QVERIFY(widget.mediaObject() == 0); + QVERIFY(item.mediaObject() == &player); + + player.setVideoOutput(reinterpret_cast(0)); + QVERIFY(item.mediaObject() == 0); + + player.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == &player); + + player.setVideoOutput(reinterpret_cast(0)); + QVERIFY(widget.mediaObject() == 0); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + player.setVideoOutput(reinterpret_cast(0)); + QVERIFY(service.rendererControl->surface() == 0); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + + player.setVideoOutput(&widget); + QVERIFY(service.rendererControl->surface() == 0); + QVERIFY(widget.mediaObject() == &player); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == &surface); + QVERIFY(widget.mediaObject() == 0); +} + + +void tst_QMediaPlayerWidgets::testSetVideoOutputNoService() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockMediaServiceProvider provider(0, true); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == 0); + + player.setVideoOutput(&item); + QVERIFY(item.mediaObject() == 0); + + player.setVideoOutput(&surface); + // Nothing we can verify here other than it doesn't assert. +} + +void tst_QMediaPlayerWidgets::testSetVideoOutputNoControl() +{ + QVideoWidget widget; + QGraphicsVideoItem item; + MockVideoSurface surface; + + MockMediaPlayerService service; + service.rendererRef = 1; + service.windowRef = 1; + + MockMediaServiceProvider provider(&service); + QMediaPlayer player(0, 0, &provider); + + player.setVideoOutput(&widget); + QVERIFY(widget.mediaObject() == 0); + + player.setVideoOutput(&item); + QVERIFY(item.mediaObject() == 0); + + player.setVideoOutput(&surface); + QVERIFY(service.rendererControl->surface() == 0); +} + diff --git a/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.h b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.h new file mode 100755 index 000000000..e5f9b674a --- /dev/null +++ b/tests/auto/unit/qmediaplayerwidgets/tst_qmediaplayerwidgets.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QMEDIAPLAYER_H +#define TST_QMEDIAPLAYER_H + +#include +#include +#include +#include + +#include +#include +#include + +#include "mockmediaserviceprovider.h" +#include "mockmediaplayerservice.h" + +QT_USE_NAMESPACE + +class tst_QMediaPlayerWidgets: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void testSetVideoOutput(); + void testSetVideoOutputNoService(); + void testSetVideoOutputNoControl(); + +private: + MockMediaServiceProvider *mockProvider; + MockMediaPlayerService *mockService; + QMediaPlayer *player; +}; + +#endif //TST_QMEDIAPLAYER_H diff --git a/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro b/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro new file mode 100644 index 000000000..c6b28a7cf --- /dev/null +++ b/tests/auto/unit/qmediaplaylist/qmediaplaylist.pro @@ -0,0 +1,18 @@ +CONFIG += testcase +TARGET = tst_qmediaplaylist + +include (../qmultimedia_common/mockplaylist.pri) + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +DEFINES += TESTDATA_DIR=\\\"$$PWD/\\\" + +HEADERS += \ + $$QT.multimedia.sources/../plugins/m3u/qm3uhandler.h + +SOURCES += \ + tst_qmediaplaylist.cpp \ + $$QT.multimedia.sources/../plugins/m3u/qm3uhandler.cpp + +INCLUDEPATH += $$QT.multimedia.sources/../plugins/m3u diff --git a/tests/auto/unit/qmediaplaylist/testdata/test.m3u b/tests/auto/unit/qmediaplaylist/testdata/test.m3u new file mode 100644 index 000000000..e5cb7c828 --- /dev/null +++ b/tests/auto/unit/qmediaplaylist/testdata/test.m3u @@ -0,0 +1,11 @@ +#comment + +http://test.host/path + http://test.host/path +testfile + + +testdir/testfile +/testdir/testfile +file://path/name#suffix +testfile2#suffix diff --git a/tests/auto/unit/qmediaplaylist/testdata/testfile b/tests/auto/unit/qmediaplaylist/testdata/testfile new file mode 100644 index 000000000..e69de29bb diff --git a/tests/auto/unit/qmediaplaylist/testdata/testfile2#suffix b/tests/auto/unit/qmediaplaylist/testdata/testfile2#suffix new file mode 100644 index 000000000..e69de29bb diff --git a/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp new file mode 100644 index 000000000..91c4dda55 --- /dev/null +++ b/tests/auto/unit/qmediaplaylist/tst_qmediaplaylist.cpp @@ -0,0 +1,783 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include "qmediaservice.h" +#include "qmediaplaylist.h" +#include "qmediaplaylistcontrol.h" +#include "qmediaplaylistsourcecontrol.h" +#include "qmediaplaylistnavigator.h" +#include + +#include "qm3uhandler.h" + +//TESTED_COMPONENT=src/multimedia + +#include "mockplaylistservice.h" +#include "mockmediaplaylistcontrol.h" +#include "mockmediaplaylistsourcecontrol.h" +#include "mockreadonlyplaylistprovider.h" + +#ifndef TESTDATA_DIR +#define TESTDATA_DIR "./" +#endif + +QT_USE_NAMESPACE + +class MockReadOnlyPlaylistObject : public QMediaObject +{ + Q_OBJECT +public: + MockReadOnlyPlaylistObject(QObject *parent = 0) + :QMediaObject(parent, new MockPlaylistService) + { + } +}; + +class tst_QMediaPlaylist : public QObject +{ + Q_OBJECT +public slots: + void init(); + void cleanup(); + void initTestCase(); + +private slots: + void construction(); + void append(); + void insert(); + void clear(); + void removeMedia(); + void currentItem(); + void saveAndLoad(); + void loadM3uFile(); + void playbackMode(); + void playbackMode_data(); + void shuffle(); + void readOnlyPlaylist(); + void setMediaObject(); + + void testCurrentIndexChanged_signal(); + void testCurrentMediaChanged_signal(); + void testLoaded_signal(); + void testMediaChanged_signal(); + void testPlaybackModeChanged_signal(); + void testEnums(); + + void mediaPlayListProvider(); + // TC for Abstract control classes + void mediaPlayListControl(); + void mediaPlayListSourceControl(); + + +private: + QMediaContent content1; + QMediaContent content2; + QMediaContent content3; +}; + +void tst_QMediaPlaylist::init() +{ +} + +void tst_QMediaPlaylist::initTestCase() +{ + qRegisterMetaType(); + content1 = QMediaContent(QUrl(QLatin1String("file:///1"))); + content2 = QMediaContent(QUrl(QLatin1String("file:///2"))); + content3 = QMediaContent(QUrl(QLatin1String("file:///3"))); + + QMediaPluginLoader::setStaticPlugins(QLatin1String("playlistformats"), QObjectList() << new QM3uPlaylistPlugin(this)); +} + +void tst_QMediaPlaylist::cleanup() +{ +} + +void tst_QMediaPlaylist::construction() +{ + QMediaPlaylist playlist; + QCOMPARE(playlist.mediaCount(), 0); + QVERIFY(playlist.isEmpty()); +} + +void tst_QMediaPlaylist::append() +{ + QMediaPlaylist playlist; + QVERIFY(!playlist.isReadOnly()); + + playlist.addMedia(content1); + QCOMPARE(playlist.mediaCount(), 1); + QCOMPARE(playlist.media(0), content1); + + QSignalSpy aboutToBeInsertedSignalSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int,int))); + QSignalSpy insertedSignalSpy(&playlist, SIGNAL(mediaInserted(int,int))); + playlist.addMedia(content2); + QCOMPARE(playlist.mediaCount(), 2); + QCOMPARE(playlist.media(1), content2); + + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy.first()[1].toInt(), 1); + + QCOMPARE(insertedSignalSpy.count(), 1); + QCOMPARE(insertedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(insertedSignalSpy.first()[1].toInt(), 1); + + aboutToBeInsertedSignalSpy.clear(); + insertedSignalSpy.clear(); + + QMediaContent content4(QUrl(QLatin1String("file:///4"))); + QMediaContent content5(QUrl(QLatin1String("file:///5"))); + playlist.addMedia(QList() << content3 << content4 << content5); + QCOMPARE(playlist.mediaCount(), 5); + QCOMPARE(playlist.media(2), content3); + QCOMPARE(playlist.media(3), content4); + QCOMPARE(playlist.media(4), content5); + + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy[0][0].toInt(), 2); + QCOMPARE(aboutToBeInsertedSignalSpy[0][1].toInt(), 4); + + QCOMPARE(insertedSignalSpy.count(), 1); + QCOMPARE(insertedSignalSpy[0][0].toInt(), 2); + QCOMPARE(insertedSignalSpy[0][1].toInt(), 4); + + aboutToBeInsertedSignalSpy.clear(); + insertedSignalSpy.clear(); + + playlist.addMedia(QList()); + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 0); + QCOMPARE(insertedSignalSpy.count(), 0); +} + +void tst_QMediaPlaylist::insert() +{ + QMediaPlaylist playlist; + QVERIFY(!playlist.isReadOnly()); + + playlist.addMedia(content1); + QCOMPARE(playlist.mediaCount(), 1); + QCOMPARE(playlist.media(0), content1); + + playlist.addMedia(content2); + QCOMPARE(playlist.mediaCount(), 2); + QCOMPARE(playlist.media(1), content2); + + QSignalSpy aboutToBeInsertedSignalSpy(&playlist, SIGNAL(mediaAboutToBeInserted(int,int))); + QSignalSpy insertedSignalSpy(&playlist, SIGNAL(mediaInserted(int,int))); + + playlist.insertMedia(1, content3); + QCOMPARE(playlist.mediaCount(), 3); + QCOMPARE(playlist.media(0), content1); + QCOMPARE(playlist.media(1), content3); + QCOMPARE(playlist.media(2), content2); + + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy.first()[1].toInt(), 1); + + QCOMPARE(insertedSignalSpy.count(), 1); + QCOMPARE(insertedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(insertedSignalSpy.first()[1].toInt(), 1); + + aboutToBeInsertedSignalSpy.clear(); + insertedSignalSpy.clear(); + + QMediaContent content4(QUrl(QLatin1String("file:///4"))); + QMediaContent content5(QUrl(QLatin1String("file:///5"))); + playlist.insertMedia(1, QList() << content4 << content5); + + QCOMPARE(playlist.media(0), content1); + QCOMPARE(playlist.media(1), content4); + QCOMPARE(playlist.media(2), content5); + QCOMPARE(playlist.media(3), content3); + QCOMPARE(playlist.media(4), content2); + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy[0][0].toInt(), 1); + QCOMPARE(aboutToBeInsertedSignalSpy[0][1].toInt(), 2); + + QCOMPARE(insertedSignalSpy.count(), 1); + QCOMPARE(insertedSignalSpy[0][0].toInt(), 1); + QCOMPARE(insertedSignalSpy[0][1].toInt(), 2); + + aboutToBeInsertedSignalSpy.clear(); + insertedSignalSpy.clear(); + + playlist.insertMedia(1, QList()); + QCOMPARE(aboutToBeInsertedSignalSpy.count(), 0); + QCOMPARE(insertedSignalSpy.count(), 0); +} + + +void tst_QMediaPlaylist::currentItem() +{ + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(playlist.currentMedia(), QMediaContent()); + + QCOMPARE(playlist.nextIndex(), 0); + QCOMPARE(playlist.nextIndex(2), 1); + QCOMPARE(playlist.previousIndex(), 1); + QCOMPARE(playlist.previousIndex(2), 0); + + playlist.setCurrentIndex(0); + QCOMPARE(playlist.currentIndex(), 0); + QCOMPARE(playlist.currentMedia(), content1); + + QCOMPARE(playlist.nextIndex(), 1); + QCOMPARE(playlist.nextIndex(2), -1); + QCOMPARE(playlist.previousIndex(), -1); + QCOMPARE(playlist.previousIndex(2), -1); + + playlist.setCurrentIndex(1); + QCOMPARE(playlist.currentIndex(), 1); + QCOMPARE(playlist.currentMedia(), content2); + + QCOMPARE(playlist.nextIndex(), -1); + QCOMPARE(playlist.nextIndex(2), -1); + QCOMPARE(playlist.previousIndex(), 0); + QCOMPARE(playlist.previousIndex(2), -1); + + QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range "); + playlist.setCurrentIndex(2); + + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(playlist.currentMedia(), QMediaContent()); +} + +void tst_QMediaPlaylist::clear() +{ + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + + playlist.clear(); + QVERIFY(playlist.isEmpty()); + QCOMPARE(playlist.mediaCount(), 0); +} + +void tst_QMediaPlaylist::removeMedia() +{ + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + playlist.addMedia(content3); + + QSignalSpy aboutToBeRemovedSignalSpy(&playlist, SIGNAL(mediaAboutToBeRemoved(int,int))); + QSignalSpy removedSignalSpy(&playlist, SIGNAL(mediaRemoved(int,int))); + playlist.removeMedia(1); + QCOMPARE(playlist.mediaCount(), 2); + QCOMPARE(playlist.media(1), content3); + + QCOMPARE(aboutToBeRemovedSignalSpy.count(), 1); + QCOMPARE(aboutToBeRemovedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(aboutToBeRemovedSignalSpy.first()[1].toInt(), 1); + + QCOMPARE(removedSignalSpy.count(), 1); + QCOMPARE(removedSignalSpy.first()[0].toInt(), 1); + QCOMPARE(removedSignalSpy.first()[1].toInt(), 1); + + aboutToBeRemovedSignalSpy.clear(); + removedSignalSpy.clear(); + + playlist.removeMedia(0,1); + QVERIFY(playlist.isEmpty()); + + QCOMPARE(aboutToBeRemovedSignalSpy.count(), 1); + QCOMPARE(aboutToBeRemovedSignalSpy.first()[0].toInt(), 0); + QCOMPARE(aboutToBeRemovedSignalSpy.first()[1].toInt(), 1); + + QCOMPARE(removedSignalSpy.count(), 1); + QCOMPARE(removedSignalSpy.first()[0].toInt(), 0); + QCOMPARE(removedSignalSpy.first()[1].toInt(), 1); + + + playlist.addMedia(content1); + playlist.addMedia(content2); + playlist.addMedia(content3); + + playlist.removeMedia(0,1); + QCOMPARE(playlist.mediaCount(), 1); + QCOMPARE(playlist.media(0), content3); +} + +void tst_QMediaPlaylist::saveAndLoad() +{ + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + playlist.addMedia(content3); + + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + QVERIFY(playlist.errorString().isEmpty()); + + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + + bool res = playlist.save(&buffer, "unsupported_format"); + QVERIFY(!res); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); + QVERIFY(!playlist.errorString().isEmpty()); + + QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed())); + playlist.load(&buffer, "unsupported_format"); + QCOMPARE(errorSignal.size(), 1); + QVERIFY(playlist.error() != QMediaPlaylist::NoError); + QVERIFY(!playlist.errorString().isEmpty()); + + res = playlist.save(QUrl::fromLocalFile(QLatin1String("tmp.unsupported_format")), "unsupported_format"); + QVERIFY(!res); + QVERIFY(playlist.error() != QMediaPlaylist::NoError); + QVERIFY(!playlist.errorString().isEmpty()); + + errorSignal.clear(); + playlist.load(QUrl::fromLocalFile(QLatin1String("tmp.unsupported_format")), "unsupported_format"); + QCOMPARE(errorSignal.size(), 1); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); + QVERIFY(!playlist.errorString().isEmpty()); + + res = playlist.save(&buffer, "m3u"); + + QVERIFY(res); + QVERIFY(buffer.pos() > 0); + buffer.seek(0); + + QMediaPlaylist playlist2; + playlist2.load(&buffer, "m3u"); + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + + QCOMPARE(playlist.mediaCount(), playlist2.mediaCount()); + QCOMPARE(playlist.media(0), playlist2.media(0)); + QCOMPARE(playlist.media(1), playlist2.media(1)); + QCOMPARE(playlist.media(3), playlist2.media(3)); + res = playlist.save(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u"); + QVERIFY(res); + + playlist2.clear(); + QVERIFY(playlist2.isEmpty()); + playlist2.load(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u"); + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + + QCOMPARE(playlist.mediaCount(), playlist2.mediaCount()); + QCOMPARE(playlist.media(0), playlist2.media(0)); + QCOMPARE(playlist.media(1), playlist2.media(1)); + QCOMPARE(playlist.media(3), playlist2.media(3)); +} + +void tst_QMediaPlaylist::loadM3uFile() +{ + QMediaPlaylist playlist; + + playlist.load(QUrl::fromLocalFile(QLatin1String(TESTDATA_DIR "testdata/missing_file.m3u"))); + QVERIFY(playlist.error() != QMediaPlaylist::NoError); + + playlist.load(QUrl::fromLocalFile(QLatin1String(TESTDATA_DIR "testdata/test.m3u"))); + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + QCOMPARE(playlist.mediaCount(), 7); + + QCOMPARE(playlist.media(0).canonicalUrl(), QUrl(QLatin1String("http://test.host/path"))); + QCOMPARE(playlist.media(1).canonicalUrl(), QUrl(QLatin1String("http://test.host/path"))); + QCOMPARE(playlist.media(2).canonicalUrl(), + QUrl(QLatin1String("file://" TESTDATA_DIR "testdata/testfile"))); + QCOMPARE(playlist.media(3).canonicalUrl(), + QUrl(QLatin1String("file://" TESTDATA_DIR "testdata/testdir/testfile"))); + QCOMPARE(playlist.media(4).canonicalUrl(), QUrl(QLatin1String("file:///testdir/testfile"))); + QCOMPARE(playlist.media(5).canonicalUrl(), QUrl(QLatin1String("file://path/name#suffix"))); + //ensure #2 suffix is not stripped from path + QCOMPARE(playlist.media(6).canonicalUrl(), QUrl::fromLocalFile(TESTDATA_DIR "testdata/testfile2#suffix")); +} + +void tst_QMediaPlaylist::playbackMode_data() +{ + QTest::addColumn("playbackMode"); + QTest::addColumn("expectedPrevious"); + QTest::addColumn("pos"); + QTest::addColumn("expectedNext"); + + QTest::newRow("Sequential, 0") << QMediaPlaylist::Sequential << -1 << 0 << 1; + QTest::newRow("Sequential, 1") << QMediaPlaylist::Sequential << 0 << 1 << 2; + QTest::newRow("Sequential, 2") << QMediaPlaylist::Sequential << 1 << 2 << -1; + + QTest::newRow("Loop, 0") << QMediaPlaylist::Loop << 2 << 0 << 1; + QTest::newRow("Loop, 1") << QMediaPlaylist::Loop << 0 << 1 << 2; + QTest::newRow("Lopp, 2") << QMediaPlaylist::Loop << 1 << 2 << 0; + + QTest::newRow("ItemOnce, 1") << QMediaPlaylist::CurrentItemOnce << -1 << 1 << -1; + QTest::newRow("ItemInLoop, 1") << QMediaPlaylist::CurrentItemInLoop << 1 << 1 << 1; + + // Bit difficult to test random this way +} + +void tst_QMediaPlaylist::playbackMode() +{ + QFETCH(QMediaPlaylist::PlaybackMode, playbackMode); + QFETCH(int, expectedPrevious); + QFETCH(int, pos); + QFETCH(int, expectedNext); + + QMediaPlaylist playlist; + playlist.addMedia(content1); + playlist.addMedia(content2); + playlist.addMedia(content3); + + QCOMPARE(playlist.playbackMode(), QMediaPlaylist::Sequential); + QCOMPARE(playlist.currentIndex(), -1); + + playlist.setPlaybackMode(playbackMode); + QCOMPARE(playlist.playbackMode(), playbackMode); + + playlist.setCurrentIndex(pos); + QCOMPARE(playlist.currentIndex(), pos); + QCOMPARE(playlist.nextIndex(), expectedNext); + QCOMPARE(playlist.previousIndex(), expectedPrevious); + + playlist.next(); + QCOMPARE(playlist.currentIndex(), expectedNext); + + playlist.setCurrentIndex(pos); + playlist.previous(); + QCOMPARE(playlist.currentIndex(), expectedPrevious); +} + +void tst_QMediaPlaylist::shuffle() +{ + QMediaPlaylist playlist; + QList contentList; + + for (int i=0; i<100; i++) { + QMediaContent content(QUrl::fromLocalFile(QString::number(i))); + contentList.append(content); + playlist.addMedia(content); + } + + playlist.shuffle(); + + QList shuffledContentList; + for (int i=0; i() << content1 << content2)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(!playlist.insertMedia(1, content1)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(!playlist.insertMedia(1, QList() << content1 << content2)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(!playlist.removeMedia(1)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(!playlist.removeMedia(0,2)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(!playlist.clear()); + QCOMPARE(playlist.mediaCount(), 3); + + //but it is still allowed to append/insert an empty list + QVERIFY(playlist.addMedia(QList())); + QVERIFY(playlist.insertMedia(1, QList())); + + playlist.shuffle(); + //it's still the same + QCOMPARE(playlist.media(0), content1); + QCOMPARE(playlist.media(1), content2); + QCOMPARE(playlist.media(2), content3); + QCOMPARE(playlist.media(3), QMediaContent()); + + + //load to read only playlist should fail, + //unless underlaying provider supports it + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + buffer.write(QByteArray("file:///1\nfile:///2")); + buffer.seek(0); + + QSignalSpy errorSignal(&playlist, SIGNAL(loadFailed())); + playlist.load(&buffer, "m3u"); + QCOMPARE(errorSignal.size(), 1); + QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError); + QVERIFY(!playlist.errorString().isEmpty()); + QCOMPARE(playlist.mediaCount(), 3); + + errorSignal.clear(); + playlist.load(QUrl::fromLocalFile(QLatin1String("tmp.m3u")), "m3u"); + + QCOMPARE(errorSignal.size(), 1); + QCOMPARE(playlist.error(), QMediaPlaylist::AccessDeniedError); + QVERIFY(!playlist.errorString().isEmpty()); + QCOMPARE(playlist.mediaCount(), 3); +} + +void tst_QMediaPlaylist::setMediaObject() +{ + MockReadOnlyPlaylistObject mediaObject; + + QMediaPlaylist playlist; + QVERIFY(playlist.mediaObject() == 0); + QVERIFY(!playlist.isReadOnly()); + + mediaObject.bind(&playlist); + QCOMPARE(playlist.mediaObject(), qobject_cast(&mediaObject)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(playlist.isReadOnly()); + + mediaObject.unbind(&playlist); + QVERIFY(playlist.mediaObject() == 0); + QCOMPARE(playlist.mediaCount(), 0); + QVERIFY(!playlist.isReadOnly()); + + mediaObject.bind(&playlist); + QCOMPARE(playlist.mediaObject(), qobject_cast(&mediaObject)); + QCOMPARE(playlist.mediaCount(), 3); + QVERIFY(playlist.isReadOnly()); +} + +void tst_QMediaPlaylist::testCurrentIndexChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(currentIndexChanged(int))); + QVERIFY(spy.size()== 0); + QCOMPARE(playlist.currentIndex(), -1); + + //set the current index for playlist. + playlist.setCurrentIndex(0); + QVERIFY(spy.size()== 1); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 0); //verify the current index of playlist + + //set the current index for playlist. + playlist.setCurrentIndex(1); + QVERIFY(spy.size()== 2); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 1); //verify the current index of playlist +} + +void tst_QMediaPlaylist::testCurrentMediaChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(currentMediaChanged(QMediaContent))); + QVERIFY(spy.size()== 0); + QCOMPARE(playlist.currentIndex(), -1); + QCOMPARE(playlist.currentMedia(), QMediaContent()); + + //set the current index for playlist. + playlist.setCurrentIndex(0); + QVERIFY(spy.size()== 1); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 0); //verify the current index of playlist + QCOMPARE(playlist.currentMedia(), content1); //verify the current media of playlist + + //set the current index for playlist. + playlist.setCurrentIndex(1); + QVERIFY(spy.size()== 2); //verify the signal emission. + QCOMPARE(playlist.currentIndex(), 1); //verify the current index of playlist + QCOMPARE(playlist.currentMedia(), content2); //verify the current media of playlist +} + +void tst_QMediaPlaylist::testLoaded_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(loaded())); + QVERIFY(spy.size()== 0); + + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + + //load the playlist + playlist.load(&buffer,"m3u"); + QVERIFY(spy.size()== 1); //verify the signal emission. +} + +void tst_QMediaPlaylist::testMediaChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + + QSignalSpy spy(&playlist, SIGNAL(mediaChanged(int,int))); + + // Add media to playlist + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + // Adds/inserts do not cause change signals + QVERIFY(spy.size() == 0); + + // Now change the list + playlist.shuffle(); + + QVERIFY(spy.size() == 1); + spy.clear(); + + //create media. + QMediaContent content4(QUrl(QLatin1String("file:///4"))); + QMediaContent content5(QUrl(QLatin1String("file:///5"))); + + //insert media to playlist + playlist.insertMedia(1, content4); + playlist.insertMedia(2, content5); + // Adds/inserts do not cause change signals + QVERIFY(spy.size() == 0); + + // And again + playlist.shuffle(); + + QVERIFY(spy.size() == 1); +} + +void tst_QMediaPlaylist::testPlaybackModeChanged_signal() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + + QSignalSpy spy(&playlist, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Sequential); + QVERIFY(spy.size() == 0); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::CurrentItemOnce); + QVERIFY(spy.size() == 1); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::CurrentItemInLoop); + QVERIFY(spy.size() == 2); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Sequential); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Sequential); + QVERIFY(spy.size() == 3); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Loop); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Loop); + QVERIFY(spy.size() == 4); + + // Set playback mode to the playlist + playlist.setPlaybackMode(QMediaPlaylist::Random); + QVERIFY(playlist.playbackMode()== QMediaPlaylist::Random); + QVERIFY(spy.size() == 5); +} + +void tst_QMediaPlaylist::testEnums() +{ + //create an instance of QMediaPlaylist class. + QMediaPlaylist playlist; + playlist.addMedia(content1); //set the media to playlist + playlist.addMedia(content2); //set the media to playlist + playlist.addMedia(content3); //set the media to playlist + QCOMPARE(playlist.error(), QMediaPlaylist::NoError); + + QBuffer buffer; + buffer.open(QBuffer::ReadWrite); + + // checking for QMediaPlaylist::FormatNotSupportedError enum + QVERIFY(!playlist.save(&buffer, "unsupported_format")); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); + + playlist.load(&buffer,"unsupported_format"); + QVERIFY(playlist.error() == QMediaPlaylist::FormatNotSupportedError); +} + +// MaemoAPI-1849:test QMediaPlayListControl constructor +void tst_QMediaPlaylist::mediaPlayListControl() +{ + // To check changes in abstract classe's pure virtual functions + QObject parent; + MockMediaPlaylistControl plylistctrl(&parent); +} + +// MaemoAPI-1850:test QMediaPlayListSourceControl constructor +void tst_QMediaPlaylist::mediaPlayListSourceControl() +{ + // To check changes in abstract classe's pure virtual functions + QObject parent; + MockPlaylistSourceControl plylistsrcctrl(&parent); +} + +// MaemoAPI-1852:test constructor +void tst_QMediaPlaylist::mediaPlayListProvider() +{ + // srcs of QMediaPlaylistProvider is incomplete + QObject parent; + MockReadOnlyPlaylistProvider provider(&parent); +} + +QTEST_MAIN(tst_QMediaPlaylist) +#include "tst_qmediaplaylist.moc" + diff --git a/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro b/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro new file mode 100644 index 000000000..305d63b50 --- /dev/null +++ b/tests/auto/unit/qmediaplaylistnavigator/qmediaplaylistnavigator.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qmediaplaylistnavigator + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaplaylistnavigator.cpp + diff --git a/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp b/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp new file mode 100644 index 000000000..a88884735 --- /dev/null +++ b/tests/auto/unit/qmediaplaylistnavigator/tst_qmediaplaylistnavigator.cpp @@ -0,0 +1,525 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include +#include "qlocalmediaplaylistprovider.h" +#include "qmediaplaylistnavigator.h" + +QT_USE_NAMESPACE +class tst_QMediaPlaylistNavigator : public QObject +{ + Q_OBJECT +public slots: + void init(); + void cleanup(); + +private slots: + void construction(); + void setPlaylist(); + void linearPlayback(); + void loopPlayback(); + void currentItemOnce(); + void currentItemInLoop(); + void randomPlayback(); + + void testItemAt(); + void testNextIndex(); + void testPreviousIndex(); + void testCurrentIndexChangedSignal(); + void testPlaybackModeChangedSignal(); + void testSurroundingItemsChangedSignal(); + void testActivatedSignal(); +}; + +void tst_QMediaPlaylistNavigator::init() +{ + qRegisterMetaType("QMediaPlaylist::PlaybackMode"); + qRegisterMetaType("QMediaContent"); +} + +void tst_QMediaPlaylistNavigator::cleanup() +{ +} + +void tst_QMediaPlaylistNavigator::construction() +{ + QLocalMediaPlaylistProvider playlist; + QCOMPARE(playlist.mediaCount(), 0); + + QMediaPlaylistNavigator navigator(&playlist); + QVERIFY(navigator.currentItem().isNull()); + QCOMPARE(navigator.currentIndex(), -1); +} + +void tst_QMediaPlaylistNavigator::setPlaylist() +{ + QMediaPlaylistNavigator navigator(0); + QVERIFY(navigator.playlist() != 0); + QCOMPARE(navigator.playlist()->mediaCount(), 0); + QCOMPARE(navigator.playlist()->media(0), QMediaContent()); + QVERIFY(navigator.playlist()->isReadOnly() ); + + QLocalMediaPlaylistProvider playlist; + QCOMPARE(playlist.mediaCount(), 0); + + navigator.setPlaylist(&playlist); + QCOMPARE(navigator.playlist(), (QMediaPlaylistProvider*)&playlist); + QCOMPARE(navigator.playlist()->mediaCount(), 0); + QVERIFY(!navigator.playlist()->isReadOnly() ); +} + +void tst_QMediaPlaylistNavigator::linearPlayback() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + + navigator.setPlaybackMode(QMediaPlaylist::Sequential); + QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range "); + navigator.jump(0);//it's ok to have warning here + QVERIFY(navigator.currentItem().isNull()); + QCOMPARE(navigator.currentIndex(), -1); + + QMediaContent content1(QUrl(QLatin1String("file:///1"))); + playlist.addMedia(content1); + navigator.jump(0); + QVERIFY(!navigator.currentItem().isNull()); + + QCOMPARE(navigator.currentIndex(), 0); + QCOMPARE(navigator.currentItem(), content1); + QCOMPARE(navigator.nextItem(), QMediaContent()); + QCOMPARE(navigator.nextItem(2), QMediaContent()); + QCOMPARE(navigator.previousItem(), QMediaContent()); + QCOMPARE(navigator.previousItem(2), QMediaContent()); + + QMediaContent content2(QUrl(QLatin1String("file:///2"))); + playlist.addMedia(content2); + QCOMPARE(navigator.currentIndex(), 0); + QCOMPARE(navigator.currentItem(), content1); + QCOMPARE(navigator.nextItem(), content2); + QCOMPARE(navigator.nextItem(2), QMediaContent()); + QCOMPARE(navigator.previousItem(), QMediaContent()); + QCOMPARE(navigator.previousItem(2), QMediaContent()); + + navigator.jump(1); + QCOMPARE(navigator.currentIndex(), 1); + QCOMPARE(navigator.currentItem(), content2); + QCOMPARE(navigator.nextItem(), QMediaContent()); + QCOMPARE(navigator.nextItem(2), QMediaContent()); + QCOMPARE(navigator.previousItem(), content1); + QCOMPARE(navigator.previousItem(2), QMediaContent()); + + navigator.jump(0); + navigator.next(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.next();//jump to the first item + QCOMPARE(navigator.currentIndex(), 0); + + navigator.previous(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.previous();//jump to the last item + QCOMPARE(navigator.currentIndex(), 1); +} + +void tst_QMediaPlaylistNavigator::loopPlayback() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + + navigator.setPlaybackMode(QMediaPlaylist::Loop); + QTest::ignoreMessage(QtWarningMsg, "QMediaPlaylistNavigator: Jump outside playlist range "); + navigator.jump(0); + QVERIFY(navigator.currentItem().isNull()); + QCOMPARE(navigator.currentIndex(), -1); + + QMediaContent content1(QUrl(QLatin1String("file:///1"))); + playlist.addMedia(content1); + navigator.jump(0); + QVERIFY(!navigator.currentItem().isNull()); + + QCOMPARE(navigator.currentIndex(), 0); + QCOMPARE(navigator.currentItem(), content1); + QCOMPARE(navigator.nextItem(), content1); + QCOMPARE(navigator.nextItem(2), content1); + QCOMPARE(navigator.previousItem(), content1); + QCOMPARE(navigator.previousItem(2), content1); + + QMediaContent content2(QUrl(QLatin1String("file:///2"))); + playlist.addMedia(content2); + QCOMPARE(navigator.currentIndex(), 0); + QCOMPARE(navigator.currentItem(), content1); + QCOMPARE(navigator.nextItem(), content2); + QCOMPARE(navigator.nextItem(2), content1); //loop over end of the list + QCOMPARE(navigator.previousItem(), content2); + QCOMPARE(navigator.previousItem(2), content1); + + navigator.jump(1); + QCOMPARE(navigator.currentIndex(), 1); + QCOMPARE(navigator.currentItem(), content2); + QCOMPARE(navigator.nextItem(), content1); + QCOMPARE(navigator.nextItem(2), content2); + QCOMPARE(navigator.previousItem(), content1); + QCOMPARE(navigator.previousItem(2), content2); + + navigator.jump(0); + navigator.next(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), 0); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), 0); +} + +void tst_QMediaPlaylistNavigator::currentItemOnce() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + + navigator.setPlaybackMode(QMediaPlaylist::CurrentItemOnce); + + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemOnce); + QCOMPARE(navigator.currentIndex(), -1); + + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), -1); + + navigator.jump(1); + QCOMPARE(navigator.currentIndex(), 1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.jump(1); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), -1); +} + +void tst_QMediaPlaylistNavigator::currentItemInLoop() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + + navigator.setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); + + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::CurrentItemInLoop); + QCOMPARE(navigator.currentIndex(), -1); + + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), -1); + navigator.jump(1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.next(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), 1); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), 1); +} + +void tst_QMediaPlaylistNavigator::randomPlayback() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + + navigator.setPlaybackMode(QMediaPlaylist::Random); + + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + playlist.shuffle(); + + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + int pos1 = navigator.currentIndex(); + navigator.next(); + int pos2 = navigator.currentIndex(); + navigator.next(); + int pos3 = navigator.currentIndex(); + + QVERIFY(pos1 != -1); + QVERIFY(pos2 != -1); + QVERIFY(pos3 != -1); + + navigator.previous(); + QCOMPARE(navigator.currentIndex(), pos2); + navigator.next(); + QCOMPARE(navigator.currentIndex(), pos3); + navigator.next(); + int pos4 = navigator.currentIndex(); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), pos3); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), pos2); + navigator.previous(); + QCOMPARE(navigator.currentIndex(), pos1); + navigator.previous(); + int pos0 = navigator.currentIndex(); + QVERIFY(pos0 != -1); + navigator.next(); + navigator.next(); + navigator.next(); + navigator.next(); + QCOMPARE(navigator.currentIndex(), pos4); + +} + +void tst_QMediaPlaylistNavigator::testItemAt() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + QMediaContent content = QMediaContent(QUrl(QLatin1String("file:///1"))); + playlist.addMedia(content); + + //Currently it is not pointing to any index , Returns Null mediacontent + QCOMPARE(navigator.currentIndex(), -1); + QCOMPARE(navigator.itemAt(navigator.currentIndex()),QMediaContent()); + navigator.next(); + + //Points to the added media + int pos1 = navigator.currentIndex(); + QCOMPARE(content,navigator.itemAt(pos1)); +} + +void tst_QMediaPlaylistNavigator::testNextIndex() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + playlist.shuffle(); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + int pos1 = navigator.currentIndex(); + //Pointing to the next index + navigator.next(); + int pos2 = navigator.currentIndex(); + navigator.next(); + int pos3 = navigator.currentIndex(); + + //Pointing to the previous index + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos3); + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos2); + QCOMPARE(navigator.nextIndex(2), pos3); + navigator.previous(); + QCOMPARE(navigator.nextIndex(1), pos1); +} + +void tst_QMediaPlaylistNavigator::testPreviousIndex() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + playlist.shuffle(); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + + //pointing to next index + navigator.next(); + int pos1 = navigator.currentIndex(); + navigator.next(); + int pos2 = navigator.currentIndex(); + navigator.next(); + int pos3 = navigator.currentIndex(); + QCOMPARE(navigator.previousIndex(1), pos2); + QCOMPARE(navigator.previousIndex(2), pos1); + navigator.next(); + QCOMPARE(navigator.previousIndex(1), pos3); +} + +void tst_QMediaPlaylistNavigator::testCurrentIndexChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for currentIndexChanged() signal + QSignalSpy spy(&navigator,SIGNAL(currentIndexChanged(int))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///3")))); + + //Currently it is not pointing to any index + QCOMPARE(navigator.currentIndex(), -1); + navigator.next(); + QVERIFY(spy.count() == 1); + int pos1 = navigator.currentIndex(); + //Pointing to the next index + navigator.next(); + QVERIFY(navigator.previousIndex(1) == pos1); + QVERIFY(spy.count() == 2); +} + +void tst_QMediaPlaylistNavigator::testPlaybackModeChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for currentIndexChanged() signal + QSignalSpy spy(&navigator,SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + + //set the play back mode to sequential + navigator.setPlaybackMode(QMediaPlaylist::Sequential); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); + QVERIFY(spy.count() == 1); + + //set the play back mode to loop + navigator.setPlaybackMode(QMediaPlaylist::Loop); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Loop); + QVERIFY(spy.count() == 2); +} + +void tst_QMediaPlaylistNavigator::testSurroundingItemsChangedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for surroundingItemsChanged()signal + QSignalSpy spy(&navigator,SIGNAL(surroundingItemsChanged())); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + QVERIFY(spy.count() == 1); + + //set the play back mode to sequential + navigator.setPlaybackMode(QMediaPlaylist::Sequential); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Sequential); + QVERIFY(spy.count() == 2); + + //Point to the next index + navigator.next(); + QVERIFY(spy.count() == 3); +} + +void tst_QMediaPlaylistNavigator::testActivatedSignal() +{ + QLocalMediaPlaylistProvider playlist; + QMediaPlaylistNavigator navigator(&playlist); + navigator.setPlaybackMode(QMediaPlaylist::Random); + QCOMPARE(navigator.playbackMode(), QMediaPlaylist::Random); + QCOMPARE(navigator.currentIndex(), -1); + + //Creating a QSignalSpy object for surroundingItemsChanged()signal + QSignalSpy spy(&navigator,SIGNAL(activated(QMediaContent))); + QVERIFY(spy.count() == 0); + + //Adding the media to the playlist + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///1")))); + playlist.addMedia(QMediaContent(QUrl(QLatin1String("file:///2")))); + playlist.shuffle(); + + //Point to the next index + navigator.next(); + QVERIFY(spy.count() == 1); + + //Jump to 0th item + navigator.jump(0); + QVERIFY(spy.count() == 2); + + //move to previous item + navigator.previous(); + QVERIFY(spy.count() == 3); +} + +QTEST_MAIN(tst_QMediaPlaylistNavigator) +#include "tst_qmediaplaylistnavigator.moc" diff --git a/tests/auto/unit/qmediapluginloader/qmediapluginloader.pro b/tests/auto/unit/qmediapluginloader/qmediapluginloader.pro new file mode 100644 index 000000000..f5947c6a4 --- /dev/null +++ b/tests/auto/unit/qmediapluginloader/qmediapluginloader.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +TARGET = tst_qmediapluginloader + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediapluginloader.cpp + +wince* { + PLUGIN_DEPLOY.sources = $$OUTPUT_DIR/plugins/mediaservice/*.dll + PLUGIN_DEPLOY.path = mediaservice + DEPLOYMENT += PLUGIN_DEPLOY +} + diff --git a/tests/auto/unit/qmediapluginloader/tst_qmediapluginloader.cpp b/tests/auto/unit/qmediapluginloader/tst_qmediapluginloader.cpp new file mode 100644 index 000000000..198d950a2 --- /dev/null +++ b/tests/auto/unit/qmediapluginloader/tst_qmediapluginloader.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include + +QT_USE_NAMESPACE + +class tst_QMediaPluginLoader : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testInstance(); + void testInstances(); + void testInvalidKey(); + +private: + QMediaPluginLoader *loader; +}; + +void tst_QMediaPluginLoader::initTestCase() +{ + loader = new QMediaPluginLoader(QMediaServiceProviderFactoryInterface_iid, + QLatin1String("/mediaservice"), + Qt::CaseInsensitive); +} + +void tst_QMediaPluginLoader::cleanupTestCase() +{ + delete loader; +} + +void tst_QMediaPluginLoader::testInstance() +{ + const QStringList keys = loader->keys(); + + if (keys.isEmpty()) // Test is invalidated, skip. + QSKIP("No plug-ins available", SkipAll); + + foreach (const QString &key, keys) + QVERIFY(loader->instance(key) != 0); +} + +void tst_QMediaPluginLoader::testInstances() +{ + const QStringList keys = loader->keys(); + + if (keys.isEmpty()) // Test is invalidated, skip. + QSKIP("No plug-ins available", SkipAll); + + foreach (const QString &key, keys) + QVERIFY(loader->instances(key).size() > 0); +} + +// Last so as to not interfere with the other tests if there is a failure. +void tst_QMediaPluginLoader::testInvalidKey() +{ + const QString key(QLatin1String("invalid-key")); + + // This test assumes there is no 'invalid-key' in the key list, verify that. + if (loader->keys().contains(key)) + QSKIP("a plug-in includes the invalid key", SkipAll); + + QVERIFY(loader->instance(key) == 0); + + // Test looking up the key hasn't inserted it into the list. See QMap::operator[]. + QVERIFY(!loader->keys().contains(key)); + + QVERIFY(loader->instances(key).isEmpty()); + QVERIFY(!loader->keys().contains(key)); +} + +QTEST_MAIN(tst_QMediaPluginLoader) + +#include "tst_qmediapluginloader.moc" diff --git a/tests/auto/unit/qmediarecorder/main.cpp b/tests/auto/unit/qmediarecorder/main.cpp new file mode 100755 index 000000000..cda3faf21 --- /dev/null +++ b/tests/auto/unit/qmediarecorder/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qmediarecorder.h" + +int main(int argc, char**argv) +{ + QCoreApplication app(argc,argv); + int ret; + tst_QMediaRecorder test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qmediarecorder/qmediarecorder.pro b/tests/auto/unit/qmediarecorder/qmediarecorder.pro new file mode 100644 index 000000000..1efaba0fc --- /dev/null +++ b/tests/auto/unit/qmediarecorder/qmediarecorder.pro @@ -0,0 +1,12 @@ +CONFIG += testcase +TARGET = tst_qmediarecorder + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockrecorder.pri) + +HEADERS += tst_qmediarecorder.h +SOURCES += main.cpp tst_qmediarecorder.cpp + diff --git a/tests/auto/unit/qmediarecorder/tst_qmediarecorder.cpp b/tests/auto/unit/qmediarecorder/tst_qmediarecorder.cpp new file mode 100644 index 000000000..d99d73cfb --- /dev/null +++ b/tests/auto/unit/qmediarecorder/tst_qmediarecorder.cpp @@ -0,0 +1,1286 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qmediarecorder.h" + +QT_USE_NAMESPACE + +void tst_QMediaRecorder::initTestCase() +{ + qRegisterMetaType("QMediaRecorder::State"); + qRegisterMetaType("QMediaRecorder::Error"); + + mock = new MockMediaRecorderControl(this); + service = new MockMediaRecorderService(this, mock); + object = new MockMediaObject(this, service); + capture = new QMediaRecorder(object); + + audio = qobject_cast(service->requestControl(QAudioEndpointSelector_iid)); + encode = qobject_cast(service->requestControl(QAudioEncoderControl_iid)); + videoEncode = qobject_cast(service->requestControl(QVideoEncoderControl_iid)); +} + +void tst_QMediaRecorder::cleanupTestCase() +{ + delete capture; + delete object; + delete service; + delete mock; +} + +void tst_QMediaRecorder::testNullService() +{ + const QString id(QLatin1String("application/x-format")); + + MockMediaObject object(0, 0); + QMediaRecorder recorder(&object); + + QCOMPARE(recorder.outputLocation(), QUrl()); + QCOMPARE(recorder.state(), QMediaRecorder::StoppedState); + QCOMPARE(recorder.error(), QMediaRecorder::NoError); + QCOMPARE(recorder.duration(), qint64(0)); + QCOMPARE(recorder.supportedContainers(), QStringList()); + QCOMPARE(recorder.containerDescription(id), QString()); + QCOMPARE(recorder.supportedAudioCodecs(), QStringList()); + QCOMPARE(recorder.audioCodecDescription(id), QString()); + QCOMPARE(recorder.supportedAudioSampleRates(), QList()); + QCOMPARE(recorder.supportedVideoCodecs(), QStringList()); + QCOMPARE(recorder.videoCodecDescription(id), QString()); + bool continuous = true; + QCOMPARE(recorder.supportedResolutions(QVideoEncoderSettings(), &continuous), QList()); + QCOMPARE(continuous, false); + continuous = true; + QCOMPARE(recorder.supportedFrameRates(QVideoEncoderSettings(), &continuous), QList()); + QCOMPARE(continuous, false); + QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings()); + QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings()); + QCOMPARE(recorder.containerMimeType(), QString()); + QVERIFY(!recorder.isMuted()); + recorder.setMuted(true); + QVERIFY(!recorder.isMuted()); +} + +void tst_QMediaRecorder::testNullControls() +{ + const QString id(QLatin1String("application/x-format")); + + MockMediaRecorderService service(0, 0); + service.hasControls = false; + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + + QCOMPARE(recorder.outputLocation(), QUrl()); + QCOMPARE(recorder.state(), QMediaRecorder::StoppedState); + QCOMPARE(recorder.error(), QMediaRecorder::NoError); + QCOMPARE(recorder.duration(), qint64(0)); + QCOMPARE(recorder.supportedContainers(), QStringList()); + QCOMPARE(recorder.containerDescription(id), QString()); + QCOMPARE(recorder.supportedAudioCodecs(), QStringList()); + QCOMPARE(recorder.audioCodecDescription(id), QString()); + QCOMPARE(recorder.supportedAudioSampleRates(), QList()); + QCOMPARE(recorder.supportedVideoCodecs(), QStringList()); + QCOMPARE(recorder.videoCodecDescription(id), QString()); + bool continuous = true; + QCOMPARE(recorder.supportedResolutions(QVideoEncoderSettings(), &continuous), QList()); + QCOMPARE(continuous, false); + continuous = true; + QCOMPARE(recorder.supportedFrameRates(QVideoEncoderSettings(), &continuous), QList()); + QCOMPARE(continuous, false); + QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings()); + QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings()); + QCOMPARE(recorder.containerMimeType(), QString()); + + recorder.setOutputLocation(QUrl("file://test/save/file.mp4")); + QCOMPARE(recorder.outputLocation(), QUrl()); + + QAudioEncoderSettings audio; + audio.setCodec(id); + audio.setQuality(QtMultimedia::LowQuality); + + QVideoEncoderSettings video; + video.setCodec(id); + video.setResolution(640, 480); + + recorder.setEncodingSettings(audio, video, id); + + QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings()); + QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings()); + QCOMPARE(recorder.containerMimeType(), QString()); + + QSignalSpy spy(&recorder, SIGNAL(stateChanged(QMediaRecorder::State))); + + recorder.record(); + QCOMPARE(recorder.state(), QMediaRecorder::StoppedState); + QCOMPARE(recorder.error(), QMediaRecorder::NoError); + QCOMPARE(spy.count(), 0); + + recorder.pause(); + QCOMPARE(recorder.state(), QMediaRecorder::StoppedState); + QCOMPARE(recorder.error(), QMediaRecorder::NoError); + QCOMPARE(spy.count(), 0); + + recorder.stop(); + QCOMPARE(recorder.state(), QMediaRecorder::StoppedState); + QCOMPARE(recorder.error(), QMediaRecorder::NoError); + QCOMPARE(spy.count(), 0); +} + +void tst_QMediaRecorder::testDeleteMediaObject() +{ + MockMediaRecorderControl *mock = new MockMediaRecorderControl(this); + MockMediaRecorderService *service = new MockMediaRecorderService(this, mock); + MockMediaObject *object = new MockMediaObject(this, service); + QMediaRecorder *capture = new QMediaRecorder(object); + + QVERIFY(capture->mediaObject() == object); + QVERIFY(capture->isAvailable()); + + delete object; + delete service; + delete mock; + + QVERIFY(capture->mediaObject() == 0); + QVERIFY(!capture->isAvailable()); + + delete capture; +} + +void tst_QMediaRecorder::testError() +{ + const QString errorString(QLatin1String("format error")); + + QSignalSpy spy(capture, SIGNAL(error(QMediaRecorder::Error))); + + QCOMPARE(capture->error(), QMediaRecorder::NoError); + QCOMPARE(capture->errorString(), QString()); + + mock->error(QMediaRecorder::FormatError, errorString); + QCOMPARE(capture->error(), QMediaRecorder::FormatError); + QCOMPARE(capture->errorString(), errorString); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.last()[0].value(), QMediaRecorder::FormatError); +} + +void tst_QMediaRecorder::testSink() +{ + capture->setOutputLocation(QUrl("test.tmp")); + QUrl s = capture->outputLocation(); + QCOMPARE(s.toString(), QString("test.tmp")); +} + +void tst_QMediaRecorder::testRecord() +{ + QSignalSpy stateSignal(capture,SIGNAL(stateChanged(QMediaRecorder::State))); + QSignalSpy progressSignal(capture, SIGNAL(durationChanged(qint64))); + capture->record(); + QCOMPARE(capture->state(), QMediaRecorder::RecordingState); + QCOMPARE(capture->error(), QMediaRecorder::NoError); + QCOMPARE(capture->errorString(), QString()); + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(stateSignal.count(), 1); + QCOMPARE(stateSignal.last()[0].value(), QMediaRecorder::RecordingState); + QVERIFY(progressSignal.count() > 0); + capture->pause(); + QCOMPARE(capture->state(), QMediaRecorder::PausedState); + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(stateSignal.count(), 2); + capture->stop(); + QCOMPARE(capture->state(), QMediaRecorder::StoppedState); + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(stateSignal.count(), 3); + mock->stop(); + QCOMPARE(stateSignal.count(), 3); + +} + +void tst_QMediaRecorder::testMute() +{ + QSignalSpy mutedChanged(capture, SIGNAL(mutedChanged(bool))); + QVERIFY(!capture->isMuted()); + capture->setMuted(true); + + QCOMPARE(mutedChanged.size(), 1); + QCOMPARE(mutedChanged[0][0].toBool(), true); + QVERIFY(capture->isMuted()); + + capture->setMuted(false); + + QCOMPARE(mutedChanged.size(), 2); + QCOMPARE(mutedChanged[1][0].toBool(), false); + QVERIFY(!capture->isMuted()); + + capture->setMuted(false); + QCOMPARE(mutedChanged.size(), 2); +} + +void tst_QMediaRecorder::testAudioDeviceControl() +{ + QSignalSpy readSignal(audio,SIGNAL(activeEndpointChanged(QString))); + QVERIFY(audio->availableEndpoints().size() == 3); + QVERIFY(audio->defaultEndpoint().compare("device1") == 0); + audio->setActiveEndpoint("device2"); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(audio->activeEndpoint().compare("device2") == 0); + QVERIFY(readSignal.count() == 1); + QVERIFY(audio->endpointDescription("device2").compare("dev2 comment") == 0); +} + +void tst_QMediaRecorder::testAudioEncodeControl() +{ + QStringList codecs = capture->supportedAudioCodecs(); + QVERIFY(codecs.count() == 2); + QVERIFY(capture->audioCodecDescription("audio/pcm") == "Pulse Code Modulation"); + QStringList options = encode->supportedEncodingOptions("audio/mpeg"); + QCOMPARE(options.count(), 4); + QVERIFY(encode->encodingOption("audio/mpeg","bitrate").isNull()); + encode->setEncodingOption("audio/mpeg", "bitrate", QString("vbr")); + QCOMPARE(encode->encodingOption("audio/mpeg","bitrate").toString(), QString("vbr")); + QList rates; + rates << 8000 << 11025 << 22050 << 44100; + QCOMPARE(capture->supportedAudioSampleRates(), rates); +} + +void tst_QMediaRecorder::testMediaFormatsControl() +{ + QCOMPARE(capture->supportedContainers(), QStringList() << "wav" << "mp3" << "mov"); + + QCOMPARE(capture->containerDescription("wav"), QString("WAV format")); + QCOMPARE(capture->containerDescription("mp3"), QString("MP3 format")); + QCOMPARE(capture->containerDescription("ogg"), QString()); +} + +void tst_QMediaRecorder::testVideoEncodeControl() +{ + bool continuous = false; + QList sizes = capture->supportedResolutions(QVideoEncoderSettings(), &continuous); + QCOMPARE(sizes.count(), 2); + QCOMPARE(continuous, true); + + QList rates = capture->supportedFrameRates(QVideoEncoderSettings(), &continuous); + QCOMPARE(rates.count(), 3); + QCOMPARE(continuous, false); + + QStringList vCodecs = capture->supportedVideoCodecs(); + QVERIFY(vCodecs.count() == 2); + QCOMPARE(capture->videoCodecDescription("video/3gpp"), QString("video/3gpp")); + + QStringList options = videoEncode->supportedEncodingOptions("video/3gpp"); + QCOMPARE(options.count(), 2); + + QVERIFY(encode->encodingOption("video/3gpp","me").isNull()); + encode->setEncodingOption("video/3gpp", "me", QString("dia")); + QCOMPARE(encode->encodingOption("video/3gpp","me").toString(), QString("dia")); + +} + +void tst_QMediaRecorder::testEncodingSettings() +{ + QAudioEncoderSettings audioSettings = capture->audioSettings(); + QCOMPARE(audioSettings.codec(), QString("audio/pcm")); + QCOMPARE(audioSettings.bitRate(), 128*1024); + QCOMPARE(audioSettings.sampleRate(), 8000); + QCOMPARE(audioSettings.quality(), QtMultimedia::NormalQuality); + QCOMPARE(audioSettings.channelCount(), -1); + + QCOMPARE(audioSettings.encodingMode(), QtMultimedia::ConstantQualityEncoding); + + QVideoEncoderSettings videoSettings = capture->videoSettings(); + QCOMPARE(videoSettings.codec(), QString()); + QCOMPARE(videoSettings.bitRate(), -1); + QCOMPARE(videoSettings.resolution(), QSize()); + QCOMPARE(videoSettings.frameRate(), 0.0); + QCOMPARE(videoSettings.quality(), QtMultimedia::NormalQuality); + QCOMPARE(videoSettings.encodingMode(), QtMultimedia::ConstantQualityEncoding); + + QString format = capture->containerMimeType(); + QCOMPARE(format, QString()); + + audioSettings.setCodec("audio/mpeg"); + audioSettings.setSampleRate(44100); + audioSettings.setBitRate(256*1024); + audioSettings.setQuality(QtMultimedia::HighQuality); + audioSettings.setEncodingMode(QtMultimedia::AverageBitRateEncoding); + + videoSettings.setCodec("video/3gpp"); + videoSettings.setBitRate(800); + videoSettings.setFrameRate(24*1024); + videoSettings.setResolution(QSize(800,600)); + videoSettings.setQuality(QtMultimedia::HighQuality); + audioSettings.setEncodingMode(QtMultimedia::TwoPassEncoding); + + format = QString("mov"); + + capture->setEncodingSettings(audioSettings,videoSettings,format); + + QCOMPARE(capture->audioSettings(), audioSettings); + QCOMPARE(capture->videoSettings(), videoSettings); + QCOMPARE(capture->containerMimeType(), format); +} + +void tst_QMediaRecorder::testAudioSettings() +{ + QAudioEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QAudioEncoderSettings()); + + QCOMPARE(settings.codec(), QString()); + settings.setCodec(QLatin1String("codecName")); + QCOMPARE(settings.codec(), QLatin1String("codecName")); + QVERIFY(!settings.isNull()); + QVERIFY(settings != QAudioEncoderSettings()); + + settings = QAudioEncoderSettings(); + QCOMPARE(settings.bitRate(), -1); + settings.setBitRate(128000); + QCOMPARE(settings.bitRate(), 128000); + QVERIFY(!settings.isNull()); + + settings = QAudioEncoderSettings(); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + settings.setQuality(QtMultimedia::HighQuality); + QCOMPARE(settings.quality(), QtMultimedia::HighQuality); + QVERIFY(!settings.isNull()); + + settings = QAudioEncoderSettings(); + QCOMPARE(settings.sampleRate(), -1); + settings.setSampleRate(44100); + QCOMPARE(settings.sampleRate(), 44100); + QVERIFY(!settings.isNull()); + + settings = QAudioEncoderSettings(); + QCOMPARE(settings.channelCount(), -1); + settings.setChannelCount(2); + QCOMPARE(settings.channelCount(), 2); + QVERIFY(!settings.isNull()); + + settings = QAudioEncoderSettings(); + QVERIFY(settings.isNull()); + QCOMPARE(settings.codec(), QString()); + QCOMPARE(settings.bitRate(), -1); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + QCOMPARE(settings.sampleRate(), -1); + + { + QAudioEncoderSettings settings1; + QAudioEncoderSettings settings2; + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + { + QAudioEncoderSettings settings1; + QAudioEncoderSettings settings2(settings1); + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + QAudioEncoderSettings settings1; + settings1.setBitRate(1); + QAudioEncoderSettings settings2; + settings2.setBitRate(1); + QVERIFY(settings1 == settings2); + settings2.setBitRate(2); + QVERIFY(settings1 != settings2); + + settings1 = QAudioEncoderSettings(); + settings1.setChannelCount(1); + settings2 = QAudioEncoderSettings(); + settings2.setChannelCount(1); + QVERIFY(settings1 == settings2); + settings2.setChannelCount(2); + QVERIFY(settings1 != settings2); + + settings1 = QAudioEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QAudioEncoderSettings(); + settings2.setCodec("codec1"); + QVERIFY(settings1 == settings2); + settings2.setCodec("codec2"); + QVERIFY(settings1 != settings2); + + settings1 = QAudioEncoderSettings(); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings2 = QAudioEncoderSettings(); + settings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + QVERIFY(settings1 == settings2); + settings2.setEncodingMode(QtMultimedia::TwoPassEncoding); + QVERIFY(settings1 != settings2); + + settings1 = QAudioEncoderSettings(); + settings1.setQuality(QtMultimedia::NormalQuality); + settings2 = QAudioEncoderSettings(); + settings2.setQuality(QtMultimedia::NormalQuality); + QVERIFY(settings1 == settings2); + settings2.setQuality(QtMultimedia::LowQuality); + QVERIFY(settings1 != settings2); + + settings1 = QAudioEncoderSettings(); + settings1.setSampleRate(1); + settings2 = QAudioEncoderSettings(); + settings2.setSampleRate(1); + QVERIFY(settings1 == settings2); + settings2.setSampleRate(2); + QVERIFY(settings1 != settings2); +} + +void tst_QMediaRecorder::testVideoSettings() +{ + QVideoEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QVideoEncoderSettings()); + + QCOMPARE(settings.codec(), QString()); + settings.setCodec(QLatin1String("codecName")); + QCOMPARE(settings.codec(), QLatin1String("codecName")); + QVERIFY(!settings.isNull()); + QVERIFY(settings != QVideoEncoderSettings()); + + settings = QVideoEncoderSettings(); + QCOMPARE(settings.bitRate(), -1); + settings.setBitRate(128000); + QCOMPARE(settings.bitRate(), 128000); + QVERIFY(!settings.isNull()); + + settings = QVideoEncoderSettings(); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + settings.setQuality(QtMultimedia::HighQuality); + QCOMPARE(settings.quality(), QtMultimedia::HighQuality); + QVERIFY(!settings.isNull()); + + settings = QVideoEncoderSettings(); + QCOMPARE(settings.frameRate(), qreal()); + settings.setFrameRate(30000.0/10001); + QVERIFY(qFuzzyCompare(settings.frameRate(), qreal(30000.0/10001))); + settings.setFrameRate(24.0); + QVERIFY(qFuzzyCompare(settings.frameRate(), qreal(24.0))); + QVERIFY(!settings.isNull()); + + settings = QVideoEncoderSettings(); + QCOMPARE(settings.resolution(), QSize()); + settings.setResolution(QSize(320,240)); + QCOMPARE(settings.resolution(), QSize(320,240)); + settings.setResolution(800,600); + QCOMPARE(settings.resolution(), QSize(800,600)); + QVERIFY(!settings.isNull()); + + settings = QVideoEncoderSettings(); + QVERIFY(settings.isNull()); + QCOMPARE(settings.codec(), QString()); + QCOMPARE(settings.bitRate(), -1); + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + QCOMPARE(settings.frameRate(), qreal()); + QCOMPARE(settings.resolution(), QSize()); + + { + QVideoEncoderSettings settings1; + QVideoEncoderSettings settings2; + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + { + QVideoEncoderSettings settings1; + QVideoEncoderSettings settings2(settings1); + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setQuality(QtMultimedia::HighQuality); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + QVideoEncoderSettings settings1; + settings1.setBitRate(1); + QVideoEncoderSettings settings2; + settings2.setBitRate(1); + QVERIFY(settings1 == settings2); + settings2.setBitRate(2); + QVERIFY(settings1 != settings2); + + settings1 = QVideoEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QVideoEncoderSettings(); + settings2.setResolution(QSize(800,600)); + QVERIFY(settings1 == settings2); + settings2.setResolution(QSize(400,300)); + QVERIFY(settings1 != settings2); + + settings1 = QVideoEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QVideoEncoderSettings(); + settings2.setCodec("codec1"); + QVERIFY(settings1 == settings2); + settings2.setCodec("codec2"); + QVERIFY(settings1 != settings2); + + settings1 = QVideoEncoderSettings(); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings2 = QVideoEncoderSettings(); + settings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + QVERIFY(settings1 == settings2); + settings2.setEncodingMode(QtMultimedia::TwoPassEncoding); + QVERIFY(settings1 != settings2); + + settings1 = QVideoEncoderSettings(); + settings1.setQuality(QtMultimedia::NormalQuality); + settings2 = QVideoEncoderSettings(); + settings2.setQuality(QtMultimedia::NormalQuality); + QVERIFY(settings1 == settings2); + settings2.setQuality(QtMultimedia::LowQuality); + QVERIFY(settings1 != settings2); + + settings1 = QVideoEncoderSettings(); + settings1.setFrameRate(1); + settings2 = QVideoEncoderSettings(); + settings2.setFrameRate(1); + QVERIFY(settings1 == settings2); + settings2.setFrameRate(2); + QVERIFY(settings1 != settings2); +} + + +void tst_QMediaRecorder::nullMetaDataControl() +{ + const QString titleKey(QLatin1String("Title")); + const QString title(QLatin1String("Host of Seraphim")); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.hasControls = false; + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + + QSignalSpy spy(&recorder, SIGNAL(metaDataChanged())); + + QCOMPARE(recorder.isMetaDataAvailable(), false); + QCOMPARE(recorder.isMetaDataWritable(), false); + + recorder.setMetaData(QtMultimedia::Title, title); + recorder.setExtendedMetaData(titleKey, title); + + QCOMPARE(recorder.metaData(QtMultimedia::Title).toString(), QString()); + QCOMPARE(recorder.extendedMetaData(titleKey).toString(), QString()); + QCOMPARE(recorder.availableMetaData(), QList()); + QCOMPARE(recorder.availableExtendedMetaData(), QStringList()); + QCOMPARE(spy.count(), 0); +} + +void tst_QMediaRecorder::isMetaDataAvailable() +{ + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.mockMetaDataControl->setMetaDataAvailable(false); + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + QCOMPARE(recorder.isMetaDataAvailable(), false); + + QSignalSpy spy(&recorder, SIGNAL(metaDataAvailableChanged(bool))); + service.mockMetaDataControl->setMetaDataAvailable(true); + + QCOMPARE(recorder.isMetaDataAvailable(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), true); + + service.mockMetaDataControl->setMetaDataAvailable(false); + + QCOMPARE(recorder.isMetaDataAvailable(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.at(1).at(0).toBool(), false); +} + +void tst_QMediaRecorder::isWritable() +{ + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.mockMetaDataControl->setWritable(false); + + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + + QSignalSpy spy(&recorder, SIGNAL(metaDataWritableChanged(bool))); + + QCOMPARE(recorder.isMetaDataWritable(), false); + + service.mockMetaDataControl->setWritable(true); + + QCOMPARE(recorder.isMetaDataWritable(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).at(0).toBool(), true); + + service.mockMetaDataControl->setWritable(false); + + QCOMPARE(recorder.isMetaDataWritable(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.at(1).at(0).toBool(), false); +} + +void tst_QMediaRecorder::metaDataChanged() +{ + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + + QSignalSpy spy(&recorder, SIGNAL(metaDataChanged())); + + service.mockMetaDataControl->metaDataChanged(); + QCOMPARE(spy.count(), 1); + + service.mockMetaDataControl->metaDataChanged(); + QCOMPARE(spy.count(), 2); +} + +void tst_QMediaRecorder::metaData_data() +{ + QTest::addColumn("artist"); + QTest::addColumn("title"); + QTest::addColumn("genre"); + + QTest::newRow("") + << QString::fromLatin1("Dead Can Dance") + << QString::fromLatin1("Host of Seraphim") + << QString::fromLatin1("Awesome"); +} + +void tst_QMediaRecorder::metaData() +{ + QFETCH(QString, artist); + QFETCH(QString, title); + QFETCH(QString, genre); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + QVERIFY(object.availableMetaData().isEmpty()); + + service.mockMetaDataControl->m_data.insert(QtMultimedia::AlbumArtist, artist); + service.mockMetaDataControl->m_data.insert(QtMultimedia::Title, title); + service.mockMetaDataControl->m_data.insert(QtMultimedia::Genre, genre); + + QCOMPARE(recorder.metaData(QtMultimedia::AlbumArtist).toString(), artist); + QCOMPARE(recorder.metaData(QtMultimedia::Title).toString(), title); + + QList metaDataKeys = recorder.availableMetaData(); + QCOMPARE(metaDataKeys.size(), 3); + QVERIFY(metaDataKeys.contains(QtMultimedia::AlbumArtist)); + QVERIFY(metaDataKeys.contains(QtMultimedia::Title)); + QVERIFY(metaDataKeys.contains(QtMultimedia::Genre)); +} + +void tst_QMediaRecorder::setMetaData_data() +{ + QTest::addColumn("title"); + + QTest::newRow("") + << QString::fromLatin1("In the Kingdom of the Blind the One eyed are Kings"); +} + +void tst_QMediaRecorder::setMetaData() +{ + QFETCH(QString, title); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + + recorder.setMetaData(QtMultimedia::Title, title); + QCOMPARE(recorder.metaData(QtMultimedia::Title).toString(), title); + QCOMPARE(service.mockMetaDataControl->m_data.value(QtMultimedia::Title).toString(), title); +} + +void tst_QMediaRecorder::extendedMetaData() +{ + QFETCH(QString, artist); + QFETCH(QString, title); + QFETCH(QString, genre); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + QVERIFY(recorder.availableExtendedMetaData().isEmpty()); + + service.mockMetaDataControl->m_extendedData.insert(QLatin1String("Artist"), artist); + service.mockMetaDataControl->m_extendedData.insert(QLatin1String("Title"), title); + service.mockMetaDataControl->m_extendedData.insert(QLatin1String("Genre"), genre); + + QCOMPARE(recorder.extendedMetaData(QLatin1String("Artist")).toString(), artist); + QCOMPARE(recorder.extendedMetaData(QLatin1String("Title")).toString(), title); + + QStringList extendedKeys = recorder.availableExtendedMetaData(); + QCOMPARE(extendedKeys.size(), 3); + QVERIFY(extendedKeys.contains(QLatin1String("Artist"))); + QVERIFY(extendedKeys.contains(QLatin1String("Title"))); + QVERIFY(extendedKeys.contains(QLatin1String("Genre"))); +} + +void tst_QMediaRecorder::setExtendedMetaData() +{ + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service(0, &recorderControl); + service.mockMetaDataControl->populateMetaData(); + + MockMediaObject object(0, &service); + + QMediaRecorder recorder(&object); + + QString title(QLatin1String("In the Kingdom of the Blind the One eyed are Kings")); + + recorder.setExtendedMetaData(QLatin1String("Title"), title); + QCOMPARE(recorder.extendedMetaData(QLatin1String("Title")).toString(), title); + QCOMPARE(service.mockMetaDataControl->m_extendedData.value(QLatin1String("Title")).toString(), title); +} + + +void tst_QMediaRecorder::testAudioSettingsCopyConstructor() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings; + QVERIFY(audiosettings.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings.setBitRate(128*1000); + audiosettings.setChannelCount(4); + audiosettings.setCodec("audio/pcm"); + audiosettings.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings.setQuality(QtMultimedia::LowQuality); + audiosettings.setSampleRate(44100); + + /* Copy constructor */ + QAudioEncoderSettings other(audiosettings); + QVERIFY(!(other.isNull())); + + /* Verifying whether data is copied properly or not */ + QVERIFY(other.bitRate() == audiosettings.bitRate()); + QVERIFY(other.sampleRate() == audiosettings.sampleRate()); + QVERIFY(other.channelCount() == audiosettings.channelCount()); + QCOMPARE(other.codec(), audiosettings.codec()); + QVERIFY(other.encodingMode() == audiosettings.encodingMode()); + QVERIFY(other.quality() == audiosettings.quality()); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorNotEqual() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + QAudioEncoderSettings audiosettings2; + QVERIFY(audiosettings2.isNull()); + + /* setting the desired properties to for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimedia::LowQuality); + audiosettings1.setSampleRate(44100); + + /* setting the desired properties for the AudioEncoder */ + audiosettings2.setBitRate(128*1000); + audiosettings2.setChannelCount(4); + audiosettings2.setCodec("audio/pcm"); + audiosettings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings2.setQuality(QtMultimedia::LowQuality); + audiosettings2.setSampleRate(44100); + + /* verify the both are equal or not */ + QVERIFY(!(audiosettings1 != audiosettings2)); + + /* Modify the settings value for one object */ + audiosettings2.setBitRate(64*1000); + audiosettings2.setEncodingMode(QtMultimedia::ConstantQualityEncoding); + + /* verify the not equal opertor */ + QVERIFY(audiosettings1 != audiosettings2); + + QVERIFY(audiosettings2.bitRate() != audiosettings1.bitRate()); + QVERIFY(audiosettings2.encodingMode() != audiosettings1.encodingMode()); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorEqual() +{ + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + /* setting the desired properties to for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimedia::LowQuality); + audiosettings1.setSampleRate(44100); + + QAudioEncoderSettings audiosettings2; + QVERIFY(audiosettings2.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings2.setBitRate(128*1000); + audiosettings2.setChannelCount(4); + audiosettings2.setCodec("audio/pcm"); + audiosettings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings2.setQuality(QtMultimedia::LowQuality); + audiosettings2.setSampleRate(44100); + + /* verify both the values are same or not */ + QVERIFY(audiosettings1 == audiosettings2); + audiosettings2.setChannelCount(2); + QVERIFY(audiosettings1 != audiosettings2); +} + +void tst_QMediaRecorder::testAudioSettingsOperatorAssign() +{ + + /* create an object for AudioEncodersettings */ + QAudioEncoderSettings audiosettings1; + QVERIFY(audiosettings1.isNull()); + + /* setting the desired properties for the AudioEncoder */ + audiosettings1.setBitRate(128*1000); + audiosettings1.setChannelCount(4); + audiosettings1.setCodec("audio/pcm"); + audiosettings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + audiosettings1.setQuality(QtMultimedia::LowQuality); + audiosettings1.setSampleRate(44100); + + QAudioEncoderSettings audiosettings2; + audiosettings2 = audiosettings1; + /* Verifying whether data is copied properly or not */ + QVERIFY(audiosettings2.bitRate() == audiosettings1.bitRate()); + QVERIFY(audiosettings2.sampleRate() == audiosettings1.sampleRate()); + QVERIFY(audiosettings2.channelCount() == audiosettings1.channelCount()); + QCOMPARE(audiosettings2.codec(), audiosettings1.codec()); + QVERIFY(audiosettings2.encodingMode() == audiosettings1.encodingMode()); + QVERIFY(audiosettings2.quality() == audiosettings1.quality()); +} + +void tst_QMediaRecorder::testAudioSettingsDestructor() +{ + /* Creating null object for the audioencodersettings */ + QAudioEncoderSettings * audiosettings = new QAudioEncoderSettings; + + /* Verifying the object is null or not */ + QVERIFY(audiosettings->isNull()); + /* delete the allocated memory */ + delete audiosettings; +} + +/* availabilityError() API test. */ +void tst_QMediaRecorder::testAvailabilityError() +{ + MockMediaRecorderService service(0, 0); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QCOMPARE(recorder.availabilityError(), QtMultimedia::ServiceMissingError); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service1(0, &recorderControl); + service1.mockMetaDataControl->populateMetaData(); + MockMediaObject object1(0, &service1); + QMediaRecorder recorder1(&object1); + QCOMPARE(recorder1.availabilityError(), QtMultimedia::NoError); +} + +/* isAvailable() API test. */ +void tst_QMediaRecorder::testIsAvailable() +{ + MockMediaRecorderService service(0, 0); + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + QCOMPARE(recorder.isAvailable(), false); + + MockMediaRecorderControl recorderControl(0); + MockMediaRecorderService service1(0, &recorderControl); + service1.mockMetaDataControl->populateMetaData(); + MockMediaObject object1(0, &service1); + QMediaRecorder recorder1(&object1); + QCOMPARE(recorder1.isAvailable(), true); +} + +/* mediaObject() API test. */ +void tst_QMediaRecorder::testMediaObject() +{ + MockMediaRecorderService service(0, 0); + service.hasControls = false; + MockMediaObject object(0, &service); + QMediaRecorder recorder(&object); + + QMediaObject *medobj = recorder.mediaObject(); + QVERIFY(medobj == NULL); + + QMediaObject *medobj1 = capture->mediaObject(); + QVERIFY(medobj1 != NULL); +} + +/* enum QMediaRecorder::ResourceError property test. */ +void tst_QMediaRecorder::testEnum() +{ + const QString errorString(QLatin1String("resource error")); + + QSignalSpy spy(capture, SIGNAL(error(QMediaRecorder::Error))); + + QCOMPARE(capture->error(), QMediaRecorder::NoError); + QCOMPARE(capture->errorString(), QString()); + + mock->error(QMediaRecorder::ResourceError, errorString); + QCOMPARE(capture->error(), QMediaRecorder::ResourceError); + QCOMPARE(capture->errorString(), errorString); + QCOMPARE(spy.count(), 1); + + QCOMPARE(spy.last()[0].value(), QMediaRecorder::ResourceError); +} + +/* Test the QVideoEncoderSettings quality API*/ +void tst_QMediaRecorder::testVideoSettingsQuality() +{ + /* Create the instance*/ + QVideoEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QVideoEncoderSettings()); + + /* Verify the default value is intialised correctly*/ + QCOMPARE(settings.quality(), QtMultimedia::NormalQuality); + + /* Set all types of Quality parameter and Verify if it is set correctly*/ + settings.setQuality(QtMultimedia::HighQuality); + QCOMPARE(settings.quality(), QtMultimedia::HighQuality); + QVERIFY(!settings.isNull()); + + settings.setQuality(QtMultimedia::VeryLowQuality); + QCOMPARE(settings.quality(), QtMultimedia::VeryLowQuality); + + settings.setQuality(QtMultimedia::LowQuality); + QCOMPARE(settings.quality(), QtMultimedia::LowQuality); + + settings.setQuality(QtMultimedia::VeryHighQuality); + QCOMPARE(settings.quality(), QtMultimedia::VeryHighQuality); +} + +/* Test QVideoEncoderSettings encodingMode */ +void tst_QMediaRecorder::testVideoSettingsEncodingMode() +{ + /* Create the instance*/ + QVideoEncoderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QVideoEncoderSettings()); + + /* Verify the default values are initialised correctly*/ + QCOMPARE(settings.encodingMode(), QtMultimedia::ConstantQualityEncoding); + QVERIFY(settings.isNull()); + + /* Set each type of encoding mode and Verify if it is set correctly*/ + settings.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + QCOMPARE(settings.encodingMode(),QtMultimedia::ConstantBitRateEncoding); + QVERIFY(!settings.isNull()); + + settings.setEncodingMode(QtMultimedia::AverageBitRateEncoding); + QCOMPARE(settings.encodingMode(), QtMultimedia::AverageBitRateEncoding); + + settings.setEncodingMode(QtMultimedia::TwoPassEncoding); + QCOMPARE(settings.encodingMode(), QtMultimedia::TwoPassEncoding); +} + +/* Test QVideoEncoderSettings copy constructor */ +void tst_QMediaRecorder::testVideoSettingsCopyConstructor() +{ + /* Create the instance and initialise it*/ + QVideoEncoderSettings settings1; + settings1.setCodec(QLatin1String("codecName")); + settings1.setBitRate(128000); + settings1.setQuality(QtMultimedia::HighQuality); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings1.setFrameRate(30000.0/10001); + settings1.setResolution(QSize(320,240)); + + /* Create another instance with instance1 as argument*/ + QVideoEncoderSettings settings2(settings1); + + /* Verify if all the parameters are copied correctly*/ + QCOMPARE(settings2 != settings1, false); + QCOMPARE(settings2.codec(), QLatin1String("codecName")); + QCOMPARE(settings2.bitRate(), 128000); + QCOMPARE(settings2.encodingMode(), QtMultimedia::ConstantBitRateEncoding); + QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001))); + QCOMPARE(settings2.resolution(), QSize(320,240)); + QCOMPARE(settings2.quality(), QtMultimedia::HighQuality); + + /* Verify both the instances are equal*/ + QCOMPARE(settings2, settings1); + QVERIFY(!settings2.isNull()); +} + +/* Test QVideoEncoderSettings Overloaded Operator assignment*/ +void tst_QMediaRecorder::testVideoSettingsOperatorAssignment() +{ + /* Create two instances.*/ + QVideoEncoderSettings settings1; + QVideoEncoderSettings settings2; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + /* Initialize all the parameters */ + settings1.setCodec(QLatin1String("codecName")); + settings1.setBitRate(128000); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings1.setFrameRate(30000.0/10001); + settings1.setResolution(QSize(320,240)); + settings1.setQuality(QtMultimedia::HighQuality); + /* Assign one object to other*/ + settings2 = settings1; + + /* Verify all the parameters are copied correctly*/ + QCOMPARE(settings2, settings1); + QCOMPARE(settings2.codec(), QLatin1String("codecName")); + QCOMPARE(settings2.bitRate(), 128000); + QCOMPARE(settings2.encodingMode(), QtMultimedia::ConstantBitRateEncoding); + QVERIFY(qFuzzyCompare(settings2.frameRate(), qreal(30000.0/10001))); + QCOMPARE(settings2.resolution(), QSize(320,240)); + QCOMPARE(settings2.quality(), QtMultimedia::HighQuality); + QCOMPARE(settings2, settings1); + QVERIFY(!settings2.isNull()); +} + +/* Test QVideoEncoderSettings Overloaded OperatorNotEqual*/ +void tst_QMediaRecorder::testVideoSettingsOperatorNotEqual() +{ + /* Create the instance and set the bit rate and Verify objects with OperatorNotEqual*/ + QVideoEncoderSettings settings1; + settings1.setBitRate(1); + QVideoEncoderSettings settings2; + settings2.setBitRate(1); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setBitRate(2); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Resolution with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QVideoEncoderSettings(); + settings2.setResolution(QSize(800,600)); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setResolution(QSize(400,300)); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Codec with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QVideoEncoderSettings(); + settings2.setCodec("codec1"); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setCodec("codec2"); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify EncodingMode with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings2 = QVideoEncoderSettings(); + settings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setEncodingMode(QtMultimedia::TwoPassEncoding); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify Quality with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setQuality(QtMultimedia::NormalQuality); + settings2 = QVideoEncoderSettings(); + settings2.setQuality(QtMultimedia::NormalQuality); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setQuality(QtMultimedia::LowQuality); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); + + /* Verify FrameRate with not equal operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setFrameRate(1); + settings2 = QVideoEncoderSettings(); + settings2.setFrameRate(1); + /* OperatorNotEqual returns false when both objects are equal*/ + QCOMPARE(settings1 != settings2, false); + settings2.setFrameRate(2); + /* OperatorNotEqual returns true when both objects are not equal*/ + QVERIFY(settings1 != settings2); +} + +/* Test QVideoEncoderSettings Overloaded comparison operator*/ +void tst_QMediaRecorder::testVideoSettingsOperatorComparison() +{ + /* Create the instance and set the bit rate and Verify objects with comparison operator*/ + QVideoEncoderSettings settings1; + settings1.setBitRate(1); + QVideoEncoderSettings settings2; + settings2.setBitRate(1); + + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setBitRate(2); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify resolution with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setResolution(800,600); + settings2 = QVideoEncoderSettings(); + settings2.setResolution(QSize(800,600)); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setResolution(QSize(400,300)); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify Codec with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setCodec("codec1"); + settings2 = QVideoEncoderSettings(); + settings2.setCodec("codec1"); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setCodec("codec2"); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify EncodingMode with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + settings2 = QVideoEncoderSettings(); + settings2.setEncodingMode(QtMultimedia::ConstantBitRateEncoding); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setEncodingMode(QtMultimedia::TwoPassEncoding); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify Quality with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setQuality(QtMultimedia::NormalQuality); + settings2 = QVideoEncoderSettings(); + settings2.setQuality(QtMultimedia::NormalQuality); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setQuality(QtMultimedia::LowQuality); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); + + /* Verify FrameRate with comparison operator*/ + settings1 = QVideoEncoderSettings(); + settings1.setFrameRate(1); + settings2 = QVideoEncoderSettings(); + settings2.setFrameRate(1); + /* Comparison operator returns true when both objects are equal*/ + QVERIFY(settings1 == settings2); + settings2.setFrameRate(2); + /* Comparison operator returns false when both objects are not equal*/ + QCOMPARE(settings1 == settings2, false); +} + +/* Test the destuctor of the QVideoEncoderSettings*/ +void tst_QMediaRecorder::testVideoSettingsDestructor() +{ + /* Create the instance on heap and verify if object deleted correctly*/ + QVideoEncoderSettings *settings1 = new QVideoEncoderSettings(); + QVERIFY(settings1 != NULL); + QVERIFY(settings1->isNull()); + delete settings1; + + /* Create the instance on heap and initialise it and verify if object deleted correctly.*/ + QVideoEncoderSettings *settings2 = new QVideoEncoderSettings(); + QVERIFY(settings2 != NULL); + settings2->setCodec(QString("codec")); + QVERIFY(!settings2->isNull()); + delete settings2; +} diff --git a/tests/auto/unit/qmediarecorder/tst_qmediarecorder.h b/tests/auto/unit/qmediarecorder/tst_qmediarecorder.h new file mode 100755 index 000000000..d0202a0c0 --- /dev/null +++ b/tests/auto/unit/qmediarecorder/tst_qmediarecorder.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QMEDIARECORDER_H +#define TST_QMEDIARECORDER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "mockmediarecorderservice.h" +#include "mockmediaobject.h" + +class tst_QMediaRecorder: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testNullService(); + void testNullControls(); + void testDeleteMediaObject(); + void testError(); + void testSink(); + void testRecord(); + void testMute(); + void testAudioDeviceControl(); + void testAudioEncodeControl(); + void testMediaFormatsControl(); + void testVideoEncodeControl(); + void testEncodingSettings(); + void testAudioSettings(); + void testVideoSettings(); + + void nullMetaDataControl(); + void isMetaDataAvailable(); + void isWritable(); + void metaDataChanged(); + void metaData_data(); + void metaData(); + void setMetaData_data(); + void setMetaData(); + void extendedMetaData_data() { metaData_data(); } + void extendedMetaData(); + void setExtendedMetaData_data() { extendedMetaData_data(); } + void setExtendedMetaData(); + + void testAudioSettingsCopyConstructor(); + void testAudioSettingsOperatorNotEqual(); + void testAudioSettingsOperatorEqual(); + void testAudioSettingsOperatorAssign(); + void testAudioSettingsDestructor(); + + void testAvailabilityError(); + void testIsAvailable(); + void testMediaObject(); + void testEnum(); + + void testVideoSettingsQuality(); + void testVideoSettingsEncodingMode(); + void testVideoSettingsCopyConstructor(); + void testVideoSettingsOperatorAssignment(); + void testVideoSettingsOperatorNotEqual(); + void testVideoSettingsOperatorComparison(); + void testVideoSettingsDestructor(); + +private: + QAudioEncoderControl* encode; + QAudioEndpointSelector* audio; + MockMediaObject *object; + MockMediaRecorderService*service; + MockMediaRecorderControl *mock; + QMediaRecorder *capture; + QVideoEncoderControl* videoEncode; +}; +#endif //TST_QMEDIARECORDER_H diff --git a/tests/auto/unit/qmediaresource/qmediaresource.pro b/tests/auto/unit/qmediaresource/qmediaresource.pro new file mode 100644 index 000000000..b6c1e7183 --- /dev/null +++ b/tests/auto/unit/qmediaresource/qmediaresource.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qmediaresource + +QT += network multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaresource.cpp + diff --git a/tests/auto/unit/qmediaresource/tst_qmediaresource.cpp b/tests/auto/unit/qmediaresource/tst_qmediaresource.cpp new file mode 100644 index 000000000..8051deb40 --- /dev/null +++ b/tests/auto/unit/qmediaresource/tst_qmediaresource.cpp @@ -0,0 +1,700 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include "qmediaresource.h" + +QT_USE_NAMESPACE +class tst_QMediaResource : public QObject +{ + Q_OBJECT +private slots: + void constructNull(); + void construct_data(); + void construct(); + void setResolution(); + void equality(); + void copy(); + void assign(); + + void constructorRequest(); + void copyConstructor(); +}; + +void tst_QMediaResource::constructNull() +{ + QMediaResource resource; + + QCOMPARE(resource.isNull(), true); + QCOMPARE(resource.url(), QUrl()); + QCOMPARE(resource.request(), QNetworkRequest()); + QCOMPARE(resource.mimeType(), QString()); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); +} + +void tst_QMediaResource::construct_data() +{ + QTest::addColumn("url"); + QTest::addColumn("request"); + QTest::addColumn("mimeType"); + QTest::addColumn("language"); + QTest::addColumn("audioCodec"); + QTest::addColumn("videoCodec"); + QTest::addColumn("dataSize"); + QTest::addColumn("audioBitRate"); + QTest::addColumn("sampleRate"); + QTest::addColumn("channelCount"); + QTest::addColumn("videoBitRate"); + QTest::addColumn("resolution"); + + QTest::newRow("audio content") + << QUrl(QString::fromLatin1("http:://test.com/test.mp3")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.mp3"))) + << QString::fromLatin1("audio/mpeg") + << QString::fromLatin1("eng") + << QString::fromLatin1("mp3") + << QString() + << qint64(5465433) + << 128000 + << 44100 + << 2 + << 0 + << QSize(); + QTest::newRow("image content") + << QUrl(QString::fromLatin1("http:://test.com/test.jpg")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.jpg"))) + << QString::fromLatin1("image/jpeg") + << QString() + << QString() + << QString() + << qint64(23600) + << 0 + << 0 + << 0 + << 0 + << QSize(640, 480); + QTest::newRow("video content") + << QUrl(QString::fromLatin1("http:://test.com/test.mp4")) + << QNetworkRequest(QUrl(QString::fromLatin1("http:://test.com/test.mp4"))) + << QString::fromLatin1("video/mp4") + << QString() + << QString::fromLatin1("aac") + << QString::fromLatin1("h264") + << qint64(36245851) + << 96000 + << 44000 + << 5 + << 750000 + << QSize(720, 576); + QTest::newRow("thumbnail") + << QUrl(QString::fromLatin1("file::///thumbs/test.png")) + << QNetworkRequest(QUrl(QString::fromLatin1("file::///thumbs/test.png"))) + << QString::fromLatin1("image/png") + << QString() + << QString() + << QString() + << qint64(2360) + << 0 + << 0 + << 0 + << 0 + << QSize(128, 128); +} + +void tst_QMediaResource::construct() +{ + QFETCH(QUrl, url); + QFETCH(QNetworkRequest, request); + QFETCH(QString, mimeType); + QFETCH(QString, language); + QFETCH(QString, audioCodec); + QFETCH(QString, videoCodec); + QFETCH(qint64, dataSize); + QFETCH(int, audioBitRate); + QFETCH(int, sampleRate); + QFETCH(int, channelCount); + QFETCH(int, videoBitRate); + QFETCH(QSize, resolution); + + { + QMediaResource resource(url); + + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.mimeType(), QString()); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); + } + { + QMediaResource resource(url, mimeType); + + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); + QCOMPARE(resource.mimeType(), mimeType); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); + + resource.setLanguage(language); + resource.setAudioCodec(audioCodec); + resource.setVideoCodec(videoCodec); + resource.setDataSize(dataSize); + resource.setAudioBitRate(audioBitRate); + resource.setSampleRate(sampleRate); + resource.setChannelCount(channelCount); + resource.setVideoBitRate(videoBitRate); + resource.setResolution(resolution); + + QCOMPARE(resource.language(), language); + QCOMPARE(resource.audioCodec(), audioCodec); + QCOMPARE(resource.videoCodec(), videoCodec); + QCOMPARE(resource.dataSize(), dataSize); + QCOMPARE(resource.audioBitRate(), audioBitRate); + QCOMPARE(resource.sampleRate(), sampleRate); + QCOMPARE(resource.channelCount(), channelCount); + QCOMPARE(resource.videoBitRate(), videoBitRate); + QCOMPARE(resource.resolution(), resolution); + } + { + QMediaResource resource(request, mimeType); + + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); + QCOMPARE(resource.mimeType(), mimeType); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); + + resource.setLanguage(language); + resource.setAudioCodec(audioCodec); + resource.setVideoCodec(videoCodec); + resource.setDataSize(dataSize); + resource.setAudioBitRate(audioBitRate); + resource.setSampleRate(sampleRate); + resource.setChannelCount(channelCount); + resource.setVideoBitRate(videoBitRate); + resource.setResolution(resolution); + + QCOMPARE(resource.language(), language); + QCOMPARE(resource.audioCodec(), audioCodec); + QCOMPARE(resource.videoCodec(), videoCodec); + QCOMPARE(resource.dataSize(), dataSize); + QCOMPARE(resource.audioBitRate(), audioBitRate); + QCOMPARE(resource.sampleRate(), sampleRate); + QCOMPARE(resource.channelCount(), channelCount); + QCOMPARE(resource.videoBitRate(), videoBitRate); + QCOMPARE(resource.resolution(), resolution); + } +} + +void tst_QMediaResource::setResolution() +{ + QMediaResource resource( + QUrl(QString::fromLatin1("file::///thumbs/test.png")), + QString::fromLatin1("image/png")); + + QCOMPARE(resource.resolution(), QSize()); + + resource.setResolution(QSize(120, 80)); + QCOMPARE(resource.resolution(), QSize(120, 80)); + + resource.setResolution(QSize(-1, 23)); + QCOMPARE(resource.resolution(), QSize(-1, 23)); + + resource.setResolution(QSize(-43, 34)); + QCOMPARE(resource.resolution(), QSize(-43, 34)); + + resource.setResolution(QSize(64, -1)); + QCOMPARE(resource.resolution(), QSize(64, -1)); + + resource.setResolution(QSize(64, -83)); + QCOMPARE(resource.resolution(), QSize(64, -83)); + + resource.setResolution(QSize(-12, -83)); + QCOMPARE(resource.resolution(), QSize(-12, -83)); + + resource.setResolution(QSize()); + QCOMPARE(resource.resolution(), QSize(-1, -1)); + + resource.setResolution(120, 80); + QCOMPARE(resource.resolution(), QSize(120, 80)); + + resource.setResolution(-1, 23); + QCOMPARE(resource.resolution(), QSize(-1, 23)); + + resource.setResolution(-43, 34); + QCOMPARE(resource.resolution(), QSize(-43, 34)); + + resource.setResolution(64, -1); + QCOMPARE(resource.resolution(), QSize(64, -1)); + + resource.setResolution(64, -83); + QCOMPARE(resource.resolution(), QSize(64, -83)); + + resource.setResolution(-12, -83); + QCOMPARE(resource.resolution(), QSize(-12, -83)); + + resource.setResolution(-1, -1); + QCOMPARE(resource.resolution(), QSize()); +} + +void tst_QMediaResource::equality() +{ + QMediaResource resource1( + QUrl(QString::fromLatin1("http://test.com/test.mp4")), + QString::fromLatin1("video/mp4")); + QMediaResource resource2( + QUrl(QString::fromLatin1("http://test.com/test.mp4")), + QString::fromLatin1("video/mp4")); + QMediaResource resource3( + QUrl(QString::fromLatin1("file:///thumbs/test.jpg"))); + QMediaResource resource4( + QUrl(QString::fromLatin1("file:///thumbs/test.jpg"))); + QMediaResource resource5( + QUrl(QString::fromLatin1("http://test.com/test.mp3")), + QString::fromLatin1("audio/mpeg")); + + QNetworkRequest request(QUrl("http://test.com/test.mp3")); + QString requestMimeType("audio/mp3"); + + QMediaResource requestResource1(request, requestMimeType); + QMediaResource requestResource2(request, requestMimeType); + + QCOMPARE(requestResource1 == requestResource2, true); + QCOMPARE(requestResource1 != requestResource2, false); + QCOMPARE(requestResource1 != resource5, true); + + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + QCOMPARE(resource3 == resource4, true); + QCOMPARE(resource3 != resource4, false); + + QCOMPARE(resource1 == resource3, false); + QCOMPARE(resource1 != resource3, true); + + QCOMPARE(resource1 == resource5, false); + QCOMPARE(resource1 != resource5, true); + + resource1.setAudioCodec(QString::fromLatin1("mp3")); + resource2.setAudioCodec(QString::fromLatin1("aac")); + + // Not equal differing audio codecs. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource1.setAudioCodec(QString::fromLatin1("aac")); + + // Equal. + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setVideoCodec(QString()); + + // Equal. + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setVideoCodec(QString::fromLatin1("h264")); + + // Not equal differing video codecs. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource2.setVideoCodec(QString::fromLatin1("h264")); + + // Equal. + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource2.setDataSize(0); + + // Equal. + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setDataSize(546423); + + // Not equal differing video codecs. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource2.setDataSize(546423); + + // Equal. + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setAudioBitRate(96000); + resource1.setSampleRate(48000); + resource2.setSampleRate(44100); + resource1.setChannelCount(0); + resource1.setVideoBitRate(900000); + resource2.setLanguage(QString::fromLatin1("eng")); + + // Not equal, audio bit rate, sample rate, video bit rate, and + // language. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource2.setAudioBitRate(96000); + resource1.setSampleRate(44100); + + // Not equal, differing video bit rate, and language. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource2.setVideoBitRate(900000); + resource1.setLanguage(QString::fromLatin1("eng")); + + // Equal + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setResolution(QSize()); + + // Equal + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource2.setResolution(-1, -1); + + // Equal + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + resource1.setResolution(QSize(-640, -480)); + + // Not equal, differing resolution. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + resource1.setResolution(QSize(640, 480)); + resource2.setResolution(QSize(800, 600)); + + // Not equal, differing resolution. + QCOMPARE(resource1 == resource2, false); + QCOMPARE(resource1 != resource2, true); + + resource1.setResolution(800, 600); + + // Equal + QCOMPARE(resource1 == resource2, true); + QCOMPARE(resource1 != resource2, false); + + /* equality tests for constructor of QMediaresource(QNetworkrequest,mimeType)*/ + QNetworkRequest request2(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + QString mimeType(QLatin1String("video/mp4")); + + QMediaResource resource6(request2,mimeType); + QMediaResource resource7(request2,mimeType); + + + QVERIFY(resource6.request()==request2); + QVERIFY(resource6.mimeType()==mimeType); + + + QVERIFY(resource7.request()==request2); + QVERIFY(resource7.mimeType()==mimeType); + + QVERIFY(resource6.request()==resource7.request()); + QVERIFY(resource6.mimeType()==resource7.mimeType()); + + QVERIFY(resource6==resource7); + + /*for copy constructor*/ + QMediaResource resource8(resource7); + + QVERIFY(resource8.request()==request2); + QVERIFY(resource8.mimeType()==mimeType); + + + QVERIFY(resource7.request()==request2); + QVERIFY(resource7.mimeType()==mimeType); + + QVERIFY(resource8.request()==resource7.request()); + QVERIFY(resource8.mimeType()==resource7.mimeType()); + + + QVERIFY(resource8==resource7); + + /*for assign constructor*/ + + QMediaResource resource9(request2,mimeType); + + QMediaResource resource10=resource9; + + QVERIFY(resource10.request()==request2); + QVERIFY(resource10.mimeType()==mimeType); + + + QVERIFY(resource9.request()==request2); + QVERIFY(resource9.mimeType()==mimeType); + + QVERIFY(resource8.request()==resource7.request()); + QVERIFY(resource8.mimeType()==resource7.mimeType()); + + QVERIFY(resource8==resource7); +} + +void tst_QMediaResource::copy() +{ + const QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + const QString mimeType(QLatin1String("video/mp4")); + const QString amrCodec(QLatin1String("amr")); + const QString mp3Codec(QLatin1String("mp3")); + const QString aacCodec(QLatin1String("aac")); + const QString h264Codec(QLatin1String("h264")); + + QMediaResource original(url, mimeType); + original.setAudioCodec(amrCodec); + + QMediaResource copy(original); + + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + QCOMPARE(copy.audioCodec(), amrCodec); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + original.setAudioCodec(mp3Codec); + + QCOMPARE(copy.audioCodec(), amrCodec); + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); + + copy.setAudioCodec(aacCodec); + copy.setVideoCodec(h264Codec); + + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + + QCOMPARE(original.audioCodec(), mp3Codec); +} + +void tst_QMediaResource::assign() +{ + const QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + const QString mimeType(QLatin1String("video/mp4")); + const QString amrCodec(QLatin1String("amr")); + const QString mp3Codec(QLatin1String("mp3")); + const QString aacCodec(QLatin1String("aac")); + const QString h264Codec(QLatin1String("h264")); + + QNetworkRequest request(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + const qint64 dataSize(23600); + int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; + QSize resolution(QSize(640, 480)); + QString language("eng"); + + QMediaResource copy(QUrl(QString::fromLatin1("file:///thumbs/test.jpg"))); + + QMediaResource original(url, mimeType); + original.setAudioCodec(amrCodec); + + copy = original; + + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + QCOMPARE(copy.audioCodec(), amrCodec); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + original.setAudioCodec(mp3Codec); + + QCOMPARE(copy.audioCodec(), amrCodec); + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); + + copy.setAudioCodec(aacCodec); + copy.setVideoCodec(h264Codec); + + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + + QCOMPARE(original.audioCodec(), mp3Codec); + + /* for constructor of QMediaresource(QNetworkrequest,mimeType)*/ + + QMediaResource copy1(QNetworkRequest(QUrl(QString::fromLatin1("file:///thumbs/test.jpg")))); + + QMediaResource original1(request, mimeType); + + original1.setAudioCodec(amrCodec); + original1.setLanguage(QString("eng")); + original1.setVideoCodec(h264Codec); + original1.setDataSize(dataSize); + original1.setAudioBitRate(audioBitRate); + original1.setSampleRate(sampleRate); + original1.setChannelCount(channelCount); + original1.setVideoBitRate(videoBitRate); + original1.setResolution(resolution); + + copy1 = original1; + + QCOMPARE(original1 == copy1, true); +} + +// Constructor for request without passing mimetype. +void tst_QMediaResource::constructorRequest() +{ + //Initialise the request and url. + QNetworkRequest request(QUrl(QString::fromLatin1("http:://test.com/test.mp3"))); + QUrl url(QString::fromLatin1("http:://test.com/test.mp3")); + + // Create the instance with request as parameter. + QMediaResource resource(request); + + // Verify all the parameters of objects. + QCOMPARE(resource.isNull(), false); + QCOMPARE(resource.url(), url); + QCOMPARE(resource.request(), request); + QCOMPARE(resource.mimeType(), QString()); + QCOMPARE(resource.language(), QString()); + QCOMPARE(resource.audioCodec(), QString()); + QCOMPARE(resource.videoCodec(), QString()); + QCOMPARE(resource.dataSize(), qint64(0)); + QCOMPARE(resource.audioBitRate(), 0); + QCOMPARE(resource.sampleRate(), 0); + QCOMPARE(resource.channelCount(), 0); + QCOMPARE(resource.videoBitRate(), 0); + QCOMPARE(resource.resolution(), QSize()); +} + +// Copy constructor with all the parameter and copy constructor for constructor with request and mimetype as parameter. +void tst_QMediaResource::copyConstructor() +{ + // Initialise all the parameters. + const QUrl url(QString::fromLatin1("http://test.com/test.mp4")); + const QString mimeType(QLatin1String("video/mp4")); + const QString amrCodec(QLatin1String("amr")); + const QString h264Codec(QLatin1String("h264")); + + const qint64 dataSize(23600); + int audioBitRate = 1, sampleRate = 2, channelCount = 3, videoBitRate = 4; + QSize resolution(QSize(640, 480)); + QString language("eng"); + + // Create the instance with url and mimetype. + QMediaResource original(url, mimeType); + + // Set all the parameters. + original.setAudioCodec(amrCodec); + original.setLanguage(QString("eng")); + original.setVideoCodec(h264Codec); + original.setDataSize(dataSize); + original.setAudioBitRate(audioBitRate); + original.setSampleRate(sampleRate); + original.setChannelCount(channelCount); + original.setVideoBitRate(videoBitRate); + original.setResolution(resolution); + + // Copy the instance to new object. + QMediaResource copy(original); + + // Verify all the parameters of the copied object. + QCOMPARE(copy.url(), url); + QCOMPARE(copy.mimeType(), mimeType); + QCOMPARE(copy.audioCodec(), amrCodec); + QCOMPARE(copy.language(), language ); + QCOMPARE(copy.videoCodec(), h264Codec); + QCOMPARE(copy.dataSize(), dataSize); + QCOMPARE(copy.audioBitRate(), audioBitRate); + QCOMPARE(copy.sampleRate(), sampleRate); + QCOMPARE(copy.channelCount(), channelCount); + QCOMPARE(copy.videoBitRate(), videoBitRate); + QCOMPARE(copy.resolution(), resolution); + + // Compare both the objects are equal. + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + // Initialise the request parameter. + QNetworkRequest request1(QUrl(QString::fromLatin1("http://test.com/test.mp4"))); + + // Constructor with rerquest and mimetype. + QMediaResource original1(request1, mimeType); + + // Copy the object and verify if both are eqaul or not. + QMediaResource copy1(original1); + QCOMPARE(copy1.url(), url); + QCOMPARE(copy1.mimeType(), mimeType); + QCOMPARE(copy1.request(), request1); + QCOMPARE(original1 == copy1, true); +} + +QTEST_MAIN(tst_QMediaResource) + +#include "tst_qmediaresource.moc" diff --git a/tests/auto/unit/qmediaservice/qmediaservice.pro b/tests/auto/unit/qmediaservice/qmediaservice.pro new file mode 100644 index 000000000..9ae2c5475 --- /dev/null +++ b/tests/auto/unit/qmediaservice/qmediaservice.pro @@ -0,0 +1,7 @@ +CONFIG += testcase +TARGET = tst_qmediaservice + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaservice.cpp diff --git a/tests/auto/unit/qmediaservice/tst_qmediaservice.cpp b/tests/auto/unit/qmediaservice/tst_qmediaservice.cpp new file mode 100644 index 000000000..3a46c5626 --- /dev/null +++ b/tests/auto/unit/qmediaservice/tst_qmediaservice.cpp @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QtTestMediaService; + +class QtTestMediaControlA : public QMediaControl +{ + Q_OBJECT +}; + +#define QtTestMediaControlA_iid "com.nokia.QtTestMediaControlA" +Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlA, QtTestMediaControlA_iid) + +class QtTestMediaControlB : public QMediaControl +{ + Q_OBJECT +}; + +#define QtTestMediaControlB_iid "com.nokia.QtTestMediaControlB" +Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlB, QtTestMediaControlB_iid) + + +class QtTestMediaControlC : public QMediaControl +{ + Q_OBJECT +}; + +#define QtTestMediaControlC_iid "com.nokia.QtTestMediaControlC" +Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlC, QtTestMediaControlA_iid) // Yes A. + +class QtTestMediaControlD : public QMediaControl +{ + Q_OBJECT +}; + +#define QtTestMediaControlD_iid "com.nokia.QtTestMediaControlD" +Q_MEDIA_DECLARE_CONTROL(QtTestMediaControlD, QtTestMediaControlD_iid) + +//unimplemented service +#define QtTestMediaControlE_iid "com.nokia.QtTestMediaControlF" +class QtTestMediaControlE : public QMediaControl +{ + Q_OBJECT +}; + +/* implementation of child class by inheriting The QMediaService base class for media service implementations. */ +class QtTestMediaService : public QMediaService +{ + Q_OBJECT +public: + int refA; + int refB; + int refC; + QtTestMediaControlA controlA; + QtTestMediaControlB controlB; + QtTestMediaControlC controlC; + + //constructor + QtTestMediaService(): QMediaService(0), refA(0), refB(0), refC(0) + { + } + + //requestControl() pure virtual function of QMediaService class. + QMediaControl *requestControl(const char *name) + { + if (strcmp(name, QtTestMediaControlA_iid) == 0) { + refA += 1; + + return &controlA; + } else if (strcmp(name, QtTestMediaControlB_iid) == 0) { + refB += 1; + + return &controlB; + } else if (strcmp(name, QtTestMediaControlC_iid) == 0) { + refA += 1; + + return &controlA; + } else { + return 0; + } + } + + //releaseControl() pure virtual function of QMediaService class. + void releaseControl(QMediaControl *control) + { + if (control == &controlA) + refA -= 1; + else if (control == &controlB) + refB -= 1; + else if (control == &controlC) + refC -= 1; + } + + //requestControl() function of QMediaService class. + using QMediaService::requestControl; +}; + +/* Test case implementation for QMediaService class which provides a common base class for media service implementations.*/ +class tst_QMediaService : public QObject +{ + Q_OBJECT +private slots: + void tst_destructor(); + void tst_releaseControl(); + void tst_requestControl(); + void tst_requestControlTemplate(); + + void initTestCase(); + + void control_iid(); + void control(); + +}; + +/*MaemoAPI-1668 :destructor property test. */ +void tst_QMediaService::tst_destructor() +{ + QtTestMediaService *service = new QtTestMediaService; + delete service; +} + +void tst_QMediaService::initTestCase() +{ +} + +/*MaemoAPI-1669 :releaseControl() API property test. */ +void tst_QMediaService::tst_releaseControl() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); //Controls must be returned to the service when no longer needed + QVERIFY(service.refA == 0); + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); //Controls must be returned to the service when no longer needed + QVERIFY(service.refB == 0); +} + +/*MaemoAPI-1670 :requestControl() API property test. */ +void tst_QMediaService::tst_requestControl() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlA = service.requestControl(QtTestMediaControlA_iid); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); //Controls must be returned to the service when no longer needed + + //Get a pointer to the media control implementing interface and verify. + QMediaControl* controlB = service.requestControl(QtTestMediaControlB_iid); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); //Controls must be returned to the service when no longer needed + + //If the service does not implement the control, a null pointer is returned instead. + QMediaControl* controlE = service.requestControl(QtTestMediaControlE_iid); + QVERIFY(!controlE); //should return null pointer + service.releaseControl(controlE); //Controls must be returned to the service when no longer needed + + //If the service is unavailable a null pointer is returned instead. + QMediaControl* control = service.requestControl(""); + QVERIFY(!control); //should return null pointer + service.releaseControl(control); //Controls must be returned to the service when no longer needed +} + +/*MaemoAPI-1671 :requestControl() API property test. */ +void tst_QMediaService::tst_requestControlTemplate() +{ + //test class instance creation + QtTestMediaService service; + + //Get a pointer to the media control of type T implemented by a media service. + QtTestMediaControlA *controlA = service.requestControl(); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); + + //Get a pointer to the media control of type T implemented by a media service. + QtTestMediaControlB *controlB = service.requestControl(); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); + + QVERIFY(!service.requestControl()); // Faulty implementation returns A. + QCOMPARE(service.refA, 0); // Verify the control was released. + + QVERIFY(!service.requestControl()); // No control of that type. +} + + +void tst_QMediaService::control_iid() +{ + const char *nullString = 0; + + // Default implementation. + QCOMPARE(qmediacontrol_iid(), nullString); + + // Partial template. + QVERIFY(qstrcmp(qmediacontrol_iid(), QtTestMediaControlA_iid) == 0); +} + +void tst_QMediaService::control() +{ + QtTestMediaService service; + + QtTestMediaControlA *controlA = service.requestControl(); + QCOMPARE(controlA, &service.controlA); + service.releaseControl(controlA); + + QtTestMediaControlB *controlB = service.requestControl(); + QCOMPARE(controlB, &service.controlB); + service.releaseControl(controlB); + + QVERIFY(!service.requestControl()); // Faulty implementation returns A, but is wrong class + QCOMPARE(service.refA, 0); // Verify the control was released. + + QVERIFY(!service.requestControl()); // No control of that type. +} + +QT_END_NAMESPACE + +QT_USE_NAMESPACE + +QTEST_MAIN(tst_QMediaService) + +#include "tst_qmediaservice.moc" diff --git a/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro b/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro new file mode 100644 index 000000000..d74c936e3 --- /dev/null +++ b/tests/auto/unit/qmediaserviceprovider/qmediaserviceprovider.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qmediaserviceprovider + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediaserviceprovider.cpp + diff --git a/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp b/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp new file mode 100644 index 000000000..c70401f7d --- /dev/null +++ b/tests/auto/unit/qmediaserviceprovider/tst_qmediaserviceprovider.cpp @@ -0,0 +1,499 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +QT_USE_NAMESPACE +class MockMediaService : public QMediaService +{ + Q_OBJECT +public: + MockMediaService(const QString& name, QObject *parent = 0) : QMediaService(parent) + { setObjectName(name); } + ~MockMediaService() {} + + QMediaControl* requestControl(const char *) {return 0;} + void releaseControl(QMediaControl *) {} +}; + +class MockServicePlugin1 : public QMediaServiceProviderPlugin, + public QMediaServiceSupportedFormatsInterface, + public QMediaServiceSupportedDevicesInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaServiceSupportedFormatsInterface) + Q_INTERFACES(QMediaServiceSupportedDevicesInterface) +public: + QStringList keys() const + { + return QStringList() << + QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER); + } + + QMediaService* create(QString const& key) + { + if (keys().contains(key)) + return new MockMediaService("MockServicePlugin1"); + else + return 0; + } + + void release(QMediaService *service) + { + delete service; + } + + QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const + { + if (codecs.contains(QLatin1String("mpeg4"))) + return QtMultimedia::NotSupported; + + if (mimeType == "audio/ogg") { + return QtMultimedia::ProbablySupported; + } + + return QtMultimedia::MaybeSupported; + } + + QStringList supportedMimeTypes() const + { + return QStringList("audio/ogg"); + } + + QList devices(const QByteArray &service) const + { + QList res; + return res; + } + + QString deviceDescription(const QByteArray &service, const QByteArray &device) + { + if (devices(service).contains(device)) + return QString(device)+" description"; + else + return QString(); + } +}; + +class MockServicePlugin2 : public QMediaServiceProviderPlugin, + public QMediaServiceSupportedFormatsInterface, + public QMediaServiceFeaturesInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaServiceSupportedFormatsInterface) + Q_INTERFACES(QMediaServiceFeaturesInterface) +public: + QStringList keys() const + { + return QStringList() << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) + << QLatin1String(Q_MEDIASERVICE_RADIO); + } + + QMediaService* create(QString const& key) + { + if (keys().contains(key)) + return new MockMediaService("MockServicePlugin2"); + else + return 0; + } + + void release(QMediaService *service) + { + delete service; + } + + QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const + { + Q_UNUSED(codecs); + + if (mimeType == "audio/wav") + return QtMultimedia::PreferredService; + + return QtMultimedia::NotSupported; + } + + QStringList supportedMimeTypes() const + { + return QStringList("audio/wav"); + } + + QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const + { + if (service == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)) + return QMediaServiceProviderHint::LowLatencyPlayback; + else + return 0; + } +}; + + +class MockServicePlugin3 : public QMediaServiceProviderPlugin, + public QMediaServiceSupportedDevicesInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaServiceSupportedDevicesInterface) +public: + QStringList keys() const + { + return QStringList() << + QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) << + QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE); + } + + QMediaService* create(QString const& key) + { + if (keys().contains(key)) + return new MockMediaService("MockServicePlugin3"); + else + return 0; + } + + void release(QMediaService *service) + { + delete service; + } + + QList devices(const QByteArray &service) const + { + QList res; + if (service == QByteArray(Q_MEDIASERVICE_AUDIOSOURCE)) + res << "audiosource1" << "audiosource2"; + + return res; + } + + QString deviceDescription(const QByteArray &service, const QByteArray &device) + { + if (devices(service).contains(device)) + return QString(device)+" description"; + else + return QString(); + } +}; + +class MockServicePlugin4 : public QMediaServiceProviderPlugin, + public QMediaServiceSupportedFormatsInterface, + public QMediaServiceFeaturesInterface +{ + Q_OBJECT + Q_INTERFACES(QMediaServiceSupportedFormatsInterface) + Q_INTERFACES(QMediaServiceFeaturesInterface) +public: + QStringList keys() const + { + return QStringList() << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER); + } + + QMediaService* create(QString const& key) + { + if (keys().contains(key)) + return new MockMediaService("MockServicePlugin4"); + else + return 0; + } + + void release(QMediaService *service) + { + delete service; + } + + QtMultimedia::SupportEstimate hasSupport(const QString &mimeType, const QStringList& codecs) const + { + if (codecs.contains(QLatin1String("jpeg2000"))) + return QtMultimedia::NotSupported; + + if (supportedMimeTypes().contains(mimeType)) + return QtMultimedia::ProbablySupported; + + return QtMultimedia::MaybeSupported; + } + + QStringList supportedMimeTypes() const + { + return QStringList() << "video/mp4" << "video/quicktime"; + } + + QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const + { + if (service == QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)) + return QMediaServiceProviderHint::StreamPlayback; + else + return 0; + } +}; + + + +class MockMediaServiceProvider : public QMediaServiceProvider +{ + QMediaService* requestService(const QByteArray &type, const QMediaServiceProviderHint &) + { + Q_UNUSED(type); + return 0; + } + + void releaseService(QMediaService *service) + { + Q_UNUSED(service); + } +}; + + +class tst_QMediaServiceProvider : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + +private slots: + void testDefaultProviderAvailable(); + void testObtainService(); + void testHasSupport(); + void testSupportedMimeTypes(); + void testProviderHints(); + +private: + QObjectList plugins; +}; + +void tst_QMediaServiceProvider::initTestCase() +{ + plugins << new MockServicePlugin1; + plugins << new MockServicePlugin2; + plugins << new MockServicePlugin3; + plugins << new MockServicePlugin4; + + QMediaPluginLoader::setStaticPlugins(QLatin1String("mediaservice"), plugins); +} + +void tst_QMediaServiceProvider::testDefaultProviderAvailable() +{ + // Must always be a default provider available + QVERIFY(QMediaServiceProvider::defaultServiceProvider() != 0); +} + +void tst_QMediaServiceProvider::testObtainService() +{ + QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider(); + + if (provider == 0) + QSKIP("No default provider", SkipSingle); + + QMediaService *service = 0; + + // Player + service = provider->requestService(Q_MEDIASERVICE_MEDIAPLAYER); + QVERIFY(service != 0); + provider->releaseService(service); +} + +void tst_QMediaServiceProvider::testHasSupport() +{ + MockMediaServiceProvider mockProvider; + QCOMPARE(mockProvider.hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()), + QtMultimedia::MaybeSupported); + + QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider(); + + if (provider == 0) + QSKIP("No default provider", SkipSingle); + + QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/ogv", QStringList()), + QtMultimedia::MaybeSupported); + + QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/ogg", QStringList()), + QtMultimedia::ProbablySupported); + + //while the service returns PreferredService, provider should return ProbablySupported + QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "audio/wav", QStringList()), + QtMultimedia::ProbablySupported); + + //even while all the plugins with "hasSupport" returned NotSupported, + //MockServicePlugin3 has no "hasSupport" interface, so MaybeSupported + QCOMPARE(provider->hasSupport(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER), "video/avi", + QStringList() << "mpeg4"), + QtMultimedia::MaybeSupported); + + QCOMPARE(provider->hasSupport(QByteArray("non existing service"), "video/ogv", QStringList()), + QtMultimedia::NotSupported); + + QCOMPARE(QMediaPlayer::hasSupport("video/ogv"), QtMultimedia::MaybeSupported); + QCOMPARE(QMediaPlayer::hasSupport("audio/ogg"), QtMultimedia::ProbablySupported); + QCOMPARE(QMediaPlayer::hasSupport("audio/wav"), QtMultimedia::ProbablySupported); + + //test low latency flag support + QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::LowLatency), + QtMultimedia::ProbablySupported); + //plugin1 probably supports audio/ogg, it checked because it doesn't provide features iface + QCOMPARE(QMediaPlayer::hasSupport("audio/ogg", QStringList(), QMediaPlayer::LowLatency), + QtMultimedia::ProbablySupported); + //Plugin4 is not checked here, sine it's known not support low latency + QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::LowLatency), + QtMultimedia::MaybeSupported); + + //test streaming flag support + QCOMPARE(QMediaPlayer::hasSupport("video/quicktime", QStringList(), QMediaPlayer::StreamPlayback), + QtMultimedia::ProbablySupported); + //Plugin2 is not checked here, sine it's known not support streaming + QCOMPARE(QMediaPlayer::hasSupport("audio/wav", QStringList(), QMediaPlayer::StreamPlayback), + QtMultimedia::MaybeSupported); + + //ensure the correct media player plugin is chosen for mime type + QMediaPlayer simplePlayer(0, QMediaPlayer::LowLatency); + QCOMPARE(simplePlayer.service()->objectName(), QLatin1String("MockServicePlugin2")); + + QMediaPlayer mediaPlayer; + QVERIFY(mediaPlayer.service()->objectName() != QLatin1String("MockServicePlugin2")); + + QMediaPlayer streamPlayer(0, QMediaPlayer::StreamPlayback); + QCOMPARE(streamPlayer.service()->objectName(), QLatin1String("MockServicePlugin4")); +} + +void tst_QMediaServiceProvider::testSupportedMimeTypes() +{ + QMediaServiceProvider *provider = QMediaServiceProvider::defaultServiceProvider(); + + if (provider == 0) + QSKIP("No default provider", SkipSingle); + + QVERIFY(provider->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)).contains("audio/ogg")); + QVERIFY(!provider->supportedMimeTypes(QByteArray(Q_MEDIASERVICE_MEDIAPLAYER)).contains("audio/mp3")); +} + +void tst_QMediaServiceProvider::testProviderHints() +{ + { + QMediaServiceProviderHint hint; + QVERIFY(hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::Null); + QVERIFY(hint.device().isEmpty()); + QVERIFY(hint.mimeType().isEmpty()); + QVERIFY(hint.codecs().isEmpty()); + QCOMPARE(hint.features(), 0); + } + + { + QByteArray deviceName(QByteArray("testDevice")); + QMediaServiceProviderHint hint(deviceName); + QVERIFY(!hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::Device); + QCOMPARE(hint.device(), deviceName); + QVERIFY(hint.mimeType().isEmpty()); + QVERIFY(hint.codecs().isEmpty()); + QCOMPARE(hint.features(), 0); + } + + { + QMediaServiceProviderHint hint(QMediaServiceProviderHint::LowLatencyPlayback); + QVERIFY(!hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures); + QVERIFY(hint.device().isEmpty()); + QVERIFY(hint.mimeType().isEmpty()); + QVERIFY(hint.codecs().isEmpty()); + QCOMPARE(hint.features(), QMediaServiceProviderHint::LowLatencyPlayback); + } + + { + QMediaServiceProviderHint hint(QMediaServiceProviderHint::RecordingSupport); + QVERIFY(!hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::SupportedFeatures); + QVERIFY(hint.device().isEmpty()); + QVERIFY(hint.mimeType().isEmpty()); + QVERIFY(hint.codecs().isEmpty()); + QCOMPARE(hint.features(), QMediaServiceProviderHint::RecordingSupport); + } + + { + QString mimeType(QLatin1String("video/ogg")); + QStringList codecs; + codecs << "theora" << "vorbis"; + + QMediaServiceProviderHint hint(mimeType,codecs); + QVERIFY(!hint.isNull()); + QCOMPARE(hint.type(), QMediaServiceProviderHint::ContentType); + QVERIFY(hint.device().isEmpty()); + QCOMPARE(hint.mimeType(), mimeType); + QCOMPARE(hint.codecs(), codecs); + + QMediaServiceProviderHint hint2(hint); + + QVERIFY(!hint2.isNull()); + QCOMPARE(hint2.type(), QMediaServiceProviderHint::ContentType); + QVERIFY(hint2.device().isEmpty()); + QCOMPARE(hint2.mimeType(), mimeType); + QCOMPARE(hint2.codecs(), codecs); + + QMediaServiceProviderHint hint3; + QVERIFY(hint3.isNull()); + hint3 = hint; + QVERIFY(!hint3.isNull()); + QCOMPARE(hint3.type(), QMediaServiceProviderHint::ContentType); + QVERIFY(hint3.device().isEmpty()); + QCOMPARE(hint3.mimeType(), mimeType); + QCOMPARE(hint3.codecs(), codecs); + + QCOMPARE(hint, hint2); + QCOMPARE(hint3, hint2); + + QMediaServiceProviderHint hint4(mimeType,codecs); + QCOMPARE(hint, hint4); + + QMediaServiceProviderHint hint5(mimeType,QStringList()); + QVERIFY(hint != hint5); + } +} + +QTEST_MAIN(tst_QMediaServiceProvider) + +#include "tst_qmediaserviceprovider.moc" diff --git a/tests/auto/unit/qmediatimerange/qmediatimerange.pro b/tests/auto/unit/qmediatimerange/qmediatimerange.pro new file mode 100644 index 000000000..0b6626015 --- /dev/null +++ b/tests/auto/unit/qmediatimerange/qmediatimerange.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qmediatimerange + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmediatimerange.cpp + diff --git a/tests/auto/unit/qmediatimerange/tst_qmediatimerange.cpp b/tests/auto/unit/qmediatimerange/tst_qmediatimerange.cpp new file mode 100644 index 000000000..dd8dc5ff9 --- /dev/null +++ b/tests/auto/unit/qmediatimerange/tst_qmediatimerange.cpp @@ -0,0 +1,806 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include + +QT_USE_NAMESPACE + +class tst_QMediaTimeRange: public QObject +{ + Q_OBJECT + +public slots: + +private slots: + void testCtor(); + void testIntervalCtor(); + void testGetters(); + void testAssignment(); + void testIntervalNormalize(); + void testIntervalTranslate(); + void testIntervalContains(); + void testEarliestLatest(); + void testContains(); + void testAddInterval(); + void testAddTimeRange(); + void testRemoveInterval(); + void testRemoveTimeRange(); + void testClear(); + void testComparisons(); + void testArithmetic(); +}; + +void tst_QMediaTimeRange::testIntervalCtor() +{ + //Default Ctor for Time Interval + /* create an instance for the time interval and verify the default cases */ + QMediaTimeInterval tInter; + QVERIFY(tInter.isNormal()); + QVERIFY(tInter.start() == 0); + QVERIFY(tInter.end() == 0); + + // (qint, qint) Ctor time interval + /* create an instace of QMediaTimeInterval passing start and end times and verify the all possible scenario's*/ + QMediaTimeInterval time(20,50); + QVERIFY(time.isNormal()); + QVERIFY(time.start() == 20); + QVERIFY(time.end() == 50); + + // Copy Ctor Time interval + QMediaTimeInterval other(time); + QVERIFY(other.isNormal() == time.isNormal()); + QVERIFY(other.start() == time.start()); + QVERIFY(other.end() == time.end()); + QVERIFY(other.contains(20) == time.contains(20)); + QVERIFY(other == time); +} + +void tst_QMediaTimeRange::testIntervalContains() +{ + QMediaTimeInterval time(20,50); + + /* start() <= time <= end(). Returns true if the time interval contains the specified time. */ + QVERIFY(!time.contains(10)); + QVERIFY(time.contains(20)); + QVERIFY(time.contains(30)); + QVERIFY(time.contains(50)); + QVERIFY(!time.contains(60)); + + QMediaTimeInterval x(20, 10); // denormal + + // Check denormal ranges + QVERIFY(!x.contains(5)); + QVERIFY(x.contains(10)); + QVERIFY(x.contains(15)); + QVERIFY(x.contains(20)); + QVERIFY(!x.contains(25)); + + QMediaTimeInterval y = x.normalized(); + QVERIFY(!y.contains(5)); + QVERIFY(y.contains(10)); + QVERIFY(y.contains(15)); + QVERIFY(y.contains(20)); + QVERIFY(!y.contains(25)); +} + +void tst_QMediaTimeRange::testCtor() +{ + // Default Ctor + QMediaTimeRange a; + QVERIFY(a.isEmpty()); + + // (qint, qint) Ctor + QMediaTimeRange b(10, 20); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 20); + + // Interval Ctor + QMediaTimeRange c(QMediaTimeInterval(30, 40)); + + QVERIFY(!c.isEmpty()); + QVERIFY(c.isContinuous()); + QVERIFY(c.earliestTime() == 30); + QVERIFY(c.latestTime() == 40); + + // Abnormal Interval Ctor + QMediaTimeRange d(QMediaTimeInterval(20, 10)); + + QVERIFY(d.isEmpty()); + + // Copy Ctor + QMediaTimeRange e(b); + + QVERIFY(!e.isEmpty()); + QVERIFY(e.isContinuous()); + QVERIFY(e.earliestTime() == 10); + QVERIFY(e.latestTime() == 20); + + QVERIFY(e == b); +} + +void tst_QMediaTimeRange::testGetters() +{ + QMediaTimeRange x; + + // isEmpty + QVERIFY(x.isEmpty()); + + x.addInterval(10, 20); + + // isEmpty + isContinuous + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + + x.addInterval(30, 40); + + // isEmpty + isContinuous + intervals + start + end + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.intervals().count() == 2); + QVERIFY(x.intervals()[0].start() == 10); + QVERIFY(x.intervals()[0].end() == 20); + QVERIFY(x.intervals()[1].start() == 30); + QVERIFY(x.intervals()[1].end() == 40); +} + +void tst_QMediaTimeRange::testAssignment() +{ + QMediaTimeRange x; + + // Range Assignment + x = QMediaTimeRange(10, 20); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 20); + + // Interval Assignment + x = QMediaTimeInterval(30, 40); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 30); + QVERIFY(x.latestTime() == 40); + + // Shared Data Check + QMediaTimeRange y; + + y = x; + y.addInterval(10, 20); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 30); + QVERIFY(x.latestTime() == 40); +} + +void tst_QMediaTimeRange::testIntervalNormalize() +{ + QMediaTimeInterval x(20, 10); + + QVERIFY(!x.isNormal()); + QVERIFY(x.start() == 20); + QVERIFY(x.end() == 10); + + QMediaTimeInterval y = x.normalized(); + + QVERIFY(y.isNormal()); + QVERIFY(y.start() == 10); + QVERIFY(y.end() == 20); + QVERIFY(x != y); +} + +void tst_QMediaTimeRange::testIntervalTranslate() +{ + QMediaTimeInterval x(10, 20); + x = x.translated(10); + + QVERIFY(x.start() == 20); + QVERIFY(x.end() == 30); + + /* verifying the backward through time with a negative offset.*/ + x = x.translated(-10); + + QVERIFY(x.start() == 10); + QVERIFY(x.end() == 20); +} + +void tst_QMediaTimeRange::testEarliestLatest() +{ + // Test over a single interval + QMediaTimeRange x(30, 40); + + QVERIFY(x.earliestTime() == 30); + QVERIFY(x.latestTime() == 40); + + // Test over multiple intervals + x.addInterval(50, 60); + + QVERIFY(x.earliestTime() == 30); + QVERIFY(x.latestTime() == 60); +} + +void tst_QMediaTimeRange::testContains() +{ + // Test over a single interval + QMediaTimeRange x(10, 20); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.contains(15)); + QVERIFY(x.contains(10)); + QVERIFY(x.contains(20)); + QVERIFY(!x.contains(25)); + + // Test over multiple intervals + x.addInterval(40, 50); + + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.contains(15)); + QVERIFY(x.contains(45)); + QVERIFY(!x.contains(30)); + + // Test over a concrete interval + QMediaTimeInterval y(10, 20); + QVERIFY(y.contains(15)); + QVERIFY(y.contains(10)); + QVERIFY(y.contains(20)); + QVERIFY(!y.contains(25)); +} + +void tst_QMediaTimeRange::testAddInterval() +{ + // All intervals Overlap + QMediaTimeRange x; + x.addInterval(10, 40); + x.addInterval(30, 50); + x.addInterval(20, 60); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 60); + + // 1 adjacent interval, 1 encompassed interval + x = QMediaTimeRange(); + x.addInterval(10, 40); + x.addInterval(20, 30); + x.addInterval(41, 50); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 50); + + // 1 overlapping interval, 1 disjoint interval + x = QMediaTimeRange(); + x.addInterval(10, 30); + x.addInterval(20, 40); + x.addInterval(50, 60); + + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.intervals().count() == 2); + QVERIFY(x.intervals()[0].start() == 10); + QVERIFY(x.intervals()[0].end() == 40); + QVERIFY(x.intervals()[1].start() == 50); + QVERIFY(x.intervals()[1].end() == 60); + + // Identical Add + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.addInterval(10, 20); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 20); + + // Multi-Merge + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.addInterval(30, 40); + x.addInterval(50, 60); + x.addInterval(15, 55); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 60); + + // Interval Parameter - All intervals Overlap + x = QMediaTimeRange(); + x.addInterval(QMediaTimeInterval(10, 40)); + x.addInterval(QMediaTimeInterval(30, 50)); + x.addInterval(QMediaTimeInterval(20, 60)); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 60); + + // Interval Parameter - Abnormal Interval + x = QMediaTimeRange(); + x.addInterval(QMediaTimeInterval(20, 10)); + + QVERIFY(x.isEmpty()); +} + +void tst_QMediaTimeRange::testAddTimeRange() +{ + // Add Time Range uses Add Interval internally, + // so in this test the focus is on combinations of number + // of intervals added, rather than the different types of + // merges which can occur. + QMediaTimeRange a, b; + + // Add Single into Single + a = QMediaTimeRange(10, 30); + b = QMediaTimeRange(20, 40); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 40); + + // Add Multiple into Single + a = QMediaTimeRange(); + a.addInterval(10, 30); + a.addInterval(40, 60); + + b = QMediaTimeRange(20, 50); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 60); + + // Add Single into Multiple + a = QMediaTimeRange(20, 50); + + b = QMediaTimeRange(); + b.addInterval(10, 30); + b.addInterval(40, 60); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 60); + + // Add Multiple into Multiple + a = QMediaTimeRange(); + a.addInterval(10, 30); + a.addInterval(40, 70); + a.addInterval(80, 100); + + b = QMediaTimeRange(); + b.addInterval(20, 50); + b.addInterval(60, 90); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 100); + + // Add Nothing to Single + a = QMediaTimeRange(); + b = QMediaTimeRange(10, 20); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 20); + + // Add Single to Nothing + a = QMediaTimeRange(10, 20); + b = QMediaTimeRange(); + + b.addTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 20); + + // Add Nothing to Nothing + a = QMediaTimeRange(); + b = QMediaTimeRange(); + + b.addTimeRange(a); + + QVERIFY(b.isEmpty()); +} + +void tst_QMediaTimeRange::testRemoveInterval() +{ + // Removing an interval, causing a split + QMediaTimeRange x; + x.addInterval(10, 50); + x.removeInterval(20, 40); + + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.intervals().count() == 2); + QVERIFY(x.intervals()[0].start() == 10); + QVERIFY(x.intervals()[0].end() == 19); + QVERIFY(x.intervals()[1].start() == 41); + QVERIFY(x.intervals()[1].end() == 50); + + // Removing an interval, causing a deletion + x = QMediaTimeRange(); + x.addInterval(20, 30); + x.removeInterval(10, 40); + + QVERIFY(x.isEmpty()); + + // Removing an interval, causing a tail trim + x = QMediaTimeRange(); + x.addInterval(20, 40); + x.removeInterval(30, 50); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 20); + QVERIFY(x.latestTime() == 29); + + // Removing an interval, causing a head trim + x = QMediaTimeRange(); + x.addInterval(20, 40); + x.removeInterval(10, 30); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 31); + QVERIFY(x.latestTime() == 40); + + // Identical Remove + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.removeInterval(10, 20); + + QVERIFY(x.isEmpty()); + + // Multi-Trim + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.addInterval(30, 40); + x.removeInterval(15, 35); + + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.intervals().count() == 2); + QVERIFY(x.intervals()[0].start() == 10); + QVERIFY(x.intervals()[0].end() == 14); + QVERIFY(x.intervals()[1].start() == 36); + QVERIFY(x.intervals()[1].end() == 40); + + // Multi-Delete + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.addInterval(30, 40); + x.addInterval(50, 60); + x.removeInterval(10, 60); + + QVERIFY(x.isEmpty()); + + // Interval Parameter - Removing an interval, causing a split + x = QMediaTimeRange(); + x.addInterval(10, 50); + x.removeInterval(QMediaTimeInterval(20, 40)); + + QVERIFY(!x.isEmpty()); + QVERIFY(!x.isContinuous()); + QVERIFY(x.intervals().count() == 2); + QVERIFY(x.intervals()[0].start() == 10); + QVERIFY(x.intervals()[0].end() == 19); + QVERIFY(x.intervals()[1].start() == 41); + QVERIFY(x.intervals()[1].end() == 50); + + // Interval Parameter - Abnormal Interval + x = QMediaTimeRange(); + x.addInterval(10, 40); + x.removeInterval(QMediaTimeInterval(30, 20)); + + QVERIFY(!x.isEmpty()); + QVERIFY(x.isContinuous()); + QVERIFY(x.earliestTime() == 10); + QVERIFY(x.latestTime() == 40); +} + +void tst_QMediaTimeRange::testRemoveTimeRange() +{ + // Remove Time Range uses Remove Interval internally, + // so in this test the focus is on combinations of number + // of intervals removed, rather than the different types of + // deletions which can occur. + QMediaTimeRange a, b; + + // Remove Single from Single + a = QMediaTimeRange(10, 30); + b = QMediaTimeRange(20, 40); + + b.removeTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 31); + QVERIFY(b.latestTime() == 40); + + // Remove Multiple from Single + a = QMediaTimeRange(); + a.addInterval(10, 30); + a.addInterval(40, 60); + + b = QMediaTimeRange(20, 50); + + b.removeTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 31); + QVERIFY(b.latestTime() == 39); + + // Remove Single from Multiple + a = QMediaTimeRange(20, 50); + + b = QMediaTimeRange(); + b.addInterval(10, 30); + b.addInterval(40, 60); + + b.removeTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(!b.isContinuous()); + QVERIFY(b.intervals().count() == 2); + QVERIFY(b.intervals()[0].start() == 10); + QVERIFY(b.intervals()[0].end() == 19); + QVERIFY(b.intervals()[1].start() == 51); + QVERIFY(b.intervals()[1].end() == 60); + + // Remove Multiple from Multiple + a = QMediaTimeRange(); + a.addInterval(20, 50); + a.addInterval(50, 90); + + + b = QMediaTimeRange(); + b.addInterval(10, 30); + b.addInterval(40, 70); + b.addInterval(80, 100); + + b.removeTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(!b.isContinuous()); + QVERIFY(b.intervals().count() == 2); + QVERIFY(b.intervals()[0].start() == 10); + QVERIFY(b.intervals()[0].end() == 19); + QVERIFY(b.intervals()[1].start() == 91); + QVERIFY(b.intervals()[1].end() == 100); + + // Remove Nothing from Single + a = QMediaTimeRange(); + b = QMediaTimeRange(10, 20); + + b.removeTimeRange(a); + + QVERIFY(!b.isEmpty()); + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 10); + QVERIFY(b.latestTime() == 20); + + // Remove Single from Nothing + a = QMediaTimeRange(10, 20); + b = QMediaTimeRange(); + + b.removeTimeRange(a); + + QVERIFY(b.isEmpty()); + + // Remove Nothing from Nothing + a = QMediaTimeRange(); + b = QMediaTimeRange(); + + b.removeTimeRange(a); + + QVERIFY(b.isEmpty()); +} + +void tst_QMediaTimeRange::testClear() +{ + QMediaTimeRange x; + + // Clear Nothing + x.clear(); + + QVERIFY(x.isEmpty()); + + // Clear Single + x = QMediaTimeRange(10, 20); + x.clear(); + + QVERIFY(x.isEmpty()); + + // Clear Multiple + x = QMediaTimeRange(); + x.addInterval(10, 20); + x.addInterval(30, 40); + x.clear(); + + QVERIFY(x.isEmpty()); +} + +void tst_QMediaTimeRange::testComparisons() +{ + // Interval equality + QVERIFY(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 20)); + QVERIFY(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 30)); + QVERIFY(!(QMediaTimeInterval(10, 20) != QMediaTimeInterval(10, 20))); + QVERIFY(!(QMediaTimeInterval(10, 20) == QMediaTimeInterval(10, 30))); + + // Time range equality - Single Interval + QMediaTimeRange a(10, 20), b(20, 30), c(10, 20); + + QVERIFY(a == c); + QVERIFY(!(a == b)); + QVERIFY(a != b); + QVERIFY(!(a != c)); + + // Time Range Equality - Multiple Intervals + QMediaTimeRange x, y, z; + + x.addInterval(10, 20); + x.addInterval(30, 40); + x.addInterval(50, 60); + + y.addInterval(10, 20); + y.addInterval(35, 45); + y.addInterval(50, 60); + + z.addInterval(10, 20); + z.addInterval(30, 40); + z.addInterval(50, 60); + + QVERIFY(x == z); + QVERIFY(!(x == y)); + QVERIFY(x != y); + QVERIFY(!(x != z)); +} + +void tst_QMediaTimeRange::testArithmetic() +{ + QMediaTimeRange a(10, 20), b(20, 30); + + // Test += + a += b; + + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 30); + + // Test -= + a -= b; + + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 19); + + // Test += and -= on intervals + a -= QMediaTimeInterval(10, 20); + a += QMediaTimeInterval(40, 50); + + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 40); + QVERIFY(a.latestTime() == 50); + + // Test Interval + Interval + a = QMediaTimeInterval(10, 20) + QMediaTimeInterval(20, 30); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 30); + + // Test Range + Interval + a = a + QMediaTimeInterval(30, 40); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 40); + + // Test Interval + Range + a = QMediaTimeInterval(40, 50) + a; + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 50); + + // Test Range + Range + a = a + QMediaTimeRange(50, 60); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 60); + + // Test Range - Interval + a = a - QMediaTimeInterval(50, 60); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 49); + + // Test Range - Range + a = a - QMediaTimeRange(40, 50); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 39); + + // Test Interval - Range + b = QMediaTimeInterval(0, 20) - a; + QVERIFY(b.isContinuous()); + QVERIFY(b.earliestTime() == 0); + QVERIFY(b.latestTime() == 9); + + // Test Interval - Interval + a = QMediaTimeInterval(10, 20) - QMediaTimeInterval(15, 30); + QVERIFY(a.isContinuous()); + QVERIFY(a.earliestTime() == 10); + QVERIFY(a.latestTime() == 14); +} + +QTEST_MAIN(tst_QMediaTimeRange) + +#include "tst_qmediatimerange.moc" diff --git a/tests/auto/unit/qmetadatareadercontrol/qmetadatareadercontrol.pro b/tests/auto/unit/qmetadatareadercontrol/qmetadatareadercontrol.pro new file mode 100644 index 000000000..0793a80af --- /dev/null +++ b/tests/auto/unit/qmetadatareadercontrol/qmetadatareadercontrol.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qmetadatareadercontrol + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmetadatareadercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) + diff --git a/tests/auto/unit/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp b/tests/auto/unit/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp new file mode 100644 index 000000000..30df40418 --- /dev/null +++ b/tests/auto/unit/qmetadatareadercontrol/tst_qmetadatareadercontrol.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include + +#include "mockmetadatareadercontrol.h" + +class tst_QMetaDataReaderControl : public QObject +{ + Q_OBJECT + +private slots: + // Test case for QMetaDataReaderControl + void metaDataReaderControlConstructor(); + void metaDataReaderControlAvailableMetaData(); + void metaDataReaderControlExtendedMetaData(); + void metaDataReaderControlIsMetaDataAvailable(); + void metaDataReaderControlMetaData(); + void metaDataReaderControlAvailableExtendedMetaData(); + void metaDataReaderControlMetaDataAvailableChangedSignal(); + void metaDataReaderControlMetaDataChangedSignal(); +}; + +QTEST_MAIN(tst_QMetaDataReaderControl); + +/* Test case for constructor. */ +void tst_QMetaDataReaderControl::metaDataReaderControlConstructor() +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + delete metaData; +} + +/* Test case for availableMetaData() */ +void tst_QMetaDataReaderControl::metaDataReaderControlAvailableMetaData() +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableMetaData() ; + delete metaData; +} + +/* Test case for extendedMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlExtendedMetaData () +{ + const QString titleKey(QLatin1String("Title")); + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->extendedMetaData(titleKey); + delete metaData; +} + +/* Test case for availableMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlIsMetaDataAvailable () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableMetaData(); + delete metaData; +} + +/* Test case for metaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaData () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->metaData(QtMultimedia::Title); + delete metaData; +} + +/* Test case for availableExtendedMetaData */ +void tst_QMetaDataReaderControl::metaDataReaderControlAvailableExtendedMetaData () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + metaData->availableExtendedMetaData(); + delete metaData; +} + +/* Test case for signal metaDataAvailableChanged */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaDataAvailableChangedSignal () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + QSignalSpy spy(metaData,SIGNAL(metaDataAvailableChanged(bool))); + metaData->setMetaDataAvailable(true); + QVERIFY(spy.count() == 1); + delete metaData; +} + + /* Test case for signal metaDataChanged */ +void tst_QMetaDataReaderControl::metaDataReaderControlMetaDataChangedSignal () +{ + MockMetaDataReaderControl *metaData = new MockMetaDataReaderControl(); + QVERIFY(metaData !=NULL); + QSignalSpy spy(metaData,SIGNAL(metaDataChanged())); + metaData->metaDataChanged(); + QVERIFY(spy.count () == 1); + delete metaData; +} + +#include "tst_qmetadatareadercontrol.moc" + + diff --git a/tests/auto/unit/qmetadatawritercontrol/qmetadatawritercontrol.pro b/tests/auto/unit/qmetadatawritercontrol/qmetadatawritercontrol.pro new file mode 100644 index 000000000..eef5d3239 --- /dev/null +++ b/tests/auto/unit/qmetadatawritercontrol/qmetadatawritercontrol.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +TARGET = tst_qmetadatawritercontrol + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qmetadatawritercontrol.cpp + +include (../qmultimedia_common/mockcontainer.pri) diff --git a/tests/auto/unit/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp b/tests/auto/unit/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp new file mode 100644 index 000000000..68d428151 --- /dev/null +++ b/tests/auto/unit/qmetadatawritercontrol/tst_qmetadatawritercontrol.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include "qmetadatawritercontrol.h" + +#include "mockmetadatawritercontrol.h" + +class tst_QMetaDataWriterControl: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void constructor(); +}; + +void tst_QMetaDataWriterControl::initTestCase() +{ + +} + +void tst_QMetaDataWriterControl::cleanupTestCase() +{ + +} + +//MaemoAPI-1862:test constructor +void tst_QMetaDataWriterControl::constructor() +{ + QMetaDataWriterControl *mock = new MockMetaDataWriterControl(); + mock->availableExtendedMetaData(); + mock->availableMetaData(); + mock->isMetaDataAvailable(); + mock->isWritable(); + mock->metaData((QtMultimedia::MetaData) 1 ); + mock->extendedMetaData(QString("XYZ")); + mock->setExtendedMetaData(QString("XYZ"),QVariant()); + mock->setMetaData((QtMultimedia::MetaData) 1,QVariant()); + ((MockMetaDataWriterControl*)mock)->setWritable(); + ((MockMetaDataWriterControl*)mock)->setMetaDataAvailable(); + delete mock; +} + +QTEST_MAIN(tst_QMetaDataWriterControl); + +#include "tst_qmetadatawritercontrol.moc" diff --git a/tests/auto/unit/qmultimedia_common/mock.pri b/tests/auto/unit/qmultimedia_common/mock.pri new file mode 100644 index 000000000..8b8f3e7fa --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mock.pri @@ -0,0 +1,7 @@ +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaserviceprovider.h \ + ../qmultimedia_common/mockmediaservice.h \ + ../qmultimedia_common/mockmediaobject.h diff --git a/tests/auto/unit/qmultimedia_common/mockaudioencodercontrol.h b/tests/auto/unit/qmultimedia_common/mockaudioencodercontrol.h new file mode 100644 index 000000000..85d18664a --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockaudioencodercontrol.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKAUDIOENCODERCONTROL_H +#define MOCKAUDIOENCODERCONTROL_H + +#include "qaudioencodercontrol.h" + +class MockAudioEncoderControl : public QAudioEncoderControl +{ + Q_OBJECT +public: + MockAudioEncoderControl(QObject *parent): + QAudioEncoderControl(parent) + { + m_codecs << "audio/pcm" << "audio/mpeg"; + m_descriptions << "Pulse Code Modulation" << "mp3 format"; + m_supportedEncodeOptions.insert("audio/pcm", QStringList()); + m_supportedEncodeOptions.insert("audio/mpeg", QStringList() << "quality" << "bitrate" << "mode" << "vbr"); + m_audioSettings.setCodec("audio/pcm"); + m_audioSettings.setBitRate(128*1024); + m_audioSettings.setSampleRate(8000); + m_freqs << 8000 << 11025 << 22050 << 44100; + } + + ~MockAudioEncoderControl() {} + + QAudioEncoderSettings audioSettings() const + { + return m_audioSettings; + } + + void setAudioSettings(const QAudioEncoderSettings &settings) + { + m_audioSettings = settings; + } + + QList supportedChannelCounts(const QAudioEncoderSettings & = QAudioEncoderSettings()) const + { + QList list; list << 1 << 2; return list; + } + + QList supportedSampleRates(const QAudioEncoderSettings & = QAudioEncoderSettings(), bool *continuous = 0) const + { + if (continuous) + *continuous = false; + + return m_freqs; + } + + QStringList supportedAudioCodecs() const + { + return m_codecs; + } + + QString codecDescription(const QString &codecName) const + { + return m_descriptions.value(m_codecs.indexOf(codecName)); + } + + QStringList supportedEncodingOptions(const QString &codec) const + { + return m_supportedEncodeOptions.value(codec); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + return m_encodeOptions[codec].value(name); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + m_encodeOptions[codec][name] = value; + } + +private: + QAudioEncoderSettings m_audioSettings; + + QStringList m_codecs; + QStringList m_descriptions; + + QList m_freqs; + + QMap m_supportedEncodeOptions; + QMap > m_encodeOptions; + +}; + +#endif // MOCKAUDIOENCODERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockaudioendpointselector.h b/tests/auto/unit/qmultimedia_common/mockaudioendpointselector.h new file mode 100644 index 000000000..2bc118d89 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockaudioendpointselector.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKAUDIOENDPOINTSELECTOR_H +#define MOCKAUDIOENDPOINTSELECTOR_H + +#include "qaudioendpointselector.h" + +class MockAudioEndpointSelector : public QAudioEndpointSelector +{ + Q_OBJECT +public: + MockAudioEndpointSelector(QObject *parent): + QAudioEndpointSelector(parent) + { + m_names << "device1" << "device2" << "device3"; + m_descriptions << "dev1 comment" << "dev2 comment" << "dev3 comment"; + m_audioInput = "device1"; + emit availableEndpointsChanged(); + } + ~MockAudioEndpointSelector() {} + + QList availableEndpoints() const + { + return m_names; + } + + QString endpointDescription(const QString& name) const + { + QString desc; + + for (int i = 0; i < m_names.count(); i++) { + if (m_names.at(i).compare(name) == 0) { + desc = m_descriptions.at(i); + break; + } + } + return desc; + } + + QString defaultEndpoint() const + { + return m_names.at(0); + } + + QString activeEndpoint() const + { + return m_audioInput; + } + +public Q_SLOTS: + + void setActiveEndpoint(const QString& name) + { + m_audioInput = name; + emit activeEndpointChanged(name); + } + + void addEndpoints() + { + m_names << "device4"; + emit availableEndpointsChanged(); + } + + void removeEndpoints() + { + m_names.clear(); + emit availableEndpointsChanged(); + } + +private: + QString m_audioInput; + QList m_names; + QList m_descriptions; +}; + + + +#endif // MOCKAUDIOENDPOINTSELECTOR_H diff --git a/tests/auto/unit/qmultimedia_common/mockcamera.pri b/tests/auto/unit/qmultimedia_common/mockcamera.pri new file mode 100644 index 000000000..233d5b8a2 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcamera.pri @@ -0,0 +1,22 @@ +# Camera related mock backend files +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/video \ + ../../../src/multimedia/camera + +HEADERS *= \ + ../qmultimedia_common/mockcameraservice.h \ + ../qmultimedia_common/mockcameraflashcontrol.h \ + ../qmultimedia_common/mockcameralockscontrol.h \ + ../qmultimedia_common/mockcamerafocuscontrol.h \ + ../qmultimedia_common/mockcameraimageprocessingcontrol.h \ + ../qmultimedia_common/mockcameraimagecapturecontrol.h \ + ../qmultimedia_common/mockcameraexposurecontrol.h \ + ../qmultimedia_common/mockcameracapturedestinationcontrol.h \ + ../qmultimedia_common/mockcameracapturebuffercontrol.h \ + ../qmultimedia_common/mockimageencodercontrol.h \ + ../qmultimedia_common/mockcameracontrol.h \ + + +include(mockvideo.pri) + diff --git a/tests/auto/unit/qmultimedia_common/mockcameracapturebuffercontrol.h b/tests/auto/unit/qmultimedia_common/mockcameracapturebuffercontrol.h new file mode 100644 index 000000000..d71794635 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameracapturebuffercontrol.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTUREBUFFERCONTROL_H +#define MOCKCAMERACAPTUREBUFFERCONTROL_H + +#include "qcameracapturebufferformatcontrol.h" + +class MockCaptureBufferFormatControl : public QCameraCaptureBufferFormatControl +{ + Q_OBJECT +public: + MockCaptureBufferFormatControl(QObject *parent = 0): + QCameraCaptureBufferFormatControl(parent), + m_format(QVideoFrame::Format_Jpeg) + { + } + + QList supportedBufferFormats() const + { + return QList() + << QVideoFrame::Format_Jpeg + << QVideoFrame::Format_RGB32 + << QVideoFrame::Format_AdobeDng; + } + + QVideoFrame::PixelFormat bufferFormat() const + { + return m_format; + } + + void setBufferFormat(QVideoFrame::PixelFormat format) + { + if (format != m_format && supportedBufferFormats().contains(format)) { + m_format = format; + emit bufferFormatChanged(m_format); + } + } + +private: + QVideoFrame::PixelFormat m_format; +}; + + +#endif // MOCKCAMERACAPTUREBUFFERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameracapturedestinationcontrol.h b/tests/auto/unit/qmultimedia_common/mockcameracapturedestinationcontrol.h new file mode 100644 index 000000000..3f7697d1c --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameracapturedestinationcontrol.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTUREDESTINATIONCONTROL_H +#define MOCKCAMERACAPTUREDESTINATIONCONTROL_H + +#include "qcameracapturedestinationcontrol.h" + +class MockCaptureDestinationControl : public QCameraCaptureDestinationControl +{ + Q_OBJECT +public: + MockCaptureDestinationControl(QObject *parent = 0): + QCameraCaptureDestinationControl(parent), + m_destination(QCameraImageCapture::CaptureToFile) + { + } + + bool isCaptureDestinationSupported(QCameraImageCapture::CaptureDestinations destination) const + { + return destination == QCameraImageCapture::CaptureToBuffer || + destination == QCameraImageCapture::CaptureToFile; + } + + QCameraImageCapture::CaptureDestinations captureDestination() const + { + return m_destination; + } + + void setCaptureDestination(QCameraImageCapture::CaptureDestinations destination) + { + if (isCaptureDestinationSupported(destination) && destination != m_destination) { + m_destination = destination; + emit captureDestinationChanged(m_destination); + } + } + +private: + QCameraImageCapture::CaptureDestinations m_destination; +}; + +#endif // MOCKCAMERACAPTUREDESTINATIONCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameracontrol.h b/tests/auto/unit/qmultimedia_common/mockcameracontrol.h new file mode 100644 index 000000000..893ecbfd8 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameracontrol.h @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACONTROL_H +#define MOCKCAMERACONTROL_H + +#include "qcameracontrol.h" + +class MockCameraControl : public QCameraControl +{ + friend class MockCaptureControl; + Q_OBJECT +public: + MockCameraControl(QObject *parent = 0): + QCameraControl(parent), + m_state(QCamera::UnloadedState), + m_captureMode(QCamera::CaptureStillImage), + m_status(QCamera::UnloadedStatus), + m_propertyChangesSupported(false) + { + } + + ~MockCameraControl() {} + + void start() { m_state = QCamera::ActiveState; } + virtual void stop() { m_state = QCamera::UnloadedState; } + QCamera::State state() const { return m_state; } + void setState(QCamera::State state) { + if (m_state != state) { + m_state = state; + + switch (state) { + case QCamera::UnloadedState: + m_status = QCamera::UnloadedStatus; + break; + case QCamera::LoadedState: + m_status = QCamera::LoadedStatus; + break; + case QCamera::ActiveState: + m_status = QCamera::ActiveStatus; + break; + default: + emit error(QCamera::NotSupportedFeatureError, "State not supported."); + return; + } + + emit stateChanged(m_state); + emit statusChanged(m_status); + } + } + + QCamera::Status status() const { return m_status; } + + QCamera::CaptureMode captureMode() const { return m_captureMode; } + void setCaptureMode(QCamera::CaptureMode mode) + { + if (m_captureMode != mode) { + if (m_state == QCamera::ActiveState && !m_propertyChangesSupported) + return; + m_captureMode = mode; + emit captureModeChanged(mode); + } + } + + bool isCaptureModeSupported(QCamera::CaptureMode mode) const + { + return mode == QCamera::CaptureStillImage || mode == QCamera::CaptureVideo; + } + + QCamera::LockTypes supportedLocks() const + { + return QCamera::LockExposure | QCamera::LockFocus | QCamera::LockWhiteBalance; + } + + bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const + { + Q_UNUSED(status); + if (changeType == QCameraControl::ImageEncodingSettings && m_captureMode == QCamera::CaptureVideo) + return true; + else if (changeType== QCameraControl::VideoEncodingSettings) + return true; + else + return m_propertyChangesSupported; + } + + /* helper method to emit the signal error */ + void setError(QCamera::Error err, QString errorString) + { + emit error(err, errorString); + } + + /* helper method to emit the signal statusChaged */ + void setStatus(QCamera::Status newStatus) + { + m_status = newStatus; + emit statusChanged(newStatus); + } + + QCamera::State m_state; + QCamera::CaptureMode m_captureMode; + QCamera::Status m_status; + bool m_propertyChangesSupported; +}; + + + +#endif // MOCKCAMERACONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameraexposurecontrol.h b/tests/auto/unit/qmultimedia_common/mockcameraexposurecontrol.h new file mode 100644 index 000000000..d89762d43 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraexposurecontrol.h @@ -0,0 +1,282 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAEXPOSURECONTROL_H +#define MOCKCAMERAEXPOSURECONTROL_H + +#include "qcameraexposurecontrol.h" + +class MockCameraExposureControl : public QCameraExposureControl +{ + Q_OBJECT +public: + MockCameraExposureControl(QObject *parent = 0): + QCameraExposureControl(parent), + m_aperture(2.8), + m_shutterSpeed(0.01), + m_isoSensitivity(100), + m_meteringMode(QCameraExposure::MeteringMatrix), + m_exposureCompensation(0), + m_exposureMode(QCameraExposure::ExposureAuto), + m_flashMode(QCameraExposure::FlashAuto) + { + m_isoRanges << 100 << 200 << 400 << 800; + m_apertureRanges << 2.8 << 4.0 << 5.6 << 8.0 << 11.0 << 16.0; + m_shutterRanges << 0.001 << 0.01 << 0.1 << 1.0; + m_exposureRanges << -2.0 << 2.0; + } + + ~MockCameraExposureControl() {} + + QCameraExposure::FlashModes flashMode() const {return m_flashMode;} + + void setFlashMode(QCameraExposure::FlashModes mode) + { + if (isFlashModeSupported(mode)) { + m_flashMode = mode; + } + } + + bool isFlashModeSupported(QCameraExposure::FlashModes mode) const + { + return mode & (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn); + } + + bool isFlashReady() const { return true;} + + QCameraExposure::ExposureMode exposureMode() const { return m_exposureMode; } + + void setExposureMode(QCameraExposure::ExposureMode mode) + { + if (isExposureModeSupported(mode)) + m_exposureMode = mode; + } + + //Setting the Exposure Mode Supported Enum values + bool isExposureModeSupported(QCameraExposure::ExposureMode mode) const + { + return ( mode == QCameraExposure::ExposureAuto || mode == QCameraExposure::ExposureManual || mode == QCameraExposure::ExposureBacklight || + mode == QCameraExposure::ExposureNight || mode == QCameraExposure::ExposureSpotlight ||mode == QCameraExposure::ExposureSports || + mode == QCameraExposure::ExposureSnow || mode == QCameraExposure:: ExposureLargeAperture ||mode == QCameraExposure::ExposureSmallAperture || + mode == QCameraExposure::ExposurePortrait || mode == QCameraExposure::ExposureModeVendor ||mode == QCameraExposure::ExposureBeach ); + } + + bool isParameterSupported(ExposureParameter parameter) const + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + case QCameraExposureControl::ISO: + case QCameraExposureControl::Aperture: + case QCameraExposureControl::ShutterSpeed: + return true; + default: + return false; + } + } + + QVariant exposureParameter(ExposureParameter parameter) const + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + return QVariant(m_exposureCompensation); + case QCameraExposureControl::ISO: + return QVariant(m_isoSensitivity); + case QCameraExposureControl::Aperture: + return QVariant(m_aperture); + case QCameraExposureControl::ShutterSpeed: + return QVariant(m_shutterSpeed); + default: + return QVariant(); + } + } + + QVariantList supportedParameterRange(ExposureParameter parameter) const + { + QVariantList res; + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + return m_exposureRanges; + case QCameraExposureControl::ISO: + return m_isoRanges; + case QCameraExposureControl::Aperture: + return m_apertureRanges; + case QCameraExposureControl::ShutterSpeed: + return m_shutterRanges; + default: + break; + } + + return res; + } + + ParameterFlags exposureParameterFlags(ExposureParameter parameter) const + { + ParameterFlags res = 0; + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + case QCameraExposureControl::Aperture: + case QCameraExposureControl::ShutterSpeed: + res |= ContinuousRange; + default: + break; + } + + return res; + } + + // Added exposureParameterChanged and exposureParameterRangeChanged signal + bool setExposureParameter(ExposureParameter parameter, const QVariant& value) + { + switch (parameter) { + case QCameraExposureControl::ExposureCompensation: + { + m_res.clear(); + m_res << -4.0 << 4.0; + qreal exposureCompensationlocal = qBound(-2.0, value.toReal(), 2.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_exposureCompensation = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_exposureRanges.last().toReal() != m_res.last().toReal()) { + m_exposureRanges.clear(); + m_exposureRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::ISO: + { + m_res.clear(); + m_res << 20 << 50; + qreal exposureCompensationlocal = 100*qRound(qBound(100, value.toInt(), 800)/100.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_isoSensitivity = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_isoRanges.last().toInt() != m_res.last().toInt()) { + m_isoRanges.clear(); + m_isoRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::Aperture: + { + m_res.clear(); + m_res << 12.0 << 18.0 << 20.0; + qreal exposureCompensationlocal = qBound(2.8, value.toReal(), 16.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_aperture = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_apertureRanges.last().toReal() != m_res.last().toReal()) { + m_apertureRanges.clear(); + m_apertureRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + case QCameraExposureControl::ShutterSpeed: + { + m_res.clear(); + m_res << 0.12 << 1.0 << 2.0; + qreal exposureCompensationlocal = qBound(0.001, value.toReal(), 1.0); + if (exposureParameter(parameter).toReal() != exposureCompensationlocal) { + m_shutterSpeed = exposureCompensationlocal; + emit exposureParameterChanged(parameter); + } + + if (m_shutterRanges.last().toReal() != m_res.last().toReal()) { + m_shutterRanges.clear(); + m_shutterRanges = m_res; + emit exposureParameterRangeChanged(parameter); + } + } + break; + default: + return false; + } + + emit flashReady(true); // depends on Flashcontrol + + return true; + } + + QString extendedParameterName(ExposureParameter) + { + return QString(); + } + + QCameraExposure::MeteringMode meteringMode() const + { + return m_meteringMode; + } + + void setMeteringMode(QCameraExposure::MeteringMode mode) + { + if (isMeteringModeSupported(mode)) + m_meteringMode = mode; + } + + //Setting the values for metering mode + bool isMeteringModeSupported(QCameraExposure::MeteringMode mode) const + { + return mode == QCameraExposure::MeteringAverage + || mode == QCameraExposure::MeteringMatrix + || mode == QCameraExposure::MeteringAverage + || mode ==QCameraExposure::MeteringSpot; + } + +private: + qreal m_aperture; + qreal m_shutterSpeed; + int m_isoSensitivity; + QCameraExposure::MeteringMode m_meteringMode; + qreal m_exposureCompensation; + QCameraExposure::ExposureMode m_exposureMode; + QCameraExposure::FlashModes m_flashMode; + QVariantList m_isoRanges,m_apertureRanges, m_shutterRanges, m_exposureRanges, m_res; +}; + +#endif // MOCKCAMERAEXPOSURECONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameraflashcontrol.h b/tests/auto/unit/qmultimedia_common/mockcameraflashcontrol.h new file mode 100644 index 000000000..f7a795055 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraflashcontrol.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAFLASHCONTROL_H +#define MOCKCAMERAFLASHCONTROL_H + +#include "qcameraflashcontrol.h" + +class MockCameraFlashControl : public QCameraFlashControl +{ + Q_OBJECT +public: + MockCameraFlashControl(QObject *parent = 0): + QCameraFlashControl(parent), + m_flashMode(QCameraExposure::FlashAuto) + { + } + + ~MockCameraFlashControl() {} + + QCameraExposure::FlashModes flashMode() const + { + return m_flashMode; + } + + void setFlashMode(QCameraExposure::FlashModes mode) + { + if (isFlashModeSupported(mode)) { + m_flashMode = mode; + } + emit flashReady(true); + } + //Setting the values for Flash mode + + bool isFlashModeSupported(QCameraExposure::FlashModes mode) const + { + return (mode || (QCameraExposure::FlashAuto | QCameraExposure::FlashOff | QCameraExposure::FlashOn | + QCameraExposure::FlashFill |QCameraExposure::FlashTorch |QCameraExposure::FlashSlowSyncFrontCurtain | + QCameraExposure::FlashRedEyeReduction)); + } + + bool isFlashReady() const + { + return true; + } + +private: + QCameraExposure::FlashModes m_flashMode; +}; + +#endif // MOCKCAMERAFLASHCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcamerafocuscontrol.h b/tests/auto/unit/qmultimedia_common/mockcamerafocuscontrol.h new file mode 100644 index 000000000..a0fb48199 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcamerafocuscontrol.h @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAFOCUSCONTROL_H +#define MOCKCAMERAFOCUSCONTROL_H + +#include "qcamerafocuscontrol.h" +#include "qcamerafocus.h" + +class MockCameraFocusControl : public QCameraFocusControl +{ + Q_OBJECT +public: + MockCameraFocusControl(QObject *parent = 0): + QCameraFocusControl(parent), + m_opticalZoom(1.0), + m_digitalZoom(1.0), + m_focusMode(QCameraFocus::AutoFocus), + m_focusPointMode(QCameraFocus::FocusPointAuto), + m_focusPoint(0.5, 0.5), + m_maxOpticalZoom(3.0), + m_maxDigitalZoom(4.0) + + { + m_zones << QCameraFocusZone(QRectF(0.45, 0.45, 0.1, 0.1)); + } + + ~MockCameraFocusControl() {} + + QCameraFocus::FocusMode focusMode() const + { + return m_focusMode; + } + + void setFocusMode(QCameraFocus::FocusMode mode) + { + if (isFocusModeSupported(mode)) + m_focusMode = mode; + } + + bool isFocusModeSupported(QCameraFocus::FocusMode mode) const + { + return mode == QCameraFocus::AutoFocus || mode == QCameraFocus::ContinuousFocus; + } + + qreal maximumOpticalZoom() const + { + return m_maxOpticalZoom; + } + + qreal maximumDigitalZoom() const + { + return m_maxDigitalZoom; + } + + qreal opticalZoom() const + { + return m_opticalZoom; + } + + qreal digitalZoom() const + { + return m_digitalZoom; + } + + void zoomTo(qreal optical, qreal digital) + { + optical = qBound(1.0, optical, maximumOpticalZoom()); + digital = qBound(1.0, digital, maximumDigitalZoom()); + + if (!qFuzzyCompare(digital, m_digitalZoom)) { + m_digitalZoom = digital; + emit digitalZoomChanged(m_digitalZoom); + } + + if (!qFuzzyCompare(optical, m_opticalZoom)) { + m_opticalZoom = optical; + emit opticalZoomChanged(m_opticalZoom); + } + + maxOpticalDigitalZoomChange(4.0, 5.0); + focusZonesChange(0.50, 0.50, 0.3, 0.3); + } + + QCameraFocus::FocusPointMode focusPointMode() const + { + return m_focusPointMode; + } + + void setFocusPointMode(QCameraFocus::FocusPointMode mode) + { + if (isFocusPointModeSupported(mode)) + m_focusPointMode = mode; + } + + bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const + { + switch (mode) { + case QCameraFocus::FocusPointAuto: + case QCameraFocus::FocusPointCenter: + case QCameraFocus::FocusPointCustom: + return true; + default: + return false; + } + } + + QPointF customFocusPoint() const + { + return m_focusPoint; + } + + void setCustomFocusPoint(const QPointF &point) + { + m_focusPoint = point; + } + + QCameraFocusZoneList focusZones() const + { + return m_zones; + } + + // helper function to emit maximum Optical and Digital Zoom Changed signals + void maxOpticalDigitalZoomChange(qreal maxOptical, qreal maxDigital) + { + if (maxOptical != m_maxOpticalZoom) { + m_maxOpticalZoom = maxOptical; + emit maximumOpticalZoomChanged(m_maxOpticalZoom); + } + + if (maxDigital != m_maxDigitalZoom) { + m_maxDigitalZoom = maxDigital; + emit maximumDigitalZoomChanged(m_maxDigitalZoom); + } + } + + // helper function to emit Focus Zones Changed signals + void focusZonesChange(qreal left, qreal top, qreal width, qreal height) + { + QCameraFocusZone myZone(QRectF(left, top, width, height)); + if (m_zones.last().area() != myZone.area()) { + m_zones.clear(); + m_zones << myZone; + emit focusZonesChanged(); + } + } + +private: + qreal m_opticalZoom; + qreal m_digitalZoom; + QCameraFocus::FocusMode m_focusMode; + QCameraFocus::FocusPointMode m_focusPointMode; + QPointF m_focusPoint; + // to emit maximum Optical and Digital Zoom Changed signals + qreal m_maxOpticalZoom; + qreal m_maxDigitalZoom; + // to emit focus zone changed signal + QCameraFocusZoneList m_zones; +}; + +#endif // MOCKCAMERAFOCUSCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameraimagecapturecontrol.h b/tests/auto/unit/qmultimedia_common/mockcameraimagecapturecontrol.h new file mode 100644 index 000000000..5fb3cb19d --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraimagecapturecontrol.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERACAPTURECONTROL_H +#define MOCKCAMERACAPTURECONTROL_H + +#include +#include + +#include "qcameraimagecapturecontrol.h" +#include "qcameracontrol.h" +#include "mockcameracontrol.h" + +class MockCaptureControl : public QCameraImageCaptureControl +{ + Q_OBJECT +public: + MockCaptureControl(MockCameraControl *cameraControl, QObject *parent = 0) + : QCameraImageCaptureControl(parent), m_cameraControl(cameraControl), m_captureRequest(0), m_ready(true), m_captureCanceled(false) + { + } + + ~MockCaptureControl() + { + } + + QCameraImageCapture::DriveMode driveMode() const { return QCameraImageCapture::SingleImageCapture; } + void setDriveMode(QCameraImageCapture::DriveMode) {} + + bool isReadyForCapture() const { return m_ready && m_cameraControl->state() == QCamera::ActiveState; } + + int capture(const QString &fileName) + { + if (isReadyForCapture()) { + m_fileName = fileName; + m_captureRequest++; + emit readyForCaptureChanged(m_ready = false); + QTimer::singleShot(5, this, SLOT(captured())); + return m_captureRequest; + } else { + emit error(-1, QCameraImageCapture::NotReadyError, + QLatin1String("Could not capture in stopped state")); + } + + return -1; + } + + void cancelCapture() + { + m_captureCanceled = true; + } + +private Q_SLOTS: + void captured() + { + if (!m_captureCanceled) { + emit imageCaptured(m_captureRequest, QImage()); + + emit imageMetadataAvailable(m_captureRequest, + QtMultimedia::FocalLengthIn35mmFilm, + QVariant(50)); + + emit imageMetadataAvailable(m_captureRequest, + QtMultimedia::DateTimeOriginal, + QVariant(QDateTime::currentDateTime())); + + emit imageMetadataAvailable(m_captureRequest, + QLatin1String("Answer to the Ultimate Question of Life, the Universe, and Everything"), + QVariant(42)); + } + + if (!m_ready) + { + emit readyForCaptureChanged(m_ready = true); + emit imageExposed(m_captureRequest); + } + + if (!m_captureCanceled) + emit imageSaved(m_captureRequest, m_fileName); + + m_captureCanceled = false; + } + +private: + MockCameraControl *m_cameraControl; + QString m_fileName; + int m_captureRequest; + bool m_ready; + bool m_captureCanceled; +}; + +#endif // MOCKCAMERACAPTURECONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameraimageprocessingcontrol.h b/tests/auto/unit/qmultimedia_common/mockcameraimageprocessingcontrol.h new file mode 100644 index 000000000..f02f2b404 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraimageprocessingcontrol.h @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAIMAGEPROCESSINGCONTROL_H +#define MOCKCAMERAIMAGEPROCESSINGCONTROL_H + +#include "qcameraimageprocessingcontrol.h" + +class MockImageProcessingControl : public QCameraImageProcessingControl +{ + Q_OBJECT +public: + MockImageProcessingControl(QObject *parent = 0) + : QCameraImageProcessingControl(parent) + { + m_supportedWhiteBalance.insert(QCameraImageProcessing::WhiteBalanceAuto); + } + + QCameraImageProcessing::WhiteBalanceMode whiteBalanceMode() const + { + return m_whiteBalanceMode; + } + void setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceMode mode) + { + m_whiteBalanceMode = mode; + } + + bool isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode mode) const + { + return m_supportedWhiteBalance.contains(mode); + } + + void setSupportedWhiteBalanceModes(QSet modes) + { + m_supportedWhiteBalance = modes; + } + + bool isProcessingParameterSupported(ProcessingParameter parameter) const + { + //return parameter == Contrast || parameter == Sharpening || parameter == ColorTemperature; + switch (parameter) + { + case Contrast: + case Brightness: + case Sharpening: + case Saturation: + case Denoising: + case ColorTemperature: + case ExtendedParameter: + return true; + default : + return false; + } + } + QVariant processingParameter(ProcessingParameter parameter) const + { + switch (parameter) { + case Contrast: + return m_contrast; + case Saturation: + return m_saturation; + case Brightness: + return m_brightness; + case Sharpening: + return m_sharpeningLevel; + case Denoising: + return m_denoising; + case ColorTemperature: + return m_manualWhiteBalance; + case ExtendedParameter: + return m_extendedParameter; + default: + return QVariant(); + } + } + void setProcessingParameter(ProcessingParameter parameter, QVariant value) + { + switch (parameter) { + case Contrast: + m_contrast = value; + break; + case Saturation: + m_saturation = value; + break; + case Brightness: + m_brightness = value; + break; + case Sharpening: + m_sharpeningLevel = value; + break; + case Denoising: + m_denoising = value; + break; + case ColorTemperature: + m_manualWhiteBalance = value; + break; + case ExtendedParameter: + m_extendedParameter = value; + break; + default: + break; + } + } + + +private: + QCameraImageProcessing::WhiteBalanceMode m_whiteBalanceMode; + QSet m_supportedWhiteBalance; + QVariant m_manualWhiteBalance; + QVariant m_contrast; + QVariant m_sharpeningLevel; + QVariant m_saturation; + QVariant m_brightness; + QVariant m_denoising; + QVariant m_extendedParameter; +}; + +#endif // MOCKCAMERAIMAGEPROCESSINGCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameralockscontrol.h b/tests/auto/unit/qmultimedia_common/mockcameralockscontrol.h new file mode 100644 index 000000000..87c40947d --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameralockscontrol.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERALOCKCONTROL_H +#define MOCKCAMERALOCKCONTROL_H + +#include +#include "qcameralockscontrol.h" + +class MockCameraLocksControl : public QCameraLocksControl +{ + Q_OBJECT +public: + MockCameraLocksControl(QObject *parent = 0): + QCameraLocksControl(parent), + m_focusLock(QCamera::Unlocked), + m_exposureLock(QCamera::Unlocked) + { + } + + ~MockCameraLocksControl() {} + + QCamera::LockTypes supportedLocks() const + { + return QCamera::LockExposure | QCamera::LockFocus; + } + + QCamera::LockStatus lockStatus(QCamera::LockType lock) const + { + switch (lock) { + case QCamera::LockExposure: + return m_exposureLock; + case QCamera::LockFocus: + return m_focusLock; + default: + return QCamera::Unlocked; + } + } + + void searchAndLock(QCamera::LockTypes locks) + { + if (locks & QCamera::LockExposure) { + QCamera::LockStatus newStatus = locks & QCamera::LockFocus ? QCamera::Searching : QCamera::Locked; + + if (newStatus != m_exposureLock) + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = newStatus, + QCamera::UserRequest); + } + + if (locks & QCamera::LockFocus) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Searching, + QCamera::UserRequest); + + QTimer::singleShot(5, this, SLOT(focused())); + } + } + + void unlock(QCamera::LockTypes locks) { + if (locks & QCamera::LockFocus && m_focusLock != QCamera::Unlocked) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Unlocked, + QCamera::UserRequest); + } + + if (locks & QCamera::LockExposure && m_exposureLock != QCamera::Unlocked) { + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = QCamera::Unlocked, + QCamera::UserRequest); + } + } + + /* helper method to emit the signal with LockChangeReason */ + void setLockChangeReason (QCamera::LockChangeReason lockChangeReason) + { + emit lockStatusChanged(QCamera::NoLock, + QCamera::Unlocked, + lockChangeReason); + + } + +private slots: + void focused() + { + if (m_focusLock == QCamera::Searching) { + emit lockStatusChanged(QCamera::LockFocus, + m_focusLock = QCamera::Locked, + QCamera::UserRequest); + } + + if (m_exposureLock == QCamera::Searching) { + emit lockStatusChanged(QCamera::LockExposure, + m_exposureLock = QCamera::Locked, + QCamera::UserRequest); + } + } + + +private: + QCamera::LockStatus m_focusLock; + QCamera::LockStatus m_exposureLock; +}; + + +#endif // MOCKCAMERALOCKCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockcameraservice.h b/tests/auto/unit/qmultimedia_common/mockcameraservice.h new file mode 100644 index 000000000..ea0620a13 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraservice.h @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERASERVICE_H +#define MOCKCAMERASERVICE_H + +#include "qmediaservice.h" +#include "../qmultimedia_common/mockcameraflashcontrol.h" +#include "../qmultimedia_common/mockcameralockscontrol.h" +#include "../qmultimedia_common/mockcamerafocuscontrol.h" +#include "../qmultimedia_common/mockcameraimageprocessingcontrol.h" +#include "../qmultimedia_common/mockcameraimagecapturecontrol.h" +#include "../qmultimedia_common/mockcameraexposurecontrol.h" +#include "../qmultimedia_common/mockcameracapturedestinationcontrol.h" +#include "../qmultimedia_common/mockcameracapturebuffercontrol.h" +#include "../qmultimedia_common/mockimageencodercontrol.h" +#include "../qmultimedia_common/mockcameracontrol.h" +#include "../qmultimedia_common/mockvideosurface.h" +#include "../qmultimedia_common/mockvideorenderercontrol.h" + +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) +#include "../qmultimedia_common/mockvideowindowcontrol.h" +#endif + +class MockSimpleCameraService : public QMediaService +{ + Q_OBJECT + +public: + MockSimpleCameraService(): QMediaService(0) + { + mockControl = new MockCameraControl(this); + } + + ~MockSimpleCameraService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QCameraControl_iid) == 0) + return mockControl; + return 0; + } + + void releaseControl(QMediaControl*) {} + + MockCameraControl *mockControl; +}; + + +class MockCameraService : public QMediaService +{ + Q_OBJECT + +public: + MockCameraService(): QMediaService(0) + { + mockControl = new MockCameraControl(this); + mockLocksControl = new MockCameraLocksControl(this); + mockExposureControl = new MockCameraExposureControl(this); + mockFlashControl = new MockCameraFlashControl(this); + mockFocusControl = new MockCameraFocusControl(this); + mockCaptureControl = new MockCaptureControl(mockControl, this); + mockCaptureBufferControl = new MockCaptureBufferFormatControl(this); + mockCaptureDestinationControl = new MockCaptureDestinationControl(this); + mockImageProcessingControl = new MockImageProcessingControl(this); + mockImageEncoderControl = new MockImageEncoderControl(this); + rendererControl = new MockVideoRendererControl(this); +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + windowControl = new MockVideoWindowControl(this); +#endif + rendererRef = 0; + windowRef = 0; + } + + ~MockCameraService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QCameraControl_iid) == 0) + return mockControl; + + if (qstrcmp(iid, QCameraLocksControl_iid) == 0) + return mockLocksControl; + + if (qstrcmp(iid, QCameraExposureControl_iid) == 0) + return mockExposureControl; + + if (qstrcmp(iid, QCameraFlashControl_iid) == 0) + return mockFlashControl; + + if (qstrcmp(iid, QCameraFocusControl_iid) == 0) + return mockFocusControl; + + if (qstrcmp(iid, QCameraImageCaptureControl_iid) == 0) + return mockCaptureControl; + + if (qstrcmp(iid, QCameraCaptureBufferFormatControl_iid) == 0) + return mockCaptureBufferControl; + + if (qstrcmp(iid, QCameraCaptureDestinationControl_iid) == 0) + return mockCaptureDestinationControl; + + if (qstrcmp(iid, QCameraImageProcessingControl_iid) == 0) + return mockImageProcessingControl; + + if (qstrcmp(iid, QImageEncoderControl_iid) == 0) + return mockImageEncoderControl; + + if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { + if (rendererRef == 0) { + rendererRef += 1; + return rendererControl; + } + } +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { + if (windowRef == 0) { + windowRef += 1; + return windowControl; + } + } +#endif + return 0; + } + + void releaseControl(QMediaControl *control) + { + if (control == rendererControl) + rendererRef -= 1; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + if (control == windowControl) + windowRef -= 1; +#endif + } + + MockCameraControl *mockControl; + MockCameraLocksControl *mockLocksControl; + MockCaptureControl *mockCaptureControl; + MockCaptureBufferFormatControl *mockCaptureBufferControl; + MockCaptureDestinationControl *mockCaptureDestinationControl; + MockCameraExposureControl *mockExposureControl; + MockCameraFlashControl *mockFlashControl; + MockCameraFocusControl *mockFocusControl; + MockImageProcessingControl *mockImageProcessingControl; + MockImageEncoderControl *mockImageEncoderControl; + MockVideoRendererControl *rendererControl; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + MockVideoWindowControl *windowControl; +#endif + int rendererRef; + int windowRef; +}; + +#endif // MOCKCAMERASERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockcontainer.pri b/tests/auto/unit/qmultimedia_common/mockcontainer.pri new file mode 100644 index 000000000..e4a345adb --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcontainer.pri @@ -0,0 +1,7 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediacontainercontrol.h \ + ../qmultimedia_common/mockmetadatawritercontrol.h \ + ../qmultimedia_common/mockmetadatareadercontrol.h diff --git a/tests/auto/unit/qmultimedia_common/mockimageencodercontrol.h b/tests/auto/unit/qmultimedia_common/mockimageencodercontrol.h new file mode 100644 index 000000000..c63ecd617 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockimageencodercontrol.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKIMAGEENCODERCONTROL_H +#define MOCKIMAGEENCODERCONTROL_H + +#include "qimageencodercontrol.h" + +class MockImageEncoderControl : public QImageEncoderControl +{ +public: + MockImageEncoderControl(QObject *parent = 0) + : QImageEncoderControl(parent) + { + m_settings = QImageEncoderSettings(); + } + + QList supportedResolutions(const QImageEncoderSettings & settings = QImageEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = true; + + QList resolutions; + if (settings.resolution().isValid()) { + if (settings.resolution() == QSize(160,160) || + settings.resolution() == QSize(320,240)) + resolutions << settings.resolution(); + + if (settings.quality() == QtMultimedia::HighQuality && settings.resolution() == QSize(640,480)) + resolutions << settings.resolution(); + } else { + resolutions << QSize(160, 120); + resolutions << QSize(320, 240); + if (settings.quality() == QtMultimedia::HighQuality) + resolutions << QSize(640, 480); + } + + return resolutions; + } + + QStringList supportedImageCodecs() const + { + QStringList codecs; + codecs << "PNG" << "JPEG"; + return codecs; + } + + QString imageCodecDescription(const QString &codecName) const { + if (codecName == "PNG") + return QString("Portable Network Graphic"); + if (codecName == "JPEG") + return QString("Joint Photographic Expert Group"); + return QString(); + } + + QImageEncoderSettings imageSettings() const { return m_settings; } + void setImageSettings(const QImageEncoderSettings &settings) { m_settings = settings; } + +private: + QImageEncoderSettings m_settings; +}; + + +#endif // MOCKIMAGEENCODERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediacontainercontrol.h b/tests/auto/unit/qmultimedia_common/mockmediacontainercontrol.h new file mode 100644 index 000000000..2a8832de2 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediacontainercontrol.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIACONTAINERCONTROL_H +#define MOCKMEDIACONTAINERCONTROL_H + +#include +#include "qmediacontainercontrol.h" +#include +#include +#include + +QT_USE_NAMESPACE +class MockMediaContainerControl : public QMediaContainerControl +{ + Q_OBJECT +public: + MockMediaContainerControl(QObject *parent): + QMediaContainerControl(parent) + { + m_supportedContainers.append("wav"); + m_supportedContainers.append("mp3"); + m_supportedContainers.append("mov"); + + m_descriptions.insert("wav", "WAV format"); + m_descriptions.insert("mp3", "MP3 format"); + m_descriptions.insert("mov", "MOV format"); + } + + virtual ~MockMediaContainerControl() {}; + + QStringList supportedContainers() const + { + return m_supportedContainers; + } + + QString containerMimeType() const + { + return m_format; + } + + void setContainerMimeType(const QString &formatMimeType) + { + if (m_supportedContainers.contains(formatMimeType)) + m_format = formatMimeType; + } + + QString containerDescription(const QString &formatMimeType) const + { + return m_descriptions.value(formatMimeType); + } + +private: + QStringList m_supportedContainers; + QMap m_descriptions; + QString m_format; +}; + +#endif // MOCKMEDIACONTAINERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmedianetworkaccesscontrol.h b/tests/auto/unit/qmultimedia_common/mockmedianetworkaccesscontrol.h new file mode 100644 index 000000000..472a30fc7 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmedianetworkaccesscontrol.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIANETWORKACCESSCONTROL_H +#define MOCKMEDIANETWORKACCESSCONTROL_H + +#include "qmedianetworkaccesscontrol.h" +#include "qnetworkconfiguration.h" + +class MockNetworkAccessControl : public QMediaNetworkAccessControl +{ + friend class MockMediaPlayerService; + +public: + MockNetworkAccessControl() {} + ~MockNetworkAccessControl() {} + + void setConfigurations(const QList &configurations) + { + _configurations = configurations; + _current = QNetworkConfiguration(); + } + + QNetworkConfiguration currentConfiguration() const + { + return _current; + } + +private: + void setCurrentConfiguration(QNetworkConfiguration configuration) + { + if (_configurations.contains(configuration)) + emit configurationChanged(_current = configuration); + else + emit configurationChanged(_current = QNetworkConfiguration()); + } + + QList _configurations; + QNetworkConfiguration _current; +}; + +Q_DECLARE_METATYPE(QNetworkConfiguration) + + +#endif // MOCKMEDIANETWORKACCESSCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaobject.h b/tests/auto/unit/qmultimedia_common/mockmediaobject.h new file mode 100644 index 000000000..fcc5c3731 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaobject.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAOBJECT_H +#define MOCKMEDIAOBJECT_H + +#include "qmediaobject.h" + +class MockMediaObject : public QMediaObject +{ + Q_OBJECT +public: + MockMediaObject(QObject *parent, QMediaService *service): + QMediaObject(parent, service) + { + } +}; + +#endif // MOCKMEDIAOBJECT_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h new file mode 100644 index 000000000..d88409ca5 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaplayercontrol.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYERCONTROL_H +#define MOCKMEDIAPLAYERCONTROL_H + +#include "qmediaplayercontrol.h" + +class MockMediaPlayerControl : public QMediaPlayerControl +{ + friend class MockMediaPlayerService; + +public: + MockMediaPlayerControl():QMediaPlayerControl(0) {} + + QMediaPlayer::State state() const { return _state; } + QMediaPlayer::MediaStatus mediaStatus() const { return _mediaStatus; } + + qint64 duration() const { return _duration; } + + qint64 position() const { return _position; } + + void setPosition(qint64 position) { if (position != _position) emit positionChanged(_position = position); } + + int volume() const { return _volume; } + void setVolume(int volume) { emit volumeChanged(_volume = volume); } + + bool isMuted() const { return _muted; } + void setMuted(bool muted) { if (muted != _muted) emit mutedChanged(_muted = muted); } + + int bufferStatus() const { return _bufferStatus; } + + bool isAudioAvailable() const { return _audioAvailable; } + bool isVideoAvailable() const { return _videoAvailable; } + + bool isSeekable() const { return _isSeekable; } + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(_seekRange.first, _seekRange.second); } + void setSeekRange(qint64 minimum, qint64 maximum) { _seekRange = qMakePair(minimum, maximum); } + + qreal playbackRate() const { return _playbackRate; } + void setPlaybackRate(qreal rate) { if (rate != _playbackRate) emit playbackRateChanged(_playbackRate = rate); } + + QMediaContent media() const { return _media; } + void setMedia(const QMediaContent &content, QIODevice *stream) + { + _stream = stream; + _media = content; + if (_state != QMediaPlayer::StoppedState) { + _mediaStatus = _media.isNull() ? QMediaPlayer::NoMedia : QMediaPlayer::LoadingMedia; + emit stateChanged(_state = QMediaPlayer::StoppedState); + emit mediaStatusChanged(_mediaStatus); + } + emit mediaChanged(_media = content); + } + QIODevice *mediaStream() const { return _stream; } + + void play() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PlayingState) emit stateChanged(_state = QMediaPlayer::PlayingState); } + void pause() { if (_isValid && !_media.isNull() && _state != QMediaPlayer::PausedState) emit stateChanged(_state = QMediaPlayer::PausedState); } + void stop() { if (_state != QMediaPlayer::StoppedState) emit stateChanged(_state = QMediaPlayer::StoppedState); } + + QMediaPlayer::State _state; + QMediaPlayer::MediaStatus _mediaStatus; + QMediaPlayer::Error _error; + qint64 _duration; + qint64 _position; + int _volume; + bool _muted; + int _bufferStatus; + bool _audioAvailable; + bool _videoAvailable; + bool _isSeekable; + QPair _seekRange; + qreal _playbackRate; + QMediaContent _media; + QIODevice *_stream; + bool _isValid; + QString _errorString; +}; + +#endif // MOCKMEDIAPLAYERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplayerservice.h b/tests/auto/unit/qmultimedia_common/mockmediaplayerservice.h new file mode 100644 index 000000000..fb0f1b28d --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaplayerservice.h @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKPLAYERSERVICE_H +#define MOCKPLAYERSERVICE_H + +#include "qmediaservice.h" + +#include "mockmediaplayercontrol.h" +#include "mockmediastreamscontrol.h" +#include "mockmedianetworkaccesscontrol.h" +#include "mockvideorenderercontrol.h" +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) +#include "mockvideowindowcontrol.h" +#endif + +class MockMediaPlayerService : public QMediaService +{ + Q_OBJECT + +public: + MockMediaPlayerService():QMediaService(0) + { + mockControl = new MockMediaPlayerControl; + mockStreamsControl = new MockStreamsControl; + mockNetworkControl = new MockNetworkAccessControl; + rendererControl = new MockVideoRendererControl; + rendererRef = 0; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + windowControl = new MockVideoWindowControl; + windowRef = 0; +#endif + } + + ~MockMediaPlayerService() + { + delete mockControl; + delete mockStreamsControl; + delete mockNetworkControl; + delete rendererControl; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + delete windowControl; +#endif + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QMediaPlayerControl_iid) == 0) { + return mockControl; + } else if (qstrcmp(iid, QVideoRendererControl_iid) == 0) { + if (rendererRef == 0) { + rendererRef += 1; + return rendererControl; + } + } +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + if (qstrcmp(iid, QVideoWindowControl_iid) == 0) { + if (windowRef == 0) { + windowRef += 1; + return windowControl; + } + } +#endif + + if (qstrcmp(iid, QMediaNetworkAccessControl_iid) == 0) + return mockNetworkControl; + return 0; + } + + void releaseControl(QMediaControl *control) + { + if (control == rendererControl) + rendererRef -= 1; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + if (control == windowControl) + windowRef -= 1; +#endif + } + + void setState(QMediaPlayer::State state) { emit mockControl->stateChanged(mockControl->_state = state); } + void setState(QMediaPlayer::State state, QMediaPlayer::MediaStatus status) { + mockControl->_state = state; + mockControl->_mediaStatus = status; + emit mockControl->mediaStatusChanged(status); + emit mockControl->stateChanged(state); + } + void setMediaStatus(QMediaPlayer::MediaStatus status) { emit mockControl->mediaStatusChanged(mockControl->_mediaStatus = status); } + void setIsValid(bool isValid) { mockControl->_isValid = isValid; } + void setMedia(QMediaContent media) { mockControl->_media = media; } + void setDuration(qint64 duration) { mockControl->_duration = duration; } + void setPosition(qint64 position) { mockControl->_position = position; } + void setSeekable(bool seekable) { mockControl->_isSeekable = seekable; } + void setVolume(int volume) { mockControl->_volume = volume; } + void setMuted(bool muted) { mockControl->_muted = muted; } + void setVideoAvailable(bool videoAvailable) { mockControl->_videoAvailable = videoAvailable; } + void setBufferStatus(int bufferStatus) { mockControl->_bufferStatus = bufferStatus; } + void setPlaybackRate(qreal playbackRate) { mockControl->_playbackRate = playbackRate; } + void setError(QMediaPlayer::Error error) { mockControl->_error = error; emit mockControl->error(mockControl->_error, mockControl->_errorString); } + void setErrorString(QString errorString) { mockControl->_errorString = errorString; emit mockControl->error(mockControl->_error, mockControl->_errorString); } + + void selectCurrentConfiguration(QNetworkConfiguration config) { mockNetworkControl->setCurrentConfiguration(config); } + + void reset() + { + mockControl->_state = QMediaPlayer::StoppedState; + mockControl->_mediaStatus = QMediaPlayer::UnknownMediaStatus; + mockControl->_error = QMediaPlayer::NoError; + mockControl->_duration = 0; + mockControl->_position = 0; + mockControl->_volume = 0; + mockControl->_muted = false; + mockControl->_bufferStatus = 0; + mockControl->_videoAvailable = false; + mockControl->_isSeekable = false; + mockControl->_playbackRate = 0.0; + mockControl->_media = QMediaContent(); + mockControl->_stream = 0; + mockControl->_isValid = false; + mockControl->_errorString = QString(); + + mockNetworkControl->_current = QNetworkConfiguration(); + mockNetworkControl->_configurations = QList(); + } + + MockMediaPlayerControl *mockControl; + MockStreamsControl *mockStreamsControl; + MockNetworkAccessControl *mockNetworkControl; + MockVideoRendererControl *rendererControl; +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + MockVideoWindowControl *windowControl; + int windowRef; +#endif + int rendererRef; +}; + + + +#endif // MOCKPLAYERSERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h new file mode 100644 index 000000000..186db69f1 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaplaylistcontrol.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYLISTCONTROL_H +#define MOCKMEDIAPLAYLISTCONTROL_H + +#include "qmediaplaylistcontrol.h" +#include "qmediaplaylistnavigator.h" + +#include "mockreadonlyplaylistprovider.h" + +// Hmm, read only. +class MockMediaPlaylistControl : public QMediaPlaylistControl +{ + Q_OBJECT +public: + MockMediaPlaylistControl(QObject *parent) : QMediaPlaylistControl(parent) + { + m_navigator = new QMediaPlaylistNavigator(new MockReadOnlyPlaylistProvider(this), this); + } + + ~MockMediaPlaylistControl() + { + } + + QMediaPlaylistProvider* playlistProvider() const { return m_navigator->playlist(); } + bool setPlaylistProvider(QMediaPlaylistProvider *newProvider) + { + bool bMediaContentChanged = false; + int i = 0; + for (; i < playlistProvider()->mediaCount(); i++) { + if (playlistProvider()->media(i).canonicalUrl().toString() != newProvider->media(i).canonicalUrl().toString()) { + bMediaContentChanged = true; + break; + } + } + + if (playlistProvider()->mediaCount() != newProvider->mediaCount() || bMediaContentChanged ) { + emit playlistProviderChanged(); + emit currentMediaChanged(newProvider->media(i)); + } + + m_navigator->setPlaylist(newProvider); + return true; + } + + int currentIndex() const { return m_navigator->currentIndex(); } + void setCurrentIndex(int position) + { + if (position != currentIndex()) + emit currentIndexChanged(position); + m_navigator->jump(position); + } + + int nextIndex(int steps) const { return m_navigator->nextIndex(steps); } + int previousIndex(int steps) const { return m_navigator->previousIndex(steps); } + + void next() { m_navigator->next(); } + void previous() { m_navigator->previous(); } + + QMediaPlaylist::PlaybackMode playbackMode() const { return m_navigator->playbackMode(); } + void setPlaybackMode(QMediaPlaylist::PlaybackMode mode) + { + if (playbackMode() != mode) + emit playbackModeChanged(mode); + + m_navigator->setPlaybackMode(mode); + } + +private: + QMediaPlaylistNavigator *m_navigator; +}; + +#endif // MOCKMEDIAPLAYLISTCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaplaylistsourcecontrol.h b/tests/auto/unit/qmultimedia_common/mockmediaplaylistsourcecontrol.h new file mode 100644 index 000000000..c43ef9b5d --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaplaylistsourcecontrol.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIAPLAYLISTSOURCECONTROL_H +#define MOCKMEDIAPLAYLISTSOURCECONTROL_H + +#include "qmediaplaylistsourcecontrol.h" + +class MockPlaylistSourceControl : public QMediaPlaylistSourceControl +{ + Q_OBJECT +public: + MockPlaylistSourceControl(QObject *parent) + : QMediaPlaylistSourceControl(parent), + m_playlist(0) + { + } + + ~MockPlaylistSourceControl() + { + } + + void setPlaylist(QMediaPlaylist *playlist) + { + m_playlist = playlist; + } + + QMediaPlaylist *playlist() const + { + return m_playlist; + } +private: + QMediaPlaylist *m_playlist; +}; + +#endif // MOCKMEDIAPLAYLISTSOURCECONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediarecordercontrol.h b/tests/auto/unit/qmultimedia_common/mockmediarecordercontrol.h new file mode 100644 index 000000000..77c1378a8 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediarecordercontrol.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKRECORDERCONTROL_H +#define MOCKRECORDERCONTROL_H + +#include + +#include "qmediarecordercontrol.h" + +class MockMediaRecorderControl : public QMediaRecorderControl +{ + Q_OBJECT + +public: + MockMediaRecorderControl(QObject *parent = 0): + QMediaRecorderControl(parent), + m_state(QMediaRecorder::StoppedState), + m_position(0), + m_muted(false) {} + + QUrl outputLocation() const + { + return m_sink; + } + + bool setOutputLocation(const QUrl &sink) + { + m_sink = sink; + return true; + } + + QMediaRecorder::State state() const + { + return m_state; + } + + qint64 duration() const + { + return m_position; + } + + bool isMuted() const + { + return m_muted; + } + + void applySettings() {} + + using QMediaRecorderControl::error; + +public slots: + void record() + { + m_state = QMediaRecorder::RecordingState; + m_position=1; + emit stateChanged(m_state); + emit durationChanged(m_position); + } + + void pause() + { + m_state = QMediaRecorder::PausedState; + emit stateChanged(m_state); + } + + void stop() + { + m_position=0; + m_state = QMediaRecorder::StoppedState; + emit stateChanged(m_state); + } + + void setMuted(bool muted) + { + if (m_muted != muted) + emit mutedChanged(m_muted = muted); + } + +public: + QUrl m_sink; + QMediaRecorder::State m_state; + qint64 m_position; + bool m_muted; +}; + +#endif // MOCKRECORDERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediarecorderservice.h b/tests/auto/unit/qmultimedia_common/mockmediarecorderservice.h new file mode 100644 index 000000000..fa8c29a5a --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediarecorderservice.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKSERVICE_H +#define MOCKSERVICE_H + +#include "qmediaservice.h" + +#include "mockaudioencodercontrol.h" +#include "mockmediarecordercontrol.h" +#include "mockvideoencodercontrol.h" +#include "mockaudioendpointselector.h" +#include "mockmediacontainercontrol.h" +#include "mockmetadatawritercontrol.h" + +class MockMediaRecorderService : public QMediaService +{ + Q_OBJECT +public: + MockMediaRecorderService(QObject *parent = 0, QMediaControl *control = 0): + QMediaService(parent), + mockControl(control), + hasControls(true) + { + mockAudioEndpointSelector = new MockAudioEndpointSelector(parent); + mockAudioEncoderControl = new MockAudioEncoderControl(parent); + mockFormatControl = new MockMediaContainerControl(parent); + mockVideoEncoderControl = new MockVideoEncoderControl(parent); + mockMetaDataControl = new MockMetaDataWriterControl(parent); + } + + QMediaControl* requestControl(const char *name) + { + if (hasControls && qstrcmp(name,QAudioEncoderControl_iid) == 0) + return mockAudioEncoderControl; + if (hasControls && qstrcmp(name,QAudioEndpointSelector_iid) == 0) + return mockAudioEndpointSelector; + if (hasControls && qstrcmp(name,QMediaRecorderControl_iid) == 0) + return mockControl; + if (hasControls && qstrcmp(name,QMediaContainerControl_iid) == 0) + return mockFormatControl; + if (hasControls && qstrcmp(name,QVideoEncoderControl_iid) == 0) + return mockVideoEncoderControl; + if (hasControls && qstrcmp(name, QMetaDataWriterControl_iid) == 0) + return mockMetaDataControl; + + return 0; + } + + void releaseControl(QMediaControl*) + { + } + + QMediaControl *mockControl; + QAudioEndpointSelector *mockAudioEndpointSelector; + QAudioEncoderControl *mockAudioEncoderControl; + QMediaContainerControl *mockFormatControl; + QVideoEncoderControl *mockVideoEncoderControl; + MockMetaDataWriterControl *mockMetaDataControl; + bool hasControls; +}; + +#endif // MOCKSERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaservice.h b/tests/auto/unit/qmultimedia_common/mockmediaservice.h new file mode 100644 index 000000000..3ceb1ad74 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaservice.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASERVICE_H +#define MOCKMEDIASERVICE_H + +#include "qmediaservice.h" + +class MockMediaService : public QMediaService +{ + Q_OBJECT +public: + MockMediaService(QObject *parent, QMediaControl *control): + QMediaService(parent), + mockControl(control) {} + + QMediaControl* requestControl(const char *) + { + return mockControl; + } + + void releaseControl(QMediaControl*) {} + + QMediaControl *mockControl; +}; + + +#endif // MOCKMEDIASERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h new file mode 100644 index 000000000..4573d7f96 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediaserviceprovider.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASERVICEPROVIDER_H +#define MOCKMEDIASERVICEPROVIDER_H + +#include "qmediaserviceprovider.h" +#include "qmediaservice.h" + +// Simple provider that lets you set the service +class MockMediaServiceProvider : public QMediaServiceProvider +{ +public: + MockMediaServiceProvider(QMediaService* s = 0, bool del=false) + : service(s), deleteServiceOnRelease(del) + { + } + + QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) + { + return service; + } + + void releaseService(QMediaService *service) + { + if (deleteServiceOnRelease) { + delete service; + service = 0; + } + } + + QMediaService *service; + bool deleteServiceOnRelease; +}; + +#endif // MOCKMEDIASERVICEPROVIDER_H diff --git a/tests/auto/unit/qmultimedia_common/mockmediastreamscontrol.h b/tests/auto/unit/qmultimedia_common/mockmediastreamscontrol.h new file mode 100644 index 000000000..d1d967df6 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmediastreamscontrol.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMEDIASTREAMSCONTROL_H +#define MOCKMEDIASTREAMSCONTROL_H + +#include "qmediastreamscontrol.h" + +class MockStreamsControl : public QMediaStreamsControl +{ +public: + MockStreamsControl(QObject *parent = 0) : QMediaStreamsControl(parent) {} + + int streamCount() { return _streams.count(); } + void setStreamCount(int count) { _streams.resize(count); } + + StreamType streamType(int index) { return _streams.at(index).type; } + void setStreamType(int index, StreamType type) { _streams[index].type = type; } + + QVariant metaData(int index, QtMultimedia::MetaData key) { + return _streams.at(index).metaData.value(key); } + void setMetaData(int index, QtMultimedia::MetaData key, const QVariant &value) { + _streams[index].metaData.insert(key, value); } + + bool isActive(int index) { return _streams.at(index).active; } + void setActive(int index, bool state) { _streams[index].active = state; } + +private: + struct Stream + { + Stream() : type(UnknownStream), active(false) {} + StreamType type; + QMap metaData; + bool active; + }; + + QVector _streams; +}; + +#endif // MOCKMEDIASTREAMSCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmetadatareadercontrol.h b/tests/auto/unit/qmultimedia_common/mockmetadatareadercontrol.h new file mode 100644 index 000000000..f0847622f --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmetadatareadercontrol.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMETADATAREADERCONTROL_H +#define MOCKMETADATAREADERCONTROL_H + +#include "qmetadatareadercontrol.h" + +class MockMetaDataReaderControl : public QMetaDataReaderControl +{ + Q_OBJECT +public: + MockMetaDataReaderControl(QObject *parent = 0) + : QMetaDataReaderControl(parent) + , m_available(false) + { + } + + bool isMetaDataAvailable() const + { + return m_available; + } + void setMetaDataAvailable(bool available) + { + if (m_available != available) + emit metaDataAvailableChanged(m_available = available); + } + QList availableMetaData() const + { + return m_data.keys(); + } + + QVariant metaData(QtMultimedia::MetaData key) const + { + return m_data.value(key); + } + + QVariant extendedMetaData(const QString &key) const + { + return m_extendedData.value(key); + } + + QStringList availableExtendedMetaData() const + { + return m_extendedData.keys(); + } + + using QMetaDataReaderControl::metaDataChanged; + + void populateMetaData() + { + m_available = true; + } + + bool m_available; + QMap m_data; + QMap m_extendedData; +}; + +#endif // MOCKMETADATAREADERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockmetadatawritercontrol.h b/tests/auto/unit/qmultimedia_common/mockmetadatawritercontrol.h new file mode 100644 index 000000000..e9f7c7573 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockmetadatawritercontrol.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKMETADATAWRITERCONTROL_H +#define MOCKMETADATAWRITERCONTROL_H + +#include +#include + +#include "qmetadatawritercontrol.h" + +class MockMetaDataWriterControl : public QMetaDataWriterControl +{ + Q_OBJECT +public: + MockMetaDataWriterControl(QObject *parent = 0) + : QMetaDataWriterControl(parent) + , m_available(false) + , m_writable(false) + { + } + + bool isMetaDataAvailable() const { return m_available; } + void setMetaDataAvailable(bool available) + { + if (m_available != available) + emit metaDataAvailableChanged(m_available = available); + } + QList availableMetaData() const { return m_data.keys(); } + + bool isWritable() const { return m_writable; } + void setWritable(bool writable) { emit writableChanged(m_writable = writable); } + + QVariant metaData(QtMultimedia::MetaData key) const { return m_data.value(key); }//Getting the metadata from Multimediakit + void setMetaData(QtMultimedia::MetaData key, const QVariant &value) + { + m_data.insert(key, value); + } + + QVariant extendedMetaData(const QString &key) const { return m_extendedData.value(key); } + void setExtendedMetaData(const QString &key, const QVariant &value) + { + m_extendedData.insert(key, value); + } + + QStringList availableExtendedMetaData() const { return m_extendedData.keys(); } + + using QMetaDataWriterControl::metaDataChanged; + + void populateMetaData() + { + m_available = true; + } + void setWritable() + { + emit writableChanged(true); + } + void setMetaDataAvailable() + { + emit metaDataAvailableChanged(true); + } + + bool m_available; + bool m_writable; + QMap m_data; + QMap m_extendedData; +}; + +#endif // MOCKMETADATAWRITERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockplayer.pri b/tests/auto/unit/qmultimedia_common/mockplayer.pri new file mode 100644 index 000000000..a5040ac80 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockplayer.pri @@ -0,0 +1,12 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/audio \ + ../../../src/multimedia/video \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaplayerservice.h \ + ../qmultimedia_common/mockmediaplayercontrol.h \ + ../qmultimedia_common/mockmediastreamscontrol.h \ + ../qmultimedia_common/mockmedianetworkaccesscontrol.h + +include(mockvideo.pri) diff --git a/tests/auto/unit/qmultimedia_common/mockplaylist.pri b/tests/auto/unit/qmultimedia_common/mockplaylist.pri new file mode 100644 index 000000000..c27c839c5 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockplaylist.pri @@ -0,0 +1,8 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + +HEADERS *= \ + ../qmultimedia_common/mockmediaplaylistsourcecontrol.h \ + ../qmultimedia_common/mockmediaplaylistcontrol.h \ + ../qmultimedia_common/mockreadonlyplaylistprovider.h \ + ../qmultimedia_common/mockplaylistservice.h diff --git a/tests/auto/unit/qmultimedia_common/mockplaylistservice.h b/tests/auto/unit/qmultimedia_common/mockplaylistservice.h new file mode 100644 index 000000000..3e1210c28 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockplaylistservice.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKPLAYLISTSERVICE_H +#define MOCKPLAYLISTSERVICE_H + +#include "qmediaservice.h" +#include "mockmediaplaylistcontrol.h" + +class MockPlaylistService : public QMediaService +{ + Q_OBJECT + +public: + MockPlaylistService():QMediaService(0) + { + mockControl = new MockMediaPlaylistControl(this); + } + + ~MockPlaylistService() + { + } + + QMediaControl* requestControl(const char *iid) + { + if (qstrcmp(iid, QMediaPlaylistControl_iid) == 0) + return mockControl; + return 0; + } + + void releaseControl(QMediaControl *) + { + } + + MockMediaPlaylistControl *mockControl; +}; + + +#endif // MOCKPLAYLISTSERVICE_H diff --git a/tests/auto/unit/qmultimedia_common/mockradio.pri b/tests/auto/unit/qmultimedia_common/mockradio.pri new file mode 100644 index 000000000..0f7f84a2f --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockradio.pri @@ -0,0 +1,8 @@ + +# Radio related mock backend files + +INCLUDEPATH += . + +HEADERS += \ + ../qmultimedia_common/mockradiotunercontrol.h \ + ../qmultimedia_common/mockradiodatacontrol.h diff --git a/tests/auto/unit/qmultimedia_common/mockradiodatacontrol.h b/tests/auto/unit/qmultimedia_common/mockradiodatacontrol.h new file mode 100644 index 000000000..ca6eb4020 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockradiodatacontrol.h @@ -0,0 +1,157 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKRADIODATACONTROL_H +#define MOCKRADIODATACONTROL_H + +#include "qradiodatacontrol.h" + +class MockRadioDataControl : public QRadioDataControl +{ + Q_OBJECT + +public: + MockRadioDataControl(QObject *parent): + QRadioDataControl(parent), m_err(QRadioData::NoError), + m_errstr("") + { + } + + using QRadioDataControl::error; + + bool isAvailable() const + { + return true; + } + QtMultimedia::AvailabilityError availabilityError() const + { + return QtMultimedia::NoError; + } + + QRadioData::Error error() const + { + return m_err; + } + + QString errorString() const + { + return m_errstr; + } + + QString stationId() const + { + return m_stationId; + } + + QRadioData::ProgramType programType() const + { + return m_programType; + } + + QString programTypeName() const + { + return m_programTypeName; + } + + QString stationName() const + { + return m_stationName; + } + + QString radioText() const + { + return m_radioText; + } + + void setAlternativeFrequenciesEnabled(bool enabled) + { + m_alternativeFrequenciesEnabled = enabled; + emit alternativeFrequenciesEnabledChanged(m_alternativeFrequenciesEnabled); + } + + bool isAlternativeFrequenciesEnabled() const + { + return m_alternativeFrequenciesEnabled; + } + + void forceRT( QString text ) + { + m_radioText = text; + emit radioTextChanged(m_radioText); + } + + void forceProgramType( int pty ) + { + m_programType = static_cast(pty); + emit programTypeChanged(m_programType); + } + + void forcePTYN( QString ptyn ) + { + m_programTypeName = ptyn; + emit programTypeNameChanged(m_programTypeName); + } + + void forcePI( QString pi ) + { + m_stationId = pi; + emit stationIdChanged(m_stationId); + } + + void forcePS( QString ps ) + { + m_stationName = ps; + emit stationNameChanged(m_stationName); + } + +public: + QString m_radioText; + QRadioData::ProgramType m_programType; + QString m_programTypeName; + QString m_stationId; + QString m_stationName; + bool m_alternativeFrequenciesEnabled; + + QRadioData::Error m_err; + QString m_errstr; +}; + +#endif // MOCKRADIODATACONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockradiotunercontrol.h b/tests/auto/unit/qmultimedia_common/mockradiotunercontrol.h new file mode 100644 index 000000000..664825356 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockradiotunercontrol.h @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKRADIOTUNERCONTROL_H +#define MOCKRADIOTUNERCONTROL_H + +#include "qradiotunercontrol.h" + +class MockRadioTunerControl : public QRadioTunerControl +{ + Q_OBJECT + +public: + MockRadioTunerControl(QObject *parent): + QRadioTunerControl(parent), + m_active(false), + m_searching(false),m_muted(false),m_stereo(true), + m_volume(100),m_signal(0),m_frequency(0), + m_band(QRadioTuner::FM),m_err(QRadioTuner::NoError), + m_errstr("") + { + } + + using QRadioTunerControl::error; + + QRadioTuner::State state() const + { + return m_active ? QRadioTuner::ActiveState : QRadioTuner::StoppedState; + } + + bool isAvailable() const + { + return true; + } + QtMultimedia::AvailabilityError availabilityError() const + { + return QtMultimedia::NoError; + } + + QRadioTuner::Band band() const + { + return m_band; + } + + void setBand(QRadioTuner::Band b) + { + if (b == QRadioTuner::FM2 || b == QRadioTuner::LW) { + m_err = QRadioTuner::OutOfRangeError; + m_errstr.clear(); + m_errstr = QString("band and range not supported"); + } else { + m_err = QRadioTuner::NoError; + m_errstr.clear(); + m_band = b; + emit bandChanged(m_band); + } + emit error(m_err); + + } + + bool isBandSupported(QRadioTuner::Band b) const + { + if (b == QRadioTuner::FM || b == QRadioTuner::AM) + return true; + + return false; + } + + int frequency() const + { + return m_frequency; + } + + QPair frequencyRange(QRadioTuner::Band) const + { + return qMakePair(1,2); + } + + int frequencyStep(QRadioTuner::Band) const + { + return 1; + } + + void setFrequency(int frequency) + { + if (frequency >= 148500000) { + m_err = QRadioTuner::OutOfRangeError; + m_errstr.clear(); + m_errstr = QString("band and range not supported"); + } else { + m_err = QRadioTuner::NoError; + m_errstr.clear(); + m_frequency = frequency; + emit frequencyChanged(m_frequency); + } + + emit error(m_err); + } + + bool isStereo() const + { + return m_stereo; + } + + void setStereo(bool stereo) + { + emit stereoStatusChanged(m_stereo = stereo); + } + + + QRadioTuner::StereoMode stereoMode() const + { + return m_stereoMode; + } + + void setStereoMode(QRadioTuner::StereoMode mode) + { + m_stereoMode = mode; + } + + QRadioTuner::Error error() const + { + return m_err; + } + + QString errorString() const + { + return m_errstr; + } + + int signalStrength() const + { + return m_signal; + } + + int volume() const + { + return m_volume; + } + + void setVolume(int volume) + { + m_volume = volume; + emit volumeChanged(m_volume); + } + + bool isMuted() const + { + return m_muted; + } + + void setMuted(bool muted) + { + m_muted = muted; + emit mutedChanged(m_muted); + } + + bool isSearching() const + { + return m_searching; + } + + void searchForward() + { + m_searching = true; + emit searchingChanged(m_searching); + } + + void searchBackward() + { + m_searching = true; + emit searchingChanged(m_searching); + } + + void cancelSearch() + { + m_searching = false; + emit searchingChanged(m_searching); + } + + void findNewStation( int frequency, QString stationId ) + { + setFrequency(frequency); + emit stationFound( frequency, stationId ); + } + + void searchAllStations(QRadioTuner::SearchMode searchMode = QRadioTuner::SearchFast) + { + QString programmeIdentifiers[3] = { "", "", "" }; + + if ( searchMode == QRadioTuner::SearchGetStationId ) { + programmeIdentifiers[0] = QString("MockProgramPI1"); + programmeIdentifiers[1] = QString("MockProgramPI2"); + programmeIdentifiers[2] = QString("MockProgramPI3"); + } + m_searching = true; + emit searchingChanged(m_searching); + + findNewStation(88300000, programmeIdentifiers[0]); + findNewStation(95100000, programmeIdentifiers[1]); + findNewStation(103100000, programmeIdentifiers[2]); + + m_searching = false; + emit searchingChanged(m_searching); + } + + void start() + { + if (!m_active) { + m_active = true; + emit stateChanged(state()); + } + } + + void stop() + { + if (m_active) { + m_active = false; + emit stateChanged(state()); + } + } + +public: + bool m_active; + bool m_searching; + bool m_muted; + bool m_stereo; + int m_volume; + int m_signal; + int m_frequency; + QRadioTuner::StereoMode m_stereoMode; + QRadioTuner::Band m_band; + QRadioTuner::Error m_err; + QString m_errstr; +}; + +#endif // MOCKRADIOTUNERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h b/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h new file mode 100644 index 000000000..12e48e03a --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockreadonlyplaylistprovider.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKREADONLYPLAYLISTPROVIDER_H +#define MOCKREADONLYPLAYLISTPROVIDER_H + +#include "qmediaplaylistprovider.h" + +class MockReadOnlyPlaylistProvider : public QMediaPlaylistProvider +{ + Q_OBJECT +public: + MockReadOnlyPlaylistProvider(QObject *parent) + :QMediaPlaylistProvider(parent) + { + m_items.append(QMediaContent(QUrl(QLatin1String("file:///1")))); + m_items.append(QMediaContent(QUrl(QLatin1String("file:///2")))); + m_items.append(QMediaContent(QUrl(QLatin1String("file:///3")))); + } + + int mediaCount() const { return m_items.size(); } + QMediaContent media(int index) const + { + return index >=0 && index < mediaCount() ? m_items.at(index) : QMediaContent(); + } + +private: + QList m_items; +}; + +#endif // MOCKREADONLYPLAYLISTPROVIDER_H diff --git a/tests/auto/unit/qmultimedia_common/mockrecorder.pri b/tests/auto/unit/qmultimedia_common/mockrecorder.pri new file mode 100644 index 000000000..6f8438d8f --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockrecorder.pri @@ -0,0 +1,14 @@ +INCLUDEPATH *= $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/audio \ + ../../../src/multimedia/video \ + +HEADERS *= \ + ../qmultimedia_common/mockmediarecorderservice.h \ + ../qmultimedia_common/mockmediarecordercontrol.h \ + ../qmultimedia_common/mockvideoencodercontrol.h \ + ../qmultimedia_common/mockaudioencodercontrol.h \ + ../qmultimedia_common/mockaudioendpointselector.h \ + +# We also need all the container/metadata bits +include(mockcontainer.pri) diff --git a/tests/auto/unit/qmultimedia_common/mockvideo.pri b/tests/auto/unit/qmultimedia_common/mockvideo.pri new file mode 100644 index 000000000..ea991661f --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockvideo.pri @@ -0,0 +1,14 @@ +# video related mock backend files +INCLUDEPATH += $$PWD \ + ../../../src/multimedia \ + ../../../src/multimedia/video + +contains(QT,multimediawidgets)|contains(QT,multimediawidgets-private) { + HEADERS *= ../qmultimedia_common/mockvideowindowcontrol.h + DEFINES *= QT_MULTIMEDIA_MOCK_WIDGETS +} + +HEADERS *= \ + ../qmultimedia_common/mockvideosurface.h \ + ../qmultimedia_common/mockvideorenderercontrol.h + diff --git a/tests/auto/unit/qmultimedia_common/mockvideoencodercontrol.h b/tests/auto/unit/qmultimedia_common/mockvideoencodercontrol.h new file mode 100644 index 000000000..f628c6730 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockvideoencodercontrol.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOENCODERCONTROL_H +#define MOCKVIDEOENCODERCONTROL_H + +#include "qvideoencodercontrol.h" + +class MockVideoEncoderControl : public QVideoEncoderControl +{ + Q_OBJECT +public: + MockVideoEncoderControl(QObject *parent): + QVideoEncoderControl(parent) + { + m_supportedEncodeOptions.insert("video/3gpp", QStringList() << "quantizer" << "me"); + m_supportedEncodeOptions.insert("video/H264", QStringList() << "quantizer" << "me" << "bframes"); + m_videoCodecs << "video/3gpp" << "video/H264"; + m_sizes << QSize(320,240) << QSize(640,480); + m_framerates << 30 << 15 << 1; + } + ~MockVideoEncoderControl() {} + + QVideoEncoderSettings videoSettings() const { return m_videoSettings; } + void setVideoSettings(const QVideoEncoderSettings &settings) { m_videoSettings = settings; }; + + QList supportedResolutions(const QVideoEncoderSettings & = QVideoEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = true; + + return m_sizes; + } + + QList supportedFrameRates(const QVideoEncoderSettings & = QVideoEncoderSettings(), + bool *continuous = 0) const + { + if (continuous) + *continuous = false; + + return m_framerates; + } + + QStringList supportedVideoCodecs() const { return m_videoCodecs; } + QString videoCodecDescription(const QString &codecName) const { return codecName; } + + QStringList supportedEncodingOptions(const QString &codec) const + { + return m_supportedEncodeOptions.value(codec); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + return m_encodeOptions[codec].value(name); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + m_encodeOptions[codec][name] = value; + } + +private: + QVideoEncoderSettings m_videoSettings; + + QMap m_supportedEncodeOptions; + QMap< QString, QMap > m_encodeOptions; + + QStringList m_videoCodecs; + QList m_sizes; + QList m_framerates; +}; + +#endif // MOCKVIDEOENCODERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockvideorenderercontrol.h b/tests/auto/unit/qmultimedia_common/mockvideorenderercontrol.h new file mode 100644 index 000000000..c98dd761a --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockvideorenderercontrol.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKVIDEORENDERERCONTROL_H +#define MOCKVIDEORENDERERCONTROL_H + +#include "qvideorenderercontrol.h" + +class MockVideoRendererControl : public QVideoRendererControl +{ +public: + MockVideoRendererControl(QObject *parent = 0) : QVideoRendererControl(parent), m_surface(0) {} + + QAbstractVideoSurface *surface() const { return m_surface; } + void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } + + QAbstractVideoSurface *m_surface; +}; + +#endif // MOCKVIDEORENDERERCONTROL_H diff --git a/tests/auto/unit/qmultimedia_common/mockvideosurface.h b/tests/auto/unit/qmultimedia_common/mockvideosurface.h new file mode 100644 index 000000000..bbfe35448 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockvideosurface.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOSURFACE_H +#define MOCKVIDEOSURFACE_H + +#include "qabstractvideosurface.h" + +class MockVideoSurface : public QAbstractVideoSurface +{ +public: + QList supportedPixelFormats( + const QAbstractVideoBuffer::HandleType) const + { + return QList(); + } + + bool present(const QVideoFrame &) { return false; } +}; + +#endif // MOCKVIDEOSURFACE_H diff --git a/tests/auto/unit/qmultimedia_common/mockvideowindowcontrol.h b/tests/auto/unit/qmultimedia_common/mockvideowindowcontrol.h new file mode 100644 index 000000000..83255e24c --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockvideowindowcontrol.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKVIDEOWINDOWCONTROL_H +#define MOCKVIDEOWINDOWCONTROL_H + +#if defined(QT_MULTIMEDIA_MOCK_WIDGETS) + +#include "qvideowindowcontrol.h" + +class MockVideoWindowControl : public QVideoWindowControl +{ +public: + MockVideoWindowControl(QObject *parent = 0) : QVideoWindowControl(parent) {} + WId winId() const { return 0; } + void setWinId(WId) {} + QRect displayRect() const { return QRect(); } + void setDisplayRect(const QRect &) {} + bool isFullScreen() const { return false; } + void setFullScreen(bool) {} + void repaint() {} + QSize nativeSize() const { return QSize(); } + Qt::AspectRatioMode aspectRatioMode() const { return Qt::KeepAspectRatio; } + void setAspectRatioMode(Qt::AspectRatioMode) {} + int brightness() const { return 0; } + void setBrightness(int) {} + int contrast() const { return 0; } + void setContrast(int) {} + int hue() const { return 0; } + void setHue(int) {} + int saturation() const { return 0; } + void setSaturation(int) {} +}; + +#endif // QT_MULTIMEDIA_MOCK_WIDGETS +#endif // MOCKVIDEOWINDOWCONTROL_H diff --git a/tests/auto/unit/qpaintervideosurface/qpaintervideosurface.pro b/tests/auto/unit/qpaintervideosurface/qpaintervideosurface.pro new file mode 100644 index 000000000..edf9c8975 --- /dev/null +++ b/tests/auto/unit/qpaintervideosurface/qpaintervideosurface.pro @@ -0,0 +1,18 @@ +CONFIG += testcase +TARGET = tst_qpaintervideosurface + +QT += multimedia-private multimediawidgets-private testlib +CONFIG += no_private_qt_headers_warning +contains(QT_CONFIG, opengl) | contains(QT_CONFIG, opengles2) { + QT += opengl +} else { + DEFINES += QT_NO_OPENGL +} + +contains(QT_CONFIG, opengl): QT += opengl + +SOURCES += tst_qpaintervideosurface.cpp + +# QPA-minimal and OpenGL don't get along +CONFIG += insignificant_test +QT+=widgets diff --git a/tests/auto/unit/qpaintervideosurface/tst_qpaintervideosurface.cpp b/tests/auto/unit/qpaintervideosurface/tst_qpaintervideosurface.cpp new file mode 100644 index 000000000..53ed906e9 --- /dev/null +++ b/tests/auto/unit/qpaintervideosurface/tst_qpaintervideosurface.cpp @@ -0,0 +1,1249 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) +#include +#include +#endif + +QT_USE_NAMESPACE +class tst_QPainterVideoSurface : public QObject +{ + Q_OBJECT +private slots: + void cleanup() {} + void cleanupTestCase() {} + + void colors(); + + void supportedFormat_data(); + void supportedFormat(); + + void present_data(); + void present(); + void presentOpaqueFrame(); + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + + void shaderType(); + + void shaderTypeStarted_data(); + void shaderTypeStarted(); + + void shaderSupportedFormat_data(); + void shaderSupportedFormat(); + + void shaderPresent_data(); + void shaderPresent(); + void shaderPresentOpaqueFrame_data(); + void shaderPresentOpaqueFrame(); + void shaderPresentGLFrame_data(); + void shaderPresentGLFrame(); +#endif +}; + +Q_DECLARE_METATYPE(const uchar *) + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) +Q_DECLARE_METATYPE(QPainterVideoSurface::ShaderType); + +class QtTestGLVideoBuffer : public QAbstractVideoBuffer +{ +public: + QtTestGLVideoBuffer() + : QAbstractVideoBuffer(GLTextureHandle) + , m_textureId(0) + { + glGenTextures(1, &m_textureId); + } + + ~QtTestGLVideoBuffer() + { + glDeleteTextures(1, &m_textureId); + } + + GLuint textureId() const { return m_textureId; } + + QVariant handle() const { return m_textureId; } + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} + MapMode mapMode() const { return NotMapped; } + +private: + GLuint m_textureId; +}; + +#endif + +class QtTestOpaqueVideoBuffer : public QAbstractVideoBuffer +{ +public: + QtTestOpaqueVideoBuffer() + : QAbstractVideoBuffer(UserHandle) + {} + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} + MapMode mapMode() const { return NotMapped; } +}; + +void tst_QPainterVideoSurface::colors() +{ + QPainterVideoSurface surface; + + QCOMPARE(surface.brightness(), 0); + QCOMPARE(surface.contrast(), 0); + QCOMPARE(surface.hue(), 0); + QCOMPARE(surface.saturation(), 0); + + surface.setBrightness(56); + QCOMPARE(surface.brightness(), 56); + + surface.setContrast(43); + QCOMPARE(surface.contrast(), 43); + + surface.setHue(-84); + QCOMPARE(surface.hue(), -84); + + surface.setSaturation(100); + QCOMPARE(surface.saturation(), 100); +} + +static const uchar rgb32ImageData[] = +{ + 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 +}; + +static const uchar argb32ImageData[] = +{ + 0x00, 0xff, 0x00, 0x00, 0xcc, 0x00, 0xff, 0xcc, + 0x77, 0x00, 0x00, 0x77, 0x00, 0xff, 0xff, 0x00 +}; + +static const uchar rgb24ImageData[] = +{ + 0x00, 0xff, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, + 0xcc, 0x00, 0xcc, 0x77, 0xff, 0x77, 0x00, 0x00 +}; + +static const uchar rgb565ImageData[] = +{ + 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00 +}; + +static const uchar yuvPlanarImageData[] = +{ + 0x00, 0x00, 0x0f, 0xff, 0xff, 0x0f, 0x00, 0x00, + 0x00, 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0f, 0x00, + 0x00, 0xff, 0x0f, 0x00, 0x00, 0x0f, 0xff, 0x00, + 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, + 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, + 0x0f, 0xff, 0x0f, 0x00, 0x00, 0x0f, 0xff, 0x0f, + 0x00, 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0f, 0x00, + 0x00, 0x00, 0x0f, 0xff, 0xff, 0x0f, 0x00, 0x00, + 0x00, 0x0f, 0x0f, 0x00, + 0x0f, 0x00, 0x00, 0x0f, + 0x0f, 0x00, 0x00, 0x0f, + 0x00, 0x0f, 0x0f, 0x00, + 0x00, 0x0f, 0x0f, 0x00, + 0x0f, 0x00, 0x00, 0x0f, + 0x0f, 0x00, 0x00, 0x0f, + 0x00, 0x0f, 0x0f, 0x00, +}; + +void tst_QPainterVideoSurface::supportedFormat_data() +{ + QTest::addColumn("handleType"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("frameSize"); + QTest::addColumn("supportedPixelFormat"); + QTest::addColumn("supportedFormat"); + + QTest::newRow("rgb32 640x480") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB32 + << QSize(640, 480) + << true + << true; + QTest::newRow("rgb32 -640x480") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB32 + << QSize(-640, 480) + << true + << false; + QTest::newRow("rgb24 1024x768") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB24 + << QSize(1024, 768) +#ifndef QT_OPENGL_ES + << true + << true; +#else + << false + << false; +#endif + QTest::newRow("rgb24 -1024x-768") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB24 + << QSize(-1024, -768) +#ifndef QT_OPENGL_ES + << true +#else + << false +#endif + << false; + QTest::newRow("rgb565 0x0") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB565 + << QSize(0, 0) + << true + << false; + QTest::newRow("YUV420P 640x480") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_YUV420P + << QSize(640, 480) + << false + << false; + QTest::newRow("YUV420P 640x-480") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_YUV420P + << QSize(640, -480) + << false + << false; + QTest::newRow("Y8 640x480") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_Y8 + << QSize(640, 480) + << false + << false; + QTest::newRow("Texture: rgb32 640x480") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB32 + << QSize(640, 480) + << false + << false; + QTest::newRow("Texture: rgb32 -640x480") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB32 + << QSize(-640, 480) + << false + << false; + QTest::newRow("rgb565 32x32") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB565 + << QSize(32, 32) + << true + << true; + QTest::newRow("rgb565 0x0") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB565 + << QSize(0, 0) + << true + << false; + QTest::newRow("argb32 256x256") + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_ARGB32 + << QSize(256, 256) + << true + << true; + QTest::newRow("Texture: rgb24 1024x768") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB24 + << QSize(1024, 768) + << false + << false; + QTest::newRow("Texture: rgb24 -1024x-768") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB24 + << QSize(-1024, -768) + << false + << false; + QTest::newRow("Texture: YUV420P 640x480") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_YUV420P + << QSize(640, 480) + << false + << false; + QTest::newRow("Texture: YUV420P 640x-480") + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_YUV420P + << QSize(640, -480) + << false + << false; + QTest::newRow("User Buffer: rgb32 256x256") + << QAbstractVideoBuffer::UserHandle + << QVideoFrame::Format_RGB32 + << QSize(256, 256) + << false + << false; +#if !defined(Q_OS_MAC) + QTest::newRow("Pixmap: rgb32 640x480") + << QAbstractVideoBuffer::QPixmapHandle + << QVideoFrame::Format_RGB32 + << QSize(640, 480) + << true + << true; + QTest::newRow("Pixmap: YUV420P 640x480") + << QAbstractVideoBuffer::QPixmapHandle + << QVideoFrame::Format_YUV420P + << QSize(640, 480) + << false + << true; +#endif +} + +void tst_QPainterVideoSurface::supportedFormat() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QSize, frameSize); + QFETCH(bool, supportedPixelFormat); + QFETCH(bool, supportedFormat); + + QPainterVideoSurface surface; + + const QList pixelFormats = surface.supportedPixelFormats(handleType); + + QCOMPARE(pixelFormats.contains(pixelFormat), QBool(supportedPixelFormat)); + + QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); + + QCOMPARE(surface.isFormatSupported(format), supportedFormat); + QCOMPARE(surface.start(format), supportedFormat); +} + +void tst_QPainterVideoSurface::present_data() +{ + QTest::addColumn("pixelFormatA"); + QTest::addColumn("frameSizeA"); + QTest::addColumn("frameDataA"); + QTest::addColumn("bytesA"); + QTest::addColumn("bytesPerLineA"); + QTest::addColumn("pixelFormatB"); + QTest::addColumn("frameSizeB"); + QTest::addColumn("frameDataB"); + QTest::addColumn("bytesB"); + QTest::addColumn("bytesPerLineB"); + + QTest::newRow("rgb32 -> argb32") + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_ARGB32 + << QSize(2, 2) + << static_cast(argb32ImageData) + << int(sizeof(argb32ImageData)) + << 8; + +#ifndef QT_OPENGL_ES + QTest::newRow("rgb32 -> rgb24") + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_RGB24 + << QSize(2, 2) + << static_cast(rgb24ImageData) + << int(sizeof(rgb24ImageData)) + << 8; +#endif + + QTest::newRow("rgb32 -> rgb565") + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_RGB565 + << QSize(2, 2) + << static_cast(rgb565ImageData) + << int(sizeof(rgb565ImageData)) + << 4; + +#ifndef QT_OPENGL_ES + QTest::newRow("rgb24 -> rgb565") + << QVideoFrame::Format_RGB24 + << QSize(2, 2) + << static_cast(rgb24ImageData) + << int(sizeof(rgb24ImageData)) + << 8 + << QVideoFrame::Format_RGB565 + << QSize(2, 2) + << static_cast(rgb565ImageData) + << int(sizeof(rgb565ImageData)) + << 4; +#endif +} + +void tst_QPainterVideoSurface::present() +{ + QFETCH(QVideoFrame::PixelFormat, pixelFormatA); + QFETCH(QSize, frameSizeA); + QFETCH(const uchar *, frameDataA); + QFETCH(int, bytesA); + QFETCH(int, bytesPerLineA); + QFETCH(QVideoFrame::PixelFormat, pixelFormatB); + QFETCH(QSize, frameSizeB); + QFETCH(const uchar *, frameDataB); + QFETCH(int, bytesB); + QFETCH(int, bytesPerLineB); + + QPainterVideoSurface surface; + + QImage image(320, 240, QImage::Format_RGB32); + + QSignalSpy frameSpy(&surface, SIGNAL(frameChanged())); + + const QList pixelFormats = surface.supportedPixelFormats(); + + { // Test painting before started. + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + + QVideoSurfaceFormat formatA(frameSizeA, pixelFormatA); + + QVERIFY(surface.start(formatA)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + { // Test painting before receiving a frame. + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + QVideoFrame frameA(bytesA, frameSizeA, bytesPerLineA, pixelFormatA); + + frameA.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frameA.bits(), frameDataA, frameA.mappedBytes()); + frameA.unmap(); + + QVERIFY(surface.present(frameA)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(frameSpy.count(), 1); + + { + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); + + { // Test repainting before receiving another frame. + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); + + // Not ready. + QVERIFY(!surface.present(frameA)); + QCOMPARE(frameSpy.count(), 1); + + surface.setReady(true); + QCOMPARE(surface.isReady(), true); + QVERIFY(surface.present(frameA)); + QCOMPARE(frameSpy.count(), 2); + + // Try switching to a different format after starting. + QVideoSurfaceFormat formatB(frameSizeB, pixelFormatB); + + QVERIFY(surface.start(formatB)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QVideoFrame frameB(bytesB, frameSizeB, bytesPerLineB, pixelFormatB); + + frameB.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frameB.bits(), frameDataB, frameB.mappedBytes()); + frameB.unmap(); + + QVERIFY(surface.present(frameB)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(frameSpy.count(), 3); + + { + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QVERIFY(surface.isActive()); + + surface.stop(); + + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + + // Try presenting a frame while stopped. + QVERIFY(!surface.present(frameB)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); + + // Try presenting a frame with a different format. + QVERIFY(surface.start(formatB)); + QVERIFY(!surface.present(frameA)); + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); +} + +void tst_QPainterVideoSurface::presentOpaqueFrame() +{ + QPainterVideoSurface surface; + + QImage image(320, 240, QImage::Format_RGB32); + + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QVERIFY(surface.start(format)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QVideoFrame frame(new QtTestOpaqueVideoBuffer, QSize(64, 64), QVideoFrame::Format_RGB32); + + if (surface.present(frame)) { + QPainter painter(&image); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); +} + +#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) + +void tst_QPainterVideoSurface::shaderType() +{ + QPainterVideoSurface surface; + QGLWidget widget; + widget.makeCurrent(); + + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(surface.supportedShaderTypes(), QPainterVideoSurface::NoShaders); + + surface.setGLContext(const_cast(widget.context())); + QCOMPARE(surface.glContext(), widget.context()); + + { + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + + surface.setShaderType(QPainterVideoSurface::NoShaders); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(spy.count(), 0); + } + +#ifndef QT_OPENGL_ES + if (surface.supportedShaderTypes() & QPainterVideoSurface::FragmentProgramShader) { + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + + surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::FragmentProgramShader); + QCOMPARE(spy.count(), 1); + + surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::FragmentProgramShader); + QCOMPARE(spy.count(), 1); + } +#endif + + if (surface.supportedShaderTypes() & QPainterVideoSurface::GlslShader) { + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + + surface.setShaderType(QPainterVideoSurface::GlslShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::GlslShader); + QCOMPARE(spy.count(), 1); + + surface.setShaderType(QPainterVideoSurface::GlslShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::GlslShader); + QCOMPARE(spy.count(), 1); + } + + { + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + + surface.setGLContext(const_cast(widget.context())); + QCOMPARE(surface.glContext(), widget.context()); + QCOMPARE(spy.count(), 0); + } + + surface.setGLContext(0); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(surface.supportedShaderTypes(), QPainterVideoSurface::NoShaders); + + { + QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); + + surface.setShaderType(QPainterVideoSurface::NoShaders); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(spy.count(), 0); + +#ifndef QT_OPENGL_ES + surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(spy.count(), 0); +#endif + + surface.setShaderType(QPainterVideoSurface::GlslShader); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(spy.count(), 0); + } +} + +void tst_QPainterVideoSurface::shaderTypeStarted_data() +{ + QTest::addColumn("shaderType"); + +#ifndef QT_OPENGL_ES + QTest::newRow("ARBfp") + << QPainterVideoSurface::FragmentProgramShader; +#endif + QTest::newRow("GLSL") + << QPainterVideoSurface::GlslShader; +} + +void tst_QPainterVideoSurface::shaderTypeStarted() +{ + QFETCH(QPainterVideoSurface::ShaderType, shaderType); + + QGLWidget widget; + widget.makeCurrent(); + + QPainterVideoSurface surface; + + surface.setGLContext(const_cast(widget.context())); + + if (!(surface.supportedShaderTypes() & shaderType)) + QSKIP("Shader type unsupported on this platform", SkipSingle); + + surface.setShaderType(shaderType); + QCOMPARE(surface.shaderType(), shaderType); + + QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); + { + QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); + + surface.setShaderType(QPainterVideoSurface::NoShaders); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(surface.isActive(), false); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().value(0).toBool(), false); + } + + QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); + { + QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); + + surface.setShaderType(QPainterVideoSurface::NoShaders); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(surface.isActive(), true); + QCOMPARE(spy.count(), 0); + + surface.setShaderType(shaderType); + QCOMPARE(surface.shaderType(), shaderType); + QCOMPARE(surface.isActive(), false); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().value(0).toBool(), false); + } + + QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); + { + QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); + + surface.setShaderType(shaderType); + QCOMPARE(surface.shaderType(), shaderType); + QCOMPARE(surface.isActive(), true); + QCOMPARE(spy.count(), 0); + + surface.setGLContext(0); + QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); + QCOMPARE(surface.isActive(), false); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.last().value(0).toBool(), false); + } +} + +void tst_QPainterVideoSurface::shaderSupportedFormat_data() +{ + QTest::addColumn("shaderType"); + QTest::addColumn("handleType"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("frameSize"); + QTest::addColumn("supportedPixelFormat"); + QTest::addColumn("supportedFormat"); + + QList > types; + + +#ifndef QT_OPENGL_ES + types << qMakePair(QPainterVideoSurface::FragmentProgramShader, QByteArray("ARBfp: ")); +#endif + types << qMakePair(QPainterVideoSurface::GlslShader, QByteArray("GLSL: ")); + + QPair type; + foreach (type, types) { + QTest::newRow((type.second + "rgb32 640x480").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB32 + << QSize(640, 480) + << true + << true; + QTest::newRow((type.second + "rgb32 -640x480").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB32 + << QSize(-640, 480) + << true + << false; + QTest::newRow((type.second + "rgb565 32x32").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB565 + << QSize(32, 32) + << true + << true; + QTest::newRow((type.second + "rgb565 0x0").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB565 + << QSize(0, 0) + << true + << false; + QTest::newRow((type.second + "argb32 256x256").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_ARGB32 + << QSize(256, 256) + << true + << true; + QTest::newRow((type.second + "rgb24 1024x768").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB24 + << QSize(1024, 768) +#ifndef QT_OPENGL_ES + << true + << true; +#else + << false + << false; +#endif + QTest::newRow((type.second + "rgb24 -1024x-768").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_RGB24 + << QSize(-1024, -768) +#ifndef QT_OPENGL_ES + << true +#else + << false +#endif + << false; +#ifndef Q_WS_MAC + QTest::newRow((type.second + "YUV420P 640x480").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_YUV420P + << QSize(640, 480) + << true + << true; + QTest::newRow((type.second + "YUV420P 640x-480").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_YUV420P + << QSize(640, -480) + << true + << false; +#endif + QTest::newRow((type.second + "Y8 640x480").constData()) + << type.first + << QAbstractVideoBuffer::NoHandle + << QVideoFrame::Format_Y8 + << QSize(640, 480) + << false + << false; + QTest::newRow((type.second + "Texture: rgb32 640x480").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB32 + << QSize(640, 480) + << true + << true; + QTest::newRow((type.second + "Texture: rgb32 -640x480").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB32 + << QSize(-640, 480) + << true + << false; +#ifndef Q_WS_MAC + QTest::newRow((type.second + "Texture: rgb565 32x32").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB565 + << QSize(32, 32) + << false + << false; + QTest::newRow((type.second + "Texture: rgb565 0x0").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB565 + << QSize(0, 0) + << false + << false; +#endif + QTest::newRow((type.second + "Texture argb32 256x256").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_ARGB32 + << QSize(256, 256) + << true + << true; +#ifndef Q_WS_MAC + QTest::newRow((type.second + "Texture: rgb24 1024x768").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB24 + << QSize(1024, 768) + << false + << false; + QTest::newRow((type.second + "Texture: rgb24 -1024x-768").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_RGB24 + << QSize(-1024, -768) + << false + << false; + QTest::newRow((type.second + "Texture: YUV420P 640x480").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_YUV420P + << QSize(640, 480) + << false + << false; + QTest::newRow((type.second + "Texture: YUV420P 640x-480").constData()) + << type.first + << QAbstractVideoBuffer::GLTextureHandle + << QVideoFrame::Format_YUV420P + << QSize(640, -480) + << false + << false; +#endif + QTest::newRow(type.second + "User Buffer: rgb32 256x256") + << type.first + << QAbstractVideoBuffer::UserHandle + << QVideoFrame::Format_RGB32 + << QSize(256, 256) + << false + << false; + } +} + +void tst_QPainterVideoSurface::shaderSupportedFormat() +{ + QFETCH(QPainterVideoSurface::ShaderType, shaderType); + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QSize, frameSize); + QFETCH(bool, supportedPixelFormat); + QFETCH(bool, supportedFormat); + + QGLWidget widget; + widget.makeCurrent(); + + QPainterVideoSurface surface; + surface.setGLContext(const_cast(widget.context())); + + + if (!(surface.supportedShaderTypes() & shaderType)) + QSKIP("Shader type not supported on this platform", SkipSingle); + + surface.setShaderType(shaderType); + if (surface.shaderType() != shaderType) + QSKIP("Shader type couldn't be set", SkipSingle); + + const QList pixelFormats = surface.supportedPixelFormats(handleType); + + QCOMPARE(pixelFormats.contains(pixelFormat), QBool(supportedPixelFormat)); + + QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); + + QCOMPARE(surface.isFormatSupported(format), supportedFormat); + QCOMPARE(surface.start(format), supportedFormat); +} + +void tst_QPainterVideoSurface::shaderPresent_data() +{ + QTest::addColumn("shaderType"); + QTest::addColumn("pixelFormatA"); + QTest::addColumn("frameSizeA"); + QTest::addColumn("frameDataA"); + QTest::addColumn("bytesA"); + QTest::addColumn("bytesPerLineA"); + QTest::addColumn("pixelFormatB"); + QTest::addColumn("frameSizeB"); + QTest::addColumn("frameDataB"); + QTest::addColumn("bytesB"); + QTest::addColumn("bytesPerLineB"); + + QList > types; +#ifndef QT_OPENGL_ES + types << qMakePair(QPainterVideoSurface::FragmentProgramShader, QByteArray("ARBfp: ")); +#endif + types << qMakePair(QPainterVideoSurface::GlslShader, QByteArray("GLSL: ")); + + QPair type; + foreach (type, types) { + QTest::newRow((type.second + "rgb32 -> argb32").constData()) + << type.first + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_ARGB32 + << QSize(2, 2) + << static_cast(argb32ImageData) + << int(sizeof(argb32ImageData)) + << 8; + + QTest::newRow((type.second + "rgb32 -> rgb565").constData()) + << type.first + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_RGB565 + << QSize(2, 2) + << static_cast(rgb565ImageData) + << int(sizeof(rgb565ImageData)) + << 4; +#ifndef Q_WS_MAC + QTest::newRow((type.second + "rgb32 -> yuv420p").constData()) + << type.first + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8 + << QVideoFrame::Format_YUV420P + << QSize(8, 8) + << static_cast(yuvPlanarImageData) + << int(sizeof(yuvPlanarImageData)) + << 8; + + QTest::newRow((type.second + "yv12 -> rgb32").constData()) + << type.first + << QVideoFrame::Format_YV12 + << QSize(8, 8) + << static_cast(yuvPlanarImageData) + << int(sizeof(yuvPlanarImageData)) + << 8 + << QVideoFrame::Format_RGB32 + << QSize(2, 2) + << static_cast(rgb32ImageData) + << int(sizeof(rgb32ImageData)) + << 8; +#endif + } +} + +void tst_QPainterVideoSurface::shaderPresent() +{ + QFETCH(QPainterVideoSurface::ShaderType, shaderType); + QFETCH(QVideoFrame::PixelFormat, pixelFormatA); + QFETCH(QSize, frameSizeA); + QFETCH(const uchar *, frameDataA); + QFETCH(int, bytesA); + QFETCH(int, bytesPerLineA); + QFETCH(QVideoFrame::PixelFormat, pixelFormatB); + QFETCH(QSize, frameSizeB); + QFETCH(const uchar *, frameDataB); + QFETCH(int, bytesB); + QFETCH(int, bytesPerLineB); + + QGLWidget widget; + widget.makeCurrent(); + + QPainterVideoSurface surface; + surface.setGLContext(const_cast(widget.context())); + + if (!(surface.supportedShaderTypes() & shaderType)) + QSKIP("Shader type unsupported on this platform", SkipSingle); + + surface.setShaderType(shaderType); + if (surface.shaderType() != shaderType) + QSKIP("Shader type couldn't be set", SkipSingle); + + QSignalSpy frameSpy(&surface, SIGNAL(frameChanged())); + + { // Test painting before starting the surface. + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); + + QVideoSurfaceFormat formatA(frameSizeA, pixelFormatA); + + QVERIFY(surface.start(formatA)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + // Test painting before receiving a frame. + { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QVideoFrame frameA(bytesA, frameSizeA, bytesPerLineA, pixelFormatA); + + frameA.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frameA.bits(), frameDataA, frameA.mappedBytes()); + frameA.unmap(); + + QVERIFY(surface.present(frameA)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(frameSpy.count(), 1); + + { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); + + { // Test repainting before receiving another frame. + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); + + // Not ready. + QVERIFY(!surface.present(frameA)); + QCOMPARE(frameSpy.count(), 1); + + surface.setReady(true); + QCOMPARE(surface.isReady(), true); + QVERIFY(surface.present(frameA)); + QCOMPARE(frameSpy.count(), 2); + + // Try switching to a different format after starting. + QVideoSurfaceFormat formatB(frameSizeB, pixelFormatB); + + QVERIFY(surface.start(formatB)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QVideoFrame frameB(bytesB, frameSizeB, bytesPerLineB, pixelFormatB); + + frameB.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frameB.bits(), frameDataB, frameB.mappedBytes()); + frameB.unmap(); + + QVERIFY(surface.present(frameB)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(frameSpy.count(), 3); + + { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + QCOMPARE(surface.isActive(), true); + + surface.stop(); + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + + // Try presenting a frame while stopped. + QVERIFY(!surface.present(frameB)); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); + + // Try stopping while already stopped. + surface.stop(); + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + + // Try presenting a frame with a different format. + QVERIFY(surface.start(formatB)); + QVERIFY(!surface.present(frameA)); + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); +} + +void tst_QPainterVideoSurface::shaderPresentOpaqueFrame_data() +{ + QTest::addColumn("shaderType"); + +#ifndef QT_OPENGL_ES + QTest::newRow("ARBfp") + << QPainterVideoSurface::FragmentProgramShader; +#endif + QTest::newRow("GLSL") + << QPainterVideoSurface::GlslShader; +} + +void tst_QPainterVideoSurface::shaderPresentOpaqueFrame() +{ + QFETCH(QPainterVideoSurface::ShaderType, shaderType); + + QGLWidget widget; + widget.makeCurrent(); + + QPainterVideoSurface surface; + surface.setGLContext(const_cast(widget.context())); + + if (!(surface.supportedShaderTypes() & shaderType)) + QSKIP("Shader type unsupported on this platform", SkipSingle); + + surface.setShaderType(shaderType); + if (surface.shaderType() != shaderType) + QSKIP("Shader type couldn't be set", SkipSingle); + + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QVERIFY(surface.start(format)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QVideoFrame frame(new QtTestOpaqueVideoBuffer, QSize(64, 64), QVideoFrame::Format_RGB32); + + if (surface.present(frame)) { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + + QCOMPARE(surface.isActive(), false); + QCOMPARE(surface.isReady(), false); + QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); +} + +void tst_QPainterVideoSurface::shaderPresentGLFrame_data() +{ + QTest::addColumn("shaderType"); + +#ifndef QT_OPENGL_ES + QTest::newRow("ARBfp") + << QPainterVideoSurface::FragmentProgramShader; +#endif + QTest::newRow("GLSL") + << QPainterVideoSurface::GlslShader; +} + +void tst_QPainterVideoSurface::shaderPresentGLFrame() +{ + QFETCH(QPainterVideoSurface::ShaderType, shaderType); + + QGLWidget widget; + widget.makeCurrent(); + + QPainterVideoSurface surface; + surface.setGLContext(const_cast(widget.context())); + + if (!(surface.supportedShaderTypes() & shaderType)) + QSKIP("Shader type unsupported on this platform", SkipSingle); + + surface.setShaderType(shaderType); + if (surface.shaderType() != shaderType) + QSKIP("Shader type couldn't be set", SkipSingle); + + QVideoSurfaceFormat format( + QSize(2, 2), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); + + QVERIFY(surface.start(format)); + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), true); + + QtTestGLVideoBuffer *buffer = new QtTestGLVideoBuffer; + + glBindTexture(GL_TEXTURE_2D, buffer->textureId()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb32ImageData); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + QVideoFrame frame(buffer, QSize(2, 2), QVideoFrame::Format_RGB32); + + QVERIFY(surface.present(frame)); + + { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); + + { + QPainter painter(&widget); + surface.paint(&painter, QRect(0, 0, 320, 240)); + } + + QCOMPARE(surface.isActive(), true); + QCOMPARE(surface.isReady(), false); +} + +#endif + +QTEST_MAIN(tst_QPainterVideoSurface) + +#include "tst_qpaintervideosurface.moc" diff --git a/tests/auto/unit/qradiodata/main.cpp b/tests/auto/unit/qradiodata/main.cpp new file mode 100755 index 000000000..1bd2e27be --- /dev/null +++ b/tests/auto/unit/qradiodata/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qradiodata.h" + +int main(int argc, char**argv) +{ + QCoreApplication app(argc,argv); + int ret; + tst_QRadioData test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qradiodata/qradiodata.pro b/tests/auto/unit/qradiodata/qradiodata.pro new file mode 100644 index 000000000..0e3c4edec --- /dev/null +++ b/tests/auto/unit/qradiodata/qradiodata.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qradiodata + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +HEADERS += tst_qradiodata.h +SOURCES += main.cpp tst_qradiodata.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockradio.pri) diff --git a/tests/auto/unit/qradiodata/tst_qradiodata.cpp b/tests/auto/unit/qradiodata/tst_qradiodata.cpp new file mode 100644 index 000000000..157f63def --- /dev/null +++ b/tests/auto/unit/qradiodata/tst_qradiodata.cpp @@ -0,0 +1,148 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qradiodata.h" + +QT_USE_NAMESPACE + +void tst_QRadioData::initTestCase() +{ + qRegisterMetaType("QRadioData::ProgramType"); + + mock = new MockRadioDataControl(this); + service = new MockMediaService(this, mock); + provider = new MockMediaServiceProvider(service); + radio = new QRadioData(0,provider); + QVERIFY(radio->service() != 0); + QVERIFY(radio->isAvailable()); + QVERIFY(radio->availabilityError() == QtMultimedia::NoError); +} + +void tst_QRadioData::cleanupTestCase() +{ + QVERIFY(radio->error() == QRadioData::NoError); + QVERIFY(radio->errorString().isEmpty()); + + delete radio; + delete service; + delete provider; +} + +void tst_QRadioData::testNullService() +{ + const QPair nullRange(0, 0); + + MockMediaServiceProvider provider(0); + QRadioData radio(0, &provider); + QVERIFY(!radio.isAvailable()); + QCOMPARE(radio.error(), QRadioData::ResourceError); + QCOMPARE(radio.errorString(), QString()); + QCOMPARE(radio.stationId(), QString()); + QCOMPARE(radio.programType(), QRadioData::Undefined); + QCOMPARE(radio.programTypeName(), QString()); + QCOMPARE(radio.stationName(), QString()); + QCOMPARE(radio.radioText(), QString()); + QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + +} + +void tst_QRadioData::testNullControl() +{ + const QPair nullRange(0, 0); + + MockMediaService service(0, 0); + MockMediaServiceProvider provider(&service); + QRadioData radio(0, &provider); + QVERIFY(!radio.isAvailable()); + QCOMPARE(radio.error(), QRadioData::ResourceError); + QCOMPARE(radio.errorString(), QString()); + + QCOMPARE(radio.stationId(), QString()); + QCOMPARE(radio.programType(), QRadioData::Undefined); + QCOMPARE(radio.programTypeName(), QString()); + QCOMPARE(radio.stationName(), QString()); + QCOMPARE(radio.radioText(), QString()); + QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + { + QSignalSpy spy(&radio, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); + + radio.setAlternativeFrequenciesEnabled(true); + QCOMPARE(radio.isAlternativeFrequenciesEnabled(), false); + QCOMPARE(spy.count(), 0); + } +} + +void tst_QRadioData::testAlternativeFrequencies() +{ + QSignalSpy readSignal(radio, SIGNAL(alternativeFrequenciesEnabledChanged(bool))); + radio->setAlternativeFrequenciesEnabled(true); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->isAlternativeFrequenciesEnabled() == true); + QVERIFY(readSignal.count() == 1); +} + +void tst_QRadioData::testRadioDataUpdates() +{ + QSignalSpy rtSpy(radio, SIGNAL(radioTextChanged(QString))); + QSignalSpy ptyPTYSpy(radio, SIGNAL(programTypeChanged(QRadioData::ProgramType))); + QSignalSpy ptynSpy(radio, SIGNAL(programTypeNameChanged(QString))); + QSignalSpy piSpy(radio, SIGNAL(stationIdChanged(QString))); + QSignalSpy psSpy(radio, SIGNAL(stationNameChanged(QString))); + mock->forceRT("Mock Radio Text"); + mock->forceProgramType(static_cast(QRadioData::Sport)); + mock->forcePTYN("Mock Programme Type Name"); + mock->forcePI("Mock Programme Identification"); + mock->forcePS("Mock Programme Service"); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(rtSpy.count() == 1); + QVERIFY(ptyPTYSpy.count() == 1); + QVERIFY(ptynSpy.count() == 1); + QVERIFY(piSpy.count() == 1); + QVERIFY(psSpy.count() == 1); + qDebug()<radioText(); + QCOMPARE(radio->radioText(), QString("Mock Radio Text")); + QCOMPARE(radio->programType(), QRadioData::Sport); + QCOMPARE(radio->programTypeName(), QString("Mock Programme Type Name")); + QCOMPARE(radio->stationId(), QString("Mock Programme Identification")); + QCOMPARE(radio->stationName(), QString("Mock Programme Service")); +} diff --git a/tests/auto/unit/qradiodata/tst_qradiodata.h b/tests/auto/unit/qradiodata/tst_qradiodata.h new file mode 100644 index 000000000..985197566 --- /dev/null +++ b/tests/auto/unit/qradiodata/tst_qradiodata.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QRADIODATA_H +#define TST_QRADIODATA_H + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "mockmediaserviceprovider.h" +#include "mockmediaservice.h" +#include "mockradiodatacontrol.h" + +QT_USE_NAMESPACE + +class tst_QRadioData: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testNullService(); + void testNullControl(); + void testAlternativeFrequencies(); + void testRadioDataUpdates(); + +private: + MockRadioDataControl *mock; + MockMediaService *service; + MockMediaServiceProvider *provider; + QRadioData *radio; +}; +#endif diff --git a/tests/auto/unit/qradiotuner/main.cpp b/tests/auto/unit/qradiotuner/main.cpp new file mode 100755 index 000000000..b2d6fd2b1 --- /dev/null +++ b/tests/auto/unit/qradiotuner/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +#include "tst_qradiotuner.h" + +int main(int argc, char**argv) +{ + QCoreApplication app(argc,argv); + int ret; + tst_QRadioTuner test_api; + ret = QTest::qExec(&test_api, argc, argv); + return ret; +} diff --git a/tests/auto/unit/qradiotuner/qradiotuner.pro b/tests/auto/unit/qradiotuner/qradiotuner.pro new file mode 100644 index 000000000..3d3a21f5d --- /dev/null +++ b/tests/auto/unit/qradiotuner/qradiotuner.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qradiotuner + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +HEADERS += tst_qradiotuner.h +SOURCES += main.cpp tst_qradiotuner.cpp + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockradio.pri) diff --git a/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp new file mode 100644 index 000000000..c42642283 --- /dev/null +++ b/tests/auto/unit/qradiotuner/tst_qradiotuner.cpp @@ -0,0 +1,336 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include "tst_qradiotuner.h" + +QT_USE_NAMESPACE + +void tst_QRadioTuner::initTestCase() +{ + qRegisterMetaType("QRadioTuner::State"); + qRegisterMetaType("QRadioTuner::Band"); + + mock = new MockRadioTunerControl(this); + service = new MockMediaService(this, mock); + provider = new MockMediaServiceProvider(service); + radio = new QRadioTuner(0,provider); + QVERIFY(radio->service() != 0); + QVERIFY(radio->isAvailable()); + QVERIFY(radio->availabilityError() == QtMultimedia::NoError); + + QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); + + QCOMPARE(radio->state(), QRadioTuner::StoppedState); + radio->start(); + QVERIFY(radio->availabilityError() == QtMultimedia::NoError); + QCOMPARE(radio->state(), QRadioTuner::ActiveState); + + QCOMPARE(stateSpy.count(), 1); + QCOMPARE(stateSpy.first()[0].value(), QRadioTuner::ActiveState); +} + +void tst_QRadioTuner::cleanupTestCase() +{ + QVERIFY(radio->error() == QRadioTuner::NoError); + QVERIFY(radio->errorString().isEmpty()); + + QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); + + radio->stop(); + QVERIFY(radio->availabilityError() == QtMultimedia::NoError); + QCOMPARE(radio->state(), QRadioTuner::StoppedState); + QCOMPARE(stateSpy.count(), 1); + + QCOMPARE(stateSpy.first()[0].value(), QRadioTuner::StoppedState); + + delete radio; + delete service; + delete provider; +} + +void tst_QRadioTuner::testNullService() +{ + const QPair nullRange(0, 0); + + MockMediaServiceProvider provider(0); + QRadioTuner radio(0, &provider); + QVERIFY(!radio.isAvailable()); + radio.start(); + QCOMPARE(radio.error(), QRadioTuner::ResourceError); + QCOMPARE(radio.errorString(), QString()); + QCOMPARE(radio.band(), QRadioTuner::FM); + QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false); + QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false); + QCOMPARE(radio.frequency(), 0); + QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0); + QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0); + QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange); + QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange); + QCOMPARE(radio.isStereo(), false); + QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); + QCOMPARE(radio.signalStrength(), 0); + QCOMPARE(radio.volume(), 0); + QCOMPARE(radio.isMuted(), false); + QCOMPARE(radio.isSearching(), false); + radio.stop(); +} + +void tst_QRadioTuner::testNullControl() +{ + const QPair nullRange(0, 0); + + MockMediaService service(0, 0); + MockMediaServiceProvider provider(&service); + QRadioTuner radio(0, &provider); + QVERIFY(!radio.isAvailable()); + radio.start(); + + QCOMPARE(radio.error(), QRadioTuner::ResourceError); + QCOMPARE(radio.errorString(), QString()); + + QCOMPARE(radio.band(), QRadioTuner::FM); + QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false); + QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false); + QCOMPARE(radio.frequency(), 0); + QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0); + QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0); + QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange); + QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange); + { + QSignalSpy bandSpy(&radio, SIGNAL(bandChanged(QRadioTuner::Band))); + QSignalSpy frequencySpy(&radio, SIGNAL(frequencyChanged(int))); + + radio.setFrequency(107500); + QCOMPARE(radio.band(), QRadioTuner::FM); + QCOMPARE(radio.frequency(), 0); + QCOMPARE(bandSpy.count(), 0); + QCOMPARE(frequencySpy.count(), 0); + + radio.setBand(QRadioTuner::AM); + QCOMPARE(radio.band(), QRadioTuner::FM); + QCOMPARE(radio.frequency(), 0); + QCOMPARE(bandSpy.count(), 0); + QCOMPARE(frequencySpy.count(), 0); + } + QCOMPARE(radio.isStereo(), false); + QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); + + radio.setStereoMode(QRadioTuner::ForceStereo); + QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); + + QCOMPARE(radio.signalStrength(), 0); + + QCOMPARE(radio.volume(), 0); + QCOMPARE(radio.isMuted(), false); + { + QSignalSpy volumeSpy(&radio, SIGNAL(volumeChanged(int))); + QSignalSpy muteSpy(&radio, SIGNAL(mutedChanged(bool))); + + radio.setVolume(76); + QCOMPARE(radio.volume(), 0); + QCOMPARE(volumeSpy.count(), 0); + + radio.setMuted(true); + QCOMPARE(radio.isMuted(), false); + QCOMPARE(muteSpy.count(), 0); + } + QCOMPARE(radio.isSearching(), false); + { + QSignalSpy spy(&radio, SIGNAL(searchingChanged(bool))); + + radio.searchBackward(); + QCOMPARE(radio.isSearching(), false); + QCOMPARE(spy.count(), 0); + + radio.searchForward(); + QCOMPARE(radio.isSearching(), false); + QCOMPARE(spy.count(), 0); + + radio.searchAllStations(); + QCOMPARE(radio.isSearching(), false); + QCOMPARE(spy.count(), 0); + + radio.cancelSearch(); + QCOMPARE(radio.isSearching(), false); + QCOMPARE(spy.count(), 0); + } + + radio.stop(); +} + +void tst_QRadioTuner::testBand() +{ + QVERIFY(radio->isBandSupported(QRadioTuner::FM)); + QVERIFY(!radio->isBandSupported(QRadioTuner::SW)); + + if(radio->isBandSupported(QRadioTuner::AM)) { + QSignalSpy readSignal(radio, SIGNAL(bandChanged(QRadioTuner::Band))); + radio->setBand(QRadioTuner::AM); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->band() == QRadioTuner::AM); + QVERIFY(readSignal.count() == 1); + } +} + +void tst_QRadioTuner::testFrequency() +{ + QSignalSpy readSignal(radio, SIGNAL(frequencyChanged(int))); + radio->setFrequency(104500000); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->frequency() == 104500000); + QVERIFY(readSignal.count() == 1); + + QVERIFY(radio->frequencyStep(QRadioTuner::FM) == 1); + QPair test = radio->frequencyRange(QRadioTuner::FM); + QVERIFY(test.first == 1); + QVERIFY(test.second == 2); +} + +void tst_QRadioTuner::testMute() +{ + QSignalSpy readSignal(radio, SIGNAL(mutedChanged(bool))); + radio->setMuted(true); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->isMuted()); + QVERIFY(readSignal.count() == 1); +} + +void tst_QRadioTuner::testSearch() +{ + QSignalSpy readSignal(radio, SIGNAL(searchingChanged(bool))); + QVERIFY(!radio->isSearching()); + + radio->searchForward(); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->isSearching()); + QVERIFY(readSignal.count() == 1); + + radio->cancelSearch(); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!radio->isSearching()); + QVERIFY(readSignal.count() == 2); + + radio->searchBackward(); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->isSearching()); + QVERIFY(readSignal.count() == 3); + + radio->cancelSearch(); + QVERIFY(!radio->isSearching()); +} + +void tst_QRadioTuner::testVolume() +{ + QVERIFY(radio->volume() == 100); + QSignalSpy readSignal(radio, SIGNAL(volumeChanged(int))); + radio->setVolume(50); + QTestEventLoop::instance().enterLoop(1); + QVERIFY(radio->volume() == 50); + QVERIFY(readSignal.count() == 1); +} + +void tst_QRadioTuner::testSignal() +{ + QVERIFY(radio->signalStrength() == 0); + // There is no set of this only a get, do nothing else. +} + +void tst_QRadioTuner::testStereo() +{ + /* no set function to toggle stereo status; + cannot emit stereoStatusChanged() signal */ + + QVERIFY(radio->isStereo()); + radio->setStereoMode(QRadioTuner::ForceMono); + QVERIFY(radio->stereoMode() == QRadioTuner::ForceMono); +} + +void tst_QRadioTuner::testSearchAllStations() +{ + QSignalSpy foundSpy(radio, SIGNAL(stationFound(int,QString))); + QSignalSpy completeSpy(radio, SIGNAL(searchingChanged(bool))); + radio->searchAllStations(QRadioTuner::SearchGetStationId); + QTestEventLoop::instance().enterLoop(1); + QCOMPARE(radio->frequency(), 103100000 ); + QCOMPARE(foundSpy.count(), 3); + QVERIFY(qvariant_cast(foundSpy.at(2).at(0)) == 103100000 ); + QVERIFY(qvariant_cast(foundSpy.at(2).at(1)) == QString("MockProgramPI3") ); + QCOMPARE(completeSpy.count(), 2); +} + +// QRadioTuner's errorsignal +void tst_QRadioTuner::errorSignal() +{ + qRegisterMetaType("QRadioTuner::Error"); + QObject obj; + MockRadioTunerControl dctrl(&obj); + MockMediaService service(&obj, &dctrl); + MockMediaServiceProvider provider(&service); + QRadioTuner radio(0,&provider); + QSignalSpy spy(&radio, SIGNAL(error(QRadioTuner::Error))); + QVERIFY(radio.service() != 0); + QVERIFY(radio.isAvailable()); + radio.start(); + radio.setBand(QRadioTuner::FM); + QVERIFY(spy.count() == 1); + QVERIFY(qvariant_cast(spy.at(0).at(0)) == QRadioTuner::NoError); + QVERIFY(radio.error() == QRadioTuner::NoError); + QVERIFY(radio.error() != QRadioTuner::OpenError); + QVERIFY(radio.errorString().isEmpty()); + spy.clear(); + + /* emits QRadioTuner::OutOfRangeError if band is set to FM2 or LW + and frequency set to >= 148500000 */ + + radio.setBand(QRadioTuner::LW); + radio.setBand(QRadioTuner::FM2); + radio.setFrequency(148500000); + QVERIFY(spy.count() == 3); + QVERIFY(qvariant_cast(spy.at(0).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(qvariant_cast(spy.at(1).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(qvariant_cast(spy.at(2).at(0)) == QRadioTuner::OutOfRangeError); + QVERIFY(radio.error() == QRadioTuner::OutOfRangeError); + QVERIFY2(!radio.errorString().isEmpty(), "band and range not supported"); + spy.clear(); + radio.stop(); +} diff --git a/tests/auto/unit/qradiotuner/tst_qradiotuner.h b/tests/auto/unit/qradiotuner/tst_qradiotuner.h new file mode 100644 index 000000000..364f5e2d9 --- /dev/null +++ b/tests/auto/unit/qradiotuner/tst_qradiotuner.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef TST_QRADIOTUNER_H +#define TST_QRADIOTUNER_H + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "mockmediaserviceprovider.h" +#include "mockmediaservice.h" +#include "mockradiotunercontrol.h" + +QT_USE_NAMESPACE + +class tst_QRadioTuner: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void testNullService(); + void testNullControl(); + void testBand(); + void testFrequency(); + void testMute(); + void testSearch(); + void testVolume(); + void testSignal(); + void testStereo(); + void testSearchAllStations(); + void errorSignal(); + +private: + MockRadioTunerControl *mock; + MockMediaService *service; + MockMediaServiceProvider *provider; + QRadioTuner *radio; +}; +#endif diff --git a/tests/auto/unit/qvideoencodercontrol/qvideoencodercontrol.pro b/tests/auto/unit/qvideoencodercontrol/qvideoencodercontrol.pro new file mode 100644 index 000000000..ad14a25af --- /dev/null +++ b/tests/auto/unit/qvideoencodercontrol/qvideoencodercontrol.pro @@ -0,0 +1,9 @@ +CONFIG += testcase +TARGET = tst_qvideoencodercontrol + +QT += multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += \ + tst_qvideoencodercontrol.cpp + diff --git a/tests/auto/unit/qvideoencodercontrol/tst_qvideoencodercontrol.cpp b/tests/auto/unit/qvideoencodercontrol/tst_qvideoencodercontrol.cpp new file mode 100644 index 000000000..4f1b99d8e --- /dev/null +++ b/tests/auto/unit/qvideoencodercontrol/tst_qvideoencodercontrol.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include "qvideoencodercontrol.h" +class MyVideEncoderControl: public QVideoEncoderControl +{ + Q_OBJECT + +public: + MyVideEncoderControl(QObject *parent = 0 ):QVideoEncoderControl(parent) + { + + } + + ~MyVideEncoderControl() + { + + } + + QList supportedResolutions(const QVideoEncoderSettings &settings,bool *continuous = 0) const + { + Q_UNUSED(settings); + Q_UNUSED(continuous); + + return (QList()); + } + + QList supportedFrameRates(const QVideoEncoderSettings &settings, bool *continuous = 0) const + { + Q_UNUSED(settings); + Q_UNUSED(continuous); + + return (QList()); + + } + + QStringList supportedVideoCodecs() const + { + return QStringList(); + + } + + QString videoCodecDescription(const QString &codecName) const + { + Q_UNUSED(codecName) + return QString(); + + } + + QVideoEncoderSettings videoSettings() const + { + return QVideoEncoderSettings(); + } + + void setVideoSettings(const QVideoEncoderSettings &settings) + { + Q_UNUSED(settings); + } + + QStringList supportedEncodingOptions(const QString &codec) const + { + Q_UNUSED(codec); + return QStringList(); + } + + QVariant encodingOption(const QString &codec, const QString &name) const + { + Q_UNUSED(codec); + Q_UNUSED(name); + return QVariant(); + } + + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value) + { + Q_UNUSED(codec); + Q_UNUSED(name); + Q_UNUSED(value); + } + +}; + +class tst_QVideoEncoderControl: public QObject +{ + Q_OBJECT +private slots: + void constructor(); +}; + +void tst_QVideoEncoderControl::constructor() +{ + QObject parent; + MyVideEncoderControl control(&parent); +} + +QTEST_MAIN(tst_QVideoEncoderControl) +#include "tst_qvideoencodercontrol.moc" + + diff --git a/tests/auto/unit/qvideoframe/qvideoframe.pro b/tests/auto/unit/qvideoframe/qvideoframe.pro new file mode 100644 index 000000000..cfd84a2db --- /dev/null +++ b/tests/auto/unit/qvideoframe/qvideoframe.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qvideoframe + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qvideoframe.cpp + diff --git a/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp new file mode 100644 index 000000000..595fbcf71 --- /dev/null +++ b/tests/auto/unit/qvideoframe/tst_qvideoframe.cpp @@ -0,0 +1,1126 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include +#include +#include + +// Adds an enum, and the stringized version +#define ADD_ENUM_TEST(x) \ + QTest::newRow(#x) \ + << QVideoFrame::x \ + << QString(QLatin1String(#x)); + + +class tst_QVideoFrame : public QObject +{ + Q_OBJECT +public: + tst_QVideoFrame(); + ~tst_QVideoFrame(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void create_data(); + void create(); + void createInvalid_data(); + void createInvalid(); + void createFromBuffer_data(); + void createFromBuffer(); + void createFromImage_data(); + void createFromImage(); + void createFromIncompatibleImage(); + void createNull(); + void destructor(); + void copy_data(); + void copy(); + void assign_data(); + void assign(); + void map_data(); + void map(); + void mapImage_data(); + void mapImage(); + void imageDetach(); + void formatConversion_data(); + void formatConversion(); + + void debugType_data(); + void debugType(); + + void debug_data(); + void debug(); + + void debugFormat_data(); + void debugFormat(); + + void isMapped(); + void isReadable(); + void isWritable(); +}; + +Q_DECLARE_METATYPE(QImage::Format) + +class QtTestVideoBuffer : public QObject, public QAbstractVideoBuffer +{ + Q_OBJECT +public: + QtTestVideoBuffer() + : QAbstractVideoBuffer(NoHandle) {} + explicit QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) + : QAbstractVideoBuffer(type) {} + + MapMode mapMode() const { return NotMapped; } + + uchar *map(MapMode, int *, int *) { return 0; } + void unmap() {} +}; + +tst_QVideoFrame::tst_QVideoFrame() +{ +} + +tst_QVideoFrame::~tst_QVideoFrame() +{ +} + +void tst_QVideoFrame::initTestCase() +{ +} + +void tst_QVideoFrame::cleanupTestCase() +{ +} + +void tst_QVideoFrame::init() +{ +} + +void tst_QVideoFrame::cleanup() +{ +} + +void tst_QVideoFrame::create_data() +{ + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("bytes"); + QTest::addColumn("bytesPerLine"); + + QTest::newRow("64x64 ARGB32") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << 16384 + << 256; + QTest::newRow("32x256 YUV420P") + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << 13288 + << 32; +} + +void tst_QVideoFrame::create() +{ + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(int, bytes); + QFETCH(int, bytesPerLine); + + QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.handle(), QVariant()); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createInvalid_data() +{ + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("bytes"); + QTest::addColumn("bytesPerLine"); + + QTest::newRow("64x64 ARGB32 0 size") + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << 0 + << 45; + QTest::newRow("32x256 YUV420P negative size") + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << -13288 + << 32; +} + +void tst_QVideoFrame::createInvalid() +{ + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(int, bytes); + QFETCH(int, bytesPerLine); + + QVideoFrame frame(bytes, size, bytesPerLine, pixelFormat); + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.handle(), QVariant()); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createFromBuffer_data() +{ + QTest::addColumn("handleType"); + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + + QTest::newRow("64x64 ARGB32 no handle") + << QAbstractVideoBuffer::NoHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; + QTest::newRow("64x64 ARGB32 gl handle") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; + QTest::newRow("64x64 ARGB32 user handle") + << QAbstractVideoBuffer::UserHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32; +} + +void tst_QVideoFrame::createFromBuffer() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + + QVideoFrame frame(new QtTestVideoBuffer(handleType), size, pixelFormat); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createFromImage_data() +{ + QTest::addColumn("size"); + QTest::addColumn("imageFormat"); + QTest::addColumn("pixelFormat"); + + QTest::newRow("64x64 RGB32") + << QSize(64, 64) + << QImage::Format_RGB32 + << QVideoFrame::Format_RGB32; + QTest::newRow("12x45 RGB16") + << QSize(12, 45) + << QImage::Format_RGB16 + << QVideoFrame::Format_RGB565; + QTest::newRow("19x46 ARGB32_Premultiplied") + << QSize(19, 46) + << QImage::Format_ARGB32_Premultiplied + << QVideoFrame::Format_ARGB32_Premultiplied; +} + +void tst_QVideoFrame::createFromImage() +{ + QFETCH(QSize, size); + QFETCH(QImage::Format, imageFormat); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + + const QImage image(size.width(), size.height(), imageFormat); + + QVideoFrame frame(image); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createFromIncompatibleImage() +{ + const QImage image(64, 64, QImage::Format_Mono); + + QVideoFrame frame(image); + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize(64, 64)); + QCOMPARE(frame.width(), 64); + QCOMPARE(frame.height(), 64); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::createNull() +{ + // Default ctor + { + QVideoFrame frame; + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize()); + QCOMPARE(frame.width(), -1); + QCOMPARE(frame.height(), -1); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + QVERIFY(!frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(!frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(!frame.map(QAbstractVideoBuffer::WriteOnly)); + QCOMPARE(frame.isMapped(), false); + frame.unmap(); // Shouldn't crash + QCOMPARE(frame.isReadable(), false); + QCOMPARE(frame.isWritable(), false); + } + + // Null buffer (shouldn't crash) + { + QVideoFrame frame(0, QSize(1024,768), QVideoFrame::Format_ARGB32); + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(frame.size(), QSize(1024, 768)); + QCOMPARE(frame.width(), 1024); + QCOMPARE(frame.height(), 768); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + QVERIFY(!frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(!frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(!frame.map(QAbstractVideoBuffer::WriteOnly)); + QCOMPARE(frame.isMapped(), false); + frame.unmap(); // Shouldn't crash + QCOMPARE(frame.isReadable(), false); + QCOMPARE(frame.isWritable(), false); + } +} + +void tst_QVideoFrame::destructor() +{ + QPointer buffer = new QtTestVideoBuffer; + + { + QVideoFrame frame(buffer, QSize(4, 1), QVideoFrame::Format_ARGB32); + } + + QVERIFY(buffer.isNull()); +} + +void tst_QVideoFrame::copy_data() +{ + QTest::addColumn("handleType"); + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("fieldType"); + QTest::addColumn("startTime"); + QTest::addColumn("endTime"); + + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::TopField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::BottomField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); + QTest::newRow("1052x756 ARGB32") + << QAbstractVideoBuffer::NoHandle + << QSize(1052, 756) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::ProgressiveFrame + << qint64(12345) + << qint64(12389); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); +} + +void tst_QVideoFrame::copy() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QVideoFrame::FieldType, fieldType); + QFETCH(qint64, startTime); + QFETCH(qint64, endTime); + + QPointer buffer = new QtTestVideoBuffer(handleType); + + { + QVideoFrame frame(buffer, size, pixelFormat); + frame.setFieldType(QVideoFrame::FieldType(fieldType)); + frame.setStartTime(startTime); + frame.setEndTime(endTime); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), startTime); + QCOMPARE(frame.endTime(), endTime); + + { + QVideoFrame otherFrame(frame); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), endTime); + + otherFrame.setEndTime(-1); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), qint64(-1)); + } + + QVERIFY(!buffer.isNull()); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), startTime); + QCOMPARE(frame.endTime(), qint64(-1)); // Explicitly shared. + } + + QVERIFY(buffer.isNull()); +} + +void tst_QVideoFrame::assign_data() +{ + QTest::addColumn("handleType"); + QTest::addColumn("size"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("fieldType"); + QTest::addColumn("startTime"); + QTest::addColumn("endTime"); + + QTest::newRow("64x64 ARGB32") + << QAbstractVideoBuffer::GLTextureHandle + << QSize(64, 64) + << QVideoFrame::Format_ARGB32 + << QVideoFrame::TopField + << qint64(63641740) + << qint64(63641954); + QTest::newRow("32x256 YUV420P") + << QAbstractVideoBuffer::UserHandle + << QSize(32, 256) + << QVideoFrame::Format_YUV420P + << QVideoFrame::InterlacedFrame + << qint64(12345) + << qint64(12389); +} + +void tst_QVideoFrame::assign() +{ + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(QSize, size); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QVideoFrame::FieldType, fieldType); + QFETCH(qint64, startTime); + QFETCH(qint64, endTime); + + QPointer buffer = new QtTestVideoBuffer(handleType); + + QVideoFrame frame; + { + QVideoFrame otherFrame(buffer, size, pixelFormat); + otherFrame.setFieldType(fieldType); + otherFrame.setStartTime(startTime); + otherFrame.setEndTime(endTime); + + frame = otherFrame; + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), startTime); + QCOMPARE(otherFrame.endTime(), endTime); + + otherFrame.setStartTime(-1); + + QVERIFY(!buffer.isNull()); + + QVERIFY(otherFrame.isValid()); + QCOMPARE(otherFrame.handleType(), handleType); + QCOMPARE(otherFrame.pixelFormat(), pixelFormat); + QCOMPARE(otherFrame.size(), size); + QCOMPARE(otherFrame.width(), size.width()); + QCOMPARE(otherFrame.height(), size.height()); + QCOMPARE(otherFrame.fieldType(), fieldType); + QCOMPARE(otherFrame.startTime(), qint64(-1)); + QCOMPARE(otherFrame.endTime(), endTime); + } + + QVERIFY(!buffer.isNull()); + + QVERIFY(frame.isValid()); + QCOMPARE(frame.handleType(), handleType); + QCOMPARE(frame.pixelFormat(), pixelFormat); + QCOMPARE(frame.size(), size); + QCOMPARE(frame.width(), size.width()); + QCOMPARE(frame.height(), size.height()); + QCOMPARE(frame.fieldType(), fieldType); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), endTime); + + frame = QVideoFrame(); + + QVERIFY(buffer.isNull()); + + QVERIFY(!frame.isValid()); + QCOMPARE(frame.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(frame.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(frame.size(), QSize()); + QCOMPARE(frame.width(), -1); + QCOMPARE(frame.height(), -1); + QCOMPARE(frame.fieldType(), QVideoFrame::ProgressiveFrame); + QCOMPARE(frame.startTime(), qint64(-1)); + QCOMPARE(frame.endTime(), qint64(-1)); +} + +void tst_QVideoFrame::map_data() +{ + QTest::addColumn("size"); + QTest::addColumn("mappedBytes"); + QTest::addColumn("bytesPerLine"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("mode"); + + QTest::newRow("read-only") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::ReadOnly; + + QTest::newRow("write-only") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::WriteOnly; + + QTest::newRow("read-write") + << QSize(64, 64) + << 16384 + << 256 + << QVideoFrame::Format_ARGB32 + << QAbstractVideoBuffer::ReadWrite; +} + +void tst_QVideoFrame::map() +{ + QFETCH(QSize, size); + QFETCH(int, mappedBytes); + QFETCH(int, bytesPerLine); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QAbstractVideoBuffer::MapMode, mode); + + QVideoFrame frame(mappedBytes, size, bytesPerLine, pixelFormat); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.mappedBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + + QVERIFY(frame.map(mode)); + + // Mapping twice should fail, but leave it mapped (and the mode is ignored) + QVERIFY(!frame.map(mode)); + + QVERIFY(frame.bits()); + QCOMPARE(frame.mappedBytes(), mappedBytes); + QCOMPARE(frame.bytesPerLine(), bytesPerLine); + QCOMPARE(frame.mapMode(), mode); + + frame.unmap(); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.mappedBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); +} + +void tst_QVideoFrame::mapImage_data() +{ + QTest::addColumn("size"); + QTest::addColumn("format"); + QTest::addColumn("mode"); + + QTest::newRow("read-only") + << QSize(64, 64) + << QImage::Format_ARGB32 + << QAbstractVideoBuffer::ReadOnly; + + QTest::newRow("write-only") + << QSize(15, 106) + << QImage::Format_RGB32 + << QAbstractVideoBuffer::WriteOnly; + + QTest::newRow("read-write") + << QSize(23, 111) + << QImage::Format_RGB16 + << QAbstractVideoBuffer::ReadWrite; +} + +void tst_QVideoFrame::mapImage() +{ + QFETCH(QSize, size); + QFETCH(QImage::Format, format); + QFETCH(QAbstractVideoBuffer::MapMode, mode); + + QImage image(size.width(), size.height(), format); + + QVideoFrame frame(image); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.mappedBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); + + QVERIFY(frame.map(mode)); + + QVERIFY(frame.bits()); + QCOMPARE(frame.mappedBytes(), image.byteCount()); + QCOMPARE(frame.bytesPerLine(), image.bytesPerLine()); + QCOMPARE(frame.mapMode(), mode); + + frame.unmap(); + + QVERIFY(!frame.bits()); + QCOMPARE(frame.mappedBytes(), 0); + QCOMPARE(frame.bytesPerLine(), 0); + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); +} + +void tst_QVideoFrame::imageDetach() +{ + const uint red = qRgb(255, 0, 0); + const uint blue = qRgb(0, 0, 255); + + QImage image(8, 8, QImage::Format_RGB32); + + image.fill(red); + QCOMPARE(image.pixel(4, 4), red); + + QVideoFrame frame(image); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + + QImage frameImage(frame.bits(), 8, 8, frame.bytesPerLine(), QImage::Format_RGB32); + + QCOMPARE(frameImage.pixel(4, 4), red); + + frameImage.fill(blue); + QCOMPARE(frameImage.pixel(4, 4), blue); + + // Original image has detached and is therefore unchanged. + QCOMPARE(image.pixel(4, 4), red); +} + +void tst_QVideoFrame::formatConversion_data() +{ + QTest::addColumn("imageFormat"); + QTest::addColumn("pixelFormat"); + + QTest::newRow("QImage::Format_RGB32 | QVideoFrame::Format_RGB32") + << QImage::Format_RGB32 + << QVideoFrame::Format_RGB32; + QTest::newRow("QImage::Format_ARGB32 | QVideoFrame::Format_ARGB32") + << QImage::Format_ARGB32 + << QVideoFrame::Format_ARGB32; + QTest::newRow("QImage::Format_ARGB32_Premultiplied | QVideoFrame::Format_ARGB32_Premultiplied") + << QImage::Format_ARGB32_Premultiplied + << QVideoFrame::Format_ARGB32_Premultiplied; + QTest::newRow("QImage::Format_RGB16 | QVideoFrame::Format_RGB565") + << QImage::Format_RGB16 + << QVideoFrame::Format_RGB565; + QTest::newRow("QImage::Format_ARGB8565_Premultiplied | QVideoFrame::Format_ARGB8565_Premultiplied") + << QImage::Format_ARGB8565_Premultiplied + << QVideoFrame::Format_ARGB8565_Premultiplied; + QTest::newRow("QImage::Format_RGB555 | QVideoFrame::Format_RGB555") + << QImage::Format_RGB555 + << QVideoFrame::Format_RGB555; + QTest::newRow("QImage::Format_RGB888 | QVideoFrame::Format_RGB24") + << QImage::Format_RGB888 + << QVideoFrame::Format_RGB24; + + QTest::newRow("QImage::Format_MonoLSB") + << QImage::Format_MonoLSB + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_Indexed8") + << QImage::Format_Indexed8 + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_ARGB6666_Premultiplied") + << QImage::Format_ARGB6666_Premultiplied + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_ARGB8555_Premultiplied") + << QImage::Format_ARGB8555_Premultiplied + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_RGB666") + << QImage::Format_RGB666 + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_RGB444") + << QImage::Format_RGB444 + << QVideoFrame::Format_Invalid; + QTest::newRow("QImage::Format_ARGB4444_Premultiplied") + << QImage::Format_ARGB4444_Premultiplied + << QVideoFrame::Format_Invalid; + + QTest::newRow("QVideoFrame::Format_BGRA32") + << QImage::Format_Invalid + << QVideoFrame::Format_BGRA32; + QTest::newRow("QVideoFrame::Format_BGRA32_Premultiplied") + << QImage::Format_Invalid + << QVideoFrame::Format_BGRA32_Premultiplied; + QTest::newRow("QVideoFrame::Format_BGR32") + << QImage::Format_Invalid + << QVideoFrame::Format_BGR32; + QTest::newRow("QVideoFrame::Format_BGR24") + << QImage::Format_Invalid + << QVideoFrame::Format_BGR24; + QTest::newRow("QVideoFrame::Format_BGR565") + << QImage::Format_Invalid + << QVideoFrame::Format_BGR565; + QTest::newRow("QVideoFrame::Format_BGR555") + << QImage::Format_Invalid + << QVideoFrame::Format_BGR555; + QTest::newRow("QVideoFrame::Format_BGRA5658_Premultiplied") + << QImage::Format_Invalid + << QVideoFrame::Format_BGRA5658_Premultiplied; + QTest::newRow("QVideoFrame::Format_AYUV444") + << QImage::Format_Invalid + << QVideoFrame::Format_AYUV444; + QTest::newRow("QVideoFrame::Format_AYUV444_Premultiplied") + << QImage::Format_Invalid + << QVideoFrame::Format_AYUV444_Premultiplied; + QTest::newRow("QVideoFrame::Format_YUV444") + << QImage::Format_Invalid + << QVideoFrame::Format_YUV444; + QTest::newRow("QVideoFrame::Format_YUV420P") + << QImage::Format_Invalid + << QVideoFrame::Format_YUV420P; + QTest::newRow("QVideoFrame::Format_YV12") + << QImage::Format_Invalid + << QVideoFrame::Format_YV12; + QTest::newRow("QVideoFrame::Format_UYVY") + << QImage::Format_Invalid + << QVideoFrame::Format_UYVY; + QTest::newRow("QVideoFrame::Format_YUYV") + << QImage::Format_Invalid + << QVideoFrame::Format_YUYV; + QTest::newRow("QVideoFrame::Format_NV12") + << QImage::Format_Invalid + << QVideoFrame::Format_NV12; + QTest::newRow("QVideoFrame::Format_NV21") + << QImage::Format_Invalid + << QVideoFrame::Format_NV21; + QTest::newRow("QVideoFrame::Format_IMC1") + << QImage::Format_Invalid + << QVideoFrame::Format_IMC1; + QTest::newRow("QVideoFrame::Format_IMC2") + << QImage::Format_Invalid + << QVideoFrame::Format_IMC2; + QTest::newRow("QVideoFrame::Format_IMC3") + << QImage::Format_Invalid + << QVideoFrame::Format_IMC3; + QTest::newRow("QVideoFrame::Format_IMC4") + << QImage::Format_Invalid + << QVideoFrame::Format_IMC4; + QTest::newRow("QVideoFrame::Format_Y8") + << QImage::Format_Invalid + << QVideoFrame::Format_Y8; + QTest::newRow("QVideoFrame::Format_Y16") + << QImage::Format_Invalid + << QVideoFrame::Format_Y16; + QTest::newRow("QVideoFrame::Format_Jpeg") + << QImage::Format_Invalid + << QVideoFrame::Format_Jpeg; + QTest::newRow("QVideoFrame::Format_CameraRaw") + << QImage::Format_Invalid + << QVideoFrame::Format_CameraRaw; + QTest::newRow("QVideoFrame::Format_AdobeDng") + << QImage::Format_Invalid + << QVideoFrame::Format_AdobeDng; + QTest::newRow("QVideoFrame::Format_User") + << QImage::Format_Invalid + << QVideoFrame::Format_User; + QTest::newRow("QVideoFrame::Format_User + 1") + << QImage::Format_Invalid + << QVideoFrame::PixelFormat(QVideoFrame::Format_User + 1); +} + +void tst_QVideoFrame::formatConversion() +{ + QFETCH(QImage::Format, imageFormat); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + + QCOMPARE(QVideoFrame::pixelFormatFromImageFormat(imageFormat) == pixelFormat, + imageFormat != QImage::Format_Invalid); + + QCOMPARE(QVideoFrame::imageFormatFromPixelFormat(pixelFormat) == imageFormat, + pixelFormat != QVideoFrame::Format_Invalid); +} + +#define TEST_MAPPED(frame, mode) \ +do { \ + QVERIFY(frame.bits()); \ + QVERIFY(frame.isMapped()); \ + QCOMPARE(frame.mappedBytes(), 16384); \ + QCOMPARE(frame.bytesPerLine(), 256); \ + QCOMPARE(frame.mapMode(), mode); \ +} while (0) + +#define TEST_UNMAPPED(frame) \ +do { \ + QVERIFY(!frame.bits()); \ + QVERIFY(!frame.isMapped()); \ + QCOMPARE(frame.mappedBytes(), 0); \ + QCOMPARE(frame.bytesPerLine(), 0); \ + QCOMPARE(frame.mapMode(), QAbstractVideoBuffer::NotMapped); \ +} while (0) + +void tst_QVideoFrame::isMapped() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + const QVideoFrame& constFrame(frame); + + TEST_UNMAPPED(frame); + TEST_UNMAPPED(constFrame); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + TEST_MAPPED(frame, QAbstractVideoBuffer::ReadOnly); + TEST_MAPPED(constFrame, QAbstractVideoBuffer::ReadOnly); + frame.unmap(); + TEST_UNMAPPED(frame); + TEST_UNMAPPED(constFrame); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + TEST_MAPPED(frame, QAbstractVideoBuffer::WriteOnly); + TEST_MAPPED(constFrame, QAbstractVideoBuffer::WriteOnly); + frame.unmap(); + TEST_UNMAPPED(frame); + TEST_UNMAPPED(constFrame); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + TEST_MAPPED(frame, QAbstractVideoBuffer::ReadWrite); + TEST_MAPPED(constFrame, QAbstractVideoBuffer::ReadWrite); + frame.unmap(); + TEST_UNMAPPED(frame); + TEST_UNMAPPED(constFrame); +} + +void tst_QVideoFrame::isReadable() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + + QVERIFY(!frame.isMapped()); + QVERIFY(!frame.isReadable()); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isReadable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(!frame.isReadable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isReadable()); + frame.unmap(); +} + +void tst_QVideoFrame::isWritable() +{ + QVideoFrame frame(16384, QSize(64, 64), 256, QVideoFrame::Format_ARGB32); + + QVERIFY(!frame.isMapped()); + QVERIFY(!frame.isWritable()); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(!frame.isWritable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::WriteOnly)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isWritable()); + frame.unmap(); + + QVERIFY(frame.map(QAbstractVideoBuffer::ReadWrite)); + QVERIFY(frame.isMapped()); + QVERIFY(frame.isWritable()); + frame.unmap(); +} + +void tst_QVideoFrame::debugType_data() +{ + QTest::addColumn("fieldType"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(ProgressiveFrame); + ADD_ENUM_TEST(InterlacedFrame); + ADD_ENUM_TEST(TopField); + ADD_ENUM_TEST(BottomField); +} + +void tst_QVideoFrame::debugType() +{ + QFETCH(QVideoFrame::FieldType, fieldType); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << fieldType; +} + +void tst_QVideoFrame::debug_data() +{ + QTest::addColumn("frame"); + QTest::addColumn("stringized"); + + QVideoFrame f; + QTest::newRow("default") << f << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, [no timestamp])"); + + QVideoFrame f2; + f2.setStartTime(12345); + f2.setEndTime(8000000000LL); + QTest::newRow("times") << f2 << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, 0:00:00.12345 - 2:13:20.00)"); + + QVideoFrame f3; + f3.setFieldType(QVideoFrame::ProgressiveFrame); + QTest::newRow("times prog") << f3 << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, [no timestamp])"); + + QVideoFrame f4; + f4.setFieldType(QVideoFrame::TopField); + QTest::newRow("times top") << f4 << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, [no timestamp])"); + + QVideoFrame f5; + f5.setFieldType(QVideoFrame::TopField); + f5.setEndTime(90000000000LL); + QTest::newRow("end but no start") << f5 << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, [no timestamp])"); + + QVideoFrame f6; + f6.setStartTime(12345000000LL); + f6.setEndTime(80000000000LL); + QTest::newRow("times big") << f6 << QString::fromLatin1("QVideoFrame( QSize(-1, -1) , Format_Invalid, NoHandle, NotMapped, 3:25:45.00 - 22:13:20.00)"); + + QVideoFrame g(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + QTest::newRow("more valid") << g << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, [no timestamp])"); + + QVideoFrame g2(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + g2.setStartTime(9000000000LL); + g2.setEndTime(9000000000LL); + QTest::newRow("more valid") << g2 << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, @2:30:00.00)"); + + QVideoFrame g3(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + g3.setStartTime(900000LL); + g3.setEndTime(900000LL); + QTest::newRow("more valid single timestamp") << g3 << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, @00:00.900000)"); + + QVideoFrame g4(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + g4.setStartTime(200000000LL); + g4.setEndTime(300000000LL); + QTest::newRow("more valid") << g4 << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, 03:20.00 - 05:00.00)"); + + QVideoFrame g5(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + g5.setStartTime(200000000LL); + QTest::newRow("more valid until forever") << g5 << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, 03:20.00 - forever)"); + + QVideoFrame g6(0, QSize(320,240), 640, QVideoFrame::Format_ARGB32); + g6.setStartTime(9000000000LL); + QTest::newRow("more valid for long forever") << g6 << QString::fromLatin1("QVideoFrame( QSize(320, 240) , Format_ARGB32, NoHandle, NotMapped, 2:30:00.00 - forever)"); +} + +void tst_QVideoFrame::debug() +{ + QFETCH(QVideoFrame, frame); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << frame; +} + +void tst_QVideoFrame::debugFormat_data() +{ + QTest::addColumn("format"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(Format_Invalid); + ADD_ENUM_TEST(Format_ARGB32); + ADD_ENUM_TEST(Format_ARGB32_Premultiplied); + ADD_ENUM_TEST(Format_RGB32); + ADD_ENUM_TEST(Format_RGB24); + ADD_ENUM_TEST(Format_RGB565); + ADD_ENUM_TEST(Format_RGB555); + ADD_ENUM_TEST(Format_ARGB8565_Premultiplied); + ADD_ENUM_TEST(Format_BGRA32); + ADD_ENUM_TEST(Format_BGRA32_Premultiplied); + ADD_ENUM_TEST(Format_BGR32); + ADD_ENUM_TEST(Format_BGR24); + ADD_ENUM_TEST(Format_BGR565); + ADD_ENUM_TEST(Format_BGR555); + ADD_ENUM_TEST(Format_BGRA5658_Premultiplied); + + ADD_ENUM_TEST(Format_AYUV444); + ADD_ENUM_TEST(Format_AYUV444_Premultiplied); + ADD_ENUM_TEST(Format_YUV444); + ADD_ENUM_TEST(Format_YUV420P); + ADD_ENUM_TEST(Format_YV12); + ADD_ENUM_TEST(Format_UYVY); + ADD_ENUM_TEST(Format_YUYV); + ADD_ENUM_TEST(Format_NV12); + ADD_ENUM_TEST(Format_NV21); + ADD_ENUM_TEST(Format_IMC1); + ADD_ENUM_TEST(Format_IMC2); + ADD_ENUM_TEST(Format_IMC3); + ADD_ENUM_TEST(Format_IMC4); + ADD_ENUM_TEST(Format_Y8); + ADD_ENUM_TEST(Format_Y16); + + ADD_ENUM_TEST(Format_Jpeg); + + ADD_ENUM_TEST(Format_CameraRaw); + ADD_ENUM_TEST(Format_AdobeDng); + + // User enums are formatted differently + QTest::newRow("user 1000") << QVideoFrame::Format_User << QString::fromLatin1("UserType(1000)"); + QTest::newRow("user 1005") << QVideoFrame::PixelFormat(QVideoFrame::Format_User + 5) << QString::fromLatin1("UserType(1005)"); +} + +void tst_QVideoFrame::debugFormat() +{ + QFETCH(QVideoFrame::PixelFormat, format); + QFETCH(QString, stringized); + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << format; +} + +QTEST_MAIN(tst_QVideoFrame) + +#include "tst_qvideoframe.moc" diff --git a/tests/auto/unit/qvideosurfaceformat/qvideosurfaceformat.pro b/tests/auto/unit/qvideosurfaceformat/qvideosurfaceformat.pro new file mode 100644 index 000000000..a0e6266b4 --- /dev/null +++ b/tests/auto/unit/qvideosurfaceformat/qvideosurfaceformat.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +TARGET = tst_qvideosurfaceformat + +QT += core multimedia-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qvideosurfaceformat.cpp + diff --git a/tests/auto/unit/qvideosurfaceformat/tst_qvideosurfaceformat.cpp b/tests/auto/unit/qvideosurfaceformat/tst_qvideosurfaceformat.cpp new file mode 100644 index 000000000..85cc81dcd --- /dev/null +++ b/tests/auto/unit/qvideosurfaceformat/tst_qvideosurfaceformat.cpp @@ -0,0 +1,1031 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include + +#include + +// Adds an enum, and the stringized version +#define ADD_ENUM_TEST(x) \ + QTest::newRow(#x) \ + << QVideoSurfaceFormat::x \ + << QString(QLatin1String(#x)); + +class tst_QVideoSurfaceFormat : public QObject +{ + Q_OBJECT +public: + tst_QVideoSurfaceFormat(); + ~tst_QVideoSurfaceFormat(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void constructNull(); + void construct_data(); + void construct(); + void frameSize_data(); + void frameSize(); + void viewport_data(); + void viewport(); + void scanLineDirection_data(); + void scanLineDirection(); + void frameRate_data(); + void frameRate(); + void pixelAspectRatio_data(); + void pixelAspectRatio(); + void sizeHint_data(); + void sizeHint(); + void yCbCrColorSpaceEnum_data(); + void yCbCrColorSpaceEnum (); + void staticPropertyNames(); + void dynamicProperty(); + void compare(); + void copy(); + void assign(); + + void isValid(); + void copyAllParameters (); + void assignAllParameters (); + + void propertyEdgeCases(); + void debugOperator(); + void debugOperator_data(); +}; + +tst_QVideoSurfaceFormat::tst_QVideoSurfaceFormat() +{ +} + +tst_QVideoSurfaceFormat::~tst_QVideoSurfaceFormat() +{ +} + +void tst_QVideoSurfaceFormat::initTestCase() +{ +} + +void tst_QVideoSurfaceFormat::cleanupTestCase() +{ +} + +void tst_QVideoSurfaceFormat::init() +{ +} + +void tst_QVideoSurfaceFormat::cleanup() +{ +} + +void tst_QVideoSurfaceFormat::constructNull() +{ + QVideoSurfaceFormat format; + + QVERIFY(!format.isValid()); + QCOMPARE(format.handleType(), QAbstractVideoBuffer::NoHandle); + QCOMPARE(format.pixelFormat(), QVideoFrame::Format_Invalid); + QCOMPARE(format.frameSize(), QSize()); + QCOMPARE(format.frameWidth(), -1); + QCOMPARE(format.frameHeight(), -1); + QCOMPARE(format.viewport(), QRect()); + QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + QCOMPARE(format.frameRate(), 0.0); + QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); + QCOMPARE(format.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); +} + +void tst_QVideoSurfaceFormat::construct_data() +{ + QTest::addColumn("frameSize"); + QTest::addColumn("pixelFormat"); + QTest::addColumn("handleType"); + QTest::addColumn("valid"); + + QTest::newRow("32x32 rgb32 no handle") + << QSize(32, 32) + << QVideoFrame::Format_RGB32 + << QAbstractVideoBuffer::NoHandle + << true; + + QTest::newRow("1024x768 YUV444 GL texture") + << QSize(32, 32) + << QVideoFrame::Format_YUV444 + << QAbstractVideoBuffer::GLTextureHandle + << true; + + QTest::newRow("32x32 invalid no handle") + << QSize(32, 32) + << QVideoFrame::Format_Invalid + << QAbstractVideoBuffer::NoHandle + << false; + + QTest::newRow("invalid size, rgb32 no handle") + << QSize() + << QVideoFrame::Format_RGB32 + << QAbstractVideoBuffer::NoHandle + << false; + + QTest::newRow("0x0 rgb32 no handle") + << QSize(0,0) + << QVideoFrame::Format_RGB32 + << QAbstractVideoBuffer::NoHandle + << true; +} + +void tst_QVideoSurfaceFormat::construct() +{ + QFETCH(QSize, frameSize); + QFETCH(QVideoFrame::PixelFormat, pixelFormat); + QFETCH(QAbstractVideoBuffer::HandleType, handleType); + QFETCH(bool, valid); + + QRect viewport(QPoint(0, 0), frameSize); + + QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); + + QCOMPARE(format.handleType(), handleType); + QCOMPARE(format.property("handleType").value(), handleType); + QCOMPARE(format.pixelFormat(), pixelFormat); + QCOMPARE(format.property("pixelFormat").value(), pixelFormat); + QCOMPARE(format.frameSize(), frameSize); + QCOMPARE(format.frameWidth(), frameSize.width()); + QCOMPARE(format.property("frameWidth").toInt(), frameSize.width()); + QCOMPARE(format.frameHeight(), frameSize.height()); + QCOMPARE(format.property("frameHeight").toInt(), frameSize.height()); + QCOMPARE(format.isValid(), valid); + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + QCOMPARE(format.frameRate(), 0.0); + QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); + QCOMPARE(format.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); +} + +void tst_QVideoSurfaceFormat::frameSize_data() +{ + QTest::addColumn("initialSize"); + QTest::addColumn("newSize"); + + QTest::newRow("grow") + << QSize(64, 64) + << QSize(1024, 1024); + QTest::newRow("shrink") + << QSize(1024, 1024) + << QSize(64, 64); + QTest::newRow("unchanged") + << QSize(512, 512) + << QSize(512, 512); +} + +void tst_QVideoSurfaceFormat::frameSize() +{ + QFETCH(QSize, initialSize); + QFETCH(QSize, newSize); + + { + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setFrameSize(newSize); + + QCOMPARE(format.frameSize(), newSize); + QCOMPARE(format.property("frameSize").toSize(), newSize); + QCOMPARE(format.frameWidth(), newSize.width()); + QCOMPARE(format.property("frameWidth").toInt(), newSize.width()); + QCOMPARE(format.frameHeight(), newSize.height()); + QCOMPARE(format.property("frameHeight").toInt(), newSize.height()); + } + + { + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setProperty("frameSize", newSize); + + QCOMPARE(format.frameSize(), newSize); + QCOMPARE(format.property("frameSize").toSize(), newSize); + QCOMPARE(format.frameWidth(), newSize.width()); + QCOMPARE(format.property("frameWidth").toInt(), newSize.width()); + QCOMPARE(format.frameHeight(), newSize.height()); + QCOMPARE(format.property("frameHeight").toInt(), newSize.height()); + } + +} + +void tst_QVideoSurfaceFormat::viewport_data() +{ + QTest::addColumn("initialSize"); + QTest::addColumn("viewport"); + QTest::addColumn("newSize"); + QTest::addColumn("expectedViewport"); + + QTest::newRow("grow reset") + << QSize(64, 64) + << QRect(8, 8, 48, 48) + << QSize(1024, 1024) + << QRect(0, 0, 1024, 1024); + QTest::newRow("shrink reset") + << QSize(1024, 1024) + << QRect(8, 8, 1008, 1008) + << QSize(64, 64) + << QRect(0, 0, 64, 64); + QTest::newRow("unchanged reset") + << QSize(512, 512) + << QRect(8, 8, 496, 496) + << QSize(512, 512) + << QRect(0, 0, 512, 512); +} + +void tst_QVideoSurfaceFormat::viewport() +{ + QFETCH(QSize, initialSize); + QFETCH(QRect, viewport); + QFETCH(QSize, newSize); + QFETCH(QRect, expectedViewport); + + { + QRect initialViewport(QPoint(0, 0), initialSize); + + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setViewport(viewport); + + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.property("viewport").toRect(), viewport); + + format.setFrameSize(newSize); + + QCOMPARE(format.viewport(), expectedViewport); + QCOMPARE(format.property("viewport").toRect(), expectedViewport); + } + { + QVideoSurfaceFormat format(initialSize, QVideoFrame::Format_RGB32); + + format.setProperty("viewport", viewport); + + QCOMPARE(format.viewport(), viewport); + QCOMPARE(format.property("viewport").toRect(), viewport); + } +} + +void tst_QVideoSurfaceFormat::scanLineDirection_data() +{ + QTest::addColumn("direction"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(TopToBottom); + ADD_ENUM_TEST(BottomToTop); +} + +void tst_QVideoSurfaceFormat::scanLineDirection() +{ + QFETCH(QVideoSurfaceFormat::Direction, direction); + QFETCH(QString, stringized); + + { + QVideoSurfaceFormat format(QSize(16, 16), QVideoFrame::Format_RGB32); + + format.setScanLineDirection(direction); + + QCOMPARE(format.scanLineDirection(), direction); + QCOMPARE( + qvariant_cast(format.property("scanLineDirection")), + direction); + } + { + QVideoSurfaceFormat format(QSize(16, 16), QVideoFrame::Format_RGB32); + + format.setProperty("scanLineDirection", qVariantFromValue(direction)); + + QCOMPARE(format.scanLineDirection(), direction); + QCOMPARE( + qvariant_cast(format.property("scanLineDirection")), + direction); + } + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << direction; +} + +void tst_QVideoSurfaceFormat::yCbCrColorSpaceEnum_data() +{ + QTest::addColumn("colorspace"); + QTest::addColumn("stringized"); + + ADD_ENUM_TEST(YCbCr_BT601); + ADD_ENUM_TEST(YCbCr_BT709); + ADD_ENUM_TEST(YCbCr_xvYCC601); + ADD_ENUM_TEST(YCbCr_xvYCC709); + ADD_ENUM_TEST(YCbCr_JPEG); + ADD_ENUM_TEST(YCbCr_CustomMatrix); + ADD_ENUM_TEST(YCbCr_Undefined); +} + +/* Test case for Enum YCbCr_BT601, YCbCr_xvYCC709 */ +void tst_QVideoSurfaceFormat::yCbCrColorSpaceEnum() +{ + QFETCH(QVideoSurfaceFormat::YCbCrColorSpace, colorspace); + QFETCH(QString, stringized); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setYCbCrColorSpace(colorspace); + + QCOMPARE(format.yCbCrColorSpace(), colorspace); + QCOMPARE(qvariant_cast(format.property("yCbCrColorSpace")), + colorspace); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("yCbCrColorSpace", qVariantFromValue(colorspace)); + + QCOMPARE(format.yCbCrColorSpace(), colorspace); + QCOMPARE(qvariant_cast(format.property("yCbCrColorSpace")), + colorspace); + } + + QTest::ignoreMessage(QtDebugMsg, stringized.toLatin1().constData()); + qDebug() << colorspace; +} + + +void tst_QVideoSurfaceFormat::frameRate_data() +{ + QTest::addColumn("frameRate"); + + QTest::newRow("null") + << qreal(0.0); + QTest::newRow("1/1") + << qreal(1.0); + QTest::newRow("24/1") + << qreal(24.0); + QTest::newRow("15/2") + << qreal(7.5); +} + +void tst_QVideoSurfaceFormat::frameRate() +{ + QFETCH(qreal, frameRate); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE(qvariant_cast(format.property("frameRate")), frameRate); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + format.setFrameRate(frameRate); + format.setProperty("frameRate", frameRate); + + QCOMPARE(format.frameRate(), frameRate); + QCOMPARE(qvariant_cast(format.property("frameRate")), frameRate); + } +} + +void tst_QVideoSurfaceFormat::pixelAspectRatio_data() +{ + QTest::addColumn("aspectRatio"); + + QTest::newRow("1:1") + << QSize(1, 1); + QTest::newRow("4:3") + << QSize(4, 3); + QTest::newRow("16:9") + << QSize(16, 9); +} + +void tst_QVideoSurfaceFormat::pixelAspectRatio() +{ + QFETCH(QSize, aspectRatio); + + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setPixelAspectRatio(aspectRatio); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setPixelAspectRatio(aspectRatio.width(), aspectRatio.height()); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } + { + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + format.setProperty("pixelAspectRatio", aspectRatio); + + QCOMPARE(format.pixelAspectRatio(), aspectRatio); + QCOMPARE(format.property("pixelAspectRatio").toSize(), aspectRatio); + } +} + +void tst_QVideoSurfaceFormat::sizeHint_data() +{ + QTest::addColumn("frameSize"); + QTest::addColumn("viewport"); + QTest::addColumn("aspectRatio"); + QTest::addColumn("sizeHint"); + + QTest::newRow("(0, 0, 1024x768), 1:1") + << QSize(1024, 768) + << QRect(0, 0, 1024, 768) + << QSize(1, 1) + << QSize(1024, 768); + QTest::newRow("0, 0, 1024x768), 4:3") + << QSize(1024, 768) + << QRect(0, 0, 1024, 768) + << QSize(4, 3) + << QSize(1365, 768); + QTest::newRow("(168, 84, 800x600), 1:1") + << QSize(1024, 768) + << QRect(168, 84, 800, 600) + << QSize(1, 1) + << QSize(800, 600); + QTest::newRow("(168, 84, 800x600), 4:3") + << QSize(1024, 768) + << QRect(168, 84, 800, 600) + << QSize(4, 3) + << QSize(1066, 600); + QTest::newRow("(168, 84, 800x600), 4:0") + << QSize(1024, 768) + << QRect(168, 84, 800, 600) + << QSize(4, 0) + << QSize(800, 600); +} + +void tst_QVideoSurfaceFormat::sizeHint() +{ + QFETCH(QSize, frameSize); + QFETCH(QRect, viewport); + QFETCH(QSize, aspectRatio); + QFETCH(QSize, sizeHint); + + QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_RGB32); + format.setViewport(viewport); + format.setPixelAspectRatio(aspectRatio); + + QCOMPARE(format.sizeHint(), sizeHint); + QCOMPARE(format.property("sizeHint").toSize(), sizeHint); +} + +void tst_QVideoSurfaceFormat::staticPropertyNames() +{ + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QList propertyNames = format.propertyNames(); + + QVERIFY(propertyNames.contains("handleType")); + QVERIFY(propertyNames.contains("pixelFormat")); + QVERIFY(propertyNames.contains("frameSize")); + QVERIFY(propertyNames.contains("frameWidth")); + QVERIFY(propertyNames.contains("viewport")); + QVERIFY(propertyNames.contains("scanLineDirection")); + QVERIFY(propertyNames.contains("frameRate")); + QVERIFY(propertyNames.contains("pixelAspectRatio")); + QVERIFY(propertyNames.contains("yCbCrColorSpace")); + QVERIFY(propertyNames.contains("sizeHint")); + QCOMPARE(propertyNames.count(), 10); +} + +void tst_QVideoSurfaceFormat::dynamicProperty() +{ + QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); + + QCOMPARE(format.property("integer"), QVariant()); + QCOMPARE(format.property("size"), QVariant()); + QCOMPARE(format.property("string"), QVariant()); + QCOMPARE(format.property("null"), QVariant()); + + QList propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 0); + QCOMPARE(propertyNames.count(QByteArray("string")), 0); + QCOMPARE(propertyNames.count(QByteArray("size")), 0); + QCOMPARE(propertyNames.count(QByteArray("null")), 0); + + format.setProperty("string", QString::fromLatin1("Hello")); + format.setProperty("integer", 198); + format.setProperty("size", QSize(43, 65)); + + QCOMPARE(format.property("integer").toInt(), 198); + QCOMPARE(format.property("size").toSize(), QSize(43, 65)); + QCOMPARE(format.property("string").toString(), QString::fromLatin1("Hello")); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 1); + QCOMPARE(propertyNames.count(QByteArray("size")), 1); + + format.setProperty("integer", 125423); + format.setProperty("size", QSize(1, 986)); + + QCOMPARE(format.property("integer").toInt(), 125423); + QCOMPARE(format.property("size").toSize(), QSize(1, 986)); + QCOMPARE(format.property("string").toString(), QString::fromLatin1("Hello")); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 1); + QCOMPARE(propertyNames.count(QByteArray("size")), 1); + + format.setProperty("string", QVariant()); + format.setProperty("size", QVariant()); + format.setProperty("null", QVariant()); + + QCOMPARE(format.property("integer").toInt(), 125423); + QCOMPARE(format.property("size"), QVariant()); + QCOMPARE(format.property("string"), QVariant()); + QCOMPARE(format.property("null"), QVariant()); + + propertyNames = format.propertyNames(); + + QCOMPARE(propertyNames.count(QByteArray("integer")), 1); + QCOMPARE(propertyNames.count(QByteArray("string")), 0); + QCOMPARE(propertyNames.count(QByteArray("size")), 0); + QCOMPARE(propertyNames.count(QByteArray("null")), 0); +} + +void tst_QVideoSurfaceFormat::compare() +{ + QVideoSurfaceFormat format1( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format2( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format3( + QSize(32, 32), QVideoFrame::Format_YUV444, QAbstractVideoBuffer::GLTextureHandle); + QVideoSurfaceFormat format4( + QSize(16, 16), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::UserHandle); + + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + QCOMPARE(format1 == format3, false); + QCOMPARE(format1 != format3, true); + QCOMPARE(format1 == format4, false); + QCOMPARE(format1 != format4, true); + + format2.setFrameSize(1024, 768); + + // Not equal, frame size differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setFrameSize(1024, 768); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setViewport(QRect(0, 0, 800, 600)); + format2.setViewport(QRect(112, 84, 800, 600)); + + // Not equal, viewports differ. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setViewport(QRect(112, 84, 800, 600)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + // Not equal scan line direction differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setFrameRate(7.5); + + // Not equal frame rate differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setFrameRate(qreal(7.50001)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setPixelAspectRatio(4, 3); + + // Not equal pixel aspect ratio differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setPixelAspectRatio(QSize(4, 3)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format2.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); + + // Not equal yuv color space differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format1.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_xvYCC601); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("integer", 12); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("integer", 45); + + // Not equal, integer differs. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("integer", 12); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("string", QString::fromLatin1("Hello")); + format2.setProperty("size", QSize(12, 54)); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); + + format2.setProperty("string", QString::fromLatin1("Hello")); + format1.setProperty("size", QSize(12, 54)); + + // Equal. + QCOMPARE(format1 == format2, true); + QCOMPARE(format1 != format2, false); + + format1.setProperty("string", QVariant()); + + // Not equal, property mismatch. + QCOMPARE(format1 == format2, false); + QCOMPARE(format1 != format2, true); +} + + +void tst_QVideoSurfaceFormat::copy() +{ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + QVideoSurfaceFormat copy(original); + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(original.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); +} + +void tst_QVideoSurfaceFormat::assign() +{ + QVideoSurfaceFormat copy( + QSize(64, 64), QVideoFrame::Format_AYUV444, QAbstractVideoBuffer::UserHandle); + + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + + copy = original; + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); + + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); + + QCOMPARE(original.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + QCOMPARE(original == copy, false); + QCOMPARE(original != copy, true); +} + +/* Test case for api isValid */ +void tst_QVideoSurfaceFormat::isValid() +{ + /* When both pixel format and framesize is not valid */ + QVideoSurfaceFormat format; + QVERIFY(!format.isValid()); + + /* When framesize is valid and pixel format is not valid */ + format.setFrameSize(64,64); + QVERIFY(format.frameSize() == QSize(64,64)); + QVERIFY(!format.pixelFormat()); + QVERIFY(!format.isValid()); + + /* When both the pixel format and framesize is valid. */ + QVideoSurfaceFormat format1(QSize(32, 32), QVideoFrame::Format_AYUV444); + QVERIFY(format1.isValid()); + + /* When pixel format is valid and frame size is not valid */ + format1.setFrameSize(-1,-1); + QVERIFY(!format1.frameSize().isValid()); + QVERIFY(!format1.isValid()); +} + +/* Test case for copy constructor with all the parameters. */ +void tst_QVideoSurfaceFormat::copyAllParameters() +{ + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + original.setViewport(QRect(0, 0, 1024, 1024)); + original.setFrameRate(qreal(15.0)); + original.setPixelAspectRatio(QSize(320,480)); + original.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + + /* Copy the original instance to copy and verify if both the instances + have the same parameters. */ + QVideoSurfaceFormat copy(original); + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + QCOMPARE(copy.viewport(), QRect(0, 0, 1024, 1024)); + QCOMPARE(copy.frameRate(), qreal(15.0)); + QCOMPARE(copy.pixelAspectRatio(), QSize(320,480)); + QCOMPARE(copy.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_BT709); + + /* Verify if both the instances are eqaul */ + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); +} + +/* Test case for copy constructor with all the parameters. */ +void tst_QVideoSurfaceFormat::assignAllParameters() +{ + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat copy( + QSize(64, 64), QVideoFrame::Format_AYUV444, QAbstractVideoBuffer::UserHandle); + copy.setScanLineDirection(QVideoSurfaceFormat::TopToBottom); + copy.setViewport(QRect(0, 0, 640, 320)); + copy.setFrameRate(qreal(7.5)); + copy.setPixelAspectRatio(QSize(640,320)); + copy.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT601); + + /* Create the instance and set all the parameters. */ + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + original.setViewport(QRect(0, 0, 1024, 1024)); + original.setFrameRate(qreal(15.0)); + original.setPixelAspectRatio(QSize(320,480)); + original.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + + /* Assign the original instance to copy and verify if both the instancess + have the same parameters. */ + copy = original; + + QCOMPARE(copy.handleType(), QAbstractVideoBuffer::GLTextureHandle); + QCOMPARE(copy.pixelFormat(), QVideoFrame::Format_ARGB32); + QCOMPARE(copy.frameSize(), QSize(1024, 768)); + QCOMPARE(copy.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + QCOMPARE(copy.viewport(), QRect(0, 0, 1024, 1024)); + QCOMPARE(copy.frameRate(), qreal(15.0)); + QCOMPARE(copy.pixelAspectRatio(), QSize(320,480)); + QCOMPARE(copy.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_BT709); + + /* Verify if both the instances are eqaul */ + QCOMPARE(original == copy, true); + QCOMPARE(original != copy, false); +} + +void tst_QVideoSurfaceFormat::propertyEdgeCases() +{ + // Test setting read only properties doesn't change anything + QVideoSurfaceFormat original( + QSize(1024, 768), QVideoFrame::Format_ARGB32, QAbstractVideoBuffer::GLTextureHandle); + + original.setProperty("handleType", QAbstractVideoBuffer::UserHandle); + QCOMPARE(original.handleType(), QAbstractVideoBuffer::GLTextureHandle); + + original.setProperty("pixelFormat", QVideoFrame::Format_AYUV444); + QCOMPARE(original.pixelFormat(), QVideoFrame::Format_ARGB32); + + original.setProperty("frameWidth", 512); + QCOMPARE(original.frameWidth(), 1024); + + original.setProperty("frameHeight", 77); + QCOMPARE(original.frameHeight(), 768); + + original.setProperty("sizeHint", QSize(512, 384)); + QCOMPARE(original.sizeHint(), QSize(1024,768)); + + // Now test setting some r/w properties with the wrong data type + original.setProperty("frameSize", Qt::red); + QCOMPARE(original.frameSize(), QSize(1024, 768)); + + original.setProperty("viewport", Qt::red); + QCOMPARE(original.viewport(), QRect(0, 0, 1024, 768)); + + original.setScanLineDirection(QVideoSurfaceFormat::BottomToTop); + original.setProperty("scanLineDirection", Qt::red); + QCOMPARE(original.scanLineDirection(), QVideoSurfaceFormat::BottomToTop); + + original.setFrameRate(32); + original.setProperty("frameRate", QSize(32, 43)); + QCOMPARE(original.frameRate(), qreal(32)); + + original.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + original.setProperty("yCbCrColorSpace", QSize(43,43)); + QCOMPARE(original.yCbCrColorSpace(), QVideoSurfaceFormat::YCbCr_BT709); + + original.setPixelAspectRatio(53, 45); + original.setProperty("pixelAspectRatio", Qt::red); + QCOMPARE(original.pixelAspectRatio(), QSize(53, 45)); +} + +#define ADDDEBUGTEST(format, w, h, r) \ + QTest::newRow(#format "-" #w "x" #h "@" #r) \ + << QVideoFrame::Format_ ##format \ + << "Format_" #format \ + << QSize(w, h) \ + << r; + +void tst_QVideoSurfaceFormat::debugOperator_data() +{ + // This is not too exhaustive + QTest::addColumn("format"); + QTest::addColumn("formatString"); + QTest::addColumn("frameSize"); + QTest::addColumn("frameRate"); // could be double, but formatting is unstable + + ADDDEBUGTEST(Invalid, 100, 200, 3); + ADDDEBUGTEST(ARGB32,101, 201, 4); + ADDDEBUGTEST(ARGB32_Premultiplied, 100, 202, 5); + ADDDEBUGTEST(RGB32, 8, 16, 30); + ADDDEBUGTEST(RGB24, 8, 16, 30); + ADDDEBUGTEST(RGB565, 8, 16, 30); + ADDDEBUGTEST(RGB555, 8, 16, 30); + ADDDEBUGTEST(ARGB8565_Premultiplied, 8, 16, 30); + ADDDEBUGTEST(BGRA32, 8, 16, 30); + ADDDEBUGTEST(BGRA32_Premultiplied, 8, 16, 30); + ADDDEBUGTEST(BGR32, 8, 16, 30); + ADDDEBUGTEST(BGR24, 8, 16, 30); + ADDDEBUGTEST(BGR565, 8, 16, 30); + ADDDEBUGTEST(BGR555, 8, 16, 30); + ADDDEBUGTEST(BGRA5658_Premultiplied, 8, 16, 30); + + ADDDEBUGTEST(AYUV444, 8, 16, 30); + ADDDEBUGTEST(AYUV444, 8, 16, 31); + ADDDEBUGTEST(AYUV444_Premultiplied, 8, 16, 30); + ADDDEBUGTEST(YUV444, 8, 16, 30); + ADDDEBUGTEST(YUV420P, 8, 16, 30); + ADDDEBUGTEST(YV12, 8, 16, 30); + ADDDEBUGTEST(UYVY, 8, 16, 30); + ADDDEBUGTEST(YUYV, 8, 16, 30); + ADDDEBUGTEST(NV12, 8, 16, 30); + ADDDEBUGTEST(NV12, 80, 16, 30); + ADDDEBUGTEST(NV21, 8, 16, 30); + ADDDEBUGTEST(IMC1, 8, 16, 30); + ADDDEBUGTEST(IMC2, 8, 16, 30); + ADDDEBUGTEST(IMC3, 8, 16, 30); + ADDDEBUGTEST(IMC3, 8, 160, 30); + ADDDEBUGTEST(IMC4, 8, 16, 30); + ADDDEBUGTEST(Y8, 8, 16, 30); + ADDDEBUGTEST(Y16, 8, 16, 30); + + ADDDEBUGTEST(Jpeg, 8, 16, 30); + + ADDDEBUGTEST(CameraRaw, 8, 16, 30); + ADDDEBUGTEST(AdobeDng, 8, 16, 30); + + // User is special + QTest::newRow("User-0x0@0)") + << QVideoFrame::Format_User + << "UserType(1000)" + << QSize() + << 0; +} + +void tst_QVideoSurfaceFormat::debugOperator() +{ + QFETCH(QVideoFrame::PixelFormat, format); + QFETCH(QString, formatString); + QFETCH(QSize, frameSize); + QFETCH(int, frameRate); + + QString templateOutput = QString("QVideoSurfaceFormat(%1, QSize(%2, %3) , viewport=QRect(0,1 800x600) , pixelAspectRatio=QSize(320, 200) " + ", handleType=GLTextureHandle, yCbCrColorSpace=YCbCr_BT709)\n" + " handleType = QVariant(QAbstractVideoBuffer::HandleType, ) \n" + " pixelFormat = QVariant(QVideoFrame::PixelFormat, ) \n" + " frameSize = QVariant(QSize, QSize(%4, %5) ) \n" + " frameWidth = QVariant(int, %6) \n" + " viewport = QVariant(QRect, QRect(0,1 800x600) ) \n" + " scanLineDirection = QVariant(QVideoSurfaceFormat::Direction, ) \n" +#if defined(QT_ARCH_ARM) // from qglobal.h + " frameRate = QVariant(float, %7) \n" +#else + " frameRate = QVariant(double, %7) \n" +#endif + " pixelAspectRatio = QVariant(QSize, QSize(320, 200) ) \n" + " sizeHint = QVariant(QSize, QSize(1280, 600) ) \n" + " yCbCrColorSpace = QVariant(QVideoSurfaceFormat::YCbCrColorSpace, ) ") + .arg(formatString) + .arg(frameSize.width()) + .arg(frameSize.height()) + .arg(frameSize.width()) + .arg(frameSize.height()) + .arg(frameSize.width()) + .arg(frameRate); + + QVideoSurfaceFormat vsf(frameSize, format, QAbstractVideoBuffer::GLTextureHandle); + vsf.setViewport(QRect(0,1, 800, 600)); + vsf.setPixelAspectRatio(QSize(320, 200)); + vsf.setYCbCrColorSpace(QVideoSurfaceFormat::YCbCr_BT709); + vsf.setFrameRate(frameRate); + + QTest::ignoreMessage(QtDebugMsg, templateOutput.toLatin1().constData()); + qDebug() << vsf; +} + + + +QTEST_MAIN(tst_QVideoSurfaceFormat) + + + +#include "tst_qvideosurfaceformat.moc" diff --git a/tests/auto/unit/qvideowidget/qvideowidget.pro b/tests/auto/unit/qvideowidget/qvideowidget.pro new file mode 100644 index 000000000..d0ea9fa7c --- /dev/null +++ b/tests/auto/unit/qvideowidget/qvideowidget.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qvideowidget + +QT += multimedia-private multimediawidgets-private testlib +CONFIG += no_private_qt_headers_warning + +SOURCES += tst_qvideowidget.cpp + +# QPA seems to break some assumptions +CONFIG += insignificant_test +QT+=widgets diff --git a/tests/auto/unit/qvideowidget/tst_qvideowidget.cpp b/tests/auto/unit/qvideowidget/tst_qvideowidget.cpp new file mode 100644 index 000000000..9f9bafc50 --- /dev/null +++ b/tests/auto/unit/qvideowidget/tst_qvideowidget.cpp @@ -0,0 +1,1567 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include "qvideowidget.h" + +#include "qmediaobject.h" +#include "qmediaservice.h" +#include +#include "qvideowindowcontrol.h" +#include "qvideowidgetcontrol.h" + +#include "qvideorenderercontrol.h" +#include +#include + +#include + +QT_USE_NAMESPACE +class tst_QVideoWidget : public QObject +{ + Q_OBJECT +private slots: + void nullObject(); + void nullService(); + void noOutputs(); + void serviceDestroyed(); + void objectDestroyed(); + void setMediaObject(); + + void showWindowControl(); + void fullScreenWindowControl(); + void aspectRatioWindowControl(); + void sizeHintWindowControl_data() { sizeHint_data(); } + void sizeHintWindowControl(); + void brightnessWindowControl_data() { color_data(); } + void brightnessWindowControl(); + void contrastWindowControl_data() { color_data(); } + void contrastWindowControl(); + void hueWindowControl_data() { color_data(); } + void hueWindowControl(); + void saturationWindowControl_data() { color_data(); } + void saturationWindowControl(); + + void showWidgetControl(); + void fullScreenWidgetControl(); + void aspectRatioWidgetControl(); + void sizeHintWidgetControl_data() { sizeHint_data(); } + void sizeHintWidgetControl(); + void brightnessWidgetControl_data() { color_data(); } + void brightnessWidgetControl(); + void contrastWidgetControl_data() { color_data(); } + void contrastWidgetControl(); + void hueWidgetControl_data() { color_data(); } + void hueWidgetControl(); + void saturationWidgetControl_data() { color_data(); } + void saturationWidgetControl(); + + void showRendererControl(); + void fullScreenRendererControl(); + void aspectRatioRendererControl(); + void sizeHintRendererControl_data(); + void sizeHintRendererControl(); + void brightnessRendererControl_data() { color_data(); } + void brightnessRendererControl(); + void contrastRendererControl_data() { color_data(); } + void contrastRendererControl(); + void hueRendererControl_data() { color_data(); } + void hueRendererControl(); + void saturationRendererControl_data() { color_data(); } + void saturationRendererControl(); + + void paintRendererControl(); + +private: + void sizeHint_data(); + void color_data(); +}; + +Q_DECLARE_METATYPE(Qt::AspectRatioMode) +Q_DECLARE_METATYPE(const uchar *) + +class QtTestWindowControl : public QVideoWindowControl +{ +public: + QtTestWindowControl() + : m_winId(0) + , m_repaintCount(0) + , m_brightness(0) + , m_contrast(0) + , m_saturation(0) + , m_aspectRatioMode(Qt::KeepAspectRatio) + , m_fullScreen(0) + { + } + + WId winId() const { return m_winId; } + void setWinId(WId id) { m_winId = id; } + + QRect displayRect() const { return m_displayRect; } + void setDisplayRect(const QRect &rect) { m_displayRect = rect; } + + bool isFullScreen() const { return m_fullScreen; } + void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); } + + int repaintCount() const { return m_repaintCount; } + void setRepaintCount(int count) { m_repaintCount = count; } + void repaint() { ++m_repaintCount; } + + QSize nativeSize() const { return m_nativeSize; } + void setNativeSize(const QSize &size) { m_nativeSize = size; emit nativeSizeChanged(); } + + Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; } + void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; } + + int brightness() const { return m_brightness; } + void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); } + + int contrast() const { return m_contrast; } + void setContrast(int contrast) { emit contrastChanged(m_contrast = contrast); } + + int hue() const { return m_hue; } + void setHue(int hue) { emit hueChanged(m_hue = hue); } + + int saturation() const { return m_saturation; } + void setSaturation(int saturation) { emit saturationChanged(m_saturation = saturation); } + +private: + WId m_winId; + int m_repaintCount; + int m_brightness; + int m_contrast; + int m_hue; + int m_saturation; + Qt::AspectRatioMode m_aspectRatioMode; + QRect m_displayRect; + QSize m_nativeSize; + bool m_fullScreen; +}; + +class QtTestWidgetControl : public QVideoWidgetControl +{ +public: + QtTestWidgetControl() + : m_brightness(1.0) + , m_contrast(1.0) + , m_hue(1.0) + , m_saturation(1.0) + , m_aspectRatioMode(Qt::KeepAspectRatio) + , m_fullScreen(false) + { + } + + bool isFullScreen() const { return m_fullScreen; } + void setFullScreen(bool fullScreen) { emit fullScreenChanged(m_fullScreen = fullScreen); } + + Qt::AspectRatioMode aspectRatioMode() const { return m_aspectRatioMode; } + void setAspectRatioMode(Qt::AspectRatioMode mode) { m_aspectRatioMode = mode; } + + int brightness() const { return m_brightness; } + void setBrightness(int brightness) { emit brightnessChanged(m_brightness = brightness); } + + int contrast() const { return m_contrast; } + void setContrast(int contrast) { emit contrastChanged(m_contrast = contrast); } + + int hue() const { return m_hue; } + void setHue(int hue) { emit hueChanged(m_hue = hue); } + + int saturation() const { return m_saturation; } + void setSaturation(int saturation) { emit saturationChanged(m_saturation = saturation); } + + void setSizeHint(const QSize &size) { m_widget.setSizeHint(size); } + + QWidget *videoWidget() { return &m_widget; } + +private: + class Widget : public QWidget + { + public: + QSize sizeHint() const { return m_sizeHint; } + void setSizeHint(const QSize &size) { m_sizeHint = size; updateGeometry(); } + private: + QSize m_sizeHint; + } m_widget; + int m_brightness; + int m_contrast; + int m_hue; + int m_saturation; + Qt::AspectRatioMode m_aspectRatioMode; + QSize m_sizeHint; + bool m_fullScreen; +}; + +class QtTestRendererControl : public QVideoRendererControl +{ +public: + QtTestRendererControl() + : m_surface(0) + { + } + + QAbstractVideoSurface *surface() const { return m_surface; } + void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } + +private: + QAbstractVideoSurface *m_surface; +}; + +class QtTestVideoService : public QMediaService +{ + Q_OBJECT +public: + QtTestVideoService( + QtTestWindowControl *window, + QtTestWidgetControl *widget, + QtTestRendererControl *renderer) + : QMediaService(0) + , windowRef(0) + , widgetRef(0) + , rendererRef(0) + , windowControl(window) + , widgetControl(widget) + , rendererControl(renderer) + { + } + + ~QtTestVideoService() + { + delete windowControl; + delete widgetControl; + delete rendererControl; + } + + QMediaControl *requestControl(const char *name) + { + if (qstrcmp(name, QVideoWindowControl_iid) == 0) { + if (windowControl) { + windowRef += 1; + + return windowControl; + } + } else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { + if (widgetControl) { + widgetRef += 1; + + return widgetControl; + } + } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) { + if (rendererControl) { + rendererRef += 1; + + return rendererControl; + } + } + return 0; + } + + void releaseControl(QMediaControl *control) + { + Q_ASSERT(control); + + if (control == windowControl) + windowRef -= 1; + else if (control == widgetControl) + widgetRef -= 1; + else if (control == rendererControl) + rendererRef -= 1; + } + + int windowRef; + int widgetRef; + int rendererRef; + + QtTestWindowControl *windowControl; + QtTestWidgetControl *widgetControl; + QtTestRendererControl *rendererControl; +}; + +class QtTestVideoObject : public QMediaObject +{ + Q_OBJECT +public: + QtTestVideoObject( + QtTestWindowControl *window, + QtTestWidgetControl *widget, + QtTestRendererControl *renderer): + QMediaObject(0, new QtTestVideoService(window, widget, renderer)) + { + testService = qobject_cast(service()); + } + + QtTestVideoObject(QtTestVideoService *service): + QMediaObject(0, service), + testService(service) + { + } + + ~QtTestVideoObject() + { + delete testService; + } + + QtTestVideoService *testService; +}; + +void tst_QVideoWidget::nullObject() +{ + QVideoWidget widget; + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QVERIFY(widget.sizeHint().isEmpty()); + + widget.setFullScreen(true); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), true); + + widget.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); + + { + QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); + + widget.setBrightness(100); + QCOMPARE(widget.brightness(), 100); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), 100); + + widget.setBrightness(100); + QCOMPARE(widget.brightness(), 100); + QCOMPARE(spy.count(), 1); + + widget.setBrightness(-120); + QCOMPARE(widget.brightness(), -100); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), -100); + } { + QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); + + widget.setContrast(100); + QCOMPARE(widget.contrast(), 100); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), 100); + + widget.setContrast(100); + QCOMPARE(widget.contrast(), 100); + QCOMPARE(spy.count(), 1); + + widget.setContrast(-120); + QCOMPARE(widget.contrast(), -100); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), -100); + } { + QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); + + widget.setHue(100); + QCOMPARE(widget.hue(), 100); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), 100); + + widget.setHue(100); + QCOMPARE(widget.hue(), 100); + QCOMPARE(spy.count(), 1); + + widget.setHue(-120); + QCOMPARE(widget.hue(), -100); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), -100); + } { + QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); + + widget.setSaturation(100); + QCOMPARE(widget.saturation(), 100); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), 100); + + widget.setSaturation(100); + QCOMPARE(widget.saturation(), 100); + QCOMPARE(spy.count(), 1); + + widget.setSaturation(-120); + QCOMPARE(widget.saturation(), -100); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), -100); + } +} + +void tst_QVideoWidget::nullService() +{ + QtTestVideoObject object(0); + + QVideoWidget widget; + object.bind(&widget); + + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QVERIFY(widget.sizeHint().isEmpty()); + + widget.setFullScreen(true); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), true); + + widget.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); + + widget.setBrightness(100); + QCOMPARE(widget.brightness(), 100); + + widget.setContrast(100); + QCOMPARE(widget.contrast(), 100); + + widget.setHue(100); + QCOMPARE(widget.hue(), 100); + + widget.setSaturation(100); + QCOMPARE(widget.saturation(), 100); +} + +void tst_QVideoWidget::noOutputs() +{ + QtTestVideoObject object(0, 0, 0); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QVERIFY(widget.sizeHint().isEmpty()); + + widget.setFullScreen(true); + QCOMPARE(widget.isFullScreen(), true); + + widget.setBrightness(100); + QCOMPARE(widget.brightness(), 100); + + widget.setContrast(100); + QCOMPARE(widget.contrast(), 100); + + widget.setHue(100); + QCOMPARE(widget.hue(), 100); + + widget.setSaturation(100); + QCOMPARE(widget.saturation(), 100); +} + +void tst_QVideoWidget::serviceDestroyed() +{ + QtTestVideoObject object(new QtTestWindowControl, new QtTestWidgetControl, 0); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + widget.setBrightness(100); + widget.setContrast(100); + widget.setHue(100); + widget.setSaturation(100); + + delete object.testService; + object.testService = 0; + + QCOMPARE(widget.mediaObject(), static_cast(&object)); + + QCOMPARE(widget.brightness(), 100); + QCOMPARE(widget.contrast(), 100); + QCOMPARE(widget.hue(), 100); + QCOMPARE(widget.saturation(), 100); + + widget.setFullScreen(true); + QCOMPARE(widget.isFullScreen(), true); +} + +void tst_QVideoWidget::objectDestroyed() +{ + QtTestVideoObject *object = new QtTestVideoObject( + new QtTestWindowControl, + new QtTestWidgetControl, + 0); + + QVideoWidget widget; + object->bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QCOMPARE(object->testService->windowRef, 0); + QCOMPARE(object->testService->widgetRef, 1); + QCOMPARE(object->testService->rendererRef, 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + widget.setBrightness(100); + widget.setContrast(100); + widget.setHue(100); + widget.setSaturation(100); + + // Delete the media object without deleting the service. + QtTestVideoService *service = object->testService; + object->testService = 0; + + delete object; + object = 0; + + QCOMPARE(widget.mediaObject(), static_cast(object)); + + QCOMPARE(widget.brightness(), 100); + QCOMPARE(widget.contrast(), 100); + QCOMPARE(widget.hue(), 100); + QCOMPARE(widget.saturation(), 100); + + widget.setFullScreen(true); + QCOMPARE(widget.isFullScreen(), true); + + delete service; +} + +void tst_QVideoWidget::setMediaObject() +{ + QMediaObject *nullObject = 0; + QtTestVideoObject windowObject(new QtTestWindowControl, 0, 0); + QtTestVideoObject widgetObject(0, new QtTestWidgetControl, 0); + QtTestVideoObject rendererObject(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QCOMPARE(widget.mediaObject(), nullObject); + QCOMPARE(windowObject.testService->windowRef, 0); + QCOMPARE(widgetObject.testService->widgetRef, 0); + QCOMPARE(rendererObject.testService->rendererRef, 0); + + windowObject.bind(&widget); + QCOMPARE(widget.mediaObject(), static_cast(&windowObject)); + QCOMPARE(windowObject.testService->windowRef, 1); + QCOMPARE(widgetObject.testService->widgetRef, 0); + QCOMPARE(rendererObject.testService->rendererRef, 0); + QVERIFY(windowObject.testService->windowControl->winId() != 0); + + + widgetObject.bind(&widget); + QCOMPARE(widget.mediaObject(), static_cast(&widgetObject)); + QCOMPARE(windowObject.testService->windowRef, 0); + QCOMPARE(widgetObject.testService->widgetRef, 1); + QCOMPARE(rendererObject.testService->rendererRef, 0); + + QCoreApplication::processEvents(QEventLoop::AllEvents); + QCOMPARE(widgetObject.testService->widgetControl->videoWidget()->isVisible(), true); + + QCOMPARE(windowObject.testService->windowRef, 0); + QCOMPARE(widgetObject.testService->widgetRef, 1); + QCOMPARE(rendererObject.testService->rendererRef, 0); + + rendererObject.bind(&widget); + QCOMPARE(widget.mediaObject(), static_cast(&rendererObject)); + + QCOMPARE(windowObject.testService->windowRef, 0); + QCOMPARE(widgetObject.testService->widgetRef, 0); + QCOMPARE(rendererObject.testService->rendererRef, 1); + QVERIFY(rendererObject.testService->rendererControl->surface() != 0); + + rendererObject.unbind(&widget); + QCOMPARE(widget.mediaObject(), nullObject); + + QCOMPARE(windowObject.testService->windowRef, 0); + QCOMPARE(widgetObject.testService->widgetRef, 0); + QCOMPARE(rendererObject.testService->rendererRef, 0); +} + +void tst_QVideoWidget::showWindowControl() +{ + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setNativeSize(QSize(240, 180)); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QVERIFY(object.testService->windowControl->winId() != 0); + QVERIFY(object.testService->windowControl->repaintCount() > 0); + + widget.resize(640, 480); + QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480)); + + widget.move(10, 10); + QCOMPARE(object.testService->windowControl->displayRect(), QRect(0, 0, 640, 480)); + + widget.hide(); +} + +void tst_QVideoWidget::showWidgetControl() +{ + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), true); + + widget.resize(640, 480); + + widget.move(10, 10); + + widget.hide(); + + QCOMPARE(object.testService->widgetControl->videoWidget()->isVisible(), false); +} + +void tst_QVideoWidget::showRendererControl() +{ + QtTestVideoObject object(0, 0, new QtTestRendererControl); + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QVERIFY(object.testService->rendererControl->surface() != 0); + + widget.resize(640, 480); + + widget.move(10, 10); + + widget.hide(); +} + +void tst_QVideoWidget::aspectRatioWindowControl() +{ + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setAspectRatioMode(Qt::IgnoreAspectRatio); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + // Test the aspect ratio defaults to keeping the aspect ratio. + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + + // Test the control has been informed of the aspect ratio change, post show. + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio); + + // Test an aspect ratio change is enforced immediately while visible. + widget.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); + QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::IgnoreAspectRatio); + + // Test an aspect ratio set while not visible is respected. + widget.hide(); + widget.setAspectRatioMode(Qt::KeepAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + widget.show(); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + QCOMPARE(object.testService->windowControl->aspectRatioMode(), Qt::KeepAspectRatio); +} + +void tst_QVideoWidget::aspectRatioWidgetControl() +{ + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + object.testService->widgetControl->setAspectRatioMode(Qt::IgnoreAspectRatio); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + // Test the aspect ratio defaults to keeping the aspect ratio. + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + + // Test the control has been informed of the aspect ratio change, post show. + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio); + + // Test an aspect ratio change is enforced immediately while visible. + widget.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); + QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::IgnoreAspectRatio); + + // Test an aspect ratio set while not visible is respected. + widget.hide(); + widget.setAspectRatioMode(Qt::KeepAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + widget.show(); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + QCOMPARE(object.testService->widgetControl->aspectRatioMode(), Qt::KeepAspectRatio); +} + +void tst_QVideoWidget::aspectRatioRendererControl() +{ + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + // Test the aspect ratio defaults to keeping the aspect ratio. + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + + // Test the control has been informed of the aspect ratio change, post show. + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + + // Test an aspect ratio change is enforced immediately while visible. + widget.setAspectRatioMode(Qt::IgnoreAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::IgnoreAspectRatio); + + // Test an aspect ratio set while not visible is respected. + widget.hide(); + widget.setAspectRatioMode(Qt::KeepAspectRatio); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); + widget.show(); + QCOMPARE(widget.aspectRatioMode(), Qt::KeepAspectRatio); +} + +void tst_QVideoWidget::sizeHint_data() +{ + QTest::addColumn("size"); + + QTest::newRow("720x576") + << QSize(720, 576); +} + +void tst_QVideoWidget::sizeHintWindowControl() +{ + QFETCH(QSize, size); + + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QVERIFY(widget.sizeHint().isEmpty()); + + object.testService->windowControl->setNativeSize(size); + QCOMPARE(widget.sizeHint(), size); +} + +void tst_QVideoWidget::sizeHintWidgetControl() +{ + QFETCH(QSize, size); + + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QVERIFY(widget.sizeHint().isEmpty()); + + object.testService->widgetControl->setSizeHint(size); + QCOMPARE(widget.sizeHint(), size); +} + +void tst_QVideoWidget::sizeHintRendererControl_data() +{ + QTest::addColumn("frameSize"); + QTest::addColumn("viewport"); + QTest::addColumn("pixelAspectRatio"); + QTest::addColumn("expectedSize"); + + QTest::newRow("640x480") + << QSize(640, 480) + << QRect(0, 0, 640, 480) + << QSize(1, 1) + << QSize(640, 480); + + QTest::newRow("800x600, (80,60, 640x480) viewport") + << QSize(800, 600) + << QRect(80, 60, 640, 480) + << QSize(1, 1) + << QSize(640, 480); + + QTest::newRow("800x600, (80,60, 640x480) viewport, 4:3") + << QSize(800, 600) + << QRect(80, 60, 640, 480) + << QSize(4, 3) + << QSize(853, 480); + +} + +void tst_QVideoWidget::sizeHintRendererControl() +{ + QFETCH(QSize, frameSize); + QFETCH(QRect, viewport); + QFETCH(QSize, pixelAspectRatio); + QFETCH(QSize, expectedSize); + + QtTestVideoObject object(0, 0, new QtTestRendererControl); + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); + format.setViewport(viewport); + format.setPixelAspectRatio(pixelAspectRatio); + + QVERIFY(object.testService->rendererControl->surface()->start(format)); + + QCOMPARE(widget.sizeHint(), expectedSize); +} + + +void tst_QVideoWidget::fullScreenWindowControl() +{ + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + QVideoWidget widget; + object.bind(&widget); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + Qt::WindowFlags windowFlags = widget.windowFlags(); + + QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); + + // Test showing full screen with setFullScreen(true). + widget.setFullScreen(true); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->windowControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toBool(), true); + + // Test returning to normal with setFullScreen(false). + widget.setFullScreen(false); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->windowControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test showing full screen with showFullScreen(). + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->windowControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 3); + QCOMPARE(spy.value(2).value(0).toBool(), true); + + // Test returning to normal with showNormal(). + widget.showNormal(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->windowControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + QCOMPARE(spy.value(3).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. + widget.setFullScreen(false); + QCOMPARE(object.testService->windowControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + widget.showNormal(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->windowControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + + // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + widget.setFullScreen(true); + QCOMPARE(object.testService->windowControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); + widget.showFullScreen(); + QCOMPARE(object.testService->windowControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); + + // Test if the window control exits full screen mode, the widget follows suit. + object.testService->windowControl->setFullScreen(false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 6); + QCOMPARE(spy.value(5).value(0).toBool(), false); + + // Test if the window control enters full screen mode, the widget does nothing. + object.testService->windowControl->setFullScreen(false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 6); +} + +void tst_QVideoWidget::fullScreenWidgetControl() +{ + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + QVideoWidget widget; + object.bind(&widget); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + Qt::WindowFlags windowFlags = widget.windowFlags(); + + QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); + + // Test showing full screen with setFullScreen(true). + widget.setFullScreen(true); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->widgetControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toBool(), true); + + // Test returning to normal with setFullScreen(false). + widget.setFullScreen(false); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->widgetControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test showing full screen with showFullScreen(). + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->widgetControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 3); + QCOMPARE(spy.value(2).value(0).toBool(), true); + + // Test returning to normal with showNormal(). + widget.showNormal(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(object.testService->widgetControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + QCOMPARE(spy.value(3).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. + widget.setFullScreen(false); + QCOMPARE(object.testService->widgetControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + widget.showNormal(); + QCOMPARE(object.testService->widgetControl->isFullScreen(), false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + + // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + widget.setFullScreen(true); + QCOMPARE(object.testService->widgetControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); + widget.showFullScreen(); + QCOMPARE(object.testService->widgetControl->isFullScreen(), true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); + + // Test if the window control exits full screen mode, the widget follows suit. + object.testService->widgetControl->setFullScreen(false); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 6); + QCOMPARE(spy.value(5).value(0).toBool(), false); + + // Test if the window control enters full screen mode, the widget does nothing. + object.testService->widgetControl->setFullScreen(false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 6); +} + + +void tst_QVideoWidget::fullScreenRendererControl() +{ + QtTestVideoObject object(0, 0, new QtTestRendererControl); + QVideoWidget widget; + object.bind(&widget); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + Qt::WindowFlags windowFlags = widget.windowFlags(); + + QSignalSpy spy(&widget, SIGNAL(fullScreenChanged(bool))); + + // Test showing full screen with setFullScreen(true). + widget.setFullScreen(true); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toBool(), true); + + // Test returning to normal with setFullScreen(false). + widget.setFullScreen(false); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test showing full screen with showFullScreen(). + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 3); + QCOMPARE(spy.value(2).value(0).toBool(), true); + + // Test returning to normal with showNormal(). + widget.showNormal(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + QCOMPARE(spy.value(3).value(0).toBool(), false); + QCOMPARE(widget.windowFlags(), windowFlags); + + // Test setFullScreen(false) and showNormal() do nothing when isFullScreen() == false. + widget.setFullScreen(false); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + widget.showNormal(); + QCOMPARE(widget.isFullScreen(), false); + QCOMPARE(spy.count(), 4); + + // Test setFullScreen(true) and showFullScreen() do nothing when isFullScreen() == true. + widget.showFullScreen(); + QTest::qWaitForWindowShown(&widget); + widget.setFullScreen(true); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); + widget.showFullScreen(); + QCOMPARE(widget.isFullScreen(), true); + QCOMPARE(spy.count(), 5); +} + + +void tst_QVideoWidget::color_data() +{ + QTest::addColumn("controlValue"); + QTest::addColumn("value"); + QTest::addColumn("expectedValue"); + + QTest::newRow("12") + << 0 + << 12 + << 12; + QTest::newRow("-56") + << 87 + << -56 + << -56; + QTest::newRow("100") + << 32 + << 100 + << 100; + QTest::newRow("1294") + << 0 + << 1294 + << 100; + QTest::newRow("-102") + << 34 + << -102 + << -100; +} + +void tst_QVideoWidget::brightnessWindowControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setBrightness(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + // Test the video widget resets the controls starting brightness to the default. + QCOMPARE(widget.brightness(), 0); + + QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); + + // Test the video widget sets the brightness value, bounded if necessary and emits a changed + // signal. + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(object.testService->windowControl->brightness(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + // Test the changed signal isn't emitted if the value is unchanged. + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(object.testService->windowControl->brightness(), expectedValue); + QCOMPARE(spy.count(), 1); + + // Test the changed signal is emitted if the brightness is changed internally. + object.testService->windowControl->setBrightness(controlValue); + QCOMPARE(widget.brightness(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::brightnessWidgetControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + object.testService->widgetControl->setBrightness(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QCOMPARE(widget.brightness(), 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); + + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(object.testService->widgetControl->brightness(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(object.testService->widgetControl->brightness(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->widgetControl->setBrightness(controlValue); + QCOMPARE(widget.brightness(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::brightnessRendererControl() +{ + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QSignalSpy spy(&widget, SIGNAL(brightnessChanged(int))); + + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setBrightness(value); + QCOMPARE(widget.brightness(), expectedValue); + QCOMPARE(spy.count(), 1); +} + +void tst_QVideoWidget::contrastWindowControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setContrast(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QCOMPARE(widget.contrast(), 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.contrast(), 0); + + QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(object.testService->windowControl->contrast(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(object.testService->windowControl->contrast(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->windowControl->setContrast(controlValue); + QCOMPARE(widget.contrast(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::contrastWidgetControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + object.testService->widgetControl->setContrast(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + QCOMPARE(widget.contrast(), 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.contrast(), 0); + + QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(object.testService->widgetControl->contrast(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(object.testService->widgetControl->contrast(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->widgetControl->setContrast(controlValue); + QCOMPARE(widget.contrast(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::contrastRendererControl() +{ + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QSignalSpy spy(&widget, SIGNAL(contrastChanged(int))); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setContrast(value); + QCOMPARE(widget.contrast(), expectedValue); + QCOMPARE(spy.count(), 1); +} + +void tst_QVideoWidget::hueWindowControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setHue(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + QCOMPARE(widget.hue(), 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.hue(), 0); + + QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(object.testService->windowControl->hue(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(object.testService->windowControl->hue(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->windowControl->setHue(controlValue); + QCOMPARE(widget.hue(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::hueWidgetControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + object.testService->widgetControl->setHue(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + QCOMPARE(widget.hue(), 0); + + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.hue(), 0); + + QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(object.testService->widgetControl->hue(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(object.testService->widgetControl->hue(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->widgetControl->setHue(controlValue); + QCOMPARE(widget.hue(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::hueRendererControl() +{ + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QSignalSpy spy(&widget, SIGNAL(hueChanged(int))); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setHue(value); + QCOMPARE(widget.hue(), expectedValue); + QCOMPARE(spy.count(), 1); +} + +void tst_QVideoWidget::saturationWindowControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(new QtTestWindowControl, 0, 0); + object.testService->windowControl->setSaturation(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + QCOMPARE(widget.saturation(), 0); + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.saturation(), 0); + + QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(object.testService->windowControl->saturation(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(object.testService->windowControl->saturation(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->windowControl->setSaturation(controlValue); + QCOMPARE(widget.saturation(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); +} + +void tst_QVideoWidget::saturationWidgetControl() +{ + QFETCH(int, controlValue); + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, new QtTestWidgetControl, 0); + object.testService->widgetControl->setSaturation(controlValue); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + + QCOMPARE(widget.saturation(), 0); + widget.show(); + QTest::qWaitForWindowShown(&widget); + QCOMPARE(widget.saturation(), 0); + + QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(object.testService->widgetControl->saturation(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(object.testService->widgetControl->saturation(), expectedValue); + QCOMPARE(spy.count(), 1); + + object.testService->widgetControl->setSaturation(controlValue); + QCOMPARE(widget.saturation(), controlValue); + QCOMPARE(spy.count(), 2); + QCOMPARE(spy.value(1).value(0).toInt(), controlValue); + +} + +void tst_QVideoWidget::saturationRendererControl() +{ + QFETCH(int, value); + QFETCH(int, expectedValue); + + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.show(); + QTest::qWaitForWindowShown(&widget); + QSignalSpy spy(&widget, SIGNAL(saturationChanged(int))); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.value(0).value(0).toInt(), expectedValue); + + widget.setSaturation(value); + QCOMPARE(widget.saturation(), expectedValue); + QCOMPARE(spy.count(), 1); +} + +static const uchar rgb32ImageData[] = +{ + 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 +}; + +void tst_QVideoWidget::paintRendererControl() +{ + QtTestVideoObject object(0, 0, new QtTestRendererControl); + + QVideoWidget widget; + object.bind(&widget); + widget.setWindowFlags(Qt::X11BypassWindowManagerHint); + widget.resize(640,480); + widget.show(); + QTest::qWaitForWindowShown(&widget); + + QPainterVideoSurface *surface = qobject_cast( + object.testService->rendererControl->surface()); + + QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); + + QVERIFY(surface->start(format)); + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); + + QCoreApplication::processEvents(QEventLoop::AllEvents); + + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); + + QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); + + frame.map(QAbstractVideoBuffer::WriteOnly); + memcpy(frame.bits(), rgb32ImageData, frame.mappedBytes()); + frame.unmap(); + + QVERIFY(surface->present(frame)); + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), false); + + //wait up to 2 seconds for the frame to be presented + for (int i=0; i<200 && !surface->isReady(); i++) + QTest::qWait(10); + + QCOMPARE(surface->isActive(), true); + QCOMPARE(surface->isReady(), true); +} + +QTEST_MAIN(tst_QVideoWidget) + +#include "tst_qvideowidget.moc" diff --git a/tests/auto/unit/qwavedecoder/data/corrupt_datadesc_1_16_8000.le.wav b/tests/auto/unit/qwavedecoder/data/corrupt_datadesc_1_16_8000.le.wav new file mode 100644 index 000000000..b6eac4d70 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/corrupt_datadesc_1_16_8000.le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/corrupt_fmtdesc_1_16_8000.le.wav b/tests/auto/unit/qwavedecoder/data/corrupt_fmtdesc_1_16_8000.le.wav new file mode 100644 index 000000000..2f0da1370 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/corrupt_fmtdesc_1_16_8000.le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/corrupt_fmtstring_1_16_8000.le.wav b/tests/auto/unit/qwavedecoder/data/corrupt_fmtstring_1_16_8000.le.wav new file mode 100644 index 000000000..b14a53c9e Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/corrupt_fmtstring_1_16_8000.le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/empty.wav b/tests/auto/unit/qwavedecoder/data/empty.wav new file mode 100644 index 000000000..e69de29bb diff --git a/tests/auto/unit/qwavedecoder/data/gendata.sh b/tests/auto/unit/qwavedecoder/data/gendata.sh new file mode 100755 index 000000000..0dd82cef7 --- /dev/null +++ b/tests/auto/unit/qwavedecoder/data/gendata.sh @@ -0,0 +1,68 @@ +#!/bin/bash +############################################################################# +## +## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +## All rights reserved. +## Contact: Nokia Corporation (qt-info@nokia.com) +## +## This file is the build configuration utility of the Qt Toolkit. +## +## $QT_BEGIN_LICENSE:LGPL$ +## GNU Lesser General Public License Usage +## This file may be used under the terms of the GNU Lesser General Public +## License version 2.1 as published by the Free Software Foundation and +## appearing in the file LICENSE.LGPL included in the packaging of this +## file. Please review the following information to ensure the GNU Lesser +## General Public License version 2.1 requirements will be met: +## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Nokia gives you certain additional +## rights. These rights are described in the Nokia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU General +## Public License version 3.0 as published by the Free Software Foundation +## and appearing in the file LICENSE.GPL included in the packaging of this +## file. Please review the following information to ensure the GNU General +## Public License version 3.0 requirements will be met: +## http://www.gnu.org/copyleft/gpl.html. +## +## Other Usage +## Alternatively, this file may be used in accordance with the terms and +## conditions contained in a signed written agreement between you and Nokia. +## +## +## +## +## +## $QT_END_LICENSE$ +## +############################################################################# + +# Generate some simple test data. Uses "sox". + +endian="" +endian_extn="" + +for channel in 1 2; do + if [ $channel -eq 1 ]; then + endian="little" + endian_extn="le" + fi + + if [ $channel -eq 2 ]; then + endian="big" + endian_extn="be" + fi + for samplebits in 8 16 32; do + for samplerate in 44100 8000; do + if [ $samplebits -ne 8 ]; then + sox -n --endian "${endian}" -c ${channel} -b ${samplebits} -r ${samplerate} isawav_${channel}_${samplebits}_${samplerate}_${endian_extn}.wav synth 0.25 sine 300-3300 + else + sox -n -c ${channel} -b ${samplebits} -r ${samplerate} isawav_${channel}_${samplebits}_${samplerate}.wav synth 0.25 sine 300-3300 + fi + done + done +done + diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le.wav new file mode 100644 index 000000000..88b1a8379 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_16_44100_le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_16_8000_le.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_16_8000_le.wav new file mode 100644 index 000000000..83a405907 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_16_8000_le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_32_44100_le.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_32_44100_le.wav new file mode 100644 index 000000000..9c437b155 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_32_44100_le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_32_8000_le.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_32_8000_le.wav new file mode 100644 index 000000000..f90a8bc35 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_32_8000_le.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_8_44100.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_8_44100.wav new file mode 100644 index 000000000..7d10829ea Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_8_44100.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_1_8_8000.wav b/tests/auto/unit/qwavedecoder/data/isawav_1_8_8000.wav new file mode 100644 index 000000000..76c08e89e Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_1_8_8000.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_16_44100_be.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_16_44100_be.wav new file mode 100644 index 000000000..ca0cd425a Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_16_44100_be.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_16_8000_be.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_16_8000_be.wav new file mode 100644 index 000000000..3a684590b Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_16_8000_be.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_32_44100_be.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_32_44100_be.wav new file mode 100644 index 000000000..f1aaf2906 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_32_44100_be.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_32_8000_be.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_32_8000_be.wav new file mode 100644 index 000000000..c10c20872 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_32_8000_be.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_8_44100.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_8_44100.wav new file mode 100644 index 000000000..befd02baf Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_8_44100.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/isawav_2_8_8000.wav b/tests/auto/unit/qwavedecoder/data/isawav_2_8_8000.wav new file mode 100644 index 000000000..ce8b0d06a Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/isawav_2_8_8000.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/nosampledata.wav b/tests/auto/unit/qwavedecoder/data/nosampledata.wav new file mode 100644 index 000000000..8dbde9545 Binary files /dev/null and b/tests/auto/unit/qwavedecoder/data/nosampledata.wav differ diff --git a/tests/auto/unit/qwavedecoder/data/notawav.wav b/tests/auto/unit/qwavedecoder/data/notawav.wav new file mode 100644 index 000000000..36a20ea05 --- /dev/null +++ b/tests/auto/unit/qwavedecoder/data/notawav.wav @@ -0,0 +1 @@ +Ceci n'est pas une wav file diff --git a/tests/auto/unit/qwavedecoder/data/onebyte.wav b/tests/auto/unit/qwavedecoder/data/onebyte.wav new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/tests/auto/unit/qwavedecoder/data/onebyte.wav @@ -0,0 +1 @@ +1 diff --git a/tests/auto/unit/qwavedecoder/qwavedecoder.pro b/tests/auto/unit/qwavedecoder/qwavedecoder.pro new file mode 100644 index 000000000..7428c5c3e --- /dev/null +++ b/tests/auto/unit/qwavedecoder/qwavedecoder.pro @@ -0,0 +1,12 @@ +TARGET = tst_qwavedecoder +HEADERS += $$QT.multimedia.sources/effects/qwavedecoder_p.h +SOURCES += tst_qwavedecoder.cpp \ + $$QT.multimedia.sources/effects/qwavedecoder_p.cpp + +QT += multimedia-private testlib network +CONFIG += no_private_qt_headers_warning testcase + +data.files = data/* +data.path = data +DEPLOYMENT += data + diff --git a/tests/auto/unit/qwavedecoder/tst_qwavedecoder.cpp b/tests/auto/unit/qwavedecoder/tst_qwavedecoder.cpp new file mode 100644 index 000000000..a84879b0c --- /dev/null +++ b/tests/auto/unit/qwavedecoder/tst_qwavedecoder.cpp @@ -0,0 +1,326 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/multimedia + +#include +#include + +#include +#include +#include + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 1000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !((__expr) == (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while (0) +#endif + + +class tst_QWaveDecoder : public QObject +{ + Q_OBJECT +public: + enum Corruption { + None = 1, + NotAWav = 2, + NoSampleData = 4, + FormatDescriptor = 8, + FormatString = 16, + DataDescriptor = 32 + }; + +public slots: + + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + + void file_data(); + void file(); + + void http_data() {file_data();} + void http(); + + void readAllAtOnce(); + void readPerByte(); +}; + +void tst_QWaveDecoder::init() +{ +} + +void tst_QWaveDecoder::cleanup() +{ +} + +void tst_QWaveDecoder::initTestCase() +{ +} + +void tst_QWaveDecoder::cleanupTestCase() +{ +} + +void tst_QWaveDecoder::file_data() +{ + QTest::addColumn("file"); + QTest::addColumn("corruption"); + QTest::addColumn("channels"); + QTest::addColumn("samplesize"); + QTest::addColumn("samplerate"); + QTest::addColumn("byteorder"); + + QTest::newRow("File is empty") << QString("empty.wav") << tst_QWaveDecoder::NotAWav << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("File is one byte") << QString("onebyte.wav") << tst_QWaveDecoder::NotAWav << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("File is not a wav(text)") << QString("notawav.wav") << tst_QWaveDecoder::NotAWav << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("Wav file has no sample data") << QString("nosampledata.wav") << tst_QWaveDecoder::NoSampleData << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("corrupt fmt chunk descriptor") << QString("corrupt_fmtdesc_1_16_8000.le.wav") << tst_QWaveDecoder::FormatDescriptor << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("corrupt fmt string") << QString("corrupt_fmtstring_1_16_8000.le.wav") << tst_QWaveDecoder::FormatString << -1 << -1 << -1 << QAudioFormat::LittleEndian; + QTest::newRow("corrupt data chunk descriptor") << QString("corrupt_datadesc_1_16_8000.le.wav") << tst_QWaveDecoder::DataDescriptor << -1 << -1 << -1 << QAudioFormat::LittleEndian; + + QTest::newRow("File isawav_1_8_8000.wav") << QString("isawav_1_8_8000.wav") << tst_QWaveDecoder::None << 1 << 8 << 8000 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_1_8_44100.wav") << QString("isawav_1_8_44100.wav") << tst_QWaveDecoder::None << 1 << 8 << 44100 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_2_8_8000.wav") << QString("isawav_2_8_8000.wav") << tst_QWaveDecoder::None << 2 << 8 << 8000 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_2_8_44100.wav") << QString("isawav_2_8_44100.wav") << tst_QWaveDecoder::None << 2 << 8 << 44100 << QAudioFormat::LittleEndian; + + QTest::newRow("File isawav_1_16_8000_le.wav") << QString("isawav_1_16_8000_le.wav") << tst_QWaveDecoder::None << 1 << 16 << 8000 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_1_16_44100_le.wav") << QString("isawav_1_16_44100_le.wav") << tst_QWaveDecoder::None << 1 << 16 << 44100 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_2_16_8000_be.wav") << QString("isawav_2_16_8000_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 8000 << QAudioFormat::BigEndian; + QTest::newRow("File isawav_2_16_44100_be.wav") << QString("isawav_2_16_44100_be.wav") << tst_QWaveDecoder::None << 2 << 16 << 44100 << QAudioFormat::BigEndian; + + // 32 bit waves are not supported + QTest::newRow("File isawav_1_32_8000_le.wav") << QString("isawav_1_32_8000_le.wav") << tst_QWaveDecoder::FormatDescriptor << 1 << 32 << 8000 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_1_32_44100_le.wav") << QString("isawav_1_32_44100_le.wav") << tst_QWaveDecoder::FormatDescriptor << 1 << 32 << 44100 << QAudioFormat::LittleEndian; + QTest::newRow("File isawav_2_32_8000_be.wav") << QString("isawav_2_32_8000_be.wav") << tst_QWaveDecoder::FormatDescriptor << 2 << 32 << 8000 << QAudioFormat::BigEndian; + QTest::newRow("File isawav_2_32_44100_be.wav") << QString("isawav_2_32_44100_be.wav") << tst_QWaveDecoder::FormatDescriptor << 2 << 32 << 44100 << QAudioFormat::BigEndian; +} + +void tst_QWaveDecoder::file() +{ + QFETCH(QString, file); + QFETCH(tst_QWaveDecoder::Corruption, corruption); + QFETCH(int, channels); + QFETCH(int, samplesize); + QFETCH(int, samplerate); + QFETCH(QAudioFormat::Endian, byteorder); + + QFile stream; + stream.setFileName(QString("data/") + file); + stream.open(QIODevice::ReadOnly); + + QVERIFY(stream.isOpen()); + + QWaveDecoder waveDecoder(&stream); + QSignalSpy validFormatSpy(&waveDecoder, SIGNAL(formatKnown())); + QSignalSpy parsingErrorSpy(&waveDecoder, SIGNAL(parsingError())); + + if (corruption == NotAWav) { + QSKIP("Not all failures detected correctly yet", SkipSingle); + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + } else if (corruption == NoSampleData) { + QTRY_COMPARE(validFormatSpy.count(), 1); + QCOMPARE(parsingErrorSpy.count(), 0); + QVERIFY(waveDecoder.audioFormat().isValid()); + QVERIFY(waveDecoder.size() == 0); + QVERIFY(waveDecoder.duration() == 0); + } else if (corruption == FormatDescriptor) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + } else if (corruption == FormatString) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + QVERIFY(!waveDecoder.audioFormat().isValid()); + } else if (corruption == DataDescriptor) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + QVERIFY(waveDecoder.size() == 0); + } else if (corruption == None) { + QTRY_COMPARE(validFormatSpy.count(), 1); + QCOMPARE(parsingErrorSpy.count(), 0); + QVERIFY(waveDecoder.audioFormat().isValid()); + QVERIFY(waveDecoder.size() > 0); + QVERIFY(waveDecoder.duration() == 250); + QAudioFormat format = waveDecoder.audioFormat(); + QVERIFY(format.isValid()); + QVERIFY(format.channels() == channels); + QVERIFY(format.sampleSize() == samplesize); + QVERIFY(format.sampleRate() == samplerate); + if (format.sampleSize() != 8) { + QVERIFY(format.byteOrder() == byteorder); + } + } + + stream.close(); +} + +void tst_QWaveDecoder::http() +{ + QFETCH(QString, file); + QFETCH(tst_QWaveDecoder::Corruption, corruption); + QFETCH(int, channels); + QFETCH(int, samplesize); + QFETCH(int, samplerate); + QFETCH(QAudioFormat::Endian, byteorder); + + QFile stream; + stream.setFileName(QString("data/") + file); + stream.open(QIODevice::ReadOnly); + + QVERIFY(stream.isOpen()); + + QNetworkAccessManager nam; + + QNetworkReply *reply = nam.get(QNetworkRequest(QUrl::fromLocalFile(QString::fromLatin1("data/") + file))); + + QWaveDecoder waveDecoder(reply); + QSignalSpy validFormatSpy(&waveDecoder, SIGNAL(formatKnown())); + QSignalSpy parsingErrorSpy(&waveDecoder, SIGNAL(parsingError())); + + if (corruption == NotAWav) { + QSKIP("Not all failures detected correctly yet", SkipSingle); + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + } else if (corruption == NoSampleData) { + QTRY_COMPARE(validFormatSpy.count(), 1); + QCOMPARE(parsingErrorSpy.count(), 0); + QVERIFY(waveDecoder.audioFormat().isValid()); + QVERIFY(waveDecoder.size() == 0); + QVERIFY(waveDecoder.duration() == 0); + } else if (corruption == FormatDescriptor) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + } else if (corruption == FormatString) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + QVERIFY(!waveDecoder.audioFormat().isValid()); + } else if (corruption == DataDescriptor) { + QTRY_COMPARE(parsingErrorSpy.count(), 1); + QCOMPARE(validFormatSpy.count(), 0); + QVERIFY(waveDecoder.size() == 0); + } else if (corruption == None) { + QTRY_COMPARE(validFormatSpy.count(), 1); + QCOMPARE(parsingErrorSpy.count(), 0); + QVERIFY(waveDecoder.audioFormat().isValid()); + QVERIFY(waveDecoder.size() > 0); + QVERIFY(waveDecoder.duration() == 250); + QAudioFormat format = waveDecoder.audioFormat(); + QVERIFY(format.isValid()); + QVERIFY(format.channels() == channels); + QVERIFY(format.sampleSize() == samplesize); + QVERIFY(format.sampleRate() == samplerate); + if (format.sampleSize() != 8) { + QVERIFY(format.byteOrder() == byteorder); + } + } + + delete reply; +} + +void tst_QWaveDecoder::readAllAtOnce() +{ + QFile stream; + stream.setFileName(QString("data/isawav_2_8_44100.wav")); + stream.open(QIODevice::ReadOnly); + + QVERIFY(stream.isOpen()); + + QWaveDecoder waveDecoder(&stream); + QSignalSpy validFormatSpy(&waveDecoder, SIGNAL(formatKnown())); + + QTRY_COMPARE(validFormatSpy.count(), 1); + QVERIFY(waveDecoder.size() > 0); + + QByteArray buffer; + buffer.resize(waveDecoder.size()); + + qint64 readSize = waveDecoder.read(buffer.data(), waveDecoder.size()); + QVERIFY(readSize == waveDecoder.size()); + + readSize = waveDecoder.read(buffer.data(), 1); + QVERIFY(readSize == 0); + + stream.close(); +} + +void tst_QWaveDecoder::readPerByte() +{ + QFile stream; + stream.setFileName(QString("data/isawav_2_8_44100.wav")); + stream.open(QIODevice::ReadOnly); + + QVERIFY(stream.isOpen()); + + QWaveDecoder waveDecoder(&stream); + QSignalSpy validFormatSpy(&waveDecoder, SIGNAL(formatKnown())); + + QTRY_COMPARE(validFormatSpy.count(), 1); + QVERIFY(waveDecoder.size() > 0); + + qint64 readSize = 0; + char buf; + for (int ii = 0; ii < waveDecoder.size(); ++ii) + readSize += waveDecoder.read(&buf, 1); + QVERIFY(readSize == waveDecoder.size()); + QVERIFY(waveDecoder.read(&buf,1) == 0); + + stream.close(); +} + +Q_DECLARE_METATYPE(tst_QWaveDecoder::Corruption) + +QTEST_MAIN(tst_QWaveDecoder) + +#include "tst_qwavedecoder.moc" + diff --git a/tests/auto/unit/unit.pro b/tests/auto/unit/unit.pro new file mode 100644 index 000000000..1043abf08 --- /dev/null +++ b/tests/auto/unit/unit.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += multimedia.pro +contains(QT_CONFIG,multimediawidgets): SUBDIRS += multimediawidgets.pro -- cgit v1.2.3