File indexing completed on 2024-05-12 04:49:41

0001 /****************************************************************************************
0002  * Copyright (c) 2012 Jasneet Singh Bhatti <jazneetbhatti@gmail.com>                    *
0003  * This program is free software; you can redistribute it and/or modify it under        *
0004  * the terms of the GNU General Public License as published by the Free Software        *
0005  * Foundation; either version 2 of the License, or (at your option) any later           *
0006  * version.                                                                             *
0007  *                                                                                      *
0008  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0009  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0010  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0011  *                                                                                      *
0012  * You should have received a copy of the GNU General Public License along with         *
0013  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0014  ****************************************************************************************/
0015 
0016 #include "TestQueryMaker.h"
0017 
0018 #include "mocks/MockQueryMaker.h"
0019 
0020 #include <QSignalSpy>
0021 
0022 using namespace Collections;
0023 
0024 
0025 QTEST_GUILESS_MAIN( TestQueryMaker )
0026 
0027 void
0028 TestQueryMaker::initTestCase()
0029 {
0030     m_mockQueryMaker = new MockQueryMaker();
0031     QVERIFY( m_mockQueryMaker );
0032 }
0033 
0034 void
0035 TestQueryMaker::cleanupTestCase()
0036 {
0037     if( !m_mockQueryMaker.isNull() )
0038         delete m_mockQueryMaker;
0039 }
0040 
0041 void
0042 TestQueryMaker::testSetAutoDelete_data()
0043 {
0044     QTest::addColumn<bool>( "autoDelete" );
0045 
0046     QTest::newRow( "false value" ) << false;
0047     QTest::newRow( "true value" ) << true;
0048 }
0049 
0050 void
0051 TestQueryMaker::testSetAutoDelete()
0052 {
0053     QFETCH( bool, autoDelete );
0054 
0055     QSignalSpy spyQueryDone( m_mockQueryMaker, &MockQueryMaker::queryDone );
0056     QSignalSpy spyDestroyed( m_mockQueryMaker, &MockQueryMaker::destroyed );
0057 
0058     m_mockQueryMaker->setAutoDelete( autoDelete );
0059     QVERIFY( m_mockQueryMaker );
0060 
0061     m_mockQueryMaker->emitQueryDone();
0062 
0063     // Ensure that queryDone() was indeed emitted
0064     QCOMPARE( spyQueryDone.count(), 1 );
0065 
0066     spyDestroyed.wait( 5000 );
0067 
0068     if( autoDelete )
0069     {
0070         // Signal queryDone() is connected to slot deleteLater()
0071         // and the destroyed() signal is emitted
0072         QCOMPARE( spyDestroyed.count(), 1 );
0073     }
0074     else
0075     {
0076         // Signal queryDone() is disconnected from slot deleteLater()
0077         // and no destroyed() signal is emitted
0078         QCOMPARE( spyDestroyed.count(), 0 );
0079     }
0080 }