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 "ApplicationModelTest.h"
22
#include <ApplicationModel/ApplicationModel.h>
23
#include <ApplicationModel/ApplicationProxyModel.h>
24
#include <ApplicationBackend.h>
25
#include <QStringList>
26
#include <LibQApt/Backend>
27
#include <KProtocolManager>
28
#include <qtest_kde.h>
30
#include "modeltest.h"
31
#include <Application.h>
33
QTEST_KDEMAIN_CORE( ApplicationModelTest )
35
ApplicationModelTest::ApplicationModelTest()
37
m_backend = new QApt::Backend;
39
if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
40
m_backend->setWorkerProxy(KProtocolManager::proxyFor("http"));
43
if (m_backend->xapianIndexNeedsUpdate()) {
44
m_backend->updateXapianIndex();
47
m_appBackend = new ApplicationBackend(this);
48
m_appBackend->setBackend(m_backend);
49
QTest::kWaitForSignal(m_appBackend, SIGNAL(appBackendReady()));
52
ApplicationModelTest::~ApplicationModelTest()
58
void ApplicationModelTest::testReload()
60
ApplicationModel* model = new ApplicationModel(this);
61
ApplicationProxyModel* updatesProxy = new ApplicationProxyModel(this);
62
updatesProxy->setBackend(m_backend);
63
updatesProxy->setSourceModel(model);
64
new ModelTest(model, model);
65
new ModelTest(updatesProxy, updatesProxy);
66
model->setBackend(m_appBackend);
67
updatesProxy->setStateFilter(QApt::Package::ToUpgrade);
69
QVector<Application*> apps = m_appBackend->applicationList();
70
QVector<QString> appNames(apps.size());
71
for(int i=0; i<model->rowCount(); ++i) {
72
Application* app = apps[i];
73
QCOMPARE(model->data(model->index(i), ApplicationModel::NameRole).toString(), app->name());
74
appNames[i]=app->packageName();
75
QVERIFY(app->isValid());
78
m_appBackend->reload();
79
m_appBackend->updatesCount();
80
QCOMPARE(apps, m_appBackend->applicationList() );
82
QVERIFY(!apps.isEmpty());
83
QCOMPARE(apps.count(), model->rowCount());
85
for(int i=0; i<model->rowCount(); ++i) {
86
Application* app = apps[i];
87
// qDebug() << "a" << appNames[i];
88
// if(!app->package()) qDebug() << "laaaaaa" << app->packageName();
89
QCOMPARE(appNames[i], app->packageName());
90
QCOMPARE(model->data(model->index(i), ApplicationModel::NameRole).toString(), app->name());
91
// if(appNames[i]!=app->name()) qDebug() << "ffffffff" << app->packageName() << appNames[i] << app->name() << app->isTechnical();
95
void ApplicationModelTest::testSearch()
97
ApplicationModel* model = new ApplicationModel(this);
98
ApplicationProxyModel* updatesProxy = new ApplicationProxyModel(this);
99
updatesProxy->setBackend(m_backend);
100
updatesProxy->setSourceModel(model);
101
new ModelTest(model, model);
102
new ModelTest(updatesProxy, updatesProxy);
103
model->setBackend(m_appBackend);
105
updatesProxy->search("kal");
106
int oldCount = updatesProxy->rowCount();
107
updatesProxy->search("kalgebra");
108
QVERIFY(oldCount>updatesProxy->rowCount());