From ae0602ca11090c6c70cdf289ce3871766d36519c Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Mon, 21 Sep 2015 11:53:31 +0200 Subject: code cleanup --- tests/accounts-mock/AccountsDefs.h | 15 ++++++++++++-- tests/accounts-mock/AccountsMock.cpp | 2 ++ tests/accounts-mock/AccountsMock.h | 15 ++++++++++++++ tests/accounts-mock/AccountsServiceSoundMock.cpp | 26 +++++++----------------- tests/accounts-mock/AccountsServiceSoundMock.h | 26 ++++++++++++++++++------ tests/accounts-mock/CMakeLists.txt | 5 +++-- tests/accounts-mock/main.cpp | 2 ++ 7 files changed, 62 insertions(+), 29 deletions(-) (limited to 'tests/accounts-mock') diff --git a/tests/accounts-mock/AccountsDefs.h b/tests/accounts-mock/AccountsDefs.h index e2b24ab..0e4f270 100644 --- a/tests/accounts-mock/AccountsDefs.h +++ b/tests/accounts-mock/AccountsDefs.h @@ -17,10 +17,21 @@ */ #pragma once -namespace +namespace ubuntu +{ + +namespace indicators +{ + +namespace testing { constexpr const char ACCOUNTS_SERVICE[] = "org.freedesktop.Accounts"; constexpr const char USER_PATH[] = "/org/freedesktop/Accounts/UserTest"; constexpr const char ACCOUNTS_PATH[] = "/org/freedesktop/Accounts"; constexpr const char ACCOUNTS_SOUND_INTERFACE[] = "com.ubuntu.AccountsService.Sound"; -} +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu + diff --git a/tests/accounts-mock/AccountsMock.cpp b/tests/accounts-mock/AccountsMock.cpp index 72f86a6..5c92dc5 100644 --- a/tests/accounts-mock/AccountsMock.cpp +++ b/tests/accounts-mock/AccountsMock.cpp @@ -20,6 +20,8 @@ #include "AccountsMock.h" #include "AccountsDefs.h" +using namespace ubuntu::indicators::testing; + AccountsMock::AccountsMock(QObject* parent) : QObject(parent) { diff --git a/tests/accounts-mock/AccountsMock.h b/tests/accounts-mock/AccountsMock.h index 759443c..72372e0 100644 --- a/tests/accounts-mock/AccountsMock.h +++ b/tests/accounts-mock/AccountsMock.h @@ -21,6 +21,15 @@ #include #include +namespace ubuntu +{ + +namespace indicators +{ + +namespace testing +{ + class AccountsMock : public QObject, protected QDBusContext { Q_OBJECT @@ -33,3 +42,9 @@ public: AccountsMock(QObject* parent = 0); virtual ~AccountsMock(); }; + +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu diff --git a/tests/accounts-mock/AccountsServiceSoundMock.cpp b/tests/accounts-mock/AccountsServiceSoundMock.cpp index 10f4f8d..37de377 100644 --- a/tests/accounts-mock/AccountsServiceSoundMock.cpp +++ b/tests/accounts-mock/AccountsServiceSoundMock.cpp @@ -22,6 +22,8 @@ #include "AccountsServiceSoundMock.h" #include "AccountsDefs.h" +using namespace ubuntu::indicators::testing; + AccountsServiceSoundMock::AccountsServiceSoundMock(QObject* parent) : QObject(parent) , volume_(0.0) @@ -38,23 +40,9 @@ double AccountsServiceSoundMock::volume() const void AccountsServiceSoundMock::setVolume(double volume) { volume_ = volume; - notifyPropertyChanged(ACCOUNTS_SOUND_INTERFACE, - USER_PATH, - "Volume"); -} - -void AccountsServiceSoundMock::notifyPropertyChanged(QString const & interface, - QString const & path, - QString const & propertyName) -{ - QDBusMessage signal = QDBusMessage::createSignal( - path, - "org.freedesktop.DBus.Properties", - "PropertiesChanged"); - signal << interface; - QVariantMap changedProps; - changedProps.insert(propertyName, property(propertyName.toStdString().c_str())); - signal << changedProps; - signal << QStringList(); - QDBusConnection::systemBus().send(signal); + notifier_.notifyPropertyChanged(QDBusConnection::systemBus(), + ACCOUNTS_SOUND_INTERFACE, + USER_PATH, + "Volume", + property("Volume")); } diff --git a/tests/accounts-mock/AccountsServiceSoundMock.h b/tests/accounts-mock/AccountsServiceSoundMock.h index 2be996f..bb3dbe8 100644 --- a/tests/accounts-mock/AccountsServiceSoundMock.h +++ b/tests/accounts-mock/AccountsServiceSoundMock.h @@ -20,10 +20,22 @@ #include #include +#include "DBusPropertiesNotifier.h" + +namespace ubuntu +{ + +namespace indicators +{ + +namespace testing +{ + +class DBusPropertiesNotifier; + class AccountsServiceSoundMock : public QObject, protected QDBusContext { Q_OBJECT -// Q_CLASSINFO("D-Bus Interface", "test.com.ubuntu.AccountsService.Sound") Q_PROPERTY(double Volume READ volume WRITE setVolume) public Q_SLOTS: @@ -34,11 +46,13 @@ public: AccountsServiceSoundMock(QObject* parent = 0); virtual ~AccountsServiceSoundMock(); -protected: - void notifyPropertyChanged(QString const & interface, - QString const & path, - QString const & propertyName); - private: double volume_; + DBusPropertiesNotifier notifier_; }; + +} // namespace testing + +} // namespace indicators + +} // namespace ubuntu diff --git a/tests/accounts-mock/CMakeLists.txt b/tests/accounts-mock/CMakeLists.txt index fcfab2d..aab7940 100644 --- a/tests/accounts-mock/CMakeLists.txt +++ b/tests/accounts-mock/CMakeLists.txt @@ -15,13 +15,13 @@ qt5_add_dbus_interface(interface_files ${dbusinterface_sound_xml} accountsservic qt5_add_dbus_adaptor(adaptor_files com.ubuntu.AccountsService.Sound.Mock.xml AccountsServiceSoundMock.h - AccountsServiceSoundMock + ubuntu::indicators::testing::AccountsServiceSoundMock AccountsServiceSoundMockAdaptor) qt5_add_dbus_adaptor(adaptor_files org.freedesktop.Accounts.Mock.xml AccountsMock.h - AccountsMock + ubuntu::indicators::testing::AccountsMock AccountsMockAdaptor) add_executable( @@ -30,6 +30,7 @@ add_executable( ${adaptor_files} AccountsServiceSoundMock.cpp AccountsMock.cpp + DBusPropertiesNotifier.cpp main.cpp ) diff --git a/tests/accounts-mock/main.cpp b/tests/accounts-mock/main.cpp index 04ec530..d6cd1d3 100644 --- a/tests/accounts-mock/main.cpp +++ b/tests/accounts-mock/main.cpp @@ -26,6 +26,8 @@ #include "AccountsMock.h" #include "AccountsMockAdaptor.h" +using namespace ubuntu::indicators::testing; + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); -- cgit v1.2.3