[Ktutorial-commits] SF.net SVN: ktutorial:[250] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-09-20 19:30:27
|
Revision: 250
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=250&view=rev
Author: danxuliu
Date: 2010-09-20 19:30:21 +0000 (Mon, 20 Sep 2010)
Log Message:
-----------
Fix crash when an application not supporting KTutorial was closed before TargetApplication realized that the application did not support KTutorial.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp
trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h
trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp 2010-09-19 16:40:33 UTC (rev 249)
+++ trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.cpp 2010-09-20 19:30:21 UTC (rev 250)
@@ -162,6 +162,12 @@
}
void TargetApplication::handleTargetApplicationDoesNotSupportKTutorial() {
+ //The target application not using KTutorial may have been closed by the
+ //user before the timeout expired and this slot was called
+ if (!mProcess) {
+ return;
+ }
+
mProcess->kill();
emit startFailed(InvalidApplication);
Modified: trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h 2010-09-19 16:40:33 UTC (rev 249)
+++ trunk/ktutorial/ktutorial-editor/src/targetapplication/TargetApplication.h 2010-09-20 19:30:21 UTC (rev 250)
@@ -46,6 +46,10 @@
* other problem happened (for example, if the target application does not
* support KTutorial), startFailed(Error) signal is emitted instead.
*
+ * Note that started() and startFailed(Error) signals may not be emitted if the
+ * target application is closed too soon to realize that it was successfully
+ * started or that it does not support KTutorial.
+ *
* Once the target application has been started, remoteEditorSupport
* returns a RemoteEditorSupport connected to the remote
* "org.kde.ktutorial.EditorSupport" interface exposed by the target
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp 2010-09-19 16:40:33 UTC (rev 249)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/targetapplication/TargetApplicationTest.cpp 2010-09-20 19:30:21 UTC (rev 250)
@@ -68,6 +68,8 @@
void testStartApplicationNotUsingKTutorial();
void testApplicationStopped();
+ void testApplicationStoppedBeforeBeingSuccessfullyStarted();
+ void testApplicationNotUsingKTutorialStoppedBeforeCheckTimeout();
private:
@@ -383,6 +385,71 @@
QVERIFY(!targetApplication.remoteEditorSupport());
}
+void TargetApplicationTest::
+ testApplicationStoppedBeforeBeingSuccessfullyStarted() {
+ TargetApplication targetApplication;
+ targetApplication.setTargetApplicationFilePath(mTargetApplicationStubPath);
+
+ QSignalSpy startedSpy(&targetApplication, SIGNAL(started()));
+ //TargetApplication::Error must be registered in order to be used with
+ //QSignalSpy
+ qRegisterMetaType<TargetApplication::Error>("TargetApplication::Error");
+ QSignalSpy startFailedSpy(&targetApplication,
+ SIGNAL(startFailed(TargetApplication::Error)));
+ SignalWait finishedWait(&targetApplication, SIGNAL(finished()));
+
+ targetApplication.start();
+
+ //Give the application some time to start before killing it, but not enough
+ //time to start successfully
+ QTest::qWait(5);
+
+ targetApplication.mProcess->kill();
+
+ QVERIFY(finishedWait.waitForCount(1, 1000));
+ QVERIFY(!targetApplication.remoteEditorSupport());
+
+ //Keep waiting until the timeout expires to ensure that no other signal is
+ //emitted or the process is tried to be killed again
+ QTest::qWait(3000);
+
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(startFailedSpy.count(), 0);
+}
+
+void TargetApplicationTest::
+ testApplicationNotUsingKTutorialStoppedBeforeCheckTimeout() {
+ TargetApplication targetApplication;
+ targetApplication.setTargetApplicationFilePath(
+ QApplication::applicationDirPath() + "/DummyApplication");
+
+ QSignalSpy startedSpy(&targetApplication, SIGNAL(started()));
+ //TargetApplication::Error must be registered in order to be used with
+ //QSignalSpy
+ qRegisterMetaType<TargetApplication::Error>("TargetApplication::Error");
+ QSignalSpy startFailedSpy(&targetApplication,
+ SIGNAL(startFailed(TargetApplication::Error)));
+ SignalWait finishedWait(&targetApplication, SIGNAL(finished()));
+
+ targetApplication.start();
+
+ //Give the application some time to start before killing it, but not enough
+ //time to realize that it does not use KTutorial
+ QTest::qWait(1000);
+
+ targetApplication.mProcess->kill();
+
+ QVERIFY(finishedWait.waitForCount(1, 1000));
+ QVERIFY(!targetApplication.remoteEditorSupport());
+
+ //Keep waiting until the timeout expires to ensure that no other signal is
+ //emitted or the process is tried to be killed again
+ QTest::qWait(3000);
+
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(startFailedSpy.count(), 0);
+}
+
QTEST_MAIN(TargetApplicationTest)
#include "TargetApplicationTest.moc"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|