qtmobility/tests/auto/qaudioformat/tst_qaudioformat.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 <qaudioformat.h>
       
    46 
       
    47 #include <QStringList>
       
    48 #include <QList>
       
    49 
       
    50 
       
    51 class tst_QAudioFormat : public QObject
       
    52 {
       
    53     Q_OBJECT
       
    54 
       
    55 public:
       
    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 
       
    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 
       
    88 void tst_QAudioFormat::checkFrequency()
       
    89 {
       
    90     QAudioFormat    audioFormat;
       
    91     audioFormat.setFrequency(44100);
       
    92     QVERIFY(audioFormat.frequency() == 44100);
       
    93 }
       
    94 
       
    95 void tst_QAudioFormat::checkChannels()
       
    96 {
       
    97     QAudioFormat    audioFormat;
       
    98     audioFormat.setChannels(2);
       
    99     QVERIFY(audioFormat.channels() == 2);
       
   100 }
       
   101 
       
   102 void tst_QAudioFormat::checkSampleSize()
       
   103 {
       
   104     QAudioFormat    audioFormat;
       
   105     audioFormat.setSampleSize(16);
       
   106     QVERIFY(audioFormat.sampleSize() == 16);
       
   107 }
       
   108 
       
   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 
       
   116 void tst_QAudioFormat::checkByteOrder()
       
   117 {
       
   118     QAudioFormat    audioFormat;
       
   119     audioFormat.setByteOrder(QAudioFormat::LittleEndian);
       
   120     QVERIFY(audioFormat.byteOrder() == QAudioFormat::LittleEndian);
       
   121 }
       
   122 
       
   123 void tst_QAudioFormat::checkSampleType()
       
   124 {
       
   125     QAudioFormat    audioFormat;
       
   126     audioFormat.setSampleType(QAudioFormat::SignedInt);
       
   127     QVERIFY(audioFormat.sampleType() == QAudioFormat::SignedInt);
       
   128 }
       
   129 
       
   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 
       
   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"