[Ktutorial-commits] SF.net SVN: ktutorial:[267] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-09-30 15:38:30
|
Revision: 267
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=267&view=rev
Author: danxuliu
Date: 2010-09-30 15:38:20 +0000 (Thu, 30 Sep 2010)
Log Message:
-----------
Fix waiting for a signal emitted by a null object. It didn't crash before, but now it doesn't even try to connect the signal and warns when this happens, like WaitForEvent does.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-library/src/WaitForSignal.cpp
trunk/ktutorial/ktutorial-library/tests/WaitForSignalTest.cpp
Modified: trunk/ktutorial/ktutorial-library/src/WaitForSignal.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/WaitForSignal.cpp 2010-09-30 15:35:32 UTC (rev 266)
+++ trunk/ktutorial/ktutorial-library/src/WaitForSignal.cpp 2010-09-30 15:38:20 UTC (rev 267)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008 by Daniel Calviño Sánchez *
+ * Copyright (C) 2008-2010 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -18,6 +18,8 @@
#include "WaitForSignal.h"
+#include <KDebug>
+
//public:
WaitForSignal::WaitForSignal(): WaitFor(),
@@ -30,6 +32,11 @@
}
void WaitForSignal::setSignal(QObject* sender, const QString& signal) {
+ if (!sender) {
+ kWarning() << "The object that emits the signal to wait for is null!";
+ return;
+ }
+
QString signalName = signal;
if (!signalName.startsWith('2')) {
signalName = QString("2%1").arg(signal);
Modified: trunk/ktutorial/ktutorial-library/tests/WaitForSignalTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/WaitForSignalTest.cpp 2010-09-30 15:35:32 UTC (rev 266)
+++ trunk/ktutorial/ktutorial-library/tests/WaitForSignalTest.cpp 2010-09-30 15:38:20 UTC (rev 267)
@@ -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,8 +51,10 @@
void testConstructor();
void testConstructorWithoutSignalMacro();
+ void testConstructorWithNullObject();
void testConstructorDefault();
void testConstructorDefaultWithoutSignalMacro();
+ void testConstructorDefaultWithNullObject();
void testSetActive();
@@ -77,6 +79,13 @@
QCOMPARE(mDummySignalConnectionCount, 1);
}
+void WaitForSignalTest::testConstructorWithNullObject() {
+ WaitForSignal waitForSignal(0, SIGNAL(dummySignal()));
+
+ QVERIFY(!waitForSignal.isActive());
+ QVERIFY(!waitForSignal.conditionMet());
+}
+
void WaitForSignalTest::testConstructorDefault() {
WaitForSignal waitForSignal;
waitForSignal.setSignal(this, SIGNAL(dummySignal()));
@@ -95,6 +104,14 @@
QCOMPARE(mDummySignalConnectionCount, 1);
}
+void WaitForSignalTest::testConstructorDefaultWithNullObject() {
+ WaitForSignal waitForSignal;
+ waitForSignal.setSignal(0, SIGNAL(dummySignal()));
+
+ QVERIFY(!waitForSignal.isActive());
+ QVERIFY(!waitForSignal.conditionMet());
+}
+
void WaitForSignalTest::testSetActive() {
WaitForSignal waitForSignal(this, SIGNAL(dummySignal()));
waitForSignal.mConditionMet = true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|