1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 **   * Redistributions of source code must retain the above copyright
25 **     notice, this list of conditions and the following disclaimer.
26 **   * Redistributions in binary form must reproduce the above copyright
27 **     notice, this list of conditions and the following disclaimer in
28 **     the documentation and/or other materials provided with the
29 **     distribution.
30 **   * Neither the name of The Qt Company Ltd nor the names of its
31 **     contributors may be used to endorse or promote products derived
32 **     from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 //! [0]
51 QVERIFY(spy.isValid());
52 //! [0]
53 
54 //! [13]
55 QTest::keyClick(myWidget, 'a');
56 //! [13]
57 
58 //! [14]
59 QTest::keyClick(myWidget, Qt::Key_Escape);
60 
61 QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
62 //! [14]
63 
64 //! [15]
65 QTest::keyClicks(myWidget, "hello world");
66 //! [15]
67 
68 //! [16]
69 namespace QTest {
70     template<>
toString(const MyPoint & point)71     char *toString(const MyPoint &point)
72     {
73         const QByteArray ba("MyPoint("
74                             + QByteArray::number(point.x()) + ", "
75                             + QByteArray::number(point.y()) + ')');
76         return qstrdup(ba.data());
77     }
78 }
79 //! [16]
80 
81 //! [toString-overload]
82 namespace {
toString(const MyPoint & point)83     char *toString(const MyPoint &point)
84     {
85         return QTest::toString("MyPoint(" +
86                                QByteArray::number(point.x()) + ", " +
87                                QByteArray::number(point.y()) + ')');
88     }
89 }
90 //! [toString-overload]
91 
processTouchEvent()92 void processTouchEvent()
93 {
94 //! [25]
95 QTouchDevice *dev = QTest::createTouchDevice();
96 QWidget widget;
97 
98 QTest::touchEvent(&widget, dev)
99     .press(0, QPoint(10, 10));
100 QTest::touchEvent(&widget, dev)
101     .stationary(0)
102     .press(1, QPoint(40, 10));
103 QTest::touchEvent(&widget, dev)
104     .move(0, QPoint(12, 12))
105     .move(1, QPoint(45, 5));
106 QTest::touchEvent(&widget, dev)
107     .release(0, QPoint(12, 12))
108     .release(1, QPoint(45, 5));
109 //! [25]
110 }
111 
112 //! [26]
parse()113 bool tst_MyXmlParser::parse()
114 {
115     MyXmlParser parser;
116     QString input = QFINDTESTDATA("testxml/simple1.xml");
117     QVERIFY(parser.parse(input));
118 }
119 //! [26]
120 
121 //! [28]
122 QWidget myWindow;
123 QTest::keyClick(&myWindow, Qt::Key_Tab);
124 //! [28]
125 
126 //! [29]
127 QTest::keyClick(&myWindow, Qt::Key_Escape);
128 QTest::keyClick(&myWindow, Qt::Key_Escape, Qt::ShiftModifier, 200);
129 //! [29]
130 
131 //! [30]
initTestCase_data()132 void TestQLocale::initTestCase_data()
133 {
134     QTest::addColumn<QLocale>("locale");
135     QTest::newRow("C") << QLocale::c();
136     QTest::newRow("UKish") << QLocale("en_GB");
137     QTest::newRow("USAish") << QLocale(QLocale::English, QLocale::UnitedStates);
138 }
139 
roundTripInt_data()140 void TestQLocale::roundTripInt_data()
141 {
142     QTest::addColumn<int>("number");
143     QTest::newRow("zero") << 0;
144     QTest::newRow("one") << 1;
145     QTest::newRow("two") << 2;
146     QTest::newRow("ten") << 10;
147 }
148 //! [30]
149 
150 //! [31]
roundTripInt()151 void TestQLocale::roundTripInt()
152 {
153     QFETCH_GLOBAL(QLocale, locale);
154     QFETCH(int, number);
155     bool ok;
156     QCOMPARE(locale.toInt(locale.toString(number), &ok), number);
157     QVERIFY(ok);
158 }
159 //! [31]
160 
161 //! [34]
toString(const MyType & t)162 char *toString(const MyType &t)
163 {
164     char *repr = new char[t.reprSize()];
165     t.writeRepr(repr);
166     return repr;
167 }
168 //! [34]
169