Skip to content

Commit 726f548

Browse files
committed
improved test automation
1 parent bb77584 commit 726f548

File tree

15 files changed

+189
-47
lines changed

15 files changed

+189
-47
lines changed
-8.45 MB
Binary file not shown.

tests/TestInstaller/TestInstaller.pro

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/TestInstaller/build_mac.command

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/TestInstaller/build_win.bat

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/TestInstaller/build_x11.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/TestInstaller/packages/de.skycoder42.QtAutoUpdaterTestInstaller/data/version.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/auto/autoupdatercore/UpdaterTest/UpdaterTest.pro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ CONFIG -= app_bundle
1515

1616
TEMPLATE = app
1717

18-
SOURCES += tst_updatertest.cpp
18+
SOURCES += tst_updatertest.cpp \
19+
installercontroller.cpp
1920
DEFINES += SRCDIR=\\\"$$PWD/\\\"
21+
DEFINES += BINDIR=\\\"$$[QT_INSTALL_BINS]/../../../Tools/QtInstallerFramework/2.0/bin/\\\"
22+
23+
HEADERS += \
24+
installercontroller.h
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "installercontroller.h"
2+
3+
#include <QProcess>
4+
#include <QtTest>
5+
6+
static const QString configFile = SRCDIR + QStringLiteral("../../../installer/config/config.xml");
7+
static const QString configScript = SRCDIR + QStringLiteral("../../../installer/config/controller.qs");
8+
static const QString pkgFile = SRCDIR + QStringLiteral("../../../installer/packages/de.skycoder42.QtAutoUpdaterTestInstaller/meta/package.xml");
9+
static const QString binarycreator = BINDIR + QStringLiteral("binarycreator");
10+
static const QString repogen = BINDIR + QStringLiteral("repogen");
11+
12+
InstallerController::InstallerController(QObject *parent) :
13+
QObject(parent),
14+
_version(1, 0, 0),
15+
_buildDir()
16+
{
17+
setVersion(_version);
18+
}
19+
20+
void InstallerController::createRepository()
21+
{
22+
auto res = QProcess::execute(repogen, {"--update-new-components", "-p", _buildDir.path() + "/packages", _buildDir.path() + "/repository"});
23+
QCOMPARE(res, 0);
24+
}
25+
26+
void InstallerController::createInstaller()
27+
{
28+
QFile configSrc(configFile);
29+
QFile configOut(_buildDir.path() + "/config.xml");
30+
31+
QVERIFY(configSrc.open(QIODevice::ReadOnly | QIODevice::Text));
32+
QVERIFY(configOut.open(QIODevice::WriteOnly | QIODevice::Text));
33+
auto src = QString::fromUtf8(configSrc.readAll());
34+
configOut.write(src
35+
.arg(_buildDir.path() + "/install")
36+
.arg(_buildDir.path())
37+
.toUtf8());
38+
configSrc.close();
39+
configOut.close();
40+
41+
auto res = QProcess::execute(binarycreator, {"-n", "-c", configOut.fileName(), "-p", _buildDir.path() + "/packages", _buildDir.path() + "/QtAutoUpdaterTestInstaller"});
42+
QCOMPARE(res, 0);
43+
}
44+
45+
void InstallerController::installLocal()
46+
{
47+
auto res = QProcess::execute(_buildDir.path() + "/QtAutoUpdaterTestInstaller", {"-platform", "minimal", "--script", configScript});
48+
QCOMPARE(res, 0);
49+
}
50+
51+
void InstallerController::runUpdater()
52+
{
53+
54+
}
55+
56+
QVersionNumber InstallerController::version() const
57+
{
58+
return _version;
59+
}
60+
61+
QString InstallerController::maintenanceToolPath() const
62+
{
63+
return _buildDir.path() + "/install";
64+
}
65+
66+
void InstallerController::setVersion(QVersionNumber version)
67+
{
68+
_version = version;
69+
70+
QDir tDir(_buildDir.path());
71+
QVERIFY(tDir.mkpath("packages/de.skycoder42.QtAutoUpdaterTestInstaller/meta"));
72+
QVERIFY(tDir.mkpath("packages/de.skycoder42.QtAutoUpdaterTestInstaller/data"));
73+
74+
QFile pkgSrc(pkgFile);
75+
QFile pkgOut(_buildDir.path() + "/packages/de.skycoder42.QtAutoUpdaterTestInstaller/meta/package.xml");
76+
77+
QVERIFY(pkgSrc.open(QIODevice::ReadOnly | QIODevice::Text));
78+
QVERIFY(pkgOut.open(QIODevice::WriteOnly | QIODevice::Text));
79+
auto src = QString::fromUtf8(pkgSrc.readAll());
80+
pkgOut.write(src.arg(_version.toString()).toUtf8());
81+
pkgSrc.close();
82+
pkgOut.close();
83+
84+
QFile dataFile(_buildDir.path() + "/packages/de.skycoder42.QtAutoUpdaterTestInstaller/data/version.txt");
85+
QVERIFY(dataFile.open(QIODevice::WriteOnly | QIODevice::Text));
86+
dataFile.write(_version.toString().toUtf8());
87+
dataFile.close();
88+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef INSTALLERCONTROLLER_H
2+
#define INSTALLERCONTROLLER_H
3+
4+
#include <QObject>
5+
#include <QVersionNumber>
6+
#include <QTemporaryDir>
7+
8+
class InstallerController : public QObject
9+
{
10+
Q_OBJECT
11+
12+
Q_PROPERTY(QVersionNumber version READ version WRITE setVersion)
13+
14+
public:
15+
explicit InstallerController(QObject *parent = nullptr);
16+
17+
void createRepository();
18+
void createInstaller();
19+
void installLocal();
20+
void runUpdater();
21+
22+
QVersionNumber version() const;
23+
QString maintenanceToolPath() const;
24+
25+
public slots:
26+
void setVersion(QVersionNumber version);
27+
28+
private:
29+
QVersionNumber _version;
30+
QTemporaryDir _buildDir;
31+
};
32+
33+
#endif // INSTALLERCONTROLLER_H

tests/auto/autoupdatercore/UpdaterTest/tst_updatertest.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QSignalSpy>
44
#include <QVector>
55
#include <functional>
6+
#include "installercontroller.h"
67
using namespace QtAutoUpdater;
78

89
#define TEST_DELAY 1000
@@ -22,18 +23,31 @@ class UpdaterTest : public QObject
2223
Q_OBJECT
2324

2425
private Q_SLOTS:
26+
void initTestCase();
2527
void testUpdaterInitState();
2628

2729
void testUpdateCheck_data();
2830
void testUpdateCheck();
2931

3032
private:
3133
Updater *updater;
34+
35+
InstallerController *controller;
3236
QSignalSpy *checkSpy;
3337
QSignalSpy *runningSpy;
3438
QSignalSpy *updateInfoSpy;
3539
};
3640

41+
void UpdaterTest::initTestCase()
42+
{
43+
controller = new InstallerController(this);
44+
controller->createRepository();
45+
controller->createInstaller();
46+
controller->installLocal();
47+
controller->setVersion({1, 1, 0});
48+
controller->createRepository();
49+
}
50+
3751
void UpdaterTest::testUpdaterInitState()
3852
{
3953
updater = new Updater(this);
@@ -64,9 +78,8 @@ void UpdaterTest::testUpdateCheck_data()
6478
QTest::addColumn<QList<Updater::UpdateInfo>>("updates");
6579

6680
QList<Updater::UpdateInfo> updates;
67-
updates += {"QtAutoUpdaterTestInstaller", QVersionNumber::fromString("1.0.1"), 46ull};
68-
QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
69-
QString path = homePath + "/QtAutoUpdaterTestInstaller";
81+
updates += {"QtAutoUpdaterTestInstaller", QVersionNumber::fromString("1.1.0"), 45ull};
82+
QString path = controller->maintenanceToolPath();
7083
QTest::newRow("QtAutoUpdaterTestInstaller") << path + "/maintenancetool"
7184
<< true
7285
<< updates;
@@ -76,7 +89,7 @@ void UpdaterTest::testUpdateCheck_data()
7689
#ifdef Q_OS_WIN
7790
path = "C:/Qt";
7891
#else
79-
path = homePath + "/Qt";
92+
path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Qt";
8093
#endif
8194
QTest::newRow("Qt") << path + "/MaintenanceTool"
8295
<< false

0 commit comments

Comments
 (0)