aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcontextpropertydump/tst_qmlcontextpropertydump.cpp
blob: d34f9ae20aa41e7dac84096ad24f2cf9bf33d31b (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
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QtCore/qstring.h>
#include <QtCore/qprocess.h>
#include <QtCore/qlibraryinfo.h>

using namespace Qt::StringLiterals;

class tst_qmlcontextpropertydump : public QQmlDataTest
{
    Q_OBJECT

public:
    tst_qmlcontextpropertydump();

private slots:
    void dump();

private:
    QString m_executablePath;
};

tst_qmlcontextpropertydump::tst_qmlcontextpropertydump() : QQmlDataTest(QT_QMLTEST_DATADIR)
{
    m_executablePath =
            QLibraryInfo::path(QLibraryInfo::BinariesPath).append("/qmlcontextpropertydump"_L1);

#ifdef Q_OS_WIN
    m_executablePath.append(".exe"_L1);
#endif
    if (!QFileInfo::exists(m_executablePath))
        qWarning() << "executable not found (looked for %0)"_L1.arg(m_executablePath);
}

void tst_qmlcontextpropertydump::dump()
{
    QProcess process;
    process.setProgram(m_executablePath);
    QTemporaryDir output;
    QVERIFY(output.isValid());
    process.setArguments({ "-s"_L1, testFile("ContextProperties"_L1), "-b"_L1, output.path() });

    process.start();
    QVERIFY(process.waitForFinished());
    QCOMPARE(process.exitStatus(), QProcess::NormalExit);
    QCOMPARE(process.exitCode(), 0);

    QFile outputFile(output.filePath(".qt/contextPropertyDump.ini"));
    QVERIFY(outputFile.open(QFile::ReadOnly | QFile::Text));

    const QString outputFileContent = outputFile.readAll();
    const QString expectedOutput =
            R"([cachedHeuristicList]
1\name=myContextProperty1
2\name=myContextProperty2
size=2

[property_myContextProperty1]
1\fileName=%1/src/someFile.cpp
1\sourceLocation="324,18,14,45"
size=1

[property_myContextProperty2]
1\fileName=%1/src/someFile.cpp
1\sourceLocation="438,18,16,19"
size=1
)"_L1.arg(testFile("ContextProperties"_L1));

    {
        QFile expectedOutputFile(output.filePath("expected.ini"));
        QVERIFY(expectedOutputFile.open(QFile::WriteOnly | QFile::Text));
        expectedOutputFile.write(expectedOutput.toUtf8());
    }

    QCOMPARE(outputFileContent, expectedOutput);
}

QTEST_GUILESS_MAIN(tst_qmlcontextpropertydump)
#include "tst_qmlcontextpropertydump.moc"