File indexing completed on 2024-06-09 04:46:04
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 "TestMetaAlbumKey.h" 0017 0018 #include "amarokconfig.h" 0019 #include "config-amarok-test.h" 0020 #include "core/meta/Meta.h" 0021 #include "core/meta/support/MetaKeys.h" 0022 #include "core-impl/collections/support/CollectionManager.h" 0023 0024 0025 QTEST_MAIN( TestMetaAlbumKey ) 0026 0027 TestMetaAlbumKey::~TestMetaAlbumKey() 0028 { 0029 } 0030 0031 void 0032 TestMetaAlbumKey::initTestCase() 0033 { 0034 AmarokConfig::instance("amarokrc"); 0035 0036 // Artist Name - Amarok Album Name - Amarok Test Album 0037 m_track1 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album/Track01.ogg" )) ); 0038 0039 // Artist Name - Amarok Album Name - Amarok Test Album 2 0040 m_track2 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album2/Track01.ogg" )) ); 0041 0042 // Artist Name - Amarok 2 Album Name - Amarok Test Album 2 0043 m_track3 = CollectionManager::instance()->trackForUrl( QUrl::fromLocalFile(dataPath( "data/audio/album2/Track02.ogg" )) ); 0044 0045 m_album1 = m_track1->album(); 0046 m_album2 = m_track2->album(); 0047 m_album3 = m_track3->album(); 0048 } 0049 0050 QString 0051 TestMetaAlbumKey::dataPath( const QString &relPath ) 0052 { 0053 return QDir::toNativeSeparators( QString( AMAROK_TEST_DIR ) + '/' + relPath ); 0054 } 0055 0056 void 0057 TestMetaAlbumKey::testAlbumKey() 0058 { 0059 Meta::AlbumKey albumKey1( m_album1 ); 0060 0061 QCOMPARE( albumKey1.m_albumName, m_album1->name() ); 0062 QCOMPARE( albumKey1.m_artistName, m_album1->albumArtist()->name() ); 0063 } 0064 0065 void 0066 TestMetaAlbumKey::testOperatorAssignment() 0067 { 0068 // For Constructor : AlbumKey( const AlbumPtr &album ) 0069 Meta::AlbumKey albumKey1( m_album1 ), albumKey2( m_album2 ), tempAlbumKey; 0070 0071 QVERIFY( !( albumKey1 == albumKey2 ) ); 0072 0073 tempAlbumKey = albumKey1; 0074 QCOMPARE( albumKey1, tempAlbumKey ); 0075 0076 // For Constructor : AlbumKey( const QString &name, const QString &artistName ) 0077 Meta::AlbumKey albumKey3( "Artist 1", "Album 1" ), albumKey4( "Artist 2", "Album 2" ); 0078 0079 QVERIFY( !( albumKey1 == albumKey2 ) ); 0080 0081 tempAlbumKey = albumKey1; 0082 QCOMPARE( albumKey1, tempAlbumKey ); 0083 } 0084 0085 void 0086 TestMetaAlbumKey::testOperatorLessThan() 0087 { 0088 // For Constructor : AlbumKey( const AlbumPtr &album ) 0089 Meta::AlbumKey albumKey1( m_album1 ), albumKey2( m_album2 ), albumKey3( m_album3 ); 0090 0091 // Same artist name, different album name 0092 QVERIFY( albumKey1 < albumKey2 ); 0093 0094 // Same artist name, same album name 0095 QVERIFY( !( albumKey1 < albumKey1 ) ); 0096 0097 // Different artist name, same album name 0098 QVERIFY( albumKey2 < albumKey3 ); 0099 0100 // Different artist name, different album name 0101 QVERIFY( albumKey1 < albumKey3 ); 0102 0103 // For Constructor : AlbumKey( const QString &name, const QString &artistName ) 0104 Meta::AlbumKey albumKey4( "Artist 1", "Album 1" ), albumKey5( "Artist 1", "Album 2" ), 0105 albumKey6( "Artist 2", "Album 2" ); 0106 0107 // Same artist name, different album name 0108 QVERIFY( albumKey4 < albumKey5 ); 0109 0110 // Same artist name, same album name 0111 QVERIFY( !( albumKey4 < albumKey4 ) ); 0112 0113 // Different artist name, same album name 0114 QVERIFY( albumKey5 < albumKey6 ); 0115 0116 // Different artist name, different album name 0117 QVERIFY( albumKey4 < albumKey6 ); 0118 }