[Ktutorial-commits] SF.net SVN: ktutorial:[316] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2011-06-08 12:46:14
|
Revision: 316 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=316&view=rev Author: danxuliu Date: 2011-06-08 12:46:04 +0000 (Wed, 08 Jun 2011) Log Message: ----------- Add support for testing a tutorial from a specific step instead of just from the start. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp 2011-06-08 12:46:04 UTC (rev 316) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -103,7 +103,8 @@ mEventSpy = 0; } -void EditorSupport::testScriptedTutorial(const QString& filename) { +void EditorSupport::testScriptedTutorial(const QString& filename, + const QString& stepId) { ScriptedTutorial* scriptedTutorial = new ScriptedTutorial(filename); if (!scriptedTutorial->isValid()) { @@ -119,6 +120,10 @@ emit started(scriptedTutorial); scriptedTutorial->start(); + + if (!stepId.isEmpty()) { + scriptedTutorial->nextStep(stepId); + } } //private: Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h 2011-06-08 12:46:04 UTC (rev 316) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -43,7 +43,8 @@ * disable the EventSpy (as notifying all the events sent by an application * through D-Bus is very costly, the EventSpy should be enabled only when * needed), highlight and stop the highlighting of widgets, and test a scripted - * tutorial (starting the tutorial stored in the given filename). + * tutorial (starting the tutorial stored in the given filename and, optionally, + * from the given step id). * * The object register assigns an id to QObjects to be identified by the remote * KTutorial editor. Using that id, KTutorial editor can request further @@ -121,10 +122,14 @@ /** * Starts the scripted tutorial stored in the given filename. + * If a step id is given, the tutorial is changed to that step after + * starting. * * @param filename The name of the file to read the scripted tutorial from. + * @param stepId The id of the step to change to, if any. */ - void testScriptedTutorial(const QString& filename); + void testScriptedTutorial(const QString& filename, + const QString& stepId = QString()); Q_SIGNALS: Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp 2011-06-08 12:46:04 UTC (rev 316) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -57,8 +57,9 @@ mEditorSupport->disableEventSpy(); } -void EditorSupportAdaptor::testScriptedTutorial(const QString& filename) { - mEditorSupport->testScriptedTutorial(filename); +void EditorSupportAdaptor::testScriptedTutorial(const QString& filename, + const QString& stepId) { + mEditorSupport->testScriptedTutorial(filename, stepId); } } Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h 2011-06-08 12:46:04 UTC (rev 316) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -89,10 +89,14 @@ /** * Starts the scripted tutorial stored in the given filename. + * If a step id is given, the tutorial is changed to that step after + * starting. * * @param filename The name of the file to read the scripted tutorial from. + * @param stepId The id of the step to change to, if any. */ - void testScriptedTutorial(const QString& filename); + void testScriptedTutorial(const QString& filename, + const QString& stepId = QString()); private: Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp 2011-06-08 12:46:04 UTC (rev 316) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Daniel Calviño Sánchez * + * Copyright (C) 2010-2011 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -25,13 +25,23 @@ #include "EditorSupportAdaptor.h" +#define protected public +#define private public +#include "../Tutorial.h" +#undef private +#undef protected + #include "EditorSupport.h" #include "EventSpy.h" #include "ObjectRegister.h" +#include "../Step.h" #include "../extendedinformation/WidgetHighlighter.h" using extendedinformation::WidgetHighlighter; +//Tutorial* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Tutorial*); + namespace editorsupport { class EditorSupportAdaptorTest: public QObject { @@ -54,6 +64,7 @@ void testDisableEventSpy(); void testTestScriptedTutorial(); + void testTestScriptedTutorialWithStepId(); }; @@ -158,8 +169,38 @@ QCOMPARE(startedSpy.count(), 1); } +void EditorSupportAdaptorTest::testTestScriptedTutorialWithStepId() { + KTemporaryFile temporaryFile; + temporaryFile.setSuffix(".js"); + temporaryFile.open(); + + QTextStream out(&temporaryFile); + out << "tutorial.tutorialInformationAsObject().setName(\ +\"Test tutorial\");\n"; + out << "tutorial.addStep(ktutorial.newStep(\"start\"));\n"; + out << "tutorial.addStep(ktutorial.newStep(\"second step\"));\n"; + out << "tutorial.addStep(ktutorial.newStep(\"third step\"));\n"; + out.flush(); + + EditorSupport editorSupport; + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + //Tutorial* must be registered in order to be used with QSignalSpy + qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy startedSpy(&editorSupport, SIGNAL(started(Tutorial*))); + + adaptor->testScriptedTutorial(temporaryFile.fileName(), "third step"); + + QCOMPARE(startedSpy.count(), 1); + QVariant argument = startedSpy.at(0).at(0); + + Tutorial* tutorial = qvariant_cast<Tutorial*>(argument); + QVERIFY(tutorial->mCurrentStep); + QCOMPARE(tutorial->mCurrentStep->id(), QString("third step")); } +} + QTEST_MAIN(editorsupport::EditorSupportAdaptorTest) #include "EditorSupportAdaptorTest.moc" Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2011-05-28 04:00:15 UTC (rev 315) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2011-06-08 12:46:04 UTC (rev 316) @@ -26,6 +26,7 @@ #define protected public #define private public #include "EditorSupport.h" +#include "../Tutorial.h" #undef private #undef protected @@ -33,7 +34,7 @@ #include "EventSpy.h" #include "ObjectRegister.h" #include "ObjectRegisterAdaptor.h" -#include "../Tutorial.h" +#include "../Step.h" #include "../TutorialInformation.h" #include "../extendedinformation/WidgetHighlighter.h" @@ -87,6 +88,7 @@ void testDisableEventSpy(); void testTestScriptedTutorial(); + void testTestScriptedTutorialWithStepId(); void testTestScriptedTutorialWithInvalidTutorial(); void testObjectRegisterWhenEventSpyNotifiesEventBeforeEndingConstructor(); @@ -267,7 +269,8 @@ temporaryFile.fileName()); QCOMPARE(tutorial->tutorialInformation()->name(), QString("Test tutorial")); - //Ensuring that the tutorial was really started is too cumbersome + QVERIFY(tutorial->mCurrentStep); + QCOMPARE(tutorial->mCurrentStep->id(), QString("start")); QSignalSpy destroyedSpy(tutorial, SIGNAL(destroyed())); @@ -287,6 +290,58 @@ QCOMPARE(destroyedSpy.count(), 1); } +void EditorSupportTest::testTestScriptedTutorialWithStepId() { + KTemporaryFile temporaryFile; + temporaryFile.setSuffix(".js"); + temporaryFile.open(); + + QTextStream out(&temporaryFile); + out << "tutorial.tutorialInformationAsObject().setName(\ +\"Test tutorial\");\n"; + out << "tutorial.addStep(ktutorial.newStep(\"start\"));\n"; + out << "tutorial.addStep(ktutorial.newStep(\"second step\"));\n"; + out << "tutorial.addStep(ktutorial.newStep(\"third step\"));\n"; + out.flush(); + + EditorSupport editorSupport; + + //Tutorial* must be registered in order to be used with QSignalSpy + int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*"); + QSignalSpy startedSpy(&editorSupport, SIGNAL(started(Tutorial*))); + + editorSupport.testScriptedTutorial(temporaryFile.fileName(), "third step"); + + QCOMPARE(startedSpy.count(), 1); + QVariant argument = startedSpy.at(0).at(0); + QCOMPARE(argument.userType(), tutorialStarType); + + Tutorial* tutorial = qvariant_cast<Tutorial*>(argument); + QVERIFY(tutorial->tutorialInformation()); + QCOMPARE(tutorial->tutorialInformation()->id(), + temporaryFile.fileName()); + QCOMPARE(tutorial->tutorialInformation()->name(), QString("Test tutorial")); + + QVERIFY(tutorial->mCurrentStep); + QCOMPARE(tutorial->mCurrentStep->id(), QString("third step")); + + QSignalSpy destroyedSpy(tutorial, SIGNAL(destroyed())); + + //Process deleteLater() + QCoreApplication::sendPostedEvents(tutorial, QEvent::DeferredDelete); + + //Ensure that the tutorial is not deleted before explicitly calling finish + //(for example, if the test tutorial written in the text stream does not + //have a start step) + QCOMPARE(destroyedSpy.count(), 0); + + tutorial->finish(); + + //Process deleteLater() + QCoreApplication::sendPostedEvents(tutorial, QEvent::DeferredDelete); + + QCOMPARE(destroyedSpy.count(), 1); +} + void EditorSupportTest::testTestScriptedTutorialWithInvalidTutorial() { KTemporaryFile temporaryFile; temporaryFile.setSuffix(".js"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |