diff options
author | Yoann Lopes <yoann.lopes@digia.com> | 2014-01-22 16:18:42 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-28 14:10:00 +0100 |
commit | b28ee24628f77fced393cacc45500be6761e4497 (patch) | |
tree | 811173f8a2caf84e0fa386010283ccfd32c6ad0d /tests/auto/unit/qcamerainfo | |
parent | d964388b38ec4762e315d86aacb779604bcdca1b (diff) |
New QCameraInfo class.
The class allows to get the list of available cameras on the system as
well as getting some static information about them such as their unique
ID, display name, physical position and sensor orientation.
This makes QCamera::availableDevices() and QCamera::deviceDescription()
obsolete.
This patch contains the API, documentation and auto-tests but not the
actual implementation by each backend (except for retrieving the default
camera device).
[ChangeLog][QtMultimedia] Added new QCameraInfo class
[ChangeLog][QtMultimedia] QCamera: availableDevices() and
deviceDescription() are deprecated, use QCameraInfo instead
Change-Id: I64fd65729ab26a789468979ed5444ee90bb82cd0
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
Diffstat (limited to 'tests/auto/unit/qcamerainfo')
-rw-r--r-- | tests/auto/unit/qcamerainfo/qcamerainfo.pro | 10 | ||||
-rw-r--r-- | tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp | 217 |
2 files changed, 227 insertions, 0 deletions
diff --git a/tests/auto/unit/qcamerainfo/qcamerainfo.pro b/tests/auto/unit/qcamerainfo/qcamerainfo.pro new file mode 100644 index 000000000..70cea2ded --- /dev/null +++ b/tests/auto/unit/qcamerainfo/qcamerainfo.pro @@ -0,0 +1,10 @@ +CONFIG += testcase +TARGET = tst_qcamerainfo + +QT += multimedia-private testlib + +include (../qmultimedia_common/mock.pri) +include (../qmultimedia_common/mockcamera.pri) + +SOURCES += tst_qcamerainfo.cpp +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp b/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp new file mode 100644 index 000000000..86bd05f77 --- /dev/null +++ b/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp @@ -0,0 +1,217 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QDebug> + +#include <qcamera.h> +#include <qcamerainfo.h> + +#include "mockcameraservice.h" +#include "mockmediaserviceprovider.h" + +QT_USE_NAMESPACE + +class tst_QCameraInfo: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void init(); + void cleanup(); + +private slots: + void constructor(); + void defaultCamera(); + void availableCameras(); + void equality_operators(); + +private: + MockSimpleCameraService *mockSimpleCameraService; + MockCameraService *mockCameraService; + MockMediaServiceProvider *provider; +}; + +void tst_QCameraInfo::initTestCase() +{ +} + +void tst_QCameraInfo::init() +{ + provider = new MockMediaServiceProvider; + mockSimpleCameraService = new MockSimpleCameraService; + mockCameraService = new MockCameraService; + + provider->service = mockCameraService; + QMediaServiceProvider::setDefaultServiceProvider(provider); +} + +void tst_QCameraInfo::cleanup() +{ + delete provider; + delete mockCameraService; + delete mockSimpleCameraService; +} + +void tst_QCameraInfo::constructor() +{ + // Service doesn't implement QVideoDeviceSelectorControl + // QCameraInfo should not be valid in this case + provider->service = mockSimpleCameraService; + + { + QCamera camera; + QCameraInfo info(camera); + QVERIFY(info.isNull()); + QVERIFY(info.deviceName().isEmpty()); + QVERIFY(info.description().isEmpty()); + QCOMPARE(info.position(), QCamera::UnspecifiedPosition); + QCOMPARE(info.orientation(), 0); + } + + // Service implements QVideoDeviceSelectorControl + provider->service = mockCameraService; + + { + // default camera + QCamera camera; + QCameraInfo info(camera); + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("othercamera")); + QCOMPARE(info.description(), QStringLiteral("othercamera desc")); + QCOMPARE(info.position(), QCamera::UnspecifiedPosition); + QCOMPARE(info.orientation(), 0); + } + + QCamera camera("backcamera"); + QCameraInfo info(camera); + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("backcamera")); + QCOMPARE(info.description(), QStringLiteral("backcamera desc")); + QCOMPARE(info.position(), QCamera::BackFace); + QCOMPARE(info.orientation(), 90); + + QCameraInfo info2(info); + QVERIFY(!info2.isNull()); + QCOMPARE(info2.deviceName(), QStringLiteral("backcamera")); + QCOMPARE(info2.description(), QStringLiteral("backcamera desc")); + QCOMPARE(info2.position(), QCamera::BackFace); + QCOMPARE(info2.orientation(), 90); +} + +void tst_QCameraInfo::defaultCamera() +{ + provider->service = mockCameraService; + + QCameraInfo info = QCameraInfo::defaultCamera(); + + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("othercamera")); + QCOMPARE(info.description(), QStringLiteral("othercamera desc")); + QCOMPARE(info.position(), QCamera::UnspecifiedPosition); + QCOMPARE(info.orientation(), 0); + + QCamera camera(info); + QCOMPARE(QCameraInfo(camera), info); +} + +void tst_QCameraInfo::availableCameras() +{ + provider->service = mockCameraService; + + QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); + QCOMPARE(cameras.count(), 2); + + QCameraInfo info = cameras.at(0); + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("backcamera")); + QCOMPARE(info.description(), QStringLiteral("backcamera desc")); + QCOMPARE(info.position(), QCamera::BackFace); + QCOMPARE(info.orientation(), 90); + + info = cameras.at(1); + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("othercamera")); + QCOMPARE(info.description(), QStringLiteral("othercamera desc")); + QCOMPARE(info.position(), QCamera::UnspecifiedPosition); + QCOMPARE(info.orientation(), 0); + + cameras = QCameraInfo::availableCameras(QCamera::BackFace); + QCOMPARE(cameras.count(), 1); + info = cameras.at(0); + QVERIFY(!info.isNull()); + QCOMPARE(info.deviceName(), QStringLiteral("backcamera")); + QCOMPARE(info.description(), QStringLiteral("backcamera desc")); + QCOMPARE(info.position(), QCamera::BackFace); + QCOMPARE(info.orientation(), 90); + + cameras = QCameraInfo::availableCameras(QCamera::FrontFace); + QCOMPARE(cameras.count(), 0); +} + +void tst_QCameraInfo::equality_operators() +{ + provider->service = mockCameraService; + + QCameraInfo defaultCamera = QCameraInfo::defaultCamera(); + QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); + + QVERIFY(defaultCamera == cameras.at(1)); + QVERIFY(defaultCamera != cameras.at(0)); + QVERIFY(cameras.at(0) != cameras.at(1)); + + { + QCamera camera(defaultCamera); + QVERIFY(QCameraInfo(camera) == defaultCamera); + QVERIFY(QCameraInfo(camera) == cameras.at(1)); + } + + { + QCamera camera(cameras.at(0)); + QVERIFY(QCameraInfo(camera) == cameras.at(0)); + } +} + + +QTEST_MAIN(tst_QCameraInfo) + +#include "tst_qcamerainfo.moc" |