[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [cantor] src/lib/test: use QSignalSpy to detect if a signal was emited in the unit tests.
From:       Alexander Rieder <alexanderrieder () gmail ! com>
Date:       2014-02-06 21:38:53
Message-ID: E1WBWer-0000IE-FV () scm ! kde ! org
[Download RAW message or body]

Git commit ab7c8302fe7c20e9b7956a4c886d706f14033ffe by Alexander Rieder.
Committed on 06/02/2014 at 21:36.
Pushed by arieder into branch 'master'.

use QSignalSpy to detect if a signal was emited in the unit tests.

this way we won't miss signals when they are emitted immediately, i.e. before we
create the temporary event loop.

patch by Tuukka Verho, thanks!

BUG: 330665

M  +8    -12   src/lib/test/backendtest.cpp

http://commits.kde.org/cantor/ab7c8302fe7c20e9b7956a4c886d706f14033ffe

diff --git a/src/lib/test/backendtest.cpp b/src/lib/test/backendtest.cpp
index 3492958..052de50 100644
--- a/src/lib/test/backendtest.cpp
+++ b/src/lib/test/backendtest.cpp
@@ -23,6 +23,8 @@
 #include "backend.h"
 #include "session.h"
 
+#include <QSignalSpy>
+
 void BackendTest::createSession()
 {
     Cantor::Backend* b=Cantor::Backend::createBackend( backendName() );
@@ -33,11 +35,13 @@ void BackendTest::createSession()
     }
 
     m_session=b->createSession();
+
+    QSignalSpy spy(m_session, SIGNAL( ready() ) );
     m_session->login();
+    if(spy.isEmpty())
+        waitForSignal(m_session, SIGNAL( ready() ) );
 
-    QEventLoop loop;
-    connect( m_session, SIGNAL( ready() ), &loop, SLOT( quit() ) );
-    loop.exec();
+    QVERIFY(!spy.isEmpty());
 }
 
 Cantor::Expression* BackendTest::evalExp(const QString& exp )
@@ -46,15 +50,7 @@ Cantor::Expression* BackendTest::evalExp(const QString& exp )
 
    if(e->status()==Cantor::Expression::Computing)
    {
-       //Create a timeout, that kills the eventloop, if the expression doesn't finish
-       QTimer timeout( this );
-       timeout.setSingleShot( true );
-       timeout.start( 5000 );
-       QEventLoop loop;
-       connect( &timeout, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
-       connect( e, SIGNAL( statusChanged( Cantor::Expression::Status ) ), &loop, SLOT( quit() ) );
-
-       loop.exec();
+       waitForSignal( e, SIGNAL( statusChanged( Cantor::Expression::Status ) ) );
    }
    return e;
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic