[Ktutorial-commits] SF.net SVN: ktutorial:[87] trunk/ktutorial
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-02-10 18:29:56
|
Revision: 87 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=87&view=rev Author: danxuliu Date: 2010-02-10 18:29:49 +0000 (Wed, 10 Feb 2010) Log Message: ----------- Add tearDown() method to Tutorial to be executed after the tutorial finishes. Setup() is now executed when the tutorial is started even if there is no start step, to ensure that whenever a setup method is executed, a tearDown method will be executed, and whenever a tearDown method is executed, a setup method was executed. Modified Paths: -------------- trunk/ktutorial/src/Tutorial.cpp trunk/ktutorial/src/Tutorial.h trunk/ktutorial/src/scripting/ScriptedTutorial.cpp trunk/ktutorial/src/scripting/ScriptedTutorial.h trunk/ktutorial/test/TutorialTest.cpp trunk/ktutorial/test/scripting/ScriptedTutorialTest.cpp Modified: trunk/ktutorial/src/Tutorial.cpp =================================================================== --- trunk/ktutorial/src/Tutorial.cpp 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/src/Tutorial.cpp 2010-02-10 18:29:49 UTC (rev 87) @@ -41,14 +41,14 @@ } void Tutorial::start() { + setup(); + if (!mSteps.contains("start")) { kError() << "No start step found in tutorial " << mTutorialInformation->id(); - emit finished(); + finish(); return; } - setup(); - nextStep("start"); } @@ -89,5 +89,7 @@ mCurrentStep->setActive(false); } + tearDown(); + emit finished(); } Modified: trunk/ktutorial/src/Tutorial.h =================================================================== --- trunk/ktutorial/src/Tutorial.h 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/src/Tutorial.h 2010-02-10 18:29:49 UTC (rev 87) @@ -58,7 +58,8 @@ * information about the Tutorial and add all the Steps with their WaitFors and * Options. Add as many slots as needed to the class to connect them with the * WaitFors and Options when added to their Steps. If something must be set - * before starting the Tutorial redefine setup(), and you are done. + * before starting the Tutorial redefine setup(), if something must be cleaned + * after finishing the tutorial redefine tearDown(), and you are done. */ class KTUTORIAL_EXPORT Tutorial: public QObject { Q_OBJECT @@ -141,7 +142,8 @@ /** * Finishes this Tutorial. - * The current step is deactivated and finished signal is emitted. + * The current step is deactivated, this tutorial is cleaned, and finished + * signal is emitted. * * This slot is used internally. Do not call or connect to this slot * yourself. @@ -182,6 +184,14 @@ virtual void setup() { } + /** + * Sets up the Tutorial before activating start Step. + * Tutorial subclasses can redefine it if they need to set up something + * before start. + */ + virtual void tearDown() { + } + private: /** Modified: trunk/ktutorial/src/scripting/ScriptedTutorial.cpp =================================================================== --- trunk/ktutorial/src/scripting/ScriptedTutorial.cpp 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/src/scripting/ScriptedTutorial.cpp 2010-02-10 18:29:49 UTC (rev 87) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -56,6 +56,10 @@ emit setup(this); } +void ScriptedTutorial::tearDown() { + emit tearDown(this); } +} + #include "ScriptedTutorial.moc" Modified: trunk/ktutorial/src/scripting/ScriptedTutorial.h =================================================================== --- trunk/ktutorial/src/scripting/ScriptedTutorial.h 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/src/scripting/ScriptedTutorial.h 2010-02-10 18:29:49 UTC (rev 87) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -45,6 +45,9 @@ * in the script and connect it to setup(QObject*) signal. Note that, although * the argument in the signal is declared as QObject*, it is in fact the * ScriptedStep that emitted the signal. It is a Kross limitation. + * + * You can do the same if something has to be cleaned after the Tutorial + * finishes using tearDown(QObject*) signal. */ class ScriptedTutorial: public Tutorial { Q_OBJECT @@ -99,6 +102,17 @@ */ void setup(QObject* scriptedTutorial); + /** + * Emitted when this ScriptedTutorial has to be cleaned. + * + * @param scriptedTutorial A pointer to this ScriptedTutorial. + * @see Tutorial::tearDown() + * @todo Change argument type to scripting::ScriptedTutorial* once all major + * Kross scripting backends support classes wrapped through + * WrapperInterface + */ + void tearDown(QObject* scriptedTutorial); + protected: /** @@ -107,6 +121,12 @@ */ virtual void setup(); + /** + * Emits tearDown(scripting::ScriptedTutorial*) signal using this + * ScriptedTutorial as parameter. + */ + virtual void tearDown(); + private: /** Modified: trunk/ktutorial/test/TutorialTest.cpp =================================================================== --- trunk/ktutorial/test/TutorialTest.cpp 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/test/TutorialTest.cpp 2010-02-10 18:29:49 UTC (rev 87) @@ -57,10 +57,12 @@ public: int mSetupCount; + int mTearDownCount; MockTutorial(TutorialInformation* tutorialInformation): Tutorial(tutorialInformation) { mSetupCount = 0; + mTearDownCount = 0; } protected: @@ -69,6 +71,10 @@ mSetupCount++; } + virtual void tearDown() { + mTearDownCount++; + } + }; void TutorialTest::testConstructor() { @@ -195,6 +201,7 @@ QCOMPARE(tutorial.mCurrentStep, stepStart); QVERIFY(stepStart->isActive()); QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(tutorial.mTearDownCount, 0); } void TutorialTest::testStartNoStartStep() { @@ -212,10 +219,11 @@ tutorial.start(); - QCOMPARE(tutorial.mSetupCount, 0); + QCOMPARE(tutorial.mSetupCount, 1); QCOMPARE(stepActivatedSpy.count(), 0); QCOMPARE(tutorial.mCurrentStep, (Step*)0); QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(tutorial.mTearDownCount, 1); } void TutorialTest::testNextStepId() { @@ -344,6 +352,7 @@ QVERIFY(!stepStart->isActive()); QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(tutorial.mTearDownCount, 1); } QTEST_MAIN(TutorialTest) Modified: trunk/ktutorial/test/scripting/ScriptedTutorialTest.cpp =================================================================== --- trunk/ktutorial/test/scripting/ScriptedTutorialTest.cpp 2010-02-10 18:06:14 UTC (rev 86) +++ trunk/ktutorial/test/scripting/ScriptedTutorialTest.cpp 2010-02-10 18:29:49 UTC (rev 87) @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009 by Daniel Calviño Sánchez * + * Copyright (C) 2009-2010 by Daniel Calviño Sánchez * * dan...@gm... * * * * This program is free software; you can redistribute it and/or modify * @@ -51,6 +51,9 @@ void testSetup(); void testSetupObjectArgument(); + void testTearDown(); + void testTearDownObjectArgument(); + private: KTemporaryFile* mTemporaryFile; @@ -161,8 +164,46 @@ QCOMPARE(qvariant_cast<QObject*>(argument), &scriptedTutorial); } +void ScriptedTutorialTest::testTearDown() { + QSKIP("Skipped until tearDown argument is set again to scripting::ScriptedTutorial*", SkipAll); + + ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName()); + + //ScriptedTutorial* must be registered in order to be used with QSignalSpy. + //The name must contain the namespace, as it needs the full name used in the + //signal (and the signal has to be declared using the full namespace so the + //spied argument can be converted using qvariant_cast). + int scriptedTutorialStarType = + qRegisterMetaType<ScriptedTutorial*>("scripting::ScriptedTutorial*"); + QSignalSpy tearDownSpy(&scriptedTutorial, + SIGNAL(tearDown(scripting::ScriptedTutorial*))); + + scriptedTutorial.tearDown(); + + QCOMPARE(tearDownSpy.count(), 1); + QVariant argument = tearDownSpy.at(0).at(0); + QCOMPARE(argument.userType(), scriptedTutorialStarType); + QCOMPARE(qvariant_cast<ScriptedTutorial*>(argument), &scriptedTutorial); } +void ScriptedTutorialTest::testTearDownObjectArgument() { + ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName()); + + QSignalSpy tearDownSpy(&scriptedTutorial, SIGNAL(tearDown(QObject*))); + + scriptedTutorial.tearDown(); + + QCOMPARE(tearDownSpy.count(), 1); + QVariant argument = tearDownSpy.at(0).at(0); + //From QVariant::Type documentation + //"Although this function is declared as returning QVariant::Type, the + //return value should be interpreted as QMetaType::Type" + QCOMPARE((QMetaType::Type)argument.type(), QMetaType::QObjectStar); + QCOMPARE(qvariant_cast<QObject*>(argument), &scriptedTutorial); +} + +} + QTEST_MAIN(scripting::ScriptedTutorialTest) #include "ScriptedTutorialTest.moc" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |