summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Wolf <ext-martin.2.wolf@nokia.com>2010-03-19 12:29:36 +0200
committerMartin Wolf <ext-martin.2.wolf@nokia.com>2010-03-19 12:29:36 +0200
commitcedefad1cbd0857fd1247dfb65a38f1bd0323304 (patch)
tree0cc87b46efdc11d631ddecd5bab1bddb2f3f7305 /tests
parent6eff9f8263541053b66d10960e909707ed592f62 (diff)
parent50dbb5b9aad308fe9c23db4e6db3f4b1a07dab17 (diff)
downloadlibresourceqt-cedefad1cbd0857fd1247dfb65a38f1bd0323304.tar.gz
Merge branch 'master' of ssh://mawolf@karma.research.nokia.com/u/repositories/libresourceqt
Diffstat (limited to 'tests')
-rw-r--r--tests/test-resource-engine/test-resource-engine.cpp116
-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, 203 insertions, 37 deletions
diff --git a/tests/test-resource-engine/test-resource-engine.cpp b/tests/test-resource-engine/test-resource-engine.cpp
index 804ef16..42f1a0e 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,
@@ -129,28 +131,28 @@ void TestResourceEngine::testAcquire()
void TestResourceEngine::handleAcquire(quint32 bitmaskOfGrantedResources)
{
- qDebug("Acquired resources: 0x%04x", bitmaskOfGrantedResources);
+ //qDebug("Acquired resources: 0x%04x", bitmaskOfGrantedResources);
QVERIFY(messageOperationShoulSucceed);
bool hasOptionalResource = false;
QList<Resource *> resourceList = resourceSet->resources();
for (int i=0; i < resourceList.size(); i++) {
quint32 bitmask = resourceTypeToLibresourceType(resourceList.at(i)->type());
- qDebug("Checking if resource %x(%x) is in the list", resourceList.at(i)->type(), bitmask);
+ //qDebug("Checking if resource %x(%x) is in the list", resourceList.at(i)->type(), bitmask);
if ((bitmask & bitmaskOfGrantedResources) == bitmask)
{
- qDebug("Yes :)");
+ //qDebug("Yes :)");
if (resourceList.at(i)->type() == optionalType) {
- qDebug("Resource is the one we are looking for. :D");
+ //qDebug("Resource is the one we are looking for. :D");
hasOptionalResource = true;
break;
}
}
else {
- qDebug("No :(");
+ //qDebug("No :(");
}
}
if ((optionalType == NumberOfTypes) && (bitmaskOfGrantedResources > 0)) {
- qDebug("Expected to get no optional resources");
+ //qDebug("Expected to get no optional resources");
hasOptionalResource = true;
}
QVERIFY(hasOptionalResource);
@@ -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" << 12345u << "media.role" << "music";
+ QTest::newRow("'':12345:'media.role':'music'") << "" << 12345u << "media.role" << "music";
+ QTest::newRow(":12345:'media.role':'music'") << QString() << 12345u << "media.role" << "music";
+ QTest::newRow("'player':0:'media.role':'music'") << "player" << 0u << "media.role" << "music";
+ QTest::newRow("'player':12345:'':'music'") << "player" << 12345u << "" << "music";
+ QTest::newRow("'player':12345::'music'") << "player" << 12345u << QString() << "music";
+ QTest::newRow("'player':12345:'':''") << "player" << 12345u << "" << "";
+ QTest::newRow("'player':12345::") << "player" << 12345u << QString() << QString();
+ QTest::newRow("'player':12345:'media.role':''") << "player" << 12345u << "media.role" << "";
+ QTest::newRow("'player':12345:'media.role':") << "player" << 12345u << "media.role" << QString();
+ QTest::newRow("'':0:'':''") << "" << 0u << "" << "";
+ QTest::newRow(":0::") << QString() << 0u << QString() << QString();
+}
+
+char *expectedGroup, *expectedStreamName, *expectedStreamValue;
+
+void TestResourceEngine::testRegisterAudioProperties()
+{
+ QFETCH(QString, audioGroup);
+ QFETCH(quint32, pid);
+ QFETCH(QString, streamName);
+ QFETCH(QString, streamValue);
+
+ requestShouldFail = false;
+
+ if(audioGroup.isEmpty() || audioGroup.isNull()) {
+ expectedGroup = NULL;
+ }
+ else {
+ QByteArray ba = audioGroup.toLatin1();
+ expectedGroup = strdup(ba.data());
+ }
+
+ if(streamName.isEmpty() || streamName.isNull() || streamValue.isEmpty() || streamValue.isNull()) {
+ expectedStreamName = NULL;
+ expectedStreamValue = NULL;
+ }
+ else {
+ QByteArray ba = streamName.toLatin1();
+ expectedStreamName = strdup(ba.data());
+ ba = streamValue.toLatin1();
+ expectedStreamValue = strdup(ba.data());
+ }
+ //qDebug() << "streamValue = " << streamValue;
+ //qDebug("expectedStreamValue = %s", expectedStreamValue);
+
+ resourceEngine->connectToManager();
+
+ bool audioPropertiesSetSucceeded = resourceEngine->registerAudioProperties(audioGroup, pid, streamName, streamValue);
+ QVERIFY(audioPropertiesSetSucceeded);
+}
+
QTEST_MAIN(TestResourceEngine)
////////////////////////////////////////////////////////////////
@@ -297,7 +358,7 @@ int resconn_disconnect(resset_t *resSet, resmsg_t *message,
static void verify_resconn_disconnect(resset_t *resourceSet, resmsg_t *message,
resproto_status_t callbackFunction)
{
- qDebug("resourceSet = %p resSet = %p", resourceSet, resSet);
+ //qDebug("resourceSet = %p resSet = %p", resourceSet, resSet);
QVERIFY(resourceSet == resSet);
QVERIFY(message->record.type == RESMSG_UNREGISTER);
QVERIFY(message->record.id == theID);
@@ -309,7 +370,7 @@ int resproto_send_message(resset_t *resourceSet, resmsg_t *message,
resproto_status_t callbackFunction)
{
resmsg_t grantMessage, statusMessage;
- qDebug("%s(): id:%u req#: %u", __FUNCTION__, message->record.id, message->record.reqno);
+ //qDebug("%s(): id:%u req#: %u", __FUNCTION__, message->record.id, message->record.reqno);
verify_resproto_send_message(resourceSet, message, callbackFunction);
@@ -348,8 +409,16 @@ 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...");
+ //qDebug("Unknown message requested...");
return 0;
}
@@ -369,16 +438,43 @@ 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));
+ break;
default:
bool expectedMessageType = false;
QVERIFY(expectedMessageType);
}
}
+static bool strverify(const char *a, const char *b)
+{
+ //qDebug("a='%s' b='%s'", a, 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