File indexing completed on 2024-04-28 04:48:05

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 "TestAmarokUrls.h"
0018 
0019 #include "core/support/Components.h"
0020 #include "EngineController.h"
0021 
0022 #include "config-amarok-test.h"
0023 
0024 #include "amarokurls/AmarokUrl.h"
0025 #include "amarokurls/AmarokUrlHandler.h"
0026 
0027 #include <QTest>
0028 
0029 QTEST_GUILESS_MAIN( TestAmarokUrls )
0030 
0031 TestAmarokUrls::TestAmarokUrls()
0032   : QObject()
0033 {
0034     //apparently the engine controller is needed somewhere, or we will get a crash...
0035     EngineController *controller = new EngineController();
0036     Amarok::Components::setEngineController( controller );
0037 }
0038 
0039 void
0040 TestAmarokUrls::testConstructUrl()
0041 {
0042 
0043     AmarokUrl url;
0044 
0045     url.setCommand( "navigate" );
0046     url.setPath( "collections" );
0047     url.setArg( "filter", "artist:\"Code Monkeys\"" );
0048     url.setArg( "levels", "artist-album" );
0049 
0050     QCOMPARE( url.command(), QString( "navigate" ) );
0051     QCOMPARE( url.path(), QString( "collections" ) );
0052     QCOMPARE( url.args().size(), 2 );
0053     QVERIFY( url.args().keys().contains( "filter" ) );
0054     QVERIFY( url.args().keys().contains( "levels" ) );
0055     QCOMPARE( url.args().value( "filter" ), QString( "artist:\"Code Monkeys\"" ) );
0056     QCOMPARE( url.args().value( "levels" ), QString( "artist-album") );
0057 
0058     QCOMPARE( url.prettyCommand(), The::amarokUrlHandler()->prettyCommand( "navigate" ) );
0059 
0060 
0061 }
0062 
0063 
0064 void
0065 TestAmarokUrls::testUrlFromString()
0066 {
0067 
0068     AmarokUrl url( "amarok://navigate/collections?filter=artist:\"Code Monkeys\"&levels=artist-album" );
0069 
0070     QCOMPARE( url.command(), QString( "navigate" ) );
0071     QCOMPARE( url.path(), QString( "collections" ) );
0072     QCOMPARE( url.args().size(), 2 );
0073     QVERIFY( url.args().keys().contains( "filter" ) );
0074     QVERIFY( url.args().keys().contains( "levels" ) );
0075     QCOMPARE( url.args().value( "filter" ), QString( "artist:\"Code Monkeys\"" ) );
0076     QCOMPARE( url.args().value( "levels" ), QString( "artist-album") );
0077 
0078     QCOMPARE( url.prettyCommand(), The::amarokUrlHandler()->prettyCommand( "navigate" ) );
0079 
0080 }
0081 
0082 void TestAmarokUrls::testEncoding()
0083 {
0084     QString urlString( "amarok://navigate/collections?filter=artist:\"Code Monkeys\"&levels=artist-album" );
0085     AmarokUrl url( urlString );
0086 
0087     QUrl qUrl( urlString );
0088 
0089     QCOMPARE( url.url(), QString( qUrl.toEncoded() ) );
0090 
0091 
0092     //check that we do  not "double encode" anything
0093     AmarokUrl url2( "amarok://navigate/collections?filter=artist:%22Code%20Monkeys%22&levels=artist-album" );
0094     QCOMPARE( url2.url(), QString( qUrl.toEncoded() ) );
0095 }
0096 
0097