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 | #include <qmediaobject.h> |
33 | #include <qmediacontrol.h> |
34 | #include <qmediaservice.h> |
35 | #include <qmediarecordercontrol.h> |
36 | #include <qmediarecorder.h> |
37 | #include <qmetadatawritercontrol.h> |
38 | #include <qaudioinputselectorcontrol.h> |
39 | #include <qaudioencodersettingscontrol.h> |
40 | #include <qmediacontainercontrol.h> |
41 | #include <qvideoencodersettingscontrol.h> |
42 | #include <qaudioformat.h> |
43 | |
44 | #include "mockmediacontainercontrol.h" |
45 | #include "mockmetadatawritercontrol.h" |
46 | #include "mockmediarecordercontrol.h" |
47 | #include "mockmediaobject.h" |
48 | |
49 | QT_USE_NAMESPACE |
50 | |
51 | class TestBindableService : public QMediaService |
52 | { |
53 | Q_OBJECT |
54 | public: |
55 | TestBindableService(QObject *parent, QMediaControl *control): |
56 | QMediaService(parent), |
57 | mockControl(control), |
58 | hasControls(true) |
59 | { |
60 | mockContainerControl = new MockMediaContainerControl(parent); //Creating the object for Media |
61 | mockMetaDataControl = new MockMetaDataWriterControl(parent); //Creating the object for MetaData |
62 | } |
63 | |
64 | QMediaControl* requestControl(const char *name) |
65 | { |
66 | if (hasControls && qstrcmp(str1: name,QMediaRecorderControl_iid) == 0) |
67 | return mockControl; |
68 | if (hasControls && qstrcmp(str1: name,QMediaContainerControl_iid) == 0) |
69 | return mockContainerControl; |
70 | if (hasControls && qstrcmp(str1: name, QMetaDataWriterControl_iid) == 0) |
71 | return mockMetaDataControl; |
72 | |
73 | return 0; |
74 | } |
75 | |
76 | void releaseControl(QMediaControl*) {} |
77 | //Initialising the objects for the media |
78 | QMediaControl *mockControl; |
79 | QMediaContainerControl *mockContainerControl; |
80 | MockMetaDataWriterControl *mockMetaDataControl; |
81 | bool hasControls; |
82 | }; |
83 | |
84 | class tst_QMediaBindableInterface:public QObject |
85 | { |
86 | Q_OBJECT |
87 | private slots: |
88 | void init() |
89 | { |
90 | |
91 | } |
92 | |
93 | void cleanup() |
94 | { |
95 | |
96 | } |
97 | |
98 | void testMediaObject() //Verifying the mediaobject api |
99 | { |
100 | MockMediaRecorderControl recorderControl(0); |
101 | TestBindableService service(0, &recorderControl); |
102 | service.mockMetaDataControl->populateMetaData(); |
103 | MockMediaObject object(0, &service); |
104 | QMediaRecorder recorder(&object); |
105 | QMediaObject *obj = recorder.mediaObject(); |
106 | QVERIFY(obj != NULL); |
107 | QVERIFY(obj->isAvailable()); |
108 | } |
109 | |
110 | void testDestructor() //Invoking the destructor |
111 | { |
112 | MockMediaRecorderControl recorderControl(0); |
113 | TestBindableService service(0, &recorderControl); |
114 | service.mockMetaDataControl->populateMetaData(); |
115 | MockMediaObject object(0, &service); |
116 | QMediaRecorder *recorder = new QMediaRecorder(&object); |
117 | QVERIFY(recorder->isAvailable()); |
118 | delete recorder; |
119 | recorder = NULL; |
120 | } |
121 | }; |
122 | |
123 | QTEST_MAIN(tst_QMediaBindableInterface) |
124 | #include "tst_qmediabindableinterface.moc" |
125 | |