[Ktutorial-commits] SF.net SVN: ktutorial:[266] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-09-30 15:35:41
|
Revision: 266
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=266&view=rev
Author: danxuliu
Date: 2010-09-30 15:35:32 +0000 (Thu, 30 Sep 2010)
Log Message:
-----------
Fix crash when waiting for an event received by a null object.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp
trunk/ktutorial/ktutorial-library/tests/WaitForEventTest.cpp
Modified: trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp 2010-09-28 21:32:13 UTC (rev 265)
+++ trunk/ktutorial/ktutorial-library/src/WaitForEvent.cpp 2010-09-30 15:35:32 UTC (rev 266)
@@ -35,10 +35,20 @@
mEventType(type),
mConditionMet(false) {
+ if (!object) {
+ kWarning() << "The object that receives the event to wait for is null!";
+ return;
+ }
+
object->installEventFilter(this);
}
void WaitForEvent::setEvent(QObject* object, const QString& typeName) {
+ if (!object) {
+ kWarning() << "The object that receives the event to wait for is null!";
+ return;
+ }
+
int index = QEvent::staticMetaObject.indexOfEnumerator("Type");
QMetaEnum eventTypeEnumerator = QEvent::staticMetaObject.enumerator(index);
Modified: trunk/ktutorial/ktutorial-library/tests/WaitForEventTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/WaitForEventTest.cpp 2010-09-28 21:32:13 UTC (rev 265)
+++ trunk/ktutorial/ktutorial-library/tests/WaitForEventTest.cpp 2010-09-30 15:35:32 UTC (rev 266)
@@ -29,7 +29,9 @@
private slots:
void testConstructor();
+ void testConstructorWithNullObject();
void testConstructorDefault();
+ void testConstructorDefaultWithNullObject();
void testSetActive();
@@ -74,6 +76,13 @@
QVERIFY(!waitForEvent.conditionMet());
}
+void WaitForEventTest::testConstructorWithNullObject() {
+ WaitForEvent waitForEvent(0, QEvent::ChildAdded);
+
+ QVERIFY(!waitForEvent.isActive());
+ QVERIFY(!waitForEvent.conditionMet());
+}
+
void WaitForEventTest::testConstructorDefault() {
WaitForEvent waitForEvent;
waitForEvent.setEvent(this, "ChildAdded");
@@ -82,6 +91,14 @@
QVERIFY(!waitForEvent.conditionMet());
}
+void WaitForEventTest::testConstructorDefaultWithNullObject() {
+ WaitForEvent waitForEvent;
+ waitForEvent.setEvent(0, "ChildAdded");
+
+ QVERIFY(!waitForEvent.isActive());
+ QVERIFY(!waitForEvent.conditionMet());
+}
+
void WaitForEventTest::testSetActive() {
WaitForEvent waitForEvent(this, QEvent::ChildAdded);
waitForEvent.mConditionMet = true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|