[Ktutorial-commits] SF.net SVN: ktutorial:[254] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-09-25 03:33:45
|
Revision: 254 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=254&view=rev Author: danxuliu Date: 2010-09-25 03:33:38 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Add support to test in the target application the tutorial being designed in the editor. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/EditActions.cpp trunk/ktutorial/ktutorial-editor/src/EditActions.h trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.cpp trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/TutorialTester.cpp trunk/ktutorial/ktutorial-editor/src/TutorialTester.h Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-09-25 03:33:38 UTC (rev 254) @@ -21,6 +21,13 @@ KTutorialEditor.cpp ) +if (QT_QTDBUS_FOUND) + set(ktutorial_editor_SRCS + ${ktutorial_editor_SRCS} + TutorialTester.cpp + ) +endif (QT_QTDBUS_FOUND) + # Instead of compiling the executable directly from the sources, the sources are # compiled to a static library that is linked (and, being static, also embedded) # in the editor executable. Modified: trunk/ktutorial/ktutorial-editor/src/EditActions.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2010-09-25 03:33:38 UTC (rev 254) @@ -37,6 +37,10 @@ #include "view/TutorialCustomCodeWidget.h" #include "view/TutorialInformationWidget.h" +#ifdef QT_QTDBUS_FOUND +#include "TutorialTester.h" +#endif + //public: EditActions::EditActions(KTutorialEditor* tutorialEditor): @@ -207,6 +211,18 @@ action->setEnabled(false); actionCollection->addAction("removeReaction", action); connect(action, SIGNAL(triggered(bool)), this, SLOT(removeReaction())); + +#ifdef QT_QTDBUS_FOUND + action = new KAction(this); + action->setText(i18nc("@action", "Test tutorial")); + action->setStatusTip(i18nc("@info:status", "Starts the tutorial in the " +"target application.")); + action->setIcon(KIcon("document-preview")); + action->setEnabled(true); + actionCollection->addAction("testTutorial", action); + connect(action, SIGNAL(triggered(bool)), + new TutorialTester(mTutorialEditor), SLOT(testTutorial())); +#endif } int EditActions::showEditionDialog(CommandWidget* commandWidget) { Modified: trunk/ktutorial/ktutorial-editor/src/EditActions.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.h 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.h 2010-09-25 03:33:38 UTC (rev 254) @@ -30,7 +30,8 @@ /** * Edition related actions. * EditActions provide the actions to edit a tutorial (set the setup code, add a - * step...), and also actions to undo and redo the edition. + * step...), actions to undo and redo the edition, and also an action to test + * the current tutorial in the target application. * * KTutorialEditor notifies EditActions when a step or reaction is selected, so * it can know which step or reaction have to be edited. EditActions provides Added: trunk/ktutorial/ktutorial-editor/src/TutorialTester.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/TutorialTester.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/TutorialTester.cpp 2010-09-25 03:33:38 UTC (rev 254) @@ -0,0 +1,92 @@ +/*************************************************************************** + * 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 "TutorialTester.h" + +#include <KLocalizedString> +#include <KMessageBox> +#include <KTemporaryFile> + +#include "KTutorialEditor.h" +#include "serialization/Serialization.h" +#include "targetapplication/RemoteEditorSupport.h" +#include "targetapplication/TargetApplication.h" +#include "view/TargetApplicationView.h" + +//public: + +TutorialTester::TutorialTester(KTutorialEditor* tutorialEditor): + QObject(tutorialEditor), + mTutorialEditor(tutorialEditor) { + + mTargetApplicationView = + new TargetApplicationView(TargetApplication::self(), mTutorialEditor); +} + +//public slots: + +void TutorialTester::testTutorial() { + if (TargetApplication::self()->remoteEditorSupport()) { + sendTutorialToTargetApplication(); + } else { + connect(TargetApplication::self(), SIGNAL(started()), + this, SLOT(sendTutorialToTargetApplication())); + + mTargetApplicationView->start(); + } +} + +//private slots: + +void TutorialTester::sendTutorialToTargetApplication() { + disconnect(TargetApplication::self(), SIGNAL(started()), + this, SLOT(sendTutorialToTargetApplication())); + + //As this TutorialTester is set as parent of the KTemporaryFile object, the + //file will be automatically removed when this TutorialTester is destroyed + KTemporaryFile* temporaryFile = new KTemporaryFile(); + temporaryFile->setAutoRemove(true); + temporaryFile->setParent(this); + temporaryFile->setSuffix(".js"); + temporaryFile->open(); + + const Tutorial* tutorial = mTutorialEditor->tutorial(); + try { + Serialization(mTutorialEditor). + exportTutorial(tutorial, "*.js", temporaryFile->fileName()); + } catch (IOException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"save the tutorial to a temporary file (to be used by the target application " +"to test the tutorial):<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be saved"); + KMessageBox::error(mTutorialEditor, text, caption); + delete temporaryFile; + return; + } + + try { + TargetApplication::self()->remoteEditorSupport()->testScriptedTutorial( + temporaryFile->fileName()); + } catch (DBusException e) { + QString text = i18nc("@label", "There was a problem when trying to " +"tell the target application to start the tutorial:<nl/>%1", e.message()); + QString caption = i18nc("@title:window", "Tutorial could not be " +"started"); + KMessageBox::error(mTutorialEditor, text, caption); + } +} Property changes on: trunk/ktutorial/ktutorial-editor/src/TutorialTester.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/TutorialTester.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/TutorialTester.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/TutorialTester.h 2010-09-25 03:33:38 UTC (rev 254) @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 TUTORIALTESTER_H +#define TUTORIALTESTER_H + +#include <QObject> + +class KTutorialEditor; +class TargetApplicationView; + +/** + * Utility class to test a tutorial in the target application, starting it if + * necessary. + */ +class TutorialTester: public QObject { +Q_OBJECT +public: + + /** + * Creates a new TutorialTester with the given KTutorialEditor. + * + * @param tutorialEditor The parent KTutorialEditor. + */ + explicit TutorialTester(KTutorialEditor* tutorialEditor); + +public Q_SLOTS: + + /** + * Tests the current tutorial in the target application. + * The tutorial is saved to a temporary file that will be removed when the + * editor is closed. + */ + void testTutorial(); + +private: + + /** + * The KTutorialEditor to work with. + */ + KTutorialEditor* mTutorialEditor; + + /** + * The TargetApplicationView used to start the target application. + */ + TargetApplicationView* mTargetApplicationView; + +private Q_SLOTS: + + /** + * Exports the current tutorial to a temporary Javascript file and sends the + * file name to the target application to test the tutorial. + */ + void sendTutorialToTargetApplication(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/TutorialTester.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc =================================================================== --- trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/ktutorial-editorui.rc 2010-09-25 03:33:38 UTC (rev 254) @@ -27,6 +27,8 @@ <Action name="setReactionData"/> <Action name="removeReaction"/> </Menu> + <Separator/> + <Action name="testTutorial"/> </Menu> <Menu name="view"> <Menu name="panels"> @@ -40,5 +42,7 @@ <ToolBar name="mainToolBar"> <Text context="@title:menu">Main Toolbar</Text> <Action name="exportTutorial"/> + <Separator/> + <Action name="testTutorial"/> </ToolBar> </gui> Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.cpp 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.cpp 2010-09-25 03:33:38 UTC (rev 254) @@ -99,3 +99,11 @@ delete mRemoteEventSpy; mRemoteEventSpy = 0; } + +void RemoteEditorSupport::testScriptedTutorial(const QString& filename) + throw (DBusException) { + QDBusReply<void> reply = call("testScriptedTutorial", filename); + if (!reply.isValid()) { + throw DBusException(reply.error().message()); + } +} Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.h 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/src/targetapplication/RemoteEditorSupport.h 2010-09-25 03:33:38 UTC (rev 254) @@ -114,6 +114,14 @@ */ void disableEventSpy() throw (DBusException); + /** + * Tests the scripted tutorial stored in the file with the given name. + * The target application just starts the tutorial and shows it to the user. + * + * @param filename The name of the file that contains the tutorial to test. + */ + void testScriptedTutorial(const QString& filename) throw (DBusException); + private: /** Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteClassStubs.h 2010-09-25 03:33:38 UTC (rev 254) @@ -132,6 +132,7 @@ QList<int> mStopHighlightingRemoteWidgetIds; int mEnableEventSpyCount; int mDisableEventSpyCount; + QList<QString> mTestScriptedTutorialFilenames; StubEditorSupport(QObject* parent = 0): QObject(parent), mEventSpy(0), @@ -171,6 +172,10 @@ QDBusConnection::sessionBus().unregisterObject("/ktutorial/EventSpy"); } + void testScriptedTutorial(const QString& filename) { + mTestScriptedTutorialFilenames.append(filename); + } + }; #endif Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp 2010-09-25 03:01:55 UTC (rev 253) +++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/RemoteEditorSupportTest.cpp 2010-09-25 03:33:38 UTC (rev 254) @@ -65,6 +65,9 @@ void testDisableEventSpyTwice(); void testDisableEventSpyWhenRemoteEditorSupportIsNotAvailable(); + void testTestScriptedTutorial(); + void testTestScriptedTutorialWhenRemoteEditorSupportIsNotAvailable(); + private: StubEditorSupport* mEditorSupport; @@ -328,6 +331,30 @@ EXPECT_EXCEPTION(remoteEditorSupport.disableEventSpy(), DBusException); } +void RemoteEditorSupportTest::testTestScriptedTutorial() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + RemoteEditorSupport remoteEditorSupport( + QDBusConnection::sessionBus().baseService(), &mapper); + + remoteEditorSupport.testScriptedTutorial("/some/file"); + + QCOMPARE(mEditorSupport->mTestScriptedTutorialFilenames.count(), 1); + QCOMPARE(mEditorSupport->mTestScriptedTutorialFilenames[0], + QString("/some/file")); +} + +void RemoteEditorSupportTest:: + testTestScriptedTutorialWhenRemoteEditorSupportIsNotAvailable() { + RemoteObjectMapper mapper(QDBusConnection::sessionBus().baseService()); + RemoteEditorSupport remoteEditorSupport( + QDBusConnection::sessionBus().baseService(), &mapper); + + QDBusConnection::sessionBus().unregisterObject("/ktutorial"); + + EXPECT_EXCEPTION(remoteEditorSupport.testScriptedTutorial("/some/file"), + DBusException); +} + QTEST_MAIN(RemoteEditorSupportTest) #include "RemoteEditorSupportTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |