File indexing completed on 2024-06-16 04:32:38

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Nikolaj Hald Nielsen <nhn@kde.com>                                *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Pulic License for more details.              *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "TestCueFileSupport.h"
0018 
0019 #include "config-amarok-test.h"
0020 #include "core-impl/meta/cue/CueFileSupport.h"
0021 
0022 #include <QtDebug>
0023 
0024 #include <QTest>
0025 
0026 
0027 QTEST_GUILESS_MAIN( TestCueFileSupport )
0028 
0029 using namespace MetaCue;
0030 
0031 TestCueFileSupport::TestCueFileSupport()
0032     : QObject()
0033 {
0034 }
0035 
0036 void TestCueFileSupport::testLocateCueFile()
0037 {
0038   //Check that we find the right .cue file and that it passes the validator
0039   QUrl cueTestUrl = QUrl::fromLocalFile(dataPath( "data/cue/testsheet01-iso8859-1.cue" ));
0040   QUrl cueResultUrl = CueFileSupport::locateCueSheet( cueTestUrl );
0041 
0042   QVERIFY( !cueResultUrl.url().isEmpty() );
0043   QCOMPARE( cueResultUrl.url(), cueTestUrl.url() );
0044 
0045   //Check that a nonexisting cue file returns an empty url
0046   QUrl testUrl = QUrl::fromLocalFile(dataPath( "data/cue/test_silence.ogg" ));
0047   cueResultUrl = CueFileSupport::locateCueSheet( testUrl );
0048 
0049   QVERIFY( cueResultUrl.isEmpty() );
0050 
0051   //Check that an existing but invalid cue file returns an empty url
0052   testUrl = QUrl::fromLocalFile(dataPath( "data/cue/invalid.cue" ));
0053   cueResultUrl = CueFileSupport::locateCueSheet( testUrl );
0054 
0055   QVERIFY( cueResultUrl.isEmpty() );
0056 }
0057 
0058 void TestCueFileSupport::testIso88591Cue()
0059 {
0060     QUrl testUrl = QUrl::fromLocalFile(dataPath( "data/cue/testsheet01-iso8859-1.cue" ));
0061     QUrl testTrackUrl = QUrl::fromLocalFile((QString( "Die Toten Hosen - In aller Stille (2008).mp3" )));
0062     CueFileItemMap cueItemMap = CueFileSupport::loadCueFile( testUrl, testTrackUrl, 48000 );
0063 
0064     QCOMPARE( cueItemMap.size(), 14 );
0065     QCOMPARE( cueItemMap.value( cueItemMap.keys()[2] ).title(), QString( "Disco" ) );
0066     QCOMPARE( cueItemMap.value( cueItemMap.keys()[2] ).artist(), QString( "Die Toten Hosen" ) );
0067 }
0068 
0069 void TestCueFileSupport::testUtf8Cue()
0070 {
0071     QUrl testUrl = QUrl::fromLocalFile(dataPath( "data/cue/testsheet01-utf8.cue" ));
0072     QUrl testTrackUrl = QUrl::fromLocalFile(QString( "Die Toten Hosen - In aller Stille (2008).mp3" ));
0073     CueFileItemMap cueItemMap = CueFileSupport::loadCueFile( testUrl, testTrackUrl, 48000 );
0074 
0075     QCOMPARE( cueItemMap.size(), 14 );
0076     QCOMPARE( cueItemMap.value( cueItemMap.keys()[6] ).title(), QString( "Ertrinken" ) );
0077     QCOMPARE( cueItemMap.value( cueItemMap.keys()[6] ).artist(), QString( "Die Toten Hosen" ) );
0078 }
0079 
0080 QString TestCueFileSupport::dataPath( const QString &relPath )
0081 {
0082     return QDir::toNativeSeparators( QString( AMAROK_TEST_DIR ) + '/' + relPath );
0083 }