| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the test suite of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | //TESTED_COMPONENT=src/multimedia | 
| 30 |  | 
| 31 | #include <QtTest/QtTest> | 
| 32 |  | 
| 33 | #include <qabstractvideobuffer.h> | 
| 34 |  | 
| 35 | // Adds an enum, and the stringized version | 
| 36 | #define ADD_ENUM_TEST(x) \ | 
| 37 |     QTest::newRow(#x) \ | 
| 38 |         << QAbstractVideoBuffer::x \ | 
| 39 |     << QString(QLatin1String(#x)); | 
| 40 |  | 
| 41 | class tst_QAbstractVideoBuffer : public QObject | 
| 42 | { | 
| 43 |     Q_OBJECT | 
| 44 | public: | 
| 45 |     tst_QAbstractVideoBuffer(); | 
| 46 |     ~tst_QAbstractVideoBuffer(); | 
| 47 |  | 
| 48 | public slots: | 
| 49 |     void initTestCase(); | 
| 50 |     void cleanupTestCase(); | 
| 51 |     void init(); | 
| 52 |     void cleanup(); | 
| 53 |  | 
| 54 | private slots: | 
| 55 |     void handleType_data(); | 
| 56 |     void handleType(); | 
| 57 |     void handle(); | 
| 58 |     void mapMode(); | 
| 59 |     void mapModeDebug_data(); | 
| 60 |     void mapModeDebug(); | 
| 61 | }; | 
| 62 |  | 
| 63 | class QtTestVideoBuffer : public QAbstractVideoBuffer | 
| 64 | { | 
| 65 | public: | 
| 66 |     QtTestVideoBuffer(QAbstractVideoBuffer::HandleType type) : QAbstractVideoBuffer(type) {} | 
| 67 |  | 
| 68 |     MapMode mapMode() const { return QAbstractVideoBuffer::ReadWrite; } | 
| 69 |  | 
| 70 |     uchar *map(MapMode, int *, int *) { return 0; } | 
| 71 |     void unmap() {} | 
| 72 | }; | 
| 73 |  | 
| 74 | tst_QAbstractVideoBuffer::tst_QAbstractVideoBuffer() | 
| 75 | { | 
| 76 | } | 
| 77 |  | 
| 78 | tst_QAbstractVideoBuffer::~tst_QAbstractVideoBuffer() | 
| 79 | { | 
| 80 | } | 
| 81 |  | 
| 82 | void tst_QAbstractVideoBuffer::initTestCase() | 
| 83 | { | 
| 84 | } | 
| 85 |  | 
| 86 | void tst_QAbstractVideoBuffer::cleanupTestCase() | 
| 87 | { | 
| 88 | } | 
| 89 |  | 
| 90 | void tst_QAbstractVideoBuffer::init() | 
| 91 | { | 
| 92 | } | 
| 93 |  | 
| 94 | void tst_QAbstractVideoBuffer::cleanup() | 
| 95 | { | 
| 96 | } | 
| 97 |  | 
| 98 | void tst_QAbstractVideoBuffer::handleType_data() | 
| 99 | { | 
| 100 |     QTest::addColumn<QAbstractVideoBuffer::HandleType>(name: "type" ); | 
| 101 |     QTest::addColumn<QString>(name: "stringized" ); | 
| 102 |  | 
| 103 |     ADD_ENUM_TEST(NoHandle); | 
| 104 |     ADD_ENUM_TEST(GLTextureHandle); | 
| 105 |     ADD_ENUM_TEST(XvShmImageHandle); | 
| 106 |     ADD_ENUM_TEST(QPixmapHandle); | 
| 107 |     ADD_ENUM_TEST(CoreImageHandle); | 
| 108 |  | 
| 109 |     // User handles are different | 
| 110 |  | 
| 111 |     QTest::newRow(dataTag: "user1" ) | 
| 112 |             << QAbstractVideoBuffer::UserHandle << QString::fromLatin1(str: "UserHandle(1000)" ); | 
| 113 |     QTest::newRow(dataTag: "user2" ) | 
| 114 |             << QAbstractVideoBuffer::HandleType(QAbstractVideoBuffer::UserHandle + 1) << QString::fromLatin1(str: "UserHandle(1001)" ); | 
| 115 | } | 
| 116 |  | 
| 117 | void tst_QAbstractVideoBuffer::handleType() | 
| 118 | { | 
| 119 |     QFETCH(QAbstractVideoBuffer::HandleType, type); | 
| 120 |     QFETCH(QString, stringized); | 
| 121 |  | 
| 122 |     QtTestVideoBuffer buffer(type); | 
| 123 |  | 
| 124 |     QCOMPARE(buffer.handleType(), type); | 
| 125 |  | 
| 126 |     QTest::ignoreMessage(type: QtDebugMsg, message: stringized.toLatin1().constData()); | 
| 127 |     qDebug() << type; | 
| 128 | } | 
| 129 |  | 
| 130 | void tst_QAbstractVideoBuffer::handle() | 
| 131 | { | 
| 132 |     QtTestVideoBuffer buffer(QAbstractVideoBuffer::NoHandle); | 
| 133 |  | 
| 134 |     QVERIFY(buffer.handle().isNull()); | 
| 135 | } | 
| 136 |  | 
| 137 | void tst_QAbstractVideoBuffer::mapMode() | 
| 138 | { | 
| 139 |     QtTestVideoBuffer maptest(QAbstractVideoBuffer::NoHandle); | 
| 140 |     QVERIFY2(maptest.mapMode() == QAbstractVideoBuffer::ReadWrite, "ReadWrite Failed" ); | 
| 141 | } | 
| 142 |  | 
| 143 | void tst_QAbstractVideoBuffer::mapModeDebug_data() | 
| 144 | { | 
| 145 |     QTest::addColumn<QAbstractVideoBuffer::MapMode>(name: "mapMode" ); | 
| 146 |     QTest::addColumn<QString>(name: "stringized" ); | 
| 147 |  | 
| 148 |     ADD_ENUM_TEST(NotMapped); | 
| 149 |     ADD_ENUM_TEST(ReadOnly); | 
| 150 |     ADD_ENUM_TEST(WriteOnly); | 
| 151 |     ADD_ENUM_TEST(ReadWrite); | 
| 152 | } | 
| 153 |  | 
| 154 | void tst_QAbstractVideoBuffer::mapModeDebug() | 
| 155 | { | 
| 156 |     QFETCH(QAbstractVideoBuffer::MapMode, mapMode); | 
| 157 |     QFETCH(QString, stringized); | 
| 158 |  | 
| 159 |     QTest::ignoreMessage(type: QtDebugMsg, message: stringized.toLatin1().constData()); | 
| 160 |     qDebug() << mapMode; | 
| 161 | } | 
| 162 |  | 
| 163 | QTEST_MAIN(tst_QAbstractVideoBuffer) | 
| 164 |  | 
| 165 | #include "tst_qabstractvideobuffer.moc" | 
| 166 |  |