summaryrefslogtreecommitdiff
path: root/tests/test-resource-set/test-resource-set.cpp
blob: 21995e1bd7e325dbfcfc79b7576b9804fe84e628 (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*************************************************************************
This file is part of libresourceqt

Copyright (C) 2010 Nokia Corporation.

This library is free software; you can redistribute
it and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation
version 2.1 of the License.

This library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA.
*************************************************************************/



#include "test-resource-set.h"

using namespace ResourcePolicy;

Resource * TestResourceSet::resourceFromType(ResourceType type)
{
    switch (type) {
    case AudioPlaybackType:
        return new AudioResource;
    case AudioRecorderType:
        return new AudioRecorderResource;
    case VideoPlaybackType:
        return new VideoResource;
    case VideoRecorderType:
        return new VideoRecorderResource;
    case VibraType:
        return new VibraResource;
    case LedsType:
        return new LedsResource;
    case BacklightType:
        return new BacklightResource;
    case SystemButtonType:
        return new SystemButtonResource;
    case LockButtonType:
        return new LockButtonResource;
    case ScaleButtonType:
        return new ScaleButtonResource;
    case SnapButtonType:
        return new SnapButtonResource;
    case LensCoverType:
        return new LensCoverResource;
    case HeadsetButtonsType:
        return new HeadsetButtonsResource;
    default:
        return NULL;
    }
}

using namespace ResourcePolicy;

TestResourceSet::TestResourceSet()
{
}

TestResourceSet::~TestResourceSet()
{
}

void TestResourceSet::init()
{
    resourceSet = new ResourceSet("player");
}

void TestResourceSet::cleanup()
{
    delete resourceSet;
}

void TestResourceSet::testIdentifier()
{
    ResourceSet otherSet("game");

    bool identifiersAreUnique = (resourceSet->id() != otherSet.id());
    QVERIFY(identifiersAreUnique);
}

void TestResourceSet::testAddResource()
{
    for (int i = 0;i < NumberOfTypes;i++) {
        ResourceType type = (ResourceType)i;
        resourceSet->addResource(type);
        bool setContainsGivenResource = resourceSet->contains(type);
        QVERIFY(setContainsGivenResource);
    }
}

void TestResourceSet::testAddResourceObject()
{
    for (int i = 0;i < NumberOfTypes;i++) {
        ResourceType type = (ResourceType)i;
        Resource *resource = resourceFromType(type);
        resourceSet->addResourceObject(resource);
        bool setContainsGivenResource = resourceSet->contains(type);
        QVERIFY(setContainsGivenResource);
    }
}

void TestResourceSet::testDelResource()
{
    for (int i = 0;i < NumberOfTypes;i++) {
        ResourceType type = (ResourceType)i;
        resourceSet->addResource(type);
        bool setContainsGivenResource = resourceSet->contains(type);
        QVERIFY(setContainsGivenResource);
    }

    for (int i = 0;i < NumberOfTypes;i++) {
        ResourceType type = (ResourceType)i;
        resourceSet->deleteResource(type);
        bool setNoLongerContainType = !resourceSet->contains(type);
        QVERIFY(setNoLongerContainType);
        for (int j = 0; j < NumberOfTypes; j++) {
            if(j == i) continue;
            ResourceType otherType = (ResourceType)j;
            bool setStillContainsOtherTypes = resourceSet->contains(otherType);
            QVERIFY(setStillContainsOtherTypes);
        }
        resourceSet->addResource(type);
    }
}

void TestResourceSet::testContainsSet()
{
    QList<ResourceType> types, subset;

    for (int i = 0;i < NumberOfTypes;i++) {
        ResourceType type = (ResourceType)i;
        resourceSet->addResource(type);
        types.append(type);
    }

    subset << AudioPlaybackType << VideoPlaybackType
    << AudioRecorderType << VideoRecorderType << LensCoverType;

    bool containsAll = resourceSet->contains(types);
    bool containsSubset = resourceSet->contains(subset);
    QVERIFY(containsAll);
    QVERIFY(containsSubset);
}

void TestResourceSet::testConnectToSignals()
{
    bool signalConnectionSucceeded=false;
    signalConnectionSucceeded = QObject::connect(resourceSet,
        SIGNAL(resourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &)),
        this, SLOT(handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &)));

    QVERIFY(signalConnectionSucceeded);

    signalConnectionSucceeded = QObject::connect(resourceSet,
        SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType> &)),
        this, SLOT(handleResourcesGranted(const QList<ResourcePolicy::ResourceType> &)));

    QVERIFY(signalConnectionSucceeded);

    signalConnectionSucceeded = QObject::connect(resourceSet,
        SIGNAL(resourcesDenied()),
        this, SLOT(handleResourcesDenied()));

    QVERIFY(signalConnectionSucceeded);

    signalConnectionSucceeded = QObject::connect(resourceSet,
        SIGNAL(resourcesReleased()),
        this, SLOT(handleResourcesReleased()));

    QVERIFY(signalConnectionSucceeded);

    signalConnectionSucceeded = QObject::connect(resourceSet,
        SIGNAL(lostResources()),
        this, SLOT(handleLostResources()));

    QVERIFY(signalConnectionSucceeded);

}

void TestResourceSet::handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &)
{

}
void TestResourceSet::handleResourcesGranted(const QList<ResourcePolicy::ResourceType> &)
{
}

void TestResourceSet::handleResourcesDenied()
{
}

void TestResourceSet::handleResourcesReleased()
{
}

void TestResourceSet::handleLostResources()
{
}

QTEST_MAIN(TestResourceSet)