1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-01 18:04:05 +02:00

Add liblastfm2 and make tomahawk build against it

This commit is contained in:
Jeff Mitchell
2011-03-24 19:18:42 -04:00
parent 1780781e12
commit b7a1cb8d99
114 changed files with 14711 additions and 3 deletions

35
thirdparty/liblastfm2/tests/TestTrack.h vendored Normal file
View File

@@ -0,0 +1,35 @@
/*
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
*/
#include <QtTest>
#include <lastfm/Track>
using lastfm::Track;
class TestTrack : public QObject
{
Q_OBJECT
Track example()
{
lastfm::MutableTrack t;
t.setTitle( "Test Title" );
t.setArtist( "Test Artist" );
t.setAlbum( "Test Album" );
return t;
}
private slots:
void testClone()
{
Track original = example();
Track copy = original;
#define TEST( x ) QVERIFY( original.x == copy.x )
TEST( title() );
TEST( artist() );
TEST( album() );
#undef TEST
}
};

View File

@@ -0,0 +1,80 @@
/*
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
*/
#include <QtTest>
#include <QtNetwork>
#include <QEventLoop>
#include <lastfm/UrlBuilder>
#include <lastfm/global.h>
static inline int getResponseCode( const QUrl& url )
{
QNetworkAccessManager nam;
QNetworkReply* reply = nam.head( QNetworkRequest(url) );
QEventLoop loop;
loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
loop.exec();
int const code = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
if (reply->error() != QNetworkReply::NoError)
qDebug() << url << lastfm::qMetaEnumString<QNetworkReply>( reply->error(), "NetworkError" ) << code;
return code;
}
class TestUrlBuilder : public QObject
{
Q_OBJECT
private slots:
void encode() /** @author <jono@last.fm> */
{
QFETCH( QString, input );
QFETCH( QString, output );
QCOMPARE( lastfm::UrlBuilder::encode( input ), output.toAscii() );
}
void encode_data() /** @author <jono@last.fm> */
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("output");
QTest::newRow( "ascii" ) << "Metallica" << "Metallica";
QTest::newRow( "ascii alphanumeric" ) << "Apollo 440" << "Apollo+440";
QTest::newRow( "ascii with symbols" ) << "some track [original version]" << "some+track+%5Boriginal+version%5D";
QTest::newRow( "ascii with last.fm-special symbols" ) << "Survivalism [Revision #1]" << "Survivalism%2B%255BRevision%2B%25231%255D";
}
void no404() /** @author <max@last.fm> */
{
QFETCH( QString, artist );
QFETCH( QString, track );
QUrl url = lastfm::UrlBuilder( "music" ).slash( artist ).slash( "_" ).slash( track ).url();
QCOMPARE( getResponseCode( url ), 200 );
}
void no404_data() /** @author <max@last.fm> */
{
QTest::addColumn<QString>("artist");
QTest::addColumn<QString>("track");
#define NEW_ROW( x, y ) QTest::newRow( x " - " y ) << x << y;
NEW_ROW( "Air", "Radio #1" );
NEW_ROW( "Pink Floyd", "Speak to Me / Breathe" );
NEW_ROW( "Radiohead", "2 + 2 = 5" );
NEW_ROW( "Above & Beyond", "World On Fire (Maor Levi Remix)" );
#undef NEW_ROW
}
void test404() /** @author <max@last.fm> */
{
QCOMPARE( getResponseCode( QUrl("http://www.last.fm/404") ), 404 );
}
};

22
thirdparty/liblastfm2/tests/main.cpp vendored Normal file
View File

@@ -0,0 +1,22 @@
/*
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
*/
#include <QtCore>
#include <QtTest>
#include "TestTrack.h"
#include "TestUrlBuilder.h"
int main( int argc, char** argv)
{
QCoreApplication app( argc, argv );
#define TEST( Type ) { \
Type o; \
if (int r = QTest::qExec( &o, argc, argv ) != 0) return r; }
TEST( TestTrack );
TEST( TestUrlBuilder );
return 0;
}

4
thirdparty/liblastfm2/tests/tests.pro vendored Normal file
View File

@@ -0,0 +1,4 @@
QT = core testlib network xml
LIBS += -llastfm -L$$DESTDIR
SOURCES = main.cpp
HEADERS = TestTrack.h TestUrlBuilder.h