File indexing completed on 2024-05-12 04:49:41
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 "TestCollection.h" 0017 0018 #include "core/capabilities/ActionsCapability.h" 0019 #include "core/capabilities/BookmarkThisCapability.h" 0020 #include "core/collections/Collection.h" 0021 #include "core/collections/CollectionLocation.h" 0022 0023 #include <QIcon> 0024 0025 0026 using namespace Collections; 0027 0028 /** 0029 * Ad-hoc mock to test location() method of Collection 0030 */ 0031 class CollectionMock : public Collection 0032 { 0033 public: 0034 /** 0035 * Mock implementations of pure virtual methods of class Collections::Collection 0036 * to enable creation of an instance of this mock class 0037 * 0038 * NOT TO BE USED ANYWHERE IN THE TEST 0039 */ 0040 QueryMaker *queryMaker() override 0041 { 0042 Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called"); 0043 return nullptr; 0044 } 0045 0046 QString collectionId() const override 0047 { 0048 Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called"); 0049 return QString(); 0050 } 0051 0052 QString prettyName() const override 0053 { 0054 Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called"); 0055 return QString(); 0056 } 0057 0058 QIcon icon() const override 0059 { 0060 Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called"); 0061 return QIcon(); 0062 } 0063 }; 0064 0065 /** 0066 * Ad-hoc mock to reimplement isWritable() and isOrganizable() methods of 0067 * CollectionLocation to incorporate multiple test cases 0068 */ 0069 class CollectionLocationMock : public CollectionLocation 0070 { 0071 public: 0072 bool isWritable() const override 0073 { 0074 QFETCH( bool, isWritable ); 0075 return isWritable; 0076 } 0077 0078 bool isOrganizable() const override 0079 { 0080 QFETCH( bool, isOrganizable ); 0081 return isOrganizable; 0082 } 0083 }; 0084 0085 /** 0086 * Ad-hoc mock to test isWritable() and isOrganizable() methods of Collection 0087 * with multiple test cases 0088 */ 0089 class TestingCollectionMock : public CollectionMock 0090 { 0091 public: 0092 Collections::CollectionLocation *location() override 0093 { 0094 return new CollectionLocationMock(); 0095 } 0096 }; 0097 0098 0099 QTEST_MAIN( TestCollection ) 0100 0101 void 0102 TestCollection::initTestCase() 0103 { 0104 m_collection1 = new CollectionMock(); 0105 m_collection2 = new TestingCollectionMock(); 0106 m_trackProvider = new TrackProvider(); 0107 } 0108 0109 void 0110 TestCollection::cleanupTestCase() 0111 { 0112 delete( m_collection1 ); 0113 delete( m_collection2 ); 0114 delete( m_trackProvider ); 0115 } 0116 0117 // TrackProvider 0118 void 0119 TestCollection::testTrackForUrl() 0120 { 0121 // Always returns a shared pointer pointing to null by default 0122 QUrl url; 0123 QVERIFY( m_trackProvider->trackForUrl( url ).isNull() ); 0124 } 0125 0126 // Collection 0127 void 0128 TestCollection::testLocation() 0129 { 0130 CollectionLocation *collectionLocation = m_collection1->location(); 0131 QVERIFY( collectionLocation ); 0132 delete( collectionLocation ); 0133 } 0134 0135 void 0136 TestCollection::testIsWritable_data() 0137 { 0138 QTest::addColumn<bool>( "isWritable" ); 0139 0140 QTest::newRow( "true value" ) << true; 0141 QTest::newRow( "false value" ) << false; 0142 } 0143 0144 void 0145 TestCollection::testIsWritable() 0146 { 0147 CollectionLocationMock *collectionLocationMock = new CollectionLocationMock(); 0148 QCOMPARE( m_collection2->isWritable(), collectionLocationMock->isWritable() ); 0149 delete( collectionLocationMock ); 0150 } 0151 0152 void 0153 TestCollection::testIsOrganizable_data() 0154 { 0155 QTest::addColumn<bool>( "isOrganizable" ); 0156 0157 QTest::newRow( "true value" ) << true; 0158 QTest::newRow( "false value" ) << false; 0159 } 0160 0161 void 0162 TestCollection::testIsOrganizable() 0163 { 0164 CollectionLocationMock *collectionLocationMock = new CollectionLocationMock(); 0165 QCOMPARE( m_collection2->isOrganizable(), collectionLocationMock->isOrganizable() ); 0166 delete( collectionLocationMock ); 0167 }