From b438e6c37c9814d0b631613b75f96f101faf77ad Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 23 Nov 2021 18:15:36 +0200 Subject: [PATCH] de-duplicate code in tests and benchmarks Signed-off-by: Ivailo Monev --- .../tst_qdeclarativeproperty.cpp | 5 +---- .../declarative/creation/tst_creation.cpp | 9 +++------ tests/benchmarks/declarative/script/tst_script.cpp | 7 ++----- .../declarative/typeimports/tst_typeimports.cpp | 13 +++++-------- tests/shared/util.h | 2 ++ 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/tests/auto/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/qdeclarativeproperty/tst_qdeclarativeproperty.cpp index 9cf98b4d1..377a22a39 100644 --- a/tests/auto/qdeclarativeproperty/tst_qdeclarativeproperty.cpp +++ b/tests/auto/qdeclarativeproperty/tst_qdeclarativeproperty.cpp @@ -27,10 +27,7 @@ #include #include -inline QUrl TEST_FILE(const QString &filename) -{ - return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); -} +#include "../../shared/util.h" class MyQmlObject : public QObject { diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 5fd830f01..fc722d0fc 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -31,6 +31,8 @@ #include #include +#include "../../../shared/util.h" + class tst_creation : public QObject { Q_OBJECT @@ -89,11 +91,6 @@ tst_creation::tst_creation() QDeclarativeTextInput te; } -inline QUrl TEST_FILE(const QString &filename) -{ - return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); -} - void tst_creation::qobject_cpp() { QBENCHMARK { @@ -286,7 +283,7 @@ void tst_creation::itemtree_data_cpp() void tst_creation::itemtree_qml() { - QDeclarativeComponent component(&engine, TEST_FILE(QLatin1String("item.qml"))); + QDeclarativeComponent component(&engine, TEST_FILE("item.qml")); QObject *obj = component.create(); delete obj; diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 148f87b4d..63d9c5bc5 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -28,6 +28,8 @@ #include #include +#include "../../../shared/util.h" + class tst_script : public QObject { Q_OBJECT @@ -78,11 +80,6 @@ private slots: void scriptfile_property(); }; -inline QUrl TEST_FILE(const char* filename) -{ - return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + QString::fromLatin1(filename)); -} - class TestObject : public QObject { Q_OBJECT diff --git a/tests/benchmarks/declarative/typeimports/tst_typeimports.cpp b/tests/benchmarks/declarative/typeimports/tst_typeimports.cpp index 8a0be37a5..dfdc66818 100644 --- a/tests/benchmarks/declarative/typeimports/tst_typeimports.cpp +++ b/tests/benchmarks/declarative/typeimports/tst_typeimports.cpp @@ -24,6 +24,8 @@ #include #include +#include "../../../shared/util.h" + class tst_typeimports : public QObject { Q_OBJECT @@ -86,15 +88,10 @@ tst_typeimports::tst_typeimports() qmlRegisterType("Qt.test", 2, 0, "TestType4"); } -inline QUrl TEST_FILE(const QString &filename) -{ - return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); -} - void tst_typeimports::cpp() { QBENCHMARK { - QDeclarativeComponent component(&engine, TEST_FILE(QLatin1String("cpp.qml"))); + QDeclarativeComponent component(&engine, TEST_FILE("cpp.qml")); QVERIFY(component.isReady()); } } @@ -102,10 +99,10 @@ void tst_typeimports::cpp() void tst_typeimports::qml() { //get rid of initialization effects - { QDeclarativeComponent component(&engine, TEST_FILE(QLatin1String("qml.qml"))); } + { QDeclarativeComponent component(&engine, TEST_FILE("qml.qml")); } QBENCHMARK { - QDeclarativeComponent component(&engine, TEST_FILE(QLatin1String("qml.qml"))); + QDeclarativeComponent component(&engine, TEST_FILE("qml.qml")); QVERIFY(component.isReady()); } } diff --git a/tests/shared/util.h b/tests/shared/util.h index e648eb953..e9fbb96f7 100644 --- a/tests/shared/util.h +++ b/tests/shared/util.h @@ -48,3 +48,5 @@ QCOMPARE(__expr, __expected); \ } while(0) +#define TEST_FILE(__filename) \ + QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + QLatin1String(__filename))