summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-dbus-pong/pong.h8
-rw-r--r--tests/test-dbus-pong/test-dbus-pong.cpp134
-rw-r--r--tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp544
-rw-r--r--tests/test-resource-engine/test-resource-engine.cpp26
-rw-r--r--tests/test-resource-engine/test-resource-engine.h64
-rw-r--r--tests/test-resource-set/test-resource-set.cpp8
-rw-r--r--tests/test-resource-set/test-resource-set.h28
-rw-r--r--tests/test-resource/test-resource.cpp14
8 files changed, 398 insertions, 428 deletions
diff --git a/tests/test-dbus-pong/pong.h b/tests/test-dbus-pong/pong.h
index 21f0082..3e81aa0 100644
--- a/tests/test-dbus-pong/pong.h
+++ b/tests/test-dbus-pong/pong.h
@@ -5,11 +5,11 @@
class Pong: public QObject
{
- Q_OBJECT
+ Q_OBJECT
public slots:
- Q_SCRIPTABLE QString ping(const QString &arg);
- Q_SCRIPTABLE unsigned int quit();
- Q_SCRIPTABLE unsigned int timeout();
+ Q_SCRIPTABLE QString ping(const QString &arg);
+ Q_SCRIPTABLE unsigned int quit();
+ Q_SCRIPTABLE unsigned int timeout();
};
#endif // _PONG_H_
diff --git a/tests/test-dbus-pong/test-dbus-pong.cpp b/tests/test-dbus-pong/test-dbus-pong.cpp
index c936cc4..fa4f71c 100644
--- a/tests/test-dbus-pong/test-dbus-pong.cpp
+++ b/tests/test-dbus-pong/test-dbus-pong.cpp
@@ -9,87 +9,79 @@
QString Pong::ping(const QString &arg)
{
- // Just return back
- return QString("%1").arg(arg);
+ // Just return back
+ return QString("%1").arg(arg);
}
unsigned int Pong::quit()
{
- // Quit application
- QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
- // Magic number
- return 12345;
+ // Quit application
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
+ // Magic number
+ return 12345;
}
unsigned int Pong::timeout()
{
- // Timeout in testing application should be set to less than 2 seconds!
- sleep(2);
- // Just to suppress warning
- return 54321;
+ // Timeout in testing application should be set to less than 2 seconds!
+ sleep(2);
+ // Just to suppress warning
+ return 54321;
}
int main(int argc, char **argv)
{
- bool useSessionBus = false;
-
- QCoreApplication app(argc, argv);
- if( app.arguments().count() > 1 )
- {
- if( app.arguments().at(1) == "--session" )
- {
- useSessionBus = true;
- }
- }
-
- QDBusConnection* myBus;
- if( useSessionBus )
- {
- myBus = new QDBusConnection(QDBusConnection::systemBus().sessionBus());
- qDebug("Using session bus ...");
- }
- else
- {
- myBus = new QDBusConnection(QDBusConnection::systemBus().systemBus());
- qDebug("Using system bus ...");
- }
-
- // Check system bus connection
- if( !myBus->isConnected() )
- {
- // Cleanup!!
- delete myBus;
- myBus = NULL;
-
- if( useSessionBus )
- {
- qDebug("Cannot connect to the D-Bus session bus.");
- }
- else
- {
- qDebug("Cannot connect to the D-Bus system bus.");
- }
-
- return 1;
- }
-
- // Create listener service
- if( !myBus->registerService("com.nokia.dbusqeventloop.test") )
- {
- qDebug("%s", qPrintable(QDBusConnection::systemBus().lastError().message()));
- exit(2);
- }
-
- Pong pong;
- // Register all slots as dbus methods
- myBus->registerObject("/", &pong, QDBusConnection::ExportAllSlots);
-
- // Let's go!
- app.exec();
-
- // Cleanup!!
- delete myBus;
- myBus = NULL;
-
- return 0;
+ bool useSessionBus = false;
+
+ QCoreApplication app(argc, argv);
+ if (app.arguments().count() > 1) {
+ if (app.arguments().at(1) == "--session") {
+ useSessionBus = true;
+ }
+ }
+
+ QDBusConnection* myBus;
+ if (useSessionBus) {
+ myBus = new QDBusConnection(QDBusConnection::systemBus().sessionBus());
+ qDebug("Using session bus ...");
+ }
+ else {
+ myBus = new QDBusConnection(QDBusConnection::systemBus().systemBus());
+ qDebug("Using system bus ...");
+ }
+
+ // Check system bus connection
+ if (!myBus->isConnected()) {
+ // Cleanup!!
+ delete myBus;
+ myBus = NULL;
+
+ if (useSessionBus) {
+ qDebug("Cannot connect to the D-Bus session bus.");
+ }
+ else {
+ qDebug("Cannot connect to the D-Bus system bus.");
+ }
+
+ return 1;
+ }
+
+ // Create listener service
+ if (!myBus->registerService("com.nokia.dbusqeventloop.test")) {
+ qDebug("%s", qPrintable(QDBusConnection::systemBus().lastError().message()));
+ exit(2);
+ }
+
+ Pong pong;
+ // Register all slots as dbus methods
+ myBus->registerObject("/", &pong, QDBusConnection::ExportAllSlots);
+
+ // Let's go!
+ app.exec();
+
+ // Cleanup!!
+ delete myBus;
+ myBus = NULL;
+
+ return 0;
}
diff --git a/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp b/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
index 606d2a9..3a005c0 100644
--- a/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
+++ b/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
@@ -3,307 +3,285 @@
class TestDbusQEventLoop: public QObject
{
- Q_OBJECT
+ Q_OBJECT
private:
- DBusConnection* systemBus;
- DBusConnection* sessionBus;
- DBUSConnectionEventLoop* dbusEventLoop;
-
- void resetValues()
- {
- wasInNotifyFnc = 0;
- responseString = 0;
- responseInt = 0;
- typeError = false;
- noResponse = false;
- timerTimeout = false;
- }
-
- void processQTEventLoop(DBusPendingCall* pending, int timeout)
- {
- // Reset response values to zeros and reset errors
- resetValues();
-
- // Do we have something pending?
- if( pending == NULL )
- {
- qDebug("QTEventLoop: pending call is NULL!");
- return;
- }
-
- MYDEBUGC("QTEventLoop: processing loop for %d ms", timeout);
- // If we have some pending operation, let's get notification about result
- dbus_pending_call_set_notify(pending, TestDbusQEventLoop::pendingNotify, this, NULL);
-
- // Setup timeout timer
- int activeTimer = startTimer(timeout);
-
- // Pump QT event loop, but only until pending operation is not finished
- while( !wasInNotifyFnc )
- {
- QCoreApplication::processEvents(QEventLoop::AllEvents);
- if( timerTimeout )
- {
- MYDEBUGC("QTEventLoop: timeout elapsed!!");
- return;
- }
- }
-
- killTimer(activeTimer);
- }
+ DBusConnection* systemBus;
+ DBusConnection* sessionBus;
+ DBUSConnectionEventLoop* dbusEventLoop;
+
+ void resetValues() {
+ wasInNotifyFnc = 0;
+ responseString = 0;
+ responseInt = 0;
+ typeError = false;
+ noResponse = false;
+ timerTimeout = false;
+ }
+
+ void processQTEventLoop(DBusPendingCall* pending, int timeout) {
+ // Reset response values to zeros and reset errors
+ resetValues();
+
+ // Do we have something pending?
+ if (pending == NULL) {
+ qDebug("QTEventLoop: pending call is NULL!");
+ return;
+ }
+
+ MYDEBUGC("QTEventLoop: processing loop for %d ms", timeout);
+ // If we have some pending operation, let's get notification about result
+ dbus_pending_call_set_notify(pending, TestDbusQEventLoop::pendingNotify, this, NULL);
+
+ // Setup timeout timer
+ int activeTimer = startTimer(timeout);
+
+ // Pump QT event loop, but only until pending operation is not finished
+ while (!wasInNotifyFnc) {
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+ if (timerTimeout) {
+ MYDEBUGC("QTEventLoop: timeout elapsed!!");
+ return;
+ }
+ }
+
+ killTimer(activeTimer);
+ }
public:
- int pongServerRunningSession;
- int pongServerRunningSystem;
- int wasInNotifyFnc;
- const char* responseString;
- uint32_t responseInt;
- bool typeError;
- bool noResponse;
- bool timerTimeout;
-
- TestDbusQEventLoop()
- {
- resetValues();
- }
+ int pongServerRunningSession;
+ int pongServerRunningSystem;
+ int wasInNotifyFnc;
+ const char* responseString;
+ uint32_t responseInt;
+ bool typeError;
+ bool noResponse;
+ bool timerTimeout;
+
+ TestDbusQEventLoop() {
+ resetValues();
+ }
protected:
- void timerEvent(QTimerEvent *e)
- {
- // Set timeout flag and kill timer
- timerTimeout = true;
- killTimer(e->timerId());
+ void timerEvent(QTimerEvent *e) {
+ // Set timeout flag and kill timer
+ timerTimeout = true;
+ killTimer(e->timerId());
}
- static void pendingNotify(DBusPendingCall *pending, void *user_data)
- {
- MYDEBUG();
- // Get pointer to main class
- TestDbusQEventLoop* pThis = reinterpret_cast<TestDbusQEventLoop*>(user_data);
- // Get message from pending call
- DBusMessage* message = dbus_pending_call_steal_reply(pending);
-
- DBusMessageIter args;
- // Parse message
- if( !dbus_message_iter_init(message, &args) )
- MYDEBUGC("Reply message has no arguments!");
- else
- {
- // Extract error message if is present
- const char* error = dbus_message_get_error_name(message);
-
- if( error != NULL )
- {
- // Check if it is NoReply message
- pThis->noResponse = (strcmp(error, "org.freedesktop.DBus.Error.NoReply") == 0);
- }
-
- // Get first argument
- int argType = dbus_message_iter_get_arg_type(&args);
- switch( argType )
- {
- case DBUS_TYPE_STRING:
- // Get string value
- dbus_message_iter_get_basic(&args, &pThis->responseString);
-
- // Display some debug info
- if( error != NULL )
- {
- MYDEBUGC("Got error [%s]: %s", error, pThis->responseString);
- }
- else
- {
- MYDEBUGC("Got Reply: %s", pThis->responseString);
- }
- break;
- case DBUS_TYPE_UINT32:
- // Handle integer
- dbus_message_iter_get_basic(&args, &pThis->responseInt);
- // Display some debug info
- MYDEBUGC("Got Reply: %d", pThis->responseInt);
- break;
- default:
- // Set unknown type flag
- pThis->typeError = true;
- // Display some debug info
- MYDEBUGC("Reply message argument has unsupported type (%d)!", argType);
- }
- }
-
- // Free message if needed
- if( message )
- dbus_message_unref(message);
-
- // Free pending call
- dbus_pending_call_unref(pending);
- // Set flag to end QEventLoop handler
- pThis->wasInNotifyFnc = 1;
- }
+ static void pendingNotify(DBusPendingCall *pending, void *user_data) {
+ MYDEBUG();
+ // Get pointer to main class
+ TestDbusQEventLoop* pThis = reinterpret_cast<TestDbusQEventLoop*>(user_data);
+ // Get message from pending call
+ DBusMessage* message = dbus_pending_call_steal_reply(pending);
+
+ DBusMessageIter args;
+ // Parse message
+ if (!dbus_message_iter_init(message, &args))
+ MYDEBUGC("Reply message has no arguments!");
+ else {
+ // Extract error message if is present
+ const char* error = dbus_message_get_error_name(message);
+
+ if (error != NULL) {
+ // Check if it is NoReply message
+ pThis->noResponse = (strcmp(error, "org.freedesktop.DBus.Error.NoReply") == 0);
+ }
+
+ // Get first argument
+ int argType = dbus_message_iter_get_arg_type(&args);
+ switch (argType) {
+ case DBUS_TYPE_STRING:
+ // Get string value
+ dbus_message_iter_get_basic(&args, &pThis->responseString);
+
+ // Display some debug info
+ if (error != NULL) {
+ MYDEBUGC("Got error [%s]: %s", error, pThis->responseString);
+ }
+ else {
+ MYDEBUGC("Got Reply: %s", pThis->responseString);
+ }
+ break;
+ case DBUS_TYPE_UINT32:
+ // Handle integer
+ dbus_message_iter_get_basic(&args, &pThis->responseInt);
+ // Display some debug info
+ MYDEBUGC("Got Reply: %d", pThis->responseInt);
+ break;
+ default:
+ // Set unknown type flag
+ pThis->typeError = true;
+ // Display some debug info
+ MYDEBUGC("Reply message argument has unsupported type (%d)!", argType);
+ }
+ }
+
+ // Free message if needed
+ if (message)
+ dbus_message_unref(message);
+
+ // Free pending call
+ dbus_pending_call_unref(pending);
+ // Set flag to end QEventLoop handler
+ pThis->wasInNotifyFnc = 1;
+ }
private slots:
- void initTestCase()
- {
- // First allocate and obtain
- dbusEventLoop = new DBUSConnectionEventLoop();
- systemBus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- sessionBus = dbus_bus_get(DBUS_BUS_SESSION, NULL);;
- // Last check, if server is running
- pongServerRunningSystem = dbus_bus_name_has_owner(systemBus, "com.nokia.dbusqeventloop.test", NULL);
- pongServerRunningSession = dbus_bus_name_has_owner(sessionBus, "com.nokia.dbusqeventloop.test", NULL);
-
-
- // Create event loop ...
- QVERIFY(dbusEventLoop != NULL);
- QVERIFY(dbusEventLoop->addConnection(systemBus) == true);
- QVERIFY(dbusEventLoop->addConnection(sessionBus) == true);
- // Then test ... otherwise something don't have to be allocated (i.e. event loop)
- QVERIFY(systemBus != NULL);
- QVERIFY(sessionBus != NULL);
- QVERIFY(pongServerRunningSystem != 0);
- QVERIFY(pongServerRunningSession != 0);
- }
-
- void cleanupTestCase()
- {
- // Create "quit" method call message
- DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "quit");
- DBusPendingCall* pending;
- QVERIFY(message != NULL);
-
- // Set correct values to suppress fake errors if connection fails in initTestCase()
- bool systemTimeout = false, sessionTimeout = false;
- int systemResponse = 12345, sessionResponse = 12345;
-
- // If pong server is running on system bus then send quit
- if( pongServerRunningSystem )
- {
- // Send the message
- dbus_connection_send_with_reply(systemBus, message, &pending, 1000);
- // Wait for response
- processQTEventLoop(pending, 4000);
- systemTimeout = timerTimeout;
- systemResponse = responseInt;
- }
-
- // If pong server is running on session bus then send quit
- if( pongServerRunningSession )
- {
- // Send the message
- dbus_connection_send_with_reply(sessionBus, message, &pending, 1000);
- // Wait for response
- processQTEventLoop(pending, 4000);
- sessionTimeout = timerTimeout;
- sessionResponse = responseInt;
- }
-
- // Free message, it is not necessary to test, QVERIFY upper will end function
- dbus_message_unref(message);
-
- // Cleanup allocated pointers
- QVERIFY(dbusEventLoop != NULL);
- if( dbusEventLoop )
- {
- delete dbusEventLoop;
- dbusEventLoop = NULL;
- }
-
- // Check if everything went well
- QVERIFY(systemTimeout == false);
- QVERIFY(systemResponse == 12345);
- QVERIFY(sessionTimeout == false);
- QVERIFY(sessionResponse == 12345);
- }
-
- void pingSystemBusTest()
- {
- // Create message
- DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "ping");
- QVERIFY(message != NULL);
- // Add argument to message
- const char* temp = "pekny kohutik co sa prechadza po svojom novom dvore a obzera si sliepocky";
- dbus_message_append_args(message, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
-
- DBusPendingCall* pending;
- // Send the message
+ void initTestCase() {
+ // First allocate and obtain
+ dbusEventLoop = new DBUSConnectionEventLoop();
+ systemBus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ sessionBus = dbus_bus_get(DBUS_BUS_SESSION, NULL);;
+ // Last check, if server is running
+ pongServerRunningSystem = dbus_bus_name_has_owner(systemBus, "com.nokia.dbusqeventloop.test", NULL);
+ pongServerRunningSession = dbus_bus_name_has_owner(sessionBus, "com.nokia.dbusqeventloop.test", NULL);
+
+
+ // Create event loop ...
+ QVERIFY(dbusEventLoop != NULL);
+ QVERIFY(dbusEventLoop->addConnection(systemBus) == true);
+ QVERIFY(dbusEventLoop->addConnection(sessionBus) == true);
+ // Then test ... otherwise something don't have to be allocated (i.e. event loop)
+ QVERIFY(systemBus != NULL);
+ QVERIFY(sessionBus != NULL);
+ QVERIFY(pongServerRunningSystem != 0);
+ QVERIFY(pongServerRunningSession != 0);
+ }
+
+ void cleanupTestCase() {
+ // Create "quit" method call message
+ DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "quit");
+ DBusPendingCall* pending;
+ QVERIFY(message != NULL);
+
+ // Set correct values to suppress fake errors if connection fails in initTestCase()
+ bool systemTimeout = false, sessionTimeout = false;
+ int systemResponse = 12345, sessionResponse = 12345;
+
+ // If pong server is running on system bus then send quit
+ if (pongServerRunningSystem) {
+ // Send the message
+ dbus_connection_send_with_reply(systemBus, message, &pending, 1000);
+ // Wait for response
+ processQTEventLoop(pending, 4000);
+ systemTimeout = timerTimeout;
+ systemResponse = responseInt;
+ }
+
+ // If pong server is running on session bus then send quit
+ if (pongServerRunningSession) {
+ // Send the message
+ dbus_connection_send_with_reply(sessionBus, message, &pending, 1000);
+ // Wait for response
+ processQTEventLoop(pending, 4000);
+ sessionTimeout = timerTimeout;
+ sessionResponse = responseInt;
+ }
+
+ // Free message, it is not necessary to test, QVERIFY upper will end function
+ dbus_message_unref(message);
+
+ // Cleanup allocated pointers
+ QVERIFY(dbusEventLoop != NULL);
+ if (dbusEventLoop) {
+ delete dbusEventLoop;
+ dbusEventLoop = NULL;
+ }
+
+ // Check if everything went well
+ QVERIFY(systemTimeout == false);
+ QVERIFY(systemResponse == 12345);
+ QVERIFY(sessionTimeout == false);
+ QVERIFY(sessionResponse == 12345);
+ }
+
+ void pingSystemBusTest() {
+ // Create message
+ DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "ping");
+ QVERIFY(message != NULL);
+ // Add argument to message
+ const char* temp = "pekny kohutik co sa prechadza po svojom novom dvore a obzera si sliepocky";
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
+
+ DBusPendingCall* pending;
+ // Send the message
dbus_connection_send_with_reply(systemBus, message, &pending, 3000);
- // Free message
- dbus_message_unref(message);
- // Process event loop
- processQTEventLoop(pending, 4000);
- // Check results
- QVERIFY(timerTimeout == false);
- QVERIFY(typeError == false);
- QVERIFY(strcmp(temp, responseString) == 0);
- }
-
- void timeoutSystemBusTest()
- {
- // Create message
- DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "timeout");
- QVERIFY(message != NULL);
-
- DBusPendingCall* pending;
- // Send the message
+ // Free message
+ dbus_message_unref(message);
+ // Process event loop
+ processQTEventLoop(pending, 4000);
+ // Check results
+ QVERIFY(timerTimeout == false);
+ QVERIFY(typeError == false);
+ QVERIFY(strcmp(temp, responseString) == 0);
+ }
+
+ void timeoutSystemBusTest() {
+ // Create message
+ DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "timeout");
+ QVERIFY(message != NULL);
+
+ DBusPendingCall* pending;
+ // Send the message
dbus_connection_send_with_reply(systemBus, message, &pending, 1000);
- // Free message
- dbus_message_unref(message);
- // Process event loop
- processQTEventLoop(pending, 3000);
- // Check results
- QVERIFY(timerTimeout == false);
- QVERIFY(noResponse == true);
- QVERIFY(typeError == false);
- // Small pause to process reply
- sleep(1);
- }
-
- void pingSessionBusTest()
- {
- // Create message
- DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "ping");
- QVERIFY(message != NULL);
- // Add argument to message
- const char* temp = "pekny kohutik co sa prechadza po svojom novom dvore a obzera si sliepocky";
- dbus_message_append_args(message, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
-
- DBusPendingCall* pending;
- // Send the message
+ // Free message
+ dbus_message_unref(message);
+ // Process event loop
+ processQTEventLoop(pending, 3000);
+ // Check results
+ QVERIFY(timerTimeout == false);
+ QVERIFY(noResponse == true);
+ QVERIFY(typeError == false);
+ // Small pause to process reply
+ sleep(1);
+ }
+
+ void pingSessionBusTest() {
+ // Create message
+ DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "ping");
+ QVERIFY(message != NULL);
+ // Add argument to message
+ const char* temp = "pekny kohutik co sa prechadza po svojom novom dvore a obzera si sliepocky";
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &temp, DBUS_TYPE_INVALID);
+
+ DBusPendingCall* pending;
+ // Send the message
dbus_connection_send_with_reply(sessionBus, message, &pending, 3000);
- // Free message
- dbus_message_unref(message);
- // Process event loop
- processQTEventLoop(pending, 4000);
- // Check results
- QVERIFY(timerTimeout == false);
- QVERIFY(typeError == false);
- QVERIFY(strcmp(temp, responseString) == 0);
- }
-
- void timeoutSessionBusTest()
- {
- // Create message
- DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "timeout");
- QVERIFY(message != NULL);
-
- DBusPendingCall* pending;
- // Send the message
+ // Free message
+ dbus_message_unref(message);
+ // Process event loop
+ processQTEventLoop(pending, 4000);
+ // Check results
+ QVERIFY(timerTimeout == false);
+ QVERIFY(typeError == false);
+ QVERIFY(strcmp(temp, responseString) == 0);
+ }
+
+ void timeoutSessionBusTest() {
+ // Create message
+ DBusMessage* message = dbus_message_new_method_call("com.nokia.dbusqeventloop.test", "/", NULL, "timeout");
+ QVERIFY(message != NULL);
+
+ DBusPendingCall* pending;
+ // Send the message
dbus_connection_send_with_reply(sessionBus, message, &pending, 1000);
- // Free message
- dbus_message_unref(message);
- // Process event loop
- processQTEventLoop(pending, 3000);
- // Check results
- QVERIFY(timerTimeout == false);
- QVERIFY(noResponse == true);
- QVERIFY(typeError == false);
- // Small pause to process reply
- sleep(1);
- }
+ // Free message
+ dbus_message_unref(message);
+ // Process event loop
+ processQTEventLoop(pending, 3000);
+ // Check results
+ QVERIFY(timerTimeout == false);
+ QVERIFY(noResponse == true);
+ QVERIFY(typeError == false);
+ // Small pause to process reply
+ sleep(1);
+ }
};
QTEST_MAIN(TestDbusQEventLoop)
diff --git a/tests/test-resource-engine/test-resource-engine.cpp b/tests/test-resource-engine/test-resource-engine.cpp
index 49d8d0d..dc16405 100644
--- a/tests/test-resource-engine/test-resource-engine.cpp
+++ b/tests/test-resource-engine/test-resource-engine.cpp
@@ -16,10 +16,10 @@ static void verify_resconn_connect(resconn_t *connection, resmsg_t *message,
static void verify_resconn_disconnect(resset_t *resourceSet, resmsg_t *message,
resproto_status_t callbackFunction);
static void verify_resproto_send_message(resset_t *resourceSet, resmsg_t *message,
- resproto_status_t callbackFunction);
+ resproto_status_t callbackFunction);
TestResourceEngine::TestResourceEngine()
- : resourceEngine(NULL), resourceSet(NULL)
+ : resourceEngine(NULL), resourceSet(NULL)
{
audioPlayback = new AudioResource;
videoPlayback = new VideoResource;
@@ -132,13 +132,13 @@ void TestResourceEngine::handleAcquire(QList<ResourceType> optionalResources)
{
QVERIFY(acquireShouldSucceed);
bool hasOptionalResource = false;
- for(int i=0; i < optionalResources.size(); i++) {
- if(optionalResources.at(i) == optionalType) {
+ for (int i = 0; i < optionalResources.size(); i++) {
+ if (optionalResources.at(i) == optionalType) {
hasOptionalResource = true;
break;
}
}
- if((optionalType == NumberOfTypes) && (optionalResources.size() == 0)) {
+ if ((optionalType == NumberOfTypes) && (optionalResources.size() == 0)) {
hasOptionalResource = true;
}
QVERIFY(hasOptionalResource);
@@ -170,7 +170,7 @@ resconn_t* resproto_init(resproto_role_t role, resproto_transport_t transport, .
verify_resproto_init(role, transport, callbackFunction, dbusConnection);
- resourceConnection =(resconn_t *) calloc(1, sizeof(resconn_t));
+ resourceConnection = (resconn_t *) calloc(1, sizeof(resconn_t));
return resourceConnection;
}
@@ -206,10 +206,10 @@ static void verify_resconn_connect(resconn_t *connection, resmsg_t *message,
QVERIFY(message->record.type == RESMSG_REGISTER);
QVERIFY(message->record.id == theID);
QVERIFY(message->record.reqno == 1);
- QVERIFY(message->record.rset.all == (RESMSG_AUDIO_PLAYBACK|RESMSG_AUDIO_RECORDING
- |RESMSG_VIDEO_PLAYBACK|RESMSG_VIDEO_RECORDING));
- QVERIFY(message->record.rset.opt == (RESMSG_AUDIO_RECORDING|RESMSG_VIDEO_PLAYBACK
- |RESMSG_VIDEO_RECORDING));
+ QVERIFY(message->record.rset.all == (RESMSG_AUDIO_PLAYBACK | RESMSG_AUDIO_RECORDING
+ | RESMSG_VIDEO_PLAYBACK | RESMSG_VIDEO_RECORDING));
+ QVERIFY(message->record.rset.opt == (RESMSG_AUDIO_RECORDING | RESMSG_VIDEO_PLAYBACK
+ | RESMSG_VIDEO_RECORDING));
QVERIFY(message->record.rset.share == 0);
QVERIFY(message->record.rset.mask == 0);
QCOMPARE(message->record.klass, "player");
@@ -227,7 +227,7 @@ char *resmsg_res_str(uint32_t res, char *buf, int len)
int resproto_set_handler(union resconn_u *, resmsg_type_t type,
resproto_handler_t callbackFunction)
{
- if(type == RESMSG_GRANT) {
+ if (type == RESMSG_GRANT) {
grantCallback = callbackFunction;
}
return 1;
@@ -273,9 +273,9 @@ int resproto_send_message(resset_t *resourceSet, resmsg_t *message,
}
static void verify_resproto_send_message(resset_t *resourceSet, resmsg_t *message,
- resproto_status_t callbackFunction)
+ resproto_status_t callbackFunction)
{
- if(message->record.type == RESMSG_ACQUIRE) {
+ if (message->record.type == RESMSG_ACQUIRE) {
QVERIFY(resourceSet == resSet);
QVERIFY(message->record.id == theID);
QVERIFY(callbackFunction != NULL);
diff --git a/tests/test-resource-engine/test-resource-engine.h b/tests/test-resource-engine/test-resource-engine.h
index c18ae43..151f26a 100644
--- a/tests/test-resource-engine/test-resource-engine.h
+++ b/tests/test-resource-engine/test-resource-engine.h
@@ -9,38 +9,38 @@ Q_DECLARE_METATYPE(ResourcePolicy::ResourceType)
namespace ResourcePolicy
{
- class TestResourceEngine: public QObject
- {
- Q_OBJECT
- private:
- ResourceEngine *resourceEngine;
- AudioResource *audioPlayback;
- VideoResource *videoPlayback;
- AudioRecorderResource *audioRecorder;
- VideoRecorderResource *videoRecorder;
- bool libresourceInitialized;
-
- public:
- ResourceSet *resourceSet;
-
- TestResourceEngine();
- ~TestResourceEngine();
- public slots:
- void connectedHandler();
- void handleDeny();
- void handleAcquire(QList<ResourceType> optionalResources);
-
- private slots:
- void init();
-
- void testConnect();
- void testDisconnect();
-
- void testStatusMessage();
-
- void testAcquire_data();
- void testAcquire();
- };
+class TestResourceEngine: public QObject
+{
+ Q_OBJECT
+private:
+ ResourceEngine *resourceEngine;
+ AudioResource *audioPlayback;
+ VideoResource *videoPlayback;
+ AudioRecorderResource *audioRecorder;
+ VideoRecorderResource *videoRecorder;
+ bool libresourceInitialized;
+
+public:
+ ResourceSet *resourceSet;
+
+ TestResourceEngine();
+ ~TestResourceEngine();
+public slots:
+ void connectedHandler();
+ void handleDeny();
+ void handleAcquire(QList<ResourceType> optionalResources);
+
+private slots:
+ void init();
+
+ void testConnect();
+ void testDisconnect();
+
+ void testStatusMessage();
+
+ void testAcquire_data();
+ void testAcquire();
+};
}
#endif
diff --git a/tests/test-resource-set/test-resource-set.cpp b/tests/test-resource-set/test-resource-set.cpp
index e9ee74b..529d9e0 100644
--- a/tests/test-resource-set/test-resource-set.cpp
+++ b/tests/test-resource-set/test-resource-set.cpp
@@ -2,7 +2,7 @@
Resource * TestResourceSet::resourceFromType(ResourceType type)
{
- switch(type) {
+ switch (type) {
case AudioPlaybackType:
return audioResource;
case AudioRecorderType:
@@ -88,7 +88,7 @@ void TestResourceSet::testIdentifier()
void TestResourceSet::testAddResource()
{
- for(int i=0;i<NumberOfTypes;i++) {
+ for (int i = 0;i < NumberOfTypes;i++) {
ResourceType type = (ResourceType)i;
Resource *resource = resourceFromType(type);
resourceSet->addResource(resource);
@@ -155,11 +155,11 @@ void TestResourceSet::testContainsSet()
QList<Resource *> resources;
types << AudioPlaybackType << VideoPlaybackType
- << AudioRecorderType << VideoRecorderType << LensCoverType;
+ << AudioRecorderType << VideoRecorderType << LensCoverType;
subset << AudioPlaybackType << VideoPlaybackType << LensCoverType;
resources << audioResource << videoResource
- << audioRecorderResource << videoRecorderResource << lensCoverResource;
+ << audioRecorderResource << videoRecorderResource << lensCoverResource;
resourceSet->addResources(resources);
diff --git a/tests/test-resource-set/test-resource-set.h b/tests/test-resource-set/test-resource-set.h
index 5c6498b..24ca0c7 100644
--- a/tests/test-resource-set/test-resource-set.h
+++ b/tests/test-resource-set/test-resource-set.h
@@ -8,9 +8,9 @@ using namespace ResourcePolicy;
class TestResourceSet: public QObject
{
- Q_OBJECT
+ Q_OBJECT
private:
- ResourceSet *resourceSet;
+ ResourceSet *resourceSet;
AudioResource *audioResource;
AudioRecorderResource *audioRecorderResource;
@@ -27,24 +27,24 @@ private:
Resource * resourceFromType(ResourceType type);
public:
- TestResourceSet();
- ~TestResourceSet();
+ TestResourceSet();
+ ~TestResourceSet();
+
-
private slots:
- void init();
- void cleanup();
+ void init();
+ void cleanup();
- void testIdentifier();
+ void testIdentifier();
- void testAddResource();
- void testAddResources();
- void testDelResource();
+ void testAddResource();
+ void testAddResources();
+ void testDelResource();
- void testContainsSingle();
- void testDoesNotContainSingle();
- void testContainsSet();
+ void testContainsSingle();
+ void testDoesNotContainSingle();
+ void testContainsSet();
};
#endif
diff --git a/tests/test-resource/test-resource.cpp b/tests/test-resource/test-resource.cpp
index e943fa2..b6879db 100644
--- a/tests/test-resource/test-resource.cpp
+++ b/tests/test-resource/test-resource.cpp
@@ -5,7 +5,7 @@ using namespace ResourcePolicy;
Resource * TestResource::resourceFromType(ResourceType type)
{
- switch(type) {
+ switch (type) {
case AudioPlaybackType:
return audioResource;
case AudioRecorderType:
@@ -37,7 +37,7 @@ Resource * TestResource::resourceFromType(ResourceType type)
const char * TestResource::stringFromType(ResourceType type)
{
- switch(type) {
+ switch (type) {
case AudioPlaybackType:
return "AudioPlaybackType";
case AudioRecorderType:
@@ -110,10 +110,10 @@ void TestResource::cleanup()
void TestResource::testType()
{
- for(quint32 type=AudioPlaybackType; type < NumberOfTypes; type++) {
+ for (quint32 type = AudioPlaybackType; type < NumberOfTypes; type++) {
ResourceType expected = (ResourceType)type;
Resource *resource = resourceFromType(expected);
- if(resource->type() != expected) {
+ if (resource->type() != expected) {
qDebug("expected ResourceType = %s, got %s",
stringFromType(expected), stringFromType(resource->type()));
}
@@ -126,7 +126,7 @@ void TestResource::testOptional_data()
QTest::addColumn<ResourceType>("type");
QTest::addColumn<bool>("optional");
QTest::addColumn<bool>("expected");
-
+
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;
@@ -136,7 +136,7 @@ void TestResource::testOptional_data()
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 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;
@@ -169,7 +169,7 @@ void TestResource::testOptional()
void TestResource::testClone()
{
- for(quint32 type=AudioPlaybackType; type < NumberOfTypes; type++) {
+ for (quint32 type = AudioPlaybackType; type < NumberOfTypes; type++) {
Resource *resource = resourceFromType((ResourceType)type);
resource->setOptional();
Resource *copy = resource->clone();