de-duplicate code in tests and benchmarks

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-11-23 18:15:36 +02:00
parent 289cbb7dd1
commit b438e6c37c
5 changed files with 13 additions and 23 deletions

View file

@ -27,10 +27,7 @@
#include <qdeclarativebinding_p.h>
#include <qdir.h>
inline QUrl TEST_FILE(const QString &filename)
{
return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename);
}
#include "../../shared/util.h"
class MyQmlObject : public QObject
{

View file

@ -31,6 +31,8 @@
#include <qdeclarativetextinput_p.h>
#include <qobject_p.h>
#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;

View file

@ -28,6 +28,8 @@
#include <QScriptEngine>
#include <QScriptValue>
#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

View file

@ -24,6 +24,8 @@
#include <QDeclarativeComponent>
#include <QDebug>
#include "../../../shared/util.h"
class tst_typeimports : public QObject
{
Q_OBJECT
@ -86,15 +88,10 @@ tst_typeimports::tst_typeimports()
qmlRegisterType<TestType4>("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());
}
}

View file

@ -48,3 +48,5 @@
QCOMPARE(__expr, __expected); \
} while(0)
#define TEST_FILE(__filename) \
QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + QLatin1String(__filename))