aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_generate_qmlls_ini/main.cpp
blob: a7bdbf1e1816e01bb42d74faf53d2d4b270ca9f3 (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
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
#include <QtQml/qqml.h>
#include <QtTest/qtest.h>

class tst_generate_qmlls_ini : public QObject
{
    Q_OBJECT
private slots:
    void qmllsIniAreCorrect();
};

using namespace Qt::StringLiterals;

#ifndef SOURCE_DIRECTORY
#  define SOURCE_DIRECTORY u"invalid_source_directory"_s
#endif
#ifndef BUILD_DIRECTORY
#  define BUILD_DIRECTORY u"invalid_build_directory"_s
#endif

void tst_generate_qmlls_ini::qmllsIniAreCorrect()
{
    const QString qmllsIniName = u".qmlls.ini"_s;
    QDir source(SOURCE_DIRECTORY);
    QDir build(BUILD_DIRECTORY);
    if (!source.exists())
        QSKIP(u"Cannot find source directory '%1', skipping test..."_s.arg(SOURCE_DIRECTORY)
                      .toLatin1());

    {
        auto file = QFile(source.absoluteFilePath(qmllsIniName));
        QVERIFY(file.exists());
        QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
        const auto fileContent = QString::fromUtf8(file.readAll());
        auto secondFolder = QDir(build.absolutePath().append(u"/qml/hello/subfolders"_s));
        QVERIFY(secondFolder.exists());
        QCOMPARE(fileContent,
                 u"[General]\nbuildDir=%1%2%3\nno-cmake-calls=false\n"_s.arg(build.absolutePath(), QDir::listSeparator(),
                                                       secondFolder.absolutePath()));
    }

    {
    QDir sourceSubfolder = source;
    QVERIFY(sourceSubfolder.cd(u"SomeSubfolder"_s));
    QDir buildSubfolder(build.absolutePath().append(u"/SomeSubfolder/qml/Some/Sub/Folder"_s));
    {
        auto file = QFile(sourceSubfolder.absoluteFilePath(qmllsIniName));
        QVERIFY(file.exists());
        QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
        const auto fileContent = QString::fromUtf8(file.readAll());
        QCOMPARE(fileContent,
                 u"[General]\nbuildDir=%1\nno-cmake-calls=false\n"_s.arg(buildSubfolder.absolutePath()));
    }
    }

    {
        QDir dottedUriSubfolder = source;
        QVERIFY(dottedUriSubfolder.cd(u"Dotted"_s));
        QVERIFY(dottedUriSubfolder.cd(u"Uri"_s));
        {
            auto file = QFile(dottedUriSubfolder.absoluteFilePath(qmllsIniName));
            QVERIFY(file.exists());
            QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
            const auto fileContent = QString::fromUtf8(file.readAll());
            QCOMPARE(
                    fileContent,
                    u"[General]\nbuildDir=%1\nno-cmake-calls=false\n"_s.arg(build.absolutePath()));
        }
    }
    {
        QDir dottedUriSubfolder = source;
        QVERIFY(dottedUriSubfolder.cd(u"Dotted"_s));
        QVERIFY(dottedUriSubfolder.cd(u"Uri"_s));
        QVERIFY(dottedUriSubfolder.cd(u"Hello"_s));
        QVERIFY(dottedUriSubfolder.cd(u"World"_s));
        {
            auto file = QFile(dottedUriSubfolder.absoluteFilePath(qmllsIniName));
            QVERIFY(file.exists());
            QVERIFY(file.open(QFile::ReadOnly | QFile::Text));
            const auto fileContent = QString::fromUtf8(file.readAll());
            QCOMPARE(
                    fileContent,
                    u"[General]\nbuildDir=%1\nno-cmake-calls=false\n"_s.arg(build.absolutePath()));
        }
    }
}

QTEST_MAIN(tst_generate_qmlls_ini)

#include "main.moc"