author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtTest/QtTest> |
|
43 |
||
44 |
#include <QtMultimedia/QAbstractVideoSurface> |
|
45 |
#include <QtMultimedia/QVideoSurfaceFormat> |
|
46 |
||
47 |
class tst_QAbstractVideoSurface : public QObject |
|
48 |
{ |
|
49 |
Q_OBJECT |
|
50 |
public: |
|
51 |
tst_QAbstractVideoSurface(); |
|
52 |
~tst_QAbstractVideoSurface(); |
|
53 |
||
54 |
public slots: |
|
55 |
void initTestCase(); |
|
56 |
void cleanupTestCase(); |
|
57 |
void init(); |
|
58 |
void cleanup(); |
|
59 |
||
60 |
private slots: |
|
61 |
void setError(); |
|
62 |
void isFormatSupported_data(); |
|
63 |
void isFormatSupported(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
void nearestFormat_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
void nearestFormat(); |
0 | 66 |
void start_data(); |
67 |
void start(); |
|
68 |
}; |
|
69 |
||
70 |
typedef QMap<QAbstractVideoBuffer::HandleType, QVideoFrame::PixelFormat> SupportedFormatMap; |
|
71 |
||
72 |
Q_DECLARE_METATYPE(SupportedFormatMap) |
|
73 |
Q_DECLARE_METATYPE(QVideoSurfaceFormat) |
|
74 |
Q_DECLARE_METATYPE(QAbstractVideoSurface::Error); |
|
75 |
||
76 |
class QtTestVideoSurface : public QAbstractVideoSurface |
|
77 |
{ |
|
78 |
Q_OBJECT |
|
79 |
public: |
|
80 |
explicit QtTestVideoSurface(QObject *parent = 0) : QAbstractVideoSurface(parent) {} |
|
81 |
explicit QtTestVideoSurface(SupportedFormatMap formats, QObject *parent = 0) |
|
82 |
: QAbstractVideoSurface(parent), supportedFormats(formats) {} |
|
83 |
||
84 |
QList<QVideoFrame::PixelFormat> supportedPixelFormats( |
|
85 |
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const |
|
86 |
{ |
|
87 |
return supportedFormats.values(handleType); |
|
88 |
} |
|
89 |
||
90 |
bool present(const QVideoFrame &) { return false; } |
|
91 |
||
92 |
using QAbstractVideoSurface::setError; |
|
93 |
||
94 |
private: |
|
95 |
SupportedFormatMap supportedFormats; |
|
96 |
}; |
|
97 |
||
98 |
tst_QAbstractVideoSurface::tst_QAbstractVideoSurface() |
|
99 |
{ |
|
100 |
} |
|
101 |
||
102 |
tst_QAbstractVideoSurface::~tst_QAbstractVideoSurface() |
|
103 |
{ |
|
104 |
} |
|
105 |
||
106 |
void tst_QAbstractVideoSurface::initTestCase() |
|
107 |
{ |
|
108 |
} |
|
109 |
||
110 |
void tst_QAbstractVideoSurface::cleanupTestCase() |
|
111 |
{ |
|
112 |
} |
|
113 |
||
114 |
void tst_QAbstractVideoSurface::init() |
|
115 |
{ |
|
116 |
} |
|
117 |
||
118 |
void tst_QAbstractVideoSurface::cleanup() |
|
119 |
{ |
|
120 |
} |
|
121 |
||
122 |
void tst_QAbstractVideoSurface::setError() |
|
123 |
{ |
|
124 |
qRegisterMetaType<QAbstractVideoSurface::Error>(); |
|
125 |
||
126 |
QtTestVideoSurface surface; |
|
127 |
||
128 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); |
|
129 |
||
130 |
surface.setError(QAbstractVideoSurface::StoppedError); |
|
131 |
QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); |
|
132 |
||
133 |
surface.setError(QAbstractVideoSurface::ResourceError); |
|
134 |
QCOMPARE(surface.error(), QAbstractVideoSurface::ResourceError); |
|
135 |
||
136 |
surface.setError(QAbstractVideoSurface::NoError); |
|
137 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); |
|
138 |
} |
|
139 |
||
140 |
void tst_QAbstractVideoSurface::isFormatSupported_data() |
|
141 |
{ |
|
142 |
QTest::addColumn<SupportedFormatMap>("supportedFormats"); |
|
143 |
QTest::addColumn<QVideoSurfaceFormat>("format"); |
|
144 |
QTest::addColumn<bool>("supported"); |
|
145 |
||
146 |
SupportedFormatMap formats; |
|
147 |
||
148 |
QTest::newRow("no formats: rgb32") |
|
149 |
<< formats |
|
150 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) |
|
151 |
<< false; |
|
152 |
QTest::newRow("no formats: yv12") |
|
153 |
<< formats |
|
154 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) |
|
155 |
<< false; |
|
156 |
QTest::newRow("no formats: rgb32 gl") |
|
157 |
<< formats |
|
158 |
<< QVideoSurfaceFormat( |
|
159 |
QSize(800, 600), |
|
160 |
QVideoFrame::Format_RGB32, |
|
161 |
QAbstractVideoBuffer::GLTextureHandle) |
|
162 |
<< false; |
|
163 |
QTest::newRow("no formats: rgb24 gl") |
|
164 |
<< formats |
|
165 |
<< QVideoSurfaceFormat( |
|
166 |
QSize(800, 600), |
|
167 |
QVideoFrame::Format_RGB24, |
|
168 |
QAbstractVideoBuffer::GLTextureHandle) |
|
169 |
<< false; |
|
170 |
||
171 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB32); |
|
172 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_RGB24); |
|
173 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YUV444); |
|
174 |
formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB32); |
|
175 |
||
176 |
QTest::newRow("supported: rgb32") |
|
177 |
<< formats |
|
178 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB32) |
|
179 |
<< true; |
|
180 |
QTest::newRow("supported: rgb24") |
|
181 |
<< formats |
|
182 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_RGB24) |
|
183 |
<< true; |
|
184 |
QTest::newRow("unsupported: yv12") |
|
185 |
<< formats |
|
186 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) |
|
187 |
<< false; |
|
188 |
QTest::newRow("supported: rgb32 gl") |
|
189 |
<< formats |
|
190 |
<< QVideoSurfaceFormat( |
|
191 |
QSize(800, 600), |
|
192 |
QVideoFrame::Format_RGB32, |
|
193 |
QAbstractVideoBuffer::GLTextureHandle) |
|
194 |
<< true; |
|
195 |
QTest::newRow("unsupported: rgb24 gl") |
|
196 |
<< formats |
|
197 |
<< QVideoSurfaceFormat( |
|
198 |
QSize(800, 600), |
|
199 |
QVideoFrame::Format_RGB24, |
|
200 |
QAbstractVideoBuffer::GLTextureHandle) |
|
201 |
<< false; |
|
202 |
QTest::newRow("unsupported: yv12 gl") |
|
203 |
<< formats |
|
204 |
<< QVideoSurfaceFormat( |
|
205 |
QSize(800, 600), |
|
206 |
QVideoFrame::Format_YV12, |
|
207 |
QAbstractVideoBuffer::GLTextureHandle) |
|
208 |
<< false; |
|
209 |
||
210 |
formats.insertMulti(QAbstractVideoBuffer::NoHandle, QVideoFrame::Format_YV12); |
|
211 |
formats.insertMulti(QAbstractVideoBuffer::GLTextureHandle, QVideoFrame::Format_RGB24); |
|
212 |
||
213 |
QTest::newRow("supported: yv12") |
|
214 |
<< formats |
|
215 |
<< QVideoSurfaceFormat(QSize(800, 600), QVideoFrame::Format_YV12) |
|
216 |
<< true; |
|
217 |
QTest::newRow("supported: rgb24 gl") |
|
218 |
<< formats |
|
219 |
<< QVideoSurfaceFormat( |
|
220 |
QSize(800, 600), |
|
221 |
QVideoFrame::Format_RGB24, |
|
222 |
QAbstractVideoBuffer::GLTextureHandle) |
|
223 |
<< true; |
|
224 |
} |
|
225 |
||
226 |
void tst_QAbstractVideoSurface::isFormatSupported() |
|
227 |
{ |
|
228 |
QFETCH(SupportedFormatMap, supportedFormats); |
|
229 |
QFETCH(QVideoSurfaceFormat, format); |
|
230 |
QFETCH(bool, supported); |
|
231 |
||
232 |
QtTestVideoSurface surface(supportedFormats); |
|
233 |
||
234 |
QCOMPARE(surface.isFormatSupported(format), supported); |
|
235 |
} |
|
236 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
void tst_QAbstractVideoSurface::nearestFormat_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
239 |
isFormatSupported_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
void tst_QAbstractVideoSurface::nearestFormat() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
QFETCH(SupportedFormatMap, supportedFormats); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
QFETCH(QVideoSurfaceFormat, format); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
QFETCH(bool, supported); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
QtTestVideoSurface surface(supportedFormats); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
249 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
QCOMPARE(surface.nearestFormat(format) == format, supported); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
|
0 | 253 |
void tst_QAbstractVideoSurface::start_data() |
254 |
{ |
|
255 |
QTest::addColumn<QVideoSurfaceFormat>("format"); |
|
256 |
||
257 |
QTest::newRow("rgb32") << QVideoSurfaceFormat( |
|
258 |
QSize(800, 600), |
|
259 |
QVideoFrame::Format_RGB32); |
|
260 |
QTest::newRow("yv12") << QVideoSurfaceFormat( |
|
261 |
QSize(800, 600), |
|
262 |
QVideoFrame::Format_YV12); |
|
263 |
QTest::newRow("rgb32 gl") << QVideoSurfaceFormat( |
|
264 |
QSize(800, 600), |
|
265 |
QVideoFrame::Format_RGB32, |
|
266 |
QAbstractVideoBuffer::GLTextureHandle); |
|
267 |
} |
|
268 |
||
269 |
void tst_QAbstractVideoSurface::start() |
|
270 |
{ |
|
271 |
QFETCH(QVideoSurfaceFormat, format); |
|
272 |
||
273 |
QtTestVideoSurface surface; |
|
274 |
surface.setError(QAbstractVideoSurface::ResourceError); |
|
275 |
||
276 |
QSignalSpy formatSpy(&surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
QSignalSpy activeSpy(&surface, SIGNAL(activeChanged(bool))); |
0 | 278 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
QVERIFY(!surface.isActive()); |
0 | 280 |
QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); |
281 |
||
282 |
QVERIFY(surface.start(format)); |
|
283 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
QVERIFY(surface.isActive()); |
0 | 285 |
QCOMPARE(surface.surfaceFormat(), format); |
286 |
||
287 |
QCOMPARE(formatSpy.count(), 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.last().at(0)), format); |
0 | 289 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
QCOMPARE(activeSpy.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
QCOMPARE(activeSpy.last().at(0).toBool(), true); |
0 | 292 |
|
293 |
// error() is reset on a successful start. |
|
294 |
QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); |
|
295 |
||
296 |
surface.stop(); |
|
297 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
QVERIFY(!surface.isActive()); |
0 | 299 |
QCOMPARE(surface.surfaceFormat(), QVideoSurfaceFormat()); |
300 |
||
301 |
QCOMPARE(formatSpy.count(), 2); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
302 |
QCOMPARE(qvariant_cast<QVideoSurfaceFormat>(formatSpy.last().at(0)), QVideoSurfaceFormat()); |
0 | 303 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
QCOMPARE(activeSpy.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
305 |
QCOMPARE(activeSpy.last().at(0).toBool(), false); |
0 | 306 |
} |
307 |
||
308 |
QTEST_MAIN(tst_QAbstractVideoSurface) |
|
309 |
||
310 |
#include "tst_qabstractvideosurface.moc" |