[Ktutorial-commits] SF.net SVN: ktutorial:[234] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-04-25 23:10:51
|
Revision: 234 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=234&view=rev Author: danxuliu Date: 2010-04-25 23:10:44 +0000 (Sun, 25 Apr 2010) Log Message: ----------- -Add RemoteClass to act as a proxy for class information provided by the target application. -Provide completion in the signal line edit in WaitForSignalWidget with the signals of the chosen RemoteObject. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/targetapplication/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.h trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEventSpyTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationStub.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/CMakeLists.txt 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/CMakeLists.txt 2010-04-25 23:10:44 UTC (rev 234) @@ -1,5 +1,6 @@ set(ktutorial_editor_targetapplication_SRCS DBusException.cpp + RemoteClass.cpp RemoteEditorSupport.cpp RemoteEventSpy.cpp RemoteObject.cpp Added: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "RemoteClass.h" + +#include <QtDBus/QtDBus> + +#include "RemoteObjectMapper.h" + +//public: + +RemoteClass::RemoteClass(const QString& service, RemoteObjectMapper* mapper, + const QString& className): + QDBusAbstractInterface(service, "/ktutorial/ObjectRegister", + "org.kde.ktutorial.ClassRegister", + QDBusConnection::sessionBus(), 0), + mMapper(mapper), + mClassName(className) { +} + +QString RemoteClass::className() const { + return mClassName; +} + +RemoteClass* RemoteClass::superClass() throw (DBusException) { + QDBusReply<QString> reply = call("superClass", mClassName); + if (!reply.isValid()) { + throw DBusException(reply.error().message()); + } + + if (reply.value().isEmpty()) { + return 0; + } + + return mMapper->remoteClass(reply.value()); +} + +QStringList RemoteClass::signalList() throw (DBusException) { + QDBusReply<QStringList> reply = call("signalList", mClassName); + if (!reply.isValid()) { + throw DBusException(reply.error().message()); + } + + return reply.value(); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h 2010-04-25 23:10:44 UTC (rev 234) @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef REMOTECLASS_H +#define REMOTECLASS_H + +#include <QDBusAbstractInterface> + +#include "DBusException.h" + +class RemoteObjectMapper; + +/** + * Proxy for remote classes exposed by KTutorial editor support module in + * KTutorial library. + * RemoteClass represents a remote class exposed by ObjectRegister in KTutorial + * library through DBus. Its purpose is provide an API to use the remote + * class/QMetaObject like any other local object, hiding the DBus complexity + * behind it. + * + * To get the data, RemoteClass makes DBus calls to the + * "org.kde.ktutorial.ClassRegistry" interface in the DBus service specified in + * the constructor. + * + * Although the idea is let other objects use it like a local object, it has to + * communicate with the remote ObjectRegistry through DBus anyway, so the + * methods may throw a DBusException if something goes wrong. + */ +class RemoteClass: public QDBusAbstractInterface { +Q_OBJECT +public: + + /** + * Creates a new RemoteClass to represent the remote class with the given + * class name in the given DBus service name. + * + * @param service The DBus service name. + * @param mapper The RemoteObjectMapper to get RemoteClasses from. + * @param className The name of the remote class. + */ + RemoteClass(const QString& service, RemoteObjectMapper* mapper, + const QString& className); + + /** + * Returns the class name. + * + * @return The class name. + */ + QString className() const; + + /** + * Returns the remote super class. + * If it has no super class, a null pointer is returned. + * + * @return The remote super class. + * @throws DBusException If a DBus error happens. + */ + RemoteClass* superClass() throw (DBusException); + + /** + * Returns a list with the signals defined in the remote class. + * The list only includes the signals from the class itself, but not its + * super classes. + * + * @return The signals. + * @throws DBusException If a DBus error happens. + */ + QStringList signalList() throw (DBusException); + +private: + + /** + * The mapper that associates a RemoteClass with its name. + */ + RemoteObjectMapper* mMapper; + + /** + * The name of the remote class. + */ + QString mClassName; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteClass.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -46,13 +46,13 @@ return reply.value(); } -QString RemoteObject::className() throw (DBusException) { +RemoteClass* RemoteObject::remoteClass() throw (DBusException) { QDBusReply<QString> reply = call("className", mObjectId); if (!reply.isValid()) { throw DBusException(reply.error().message()); } - return reply.value(); + return mMapper->remoteClass(reply.value()); } Q_DECLARE_METATYPE(QList<int>) Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.h 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObject.h 2010-04-25 23:10:44 UTC (rev 234) @@ -23,6 +23,7 @@ #include "DBusException.h" +class RemoteClass; class RemoteObjectMapper; /** @@ -72,12 +73,12 @@ QString name() throw (DBusException); /** - * Returns the class name. + * Returns the remote class. * - * @return The class name. + * @return The remote class. * @throws DBusException If a DBus error happens. */ - QString className() throw (DBusException); + RemoteClass* remoteClass() throw (DBusException); /** * Returns a list with the RemoteObjects that represent the children of this Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -20,6 +20,7 @@ #include <QHash> +#include "RemoteClass.h" #include "RemoteObject.h" //public: @@ -30,6 +31,7 @@ RemoteObjectMapper::~RemoteObjectMapper() { qDeleteAll(mRemoteObjects); + qDeleteAll(mRemoteClasses); } RemoteObject* RemoteObjectMapper::remoteObject(int objectId) { @@ -43,7 +45,21 @@ return remoteObject; } +RemoteClass* RemoteObjectMapper::remoteClass(const QString& className) { + if (mRemoteClasses.contains(className)) { + return mRemoteClasses.value(className); + } + + RemoteClass* remoteClass = new RemoteClass(mService, this, className); + mRemoteClasses.insert(className, remoteClass); + + return remoteClass; +} + void RemoteObjectMapper::clear() { qDeleteAll(mRemoteObjects); mRemoteObjects.clear(); + + qDeleteAll(mRemoteClasses); + mRemoteClasses.clear(); } Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteObjectMapper.h 2010-04-25 23:10:44 UTC (rev 234) @@ -21,17 +21,18 @@ #include <QHash> +class RemoteClass; class RemoteObject; /** - * Map to get a RemoteObject from their objectId. - * The RemoteObjectMapper should be used to get all the RemoteObjects for its - * DBus service. It creates a new RemoteObject when there is no RemoteObject - * for the given id, or returns the previosly created one, depending on the - * case. + * Map to get RemoteObjects and RemoteClasses from their objectId or class name. + * The RemoteObjectMapper should be used to get all the RemoteObjects and + * RemoteClasses for its DBus service. It creates a new RemoteObject when there + * is no RemoteObject for the given id, or returns the previosly created one, + * depending on the case. The same behavior is shown for RemoteClasses. * - * The RemoteObjectMapper also has ownership of the RemoteObjects, so they are - * deleted when the mapper is cleared or destroyed. + * The RemoteObjectMapper also has ownership of the RemoteObjects and + * RemoteClasses, so they are deleted when the mapper is cleared or destroyed. */ class RemoteObjectMapper { public: @@ -39,13 +40,13 @@ /** * Creates a new RemoteObjectMapper for the given DBus service name. * - * @param service The DBus service name of the remote objects. + * @param service The DBus service name of the remote objects and classes. */ RemoteObjectMapper(const QString& service); /** * Destroys this RemoteObjectMapper. - * All the mapped RemoteObjects are also destroyed. + * All the mapped RemoteObjects and RemoteClasses are also destroyed. */ ~RemoteObjectMapper(); @@ -60,8 +61,18 @@ RemoteObject* remoteObject(int objectId); /** - * Destroys all the mapped RemoteObject. + * Returns the RemoteClass associated with the given class name. + * The RemoteClass is destroyed when this RemoteObjectMapper is cleared or + * destroyed, so consider using QPointer to store it. + * + * @param className The name of the remote class. + * @return The RemoteClass. */ + RemoteClass* remoteClass(const QString& className); + + /** + * Destroys all the mapped RemoteObjects and RemoteClasses. + */ void clear(); private: @@ -77,6 +88,12 @@ */ QHash<int, RemoteObject*> mRemoteObjects; + /** + * All the RemoteClasses already requested since the last time this + * RemoteObjectMapper was cleared. + */ + QHash<QString, RemoteClass*> mRemoteClasses; + }; #endif Modified: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -22,6 +22,7 @@ #include <KLocalizedString> #include "RemoteObjectTreeItemUpdater.h" +#include "../targetapplication/RemoteClass.h" #include "../targetapplication/RemoteObject.h" //public: @@ -35,7 +36,7 @@ try { mName = remoteObject->name(); - mClassName = remoteObject->className(); + mClassName = remoteObject->remoteClass()->className(); } catch (DBusException e) { mName = i18nc("@item", "D-Bus Error!"); mClassName = i18nc("@item", "D-Bus Error!"); Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -25,6 +25,7 @@ #include <KMessageBox> #include "RemoteObjectChooser.h" +#include "../targetapplication/RemoteClass.h" #include "../targetapplication/RemoteObject.h" #endif @@ -67,6 +68,24 @@ } } +//private: + +#ifdef QT_QTDBUS_FOUND +void WaitForSignalWidget::setSignalCompletion(RemoteClass* remoteClass) { + KCompletion* completion = ui->signalNameLineEdit->completionObject(); + completion->clear(); + completion->setOrder(KCompletion::Sorted); + + while (remoteClass) { + foreach (QString signal, remoteClass->signalList()) { + completion->addItem(signal); + } + + remoteClass = remoteClass->superClass(); + } +} +#endif + //private slots: #ifdef QT_QTDBUS_FOUND @@ -81,6 +100,7 @@ void WaitForSignalWidget::setChosenRemoteObject(RemoteObject* remoteObject) { try { ui->emitterNameLineEdit->setText(remoteObject->name()); + setSignalCompletion(remoteObject->remoteClass()); } catch (DBusException e) { QString text = i18nc("@label", "The emitter name can not be set, there " "was a problem getting the name from the target application: %1", e.message()); Modified: trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h 2010-04-25 23:10:44 UTC (rev 234) @@ -21,6 +21,7 @@ #include "EditionWidget.h" +class RemoteClass; class RemoteObject; class WaitForSignal; @@ -66,6 +67,16 @@ */ Ui::WaitForSignalWidget* ui; +#ifdef QT_QTDBUS_FOUND + /** + * Sets the completion of the signal line edit to the signals emitted by the + * given remote class and its super classes. + * + * @param remoteClass The class to get its signal list. + */ + void setSignalCompletion(RemoteClass* remoteClass); +#endif + private Q_SLOTS: #ifdef QT_QTDBUS_FOUND Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/CMakeLists.txt 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/CMakeLists.txt 2010-04-25 23:10:44 UTC (rev 234) @@ -24,6 +24,7 @@ unit_tests( DBusException + RemoteClass RemoteEditorSupport RemoteEventSpy RemoteObject @@ -39,6 +40,7 @@ mem_tests( DBusException + RemoteClass RemoteEditorSupport RemoteEventSpy RemoteObject Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2010-04-25 23:10:44 UTC (rev 234) @@ -41,16 +41,45 @@ }; -class StubObjectRegister: public QObject { +class StubClassRegisterAdaptor: public QDBusAbstractAdaptor { Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.ClassRegister") +public: + + StubClassRegisterAdaptor(QObject* parent): QDBusAbstractAdaptor(parent) { + } + +public slots: + + QString superClass(const QString& className) { + if (className.startsWith("Child")) { + return className.mid(QString("Child").count()); + } + + return ""; + } + + QStringList signalList(const QString& className) { + QStringList signalList; + for (int i=0; i<3; ++i) { + signalList.append(className + "Signal" + QString::number(i) + "()"); + } + + return signalList; + } +}; + +class StubObjectRegisterAdaptor: public QDBusAbstractAdaptor { +Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.ObjectRegister") public: - StubObjectRegister(QObject* parent = 0): QObject(parent) { + StubObjectRegisterAdaptor(QObject* parent): QDBusAbstractAdaptor(parent) { } public slots: + QString objectName(int objectId) { if (objectId > 100) { return ""; @@ -78,7 +107,19 @@ } return ids; } +}; +//Only one Q_CLASSINFO("D-Bus Interface", "whatever") is supported in +//each class, so adaptors have to be used to represent several interfaces +class StubObjectRegister: public QObject { +Q_OBJECT +public: + + StubObjectRegister(QObject* parent = 0): QObject(parent) { + new StubClassRegisterAdaptor(this); + new StubObjectRegisterAdaptor(this); + } + }; class StubEditorSupport: public QObject { Added: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -0,0 +1,123 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "RemoteClass.h" + +#include <QtDBus/QtDBus> + +#include "RemoteClassStubs.h" +#include "RemoteObjectMapper.h" + +#define EXPECT_EXCEPTION(statement, exception) \ +do {\ + try {\ + statement;\ + QFAIL("Expected " #exception " not thrown");\ + } catch (exception e) {\ + } catch (Exception e) {\ + QFAIL("Expected " #exception " not thrown");\ + }\ +} while (0) + +class RemoteClassTest: public QObject { +Q_OBJECT + +private slots: + + void init(); + void cleanup(); + + void testClassName(); + + void testSuperClass(); + void testSuperClassWhenRemoteClassIsNotAvailable(); + + void testSignalList(); + void testSignalListWhenRemoteClassIsNotAvailable(); + +private: + + StubObjectRegister* mObjectRegister; + + QString mService; + RemoteObjectMapper* mMapper; + +}; + +void RemoteClassTest::init() { + QVERIFY(QDBusConnection::sessionBus().isConnected()); + + mObjectRegister = new StubObjectRegister(); + QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", + mObjectRegister, QDBusConnection::ExportAdaptors); + + mService = QDBusConnection::sessionBus().baseService(); + mMapper = new RemoteObjectMapper(mService); +} + +void RemoteClassTest::cleanup() { + delete mMapper; + + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + delete mObjectRegister; +} + +void RemoteClassTest::testClassName() { + RemoteClass remoteClass(mService, mMapper, "The class name"); + + QCOMPARE(remoteClass.className(), QString("The class name")); +} + +void RemoteClassTest::testSuperClass() { + RemoteClass remoteClass(mService, mMapper, "ChildClass"); + + QCOMPARE(remoteClass.superClass()->className(), QString("Class")); + QCOMPARE(remoteClass.superClass()->superClass(), (RemoteClass*)0); +} + +void RemoteClassTest::testSuperClassWhenRemoteClassIsNotAvailable() { + RemoteClass remoteClass(mService, mMapper, "Class"); + + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + + EXPECT_EXCEPTION(remoteClass.superClass(), DBusException); +} + +void RemoteClassTest::testSignalList() { + RemoteClass remoteClass(mService, mMapper, "Class"); + + QStringList signalList = remoteClass.signalList(); + QCOMPARE(signalList.count(), 3); + QCOMPARE(signalList[0], QString("ClassSignal0()")); + QCOMPARE(signalList[1], QString("ClassSignal1()")); + QCOMPARE(signalList[2], QString("ClassSignal2()")); +} + +void RemoteClassTest::testSignalListWhenRemoteClassIsNotAvailable() { + RemoteClass remoteClass(mService, mMapper, "Class"); + + QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); + + EXPECT_EXCEPTION(remoteClass.signalList(), DBusException); +} + +QTEST_MAIN(RemoteClassTest) + +#include "RemoteClassTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -80,7 +80,7 @@ mObjectRegister = new StubObjectRegister(); QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", - mObjectRegister, QDBusConnection::ExportAllSlots); + mObjectRegister, QDBusConnection::ExportAdaptors); } void RemoteEditorSupportTest::cleanup() { Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEventSpyTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEventSpyTest.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEventSpyTest.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -52,7 +52,7 @@ mObjectRegister = new StubObjectRegister(); QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", - mObjectRegister, QDBusConnection::ExportAllSlots); + mObjectRegister, QDBusConnection::ExportAdaptors); } void RemoteEventSpyTest::cleanup() { Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectMapperTest.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -22,6 +22,7 @@ #include <QtDBus/QtDBus> +#include "RemoteClass.h" #include "RemoteClassStubs.h" #include "RemoteObject.h" @@ -37,6 +38,10 @@ void testRemoteObjectSeveralIds(); void testRemoteObjectTwice(); + void testRemoteClass(); + void testRemoteClassSeveralIds(); + void testRemoteClassTwice(); + void testClear(); private: @@ -49,7 +54,7 @@ mObjectRegister = new StubObjectRegister(); QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", - mObjectRegister, QDBusConnection::ExportAllSlots); + mObjectRegister, QDBusConnection::ExportAdaptors); } void RemoteObjectMapperTest::cleanup() { @@ -96,20 +101,60 @@ QCOMPARE(remoteObject1->name(), QString("The object name 42")); } +void RemoteObjectMapperTest::testRemoteClass() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + + RemoteClass* remoteClass = mapper.remoteClass("Class"); + + QVERIFY(remoteClass); + QCOMPARE(remoteClass->className(), QString("Class")); +} + +void RemoteObjectMapperTest::testRemoteClassSeveralIds() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + + RemoteClass* remoteClass1 = mapper.remoteClass("Class1"); + RemoteClass* remoteClass2 = mapper.remoteClass("Class2"); + RemoteClass* remoteClass3 = mapper.remoteClass("Class3"); + + QVERIFY(remoteClass1); + QVERIFY(remoteClass2); + QVERIFY(remoteClass3); + QVERIFY(remoteClass1 != remoteClass2); + QVERIFY(remoteClass1 != remoteClass3); + QVERIFY(remoteClass2 != remoteClass3); + QCOMPARE(remoteClass1->className(), QString("Class1")); + QCOMPARE(remoteClass2->className(), QString("Class2")); + QCOMPARE(remoteClass3->className(), QString("Class3")); +} + +void RemoteObjectMapperTest::testRemoteClassTwice() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + + RemoteClass* remoteClass1 = mapper.remoteClass("Class"); + RemoteClass* remoteClass2 = mapper.remoteClass("Class"); + + QVERIFY(remoteClass1); + QVERIFY(remoteClass2); + QVERIFY(remoteClass1 == remoteClass2); + QCOMPARE(remoteClass1->className(), QString("Class")); +} + void RemoteObjectMapperTest::testClear() { RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); - RemoteObject* remoteObject1 = mapper.remoteObject(42); + QPointer<RemoteObject> remoteObject1 = mapper.remoteObject(42); + QPointer<RemoteClass> remoteClass1 = mapper.remoteClass("Class"); mapper.clear(); RemoteObject* remoteObject2 = mapper.remoteObject(42); + RemoteClass* remoteClass2 = mapper.remoteClass("Class"); - QVERIFY(remoteObject1); + QVERIFY(!remoteObject1); QVERIFY(remoteObject2); - QVERIFY(remoteObject1 != remoteObject2); - //remoteObject1 values can not be checked, as it was destroyed when the - //mapper was cleared + QVERIFY(!remoteClass1); + QVERIFY(remoteClass2); } QTEST_MAIN(RemoteObjectMapperTest) Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteObjectTest.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -22,6 +22,7 @@ #include <QtDBus/QtDBus> +#include "RemoteClass.h" #include "RemoteClassStubs.h" #include "RemoteObjectMapper.h" @@ -49,8 +50,8 @@ void testName(); void testNameWhenRemoteObjectIsNotAvailable(); - void testClassName(); - void testClassNameWhenRemoteObjectIsNotAvailable(); + void testRemoteClass(); + void testRemoteClassWhenRemoteObjectIsNotAvailable(); void testChildren(); void testChildrenWhenRemoteObjectIsNotAvailable(); @@ -69,7 +70,7 @@ mObjectRegister = new StubObjectRegister(); QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", - mObjectRegister, QDBusConnection::ExportAllSlots); + mObjectRegister, QDBusConnection::ExportAdaptors); mService = QDBusConnection::sessionBus().baseService(); mMapper = new RemoteObjectMapper(mService); @@ -102,18 +103,19 @@ EXPECT_EXCEPTION(remoteObject.name(), DBusException); } -void RemoteObjectTest::testClassName() { +void RemoteObjectTest::testRemoteClass() { RemoteObject remoteObject(mService, mMapper, 42); - QCOMPARE(remoteObject.className(), QString("The class name 42")); + QCOMPARE(remoteObject.remoteClass()->className(), + QString("The class name 42")); } -void RemoteObjectTest::testClassNameWhenRemoteObjectIsNotAvailable() { +void RemoteObjectTest::testRemoteClassWhenRemoteObjectIsNotAvailable() { RemoteObject remoteObject(mService, mMapper, 42); QDBusConnection::sessionBus().unregisterObject("/ktutorial/ObjectRegister"); - EXPECT_EXCEPTION(remoteObject.className(), DBusException); + EXPECT_EXCEPTION(remoteObject.remoteClass(), DBusException); } void RemoteObjectTest::testChildren() { Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationStub.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationStub.cpp 2010-04-25 23:01:54 UTC (rev 233) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationStub.cpp 2010-04-25 23:10:44 UTC (rev 234) @@ -36,7 +36,7 @@ StubObjectRegister* objectRegister = new StubObjectRegister(); QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", - objectRegister, QDBusConnection::ExportAllSlots); + objectRegister, QDBusConnection::ExportAdaptors); return app.exec(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |