From 6d447410b4c2f63d77331b9459679dcdb8424d07 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Mon, 24 Nov 2014 10:29:36 -0800 Subject: [PATCH] Fix UAS unit test Destroyed signal must have been working incorrectly in the past. --- src/qgcunittest/UASUnitTest.cc | 3 +-- src/uas/UAS.cc | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/qgcunittest/UASUnitTest.cc b/src/qgcunittest/UASUnitTest.cc index 7167579..650f97b 100644 --- a/src/qgcunittest/UASUnitTest.cc +++ b/src/qgcunittest/UASUnitTest.cc @@ -301,7 +301,6 @@ void UASUnitTest::signalWayPoint_test() void UASUnitTest::signalUASLink_test() { - QSignalSpy spy(uas, SIGNAL(modeChanged(int,QString,QString))); uas->setMode(2, 0); QCOMPARE(spy.count(), 0);// not solve for UAS not receiving message from UAS @@ -347,7 +346,7 @@ void UASUnitTest::signalUASLink_test() delete link2; QCOMPARE(LinkManager::instance()->getLinks().count(), 1); - QCOMPARE(uas->getLinks()->count(), 2); + QCOMPARE(uas->getLinks()->count(), 1); QCOMPARE(static_cast(LinkManager::instance()->getLinks().at(0))->getId(), static_cast(uas->getLinks()->at(0))->getId()); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index bbbcc3e..aca75e9 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -3375,8 +3375,13 @@ void UAS::addLink(LinkInterface* link) void UAS::removeLink(QObject* object) { // Be careful of the fact that by the time this signal makes it through the queue - // the link object has already been destructed. - links->removeAt(links->indexOf((LinkInterface*)object)); + // the link object has already been destructed. So no dynamic_cast for example. + + LinkInterface* link = (LinkInterface*)object; + + int index = links->indexOf(link); + Q_ASSERT(index != -1); + links->removeAt(index); } /**