[Ktutorial-commits] SF.net SVN: ktutorial:[253] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-09-25 03:02:02
|
Revision: 253
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=253&view=rev
Author: danxuliu
Date: 2010-09-25 03:01:55 +0000 (Sat, 25 Sep 2010)
Log Message:
-----------
Add the ability to test a scripted tutorial through the KTutorial editor support module.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-library/src/KTutorial.cpp
trunk/ktutorial/ktutorial-library/src/Tutorial.cpp
trunk/ktutorial/ktutorial-library/src/Tutorial.h
trunk/ktutorial/ktutorial-library/src/TutorialManager.cpp
trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt
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/TutorialManagerTest.cpp
trunk/ktutorial/ktutorial-library/tests/TutorialTest.cpp
trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt
trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp
trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp
trunk/ktutorial/ktutorial-library/tests/view/TutorialManagerDialogTest.cpp
Modified: trunk/ktutorial/ktutorial-library/src/KTutorial.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -84,7 +84,11 @@
ScriptManager().loadTutorials(mTutorialmanager);
#ifdef QT_QTDBUS_FOUND
- (new editorsupport::EditorSupport(this))->setup(window);
+ editorsupport::EditorSupport* editorSupport =
+ new editorsupport::EditorSupport(this);
+ editorSupport->setup(window);
+ connect(editorSupport, SIGNAL(started(Tutorial*)),
+ this, SLOT(showStepWidget(Tutorial*)));
#endif
}
Modified: trunk/ktutorial/ktutorial-library/src/Tutorial.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/Tutorial.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -95,5 +95,5 @@
tearDown();
- emit finished();
+ emit finished(this);
}
Modified: trunk/ktutorial/ktutorial-library/src/Tutorial.h
===================================================================
--- trunk/ktutorial/ktutorial-library/src/Tutorial.h 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/Tutorial.h 2010-09-25 03:01:55 UTC (rev 253)
@@ -158,8 +158,10 @@
* This signal is emitted when this Tutorial finishes.
* Don't connect nor emit this signal yourself. It is connected
* automatically by KTutorial.
+ *
+ * @param tutorial This tutorial.
*/
- void finished();
+ void finished(Tutorial* tutorial);
/**
* This signal is emitted when a Step is activated.
Modified: trunk/ktutorial/ktutorial-library/src/TutorialManager.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/TutorialManager.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/TutorialManager.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -53,7 +53,7 @@
kDebug() << "Started: " << id;
Tutorial* tutorial = mTutorials.value(mTutorialInformations.value(id));
- connect(tutorial, SIGNAL(finished()), this, SLOT(finish()));
+ connect(tutorial, SIGNAL(finished(Tutorial*)), this, SLOT(finish()));
emit started(tutorial);
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt 2010-09-25 03:01:55 UTC (rev 253)
@@ -14,6 +14,7 @@
target_link_libraries(ktutorial_editorsupport
ktutorial_extendedinformation
+ ktutorial_scripting
${QT_QTDBUS_LIBRARY}
${KDE4_KDECORE_LIBS}
)
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -29,8 +29,10 @@
#include "ObjectRegister.h"
#include "ObjectRegisterAdaptor.h"
#include "../extendedinformation/WidgetHighlighterManager.h"
+#include "../scripting/ScriptedTutorial.h"
using extendedinformation::WidgetHighlighterManager;
+using scripting::ScriptedTutorial;
namespace editorsupport {
@@ -101,4 +103,29 @@
mEventSpy = 0;
}
+void EditorSupport::testScriptedTutorial(const QString& filename) {
+ ScriptedTutorial* scriptedTutorial = new ScriptedTutorial(filename);
+
+ if (!scriptedTutorial->isValid()) {
+ kWarning() << "Cannot test the scripted tutorial stored in "
+ << filename << ": the script is invalid";
+ delete scriptedTutorial;
+ return;
+ }
+
+ connect(scriptedTutorial, SIGNAL(finished(Tutorial*)),
+ this, SLOT(deleteFinishedTestTutorial(Tutorial*)));
+
+ emit started(scriptedTutorial);
+
+ scriptedTutorial->start();
}
+
+//private:
+
+void EditorSupport::deleteFinishedTestTutorial(Tutorial* tutorial) {
+ tutorial->deleteLater();
+}
+
+
+}
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h 2010-09-25 03:01:55 UTC (rev 253)
@@ -21,6 +21,8 @@
#include <QObject>
+class Tutorial;
+
namespace editorsupport {
class EventSpy;
class EventSupportAdaptor;
@@ -40,7 +42,8 @@
* The main object sets up the D-Bus objects and provides a way to enable and
* 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), and highlight and stop the highlighting of widgets.
+ * needed), highlight and stop the highlighting of widgets, and test a scripted
+ * tutorial (starting the tutorial stored in the given filename).
*
* The object register assigns an id to QObjects to be identified by the remote
* KTutorial editor. Using that id, KTutorial editor can request further
@@ -116,6 +119,22 @@
*/
void disableEventSpy();
+ /**
+ * Starts the scripted tutorial stored in the given filename.
+ *
+ * @param filename The name of the file to read the scripted tutorial from.
+ */
+ void testScriptedTutorial(const QString& filename);
+
+Q_SIGNALS:
+
+ /**
+ * This signals is emitted when the given tutorial is about to be started.
+ *
+ * @param tutorial The tutorial that is going to be started.
+ */
+ void started(Tutorial* tutorial);
+
private:
/**
@@ -133,6 +152,15 @@
*/
QObject* mWindow;
+private Q_SLOTS:
+
+ /**
+ * Deletes the test tutorial when it is finished.
+ *
+ * @param tutorial The tutorial to delete.
+ */
+ void deleteFinishedTestTutorial(Tutorial* tutorial);
+
};
}
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -57,4 +57,8 @@
mEditorSupport->disableEventSpy();
}
+void EditorSupportAdaptor::testScriptedTutorial(const QString& filename) {
+ mEditorSupport->testScriptedTutorial(filename);
}
+
+}
Modified: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h
===================================================================
--- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h 2010-09-25 03:01:55 UTC (rev 253)
@@ -87,6 +87,13 @@
*/
void disableEventSpy();
+ /**
+ * Starts the scripted tutorial stored in the given filename.
+ *
+ * @param filename The name of the file to read the scripted tutorial from.
+ */
+ void testScriptedTutorial(const QString& filename);
+
private:
/**
Modified: trunk/ktutorial/ktutorial-library/tests/TutorialManagerTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/TutorialManagerTest.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/TutorialManagerTest.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -62,7 +62,7 @@
}
void emitFinished() {
- emit finished();
+ emit finished(this);
}
};
Modified: trunk/ktutorial/ktutorial-library/tests/TutorialTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/TutorialTest.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/TutorialTest.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -188,6 +188,9 @@
//Step* must be declared as a metatype to be used in qvariant_cast
Q_DECLARE_METATYPE(Step*);
+//Tutorial* must be declared as a metatype to be used in qvariant_cast
+Q_DECLARE_METATYPE(Tutorial*);
+
void TutorialTest::testStart() {
MockTutorial tutorial(new TutorialInformation("pearlOrientation"));
@@ -202,7 +205,9 @@
int stepStarType = qRegisterMetaType<Step*>("Step*");
QSignalSpy stepActivatedSpy(&tutorial, SIGNAL(stepActivated(Step*)));
- QSignalSpy finishedSpy(&tutorial, SIGNAL(finished()));
+ //Tutorial* must be registered in order to be used with QSignalSpy
+ qRegisterMetaType<Tutorial*>("Tutorial*");
+ QSignalSpy finishedSpy(&tutorial, SIGNAL(finished(Tutorial*)));
tutorial.start();
@@ -228,7 +233,9 @@
qRegisterMetaType<Step*>("Step*");
QSignalSpy stepActivatedSpy(&tutorial, SIGNAL(stepActivated(Step*)));
- QSignalSpy finishedSpy(&tutorial, SIGNAL(finished()));
+ //Tutorial* must be registered in order to be used with QSignalSpy
+ int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*");
+ QSignalSpy finishedSpy(&tutorial, SIGNAL(finished(Tutorial*)));
tutorial.start();
@@ -236,6 +243,9 @@
QCOMPARE(stepActivatedSpy.count(), 0);
QCOMPARE(tutorial.mCurrentStep, (Step*)0);
QCOMPARE(finishedSpy.count(), 1);
+ QVariant argument = finishedSpy.at(0).at(0);
+ QCOMPARE(argument.userType(), tutorialStarType);
+ QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial);
QCOMPARE(tutorial.mTearDownCount, 1);
}
@@ -387,7 +397,9 @@
Step* stepStart = new Step("start");
tutorial.addStep(stepStart);
- QSignalSpy finishedSpy(&tutorial, SIGNAL(finished()));
+ //Tutorial* must be registered in order to be used with QSignalSpy
+ int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*");
+ QSignalSpy finishedSpy(&tutorial, SIGNAL(finished(Tutorial*)));
tutorial.start();
tutorial.finish();
@@ -395,6 +407,9 @@
QCOMPARE(tutorial.mCurrentStep, (Step*)0);
QVERIFY(!stepStart->isActive());
QCOMPARE(finishedSpy.count(), 1);
+ QVariant argument = finishedSpy.at(0).at(0);
+ QCOMPARE(argument.userType(), tutorialStarType);
+ QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial);
QCOMPARE(tutorial.mTearDownCount, 1);
}
Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt 2010-09-25 03:01:55 UTC (rev 253)
@@ -12,7 +12,7 @@
FOREACH(_className ${ARGN})
set(_testName ${_className}Test)
kde4_add_unit_test(${_testName} TESTNAME ktutorial-${_testName} ${_testName}.cpp)
- target_link_libraries(${_testName} ktutorial_editorsupport ${QT_QTTEST_LIBRARY})
+ target_link_libraries(${_testName} ktutorial_editorsupport ktutorial ${QT_QTTEST_LIBRARY})
ENDFOREACH(_className)
ENDMACRO(UNIT_TESTS)
Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -21,6 +21,8 @@
#include <QWidget>
#include <QtDBus/QtDBus>
+#include <KTemporaryFile>
+
#include "EditorSupportAdaptor.h"
#include "EditorSupport.h"
@@ -51,6 +53,8 @@
void testDisableEventSpy();
+ void testTestScriptedTutorial();
+
};
void EditorSupportAdaptorTest::testConstructor() {
@@ -132,8 +136,30 @@
QVERIFY(!bus.objectRegisteredAt("/ktutorial/EventSpy"));
}
+void EditorSupportAdaptorTest::testTestScriptedTutorial() {
+ KTemporaryFile temporaryFile;
+ temporaryFile.setSuffix(".js");
+ temporaryFile.open();
+
+ QTextStream out(&temporaryFile);
+ out << "tutorial.tutorialInformationAsObject().setName(\
+\"Test tutorial\");\n";
+ out.flush();
+
+ EditorSupport editorSupport;
+ EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport);
+
+ //Tutorial* must be registered in order to be used with QSignalSpy
+ int tutorialStarType = qRegisterMetaType<Tutorial*>("Tutorial*");
+ QSignalSpy startedSpy(&editorSupport, SIGNAL(started(Tutorial*)));
+
+ adaptor->testScriptedTutorial(temporaryFile.fileName());
+
+ QCOMPARE(startedSpy.count(), 1);
}
+}
+
QTEST_MAIN(editorsupport::EditorSupportAdaptorTest)
#include "EditorSupportAdaptorTest.moc"
Modified: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -21,6 +21,8 @@
#include <QApplication>
#include <QtDBus/QtDBus>
+#include <KTemporaryFile>
+
#define protected public
#define private public
#include "EditorSupport.h"
@@ -31,10 +33,15 @@
#include "EventSpy.h"
#include "ObjectRegister.h"
#include "ObjectRegisterAdaptor.h"
+#include "../Tutorial.h"
+#include "../TutorialInformation.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 EditorSupportTest: public QObject {
@@ -65,6 +72,9 @@
void testDisableEventSpy();
+ void testTestScriptedTutorial();
+ void testTestScriptedTutorialWithInvalidTutorial();
+
private:
QStringList mEventTypes;
@@ -212,8 +222,79 @@
QCOMPARE(mEventTypes.count(), 0);
}
+void EditorSupportTest::testTestScriptedTutorial() {
+ KTemporaryFile temporaryFile;
+ temporaryFile.setSuffix(".js");
+ temporaryFile.open();
+
+ QTextStream out(&temporaryFile);
+ out << "tutorial.tutorialInformationAsObject().setName(\
+\"Test tutorial\");\n";
+ out << "tutorial.addStep(ktutorial.newStep(\"start\"))";
+ 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());
+
+ 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"));
+
+ //Ensuring that the tutorial was really started is too cumbersome
+
+ 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");
+ temporaryFile.open();
+
+ QTextStream out(&temporaryFile);
+ out << "tutorial.tutorialInformationAsObject().setName(\
+\"Test tutorial\");\n";
+ out << "Just a bunch of text to make the script invalid\n";
+ out.flush();
+
+ EditorSupport editorSupport;
+
+ //Tutorial* must be registered in order to be used with QSignalSpy
+ qRegisterMetaType<Tutorial*>("Tutorial*");
+ QSignalSpy startedSpy(&editorSupport, SIGNAL(started(Tutorial*)));
+
+ editorSupport.testScriptedTutorial(temporaryFile.fileName());
+
+ QCOMPARE(startedSpy.count(), 0);
+}
+
+}
+
QTEST_MAIN(editorsupport::EditorSupportTest)
#include "EditorSupportTest.moc"
Modified: trunk/ktutorial/ktutorial-library/tests/view/TutorialManagerDialogTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/view/TutorialManagerDialogTest.cpp 2010-09-24 17:30:22 UTC (rev 252)
+++ trunk/ktutorial/ktutorial-library/tests/view/TutorialManagerDialogTest.cpp 2010-09-25 03:01:55 UTC (rev 253)
@@ -89,7 +89,7 @@
}
void emitFinished() {
- emit finished();
+ emit finished(this);
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|