summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-22 14:29:12 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-22 14:29:12 +0200
commit9f3e54044fd1e0c26153195f91889342a8425b7f (patch)
tree71bcfde9546045b27d22a3c7265015ccec07ff22 /tests
parentcfb16c2a93650ac2e0c9677bce11ed101aceffb0 (diff)
downloadlibresourceqt-9f3e54044fd1e0c26153195f91889342a8425b7f.tar.gz
added ResourceSet
Diffstat (limited to 'tests')
-rw-r--r--tests/test-resource-set.cpp117
-rw-r--r--tests/test-resource-set.h40
-rw-r--r--tests/test-resource-set.pro21
-rw-r--r--tests/test-resource.cpp98
-rw-r--r--tests/test-resource.h9
5 files changed, 284 insertions, 1 deletions
diff --git a/tests/test-resource-set.cpp b/tests/test-resource-set.cpp
new file mode 100644
index 0000000..b05a16b
--- /dev/null
+++ b/tests/test-resource-set.cpp
@@ -0,0 +1,117 @@
+#include "test-resource-set.h"
+
+using namespace ResourcePolicy;
+
+TestResourceSet::TestResourceSet()
+{
+ audioPlayback.setType(AudioPlaybackResource);
+ videoPlayback.setType(VideoPlaybackResource);
+ audioRecorder.setType(AudioRecorderResource);
+ videoRecorder.setType(VideoRecorderResource);
+}
+
+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()
+{
+ Resource resource;
+ resource.setType(AudioPlaybackResource);
+
+ resourceSet->addResource(resource);
+
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+ QVERIFY(resourcesInSet.contains(resource));
+}
+
+void TestResourceSet::testAddResources()
+{
+ QSet<Resource> resources;
+
+ resources << audioPlayback << videoPlayback;
+
+ resourceSet->addResources(resources);
+
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+ QVERIFY(resourcesInSet == resources);
+}
+
+void TestResourceSet::testSetResources()
+{
+ QSet<Resource> resources, newResources;
+
+ newResources << audioPlayback << videoPlayback;
+ resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
+ resourceSet->setResources(resources);
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+
+ resourceSet->setResources(newResources);
+
+ QSet<Resource> resourcesInNewSet = resourceSet->resources();
+ QVERIFY(resourcesInNewSet == newResources);
+}
+
+void TestResourceSet::testContainsSingle()
+{
+ QSet<Resource> resources;
+
+ resources << audioPlayback << videoPlayback << audioRecorder;
+ resourceSet->setResources(resources);
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+ resourceSet->setResources(resources);
+
+ bool containsVideoPlayback = resourceSet->contains(videoPlayback);
+ QVERIFY(containsVideoPlayback);
+}
+
+void TestResourceSet::testDoesNotContainSingle()
+{
+ QSet<Resource> resources;
+
+ resources << audioPlayback << videoPlayback;
+ resourceSet->setResources(resources);
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+ resourceSet->setResources(resources);
+
+ bool containsVideoRecorder = resourceSet->contains(videoRecorder);
+ QEXPECT_FAIL("", "This should fail since searched resource should NOT be in set", Continue);
+ QVERIFY(containsVideoRecorder);
+}
+
+
+void TestResourceSet::testContainsSet()
+{
+ QSet<Resource> resources, subset;
+
+ resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
+ subset << audioPlayback << videoPlayback;
+
+ resourceSet->setResources(resources);
+ QSet<Resource> resourcesInSet = resourceSet->resources();
+ resourceSet->setResources(resources);
+
+ bool containsSubset = resourceSet->contains(subset);
+ QVERIFY(containsSubset);
+}
+QTEST_MAIN(TestResourceSet)
diff --git a/tests/test-resource-set.h b/tests/test-resource-set.h
new file mode 100644
index 0000000..fa80df1
--- /dev/null
+++ b/tests/test-resource-set.h
@@ -0,0 +1,40 @@
+#ifndef TEST_RESOURCE_SET_H
+#define TEST_RESOURCE_SET_H
+
+#include <QtTest/QTest>
+#include "resource-set.h"
+
+using namespace ResourcePolicy;
+
+class TestResourceSet: public QObject
+{
+ Q_OBJECT
+private:
+ ResourceSet *resourceSet;
+ Resource audioPlayback;
+ Resource videoPlayback;
+ Resource videoRecorder;
+ Resource audioRecorder;
+
+public:
+ TestResourceSet();
+ ~TestResourceSet();
+
+
+private slots:
+
+ void init();
+ void cleanup();
+
+ void testIdentifier();
+
+ void testAddResource();
+ void testAddResources();
+ void testSetResources();
+
+ void testContainsSingle();
+ void testDoesNotContainSingle();
+ void testContainsSet();
+};
+
+#endif
diff --git a/tests/test-resource-set.pro b/tests/test-resource-set.pro
new file mode 100644
index 0000000..e9e24ee
--- /dev/null
+++ b/tests/test-resource-set.pro
@@ -0,0 +1,21 @@
+BASE = ..
+TEMPLATE = app
+TARGET = test-resource-set
+DESTDIR = build
+DEPENDPATH += $${BASE}/include $${BASE}/src .
+INCLUDEPATH += $${BASE}/src $${BASE}/include
+
+# Input
+HEADERS += $${BASE}/include/resource.h $${BASE}/include/resource-set.h test-resource-set.h
+SOURCES += $${BASE}/src/resource.cpp $${BASE}/src/resource-set.cpp test-resource-set.cpp
+
+OBJECTS_DIR = build
+MOC_DIR = build
+
+CONFIG += qt qtestlib debug warn_on
+QT -= gui
+
+# Install directives
+INSTALLBASE = /usr
+target.path = $$INSTALLBASE/share/libresourceqt/tests
+INSTALLS = target
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
index 95f1809..afccc16 100644
--- a/tests/test-resource.cpp
+++ b/tests/test-resource.cpp
@@ -1,4 +1,5 @@
#include "test-resource.h"
+#include <QSet>
using namespace ResourcePolicy;
@@ -60,6 +61,7 @@ void TestResource::testOptional()
QFETCH(bool, optional);
QFETCH(bool, expected);
+ resource->setType(AudioPlaybackResource);
resource->setOptional(optional);
bool result = resource->isOptional();
@@ -80,6 +82,7 @@ void TestResource::testShared()
QFETCH(bool, optional);
QFETCH(bool, expected);
+ resource->setType(AudioPlaybackResource);
resource->setShared(optional);
bool result = resource->isShared();
@@ -100,6 +103,7 @@ void TestResource::testIdentifier()
QFETCH(quint32, identifier);
QFETCH(quint32, expected);
+ resource->setType(AudioPlaybackResource);
resource->setId(identifier);
quint32 result = resource->id();
@@ -109,6 +113,7 @@ void TestResource::testIdentifier()
void TestResource::testCopy()
{
Resource copy;
+ resource->setType(AudioPlaybackResource);
resource->setOptional();
copy = *resource;
@@ -121,6 +126,7 @@ void TestResource::testCopy()
void TestResource::testCopyConstructor()
{
+ resource->setType(AudioPlaybackResource);
resource->setOptional();
Resource copy(*resource);
@@ -133,6 +139,7 @@ void TestResource::testCopyConstructor()
void TestResource::testEqualsOperator()
{
Resource copy;
+ resource->setType(AudioPlaybackResource);
resource->setOptional();
copy = *resource;
@@ -140,4 +147,95 @@ void TestResource::testEqualsOperator()
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);
+}
+
+void TestResource::testHashFunctionWithDifferentSharedness()
+{
+ 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);
+}
+
+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);
+}
+
+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));
+}
+
QTEST_MAIN(TestResource)
diff --git a/tests/test-resource.h b/tests/test-resource.h
index a5f617f..76ba5b4 100644
--- a/tests/test-resource.h
+++ b/tests/test-resource.h
@@ -19,7 +19,6 @@ public:
TestResource();
~TestResource();
-
private slots:
void init();
@@ -41,6 +40,14 @@ private slots:
void testCopyConstructor();
void testEqualsOperator();
+
+ void testHashFunctionWithCopies();
+ void testHashFunctionWithDifferentResources();
+ void testHashFunctionWithDifferentOptionality();
+ void testHashFunctionWithDifferentSharedness();
+ void testHashFunctionWithIdentical();
+
+ void testQSetOfResource();
};
#endif