1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/****************************************************************************************
* Copyright (c) 2012 Jasneet Singh Bhatti <jazneetbhatti@gmail.com> *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "TestCollection.h"
#include "core/capabilities/ActionsCapability.h"
#include "core/capabilities/BookmarkThisCapability.h"
#include "core/collections/Collection.h"
#include "core/collections/CollectionLocation.h"
#include <QIcon>
using namespace Collections;
/**
* Ad-hoc mock to test location() method of Collection
*/
class CollectionMock : public Collection
{
public:
/**
* Mock implementations of pure virtual methods of class Collections::Collection
* to enable creation of an instance of this mock class
*
* NOT TO BE USED ANYWHERE IN THE TEST
*/
QueryMaker *queryMaker() override
{
Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called");
return nullptr;
}
QString collectionId() const override
{
Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called");
return QString();
}
QString prettyName() const override
{
Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called");
return QString();
}
QIcon icon() const override
{
Q_ASSERT_X( false, __PRETTY_FUNCTION__, "should not be called");
return QIcon();
}
};
/**
* Ad-hoc mock to reimplement isWritable() and isOrganizable() methods of
* CollectionLocation to incorporate multiple test cases
*/
class CollectionLocationMock : public CollectionLocation
{
public:
bool isWritable() const override
{
QFETCH( bool, isWritable );
return isWritable;
}
bool isOrganizable() const override
{
QFETCH( bool, isOrganizable );
return isOrganizable;
}
};
/**
* Ad-hoc mock to test isWritable() and isOrganizable() methods of Collection
* with multiple test cases
*/
class TestingCollectionMock : public CollectionMock
{
public:
Collections::CollectionLocation *location() override
{
return new CollectionLocationMock();
}
};
QTEST_MAIN( TestCollection )
void
TestCollection::initTestCase()
{
m_collection1 = new CollectionMock();
m_collection2 = new TestingCollectionMock();
m_trackProvider = new TrackProvider();
}
void
TestCollection::cleanupTestCase()
{
delete( m_collection1 );
delete( m_collection2 );
delete( m_trackProvider );
}
// TrackProvider
void
TestCollection::testTrackForUrl()
{
// Always returns a shared pointer pointing to null by default
QUrl url;
QVERIFY( m_trackProvider->trackForUrl( url ).isNull() );
}
// Collection
void
TestCollection::testLocation()
{
CollectionLocation *collectionLocation = m_collection1->location();
QVERIFY( collectionLocation );
delete( collectionLocation );
}
void
TestCollection::testIsWritable_data()
{
QTest::addColumn<bool>( "isWritable" );
QTest::newRow( "true value" ) << true;
QTest::newRow( "false value" ) << false;
}
void
TestCollection::testIsWritable()
{
CollectionLocationMock *collectionLocationMock = new CollectionLocationMock();
QCOMPARE( m_collection2->isWritable(), collectionLocationMock->isWritable() );
delete( collectionLocationMock );
}
void
TestCollection::testIsOrganizable_data()
{
QTest::addColumn<bool>( "isOrganizable" );
QTest::newRow( "true value" ) << true;
QTest::newRow( "false value" ) << false;
}
void
TestCollection::testIsOrganizable()
{
CollectionLocationMock *collectionLocationMock = new CollectionLocationMock();
QCOMPARE( m_collection2->isOrganizable(), collectionLocationMock->isOrganizable() );
delete( collectionLocationMock );
}
|