1
/***************************************************************************
2
* Copyright © 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> *
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. *
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. *
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
***************************************************************************/
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>
30
QTEST_KDEMAIN_CORE( ReviewsTest )
32
ReviewsTest::ReviewsTest(QObject* parent): QObject(parent)
34
m_backend = new QApt::Backend;
35
if (m_backend->xapianIndexNeedsUpdate()) {
36
m_backend->updateXapianIndex();
39
if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
40
m_backend->setWorkerProxy(KProtocolManager::proxyFor("http"));
44
m_appBackend = new ApplicationBackend(this);
45
m_appBackend->setBackend(m_backend);
46
QTest::kWaitForSignal(m_appBackend, SIGNAL(appBackendReady()), 1000);
48
m_revBackend = new ReviewsBackend(this);
49
m_revBackend->setAptBackend(m_backend);
52
void ReviewsTest::testReviewsFetch()
54
if(m_revBackend->isFetching())
55
QTest::kWaitForSignal(m_revBackend, SIGNAL(ratingsReady()));
56
QVERIFY(!m_revBackend->isFetching());
59
void ReviewsTest::testReviewsModel_data()
61
QTest::addColumn<QString>( "application" );
62
QTest::newRow( "kate" ) << "kate";
63
QTest::newRow( "gedit" ) << "gedit";
66
void ReviewsTest::testReviewsModel()
68
QFETCH(QString, application);
69
ReviewsModel* model = new ReviewsModel(this);
70
new ModelTest(model, model);
71
model->setBackend(m_revBackend);
73
Application* app = m_appBackend->applicationByPackageName(application);
75
model->setApplication(app);
76
QTest::kWaitForSignal(model, SIGNAL(rowsInserted(QModelIndex, int, int)), 1000);
79
while(model->canFetchMore(root)) {
80
model->fetchMore(root);
81
QTest::kWaitForSignal(model, SIGNAL(rowsInserted(QModelIndex, int, int)), 1000);