File indexing completed on 2024-05-12 04:49:42

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Jasneet Singh Bhatti <jazneetbhatti@gmail.com>                    *
0003  * This program is free software; you can redistribute it and/or modify it under        *
0004  * the terms of the GNU General Public License as published by the Free Software        *
0005  * Foundation; either version 2 of the License, or (at your option) any later           *
0006  * version.                                                                             *
0007  *                                                                                      *
0008  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0009  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0010  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0011  *                                                                                      *
0012  * You should have received a copy of the GNU General Public License along with         *
0013  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0014  ****************************************************************************************/
0015 
0016 #include "TestPlaylistFormat.h"
0017 
0018 #include "core/playlists/PlaylistFormat.h"
0019 
0020 #include <QString>
0021 
0022 // so that PlaylistFormat can be used in QTest::addColumn()
0023 Q_DECLARE_METATYPE( Playlists::PlaylistFormat )
0024 
0025 QTEST_GUILESS_MAIN( TestPlaylistFormat )
0026 
0027 TestPlaylistFormat::TestPlaylistFormat()
0028 {
0029 }
0030 
0031 void
0032 TestPlaylistFormat::testGetFormat_data()
0033 {
0034     QTest::addColumn<QString>( "filename" );
0035     QTest::addColumn<Playlists::PlaylistFormat>( "playlistFormat" );
0036 
0037     // valid formats
0038     QTest::newRow( "m3u" ) << "playlist.m3u" << Playlists::M3U;
0039     QTest::newRow( "m3u8" ) << "playlist.m3u8" << Playlists::M3U;
0040     QTest::newRow( "pls" ) << "playlist.pls" << Playlists::PLS;
0041     QTest::newRow( "ram" ) << "playlist.ram" << Playlists::RAM;
0042     QTest::newRow( "smil" ) << "playlist.smil" << Playlists::SMIL;
0043     QTest::newRow( "asx" ) << "playlist.asx" << Playlists::ASX;
0044     QTest::newRow( "wax" ) << "playlist.wax" << Playlists::ASX;
0045     QTest::newRow( "xml" ) << "playlist.xml" << Playlists::XML;
0046     QTest::newRow( "xspf" ) << "playlist.xspf" << Playlists::XSPF;
0047 
0048     // unknown or invalid formats
0049     QTest::newRow( "vlc" ) << "playlist.vlc" << Playlists::Unknown;
0050     QTest::newRow( "invalidformat" ) << "playlist.invalidformat" << Playlists::NotPlaylist;
0051     QTest::newRow( "dotted invalid" ) << "this.is.an.invalid.format" << Playlists::NotPlaylist;
0052     QTest::newRow( "trailing dot" ) << "this.is.an.invalid.format.with.trailing.dot." << Playlists::NotPlaylist;
0053     QTest::newRow( "no dot" ) << "NoDots" << Playlists::NotPlaylist;
0054     QTest::newRow( "empty string" ) << "" << Playlists::NotPlaylist;
0055 }
0056 
0057 void
0058 TestPlaylistFormat::testGetFormat()
0059 {
0060     QFETCH( QString, filename );
0061     QFETCH( Playlists::PlaylistFormat, playlistFormat );
0062     QUrl url( "amarok:///playlists/" );
0063 
0064     url = url.adjusted(QUrl::RemoveFilename);
0065     url.setPath(url.path() +  filename );
0066     QCOMPARE( Playlists::getFormat( url ), playlistFormat );
0067     // file extensions in capitals must also pass this test
0068     url = url.adjusted(QUrl::RemoveFilename);
0069     url.setPath(url.path() +  filename.toUpper() );
0070     QCOMPARE( Playlists::getFormat( url ), playlistFormat );
0071 }
0072 
0073 void
0074 TestPlaylistFormat::testIsPlaylist_data()
0075 {
0076     QTest::addColumn<QString>( "filename" );
0077     QTest::addColumn<bool>( "isPlaylist" );
0078 
0079     // valid formats
0080     QTest::newRow( "m3u" ) << "playlist.m3u" << true;
0081     QTest::newRow( "m3u8" ) << "playlist.m3u8" << true;
0082     QTest::newRow( "pls" ) << "playlist.pls" << true;
0083     QTest::newRow( "ram" ) << "playlist.ram" << true;
0084     QTest::newRow( "smil" ) << "playlist.smil" << true;
0085     QTest::newRow( "asx" ) << "playlist.asx" << true;
0086     QTest::newRow( "wax" ) << "playlist.wax" << true;
0087     QTest::newRow( "xml" ) << "playlist.xml" << true;
0088     QTest::newRow( "xspf" ) << "playlist.xspf" << true;
0089 
0090     // unknown or invalid formats
0091     QTest::newRow( "vlc" ) << "playlist.vlc" << false;
0092     QTest::newRow( "invalidformat" ) << "playlist.invalidformat" << false;
0093     QTest::newRow( "dotted invalid" ) << "this.is.an.invalid.format" << false;
0094     QTest::newRow( "trailing dot" ) << "this.is.an.invalid.format.with.trailing.dot." << false;
0095     QTest::newRow( "no dot" ) << "NoDots" << false;
0096     QTest::newRow( "empty string" ) << "" << false;
0097 }
0098 
0099 void
0100 TestPlaylistFormat::testIsPlaylist()
0101 {
0102     QFETCH( QString, filename );
0103     QFETCH( bool, isPlaylist );
0104     QUrl url( "amarok:///playlists/" );
0105 
0106     url = url.adjusted(QUrl::RemoveFilename);
0107     url.setPath(url.path() +  filename );
0108     QCOMPARE( Playlists::isPlaylist( url ), isPlaylist );
0109     // file extensions in capitals must also pass this test
0110     url = url.adjusted(QUrl::RemoveFilename);
0111     url.setPath(url.path() +  filename.toUpper() );
0112     QCOMPARE( Playlists::isPlaylist( url ), isPlaylist );
0113 }