summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-10-01 22:52:19 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-10-06 16:14:32 +0200
commit03caa03fd5f6389499eec8f7e6afdb20b1c08cda (patch)
treeed88b0dda9395a0647b88a9d619abafbde5c688f /tests
parentf288f29e92102f7779101a59515f86bce64a3713 (diff)
Add a test for graph resolving.
Change-Id: I96f7077cdb9816b009d44b3daf2d985d151121fb Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com> Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/installer/solver/solver.pro1
-rw-r--r--tests/auto/installer/solver/tst_solver.cpp66
2 files changed, 66 insertions, 1 deletions
diff --git a/tests/auto/installer/solver/solver.pro b/tests/auto/installer/solver/solver.pro
index 0094bc090..76e30fa0c 100644
--- a/tests/auto/installer/solver/solver.pro
+++ b/tests/auto/installer/solver/solver.pro
@@ -1,5 +1,6 @@
include(../../qttest.pri)
QT -= gui
+QT += qml
SOURCES += tst_solver.cpp
diff --git a/tests/auto/installer/solver/tst_solver.cpp b/tests/auto/installer/solver/tst_solver.cpp
index 0621b1bb6..7730bbb5c 100644
--- a/tests/auto/installer/solver/tst_solver.cpp
+++ b/tests/auto/installer/solver/tst_solver.cpp
@@ -39,7 +39,10 @@
**
**************************************************************************/
-#include "graph.h"
+#include <component.h>
+#include <graph.h>
+#include <installercalculator.h>
+#include <packagemanagercore.h>
#include <QTest>
@@ -63,6 +66,21 @@ inline uint qHash(const Data &data)
return qHash(data.data());
}
+class NamedComponent : public Component
+{
+public:
+ NamedComponent(PackageManagerCore *core, const QString &name)
+ : NamedComponent(core, name, QLatin1String("1.0.0"))
+ {}
+
+ NamedComponent(PackageManagerCore *core, const QString &name, const QString &version)
+ : Component(core)
+ {
+ setValue(scName, name);
+ setValue(scVersion, version);
+ }
+
+};
class tst_Solver : public QObject
{
@@ -127,6 +145,52 @@ private slots:
qDebug("(%s) has a indirect dependency on (%s).", qPrintable(cycle.second.data()),
qPrintable(cycle.first.data()));
}
+
+ void resolve_data()
+ {
+ QTest::addColumn<PackageManagerCore *>("core");
+ QTest::addColumn<QList<Component *> >("selectedComponents");
+ QTest::addColumn<QList<Component *> >("expectedResult");
+ QTest::addColumn<QList<int> >("installReason");
+
+ PackageManagerCore *core = new PackageManagerCore();
+ core->setPackageManager();
+ NamedComponent *componentA = new NamedComponent(core, QLatin1String("A"));
+ NamedComponent *componentAA = new NamedComponent(core, QLatin1String("A.A"));
+ NamedComponent *componentAB = new NamedComponent(core, QLatin1String("A.B"));
+ componentA->appendComponent(componentAA);
+ componentA->appendComponent(componentAB);
+ NamedComponent *componentB = new NamedComponent(core, QLatin1String("B"));
+ componentB->addDependency(QLatin1String("A.B"));
+ core->appendRootComponent(componentA);
+ core->appendRootComponent(componentB);
+
+ QTest::newRow("Simple resolved") << core
+ << (QList<Component *>() << componentB)
+ << (QList<Component *>() << componentAB << componentB)
+ << (QList<int>()
+ << InstallerCalculator::Dependent
+ << InstallerCalculator::Resolved);
+ }
+
+ void resolve()
+ {
+ QFETCH(PackageManagerCore *, core);
+ QFETCH(QList<Component *> , selectedComponents);
+ QFETCH(QList<Component *> , expectedResult);
+ QFETCH(QList<int>, installReason);
+
+ InstallerCalculator calc(core->components(PackageManagerCore::ComponentType::AllNoReplacements));
+ calc.appendComponentsToInstall(selectedComponents);
+ QList<Component *> result = calc.orderedComponentsToInstall();
+
+ QCOMPARE(result.count(), expectedResult.count());
+ for (int i = 0; i < result.count(); i++) {
+ QCOMPARE(result.at(i), expectedResult.at(i));
+ QCOMPARE((int)calc.installReasonType(result.at(i)), installReason.at(i));
+ }
+ delete core;
+ }
};
QTEST_MAIN(tst_Solver)