summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-29 17:20:56 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-29 17:20:56 +0200
commit0746bbd252fe13ce3c4ae523fc28b0cf27314c05 (patch)
tree323b3406c6f893f21c7c7820532c0df2a61881cc /tests
parent27c45e867533ad43bc2b2e64fe577a503b2d05a8 (diff)
downloadlibresourceqt-0746bbd252fe13ce3c4ae523fc28b0cf27314c05.tar.gz
Refactored Resource into multiple classes
Diffstat (limited to 'tests')
-rw-r--r--tests/mock-resource-library.cpp57
-rw-r--r--tests/mock-resource-library.h29
-rw-r--r--tests/test-libplayback.cpp46
-rw-r--r--tests/test-libplayback.h29
-rw-r--r--tests/test-resource-set.cpp180
-rw-r--r--tests/test-resource-set.h24
-rw-r--r--tests/test-resource.cpp278
-rw-r--r--tests/test-resource.h49
-rw-r--r--tests/test-resource.pro4
9 files changed, 360 insertions, 336 deletions
diff --git a/tests/mock-resource-library.cpp b/tests/mock-resource-library.cpp
deleted file mode 100644
index 565e745..0000000
--- a/tests/mock-resource-library.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include "mock-resource-library.h"
-
-MockResourceLibrary::MockResourceLibrary(Resource *resource,
- bool makeInitializationFail,
- bool makeConnectingToServerFail,
- bool makeReserveFail)
- : QObject(resource), initializeFails(makeInitializationFail),
- connectToServerFails(makeConnectingToServerFail),
- reserveFails(makeReserveFail)
-{
- this->resource = resource;
-}
-
-MockResourceLibrary::~MockResourceLibrary()
-{
-}
-
-void MockResourceLibrary::makeInitializeFail()
-{
- initializeFails = true;
-}
-
-bool MockResourceLibrary::initialize()
-{
- if(initializeFails==false)
- return true;
- else
- return false;
-}
-
-void MockResourceLibrary::makeServerConnectFail()
-{
- connectToServerFails = true;
-}
-
-bool MockResourceLibrary::connectToServer()
-{
- if(connectToServerFails == false)
- return true;
- else
- return false;
-}
-
-bool MockResourceLibrary::reserve()
-{
- if(!reserveFails) {
- resource->handleStateChange(OwnedState);
- }
- else {
- resource->handleStateChange(NotOwnedState);
- }
-}
-
-void MockResourceLibrary::makeReserveFail()
-{
- reserveFails = true;
-}
diff --git a/tests/mock-resource-library.h b/tests/mock-resource-library.h
deleted file mode 100644
index 1d3d17d..0000000
--- a/tests/mock-resource-library.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef MOCK_RESOURCE_LIBRARY_H
-#define MOCK_RESOURCE_LIBRARY_H
-
-#include <QObject>
-#include "resource-library.h"
-#include "resource.h"
-
-class MockResourceLibrary: public QObject, public ResourceLibrary
-{
- Q_OBJECT
-private:
- bool initializeFails;
- bool connectToServerFails;
- Resource *resource;
- bool reserveFails;
-public:
- MockResourceLibrary(Resource *resource=0,bool makeInitializationFail=false,
- bool makeConnectingToServerFail=false, bool makeReserveFail=false);
- virtual ~MockResourceLibrary();
- void makeInitializeFail();
- void makeServerConnectFail();
- bool initialize();
- bool connectToServer();
-
- bool reserve();
- void makeReserveFail();
-};
-
-#endif
diff --git a/tests/test-libplayback.cpp b/tests/test-libplayback.cpp
deleted file mode 100644
index ac4107c..0000000
--- a/tests/test-libplayback.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "test-libplayback.h"
-
-using namespace ResourceTypes;
-
-TestLibplayback::TestLibplayback()
-{
- resourceFactory=NULL;
- resource=NULL;
- loop=NULL;
- timer=NULL;
-}
-
-TestLibplayback::~TestLibplayback()
-{
-}
-
-void TestLibplayback::init()
-{
- loop = new QEventLoop(this);
- timer = new QTimer(this);
- resourceFactory = new ResourceFactory(this);
- QVERIFY(resourceFactory != NULL);
- resource = resourceFactory->createResource(MediaClass, AudioResource|VideoResource);
- QVERIFY(resource != NULL);
-
- timer->setInterval(3000);
- timer->setSingleShot(true);
-}
-
-void TestLibplayback::testConnectToServer()
-{
- connect(timer, SIGNAL(timeout()), loop, SLOT(quit()));
-
- qDebug("connecting to server...");
- resource->connectToServer();
-
- loop->exec();
-}
-
-void TestLibplayback::timeout()
-{
- qDebug("Timeout!");
- loop->exit(0);
-}
-
-QTEST_MAIN(TestLibplayback)
diff --git a/tests/test-libplayback.h b/tests/test-libplayback.h
deleted file mode 100644
index 03ffc4a..0000000
--- a/tests/test-libplayback.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef TEST_RESOURCE_FACTORY_H
-#define TEST_RESOURCE_FACTORY_H
-
-#include <QtTest/QTest>
-#include <QEventLoop>
-#include <QTimer>
-#include "resource-factory.h"
-#include "resource.h"
-
-class TestLibplayback: public QObject
-{
- Q_OBJECT
-private:
- ResourceFactory *resourceFactory;
- Resource *resource;
- QEventLoop *loop;
- QTimer *timer;
-public:
- TestLibplayback();
- ~TestLibplayback();
-public slots:
- void timeout();
-private slots:
- void init();
-
- void testConnectToServer();
-};
-
-#endif
diff --git a/tests/test-resource-set.cpp b/tests/test-resource-set.cpp
index a2834c7..e9ee74b 100644
--- a/tests/test-resource-set.cpp
+++ b/tests/test-resource-set.cpp
@@ -1,17 +1,69 @@
#include "test-resource-set.h"
+Resource * TestResourceSet::resourceFromType(ResourceType type)
+{
+ switch(type) {
+ case AudioPlaybackType:
+ return audioResource;
+ case AudioRecorderType:
+ return audioRecorderResource;
+ case VideoPlaybackType:
+ return videoResource;
+ case VideoRecorderType:
+ return videoRecorderResource;
+ case VibraType:
+ return vibraResource;
+ case LedsType:
+ return ledsResource;
+ case BacklightType:
+ return backlightResource;
+ case SystemButtonType:
+ return systemButtonResource;
+ case LockButtonType:
+ return lockButtonResource;
+ case ScaleButtonType:
+ return scaleButtonResource;
+ case SnapButtonType:
+ return snapButtonResource;
+ case LensCoverType:
+ return lensCoverResource;
+ default:
+ return NULL;
+ }
+}
+
using namespace ResourcePolicy;
TestResourceSet::TestResourceSet()
{
- audioPlayback.setType(AudioPlaybackResource);
- videoPlayback.setType(VideoPlaybackResource);
- audioRecorder.setType(AudioRecorderResource);
- videoRecorder.setType(VideoRecorderResource);
+ audioResource = new AudioResource;
+ audioRecorderResource = new AudioRecorderResource;
+ videoResource = new VideoResource;
+ videoRecorderResource = new VideoRecorderResource;
+ vibraResource = new VibraResource;
+ ledsResource = new LedsResource;
+ backlightResource = new BacklightResource;
+ systemButtonResource = new SystemButtonResource;
+ lockButtonResource = new LockButtonResource;
+ scaleButtonResource = new ScaleButtonResource;
+ snapButtonResource = new SnapButtonResource;
+ lensCoverResource = new LensCoverResource;
}
TestResourceSet::~TestResourceSet()
{
+ delete audioResource;
+ delete audioRecorderResource;
+ delete videoResource;
+ delete videoRecorderResource;
+ delete vibraResource;
+ delete ledsResource;
+ delete backlightResource;
+ delete systemButtonResource;
+ delete lockButtonResource;
+ delete scaleButtonResource;
+ delete snapButtonResource;
+ delete lensCoverResource;
}
void TestResourceSet::init()
@@ -36,113 +88,85 @@ void TestResourceSet::testIdentifier()
void TestResourceSet::testAddResource()
{
- Resource resource;
- resource.setType(AudioPlaybackResource);
-
- resourceSet->addResource(resource);
-
- QList<Resource> resourcesInSet = resourceSet->resources();
- QVERIFY(resourcesInSet.contains(resource));
+ for(int i=0;i<NumberOfTypes;i++) {
+ ResourceType type = (ResourceType)i;
+ Resource *resource = resourceFromType(type);
+ resourceSet->addResource(resource);
+ bool setContainsGivenResource = resourceSet->contains(type);
+ QVERIFY(setContainsGivenResource);
+ }
}
void TestResourceSet::testAddResources()
{
- QList<Resource> resources;
+ resourceSet->addResource(audioResource);
- resources << audioPlayback << videoPlayback;
+ bool setContainsAudioResource = resourceSet->contains(AudioPlaybackType);
+ QVERIFY(setContainsAudioResource);
+ QList<Resource *> resources;
+
+ resources << audioResource << videoResource;
resourceSet->addResources(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);
+ QVERIFY(resourceSet->contains(AudioPlaybackType));
+ QVERIFY(resourceSet->contains(VideoPlaybackType));
}
-void TestResourceSet::testSetResources()
+void TestResourceSet::testDelResource()
{
- QList<Resource> resources, newResources;
-
- newResources << audioPlayback << videoPlayback;
- resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
- resourceSet->setResources(resources);
- QList<Resource> resourcesInSet = resourceSet->resources();
-
- resourceSet->setResources(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);
+ resourceSet->addResource(audioResource);
+ resourceSet->addResource(vibraResource);
+ resourceSet->delResource(AudioPlaybackType);
+
+ bool setDoesNotContainAudioResource = !resourceSet->contains(AudioPlaybackType);
+ QVERIFY(setDoesNotContainAudioResource);
+ QVERIFY(resourceSet->contains(VibraType));
}
void TestResourceSet::testContainsSingle()
{
- QList<Resource> resources;
+ QList<Resource *> resources;
- resources << audioPlayback << videoPlayback << audioRecorder;
- resourceSet->setResources(resources);
- QList<Resource> resourcesInSet = resourceSet->resources();
- resourceSet->setResources(resources);
+ resources << audioResource << videoResource << audioRecorderResource;
+ resourceSet->addResources(resources);
+ QList<Resource *> resourcesInSet = resourceSet->resources();
- bool containsVideoPlayback = resourceSet->contains(videoPlayback);
+ bool containsVideoPlayback = resourceSet->contains(VideoPlaybackType);
QVERIFY(containsVideoPlayback);
}
void TestResourceSet::testDoesNotContainSingle()
{
- QList<Resource> resources;
+ QList<Resource *> resources;
- resources << audioPlayback << videoPlayback;
- resourceSet->setResources(resources);
- QList<Resource> resourcesInSet = resourceSet->resources();
- resourceSet->setResources(resources);
+ resources << audioResource << videoResource;
+ resourceSet->addResources(resources);
+ QList<Resource *> resourcesInSet = resourceSet->resources();
- bool containsVideoRecorder = resourceSet->contains(videoRecorder);
- QEXPECT_FAIL("", "This should fail since searched resource should NOT be in set", Continue);
- QVERIFY(containsVideoRecorder);
+ bool doesNotContainVideoRecorder = !resourceSet->contains(VideoRecorderType);
+ QVERIFY(doesNotContainVideoRecorder);
}
void TestResourceSet::testContainsSet()
{
- QList<Resource> resources, subset;
+ QList<ResourceType> types, subset;
+ QList<Resource *> resources;
+
+ types << AudioPlaybackType << VideoPlaybackType
+ << AudioRecorderType << VideoRecorderType << LensCoverType;
+ subset << AudioPlaybackType << VideoPlaybackType << LensCoverType;
- resources << audioPlayback << videoPlayback << audioRecorder << videoRecorder;
- subset << audioPlayback << videoPlayback;
+ resources << audioResource << videoResource
+ << audioRecorderResource << videoRecorderResource << lensCoverResource;
- resourceSet->setResources(resources);
- QList<Resource> resourcesInSet = resourceSet->resources();
- resourceSet->setResources(resources);
+ resourceSet->addResources(resources);
+ bool containsAll = resourceSet->contains(types);
bool containsSubset = resourceSet->contains(subset);
+ QVERIFY(containsAll);
QVERIFY(containsSubset);
}
QTEST_MAIN(TestResourceSet)
+
diff --git a/tests/test-resource-set.h b/tests/test-resource-set.h
index fa80df1..0a3eeef 100644
--- a/tests/test-resource-set.h
+++ b/tests/test-resource-set.h
@@ -10,12 +10,22 @@ class TestResourceSet: public QObject
{
Q_OBJECT
private:
- ResourceSet *resourceSet;
- Resource audioPlayback;
- Resource videoPlayback;
- Resource videoRecorder;
- Resource audioRecorder;
-
+ ResourceSet *resourceSet;
+
+ AudioResource *audioResource;
+ AudioRecorderResource *audioRecorderResource;
+ Resource *videoResource;
+ Resource *videoRecorderResource;
+ Resource *vibraResource;
+ Resource *ledsResource;
+ Resource *backlightResource;
+ Resource *systemButtonResource;
+ Resource *lockButtonResource;
+ Resource *scaleButtonResource;
+ Resource *snapButtonResource;
+ Resource *lensCoverResource;
+
+ Resource * resourceFromType(ResourceType type);
public:
TestResourceSet();
~TestResourceSet();
@@ -30,7 +40,7 @@ private slots:
void testAddResource();
void testAddResources();
- void testSetResources();
+ void testDelResource();
void testContainsSingle();
void testDoesNotContainSingle();
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
index e5c60bd..2098a88 100644
--- a/tests/test-resource.cpp
+++ b/tests/test-resource.cpp
@@ -3,139 +3,279 @@
using namespace ResourcePolicy;
-TestResource::TestResource()
+Resource * TestResource::resourceFromType(ResourceType type)
{
+ switch(type) {
+ case AudioPlaybackType:
+ return audioResource;
+ case AudioRecorderType:
+ return audioRecorderResource;
+ case VideoPlaybackType:
+ return videoResource;
+ case VideoRecorderType:
+ return videoRecorderResource;
+ case VibraType:
+ return vibraResource;
+ case LedsType:
+ return ledsResource;
+ case BacklightType:
+ return backlightResource;
+ case SystemButtonType:
+ return systemButtonResource;
+ case LockButtonType:
+ return lockButtonResource;
+ case ScaleButtonType:
+ return scaleButtonResource;
+ case SnapButtonType:
+ return snapButtonResource;
+ case LensCoverType:
+ return lensCoverResource;
+ default:
+ return NULL;
+ }
}
-TestResource::~TestResource()
+const char * TestResource::stringFromType(ResourceType type)
{
+ switch(type) {
+ case AudioPlaybackType:
+ return "AudioPlaybackType";
+ case AudioRecorderType:
+ return "AudioRecorderType";
+ case VideoPlaybackType:
+ return "VideoPlaybackType";
+ case VideoRecorderType:
+ return "VideoRecorderType";
+ case VibraType:
+ return "VibraType";
+ case LedsType:
+ return "LedsType";
+ case BacklightType:
+ return "BacklightType";
+ case SystemButtonType:
+ return "SystemButtonType";
+ case LockButtonType:
+ return "LockButtonType";
+ case ScaleButtonType:
+ return "ScaleButtonType";
+ case SnapButtonType:
+ return "SnapButtonType";
+ case LensCoverType:
+ return "LensCoverType";
+ default:
+ qDebug("Unknown Type 0x%02x requested", type);
+ return NULL;
+ }
}
-void TestResource::init()
+TestResource::TestResource()
{
- resource = new Resource();
}
-void TestResource::cleanup()
+TestResource::~TestResource()
{
- delete resource;
}
-void TestResource::testType_data()
+void TestResource::init()
{
- QTest::addColumn<ResourceType>("type");
- QTest::addColumn<ResourceType>("expected");
+ audioResource = new AudioResource;
+ audioRecorderResource = new AudioRecorderResource;
+ videoResource = new VideoResource;
+ videoRecorderResource = new VideoRecorderResource;
+ vibraResource = new VibraResource;
+ ledsResource = new LedsResource;
+ backlightResource = new BacklightResource;
+ systemButtonResource = new SystemButtonResource;
+ lockButtonResource = new LockButtonResource;
+ scaleButtonResource = new ScaleButtonResource;
+ snapButtonResource = new SnapButtonResource;
+ lensCoverResource = new LensCoverResource;
+}
- QTest::newRow("AudioPlayback") << AudioPlaybackResource << AudioPlaybackResource;
- QTest::newRow("VideoPlayback") << VideoPlaybackResource << VideoPlaybackResource;
- QTest::newRow("AudioRecorder") << AudioRecorderResource << AudioRecorderResource;
- QTest::newRow("VideoRecorder") << VideoRecorderResource << VideoRecorderResource;
- QTest::newRow("Invalid") << InvalidResource << InvalidResource;
+void TestResource::cleanup()
+{
+ delete audioResource;
+ delete audioRecorderResource;
+ delete videoResource;
+ delete videoRecorderResource;
+ delete vibraResource;
+ delete ledsResource;
+ delete backlightResource;
+ delete systemButtonResource;
+ delete lockButtonResource;
+ delete scaleButtonResource;
+ delete snapButtonResource;
+ delete lensCoverResource;
}
void TestResource::testType()
{
- QFETCH(ResourceType, type);
- QFETCH(ResourceType, expected);
- bool setWasSuccessfull = resource->setType(type);
- ResourceType result = resource->type();
-
- if(expected == InvalidResource) {
- QEXPECT_FAIL("", "Expecting to fail since type == InvalidResource", Continue);
+ for(quint32 type=AudioPlaybackType; type < NumberOfTypes; type++) {
+ ResourceType expected = (ResourceType)type;
+ Resource *resource = resourceFromType(expected);
+ if(resource->type() != expected) {
+ qDebug("expected ResourceType = %s, got %s",
+ stringFromType(expected), stringFromType(resource->type()));
+ }
+ QVERIFY(resource->type() == expected);
}
- QVERIFY(setWasSuccessfull);
- QCOMPARE(result, expected);
}
void TestResource::testOptional_data()
{
+ QTest::addColumn<ResourceType>("type");
QTest::addColumn<bool>("optional");
QTest::addColumn<bool>("expected");
- QTest::newRow("Resource is optional") << true << true;
- QTest::newRow("Resource is not optional") << false << false;
+ QTest::newRow("Resource is optional") << AudioPlaybackType << true << true;
+ QTest::newRow("Resource is not optional") << AudioPlaybackType << false << false;
+ QTest::newRow("Resource is optional") << AudioRecorderType << true << true;
+ QTest::newRow("Resource is not optional") << AudioRecorderType << false << false;
+ QTest::newRow("Resource is optional") << VideoPlaybackType << true << true;
+ QTest::newRow("Resource is not optional") << VideoPlaybackType << false << false;
+ QTest::newRow("Resource is optional") << VideoRecorderType << true << true;
+ QTest::newRow("Resource is not optional") << VideoRecorderType << false << false;
+ QTest::newRow("Resource is optional") << VibraType << true << true;
+ QTest::newRow("Resource is not optional") << VibraType<< false << false;
+ QTest::newRow("Resource is optional") << BacklightType << true << true;
+ QTest::newRow("Resource is not optional") << BacklightType << false << false;
+ QTest::newRow("Resource is optional") << SystemButtonType << true << true;
+ QTest::newRow("Resource is not optional") << SystemButtonType << false << false;
+ QTest::newRow("Resource is optional") << LedsType << true << true;
+ QTest::newRow("Resource is not optional") << LedsType << false << false;
+ QTest::newRow("Resource is optional") << LockButtonType << true << true;
+ QTest::newRow("Resource is not optional") << LockButtonType << false << false;
+ QTest::newRow("Resource is optional") << ScaleButtonType << true << true;
+ QTest::newRow("Resource is not optional") << ScaleButtonType << false << false;
+ QTest::newRow("Resource is optional") << SnapButtonType << true << true;
+ QTest::newRow("Resource is not optional") << SnapButtonType << false << false;
+ QTest::newRow("Resource is optional") << LensCoverType << true << true;
+ QTest::newRow("Resource is not optional") << LensCoverType << false << false;
}
void TestResource::testOptional()
{
+ QFETCH(ResourceType, type);
QFETCH(bool, optional);
QFETCH(bool, expected);
- resource->setType(AudioPlaybackResource);
+ Resource *resource = resourceFromType(type);
+
resource->setOptional(optional);
bool result = resource->isOptional();
- QCOMPARE(result, expected);
+ QVERIFY(result == expected);
}
void TestResource::testShared_data()
{
- QTest::addColumn<bool>("optional");
+ QTest::addColumn<ResourceType>("type");
+ QTest::addColumn<bool>("shared");
QTest::addColumn<bool>("expected");
- QTest::newRow("Resource is shared") << true << true;
- QTest::newRow("Resource is not shared") << false << false;
+ QTest::newRow("Resource is shared") << AudioPlaybackType << true << true;
+ QTest::newRow("Resource is not shared") << AudioPlaybackType << false << false;
+ QTest::newRow("Resource is shared") << AudioRecorderType << true << true;
+ QTest::newRow("Resource is not shared") << AudioRecorderType << false << false;
+ QTest::newRow("Resource is shared") << VideoPlaybackType << true << true;
+ QTest::newRow("Resource is not shared") << VideoPlaybackType << false << false;
+ QTest::newRow("Resource is shared") << VideoRecorderType << true << true;
+ QTest::newRow("Resource is not shared") << VideoRecorderType << false << false;
+ QTest::newRow("Resource is shared") << VibraType << true << true;
+ QTest::newRow("Resource is not shared") << VibraType<< false << false;
+ QTest::newRow("Resource is shared") << BacklightType << true << true;
+ QTest::newRow("Resource is not shared") << BacklightType << false << false;
+ QTest::newRow("Resource is shared") << SystemButtonType << true << true;
+ QTest::newRow("Resource is not shared") << SystemButtonType << false << false;
+ QTest::newRow("Resource is shared") << LedsType << true << true;
+ QTest::newRow("Resource is not shared") << LedsType << false << false;
+ QTest::newRow("Resource is shared") << LockButtonType << true << true;
+ QTest::newRow("Resource is not shared") << LockButtonType << false << false;
+ QTest::newRow("Resource is shared") << ScaleButtonType << true << true;
+ QTest::newRow("Resource is not shared") << ScaleButtonType << false << false;
+ QTest::newRow("Resource is shared") << SnapButtonType << true << true;
+ QTest::newRow("Resource is not shared") << SnapButtonType << false << false;
+ QTest::newRow("Resource is shared") << LensCoverType << true << true;
+ QTest::newRow("Resource is not shared") << LensCoverType << false << false;
}
void TestResource::testShared()
{
- QFETCH(bool, optional);
+ QFETCH(ResourceType, type);
+ QFETCH(bool, shared);
QFETCH(bool, expected);
- resource->setType(AudioPlaybackResource);
- resource->setShared(optional);
+ Resource *resource = resourceFromType(type);
+ resource->setShared(shared);
+
bool result = resource->isShared();
QCOMPARE(result, expected);
}
-void TestResource::testCopy()
+void TestResource::testGranted_data()
{
- Resource copy;
- resource->setType(AudioPlaybackResource);
- resource->setOptional();
-
- copy = *resource;
-
- QCOMPARE(copy.isOptional(), resource->isOptional());
- QCOMPARE(copy.isShared(), resource->isShared());
- QCOMPARE(copy.type(), resource->type());
+ QTest::addColumn<ResourceType>("type");
+ QTest::addColumn<bool>("granted");
+ QTest::addColumn<bool>("expected");
+
+ QTest::newRow("Resource is granted") << AudioPlaybackType << true << true;
+ QTest::newRow("Resource is denied") << AudioPlaybackType << false << false;
+ QTest::newRow("Resource is granted") << AudioRecorderType << true << true;
+ QTest::newRow("Resource is denied") << AudioRecorderType << false << false;
+ QTest::newRow("Resource is granted") << VideoPlaybackType << true << true;
+ QTest::newRow("Resource is denied") << VideoPlaybackType << false << false;
+ QTest::newRow("Resource is granted") << VideoRecorderType << true << true;
+ QTest::newRow("Resource is denied") << VideoRecorderType << false << false;
+ QTest::newRow("Resource is granted") << VibraType << true << true;
+ QTest::newRow("Resource is denied") << VibraType<< false << false;
+ QTest::newRow("Resource is granted") << BacklightType << true << true;
+ QTest::newRow("Resource is denied") << BacklightType << false << false;
+ QTest::newRow("Resource is granted") << SystemButtonType << true << true;
+ QTest::newRow("Resource is denied") << SystemButtonType << false << false;
+ QTest::newRow("Resource is granted") << LedsType << true << true;
+ QTest::newRow("Resource is denied") << LedsType << false << false;
+ QTest::newRow("Resource is granted") << LockButtonType << true << true;
+ QTest::newRow("Resource is denied") << LockButtonType << false << false;
+ QTest::newRow("Resource is granted") << ScaleButtonType << true << true;
+ QTest::newRow("Resource is denied") << ScaleButtonType << false << false;
+ QTest::newRow("Resource is granted") << SnapButtonType << true << true;
+ QTest::newRow("Resource is denied") << SnapButtonType << false << false;
+ QTest::newRow("Resource is granted") << LensCoverType << true << true;
+ QTest::newRow("Resource is denied") << LensCoverType << false << false;
}
-void TestResource::testCopyConstructor()
+void TestResource::testGranted()
{
- resource->setType(AudioPlaybackResource);
- resource->setOptional();
- Resource copy(*resource);
+ QFETCH(ResourceType, type);
+ QFETCH(bool, granted);
+ QFETCH(bool, expected);
- QCOMPARE(copy.isOptional(), resource->isOptional());
- QCOMPARE(copy.isShared(), resource->isShared());
- QCOMPARE(copy.type(), resource->type());
-}
+ Resource *resource = resourceFromType(type);
-void TestResource::testEqualsOperator()
-{
- Resource copy;
- resource->setType(AudioPlaybackResource);
- copy = *resource;
+ if(granted)
+ resource->setGranted();
+ else
+ resource->unsetGranted();
+ bool result = resource->isGranted();
- resource->setOptional();
- resource->setShared();
-
- QVERIFY(copy == *resource);
+ QVERIFY(result == expected);
}
-void TestResource::testEqualsOperatorWithDifferentTypes()
+void TestResource::testClone()
{
- Resource copy;
- resource->setType(AudioPlaybackResource);
- copy = *resource;
-
- resource->setOptional();
- copy.setType(VideoPlaybackResource);
+ for(quint32 type=AudioPlaybackType; type < NumberOfTypes; type++) {
+ Resource *resource = resourceFromType((ResourceType)type);
+ resource->setOptional();
+ Resource *copy = resource->clone();
- QEXPECT_FAIL("", "Expecting to fail since different types.", Continue);
- QVERIFY(copy == *resource);
+ QCOMPARE(copy->isOptional(), resource->isOptional());
+ QCOMPARE(copy->isShared(), resource->isShared());
+ QCOMPARE(copy->isGranted(), resource->isGranted());
+ QCOMPARE(copy->type(), resource->type());
+ delete copy;
+ }
}
QTEST_MAIN(TestResource)
+
diff --git a/tests/test-resource.h b/tests/test-resource.h
index b0e6964..fc04c47 100644
--- a/tests/test-resource.h
+++ b/tests/test-resource.h
@@ -3,7 +3,7 @@
#include <QtTest/QTest>
#include <QMetaType>
-#include "resource.h"
+#include "resources.h"
Q_DECLARE_METATYPE(ResourcePolicy::ResourceType)
@@ -11,33 +11,44 @@ using namespace ResourcePolicy;
class TestResource: public QObject
{
- Q_OBJECT
+ Q_OBJECT
private:
- Resource *resource;
-
+ AudioResource *audioResource;
+ AudioRecorderResource *audioRecorderResource;
+ Resource *videoResource;
+ Resource *videoRecorderResource;
+ Resource *vibraResource;
+ Resource *ledsResource;
+ Resource *backlightResource;
+ Resource *systemButtonResource;
+ Resource *lockButtonResource;
+ Resource *scaleButtonResource;
+ Resource *snapButtonResource;
+ Resource *lensCoverResource;
+
+ Resource * resourceFromType(ResourceType type);
+ const char * stringFromType(ResourceType type);
public:
- TestResource();
- ~TestResource();
+ TestResource();
+ ~TestResource();
private slots:
- void init();
- void cleanup();
+ void init();
+ void cleanup();
+
+ void testType();
- void testType_data();
- void testType();
-
- void testOptional_data();
- void testOptional();
+ void testOptional_data();
+ void testOptional();
- void testShared_data();
- void testShared();
+ void testShared_data();
+ void testShared();
- void testCopy();
- void testCopyConstructor();
+ void testGranted_data();
+ void testGranted();
- void testEqualsOperator();
- void testEqualsOperatorWithDifferentTypes();
+ void testClone();
};
#endif
diff --git a/tests/test-resource.pro b/tests/test-resource.pro
index bb4da4c..7ab2678 100644
--- a/tests/test-resource.pro
+++ b/tests/test-resource.pro
@@ -6,8 +6,8 @@ DEPENDPATH += $${BASE}/include $${BASE}/src .
INCLUDEPATH += $${BASE}/src $${BASE}/include
# Input
-HEADERS += $${BASE}/include/resource.h test-resource.h
-SOURCES += $${BASE}/src/resource.cpp test-resource.cpp
+HEADERS += $${BASE}/include/resource.h $${BASE}/include/resources.h test-resource.h
+SOURCES += $${BASE}/src/resource.cpp $${BASE}/src/resources.cpp test-resource.cpp
OBJECTS_DIR = build
MOC_DIR = build