8#include <QtTest/qtest.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qtimer.h>
11#include <QtGui/qguiapplication.h>
12#include <QtQuick/qquickwindow.h>
15#include <QtQml/qqmlcomponent.h>
28 static constexpr int m_argc = 1;
29 static constexpr char *m_argv[] = {
const_cast<char *
>(
"tst_qmltc_examples") };
41#define CREATE_DUMMY_ARGC_ARGV() \
43 char *argv[] = { const_cast<char *>("tst_qmltc_examples") };
45void tst_qmltc_examples::app()
56 QScopedPointer<QmltcExample::myApp> documentRoot(
57 new QmltcExample::myApp(&e,
nullptr, [](
auto&
component){
61 documentRoot->setParentItem(
window.contentItem());
62 window.setHeight(documentRoot->height());
63 window.setWidth(documentRoot->width());
75void tst_qmltc_examples::appComponent()
101 documentRootItem->setParentItem(
window.contentItem());
113#if !defined(QMLTC_TESTS_SOURCE_DIR) || !defined(QMLTC_TESTS_BINARY_DIR)
114# error "Tests assume that QMLTC_TESTS_{SOURCE,BINARY}_DIR are specified (through CMake)"
118template<
typename Predicate>
131 content->append(std::move(
line));
135void tst_qmltc_examples::helloWorld()
138 QSKIP(
"expected C++ files are not bundled with Android tests.");
143 + u
"/.qmltc/tst_qmltc_examples/helloworld.h",
144 [](
const QString &) {
return true; });
146 QFAIL(
"Reading _generated_ C++ content for special/HelloWorld.qml failed");
149 const auto filterDocumentationLines = [encounteredStart =
false](
QStringView line)
mutable {
151 encounteredStart =
true;
154 if (!encounteredStart)
160 QStringLiteral(QMLTC_TESTS_SOURCE_DIR) + u
"/special/HelloWorld.qml.cpp",
161 filterDocumentationLines);
163 QFAIL(
"Reading special/HelloWorld.qml.cpp failed");
165 QVERIFY(!generatedCode.isEmpty());
166 QVERIFY(!documentationCode.isEmpty());
168 auto begin = generatedCode.cbegin();
169 for (
const QString &existingString :
std::as_const(documentationCode)) {
170 auto pos = std::find(
begin, generatedCode.cend(), existingString);
176#undef CREATE_DUMMY_ARGC_ARGV
179#include "tst_qmltc_examples.moc"
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
static void quit()
\threadsafe
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static void setApplicationDisplayName(const QString &name)
QObject * parent() const
Returns a pointer to the parent object.
template< class T > T qobject_cast(const QObject *object)
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise retu...
The QQmlComponent class encapsulates a QML component definition.
The QQmlEngine class provides an environment for instantiating QML components.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QString trimmed() const &
bool singleShot
whether the timer is a single-shot timer
tst_qmltc_examples(QObject *parent=nullptr)
Q_TESTLIB_EXPORT bool currentTestFailed()
Returns true if the current test function has failed, otherwise false.
static QDBusError::ErrorType get(const char *name)
GLint GLsizei GLsizei height
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
static qreal component(const QPointF &point, unsigned int i)
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define qPrintable(string)
#define QStringLiteral(str)
#define QTEST_APPLESS_MAIN(TestObject)
#define QSKIP(statement,...)
#define QVERIFY(statement)
#define QVERIFY2(statement, description)
QUrl url("example.com")
[constructor-url-reference]
QApplication app(argc, argv)
[0]
void readFileContent(QStringList *content, const QString &url, Predicate filter)
#define CREATE_DUMMY_ARGC_ARGV()