From 52c09f5618db5b793cb1a4114c7f35c7d13a3967 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 12 Feb 2013 10:07:19 +0100 Subject: Add auto-test for QInstaller::Settings Change-Id: I693f051636a81c395b3c75701a803ea7593a1fc1 Reviewed-by: Niels Weber Reviewed-by: Karsten Heimrich --- tests/auto/auto.pro | 4 + tests/auto/installer/installer.pro | 4 + .../installer/settings/data/malformed_config.xml | 8 ++ .../installer/settings/data/tutorial_config.xml | 9 +++ tests/auto/installer/settings/settings.pro | 8 ++ tests/auto/installer/settings/settings.qrc | 6 ++ tests/auto/installer/settings/tst_settings.cpp | 89 ++++++++++++++++++++++ tests/auto/qttest.pri | 18 +++++ tests/tests.pro | 1 + 9 files changed, 147 insertions(+) create mode 100644 tests/auto/auto.pro create mode 100644 tests/auto/installer/installer.pro create mode 100644 tests/auto/installer/settings/data/malformed_config.xml create mode 100644 tests/auto/installer/settings/data/tutorial_config.xml create mode 100644 tests/auto/installer/settings/settings.pro create mode 100644 tests/auto/installer/settings/settings.qrc create mode 100644 tests/auto/installer/settings/tst_settings.cpp create mode 100644 tests/auto/qttest.pri (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 000000000..aed5d01af --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + installer diff --git a/tests/auto/installer/installer.pro b/tests/auto/installer/installer.pro new file mode 100644 index 000000000..c01c4125c --- /dev/null +++ b/tests/auto/installer/installer.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + settings diff --git a/tests/auto/installer/settings/data/malformed_config.xml b/tests/auto/installer/settings/data/malformed_config.xml new file mode 100644 index 000000000..ebac3027c --- /dev/null +++ b/tests/auto/installer/settings/data/malformed_config.xml @@ -0,0 +1,8 @@ + + + Your application + 1.2.3 + Your application Installer + Your vendor + Super App + @rootDir@InstallationDirectory diff --git a/tests/auto/installer/settings/data/tutorial_config.xml b/tests/auto/installer/settings/data/tutorial_config.xml new file mode 100644 index 000000000..235434776 --- /dev/null +++ b/tests/auto/installer/settings/data/tutorial_config.xml @@ -0,0 +1,9 @@ + + + Your application + 1.2.3 + Your application Installer + Your vendor + Super App + @rootDir@InstallationDirectory + diff --git a/tests/auto/installer/settings/settings.pro b/tests/auto/installer/settings/settings.pro new file mode 100644 index 000000000..a1932af06 --- /dev/null +++ b/tests/auto/installer/settings/settings.pro @@ -0,0 +1,8 @@ +include(../../qttest.pri) + +QT += network + +SOURCES += tst_settings.cpp + +RESOURCES += \ + settings.qrc diff --git a/tests/auto/installer/settings/settings.qrc b/tests/auto/installer/settings/settings.qrc new file mode 100644 index 000000000..eaa92b93e --- /dev/null +++ b/tests/auto/installer/settings/settings.qrc @@ -0,0 +1,6 @@ + + + data/tutorial_config.xml + data/malformed_config.xml + + diff --git a/tests/auto/installer/settings/tst_settings.cpp b/tests/auto/installer/settings/tst_settings.cpp new file mode 100644 index 000000000..2fcd6bf3f --- /dev/null +++ b/tests/auto/installer/settings/tst_settings.cpp @@ -0,0 +1,89 @@ +#include +#include "settings.h" +#include "errors.h" +#include "repository.h" + +#include + +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()); + QCOMPARE(settings.defaultRepositories(), QSet()); + QCOMPARE(settings.temporaryRepositories(), QSet()); + QCOMPARE(settings.userRepositories(), QSet()); + + 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" diff --git a/tests/auto/qttest.pri b/tests/auto/qttest.pri new file mode 100644 index 000000000..f6be301e8 --- /dev/null +++ b/tests/auto/qttest.pri @@ -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 +#} diff --git a/tests/tests.pro b/tests/tests.pro index 06876e66d..a485d20d3 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -2,6 +2,7 @@ CONFIG += ordered TEMPLATE = subdirs EXTRASUBDIRS = \ + auto \ downloadspeed \ environmentvariable \ extractarchiveoperationtest \ -- cgit v1.2.3