Hello everybody,
I writing my first Unit test application but there are problems when using Signals and slots.
slots never been called. and also is it possible to test a class inherits QThread.
Here are my code sample
Qt Code:
  1. TestSearchEngine::TestSearchEngine()
  2. {
  3. m_pSearchEngine = new SearchEngine();
  4. connect(m_pSearchEngine, SIGNAL(resultsDetected(int)), this, SLOT(onSearchResultDetected(int)));
  5.  
  6. }
  7.  
  8. void TestSearchEngine::testSearch()
  9. {
  10. QStringList searchWords;
  11. searchWords <<tr("sampleword");
  12. QList<int> booksId;
  13. booksId << 11430;
  14. QBENCHMARK{
  15. m_pSearchEngine->search(searchWords, booksId);}
  16. }
  17.  
  18. void TestSearchEngine::onSearchResultDetected(int count)
  19. {
  20. QCOMPARE(count, 3075 );
  21. testSearchResult(1);
  22.  
  23. }
  24.  
  25. void TestSearchEngine::testSearchResult(int index)
  26. {
  27. QBENCHMARK{
  28. m_pSearchEngine->searchResult(index);}
  29. }
To copy to clipboard, switch view to plain text mode 
Note that m_pSearchEngine is an object of a class inherits QThread and it starts the thread when calling search function.
Thank you