4
0
mirror of https://github.com/QuasarApp/installer-framework.git synced 2025-05-05 09:49:32 +00:00

Add auto-test for QInstaller::Settings

Change-Id: I693f051636a81c395b3c75701a803ea7593a1fc1
Reviewed-by: Niels Weber <niels.weber@digia.com>
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
This commit is contained in:
Kai Koehne 2013-02-12 10:07:19 +01:00
parent aa00cc5060
commit 52c09f5618
9 changed files with 147 additions and 0 deletions

4
tests/auto/auto.pro Normal file

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
installer

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
settings

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Your application</Name>
<Version>1.2.3</Version>
<Title>Your application Installer</Title>
<Publisher>Your vendor</Publisher>
<StartMenuDir>Super App</StartMenuDir>
<TargetDir>@rootDir@InstallationDirectory</TargetDir>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Your application</Name>
<Version>1.2.3</Version>
<Title>Your application Installer</Title>
<Publisher>Your vendor</Publisher>
<StartMenuDir>Super App</StartMenuDir>
<TargetDir>@rootDir@InstallationDirectory</TargetDir>
</Installer>

@ -0,0 +1,8 @@
include(../../qttest.pri)
QT += network
SOURCES += tst_settings.cpp
RESOURCES += \
settings.qrc

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>data/tutorial_config.xml</file>
<file>data/malformed_config.xml</file>
</qresource>
</RCC>

@ -0,0 +1,89 @@
#include <QTest>
#include "settings.h"
#include "errors.h"
#include "repository.h"
#include <QFile>
using namespace QInstaller;
class tst_Settings : public QObject
{
Q_OBJECT
private slots:
void loadConfig();
void loadNotExistingConfig();
void loadMalformedConfig();
};
void tst_Settings::loadConfig()
{
Settings settings =
Settings::fromFileAndPrefix(":///data/tutorial_config.xml", ":///data");
// specified values
QCOMPARE(settings.applicationName(), QLatin1String("Your application"));
QCOMPARE(settings.applicationVersion(), QLatin1String("1.2.3"));
QCOMPARE(settings.title(), QLatin1String("Your application Installer"));
QCOMPARE(settings.publisher(), QLatin1String("Your vendor"));
QCOMPARE(settings.startMenuDir(), QLatin1String("Super App"));
QCOMPARE(settings.targetDir(), QLatin1String("@rootDir@InstallationDirectory"));
// default values
QCOMPARE(settings.logo(), QLatin1String(":///data/"));
QCOMPARE(settings.logoSmall(), QLatin1String(":///data/"));
QCOMPARE(settings.url(), QString());
QCOMPARE(settings.watermark(), QLatin1String(":///data/"));
QCOMPARE(settings.background(), QLatin1String(":///data/"));
QCOMPARE(settings.icon(), QLatin1String(":/installer.png"));
QCOMPARE(settings.runProgram(), QString());
QCOMPARE(settings.runProgramDescription(), QString());
QCOMPARE(settings.adminTargetDir(), QString());
QCOMPARE(settings.removeTargetDir(), QLatin1String("true"));
QCOMPARE(settings.uninstallerName(), QLatin1String("uninstall"));
QCOMPARE(settings.uninstallerIniFile(), QLatin1String("uninstall.ini"));
QCOMPARE(settings.configurationFileName(), QLatin1String("components.xml"));
QCOMPARE(settings.dependsOnLocalInstallerBinary(), false);
QCOMPARE(settings.repositorySettingsPageVisible(), true);
QCOMPARE(settings.hasReplacementRepos(), false);
QCOMPARE(settings.allowSpaceInPath(), false);
QCOMPARE(settings.certificateFiles(), QStringList());
QCOMPARE(settings.allowNonAsciiCharacters(), false);
QCOMPARE(settings.hasReplacementRepos(), false);
QCOMPARE(settings.repositories(), QSet<Repository>());
QCOMPARE(settings.defaultRepositories(), QSet<Repository>());
QCOMPARE(settings.temporaryRepositories(), QSet<Repository>());
QCOMPARE(settings.userRepositories(), QSet<Repository>());
QCOMPARE(settings.proxyType(), Settings::NoProxy);
QCOMPARE(settings.ftpProxy(), QNetworkProxy());
QCOMPARE(settings.httpProxy(), QNetworkProxy());
}
void tst_Settings::loadNotExistingConfig()
{
try {
Settings::fromFileAndPrefix(":/data/inexisting_config.xml", ":/data");
} catch (const Error &error) {
QVERIFY(error.message() == ("Could not open settings file :/data/inexisting_config.xml for reading: Unknown error"));
return;
}
QFAIL("No exception thrown");
}
void tst_Settings::loadMalformedConfig()
{
try {
Settings::fromFileAndPrefix(":/data/malformed_config.xml", ":/data");
} catch (const Error &error) {
QVERIFY(error.message().startsWith("Xml parse error"));
return;
}
QFAIL("No exception thrown");
}
QTEST_MAIN(tst_Settings)
#include "tst_settings.moc"

18
tests/auto/qttest.pri Normal file

@ -0,0 +1,18 @@
include(../../installerfw.pri)
#include(qttestrpath.pri)
isEmpty(TEMPLATE):TEMPLATE=app
QT += testlib
CONFIG += qt warn_on console depend_includepath testcase
CONFIG -= app_bundle
DEFINES -= QT_NO_CAST_FROM_ASCII
# prefix test binary with tst_
!contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_")
#win32 {
# lib = ../../
# lib ~= s,/,\\,g
# # the below gets added to later by testcase.prf
# check.commands = cd . & set PATH=$$lib;%PATH%& cmd /c
#}

@ -2,6 +2,7 @@ CONFIG += ordered
TEMPLATE = subdirs
EXTRASUBDIRS = \
auto \
downloadspeed \
environmentvariable \
extractarchiveoperationtest \