1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 |
|
---|
42 | void wrapInFunction()
|
---|
43 | {
|
---|
44 |
|
---|
45 | //! [0]
|
---|
46 | QVERIFY(1 + 1 == 2);
|
---|
47 | //! [0]
|
---|
48 |
|
---|
49 |
|
---|
50 | //! [1]
|
---|
51 | QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occurred.");
|
---|
52 | //! [1]
|
---|
53 |
|
---|
54 |
|
---|
55 | //! [2]
|
---|
56 | QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
|
---|
57 | //! [2]
|
---|
58 |
|
---|
59 |
|
---|
60 | //! [3]
|
---|
61 | void TestQString::toInt_data()
|
---|
62 | {
|
---|
63 | QTest::addColumn<QString>("aString");
|
---|
64 | QTest::addColumn<int>("expected");
|
---|
65 |
|
---|
66 | QTest::newRow("positive value") << "42" << 42;
|
---|
67 | QTest::newRow("negative value") << "-42" << -42;
|
---|
68 | QTest::newRow("zero") << "0" << 0;
|
---|
69 | }
|
---|
70 | //! [3]
|
---|
71 |
|
---|
72 |
|
---|
73 | //! [4]
|
---|
74 | void TestQString::toInt()
|
---|
75 | {
|
---|
76 | QFETCH(QString, aString);
|
---|
77 | QFETCH(int, expected);
|
---|
78 |
|
---|
79 | QCOMPARE(aString.toInt(), expected);
|
---|
80 | }
|
---|
81 | //! [4]
|
---|
82 |
|
---|
83 |
|
---|
84 | //! [5]
|
---|
85 | if (sizeof(int) != 4)
|
---|
86 | QFAIL("This test has not been ported to this platform yet.");
|
---|
87 | //! [5]
|
---|
88 |
|
---|
89 |
|
---|
90 | //! [6]
|
---|
91 | QFETCH(QString, myString);
|
---|
92 | QCOMPARE(QString("hello").toUpper(), myString);
|
---|
93 | //! [6]
|
---|
94 |
|
---|
95 |
|
---|
96 | //! [7]
|
---|
97 | QTEST(QString("hello").toUpper(), "myString");
|
---|
98 | //! [7]
|
---|
99 |
|
---|
100 |
|
---|
101 | //! [8]
|
---|
102 | if (!QSqlDatabase::drivers().contains("SQLITE"))
|
---|
103 | QSKIP("This test requires the SQLITE database driver", SkipAll);
|
---|
104 | //! [8]
|
---|
105 |
|
---|
106 |
|
---|
107 | //! [9]
|
---|
108 | QEXPECT_FAIL("", "Will fix in the next release", Continue);
|
---|
109 | QCOMPARE(i, 42);
|
---|
110 | QCOMPARE(j, 43);
|
---|
111 | //! [9]
|
---|
112 |
|
---|
113 |
|
---|
114 | //! [10]
|
---|
115 | QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
|
---|
116 | QCOMPARE(i, 42);
|
---|
117 | //! [10]
|
---|
118 |
|
---|
119 |
|
---|
120 | //! [11]
|
---|
121 | class TestQString: public QObject { ... };
|
---|
122 | QTEST_MAIN(TestQString)
|
---|
123 | //! [11]
|
---|
124 |
|
---|
125 |
|
---|
126 | //! [12]
|
---|
127 | #ifdef Q_WS_X11
|
---|
128 | QTEST_MAIN(MyX11Test)
|
---|
129 | #else
|
---|
130 | // do nothing on non-X11 platforms
|
---|
131 | QTEST_NOOP_MAIN
|
---|
132 | #endif
|
---|
133 | //! [12]
|
---|
134 |
|
---|
135 |
|
---|
136 | //! [13]
|
---|
137 | QTest::keyClick(myWidget, 'a');
|
---|
138 | //! [13]
|
---|
139 |
|
---|
140 |
|
---|
141 | //! [14]
|
---|
142 | QTest::keyClick(myWidget, Qt::Key_Escape);
|
---|
143 |
|
---|
144 | QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
|
---|
145 | //! [14]
|
---|
146 |
|
---|
147 |
|
---|
148 | //! [15]
|
---|
149 | QTest::keyClicks(myWidget, "hello world");
|
---|
150 | //! [15]
|
---|
151 |
|
---|
152 |
|
---|
153 | //! [16]
|
---|
154 | namespace QTest {
|
---|
155 | template<>
|
---|
156 | char *toString(const MyPoint &point)
|
---|
157 | {
|
---|
158 | QByteArray ba = "MyPoint(";
|
---|
159 | ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
|
---|
160 | ba += ")";
|
---|
161 | return qstrdup(ba.data());
|
---|
162 | }
|
---|
163 | }
|
---|
164 | //! [16]
|
---|
165 |
|
---|
166 |
|
---|
167 | //! [17]
|
---|
168 | int i = 0;
|
---|
169 | while (myNetworkServerNotResponding() && i++ < 50)
|
---|
170 | QTest::qWait(250);
|
---|
171 | //! [17]
|
---|
172 |
|
---|
173 |
|
---|
174 | //! [18]
|
---|
175 | MyFirstTestObject test1;
|
---|
176 | QTest::qExec(&test1);
|
---|
177 |
|
---|
178 | MySecondTestObject test2;
|
---|
179 | QTest::qExec(&test2);
|
---|
180 | //! [18]
|
---|
181 |
|
---|
182 |
|
---|
183 | //! [19]
|
---|
184 | QDir dir;
|
---|
185 |
|
---|
186 | QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
|
---|
187 | dir.mkdir("");
|
---|
188 | //! [19]
|
---|
189 |
|
---|
190 |
|
---|
191 | //! [20]
|
---|
192 | void myTestFunction_data()
|
---|
193 | {
|
---|
194 | QTest::addColumn<QString>("aString");
|
---|
195 | QTest::newRow("just hello") << QString("hello");
|
---|
196 | QTest::newRow("a null string") << QString();
|
---|
197 | }
|
---|
198 | //! [20]
|
---|
199 |
|
---|
200 |
|
---|
201 | //! [21]
|
---|
202 | void myTestFunction_data() {
|
---|
203 | QTest::addColumn<int>("intval");
|
---|
204 | QTest::addColumn<QString>("str");
|
---|
205 | QTest::addColumn<double>("dbl");
|
---|
206 |
|
---|
207 | QTest::newRow("row1") << 1 << "hello" << 1.5;
|
---|
208 | }
|
---|
209 | //! [21]
|
---|
210 |
|
---|
211 |
|
---|
212 | //! [22]
|
---|
213 | void MyTestClass::cleanup()
|
---|
214 | {
|
---|
215 | if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
|
---|
216 | // clean up all database connections
|
---|
217 | closeAllDatabases();
|
---|
218 | }
|
---|
219 | }
|
---|
220 | //! [22]
|
---|
221 |
|
---|
222 |
|
---|
223 | //! [23]
|
---|
224 | QTest::qSleep(250);
|
---|
225 | //! [23]
|
---|
226 |
|
---|
227 | //! [24]
|
---|
228 | QWidget widget;
|
---|
229 | widget.show();
|
---|
230 | QTest::qWaitForWindowShown(&widget);
|
---|
231 | //! [24]
|
---|
232 |
|
---|
233 | //! [25]
|
---|
234 | QWidget widget;
|
---|
235 |
|
---|
236 | QTest::touchEvent(&widget)
|
---|
237 | .press(0, QPoint(10, 10));
|
---|
238 | QTest::touchEvent(&widget)
|
---|
239 | .stationary(0)
|
---|
240 | .press(1, QPoint(40, 10));
|
---|
241 | QTest::touchEvent(&widget)
|
---|
242 | .move(0, QPoint(12, 12))
|
---|
243 | .move(1, QPoint(45, 5));
|
---|
244 | QTest::touchEvent(&widget)
|
---|
245 | .release(0)
|
---|
246 | .release(1);
|
---|
247 | //! [25]
|
---|
248 |
|
---|
249 | }
|
---|
250 |
|
---|