Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_qtestlib_qtestcase_snippet.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
6
8QTest::keyClick(myWidget, 'a');
10
13
16
18QTest::keyClicks(myWidget, "hello world");
20
22namespace QTest {
23 template<>
24 char *toString(const MyPoint &point)
25 {
26 const QByteArray ba("MyPoint("
27 + QByteArray::number(point.x()) + ", "
28 + QByteArray::number(point.y()) + ')');
29 return qstrdup(ba.data());
30 }
31}
33
35namespace {
36 char *toString(const MyPoint &point)
37 {
38 return QTest::toString("MyPoint(" +
39 QByteArray::number(point.x()) + ", " +
40 QByteArray::number(point.y()) + ')');
41 }
42}
44
46{
48QTouchDevice *dev = QTest::createTouchDevice();
50
52 .press(0, QPoint(10, 10));
54 .stationary(0)
55 .press(1, QPoint(40, 10));
57 .move(0, QPoint(12, 12))
58 .move(1, QPoint(45, 5));
60 .release(0, QPoint(12, 12))
61 .release(1, QPoint(45, 5));
63}
64
66bool tst_MyXmlParser::parse()
67{
68 MyXmlParser parser;
69 QString input = QFINDTESTDATA("testxml/simple1.xml");
70 QVERIFY(parser.parse(input));
71}
73
78
83
85void TestQLocale::initTestCase_data()
86{
87 QTest::addColumn<QLocale>("locale");
88 QTest::newRow("C") << QLocale::c();
89 QTest::newRow("UKish") << QLocale("en_GB");
91}
92
93void TestQLocale::roundTripInt_data()
94{
95 QTest::addColumn<int>("number");
96 QTest::newRow("zero") << 0;
97 QTest::newRow("one") << 1;
98 QTest::newRow("two") << 2;
99 QTest::newRow("ten") << 10;
100}
102
104void TestQLocale::roundTripInt()
105{
106 QFETCH_GLOBAL(QLocale, locale);
107 QFETCH(int, number);
108 bool ok;
109 QCOMPARE(locale.toInt(locale.toString(number), &ok), number);
110 QVERIFY(ok);
111}
113
115char *toString(const MyType &t)
116{
117 char *repr = new char[t.reprSize()];
118 t.writeRepr(repr);
119 return repr;
120}
122
124QSignalSpy doubleClickSpy(target, &TargetClass::doubleClicked);
125const QPoint p(1, 2);
127QVERIFY(target.isPressed());
129QCOMPARE(target.isPressed(), false);
131QCOMPARE(target.pressCount(), 2);
\inmodule QtCore
Definition qbytearray.h:57
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:611
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
\inmodule QtDBus
qsizetype count() const noexcept
Definition qlist.h:398
@ UnitedStates
Definition qlocale.h:816
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
Definition qlocale.h:1146
@ English
Definition qlocale.h:119
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtTest
Definition qsignalspy.h:22
bool isValid() const noexcept
Returns true if the signal spy listens to a valid signal, otherwise false.
Definition qsignalspy.h:44
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QTouchEventSequence & move(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & press(int touchId, const QPoint &pt, QWindow *window=nullptr)
QTouchEventSequence & release(int touchId, const QPoint &pt, QWindow *window=nullptr)
virtual QTouchEventSequence & stationary(int touchId)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QOpenGLWidget * widget
[1]
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
Q_QML_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Appends a new row to the current test data.
Q_GUI_EXPORT QPointingDevice * createTouchDevice(QInputDevice::DeviceType devType=QInputDevice::DeviceType::TouchScreen, QInputDevice::Capabilities caps=QInputDevice::Capability::Position)
char * toString(const MyPoint &point)
void mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Definition qtestmouse.h:133
static void keyClick(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Definition qtestmouse.h:129
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
Definition qtesttouch.h:42
@ LeftButton
Definition qnamespace.h:58
@ Key_Escape
Definition qnamespace.h:663
@ Key_Tab
Definition qnamespace.h:664
@ ShiftModifier
@ NoModifier
Q_CORE_EXPORT char * qstrdup(const char *)
GLenum target
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
GLenum GLenum GLenum input
#define QFETCH(Type, name)
Definition qtestcase.h:278
#define QCOMPARE(actual, expected)
Definition qtestcase.h:81
#define QVERIFY(statement)
Definition qtestcase.h:58
#define QFINDTESTDATA(basepath)
Definition qtestcase.h:299
#define QFETCH_GLOBAL(Type, name)
Definition qtestcase.h:281
QByteArray ba
[0]
QSignalSpy doubleClickSpy(target, &TargetClass::doubleClicked)
[34]
void processTouchEvent()
[toString-overload]
char * toString(const MyType &t)
[31]
QWidget myWindow
[26]