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
30
31#include <QtTest/QtTest>
32#include <QDebug>
33
34#include "qcameraviewfinder.h"
35#include "qcamera.h"
36#include "qmediaobject.h"
37
38#include "mockcameraservice.h"
39#include "mockmediaserviceprovider.h"
40
41class tst_QCameraViewFinder : public QObject
42{
43 Q_OBJECT
44public slots:
45 void initTestCase();
46 void cleanupTestCase();
47
48private slots:
49 void testConstructor();
50 void testMediaObject();
51
52private:
53 MockCameraService *mockcameraservice;
54 MockMediaServiceProvider *provider;
55 QCamera *camera;
56 QCameraViewfinder *viewFinder;
57};
58
59void tst_QCameraViewFinder::initTestCase()
60{
61 provider = new MockMediaServiceProvider;
62 mockcameraservice = new MockCameraService;
63 provider->service = mockcameraservice;
64 QMediaServiceProvider::setDefaultServiceProvider(provider);
65
66 camera = new QCamera;
67 viewFinder = new QCameraViewfinder();
68}
69
70void tst_QCameraViewFinder::cleanupTestCase()
71{
72 delete mockcameraservice;
73 delete provider;
74}
75
76void tst_QCameraViewFinder::testConstructor()
77{
78 /* Verify whether the object is created or not */
79 QVERIFY(viewFinder != NULL);
80 QCOMPARE(viewFinder->isVisible(),false);
81 QCOMPARE(viewFinder->isEnabled(),true);
82 viewFinder->show();
83}
84
85void tst_QCameraViewFinder::testMediaObject()
86{
87 QVERIFY(viewFinder != NULL);
88 viewFinder->show();
89 /* Sets the QVideoWidget based camera viewfinder.*/
90 camera->setViewfinder(viewFinder);
91 QCOMPARE(viewFinder->isVisible(),true);
92
93 /* Return the currently attached media object.*/
94 QMediaObject *media = viewFinder->mediaObject();
95
96 /* Verifying the object */
97 QCOMPARE(media, camera);
98}
99
100QTEST_MAIN(tst_QCameraViewFinder)
101#include "tst_qcameraviewfinder.moc"
102

source code of qtmultimedia/tests/auto/unit/qcameraviewfinder/tst_qcameraviewfinder.cpp