summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h20
-rw-r--r--libresourceqt/src/resource-engine.cpp3
-rw-r--r--libresourceqt/src/resource-engine.h1
-rw-r--r--libresourceqt/src/resource-set.cpp3
-rw-r--r--tests/test-security-with-aegis-token/test-security-with-aegis-token.pro18
-rw-r--r--tests/test-security-with-aegis-token/test-security.cpp47
-rw-r--r--tests/test-security-without-aegis-token/test-security-without-aegis-token.pro20
-rw-r--r--tests/test-security-without-aegis-token/test-security.cpp47
-rw-r--r--tests/tests.pro4
-rw-r--r--tests/tests.xml7
10 files changed, 162 insertions, 8 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index 2fecd80..710dc7d 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -206,28 +206,34 @@ signals:
*/
void resourcesBecameAvailable(const QList<ResourcePolicy::ResourceType> &availableResources);
/**
- * This signal is emited as a response to the acquire() request.
+ * This signal is emitted as a response to the acquire() request.
* \param grantedOptionalResources The list of granted optional resources.
- * All the mandatory resources have also been aquired.
+ * All the mandatory resources have also been acquired.
*/
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.
+ * This signal is emitted as a response to the acquire() request, in the
+ * case where one or more of the mandatory resources were not available.
*/
void resourcesDenied();
/**
- * This signal is emited as a response to the release() request.
+ * This signal is emitted as a response to the release() request.
*/
void resourcesReleased();
/**
- * This signal is emited when some other program with a higher priority
- * superseeds us, and as a result we loose (some of) our resources.
+ * This signal is emitted when some other program with a higher priority
+ * supersedes us, and as a result we loose (some of) our resources.
* It is very important to connect to this signal as it is signaling when
* the acquired resources shouldn't be used anymore.
*/
void lostResources();
+ /**
+ * Subscribe to this signal to receive error notifications,
+ * particularly security errors.
+ */
+ void errorCallback(quint32, const char*);
+
private:
bool initialize();
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index 6d50b87..e040562 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -429,6 +429,9 @@ void ResourceEngine::handleError(quint32 requestNo, qint32 code, const char *mes
qDebug("ResourceEngine(%d) - Error on request %u(0x%02x): %d - %s",
identifier, requestNo, originalMessageType, code, message);
messageMap.remove(requestNo);
+
+ qDebug("emitting errorCallback");
+ emit errorCallback(code, message);
}
bool ResourceEngine::isConnectedToManager()
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 38849aa..58e071b 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -59,6 +59,7 @@ signals:
void resourcesLost(quint32 bitmaskOfGrantedResources);
void connectedToManager();
void disconnectedFromManager();
+ void errorCallback(quint32 code, const char* );
private:
bool connected;
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index 27e809b..f5faade 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -47,6 +47,9 @@ bool ResourceSet::initialize()
this, SLOT(handleResourcesLost(quint32)));
QObject::connect(resourceEngine, SIGNAL(resourcesBecameAvailable(quint32)),
this, SLOT(handleResourcesBecameAvailable(quint32)));
+ QObject::connect(resourceEngine, SIGNAL(errorCallback(quint32, const char*)),
+ this, SIGNAL(errorCallback(quint32, const char*)));
+
qDebug("initializing resource engine...");
if (!resourceEngine->initialize()) {
return false;
diff --git a/tests/test-security-with-aegis-token/test-security-with-aegis-token.pro b/tests/test-security-with-aegis-token/test-security-with-aegis-token.pro
new file mode 100644
index 0000000..2f30c56
--- /dev/null
+++ b/tests/test-security-with-aegis-token/test-security-with-aegis-token.pro
@@ -0,0 +1,18 @@
+include(../../common.pri)
+TEMPLATE = app
+TARGET = test-security-with-aegis-token
+QT = testlib core
+CONFIG -= app_bundle
+DEPENDPATH += $${POLICY} $${BASE}/src .
+INCLUDEPATH += $${LIBRESOURCEQT}/src $${LIBRESOURCEQT}/include $${LIBRESOURCEINC} $${LIBDBUSQEVENTLOOP}
+
+# Input
+SOURCES += test-security.cpp
+
+LIBS += -L$${LIBDBUSQEVENTLOOP}/build -L$${LIBRESOURCEQT}/build -ldbus-qeventloop -lresourceqt
+
+# Install options
+target.path = /usr/lib/libresourceqt-tests/
+#target.files = test-security-with-aegis-token
+
+INSTALLS = target
diff --git a/tests/test-security-with-aegis-token/test-security.cpp b/tests/test-security-with-aegis-token/test-security.cpp
new file mode 100644
index 0000000..1a90009
--- /dev/null
+++ b/tests/test-security-with-aegis-token/test-security.cpp
@@ -0,0 +1,47 @@
+#include "qt4/policy/resource-set.h"
+#include <cstdio>
+#include <cstdlib>
+#include <QCoreApplication>
+
+using namespace ResourcePolicy;
+
+class TestSecurity: public QObject
+{
+ Q_OBJECT
+
+public:
+ void testSecurity() {
+
+ ResourceSet *resourceSet = new ResourceSet("call", this);
+ resourceSet->addResource(ResourcePolicy::AudioRecorderType);
+
+ connect(resourceSet, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>&)),
+ this, SLOT(resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>&)));
+
+ connect(resourceSet, SIGNAL(errorCallback(quint32, const char*)), this, SLOT(errorCallback(quint32, const char*)));
+
+ resourceSet->acquire();
+ }
+
+private slots:
+ void resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>& /*grantedOptionalResList*/) {
+ printf(">>> resource acquired\n");
+ exit(0);
+ }
+
+ void errorCallback(quint32 code, const char* message) {
+ printf(">>> error %u, %s\n", code, message);
+ exit(1);
+ }
+};
+
+int main(int argc, char* argv[]) {
+ QCoreApplication app(argc, argv);
+
+ TestSecurity *test = new TestSecurity();
+ test->testSecurity();
+
+ return app.exec();
+}
+
+#include "test-security.moc"
diff --git a/tests/test-security-without-aegis-token/test-security-without-aegis-token.pro b/tests/test-security-without-aegis-token/test-security-without-aegis-token.pro
new file mode 100644
index 0000000..fd8b042
--- /dev/null
+++ b/tests/test-security-without-aegis-token/test-security-without-aegis-token.pro
@@ -0,0 +1,20 @@
+include(../../common.pri)
+TEMPLATE = app
+TARGET = test-security-without-aegis-token
+QT = testlib core
+CONFIG -= app_bundle
+DEPENDPATH += $${POLICY} $${BASE}/src .
+INCLUDEPATH += $${LIBRESOURCEQT}/src $${LIBRESOURCEQT}/include $${LIBRESOURCEINC} $${LIBDBUSQEVENTLOOP}
+
+# Input
+SOURCES += test-security.cpp
+
+LIBS += -L$${LIBDBUSQEVENTLOOP}/build -L$${LIBRESOURCEQT}/build -ldbus-qeventloop -lresourceqt
+
+# Install options
+# Install options
+target.path = /usr/lib/libresourceqt-tests/
+#target.files = test-security-without-aegis-token
+
+INSTALLS = target
+
diff --git a/tests/test-security-without-aegis-token/test-security.cpp b/tests/test-security-without-aegis-token/test-security.cpp
new file mode 100644
index 0000000..1a90009
--- /dev/null
+++ b/tests/test-security-without-aegis-token/test-security.cpp
@@ -0,0 +1,47 @@
+#include "qt4/policy/resource-set.h"
+#include <cstdio>
+#include <cstdlib>
+#include <QCoreApplication>
+
+using namespace ResourcePolicy;
+
+class TestSecurity: public QObject
+{
+ Q_OBJECT
+
+public:
+ void testSecurity() {
+
+ ResourceSet *resourceSet = new ResourceSet("call", this);
+ resourceSet->addResource(ResourcePolicy::AudioRecorderType);
+
+ connect(resourceSet, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>&)),
+ this, SLOT(resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>&)));
+
+ connect(resourceSet, SIGNAL(errorCallback(quint32, const char*)), this, SLOT(errorCallback(quint32, const char*)));
+
+ resourceSet->acquire();
+ }
+
+private slots:
+ void resourceAcquiredHandler(const QList<ResourcePolicy::ResourceType>& /*grantedOptionalResList*/) {
+ printf(">>> resource acquired\n");
+ exit(0);
+ }
+
+ void errorCallback(quint32 code, const char* message) {
+ printf(">>> error %u, %s\n", code, message);
+ exit(1);
+ }
+};
+
+int main(int argc, char* argv[]) {
+ QCoreApplication app(argc, argv);
+
+ TestSecurity *test = new TestSecurity();
+ test->testSecurity();
+
+ return app.exec();
+}
+
+#include "test-security.moc"
diff --git a/tests/tests.pro b/tests/tests.pro
index 3d0658c..979688f 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -9,7 +9,9 @@ SUBDIRS = test-dbus-qeventloop \
test-dbus-pong \
test-resource \
test-resource-set \
- test-resource-engine
+ test-resource-engine \
+ test-security-with-aegis-token \
+ test-security-without-aegis-token
# Install options
testsxml.path = /usr/share/libresourceqt-tests/
diff --git a/tests/tests.xml b/tests/tests.xml
index f73b9da..76d69e8 100644
--- a/tests/tests.xml
+++ b/tests/tests.xml
@@ -15,6 +15,13 @@
<step expected_result="0">/usr/lib/libresourceqt-tests/test-resource-engine-wrapper</step>
</case>
+ <case name="test-security-with-token" type="Functional" level="Component" subfeature="libresource Qt API" description="Unit tests for libresourceqt" timeout="15">
+ <step expected_result="0">/usr/lib/libresourceqt-tests/test-security-with-aegis-token</step>
+ </case>
+ <case name="test-security-without-token" type="Functional" level="Component" subfeature="libresource Qt API" description="Unit tests for libresourceqt" timeout="15">
+ <step expected_result="1">/usr/lib/libresourceqt-tests/test-security-without-aegis-token</step>
+ </case>
+
<environments>
<scratchbox>false</scratchbox>
<hardware>true</hardware>