summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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
Diffstat (limited to 'tests')
-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
4 files changed, 192 insertions, 28 deletions
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