summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-25 13:56:08 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-25 14:00:02 +0200
commit0334e01186cbb1d2a4d5f5d5ad2dabb173d87dc6 (patch)
treeb92e7466d956a8e37a8a63af24b1e3e31a556cb2
parent67649bb4c02c471ac394d490851c7c3ae5126c41 (diff)
downloadlibresourceqt-0334e01186cbb1d2a4d5f5d5ad2dabb173d87dc6.tar.gz
Fixed ResourceSet signals QList<ResourcePolicy::ResourceType> to list
namespace, so the users don't have to use namecpace ResourcePolicy
-rw-r--r--libresourceqt.pro3
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h4
-rw-r--r--libresourceqt/src/resource-engine.h4
-rw-r--r--resourceqt-client/client.cpp2
-rw-r--r--resourceqt-client/client.h14
-rw-r--r--tests/test-resource-engine/test-resource-engine.cpp96
-rw-r--r--tests/test-resource-engine/test-resource-engine.h22
-rw-r--r--tests/test-resource-set/test-resource-set.cpp59
-rw-r--r--tests/test-resource-set/test-resource-set.h43
9 files changed, 205 insertions, 42 deletions
diff --git a/libresourceqt.pro b/libresourceqt.pro
index c5814e4..d032d2e 100644
--- a/libresourceqt.pro
+++ b/libresourceqt.pro
@@ -2,11 +2,10 @@
# Main projectfile
#####################################################################
-CONFIG += ordered
+CONFIG += ordered
TEMPLATE = subdirs
SUBDIRS = libdbus-qeventloop \
libresourceqt \
resourceqt-client \
tests
-
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index bc81b89..e190cd0 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -195,13 +195,13 @@ signals:
* \param availableResources A list of available resources. The list of
* available resources contains only available resource which we have in the set.
*/
- void resourcesBecameAvailable(const QList<ResourceType> &availableResources);
+ void resourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &availableResources);
/**
* This signal is emited as a response to the acquire() request.
* \param grantedOptionalResources The list of granted optional resources.
* All the mandatory resources have also been aquired.
*/
- void resourcesGranted(const QList<ResourceType> &grantedOptionalResources);
+ void resourcesGranted(const QList<ResourcePolicy::ResourceType> &grantedOptionalResources);
/**
* This signal is emited as a response to the acquire() request, in the
* case where one or more of the mandatroy resources were not availalble.
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 6caaef7..897c27e 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -17,8 +17,8 @@ class ResourceEngine: public QObject
{
Q_OBJECT
Q_DISABLE_COPY( ResourceEngine )
-#ifndef QT_NO_DEBUG
- friend class TestResourceEngine;
+#ifdef TEST_RESOURCE_ENGINE_H
+ friend class ::TestResourceEngine;
#endif
public:
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 1c4ce34..27583fe 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -7,6 +7,8 @@
#include "client.h"
+using namespace ResourcePolicy;
+
Client::Client(QString appClass) : QObject()
{
applicationClass = appClass;
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index 81461c5..ed32538 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -6,8 +6,6 @@
#include <policy/resource-set.h>
-using namespace ResourcePolicy;
-
#define RES_AUDIO_PLAYBACK (1<<0)
#define RES_VIDEO_PLAYBACK (1<<1)
#define RES_AUDIO_RECORDING (1<<2)
@@ -33,7 +31,7 @@ public:
static uint32_t parseResourceList(QString resourceListStr);
private slots:
- void resourceAcquiredHandler(const QList<ResourceType>& grantedResList);
+ void resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>& grantedResList);
void resourceDeniedHandler();
void resourceLostHandler();
void resourceReleasedHandler();
@@ -49,14 +47,14 @@ private:
uint32_t resourcesOptional;
QString applicationClass;
- ResourceSet* resourceSet;
+ ResourcePolicy::ResourceSet* resourceSet;
- Resource* allocateResource(ResourceType resource, bool optional);
- ResourceType getResourceType(uint32_t resource);
+ ResourcePolicy::Resource* allocateResource(ResourcePolicy::ResourceType resource, bool optional);
+ ResourcePolicy::ResourceType getResourceType(uint32_t resource);
void showPrompt();
- void showResources(const QList<ResourceType> resList);
- void showResources(const QList<Resource*> resList);
+ void showResources(const QList<ResourcePolicy::ResourceType> resList);
+ void showResources(const QList<ResourcePolicy::Resource*> resList);
void updateSet(uint32_t list, uint32_t optional, bool remove);
};
diff --git a/tests/test-resource-engine/test-resource-engine.cpp b/tests/test-resource-engine/test-resource-engine.cpp
index 804ef16..8b7fe72 100644
--- a/tests/test-resource-engine/test-resource-engine.cpp
+++ b/tests/test-resource-engine/test-resource-engine.cpp
@@ -1,10 +1,12 @@
#include "test-resource-engine.h"
#include <dbus/dbus.h>
+#include <string.h>
using namespace ResourcePolicy;
quint32 theID = 0;
void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message);
+static bool strverify(const char *a, const char *b);
static void verify_resproto_init(resproto_role_t role,
resproto_transport_t transport,
@@ -197,6 +199,65 @@ void TestResourceEngine::testRelease()
QVERIFY(releaseRequestSucceeded == !requestShouldFail);
}
+void TestResourceEngine::testRegisterAudioProperties_data()
+{
+ QTest::addColumn<QString>("audioGroup");
+ QTest::addColumn<quint32>("pid");
+ QTest::addColumn<QString>("streamName");
+ QTest::addColumn<QString>("streamValue");
+
+ QTest::newRow("'player':12345:'media.role':'music'") << "player" << 12345 << "media.role" << "music";
+ QTest::newRow("'':12345:'media.role':'music'") << "" << 12345 << "media.role" << "music";
+ QTest::newRow(":12345:'media.role':'music'") << QString() << 12345 << "media.role" << "music";
+ QTest::newRow("'player':0:'media.role':'music'") << "player" << 0 << "media.role" << "music";
+ QTest::newRow("'player':12345:'':'music'") << "player" << 12345 << "" << "music";
+ QTest::newRow("'player':12345::'music'") << "player" << 12345 << QString() << "music";
+ QTest::newRow("'player':12345:'':''") << "player" << 12345 << "" << "";
+ QTest::newRow("'player':12345::") << "player" << 12345 << QString() << QString();
+ QTest::newRow("'player':12345:'media.role':''") << "player" << 12345 << "media.role" << "";
+ QTest::newRow("'player':12345:'media.role':") << "player" << 12345 << "media.role" << QString();
+ QTest::newRow("'':0:'':''") << "" << 0 << "" << "";
+ QTest::newRow(":0::") << QString() << 0 << QString() << QString();
+}
+
+char *expectedGroup, *expectedStreamName, *expectedStreamValue;
+
+void TestResourceEngine::testRegisterAudioProperties()
+{
+ QFETCH(QString, audioGroup);
+ QFETCH(quint32, pid);
+ QFETCH(QString, streamName);
+ QFETCH(QString, streamValue);
+
+ if(audioGroup.isEmpty() || audioGroup.isNull()) {
+ expectedGroup = NULL;
+ }
+ else {
+ QByteArray ba = audioGroup.toLatin1();
+ expectedGroup = strdup(ba.data());
+ }
+
+ if(streamName.isEmpty() || streamName.isNull()) {
+ expectedStreamName = NULL;
+ }
+ else {
+ QByteArray ba = streamName.toLatin1();
+ expectedStreamName = strdup(ba.data());
+ }
+ if(streamValue.isEmpty() || streamValue.isNull()) {
+ expectedStreamValue = NULL;
+ }
+ else {
+ QByteArray ba = streamValue.toLatin1();
+ expectedStreamValue = strdup(ba.data());
+ }
+
+ resourceEngine->connectToManager();
+
+ bool audioPropertiesSetSucceeded = resourceEngine->registerAudioProperties(audioGroup, pid, streamName, streamValue);
+ QVERIFY(audioPropertiesSetSucceeded);
+}
+
QTEST_MAIN(TestResourceEngine)
////////////////////////////////////////////////////////////////
@@ -348,6 +409,14 @@ int resproto_send_message(resset_t *resourceSet, resmsg_t *message,
grantMessage.record.reqno = message->record.reqno;
grantCallback(&grantMessage, resSet, resSet->userdata);
break;
+ case RESMSG_AUDIO:
+ statusMessage.type = RESMSG_STATUS;
+ statusMessage.status.errcod = 0;
+ statusMessage.status.errmsg = "";
+ statusMessage.record.id = 11;
+ statusMessage.record.reqno = 77;
+ callbackFunction(resSet, &statusMessage);
+ break;
default:
qDebug("Unknown message requested...");
return 0;
@@ -369,16 +438,41 @@ static void verify_resproto_send_message(resset_t *resourceSet, resmsg_t *messag
QVERIFY(message->possess.id == theID);
QVERIFY(callbackFunction != NULL);
break;
+ case RESMSG_AUDIO:
+ QVERIFY(resourceSet == resSet);
+ QVERIFY(message->possess.id == theID);
+ QVERIFY(callbackFunction != NULL);
+ QVERIFY(strverify(expectedGroup, message->audio.group));
+ QVERIFY(strverify(expectedStreamName, message->audio.property.name));
+ QVERIFY(strverify(expectedStreamValue, message->audio.property.match.pattern));
default:
bool expectedMessageType = false;
QVERIFY(expectedMessageType);
}
}
+static bool strverify(const char *a, const char *b)
+{
+ if (a == b) {
+ return true;
+ }
+ else if ((a == NULL) || (b == NULL)) {
+ return false;
+ }
+ else {
+ int i = strcmp(a, b);
+ if (i == 0)
+ return true;
+ else
+ return false;
+ }
+
+}
+
char *resmsg_dump_message(resmsg_t *resmsg,
int indent,
char *buf,
int len)
{
- return "message";
+ char * ret = strdup("message");
} \ No newline at end of file
diff --git a/tests/test-resource-engine/test-resource-engine.h b/tests/test-resource-engine/test-resource-engine.h
index dbdd755..5398a72 100644
--- a/tests/test-resource-engine/test-resource-engine.h
+++ b/tests/test-resource-engine/test-resource-engine.h
@@ -3,26 +3,27 @@
#include <QtTest/QTest>
#include <QMetaType>
+
+class TestResourceEngine;
+
#include "resource-engine.h"
Q_DECLARE_METATYPE(ResourcePolicy::ResourceType)
-namespace ResourcePolicy
-{
class TestResourceEngine: public QObject
{
Q_OBJECT
private:
- ResourceEngine *resourceEngine;
- AudioResource *audioPlayback;
- VideoResource *videoPlayback;
- AudioRecorderResource *audioRecorder;
- VideoRecorderResource *videoRecorder;
+ ResourcePolicy::ResourceEngine *resourceEngine;
+ ResourcePolicy::AudioResource *audioPlayback;
+ ResourcePolicy::VideoResource *videoPlayback;
+ ResourcePolicy::AudioRecorderResource *audioRecorder;
+ ResourcePolicy::VideoRecorderResource *videoRecorder;
bool libresourceInitialized;
bool acquireOrDenyWasCalled;
public:
- ResourceSet *resourceSet;
+ ResourcePolicy::ResourceSet *resourceSet;
TestResourceEngine();
~TestResourceEngine();
@@ -44,7 +45,10 @@ private slots:
void testRelease_data();
void testRelease();
+
+ void testRegisterAudioProperties_data();
+ void testRegisterAudioProperties();
};
-}
+
#endif
diff --git a/tests/test-resource-set/test-resource-set.cpp b/tests/test-resource-set/test-resource-set.cpp
index d9cbbce..61ea71c 100644
--- a/tests/test-resource-set/test-resource-set.cpp
+++ b/tests/test-resource-set/test-resource-set.cpp
@@ -1,5 +1,7 @@
#include "test-resource-set.h"
+using namespace ResourcePolicy;
+
Resource * TestResourceSet::resourceFromType(ResourceType type)
{
switch (type) {
@@ -125,5 +127,62 @@ void TestResourceSet::testContainsSet()
QVERIFY(containsAll);
QVERIFY(containsSubset);
}
+
+void TestResourceSet::testConnectToSignals()
+{
+ bool signalConnectionSucceeded=false;
+ signalConnectionSucceeded = QObject::connect(resourceSet,
+ SIGNAL(resourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &)),
+ this, SLOT(handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &)));
+
+ QVERIFY(signalConnectionSucceeded);
+
+ signalConnectionSucceeded = QObject::connect(resourceSet,
+ SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType> &)),
+ this, SLOT(handleResourcesGranted(const QList<ResourcePolicy::ResourceType> &)));
+
+ QVERIFY(signalConnectionSucceeded);
+
+ signalConnectionSucceeded = QObject::connect(resourceSet,
+ SIGNAL(resourcesDenied()),
+ this, SLOT(handleResourcesDenied()));
+
+ QVERIFY(signalConnectionSucceeded);
+
+ signalConnectionSucceeded = QObject::connect(resourceSet,
+ SIGNAL(resourcesReleased()),
+ this, SLOT(handleResourcesReleased()));
+
+ QVERIFY(signalConnectionSucceeded);
+
+ signalConnectionSucceeded = QObject::connect(resourceSet,
+ SIGNAL(lostResources()),
+ this, SLOT(handleLostResources()));
+
+ QVERIFY(signalConnectionSucceeded);
+
+}
+
+void TestResourceSet::handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &availableResources)
+{
+
+}
+void TestResourceSet::handleResourcesGranted(const QList<ResourcePolicy::ResourceType> &grantedOptionalResources)
+{
+}
+
+void TestResourceSet::handleResourcesDenied()
+{
+}
+
+void TestResourceSet::handleResourcesReleased()
+{
+}
+
+void TestResourceSet::handleLostResources()
+{
+}
+
+
QTEST_MAIN(TestResourceSet)
diff --git a/tests/test-resource-set/test-resource-set.h b/tests/test-resource-set/test-resource-set.h
index abab859..c112b6c 100644
--- a/tests/test-resource-set/test-resource-set.h
+++ b/tests/test-resource-set/test-resource-set.h
@@ -4,32 +4,37 @@
#include <QtTest/QTest>
#include <policy/resource-set.h>
-using namespace ResourcePolicy;
-
class TestResourceSet: public QObject
{
Q_OBJECT
private:
- 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);
+ ResourcePolicy::ResourceSet *resourceSet;
+
+ ResourcePolicy::AudioResource *audioResource;
+ ResourcePolicy::AudioRecorderResource *audioRecorderResource;
+ ResourcePolicy::Resource *videoResource;
+ ResourcePolicy::Resource *videoRecorderResource;
+ ResourcePolicy::Resource *vibraResource;
+ ResourcePolicy::Resource *ledsResource;
+ ResourcePolicy::Resource *backlightResource;
+ ResourcePolicy::Resource *systemButtonResource;
+ ResourcePolicy::Resource *lockButtonResource;
+ ResourcePolicy::Resource *scaleButtonResource;
+ ResourcePolicy::Resource *snapButtonResource;
+ ResourcePolicy::Resource *lensCoverResource;
+
+ ResourcePolicy::Resource * resourceFromType(ResourcePolicy::ResourceType type);
public:
TestResourceSet();
~TestResourceSet();
+public slots:
+
+ void handleResourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &availableResources);
+ void handleResourcesGranted(const QList<ResourcePolicy::ResourceType> &grantedOptionalResources);
+ void handleResourcesDenied();
+ void handleResourcesReleased();
+ void handleLostResources();
private slots:
@@ -43,6 +48,8 @@ private slots:
void testDelResource();
void testContainsSet();
+
+ void testConnectToSignals();
};
#endif