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 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#include <QtTest/QtTest>
30#include <QDebug>
31
32#include <qcamera.h>
33#include <qcamerainfo.h>
34
35#include "mockcameraservice.h"
36#include "mockmediaserviceprovider.h"
37
38QT_USE_NAMESPACE
39
40class tst_QCameraInfo: public QObject
41{
42 Q_OBJECT
43
44public slots:
45 void initTestCase();
46 void init();
47 void cleanup();
48
49private slots:
50 void constructor();
51 void defaultCamera();
52 void availableCameras();
53 void equality_operators();
54
55private:
56 MockSimpleCameraService *mockSimpleCameraService;
57 MockCameraService *mockCameraService;
58 MockMediaServiceProvider *provider;
59};
60
61void tst_QCameraInfo::initTestCase()
62{
63}
64
65void tst_QCameraInfo::init()
66{
67 provider = new MockMediaServiceProvider;
68 mockSimpleCameraService = new MockSimpleCameraService;
69 mockCameraService = new MockCameraService;
70
71 provider->service = mockCameraService;
72 QMediaServiceProvider::setDefaultServiceProvider(provider);
73}
74
75void tst_QCameraInfo::cleanup()
76{
77 delete provider;
78 delete mockCameraService;
79 delete mockSimpleCameraService;
80}
81
82void tst_QCameraInfo::constructor()
83{
84 // Service doesn't implement QVideoDeviceSelectorControl
85 // QCameraInfo should not be valid in this case
86 provider->service = mockSimpleCameraService;
87
88 {
89 QCamera camera;
90 QCameraInfo info(camera);
91 QVERIFY(info.isNull());
92 QVERIFY(info.deviceName().isEmpty());
93 QVERIFY(info.description().isEmpty());
94 QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
95 QCOMPARE(info.orientation(), 0);
96 }
97
98 // Service implements QVideoDeviceSelectorControl
99 provider->service = mockCameraService;
100
101 {
102 // default camera
103 QCamera camera;
104 QCameraInfo info(camera);
105 QVERIFY(!info.isNull());
106 QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
107 QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
108 QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
109 QCOMPARE(info.orientation(), 0);
110 }
111
112 QCamera camera("backcamera");
113 QCameraInfo info(camera);
114 QVERIFY(!info.isNull());
115 QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
116 QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
117 QCOMPARE(info.position(), QCamera::BackFace);
118 QCOMPARE(info.orientation(), 90);
119
120 QCameraInfo info2(info);
121 QVERIFY(!info2.isNull());
122 QCOMPARE(info2.deviceName(), QStringLiteral("backcamera"));
123 QCOMPARE(info2.description(), QStringLiteral("backcamera desc"));
124 QCOMPARE(info2.position(), QCamera::BackFace);
125 QCOMPARE(info2.orientation(), 90);
126}
127
128void tst_QCameraInfo::defaultCamera()
129{
130 provider->service = mockCameraService;
131
132 QCameraInfo info = QCameraInfo::defaultCamera();
133
134 QVERIFY(!info.isNull());
135 QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
136 QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
137 QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
138 QCOMPARE(info.orientation(), 0);
139
140 QCamera camera(info);
141 QCOMPARE(QCameraInfo(camera), info);
142}
143
144void tst_QCameraInfo::availableCameras()
145{
146 provider->service = mockCameraService;
147
148 QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
149 QCOMPARE(cameras.count(), 2);
150
151 QCameraInfo info = cameras.at(i: 0);
152 QVERIFY(!info.isNull());
153 QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
154 QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
155 QCOMPARE(info.position(), QCamera::BackFace);
156 QCOMPARE(info.orientation(), 90);
157
158 info = cameras.at(i: 1);
159 QVERIFY(!info.isNull());
160 QCOMPARE(info.deviceName(), QStringLiteral("othercamera"));
161 QCOMPARE(info.description(), QStringLiteral("othercamera desc"));
162 QCOMPARE(info.position(), QCamera::UnspecifiedPosition);
163 QCOMPARE(info.orientation(), 0);
164
165 cameras = QCameraInfo::availableCameras(position: QCamera::BackFace);
166 QCOMPARE(cameras.count(), 1);
167 info = cameras.at(i: 0);
168 QVERIFY(!info.isNull());
169 QCOMPARE(info.deviceName(), QStringLiteral("backcamera"));
170 QCOMPARE(info.description(), QStringLiteral("backcamera desc"));
171 QCOMPARE(info.position(), QCamera::BackFace);
172 QCOMPARE(info.orientation(), 90);
173
174 cameras = QCameraInfo::availableCameras(position: QCamera::FrontFace);
175 QCOMPARE(cameras.count(), 0);
176}
177
178void tst_QCameraInfo::equality_operators()
179{
180 provider->service = mockCameraService;
181
182 QCameraInfo defaultCamera = QCameraInfo::defaultCamera();
183 QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
184
185 QVERIFY(defaultCamera == cameras.at(1));
186 QVERIFY(defaultCamera != cameras.at(0));
187 QVERIFY(cameras.at(0) != cameras.at(1));
188
189 {
190 QCamera camera(defaultCamera);
191 QVERIFY(QCameraInfo(camera) == defaultCamera);
192 QVERIFY(QCameraInfo(camera) == cameras.at(1));
193 }
194
195 {
196 QCamera camera(cameras.at(i: 0));
197 QVERIFY(QCameraInfo(camera) == cameras.at(0));
198 }
199}
200
201
202QTEST_MAIN(tst_QCameraInfo)
203
204#include "tst_qcamerainfo.moc"
205

source code of qtmultimedia/tests/auto/unit/qcamerainfo/tst_qcamerainfo.cpp