diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-12-22 17:24:16 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2023-02-02 18:11:07 +0100 |
commit | 01d84ffc74d4328240e4f242f35f34c2164dbbca (patch) | |
tree | 36fa3292d150277179ea5492c589926cb6a8501d /tests/auto/qml/qmltc_qprocess | |
parent | 55f3bf8882fc8eeb132b4d2af9158bd1fee6bd78 (diff) |
qmltc: export generated classes
Add QMLTC_EXPORT_MACRO_NAME and QMLTC_EXPORT_FILE_NAME arguments to
qt_add_qml_module() that allows the user to export qmltc-generated code
from its library. The qmltc-generated code will include the header-file
specified in QMLTC_EXPORT_FILE_NAME and will be exported with the macro
specified by QMLTC_EXPORT_MACRO_NAME.
Leave both options unspecified to not export the code generated by
qmltc.
Describe the options in the documentation and write a test to see if the
class really has an export macro in the generated code:
1) tst_qmltc_qprocess will test if the macro and the header are correctly
inserted in the generated code.
2) tst_qmltc_{no,}diskcache will test if the generated code can still be
used from a static library.
Fixes: QTBUG-106840
Task-number: QTBUG-96040
Change-Id: I554f03bcdf043e8114e42f51a7289a5c00de4f89
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc_qprocess')
-rw-r--r-- | tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp index 7f12f29342..f0b99fcdf0 100644 --- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp +++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp @@ -51,6 +51,7 @@ private slots: void topLevelComponent(); void dashesInFilename(); void invalidSignalHandlers(); + void exports(); }; #ifndef TST_QMLTC_QPROCESS_RESOURCES @@ -261,5 +262,38 @@ void tst_qmltc_qprocess::invalidSignalHandlers() } } +static QString fileToString(const QString &path) +{ + QFile f(path); + if (f.open(QIODevice::ReadOnly)) + return QString::fromLatin1(f.readAll()); + return QString(); +} + +void tst_qmltc_qprocess::exports() +{ + const QString fileName = u"dummy.qml"_s; + QStringList extraArgs; + extraArgs << "--export" + << "MYLIB_EXPORT_MACRO" + << "--exportInclude" + << "exportheader.h"; + const auto errors = runQmltc(fileName, true, extraArgs); + + const QString headerName = m_tmpPath + u"/"_s + QFileInfo(fileName).baseName() + u".h"_s; + const QString header = fileToString(headerName); + const QString implementationName = + m_tmpPath + u"/"_s + QFileInfo(fileName).baseName() + u".cpp"_s; + const QString implementation = fileToString(implementationName); + + QCOMPARE(errors.size(), 0); + + QVERIFY(header.contains(u"class MYLIB_EXPORT_MACRO dummy : public QObject\n"_s)); + QVERIFY(!implementation.contains(u"MYLIB_EXPORT_MACRO"_s)); + + QVERIFY(header.contains(u"#include \"exportheader.h\"\n"_s)); + QVERIFY(!implementation.contains(u"exportheader.h"_s)); +} + QTEST_MAIN(tst_qmltc_qprocess) #include "tst_qmltc_qprocess.moc" |