qtmobility/tests/auto/qaudiodeviceinfo/tst_qaudiodeviceinfo.cpp
changeset 14 6fbed849b4f4
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 
       
    43 #include <QtTest/QtTest>
       
    44 #include <QtCore/qlocale.h>
       
    45 #include <qaudiodeviceinfo.h>
       
    46 
       
    47 #include <QStringList>
       
    48 #include <QList>
       
    49 
       
    50 
       
    51 class tst_QAudioDeviceInfo : public QObject
       
    52 {
       
    53     Q_OBJECT
       
    54 public:
       
    55     tst_QAudioDeviceInfo(QObject* parent=0) : QObject(parent) {}
       
    56 
       
    57 private slots:
       
    58     void initTestCase();
       
    59     void checkAvailableDefaultInput();
       
    60     void checkAvailableDefaultOutput();
       
    61     void outputList();
       
    62     void codecs();
       
    63     void channels();
       
    64     void sampleSizes();
       
    65     void byteOrders();
       
    66     void sampleTypes();
       
    67     void frequencies();
       
    68     void isformat();
       
    69     void preferred();
       
    70     void nearest();
       
    71 
       
    72 private:
       
    73     bool              available;
       
    74     QAudioDeviceInfo* device;
       
    75 };
       
    76 
       
    77 void tst_QAudioDeviceInfo::initTestCase()
       
    78 {
       
    79     // Only perform tests if audio output device exists!
       
    80     QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
       
    81     if(devices.size() > 0)
       
    82         available = true;
       
    83     else {
       
    84         qWarning()<<"NOTE: no audio output device found, no test will be performed";
       
    85         available = false;
       
    86     }
       
    87 }
       
    88 
       
    89 void tst_QAudioDeviceInfo::checkAvailableDefaultInput()
       
    90 {
       
    91     // Only perform tests if audio input device exists!
       
    92     bool storeAvailable = available;
       
    93     QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
       
    94     if(devices.size() > 0)
       
    95         available = true;
       
    96     else {
       
    97         qWarning()<<"NOTE: no audio input device found, no test will be performed";
       
    98         available = false;
       
    99     }
       
   100     if(available)
       
   101         QVERIFY(!QAudioDeviceInfo::defaultInputDevice().isNull());
       
   102     available = storeAvailable;
       
   103 }
       
   104 
       
   105 void tst_QAudioDeviceInfo::checkAvailableDefaultOutput()
       
   106 {
       
   107     if(available)
       
   108         QVERIFY(!QAudioDeviceInfo::defaultOutputDevice().isNull());
       
   109 }
       
   110 
       
   111 void tst_QAudioDeviceInfo::outputList()
       
   112 {
       
   113     if(available) {
       
   114         QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
       
   115         QVERIFY(devices.size() > 0);
       
   116         device = new QAudioDeviceInfo(devices.at(0));
       
   117     }
       
   118 }
       
   119 
       
   120 void tst_QAudioDeviceInfo::codecs()
       
   121 {
       
   122     if(available) {
       
   123         QStringList avail = device->supportedCodecs();
       
   124         QVERIFY(avail.size() > 0);
       
   125     }
       
   126 }
       
   127 
       
   128 void tst_QAudioDeviceInfo::channels()
       
   129 {
       
   130     if(available) {
       
   131         QList<int> avail = device->supportedChannels();
       
   132         QVERIFY(avail.size() > 0);
       
   133     }
       
   134 }
       
   135 
       
   136 void tst_QAudioDeviceInfo::sampleSizes()
       
   137 {
       
   138     if(available) {
       
   139         QList<int> avail = device->supportedSampleSizes();
       
   140         QVERIFY(avail.size() > 0);
       
   141     }
       
   142 }
       
   143 
       
   144 void tst_QAudioDeviceInfo::byteOrders()
       
   145 {
       
   146     if(available) {
       
   147         QList<QAudioFormat::Endian> avail = device->supportedByteOrders();
       
   148         QVERIFY(avail.size() > 0);
       
   149     }
       
   150 }
       
   151 
       
   152 void tst_QAudioDeviceInfo::sampleTypes()
       
   153 {
       
   154     if(available) {
       
   155         QList<QAudioFormat::SampleType> avail = device->supportedSampleTypes();
       
   156         QVERIFY(avail.size() > 0);
       
   157     }
       
   158 }
       
   159 
       
   160 void tst_QAudioDeviceInfo::frequencies()
       
   161 {
       
   162     if(available) {
       
   163         QList<int> avail = device->supportedFrequencies();
       
   164         QVERIFY(avail.size() > 0);
       
   165     }
       
   166 }
       
   167 
       
   168 void tst_QAudioDeviceInfo::isformat()
       
   169 {
       
   170     if(available) {
       
   171         QAudioFormat     format;
       
   172         format.setFrequency(44100);
       
   173         format.setChannels(2);
       
   174         format.setSampleType(QAudioFormat::SignedInt);
       
   175         format.setByteOrder(QAudioFormat::LittleEndian);
       
   176         format.setSampleSize(16);
       
   177         format.setCodec("audio/pcm");
       
   178 
       
   179         // Should always be true for these format
       
   180         QVERIFY(device->isFormatSupported(format));
       
   181     }
       
   182 }
       
   183 
       
   184 void tst_QAudioDeviceInfo::preferred()
       
   185 {
       
   186     if(available) {
       
   187         QAudioFormat format = device->preferredFormat();
       
   188         QVERIFY(format.frequency() == 44100);
       
   189         QVERIFY(format.channels() == 2);
       
   190     }
       
   191 }
       
   192 
       
   193 void tst_QAudioDeviceInfo::nearest()
       
   194 {
       
   195     if(available) {
       
   196         /*
       
   197         QAudioFormat format1, format2;
       
   198         format1.setFrequency(8000);
       
   199         format2 = device->nearestFormat(format1);
       
   200         QVERIFY(format2.frequency() == 44100);
       
   201         */
       
   202     }
       
   203 }
       
   204 
       
   205 QTEST_MAIN(tst_QAudioDeviceInfo)
       
   206 
       
   207 #include "tst_qaudiodeviceinfo.moc"