blob: d9cbbce5bf55480270b753edd5724c3977739afe (
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
|
#include "test-resource-set.h"
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;
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);
QVERIFY(resourceSet->id() == (quint32)resourceSet);
QVERIFY(otherSet.id() == (quint32)&otherSet);
}
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);
}
QTEST_MAIN(TestResourceSet)
|