summaryrefslogtreecommitdiffstats
path: root/tests/auto/installer/settings/tst_settings.cpp
blob: ac092554cc527fc14043d726db3b63909e33cd1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#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 loadTutorialConfig();
    void loadFullConfig();
    void loadEmptyConfig();
    void loadNotExistingConfig();
    void loadMalformedConfig();
    void loadUnknownElementConfig();
};

void tst_Settings::loadTutorialConfig()
{
    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/"));
#if defined(Q_OS_WIN)
    QCOMPARE(settings.icon(), QLatin1String(":/installer.ico"));
#elif defined(Q_OS_MAC)
    QCOMPARE(settings.icon(), QLatin1String(":/installer.icns"));
#else
    QCOMPARE(settings.icon(), QLatin1String(":/installer.png"));
#endif
    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.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::loadFullConfig()
{
    Settings settings =
            Settings::fromFileAndPrefix(":///data/full_config.xml", ":///data");
}

void tst_Settings::loadEmptyConfig()
{
    try {
        Settings::fromFileAndPrefix(":/data/empty_config.xml", ":/data");
    } catch (const Error &error) {
        QCOMPARE(error.message(), QLatin1String("Missing or empty <Name> tag in :/data/empty_config.xml."));
        return;
    }
    QFAIL("No exception thrown");
}

void tst_Settings::loadNotExistingConfig()
{
    try {
        Settings::fromFileAndPrefix(":/data/inexisting_config.xml", ":/data");
    } catch (const Error &error) {
        QCOMPARE(error.message(), QLatin1String("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) {
        QCOMPARE(error.message(), QLatin1String("Error in :/data/malformed_config.xml, line 9, column 0: "
                                           "Premature end of document."));
        return;
    }
    QFAIL("No exception thrown");
}

void tst_Settings::loadUnknownElementConfig()
{
    try {
        Settings::fromFileAndPrefix(":/data/unknown_element_config.xml", ":/data");
    } catch (const Error &error) {
        QCOMPARE(error.message(), QLatin1String("Error in :/data/unknown_element_config.xml, line 5, "
                                                "column 13: Unexpected element 'unknown'."));
        return;
    }
    QFAIL("No exception thrown");
}

QTEST_MAIN(tst_Settings)

#include "tst_settings.moc"