File: TestMetaCapability.cpp

package info (click to toggle)
amarok 3.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,168 kB
  • sloc: cpp: 195,056; xml: 4,322; ansic: 2,634; javascript: 673; ruby: 528; python: 507; sh: 252; makefile: 12
file content (108 lines) | stat: -rw-r--r-- 4,425 bytes parent folder | download | duplicates (2)
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
/****************************************************************************************
 * 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 "TestMetaCapability.h"

#include "core/capabilities/ActionsCapability.h"
#include "core/capabilities/BookmarkThisCapability.h"
#include "core/capabilities/CollectionScanCapability.h"
#include "core/capabilities/MultiSourceCapability.h"
#include "core/interfaces/MetaCapability.h"

#include <QString>

/**
 * Ad-hoc mock to test MetaCapability
 */
class MetaCapabilityMock : public MetaCapability
{
    public:
        static Capabilities::ActionsCapability *actionsCapability;
        static Capabilities::BookmarkThisCapability *bookmarkThisCapability;

        bool hasCapabilityInterface( Capabilities::Capability::Type type ) const override
        {
            switch( type )
            {
            case Capabilities::Capability::Actions:
            case Capabilities::Capability::BookmarkThis:
                return true;
            default:
                break;
            }
            return false;
        }

        Capabilities::Capability *createCapabilityInterface( Capabilities::Capability::Type type ) override
        {
            switch( type )
            {
            case Capabilities::Capability::Actions:
                return actionsCapability;
            case Capabilities::Capability::BookmarkThis:
                return bookmarkThisCapability;
            default:
                break;
            }
            return nullptr;
        }

};

static QAction *action;
static QList<QAction*> actionsList;

// Create the static instances to be returned for testing
Capabilities::ActionsCapability *MetaCapabilityMock::actionsCapability = new Capabilities::ActionsCapability( actionsList );
Capabilities::BookmarkThisCapability *MetaCapabilityMock::bookmarkThisCapability;

QTEST_MAIN( TestMetaCapability )

TestMetaCapability::TestMetaCapability()
{
     action = new QAction( nullptr );
     MetaCapabilityMock::bookmarkThisCapability = new Capabilities::BookmarkThisCapability( action );
}

void
TestMetaCapability::testHas()
{
    MetaCapability *metaCapability = new MetaCapabilityMock();
    QVERIFY( metaCapability );

    // these capabilities should be provided
    QVERIFY( metaCapability->has<Capabilities::ActionsCapability>() == true );
    QVERIFY( metaCapability->has<Capabilities::BookmarkThisCapability>() == true );

    // these should not
    QVERIFY( metaCapability->has<Capabilities::CollectionScanCapability>() == false );
    QVERIFY( metaCapability->has<Capabilities::MultiSourceCapability>() == false );
}

void
TestMetaCapability::testCreate()
{
    MetaCapability *metaCapability = new MetaCapabilityMock();
    QVERIFY( metaCapability );

    // these capabilities should be provided
    // check that the correct instances are returned
    QVERIFY( metaCapability->create<Capabilities::ActionsCapability>() == MetaCapabilityMock::actionsCapability );
    QVERIFY( metaCapability->create<Capabilities::BookmarkThisCapability>() == MetaCapabilityMock::bookmarkThisCapability );

    // these should not
    QVERIFY( metaCapability->create<Capabilities::CollectionScanCapability>() == nullptr );
    QVERIFY( metaCapability->create<Capabilities::MultiSourceCapability>() == nullptr );
}