From 346a7524047a1aa1ec64810abb8b0243ae90c3bb Mon Sep 17 00:00:00 2001 From: Wolf Bergenheim Date: Thu, 11 Feb 2010 11:21:01 +0200 Subject: astyled the code --- libdbus-qeventloop/dbusconnectioneventloop.cpp | 138 +++--- libdbus-qeventloop/dbusconnectioneventloop.h | 52 +- libresourceqt/include/qt4/policy/resource-set.h | 312 ++++++------ libresourceqt/include/qt4/policy/resource.h | 115 ++--- libresourceqt/include/qt4/policy/resources.h | 319 ++++++------ libresourceqt/src/resource-engine.cpp | 108 ++-- libresourceqt/src/resource-set.cpp | 27 +- libresourceqt/src/resource.cpp | 4 +- libresourceqt/src/resources.cpp | 48 +- tests/test-dbus-pong/pong.h | 8 +- tests/test-dbus-pong/test-dbus-pong.cpp | 134 +++-- .../test-dbus-qeventloop/test-dbus-qeventloop.cpp | 544 ++++++++++----------- .../test-resource-engine/test-resource-engine.cpp | 26 +- tests/test-resource-engine/test-resource-engine.h | 64 +-- tests/test-resource-set/test-resource-set.cpp | 8 +- tests/test-resource-set/test-resource-set.h | 28 +- tests/test-resource/test-resource.cpp | 14 +- 17 files changed, 952 insertions(+), 997 deletions(-) diff --git a/libdbus-qeventloop/dbusconnectioneventloop.cpp b/libdbus-qeventloop/dbusconnectioneventloop.cpp index 2c040b2..0bce26e 100644 --- a/libdbus-qeventloop/dbusconnectioneventloop.cpp +++ b/libdbus-qeventloop/dbusconnectioneventloop.cpp @@ -16,16 +16,14 @@ DBUSConnectionEventLoop::~DBUSConnectionEventLoop() // Handle a socket being ready to read. void DBUSConnectionEventLoop::readSocket(int fd) { - MYDEBUG(); + MYDEBUG(); Watchers::const_iterator it = watchers.find(fd); - while( it != watchers.end() && it.key() == fd ) - { + while (it != watchers.end() && it.key() == fd) { const Watcher &watcher = it.value(); - if( watcher.read && watcher.read->isEnabled() ) - { + if (watcher.read && watcher.read->isEnabled()) { watcher.read->setEnabled(false); dbus_watch_handle(watcher.watch, DBUS_WATCH_READABLE); watcher.read->setEnabled(true); @@ -41,16 +39,14 @@ void DBUSConnectionEventLoop::readSocket(int fd) // Handle a socket being ready to write. void DBUSConnectionEventLoop::writeSocket(int fd) { - MYDEBUG(); + MYDEBUG(); Watchers::const_iterator it = watchers.find(fd); - while( it != watchers.end() && it.key() == fd ) - { + while (it != watchers.end() && it.key() == fd) { const Watcher &watcher = it.value(); - if( watcher.write && watcher.write->isEnabled() ) - { + if (watcher.write && watcher.write->isEnabled()) { watcher.write->setEnabled(false); dbus_watch_handle(watcher.watch, DBUS_WATCH_WRITABLE); watcher.write->setEnabled(true); @@ -63,30 +59,30 @@ void DBUSConnectionEventLoop::writeSocket(int fd) void DBUSConnectionEventLoop::dispatch() { - MYDEBUG(); + MYDEBUG(); - for( Connections::const_iterator it = connections.constBegin(); it != connections.constEnd(); ++it ) - while( dbus_connection_dispatch(*it) == DBUS_DISPATCH_DATA_REMAINS ) + for (Connections::const_iterator it = connections.constBegin(); it != connections.constEnd(); ++it) + while (dbus_connection_dispatch(*it) == DBUS_DISPATCH_DATA_REMAINS) ; } // Handle timer events. void DBUSConnectionEventLoop::timerEvent(QTimerEvent *e) { - MYDEBUG(); - MYDEBUGC("TimerID: %d", e->timerId()); + MYDEBUG(); + MYDEBUGC("TimerID: %d", e->timerId()); DBusTimeout *timeout = timeouts.value(e->timerId()); - if( timeout ) + if (timeout) dbus_timeout_handle(timeout); } dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast(data); + DBUSConnectionEventLoop *loop = reinterpret_cast(data); int fd = dbus_watch_get_unix_fd(watch); unsigned int flags = dbus_watch_get_flags(watch); @@ -95,15 +91,13 @@ dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) DBUSConnectionEventLoop::Watcher watcher; watcher.watch = watch; - if( flags & DBUS_WATCH_READABLE ) - { + if (flags & DBUS_WATCH_READABLE) { watcher.read = new QSocketNotifier(fd, QSocketNotifier::Read, loop); watcher.read->setEnabled(enabled); loop->connect(watcher.read, SIGNAL(activated(int)), SLOT(readSocket(int))); } - if( flags & DBUS_WATCH_WRITABLE ) - { + if (flags & DBUS_WATCH_WRITABLE) { watcher.write = new QSocketNotifier(fd, QSocketNotifier::Write, loop); watcher.write->setEnabled(enabled); loop->connect(watcher.write, SIGNAL(activated(int)), SLOT(writeSocket(int))); @@ -116,24 +110,22 @@ dbus_bool_t DBUSConnectionEventLoop::addWatch(DBusWatch *watch, void *data) void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast(data); + DBUSConnectionEventLoop *loop = reinterpret_cast(data); int fd = dbus_watch_get_unix_fd(watch); DBUSConnectionEventLoop::Watchers::iterator it = loop->watchers.find(fd); - while( it != loop->watchers.end() && it.key() == fd ) - { - DBUSConnectionEventLoop::Watcher &watcher = it.value(); + while (it != loop->watchers.end() && it.key() == fd) { + DBUSConnectionEventLoop::Watcher &watcher = it.value(); - if( watcher.watch == watch ) - { - if( watcher.read ) + if (watcher.watch == watch) { + if (watcher.read) delete watcher.read; - if( watcher.write ) + if (watcher.write) delete watcher.write; loop->watchers.erase(it); @@ -147,9 +139,9 @@ void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data) void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast(data); + DBUSConnectionEventLoop *loop = reinterpret_cast(data); int fd = dbus_watch_get_unix_fd(watch); unsigned int flags = dbus_watch_get_flags(watch); @@ -157,16 +149,14 @@ void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) DBUSConnectionEventLoop::Watchers::const_iterator it = loop->watchers.find(fd); - while( it != loop->watchers.end() && it.key() == fd ) - { + while (it != loop->watchers.end() && it.key() == fd) { const DBUSConnectionEventLoop::Watcher &watcher = it.value(); - if( watcher.watch == watch ) - { - if( flags & DBUS_WATCH_READABLE && watcher.read ) + if (watcher.watch == watch) { + if (flags & DBUS_WATCH_READABLE && watcher.read) watcher.read->setEnabled(enabled); - if( flags & DBUS_WATCH_WRITABLE && watcher.write ) + if (flags & DBUS_WATCH_WRITABLE && watcher.write) watcher.write->setEnabled(enabled); return; @@ -178,14 +168,14 @@ void DBUSConnectionEventLoop::toggleWatch(DBusWatch *watch, void *data) dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); // Nothing to do if the timeout is disabled. - if( !dbus_timeout_get_enabled(timeout) ) + if (!dbus_timeout_get_enabled(timeout)) return true; // Pretend it is successful if there is no application instance. - if( !QCoreApplication::instance() ) + if (!QCoreApplication::instance()) return true; DBUSConnectionEventLoop *loop = reinterpret_cast(data); @@ -195,7 +185,7 @@ dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data MYDEBUGC("Adding timeout %d with interval %d!", id, timerInterval); - if( !id ) + if (!id) return false; loop->timeouts[id] = timeout; @@ -205,16 +195,14 @@ dbus_bool_t DBUSConnectionEventLoop::addTimeout(DBusTimeout *timeout, void *data void DBUSConnectionEventLoop::removeTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast(data); + DBUSConnectionEventLoop *loop = reinterpret_cast(data); - DBUSConnectionEventLoop::Timeouts::iterator it = loop->timeouts.begin(); + DBUSConnectionEventLoop::Timeouts::iterator it = loop->timeouts.begin(); - while( it != loop->timeouts.end() ) - { - if( it.value() == timeout ) - { + while (it != loop->timeouts.end()) { + if (it.value() == timeout) { loop->killTimer(it.key()); it = loop->timeouts.erase(it); } @@ -225,17 +213,17 @@ void DBUSConnectionEventLoop::removeTimeout(DBusTimeout *timeout, void *data) void DBUSConnectionEventLoop::toggleTimeout(DBusTimeout *timeout, void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop::removeTimeout(timeout, data); - DBUSConnectionEventLoop::addTimeout(timeout, data); + DBUSConnectionEventLoop::removeTimeout(timeout, data); + DBUSConnectionEventLoop::addTimeout(timeout, data); } void DBUSConnectionEventLoop::wakeupMain(void *data) { - MYDEBUG(); + MYDEBUG(); - DBUSConnectionEventLoop *loop = reinterpret_cast(data); + DBUSConnectionEventLoop *loop = reinterpret_cast(data); QTimer::singleShot(0, loop, SLOT(dispatch())); } @@ -245,35 +233,31 @@ bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn) { bool rc; - if( conn == NULL ) - { - return false; - } + if (conn == NULL) { + return false; + } connections.append(conn); - if( - !dbus_connection_set_watch_functions(conn, - DBUSConnectionEventLoop::addWatch, - DBUSConnectionEventLoop::removeWatch, - DBUSConnectionEventLoop::toggleWatch, - this, 0) - ) - { + if ( + !dbus_connection_set_watch_functions(conn, + DBUSConnectionEventLoop::addWatch, + DBUSConnectionEventLoop::removeWatch, + DBUSConnectionEventLoop::toggleWatch, + this, 0) + ) { rc = false; } - else if( - !dbus_connection_set_timeout_functions(conn, - DBUSConnectionEventLoop::addTimeout, - DBUSConnectionEventLoop::removeTimeout, - DBUSConnectionEventLoop::toggleTimeout, - this, 0) - ) - { + else if ( + !dbus_connection_set_timeout_functions(conn, + DBUSConnectionEventLoop::addTimeout, + DBUSConnectionEventLoop::removeTimeout, + DBUSConnectionEventLoop::toggleTimeout, + this, 0) + ) { rc = false; } - else - { + else { rc = true; } diff --git a/libdbus-qeventloop/dbusconnectioneventloop.h b/libdbus-qeventloop/dbusconnectioneventloop.h index 993c5c1..b36bf9d 100644 --- a/libdbus-qeventloop/dbusconnectioneventloop.h +++ b/libdbus-qeventloop/dbusconnectioneventloop.h @@ -11,31 +11,29 @@ //#define _DISPLAY_DEBUG_ #ifdef _DISPLAY_DEBUG_ - #include - - #define MYDEBUG() MyDebug deb(__FUNCTION__) - #define MYDEBUGC(...) qDebug(__VA_ARGS__) - - class MyDebug - { - public: - MyDebug(const char* func) - { - funcName = strdup(func); - qDebug("--> Entering: %s() ...", funcName); - } - ~MyDebug() - { - qDebug("<-- Leaving: %s() ...", funcName); - free(funcName); - } - - private: - char* funcName; - }; +#include + +#define MYDEBUG() MyDebug deb(__FUNCTION__) +#define MYDEBUGC(...) qDebug(__VA_ARGS__) + +class MyDebug +{ +public: + MyDebug(const char* func) { + funcName = strdup(func); + qDebug("--> Entering: %s() ...", funcName); + } + ~MyDebug() { + qDebug("<-- Leaving: %s() ...", funcName); + free(funcName); + } + +private: + char* funcName; +}; #else - #define MYDEBUG() - #define MYDEBUGC(...) +#define MYDEBUG() +#define MYDEBUGC(...) #endif class QSocketNotifier; @@ -48,9 +46,9 @@ class QTimerEvent; */ class DBUSConnectionEventLoop : public QObject { - Q_OBJECT + Q_OBJECT private: - Q_DISABLE_COPY(DBUSConnectionEventLoop) + Q_DISABLE_COPY(DBUSConnectionEventLoop) public: DBUSConnectionEventLoop(); @@ -61,7 +59,7 @@ public: * Add new dbus connection into handler. * \return true if everything went well. */ - bool addConnection(DBusConnection* conn); + bool addConnection(DBusConnection* conn); /** * Helper class for dbus watcher diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h index 0e18e5b..3e9bc24 100644 --- a/libresourceqt/include/qt4/policy/resource-set.h +++ b/libresourceqt/include/qt4/policy/resource-set.h @@ -9,15 +9,15 @@ /** * \mainpage Resource Policy Library - * + * * \section intro_section Introduction - * + * * This library is used to request resources from the Polict Resource Manager. * To use this library two classes are provided: \ref ResourcePolicy::Resource and * \ref ResourcePolicy::ResourceSet. - * + * * \section library_use_section Library Usage - * + * * To use the Resource Policy Library, you first need to create a number of * \ref Resource objects like this (given as an example of what a media player * might want/need): @@ -50,168 +50,168 @@ */ namespace ResourcePolicy { +/** + * The resourceSet repesents a set of attributes. Each set can only contain + * a single Resource of a given type. That is one AudioPlaybackResource, etc. + * + * Internally the set is stored as a QVector of \ref Resource objects. + */ +class ResourceSet: public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(ResourceSet) +public: + /** + * The constructor. + * \param applicationClass This parameter defines the application class. + * The application class is used to determine the priority order of the + * application. + * \param parent The optional parent of of this class. + */ + ResourceSet(const QString &applicationClass, QObject *parent = NULL); + /** + * The destructor + */ + ~ResourceSet(); /** - * The resourceSet repesents a set of attributes. Each set can only contain - * a single Resource of a given type. That is one AudioPlaybackResource, etc. - * - * Internally the set is stored as a QVector of \ref Resource objects. - */ - class ResourceSet: public QObject - { - Q_OBJECT - Q_DISABLE_COPY( ResourceSet ) - public: - /** - * The constructor. - * \param applicationClass This parameter defines the application class. - * The application class is used to determine the priority order of the - * application. - * \param parent The optional parent of of this class. - */ - ResourceSet(const QString &applicationClass, QObject *parent=NULL); - /** - * The destructor - */ - ~ResourceSet(); - /** - * Finalizes the ResourceSet. This method should be called after all - * resources have been added to the set. - * \return true if the finalization was successful. - */ - bool finalize(); + * Finalizes the ResourceSet. This method should be called after all + * resources have been added to the set. + * \return true if the finalization was successful. + */ + bool finalize(); - /** - * This method adds a resource to the set. A set contains only a single - * instance of a given resource. If the ResourceSet already contains a - * resource of the given type it will be overridden. - * \param resource The resource to add to the set. A copy of this object - * is stored in the Set. - */ - void addResource(const Resource *resource); - /** - * This method adds all resources in the list to the set. - * A set contains only a single instance of a given resource. If the - * ResourceSet already contains a resource of the given type it will be - * overridden. - * \param resources The list of resources to add to the set. These will - * be copied. - */ - void addResources(const QListresources); - /** - * This method removes the resource of the given type - * \param type The type of the resource to remove from the set. - */ - void delResource(ResourceType type); + /** + * This method adds a resource to the set. A set contains only a single + * instance of a given resource. If the ResourceSet already contains a + * resource of the given type it will be overridden. + * \param resource The resource to add to the set. A copy of this object + * is stored in the Set. + */ + void addResource(const Resource *resource); + /** + * This method adds all resources in the list to the set. + * A set contains only a single instance of a given resource. If the + * ResourceSet already contains a resource of the given type it will be + * overridden. + * \param resources The list of resources to add to the set. These will + * be copied. + */ + void addResources(const QListresources); + /** + * This method removes the resource of the given type + * \param type The type of the resource to remove from the set. + */ + void delResource(ResourceType type); - /** - * This method returns a list of all resource in the set. - * \return a QList of all resources in the set. - */ - QList resources() const; - /** - * This method returns a const pointer to a resource of a specific type. - * \type The type of resource we are interested in. - * \return a pointer to the Resource if it is defined NULL otherwise. - */ - Resource * resource(ResourceType type) const; - /** - * Checks if the \ref ResourceSet contains the given \ref Resource - * \param type The Resource to look for - * \return true if the \ref Resource is defined in this \ref ResourceSet - */ - bool contains(ResourceType type) const; + /** + * This method returns a list of all resource in the set. + * \return a QList of all resources in the set. + */ + QList resources() const; + /** + * This method returns a const pointer to a resource of a specific type. + * \type The type of resource we are interested in. + * \return a pointer to the Resource if it is defined NULL otherwise. + */ + Resource * resource(ResourceType type) const; + /** + * Checks if the \ref ResourceSet contains the given \ref Resource + * \param type The Resource to look for + * \return true if the \ref Resource is defined in this \ref ResourceSet + */ + bool contains(ResourceType type) const; - /** - * Checks if the \ref ResourceSet contains all given resources. - * \param types A list of resources to check for - * \return true if \b all given resources are defined in the ResourceSet. - */ - bool contains(const QList &types) const; + /** + * Checks if the \ref ResourceSet contains all given resources. + * \param types A list of resources to check for + * \return true if \b all given resources are defined in the ResourceSet. + */ + bool contains(const QList &types) const; - /** - * Returns the unique identifier for this ResourceSet. - * @return the unique identifier for this ResourceSet. - */ - quint32 id() const; + /** + * Returns the unique identifier for this ResourceSet. + * @return the unique identifier for this ResourceSet. + */ + quint32 id() const; - /** - * Returns the registered application class (given in the constructor). - */ - QString applicationClass(); + /** + * Returns the registered application class (given in the constructor). + */ + QString applicationClass(); - /** - * Try to acquire the \ref ResourceSet. The resourcesGranted() or - * resourcesDenied() signal will be emited depending on whether the - * requested resources could be acquired or not. - */ - bool acquire(); - /** - * Release the acquired resources. - */ - bool release(); - /** - * Commit changes to the \ref ResourceSet. Remember to call update() - * after adding and/or removing resources. - */ - bool update(); + /** + * Try to acquire the \ref ResourceSet. The resourcesGranted() or + * resourcesDenied() signal will be emited depending on whether the + * requested resources could be acquired or not. + */ + bool acquire(); + /** + * Release the acquired resources. + */ + bool release(); + /** + * Commit changes to the \ref ResourceSet. Remember to call update() + * after adding and/or removing resources. + */ + bool update(); - /** - * Stes the auto-release. When loosing the resources doue to another - * application with a higher priority the default is that we automatically - * re-gain our resources without having to re-request them. However if - * the AutoRelease is set we release the resources and need to re-acquire - * them, when the pre-emting application releases it s resources. - * This feature is by default disabled. - * Remember to call update() when changing this. - */ - void setAutoRelease(); - /** - * see \ref setAutoRelease(). - */ - void unsetAutoRelease(); - /** - * Sets that the resourcesGranted() signal is emited even if we already - * have the requested resources granted. By default this feature is off. - */ - void setAlwaysReply(); - /** - * Unsets the always reply flag (see \ref setAlwaysReply()) - */ - void unsetAlwaysReply(); + /** + * Stes the auto-release. When loosing the resources doue to another + * application with a higher priority the default is that we automatically + * re-gain our resources without having to re-request them. However if + * the AutoRelease is set we release the resources and need to re-acquire + * them, when the pre-emting application releases it s resources. + * This feature is by default disabled. + * Remember to call update() when changing this. + */ + void setAutoRelease(); + /** + * see \ref setAutoRelease(). + */ + void unsetAutoRelease(); + /** + * Sets that the resourcesGranted() signal is emited even if we already + * have the requested resources granted. By default this feature is off. + */ + void setAlwaysReply(); + /** + * Unsets the always reply flag (see \ref setAlwaysReply()) + */ + void unsetAlwaysReply(); - signals: - /** - * This signal is emited when the Resource Policy Manager notifies that - * the given resources have become available. - * \param availableResources A list of available resources. The list of - * available resources contains only available resource which we have in the set. - */ - void resourcesBecameAvailable(QList 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(QList 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. - */ - void resourcesDenied(); - /** - * This signal is emited when some other program with a higher priority - * superseeds us, and as a result we loose our resources. - */ - void lostResources(); +signals: + /** + * This signal is emited when the Resource Policy Manager notifies that + * the given resources have become available. + * \param availableResources A list of available resources. The list of + * available resources contains only available resource which we have in the set. + */ + void resourcesBecameAvailable(QList 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(QList 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. + */ + void resourcesDenied(); + /** + * This signal is emited when some other program with a higher priority + * superseeds us, and as a result we loose our resources. + */ + void lostResources(); - private: - quint32 identifier; - const QString resourceClass; - Resource* resourceSet[NumberOfTypes]; - bool connected; - bool autoRelease; - bool alwaysReply; - }; +private: + quint32 identifier; + const QString resourceClass; + Resource* resourceSet[NumberOfTypes]; + bool connected; + bool autoRelease; + bool alwaysReply; +}; } #endif diff --git a/libresourceqt/include/qt4/policy/resource.h b/libresourceqt/include/qt4/policy/resource.h index 74b3e9b..dd31a78 100644 --- a/libresourceqt/include/qt4/policy/resource.h +++ b/libresourceqt/include/qt4/policy/resource.h @@ -3,69 +3,70 @@ #include -namespace ResourcePolicy { - enum ResourceType { - AudioPlaybackType = 0, - VideoPlaybackType, - AudioRecorderType, - VideoRecorderType, - VibraType, - LedsType, - BacklightType, - SystemButtonType, - LockButtonType, - ScaleButtonType, - SnapButtonType, - LensCoverType, - NumberOfTypes - }; +namespace ResourcePolicy +{ +enum ResourceType { + AudioPlaybackType = 0, + VideoPlaybackType, + AudioRecorderType, + VideoRecorderType, + VibraType, + LedsType, + BacklightType, + SystemButtonType, + LockButtonType, + ScaleButtonType, + SnapButtonType, + LensCoverType, + NumberOfTypes +}; - class ResourceSet; +class ResourceSet; +/** +* This class is the super class for all resources. It represents a generic +* \ref Resource. The type specific resource classes should be used. +*/ +class Resource +{ +public: + friend class ResourceSet; /** - * This class is the super class for all resources. It represents a generic - * \ref Resource. The type specific resource classes should be used. - */ - class Resource - { - public: - friend class ResourceSet; - /** - * Whether or not this resource is optional, in that it doesn't need to - * be available for the set to be acquired. - * \return true when this resource is optional. - */ - bool isOptional() const; - /** - * Set the resource to be optional or mandatory. - * \param resourceIsOptional This optional parameter defaults to true. - * The default, true, results in the resource becoming optional. When it - * is set to false the resource becomes mandatory. - */ - void setOptional(bool resourceIsOptional=true); - /** - * Whether or not the resource to be shared. If it is shared then other - * programs are allowed to share this resource. - * \return true when this resource is shared. - */ - bool isGranted() const; + * Whether or not this resource is optional, in that it doesn't need to + * be available for the set to be acquired. + * \return true when this resource is optional. + */ + bool isOptional() const; + /** + * Set the resource to be optional or mandatory. + * \param resourceIsOptional This optional parameter defaults to true. + * The default, true, results in the resource becoming optional. When it + * is set to false the resource becomes mandatory. + */ + void setOptional(bool resourceIsOptional = true); + /** + * Whether or not the resource to be shared. If it is shared then other + * programs are allowed to share this resource. + * \return true when this resource is shared. + */ + bool isGranted() const; - virtual ResourceType type() const = 0; - virtual Resource * clone() const = 0; - virtual ~Resource(); - protected: - Resource(); - Resource(const Resource &other); + virtual ResourceType type() const = 0; + virtual Resource * clone() const = 0; + virtual ~Resource(); +protected: + Resource(); + Resource(const Resource &other); - ResourceType resourceType; - bool optional; - quint32 identifier; - private: - void setGranted(); - void unsetGranted(); - bool granted; + ResourceType resourceType; + bool optional; + quint32 identifier; +private: + void setGranted(); + void unsetGranted(); + bool granted; - }; +}; } #endif diff --git a/libresourceqt/include/qt4/policy/resources.h b/libresourceqt/include/qt4/policy/resources.h index 47002d7..f00cc2e 100644 --- a/libresourceqt/include/qt4/policy/resources.h +++ b/libresourceqt/include/qt4/policy/resources.h @@ -5,165 +5,166 @@ #include #include -namespace ResourcePolicy { - - class AudioResource: public Resource - { - public: - AudioResource(const QString &audioGroup=QString()); - AudioResource(const AudioResource &other); - virtual ~AudioResource(); - - QString audioGroup() const; - void setAudioGroup(const QString & newGroup); - - quint32 processID() const; - void setProcessID(quint32 newPID); - - QString streamTag() const; - void setStreamTag(const QString & newStreamTag); - - virtual ResourceType type() const; - virtual Resource * clone() const; - private: - QString group; - quint32 pid; - QString stream; - }; - - class AudioRecorderResource: public Resource - { - public: - AudioRecorderResource(const QString & audioGroup=QString()); - AudioRecorderResource(const AudioRecorderResource &other); - virtual ~AudioRecorderResource(); - - QString audioGroup() const; - void setAudioGroup(const QString & newGroup); - - quint32 processID() const; - void setProcessID(quint32 newPID); - - QString streamTag() const; - void setStreamTag(const QString & newStreamTag); - - virtual ResourceType type() const; - virtual Resource * clone() const; - private: - QString group; - quint32 pid; - QString stream; - }; - - class BacklightResource: public Resource - { - public: - BacklightResource(); - BacklightResource(const BacklightResource &other); - virtual ~BacklightResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LedsResource: public Resource - { - public: - LedsResource(); - LedsResource(const LedsResource &other); - virtual ~LedsResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VibraResource: public Resource - { - public: - VibraResource(); - VibraResource(const VibraResource &other); - virtual ~VibraResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VideoRecorderResource: public Resource - { - public: - VideoRecorderResource(); - VideoRecorderResource(const VideoRecorderResource &other); - virtual ~VideoRecorderResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VideoResource: public Resource - { - public: - VideoResource(); - VideoResource(const VideoResource &other); - virtual ~VideoResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class SystemButtonResource: public Resource - { - public: - SystemButtonResource(); - SystemButtonResource(const SystemButtonResource &other); - virtual ~SystemButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LockButtonResource: public Resource - { - public: - LockButtonResource(); - LockButtonResource(const LockButtonResource &other); - virtual ~LockButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class ScaleButtonResource: public Resource - { - public: - ScaleButtonResource(); - ScaleButtonResource(const ScaleButtonResource &other); - virtual ~ScaleButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class SnapButtonResource: public Resource - { - public: - SnapButtonResource(); - SnapButtonResource(const SnapButtonResource &other); - virtual ~SnapButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LensCoverResource: public Resource - { - public: - LensCoverResource(); - LensCoverResource(const LensCoverResource &other); - virtual ~LensCoverResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; +namespace ResourcePolicy +{ + +class AudioResource: public Resource +{ +public: + AudioResource(const QString &audioGroup = QString()); + AudioResource(const AudioResource &other); + virtual ~AudioResource(); + + QString audioGroup() const; + void setAudioGroup(const QString & newGroup); + + quint32 processID() const; + void setProcessID(quint32 newPID); + + QString streamTag() const; + void setStreamTag(const QString & newStreamTag); + + virtual ResourceType type() const; + virtual Resource * clone() const; +private: + QString group; + quint32 pid; + QString stream; +}; + +class AudioRecorderResource: public Resource +{ +public: + AudioRecorderResource(const QString & audioGroup = QString()); + AudioRecorderResource(const AudioRecorderResource &other); + virtual ~AudioRecorderResource(); + + QString audioGroup() const; + void setAudioGroup(const QString & newGroup); + + quint32 processID() const; + void setProcessID(quint32 newPID); + + QString streamTag() const; + void setStreamTag(const QString & newStreamTag); + + virtual ResourceType type() const; + virtual Resource * clone() const; +private: + QString group; + quint32 pid; + QString stream; +}; + +class BacklightResource: public Resource +{ +public: + BacklightResource(); + BacklightResource(const BacklightResource &other); + virtual ~BacklightResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class LedsResource: public Resource +{ +public: + LedsResource(); + LedsResource(const LedsResource &other); + virtual ~LedsResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class VibraResource: public Resource +{ +public: + VibraResource(); + VibraResource(const VibraResource &other); + virtual ~VibraResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class VideoRecorderResource: public Resource +{ +public: + VideoRecorderResource(); + VideoRecorderResource(const VideoRecorderResource &other); + virtual ~VideoRecorderResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class VideoResource: public Resource +{ +public: + VideoResource(); + VideoResource(const VideoResource &other); + virtual ~VideoResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class SystemButtonResource: public Resource +{ +public: + SystemButtonResource(); + SystemButtonResource(const SystemButtonResource &other); + virtual ~SystemButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class LockButtonResource: public Resource +{ +public: + LockButtonResource(); + LockButtonResource(const LockButtonResource &other); + virtual ~LockButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class ScaleButtonResource: public Resource +{ +public: + ScaleButtonResource(); + ScaleButtonResource(const ScaleButtonResource &other); + virtual ~ScaleButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class SnapButtonResource: public Resource +{ +public: + SnapButtonResource(); + SnapButtonResource(const SnapButtonResource &other); + virtual ~SnapButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; + +class LensCoverResource: public Resource +{ +public: + LensCoverResource(); + LensCoverResource(const LensCoverResource &other); + virtual ~LensCoverResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; +}; } #endif diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp index e2d6113..0bc8fcd 100644 --- a/libresourceqt/src/resource-engine.cpp +++ b/libresourceqt/src/resource-engine.cpp @@ -14,9 +14,9 @@ static void handleGrantMessage(resmsg_t *msg, resset_t *rs, void *data); static void handleAdviceMessage(resmsg_t *msg, resset_t *rs, void *data); ResourceEngine::ResourceEngine(ResourceSet *resourceSet) - : QObject(resourceSet), connected(false), resourceSet(resourceSet), - libresourceConnection(NULL), libresourceSet(NULL), requestId(0), - messageMap(), mode(0) + : QObject(resourceSet), connected(false), resourceSet(resourceSet), + libresourceConnection(NULL), libresourceSet(NULL), requestId(0), + messageMap(), mode(0) { } @@ -31,15 +31,15 @@ bool ResourceEngine::initialize() dbus_error_init(&dbusError); dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError); - if(dbus_error_is_set(&dbusError)) { + if (dbus_error_is_set(&dbusError)) { qDebug("Error getting the system bus: %s", dbusError.message); dbus_error_free(&dbusError); return false; } dbus_error_free(&dbusError); libresourceConnection = resproto_init(RESPROTO_ROLE_CLIENT, RESPROTO_TRANSPORT_DBUS, - connectionIsUp, dbusConnection); - if(libresourceConnection == NULL) { + connectionIsUp, dbusConnection); + if (libresourceConnection == NULL) { return NULL; } @@ -148,7 +148,7 @@ bool ResourceEngine::disconnect() int r = resconn_disconnect(libresourceSet, &resourceMessage, statusCallbackHandler); connected = false; - if(r) + if (r) return true; else return false; @@ -157,8 +157,8 @@ bool ResourceEngine::disconnect() static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet) { QList resourceList = resourceSet->resources(); - quint32 bitmask=0; - for(int i=0; i < resourceList.size(); i++) { + quint32 bitmask = 0; + for (int i = 0; i < resourceList.size(); i++) { bitmask += resourceTypeToLibresourceType(resourceList[i]->type()); } return bitmask; @@ -166,46 +166,46 @@ static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet) static inline quint32 resourceTypeToLibresourceType(ResourceType type) { - quint32 bitmask=0; - switch(type) { - case AudioPlaybackType: - bitmask += RESMSG_AUDIO_PLAYBACK; - break; - case VideoPlaybackType: - bitmask += RESMSG_VIDEO_PLAYBACK; - break; - case AudioRecorderType: - bitmask += RESMSG_AUDIO_RECORDING; - break; - case VideoRecorderType: - bitmask += RESMSG_VIDEO_RECORDING; - break; - case VibraType: - bitmask += RESMSG_VIBRA; - break; - case LedsType: - bitmask += RESMSG_LEDS; - break; - case BacklightType: - bitmask += RESMSG_BACKLIGHT; - break; - case SystemButtonType: - bitmask += RESMSG_SYSTEM_BUTTON; - break; - case LockButtonType: - bitmask += RESMSG_LOCK_BUTTON; - break; - case ScaleButtonType: - bitmask += RESMSG_SCALE_BUTTON; - break; - case SnapButtonType: - bitmask += RESMSG_SNAP_BUTTON; - break; - case LensCoverType: - bitmask += RESMSG_LENS_COVER; - break; - default: - break; + quint32 bitmask = 0; + switch (type) { + case AudioPlaybackType: + bitmask += RESMSG_AUDIO_PLAYBACK; + break; + case VideoPlaybackType: + bitmask += RESMSG_VIDEO_PLAYBACK; + break; + case AudioRecorderType: + bitmask += RESMSG_AUDIO_RECORDING; + break; + case VideoRecorderType: + bitmask += RESMSG_VIDEO_RECORDING; + break; + case VibraType: + bitmask += RESMSG_VIBRA; + break; + case LedsType: + bitmask += RESMSG_LEDS; + break; + case BacklightType: + bitmask += RESMSG_BACKLIGHT; + break; + case SystemButtonType: + bitmask += RESMSG_SYSTEM_BUTTON; + break; + case LockButtonType: + bitmask += RESMSG_LOCK_BUTTON; + break; + case ScaleButtonType: + bitmask += RESMSG_SCALE_BUTTON; + break; + case SnapButtonType: + bitmask += RESMSG_SNAP_BUTTON; + break; + case LensCoverType: + bitmask += RESMSG_LENS_COVER; + break; + default: + break; } return bitmask; } @@ -213,9 +213,9 @@ static inline quint32 resourceTypeToLibresourceType(ResourceType type) static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet) { QList resourceList = resourceSet->resources(); - quint32 bitmask=0; - for(int i=0; i < resourceList.size(); i++) { - if(resourceList[i]->isOptional()) { + quint32 bitmask = 0; + for (int i = 0; i < resourceList.size(); i++) { + if (resourceList[i]->isOptional()) { bitmask += resourceTypeToLibresourceType(resourceList[i]->type()); } } @@ -232,12 +232,12 @@ static void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message) void ResourceEngine::handleStatusMessage(quint32 requestNo) { resmsg_type_t messageType = messageMap.take(requestNo); - if(messageType == RESMSG_REGISTER) { + if (messageType == RESMSG_REGISTER) { qDebug("connected!"); connected = true; emit connectedToManager(); } - else if(messageType == RESMSG_UNREGISTER) { + else if (messageType == RESMSG_UNREGISTER) { qDebug("disconnected!"); connected = false; emit disconnectedFromManager(); diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp index f8f3826..93af954 100644 --- a/libresourceqt/src/resource-set.cpp +++ b/libresourceqt/src/resource-set.cpp @@ -3,8 +3,8 @@ using namespace ResourcePolicy; ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent) - : QObject(parent), resourceClass(applicationClass), autoRelease(false), - alwaysReply(false) + : QObject(parent), resourceClass(applicationClass), autoRelease(false), + alwaysReply(false) { identifier = (quint32)this; @@ -13,7 +13,7 @@ ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent) ResourceSet::~ResourceSet() { - for(int i=0;itype() == AudioPlaybackType) || (resource->type() == AudioRecorderType)) { + if ((resource->type() == AudioPlaybackType) || (resource->type() == AudioRecorderType)) { qDebug("audioResource..."); } resourceSet[resource->type()] = resource->clone(); @@ -33,14 +33,14 @@ void ResourceSet::addResource(const Resource *resource) void ResourceSet::addResources(const QListresources) { - for(int i=0; i < resources.size(); i++) { + for (int i = 0; i < resources.size(); i++) { addResource(resources.at(i)); } } void ResourceSet::delResource(ResourceType type) { - if(contains(type)) { + if (contains(type)) { delete resourceSet[type]; resourceSet[type] = NULL; } @@ -48,7 +48,7 @@ void ResourceSet::delResource(ResourceType type) bool ResourceSet::contains(ResourceType type) const { - if((type < NumberOfTypes) && (resourceSet[type] != NULL)) + if ((type < NumberOfTypes) && (resourceSet[type] != NULL)) return true; else return false; @@ -56,12 +56,13 @@ bool ResourceSet::contains(ResourceType type) const bool ResourceSet::contains(const QList &types) const { - bool containsAll=true; - int i=0; + bool containsAll = true; + int i = 0; do { containsAll = contains(types.at(i)); i++; - } while((i < types.size()) && containsAll); + } + while ((i < types.size()) && containsAll); return containsAll; } @@ -73,8 +74,8 @@ quint32 ResourceSet::id() const QList ResourceSet::resources() const { QList listOfResources; - for(int i=0; i < NumberOfTypes; i++) { - if(resourceSet[i] != NULL) { + for (int i = 0; i < NumberOfTypes; i++) { + if (resourceSet[i] != NULL) { Resource *clone = resourceSet[i]->clone(); listOfResources.append(clone); } @@ -84,7 +85,7 @@ QList ResourceSet::resources() const Resource * ResourceSet::resource(ResourceType type) const { - if(contains(type)) + if (contains(type)) return resourceSet[type]->clone(); else return NULL; diff --git a/libresourceqt/src/resource.cpp b/libresourceqt/src/resource.cpp index c9bd79e..d288ae6 100644 --- a/libresourceqt/src/resource.cpp +++ b/libresourceqt/src/resource.cpp @@ -3,14 +3,14 @@ using namespace ResourcePolicy; Resource::Resource() - : optional(false), + : optional(false), identifier(0), granted(false) { identifier = (quint32)this; } Resource::Resource(const Resource &other) - : optional(other.optional), + : optional(other.optional), identifier(other.identifier), granted(other.granted) { } diff --git a/libresourceqt/src/resources.cpp b/libresourceqt/src/resources.cpp index c763ebc..12d9492 100644 --- a/libresourceqt/src/resources.cpp +++ b/libresourceqt/src/resources.cpp @@ -3,12 +3,12 @@ using namespace ResourcePolicy; AudioResource::AudioResource(const QString &audioGroup) - : Resource(), group(audioGroup), pid(0), stream(QString()) + : Resource(), group(audioGroup), pid(0), stream(QString()) { } AudioResource::AudioResource(const AudioResource &other) - : Resource(other), group(other.group), pid(other.pid), stream(other.stream) + : Resource(other), group(other.group), pid(other.pid), stream(other.stream) { } @@ -57,12 +57,12 @@ ResourceType AudioResource::type() const } AudioRecorderResource::AudioRecorderResource(const QString & audioGroup) - : Resource(), group(audioGroup), pid(0), stream(QString()) + : Resource(), group(audioGroup), pid(0), stream(QString()) { } AudioRecorderResource::AudioRecorderResource(const AudioRecorderResource &other) - : Resource(other), group(other.group), pid(other.pid), stream(other.stream) + : Resource(other), group(other.group), pid(other.pid), stream(other.stream) { } @@ -106,12 +106,12 @@ ResourceType AudioRecorderResource::type() const } VideoResource::VideoResource() - : Resource() + : Resource() { } VideoResource::VideoResource(const VideoResource &other) - : Resource(other) + : Resource(other) { } @@ -130,12 +130,12 @@ ResourceType VideoResource::type() const } VideoRecorderResource::VideoRecorderResource() - : Resource() + : Resource() { } VideoRecorderResource::VideoRecorderResource(const VideoRecorderResource &other) - : Resource(other) + : Resource(other) { } @@ -154,12 +154,12 @@ ResourceType VideoRecorderResource::type() const } VibraResource::VibraResource() - : Resource() + : Resource() { } VibraResource::VibraResource(const VibraResource &other) - : Resource(other) + : Resource(other) { } @@ -178,12 +178,12 @@ ResourceType VibraResource::type() const } LedsResource::LedsResource() - : Resource() + : Resource() { } LedsResource::LedsResource(const LedsResource &other) - : Resource(other) + : Resource(other) { } @@ -202,12 +202,12 @@ ResourceType LedsResource::type() const } BacklightResource::BacklightResource() - : Resource() + : Resource() { } BacklightResource::BacklightResource(const BacklightResource &other) - : Resource(other) + : Resource(other) { } @@ -226,12 +226,12 @@ ResourceType BacklightResource::type() const } SystemButtonResource::SystemButtonResource() - : Resource() + : Resource() { } SystemButtonResource::SystemButtonResource(const SystemButtonResource &other) - : Resource(other) + : Resource(other) { } @@ -250,12 +250,12 @@ ResourceType SystemButtonResource::type() const } LockButtonResource::LockButtonResource() - : Resource() + : Resource() { } LockButtonResource::LockButtonResource(const LockButtonResource &other) - : Resource(other) + : Resource(other) { } @@ -274,12 +274,12 @@ ResourceType LockButtonResource::type() const } ScaleButtonResource::ScaleButtonResource() - : Resource() + : Resource() { } ScaleButtonResource::ScaleButtonResource(const ScaleButtonResource &other) - : Resource(other) + : Resource(other) { } @@ -298,12 +298,12 @@ ResourceType ScaleButtonResource::type() const } SnapButtonResource::SnapButtonResource() - : Resource() + : Resource() { } SnapButtonResource::SnapButtonResource(const SnapButtonResource &other) - : Resource(other) + : Resource(other) { } @@ -322,12 +322,12 @@ ResourceType SnapButtonResource::type() const } LensCoverResource::LensCoverResource() - : Resource() + : Resource() { } LensCoverResource::LensCoverResource(const LensCoverResource &other) - : Resource(other) + : Resource(other) { } 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(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(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 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 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 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;iaddResource(resource); @@ -155,11 +155,11 @@ void TestResourceSet::testContainsSet() QList 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("type"); QTest::addColumn("optional"); QTest::addColumn("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(); -- cgit v1.2.3