[muon] libmuon/backends/ApplicationBackend/tests: Introduce a new test within the SourcesTest for APT

Aleix Pol aleixpol at kde.org
Wed Jan 14 04:05:21 UTC 2015


Git commit 88433b3fd9ad816f1ac05d6f5205cc03165eac84 by Aleix Pol.
Committed on 14/01/2015 at 04:04.
Pushed by apol into branch 'master'.

Introduce a new test within the SourcesTest for APT

Tries to ensure that the origins of the packages maps to one of the offered
sources.
Problem is, it doesn't work well, many packages provide an empty origin "".
CC'ing kubuntu-devel, hoping they will know how to fix this.

CCMAIL: kubuntu-devel at lists.ubuntu.com

M  +34   -5    libmuon/backends/ApplicationBackend/tests/SourcesTest.cpp
M  +4    -0    libmuon/backends/ApplicationBackend/tests/SourcesTest.h

http://commits.kde.org/muon/88433b3fd9ad816f1ac05d6f5205cc03165eac84

diff --git a/libmuon/backends/ApplicationBackend/tests/SourcesTest.cpp b/libmuon/backends/ApplicationBackend/tests/SourcesTest.cpp
index 5afa6c5..64d6f07 100644
--- a/libmuon/backends/ApplicationBackend/tests/SourcesTest.cpp
+++ b/libmuon/backends/ApplicationBackend/tests/SourcesTest.cpp
@@ -53,16 +53,23 @@ SourcesTest::SourcesTest(QObject* parent): QObject(parent)
     m->integrateMainWindow(m_window);
     m_appBackend = backendByName(m, "ApplicationBackend");
     QVERIFY(QSignalSpy(m, SIGNAL(allInitialized())).wait());
+    
+    SourcesModel* sources = SourcesModel::global();
+    QVERIFY(sources->rowCount() == 1);
+    QVERIFY(!backend()->name().isEmpty());
 }
 
-void SourcesTest::testSourcesFetch()
+AbstractSourcesBackend* SourcesTest::backend() const
 {
     SourcesModel* sources = SourcesModel::global();
-    QVERIFY(sources->rowCount() == 1);
     QObject* l = sources->data(sources->index(0), SourcesModel::SourceBackend).value<QObject*>();
-    AbstractSourcesBackend* backend = qobject_cast<AbstractSourcesBackend*>(l);
-    QVERIFY(!backend->name().isEmpty());
-    QAbstractItemModel* aptSources = backend->sources();
+    return qobject_cast<AbstractSourcesBackend*>(l);
+}
+
+
+void SourcesTest::testSourcesFetch()
+{
+    QAbstractItemModel* aptSources = backend()->sources();
     
     for(int i = 0, c=aptSources->rowCount(); i<c; ++i) {
         QVERIFY(aptSources);
@@ -70,3 +77,25 @@ void SourcesTest::testSourcesFetch()
         QVERIFY(idx.data(Qt::DisplayRole).toString() != QString());
     }
 }
+
+void SourcesTest::testResourcesMatchSources()
+{
+    QAbstractItemModel* aptSources = backend()->sources();
+    QSet<QString> allSources;
+    for (int i=0, c=aptSources->rowCount(); i<c; ++i) {
+        QModelIndex idx = aptSources->index(i, 0);
+        allSources += idx.data(Qt::DisplayRole).toString();
+    }
+    
+    ResourcesModel* rmodel = ResourcesModel::global();
+    for (int i=0, c=rmodel->rowCount(); i<c; ++i) {
+        QModelIndex idx = rmodel->index(i, 0);
+        QString origin = idx.data(ResourcesModel::OriginRole).toString();
+        bool found = allSources.contains(origin);
+        if (!found) {
+            qDebug() << "couldn't find" << origin << "for" << idx.data(ResourcesModel::NameRole).toString() << "@" << i << "/" << c << "in" << allSources;
+            QEXPECT_FAIL("", "I need to ask the Kubuntu guys, I don't understand", Continue);
+        }
+        QVERIFY(found);
+    }
+}
diff --git a/libmuon/backends/ApplicationBackend/tests/SourcesTest.h b/libmuon/backends/ApplicationBackend/tests/SourcesTest.h
index d8a808b..b5c4b5f 100644
--- a/libmuon/backends/ApplicationBackend/tests/SourcesTest.h
+++ b/libmuon/backends/ApplicationBackend/tests/SourcesTest.h
@@ -24,6 +24,7 @@
 #include <QtCore/QObject>
 
 class MuonMainWindow;
+class AbstractSourcesBackend;
 class AbstractResourcesBackend;
 
 class SourcesTest : public QObject
@@ -34,8 +35,11 @@ class SourcesTest : public QObject
 
     private slots:
         void testSourcesFetch();
+        void testResourcesMatchSources();
 
     private:
+        AbstractSourcesBackend* backend() const;
+
         AbstractResourcesBackend* m_appBackend;
         MuonMainWindow* m_window;
 



More information about the kubuntu-devel mailing list