~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to discover/tests/ReviewsTest.cpp

Tags: upstream-1.3.65
Import upstream version 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright © 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>       *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or         *
 
5
 *   modify it under the terms of the GNU General Public License as        *
 
6
 *   published by the Free Software Foundation; either version 2 of        *
 
7
 *   the License or (at your option) version 3 or any later version        *
 
8
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 
9
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 
10
 *   defined in Section 14 of version 3 of the license.                    *
 
11
 *                                                                         *
 
12
 *   This program is distributed in the hope that it will be useful,       *
 
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
15
 *   GNU General Public License for more details.                          *
 
16
 *                                                                         *
 
17
 *   You should have received a copy of the GNU General Public License     *
 
18
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "ReviewsTest.h"
 
22
#include <../ReviewsModel.h>
 
23
#include <ReviewsBackend/ReviewsBackend.h>
 
24
#include <ApplicationBackend.h>
 
25
#include <libqapt/backend.h>
 
26
#include <KProtocolManager>
 
27
#include <qtest_kde.h>
 
28
#include <libmuon/tests/modeltest.h>
 
29
 
 
30
QTEST_KDEMAIN_CORE( ReviewsTest )
 
31
 
 
32
ReviewsTest::ReviewsTest(QObject* parent): QObject(parent)
 
33
{
 
34
    m_backend = new QApt::Backend;
 
35
    if (m_backend->xapianIndexNeedsUpdate()) {
 
36
        m_backend->updateXapianIndex();
 
37
    }
 
38
 
 
39
    if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
 
40
        m_backend->setWorkerProxy(KProtocolManager::proxyFor("http"));
 
41
    }
 
42
    m_backend->init();
 
43
    
 
44
    m_appBackend = new ApplicationBackend(this);
 
45
    m_appBackend->setBackend(m_backend);
 
46
    QTest::kWaitForSignal(m_appBackend, SIGNAL(appBackendReady()), 1000);
 
47
    
 
48
    m_revBackend = new ReviewsBackend(this);
 
49
    m_revBackend->setAptBackend(m_backend);
 
50
}
 
51
 
 
52
void ReviewsTest::testReviewsFetch()
 
53
{
 
54
    if(m_revBackend->isFetching())
 
55
        QTest::kWaitForSignal(m_revBackend, SIGNAL(ratingsReady()));
 
56
    QVERIFY(!m_revBackend->isFetching());
 
57
}
 
58
 
 
59
void ReviewsTest::testReviewsModel_data()
 
60
{
 
61
    QTest::addColumn<QString>( "application" );
 
62
    QTest::newRow( "kate" ) << "kate";
 
63
    QTest::newRow( "gedit" ) << "gedit";
 
64
}
 
65
 
 
66
void ReviewsTest::testReviewsModel()
 
67
{
 
68
    QFETCH(QString, application);
 
69
    ReviewsModel* model = new ReviewsModel(this);
 
70
    new ModelTest(model, model);
 
71
    model->setBackend(m_revBackend);
 
72
    
 
73
    Application* app = m_appBackend->applicationByPackageName(application);
 
74
    QVERIFY(app);
 
75
    model->setApplication(app);
 
76
    QTest::kWaitForSignal(model, SIGNAL(rowsInserted(QModelIndex, int, int)), 1000);
 
77
    
 
78
    QModelIndex root;
 
79
    while(model->canFetchMore(root)) {
 
80
        model->fetchMore(root);
 
81
        QTest::kWaitForSignal(model, SIGNAL(rowsInserted(QModelIndex, int, int)), 1000);
 
82
    }
 
83
    
 
84
    delete model;
 
85
}