diff options
Diffstat (limited to 'tests/test-resource.cpp')
-rw-r--r-- | tests/test-resource.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
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) |