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

« back to all changes in this revision

Viewing changes to libmuon/tests/ApplicationModelTest.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 "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>
 
29
 
 
30
#include "modeltest.h"
 
31
#include <Application.h>
 
32
 
 
33
QTEST_KDEMAIN_CORE( ApplicationModelTest )
 
34
 
 
35
ApplicationModelTest::ApplicationModelTest()
 
36
{
 
37
    m_backend = new QApt::Backend;
 
38
 
 
39
    if (KProtocolManager::proxyType() == KProtocolManager::ManualProxy) {
 
40
        m_backend->setWorkerProxy(KProtocolManager::proxyFor("http"));
 
41
    }
 
42
    m_backend->init();
 
43
    if (m_backend->xapianIndexNeedsUpdate()) {
 
44
        m_backend->updateXapianIndex();
 
45
    }
 
46
    
 
47
    m_appBackend = new ApplicationBackend(this);
 
48
    m_appBackend->setBackend(m_backend);
 
49
    QTest::kWaitForSignal(m_appBackend, SIGNAL(appBackendReady()));
 
50
}
 
51
 
 
52
ApplicationModelTest::~ApplicationModelTest()
 
53
{
 
54
    delete m_appBackend;
 
55
    delete m_backend;
 
56
}
 
57
 
 
58
void ApplicationModelTest::testReload()
 
59
{
 
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);
 
68
    
 
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());
 
76
    }
 
77
    
 
78
    m_appBackend->reload();
 
79
    m_appBackend->updatesCount();
 
80
    QCOMPARE(apps, m_appBackend->applicationList() );
 
81
    
 
82
    QVERIFY(!apps.isEmpty());
 
83
    QCOMPARE(apps.count(), model->rowCount());
 
84
    
 
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();
 
92
    }
 
93
}
 
94
 
 
95
void ApplicationModelTest::testSearch()
 
96
{
 
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);
 
104
    
 
105
    updatesProxy->search("kal");
 
106
    int oldCount = updatesProxy->rowCount();
 
107
    updatesProxy->search("kalgebra");
 
108
    QVERIFY(oldCount>updatesProxy->rowCount());
 
109
}