summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-25 11:12:45 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-25 11:12:45 +0200
commitca994fc17c8bdb66c64beaead40bc2727ea89468 (patch)
treef03b032af15c214610d84fe7f1dc99c726eff610 /tests
parent9f3e54044fd1e0c26153195f91889342a8425b7f (diff)
downloadlibresourceqt-ca994fc17c8bdb66c64beaead40bc2727ea89468.tar.gz
Chaged Resource::type to be stored as a number instead of a string. Also
changed ResourceSet to store resources as a QVector instead of a QSet.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-resource-set.cpp59
-rw-r--r--tests/test-resource.cpp116
-rw-r--r--tests/test-resource.h12
3 files changed, 54 insertions, 133 deletions
diff --git a/tests/test-resource-set.cpp b/tests/test-resource-set.cpp
index b05a16b..a2834c7 100644
--- a/tests/test-resource-set.cpp
+++ b/tests/test-resource-set.cpp
@@ -41,44 +41,75 @@ void TestResourceSet::testAddResource()
resourceSet->addResource(resource);
- QSet<Resource> resourcesInSet = resourceSet->resources();
+ QList<Resource> resourcesInSet = resourceSet->resources();
QVERIFY(resourcesInSet.contains(resource));
}
void TestResourceSet::testAddResources()
{
- QSet<Resource> resources;
+ QList<Resource> resources;
resources << audioPlayback << videoPlayback;
resourceSet->addResources(resources);
- QSet<Resource> resourcesInSet = resourceSet->resources();
- QVERIFY(resourcesInSet == resources);
+ QList<Resource> resourcesInSet = resourceSet->resources();
+ bool resultContainsAllItems = false;
+ for(int i=0; i<resourcesInSet.size(); i++) {
+ resultContainsAllItems = resources.contains(resourcesInSet.at(i));
+ if(!resultContainsAllItems) {
+ qDebug("resources doesn't contain Resource 0x%02x", resourcesInSet.at(i).type());
+ break;
+ }
+ }
+ QVERIFY(resultContainsAllItems);
+ for(int i=0; i<resources.size(); i++) {
+ resultContainsAllItems = resourcesInSet.contains(resources.at(i));
+ if(!resultContainsAllItems) {
+ break;
+ }
+ }
+ QVERIFY(resultContainsAllItems);
}
void TestResourceSet::testSetResources()
{
- QSet<Resource> resources, newResources;
+ QList<Resource> resources, newResources;
newResources << audioPlayback << videoPlayback;
resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
resourceSet->setResources(resources);
- QSet<Resource> resourcesInSet = resourceSet->resources();
+ QList<Resource> resourcesInSet = resourceSet->resources();
resourceSet->setResources(newResources);
- QSet<Resource> resourcesInNewSet = resourceSet->resources();
- QVERIFY(resourcesInNewSet == newResources);
+ QList<Resource> resourcesInNewSet = resourceSet->resources();
+ bool resultContainsAllItems = false;
+ for(int i=0; i<resourcesInNewSet.size(); i++) {
+ resultContainsAllItems = newResources.contains(resourcesInNewSet.at(i));
+ if(!resultContainsAllItems) {
+ qDebug("newResources doesn't contain Resource 0x%02x", resourcesInNewSet.at(i).type());
+ break;
+ }
+ }
+ QVERIFY(resultContainsAllItems);
+ for(int i=0; i<newResources.size(); i++) {
+ resultContainsAllItems = resourcesInNewSet.contains(newResources.at(i));
+ if(!resultContainsAllItems) {
+ qDebug("newResources doesn't contain Resource 0x%02x", resourcesInNewSet.at(i).type());
+ break;
+ }
+ }
+ QVERIFY(resultContainsAllItems);
}
void TestResourceSet::testContainsSingle()
{
- QSet<Resource> resources;
+ QList<Resource> resources;
resources << audioPlayback << videoPlayback << audioRecorder;
resourceSet->setResources(resources);
- QSet<Resource> resourcesInSet = resourceSet->resources();
+ QList<Resource> resourcesInSet = resourceSet->resources();
resourceSet->setResources(resources);
bool containsVideoPlayback = resourceSet->contains(videoPlayback);
@@ -87,11 +118,11 @@ void TestResourceSet::testContainsSingle()
void TestResourceSet::testDoesNotContainSingle()
{
- QSet<Resource> resources;
+ QList<Resource> resources;
resources << audioPlayback << videoPlayback;
resourceSet->setResources(resources);
- QSet<Resource> resourcesInSet = resourceSet->resources();
+ QList<Resource> resourcesInSet = resourceSet->resources();
resourceSet->setResources(resources);
bool containsVideoRecorder = resourceSet->contains(videoRecorder);
@@ -102,13 +133,13 @@ void TestResourceSet::testDoesNotContainSingle()
void TestResourceSet::testContainsSet()
{
- QSet<Resource> resources, subset;
+ QList<Resource> resources, subset;
resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
subset << audioPlayback << videoPlayback;
resourceSet->setResources(resources);
- QSet<Resource> resourcesInSet = resourceSet->resources();
+ QList<Resource> resourcesInSet = resourceSet->resources();
resourceSet->setResources(resources);
bool containsSubset = resourceSet->contains(subset);
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
index afccc16..e5c60bd 100644
--- a/tests/test-resource.cpp
+++ b/tests/test-resource.cpp
@@ -74,7 +74,7 @@ void TestResource::testShared_data()
QTest::addColumn<bool>("expected");
QTest::newRow("Resource is shared") << true << true;
- QTest::newRow("Resource is not hhared") << false << false;
+ QTest::newRow("Resource is not shared") << false << false;
}
void TestResource::testShared()
@@ -89,27 +89,6 @@ void TestResource::testShared()
QCOMPARE(result, expected);
}
-void TestResource::testIdentifier_data()
-{
- QTest::addColumn<quint32>("identifier");
- QTest::addColumn<quint32>("expected");
-
- QTest::newRow("Set identifier") << (quint32)this << (quint32)this;
- QTest::newRow("Set to 0") << 0U << 0U;
-}
-
-void TestResource::testIdentifier()
-{
- QFETCH(quint32, identifier);
- QFETCH(quint32, expected);
-
- resource->setType(AudioPlaybackResource);
- resource->setId(identifier);
- quint32 result = resource->id();
-
- QCOMPARE(result, expected);
-}
-
void TestResource::testCopy()
{
Resource copy;
@@ -118,7 +97,6 @@ void TestResource::testCopy()
copy = *resource;
- QCOMPARE(copy.id(), resource->id());
QCOMPARE(copy.isOptional(), resource->isOptional());
QCOMPARE(copy.isShared(), resource->isShared());
QCOMPARE(copy.type(), resource->type());
@@ -130,7 +108,6 @@ void TestResource::testCopyConstructor()
resource->setOptional();
Resource copy(*resource);
- QCOMPARE(copy.id(), resource->id());
QCOMPARE(copy.isOptional(), resource->isOptional());
QCOMPARE(copy.isShared(), resource->isShared());
QCOMPARE(copy.type(), resource->type());
@@ -140,102 +117,25 @@ void TestResource::testEqualsOperator()
{
Resource copy;
resource->setType(AudioPlaybackResource);
- resource->setOptional();
-
copy = *resource;
- QVERIFY(copy == *resource);
-}
-
-void TestResource::testHashFunctionWithCopies()
-{
- resource->setType(AudioPlaybackResource);
resource->setOptional();
resource->setShared();
- Resource copy(*resource);
- uint originalHash = qHash(*resource);
- uint copyHash = qHash(copy);
-
- QCOMPARE(originalHash, copyHash);
-}
-
-void TestResource::testHashFunctionWithDifferentResources()
-{
- resource->setType(AudioPlaybackResource);
- resource->setOptional();
- resource->setShared();
- Resource copy(*resource);
- copy.setType(VideoPlaybackResource);
-
- uint originalHash = qHash(*resource);
- uint copyHash = qHash(copy);
-
- QEXPECT_FAIL("", "Expecting to fail since they are different resources", Continue);
- QCOMPARE(originalHash, copyHash);
-}
-
-void TestResource::testHashFunctionWithDifferentOptionality()
-{
- resource->setType(AudioPlaybackResource);
- resource->setOptional();
- resource->setShared();
- Resource copy(*resource);
- copy.setOptional(false);
-
- uint originalHash = qHash(*resource);
- uint copyHash = qHash(copy);
-
- QEXPECT_FAIL("", "Expecting to fail since one isOptional, the other isn't", Continue);
- QCOMPARE(originalHash, copyHash);
+ QVERIFY(copy == *resource);
}
-void TestResource::testHashFunctionWithDifferentSharedness()
+void TestResource::testEqualsOperatorWithDifferentTypes()
{
+ Resource copy;
resource->setType(AudioPlaybackResource);
- resource->setOptional();
- resource->setShared();
- Resource copy(*resource);
- copy.setShared(false);
-
- uint originalHash = qHash(*resource);
- uint copyHash = qHash(copy);
-
- QEXPECT_FAIL("", "Expecting to fail since one isShared , the other isn't", Continue);
- QCOMPARE(originalHash, copyHash);
-}
+ copy = *resource;
-void TestResource::testHashFunctionWithIdentical()
-{
- resource->setType(AudioPlaybackResource);
resource->setOptional();
- resource->setShared();
- Resource copy;
- copy.setOptional();
- copy.setShared();
- copy.setType(AudioPlaybackResource);
-
- uint originalHash = qHash(*resource);
- uint copyHash = qHash(copy);
-
- QCOMPARE(originalHash, copyHash);
-}
+ copy.setType(VideoPlaybackResource);
-void TestResource::testQSetOfResource()
-{
- Resource a,b,c;
- a.setType(AudioPlaybackResource);
- b.setType(VideoPlaybackResource);
- c.setType(AudioRecorderResource);
-
- QSet<Resource> set;
- set.insert(a);
- set.insert(b);
- set.insert(c);
-
- QVERIFY(set.contains(a));
- QVERIFY(set.contains(b));
- QVERIFY(set.contains(c));
+ QEXPECT_FAIL("", "Expecting to fail since different types.", Continue);
+ QVERIFY(copy == *resource);
}
QTEST_MAIN(TestResource)
diff --git a/tests/test-resource.h b/tests/test-resource.h
index 76ba5b4..b0e6964 100644
--- a/tests/test-resource.h
+++ b/tests/test-resource.h
@@ -33,21 +33,11 @@ private slots:
void testShared_data();
void testShared();
- void testIdentifier_data();
- void testIdentifier();
-
void testCopy();
void testCopyConstructor();
void testEqualsOperator();
-
- void testHashFunctionWithCopies();
- void testHashFunctionWithDifferentResources();
- void testHashFunctionWithDifferentOptionality();
- void testHashFunctionWithDifferentSharedness();
- void testHashFunctionWithIdentical();
-
- void testQSetOfResource();
+ void testEqualsOperatorWithDifferentTypes();
};
#endif