1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
43 #include <QtTest/QtTest>
44 #include <QtCore/qlocale.h>
45 #include <qaudioformat.h>
46 
47 #include <QStringList>
48 #include <QList>
49 
50 
51 class tst_QAudioFormat : public QObject
52 {
53     Q_OBJECT
54 
55 public:
tst_QAudioFormat(QObject * parent=0)56     tst_QAudioFormat(QObject* parent=0) : QObject(parent) {}
57 
58 private slots:
59     void checkNull();
60     void checkFrequency();
61     void checkChannels();
62     void checkSampleSize();
63     void checkCodec();
64     void checkByteOrder();
65     void checkSampleType();
66     void checkEquality();
67     void checkAssignment();
68 };
69 
checkNull()70 void tst_QAudioFormat::checkNull()
71 {
72     // Default constructed QAudioFormat is invalid.
73     QAudioFormat    audioFormat0;
74     QVERIFY(!audioFormat0.isValid());
75 
76     // validity is transferred
77     QAudioFormat    audioFormat1(audioFormat0);
78     QVERIFY(!audioFormat1.isValid());
79 
80     audioFormat0.setFrequency(44100);
81     audioFormat0.setChannels(2);
82     audioFormat0.setSampleSize(16);
83     audioFormat0.setCodec("audio/pcm");
84     audioFormat0.setSampleType(QAudioFormat::SignedInt);
85     QVERIFY(audioFormat0.isValid());
86 }
87 
checkFrequency()88 void tst_QAudioFormat::checkFrequency()
89 {
90     QAudioFormat    audioFormat;
91     audioFormat.setFrequency(44100);
92     QVERIFY(audioFormat.frequency() == 44100);
93 }
94 
checkChannels()95 void tst_QAudioFormat::checkChannels()
96 {
97     QAudioFormat    audioFormat;
98     audioFormat.setChannels(2);
99     QVERIFY(audioFormat.channels() == 2);
100 }
101 
checkSampleSize()102 void tst_QAudioFormat::checkSampleSize()
103 {
104     QAudioFormat    audioFormat;
105     audioFormat.setSampleSize(16);
106     QVERIFY(audioFormat.sampleSize() == 16);
107 }
108 
checkCodec()109 void tst_QAudioFormat::checkCodec()
110 {
111     QAudioFormat    audioFormat;
112     audioFormat.setCodec(QString::fromLatin1("audio/pcm"));
113     QVERIFY(audioFormat.codec() == QString::fromLatin1("audio/pcm"));
114 }
115 
checkByteOrder()116 void tst_QAudioFormat::checkByteOrder()
117 {
118     QAudioFormat    audioFormat;
119     audioFormat.setByteOrder(QAudioFormat::LittleEndian);
120     QVERIFY(audioFormat.byteOrder() == QAudioFormat::LittleEndian);
121 }
122 
checkSampleType()123 void tst_QAudioFormat::checkSampleType()
124 {
125     QAudioFormat    audioFormat;
126     audioFormat.setSampleType(QAudioFormat::SignedInt);
127     QVERIFY(audioFormat.sampleType() == QAudioFormat::SignedInt);
128 }
129 
checkEquality()130 void tst_QAudioFormat::checkEquality()
131 {
132     QAudioFormat    audioFormat0;
133     QAudioFormat    audioFormat1;
134 
135     // Null formats are equivalent
136     QVERIFY(audioFormat0 == audioFormat1);
137     QVERIFY(!(audioFormat0 != audioFormat1));
138 
139     // on filled formats
140     audioFormat0.setFrequency(8000);
141     audioFormat0.setChannels(1);
142     audioFormat0.setSampleSize(8);
143     audioFormat0.setCodec("audio/pcm");
144     audioFormat0.setByteOrder(QAudioFormat::LittleEndian);
145     audioFormat0.setSampleType(QAudioFormat::UnSignedInt);
146 
147     audioFormat1.setFrequency(8000);
148     audioFormat1.setChannels(1);
149     audioFormat1.setSampleSize(8);
150     audioFormat1.setCodec("audio/pcm");
151     audioFormat1.setByteOrder(QAudioFormat::LittleEndian);
152     audioFormat1.setSampleType(QAudioFormat::UnSignedInt);
153 
154     QVERIFY(audioFormat0 == audioFormat1);
155     QVERIFY(!(audioFormat0 != audioFormat1));
156 
157     audioFormat0.setFrequency(44100);
158     QVERIFY(audioFormat0 != audioFormat1);
159     QVERIFY(!(audioFormat0 == audioFormat1));
160 }
161 
checkAssignment()162 void tst_QAudioFormat::checkAssignment()
163 {
164     QAudioFormat    audioFormat0;
165     QAudioFormat    audioFormat1;
166 
167     audioFormat0.setFrequency(8000);
168     audioFormat0.setChannels(1);
169     audioFormat0.setSampleSize(8);
170     audioFormat0.setCodec("audio/pcm");
171     audioFormat0.setByteOrder(QAudioFormat::LittleEndian);
172     audioFormat0.setSampleType(QAudioFormat::UnSignedInt);
173 
174     audioFormat1 = audioFormat0;
175     QVERIFY(audioFormat1 == audioFormat0);
176 
177     QAudioFormat    audioFormat2(audioFormat0);
178     QVERIFY(audioFormat2 == audioFormat0);
179 }
180 
181 QTEST_MAIN(tst_QAudioFormat)
182 
183 #include "tst_qaudioformat.moc"
184