8#include <QtTest/qtestcase.h>
9#include <QtTest/qtestsystem.h>
10#include <QtTest/private/qtestblacklist_p.h>
11#include <QtTest/private/qtestresult_p.h>
12#include <QtTest/private/qtesttable_p.h>
13#include <QtTest/private/qtestlog_p.h>
15#include <QtTest/qbenchmark.h>
16#include <QtTest/private/qbenchmark_p.h>
17#include <QtCore/qset.h>
18#include <QtCore/qmap.h>
19#include <QtCore/qbytearray.h>
20#include <QtCore/qcoreapplication.h>
21#include <QtCore/qdatetime.h>
22#include <QtCore/qdebug.h>
25#if QT_CONFIG(regularexpression)
26#include <QtCore/qregularexpression.h>
28#include <QtQuick/qquickwindow.h>
29#include <QtGui/qvector3d.h>
30#include <QtGui/qimagewriter.h>
31#include <QtQml/private/qqmlglobal_p.h>
32#include <QtQml/QQmlEngine>
33#include <QtQml/QQmlContext>
34#include <private/qv4qobjectwrapper_p.h>
85 ||
x >= m_image.width()
86 ||
y >= m_image.height()
89 ||
x *
y >= m_image.width() * m_image.height())
98 return m_image.isNull();
100 return m_image ==
other->m_image;
106 if (!writer.write(m_image)) {
116 return m_image.width();
121 return m_image.height();
126 return m_image.size();
190 return d->testCaseName;
196 d->testCaseName =
name;
212 return d->functionName;
218 if (!
name.isEmpty()) {
219 if (
d->testCaseName.isEmpty()) {
221 (
d->intern(
name).constData());
232 d->functionName =
name;
253 if (!
tag.isEmpty()) {
410 d->table->
addColumn(qMetaTypeId<QString>(),
"qmltest_dummy_data_column");
452 if (!success &&
message.isEmpty()) {
454 (success,
"verify()",
"",
458 (success,
message.toUtf8().constData(),
"",
465 if (actual.userType() == QMetaType::QColor ||
expected.userType() == QMetaType::QColor) {
466 if (!actual.canConvert(
QMetaType(QMetaType::QColor))
486 return (
qAbs(act.
red() - exp.red()) <= delta
487 &&
qAbs(act.
green() - exp.green()) <= delta
488 &&
qAbs(act.
blue() - exp.blue()) <= delta
489 &&
qAbs(act.
alpha() - exp.alpha()) <= delta);
493 qreal act = actual.toFloat(&
ok);
501 return (
qAbs(act - exp) <= delta);
518 if (
value->isObject()
523 switch (
v.userType()) {
524 case QMetaType::QVector3D:
530 case QMetaType::QUrl:
536 case QMetaType::QDateTime:
568 (success,
message.toUtf8().constData(),
587 (
tag.toLatin1().constData(),
596 (
tag.toLatin1().constData(),
609#if QT_CONFIG(regularexpression)
620#if QT_CONFIG(regularexpression)
648 delete d->benchmarkData;
652 d->resultsList.clear();
667 if (
d->iterCount > -1)
671 if (
d->iterCount == -1) {
684static QList<QBenchmarkResult>
qMedian(
const QList<QList<QBenchmarkResult>> &container)
686 const int count = container.size();
691 return container.at(0);
693 QList<QList<QBenchmarkResult>> containerCopy = container;
694 std::sort(containerCopy.begin(), containerCopy.end(),
695 [](
const QList<QBenchmarkResult> &
a,
const QList<QBenchmarkResult> &
b) {
696 return a.first() < b.first();
699 const int middle =
count / 2;
702 return containerCopy.at(middle);
724 delete d->benchmarkIter;
732 if (
d->benchmarkIter)
733 return d->benchmarkIter->isDone();
741 if (
d->benchmarkIter)
742 d->benchmarkIter->next();
748 delete d->benchmarkIter;
749 d->benchmarkIter =
nullptr;
772bool QuickTestResult::isPolishScheduled(
QObject *itemOrWindow)
const
774 if (
auto item = qobject_cast<QQuickItem*>(itemOrWindow))
777 if (
auto window = qobject_cast<QQuickWindow*>(itemOrWindow))
780 qmlWarning(
this) <<
"isPolishScheduled() expects either an Item or Window, but got"
781 << QDebug::toString(itemOrWindow);
785bool QuickTestResult::waitForPolish(
QObject *itemOrWindow,
int timeout)
const
787 if (
auto item = qobject_cast<QQuickItem*>(itemOrWindow))
790 if (
auto window = qobject_cast<QQuickWindow*>(itemOrWindow))
793 qmlWarning(
this) <<
"waitForItemPolish() expects either an Item or Window, but got"
794 << QDebug::toString(itemOrWindow);
830#if defined(QTEST_NOEXITCODE)
841#include "quicktestresult.moc"
842#include "moc_quicktestresult_p.cpp"
static QBenchmarkGlobalData * current
static QBenchmarkTestMethodData * current
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
The QColor class provides colors based on RGB, HSV or CMYK values.
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
int alpha() const noexcept
Returns the alpha color component of this color.
int red() const noexcept
Returns the red color component of this color.
int blue() const noexcept
Returns the blue color component of this color.
int green() const noexcept
Returns the green color component of this color.
\inmodule QtCore\reentrant
static QString toNativeSeparators(const QString &pathName)
qreal y() const
This convenience function is equivalent to calling pos().y().
QGraphicsWidget * window() const
qreal x() const
This convenience function is equivalent to calling pos().x().
The QImageWriter class provides a format independent interface for writing images to files or other d...
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
int width() const
Returns the width of the image.
int height() const
Returns the height of the image.
qreal devicePixelRatio() const
Returns the device pixel ratio for the image.
QV4::ExecutionEngine * handle() const
The QJSValue class acts as a container for Qt/JavaScript data types.
QString toString() const
Returns the string value of this QJSValue, as defined in \l{ECMA-262} section 9.8,...
bool isEmpty() const noexcept
qsizetype length() const noexcept
T findChild(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
QObject * parent() const
Returns a pointer to the parent object.
\inmodule QtCore\reentrant
virtual QVariant colorFromString(const QString &, bool *)
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
The QQmlEngine class provides an environment for instantiating QML components.
static void setContextForObject(QObject *, QQmlContext *)
Sets the QQmlContext for the object to context.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
static void startLogging()
static void addBenchmarkResults(const QList< QBenchmarkResult > &result)
static void stopLogging()
static void failOnWarning()
static void warn(const char *msg, const char *file, int line)
static void ignoreMessage(QtMsgType type, const char *msg)
static void finishedCurrentTestDataCleanup()
This function is called after completing each test function, including test functions that are not da...
static void finishedCurrentTestData()
This function is called after completing each test function, including test functions that are not da...
static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line)
static bool verify(bool statement, const char *statementStr, const char *extraInfo, const char *file, int line)
static bool currentTestFailed()
static void setSkipCurrentTest(bool value)
static void setCurrentAppName(const char *appName)
static void setCurrentTestFunction(const char *func)
static void setBlacklistCurrentTest(bool b)
static void setCurrentTestObject(const char *name)
static const char * currentDataTag()
static bool compare(bool success, const char *failureMsg, char *val1, char *val2, const char *actual, const char *expected, const char *file, int line)
static void addFailure(const char *message, const char *file=nullptr, int line=0)
static bool skipCurrentTest()
static void finishedCurrentTestFunction()
This function is called after completing each test function, including test functions that are data-d...
static void setCurrentTestData(QTestData *data)
static void addSkip(const char *message, const char *file, int line)
void addColumn(int elementType, const char *elementName)
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
The QVector3D class represents a vector or vertex in 3D space.
bool equals(QuickTestImageObject *other) const
int red(int x, int y) const
QVariant pixel(int x, int y) const
void save(const QString &filePath)
int green(int x, int y) const
int alpha(int x, int y) const
int blue(int x, int y) const
QByteArray intern(const QString &str)
QSet< QByteArray > internedStrings
QList< QList< QBenchmarkResult > > resultsList
QTest::QBenchmarkIterationController * benchmarkIter
~QuickTestResultPrivate()
QBenchmarkTestMethodData * benchmarkData
void warn(const QString &message, const QUrl &location, int line)
void finishTestDataCleanup()
void functionNameChanged()
void setFunctionName(const QString &name)
QStringList functionsToRun
bool verify(bool success, const QString &message, const QUrl &location, int line)
bool isBenchmarkDone() const
bool isSkipped() const
\qmlproperty bool TestResult::skipped
bool measurementAccepted()
void finishTestFunction()
const QString & objectName
bool expectFailContinue(const QString &tag, const QString &comment, const QUrl &location, int line)
void reset()
\qmlmethod TestResult::reset()
void setTestCaseName(const QString &name)
static void setCurrentAppname(const char *appname)
bool compare(bool success, const QString &message, const QVariant &val1, const QVariant &val2, const QUrl &location, int line)
QuickTestResult(QObject *parent=nullptr)
void stopLogging()
\qmlmethod TestResult::stopLogging()
static void setProgramName(const char *name)
bool isFailed() const
\qmlproperty bool TestResult::failed
void ignoreWarning(const QJSValue &message)
void testCaseNameChanged()
bool needsMoreMeasurements()
void startBenchmark(RunMode runMode, const QString &tag)
void startLogging()
\qmlmethod TestResult::startLogging()
void fail(const QString &message, const QUrl &location, int line)
bool expectFail(const QString &tag, const QString &comment, const QUrl &location, int line)
void stringify(QQmlV4FunctionPtr args)
~QuickTestResult() override
static void parseArgs(int argc, char *argv[])
bool fuzzyCompare(const QVariant &actual, const QVariant &expected, qreal delta)
bool waitForRendering(QQuickItem *item, int timeout=5000)
void setDataTag(const QString &tag)
QObject * grabImage(QQuickItem *item)
void skip(const QString &message, const QUrl &location, int line)
void setSkipped(bool skip)
Q_QMLTEST_EXPORT bool qWaitForPolish(const QQuickItem *item, int timeout=defaultTimeout)
Q_QMLTEST_EXPORT bool qIsPolishScheduled(const QQuickItem *item)
Combined button and popup list for selecting options.
bool checkBlackLists(const char *slot, const char *data, const char *global)
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool qml)
char * toString(const MyPoint &point)
Q_TESTLIB_EXPORT QStringList testFunctions
Q_CORE_EXPORT void qSleep(int ms)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Q_TESTLIB_EXPORT QStringList testTags
Q_CORE_EXPORT void qWait(int ms)
This is an overloaded member function, provided for convenience. It differs from the above function o...
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr const T & qMin(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
GLbitfield GLuint64 timeout
[4]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLsizei const GLchar * message
GLfloat GLfloat GLfloat alpha
GLenum GLenum GLsizei void * table
QQmlContext * qmlContext(const QObject *obj)
Q_AUTOTEST_EXPORT QQmlColorProvider * QQml_colorProvider(void)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
bool qWaitForSignal(QObject *obj, const char *signal, int timeout)
static QBenchmarkGlobalData globalBenchmarkData
static QString qtestFixUrl(const QUrl &location)
static QList< QBenchmarkResult > qMedian(const QList< QList< QBenchmarkResult > > &container)
static bool loggingStarted
static QT_BEGIN_NAMESPACE const char * globalProgramName
QUrl url("example.com")
[constructor-url-reference]
\inmodule QtCore \reentrant
static constexpr ReturnedValue null()
ReturnedValue throwError(const Value &value)
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols=true)