1 /**************************************************************************************** 2 * Copyright (c) 2010-2012 Leo Franchi <lfranchi@kde.org> * 3 * Copyright (c) 2011 Jeff Mitchell <mitchell@kde.org> * 4 * * 5 * This program is free software; you can redistribute it and/or modify it under * 6 * the terms of the GNU General Public License as published by the Free Software * 7 * Foundation; either version 2 of the License, or (at your option) any later * 8 * version. * 9 * * 10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 12 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License along with * 15 * this program. If not, see <http://www.gnu.org/licenses/>. * 16 ****************************************************************************************/ 17 18 #ifndef ECHONEST_TRACK_TEST_H 19 #define ECHONEST_TRACK_TEST_H 20 21 #include <QtTest/QtTest> 22 #include <QNetworkAccessManager> 23 #include <QThread> 24 25 #include "Config.h" 26 #include "Track.h" 27 28 static QThread* s_mainThread; 29 30 class TrackTest : public QObject 31 { 32 Q_OBJECT 33 private slots: 34 void initTestCase(); 35 36 void testAnalyzeFromMD5(); 37 void testAnalyzerFromId(); 38 void testProfileFromMD5(); 39 void testProfileFromId(); 40 41 void testThreads(); 42 43 private: 44 void testUploadLocalFile(); // slow and uploads an mp3, only enable on demand 45 void verifyTrack1( const Echonest::Track& track ); 46 void verifyTrack2( const Echonest::Track& track ); 47 }; 48 49 class TrackTestThreadObject : public QObject 50 { 51 Q_OBJECT 52 53 public: TrackTestThreadObject()54 TrackTestThreadObject() 55 { 56 } 57 ~TrackTestThreadObject()58 virtual ~TrackTestThreadObject() 59 { 60 } 61 62 public slots: go()63 void go() 64 { 65 Echonest::Config::instance()->setNetworkAccessManager( new QNetworkAccessManager() ); 66 67 QByteArray id = "TROICNF12B048DE990"; 68 QNetworkReply* reply = Echonest::Track::analyzeTrackId( id, true ); 69 QEventLoop loop; 70 loop.connect( reply, SIGNAL(finished()), SLOT(quit()) ); 71 loop.exec(); 72 73 QVERIFY( reply->error() == QNetworkReply::NoError ); 74 qDebug() << "main thread is " << s_mainThread << " and current thread is " << QThread::currentThread(); 75 QVERIFY( QThread::currentThread() != s_mainThread ); 76 QThread::currentThread()->quit(); 77 } 78 79 }; 80 81 82 #endif 83