1 |
|
---|
2 | void wrapInFunction()
|
---|
3 | {
|
---|
4 |
|
---|
5 | //! [0]
|
---|
6 | QVERIFY(1 + 1 == 2);
|
---|
7 | //! [0]
|
---|
8 |
|
---|
9 |
|
---|
10 | //! [1]
|
---|
11 | QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.");
|
---|
12 | //! [1]
|
---|
13 |
|
---|
14 |
|
---|
15 | //! [2]
|
---|
16 | QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
|
---|
17 | //! [2]
|
---|
18 |
|
---|
19 |
|
---|
20 | //! [3]
|
---|
21 | void TestQString::toInt_data()
|
---|
22 | {
|
---|
23 | QTest::addColumn<QString>("aString");
|
---|
24 | QTest::addColumn<int>("expected");
|
---|
25 |
|
---|
26 | QTest::newRow("positive value") << "42" << 42;
|
---|
27 | QTest::newRow("negative value") << "-42" << -42;
|
---|
28 | QTest::newRow("zero") << "0" << 0;
|
---|
29 | }
|
---|
30 | //! [3]
|
---|
31 |
|
---|
32 |
|
---|
33 | //! [4]
|
---|
34 | void TestQString::toInt()
|
---|
35 | {
|
---|
36 | QFETCH(QString, aString);
|
---|
37 | QFETCH(int, expected);
|
---|
38 |
|
---|
39 | QCOMPARE(aString.toInt(), expected);
|
---|
40 | }
|
---|
41 | //! [4]
|
---|
42 |
|
---|
43 |
|
---|
44 | //! [5]
|
---|
45 | if (sizeof(int) != 4)
|
---|
46 | QFAIL("This test has not been ported to this platform yet.");
|
---|
47 | //! [5]
|
---|
48 |
|
---|
49 |
|
---|
50 | //! [6]
|
---|
51 | QFETCH(QString, myString);
|
---|
52 | QCOMPARE(QString("hello").toUpper(), myString);
|
---|
53 | //! [6]
|
---|
54 |
|
---|
55 |
|
---|
56 | //! [7]
|
---|
57 | QTEST(QString("hello").toUpper(), "myString");
|
---|
58 | //! [7]
|
---|
59 |
|
---|
60 |
|
---|
61 | //! [8]
|
---|
62 | if (!QSqlDatabase::drivers().contains("SQLITE"))
|
---|
63 | QSKIP("This test requires the SQLITE database driver", SkipAll);
|
---|
64 | //! [8]
|
---|
65 |
|
---|
66 |
|
---|
67 | //! [9]
|
---|
68 | QEXPECT_FAIL("", "Will fix in the next release", Continue);
|
---|
69 | QCOMPARE(i, 42);
|
---|
70 | QCOMPARE(j, 43);
|
---|
71 | //! [9]
|
---|
72 |
|
---|
73 |
|
---|
74 | //! [10]
|
---|
75 | QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
|
---|
76 | QCOMPARE(i, 42);
|
---|
77 | //! [10]
|
---|
78 |
|
---|
79 |
|
---|
80 | //! [11]
|
---|
81 | class TestQString: public QObject { ... };
|
---|
82 | QTEST_MAIN(TestQString)
|
---|
83 | //! [11]
|
---|
84 |
|
---|
85 |
|
---|
86 | //! [12]
|
---|
87 | #ifdef Q_WS_X11
|
---|
88 | QTEST_MAIN(MyX11Test)
|
---|
89 | #else
|
---|
90 | // do nothing on non-X11 platforms
|
---|
91 | QTEST_NOOP_MAIN
|
---|
92 | #endif
|
---|
93 | //! [12]
|
---|
94 |
|
---|
95 |
|
---|
96 | //! [13]
|
---|
97 | QTest::keyClick(myWidget, 'a');
|
---|
98 | //! [13]
|
---|
99 |
|
---|
100 |
|
---|
101 | //! [14]
|
---|
102 | QTest::keyClick(myWidget, Qt::Key_Escape);
|
---|
103 |
|
---|
104 | QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
|
---|
105 | //! [14]
|
---|
106 |
|
---|
107 |
|
---|
108 | //! [15]
|
---|
109 | QTest::keyClicks(myWidget, "hello world");
|
---|
110 | //! [15]
|
---|
111 |
|
---|
112 |
|
---|
113 | //! [16]
|
---|
114 | namespace QTest {
|
---|
115 | template<>
|
---|
116 | char *toString(const MyPoint &point)
|
---|
117 | {
|
---|
118 | QByteArray ba = "MyPoint(";
|
---|
119 | ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
|
---|
120 | ba += ")";
|
---|
121 | return qstrdup(ba.data());
|
---|
122 | }
|
---|
123 | }
|
---|
124 | //! [16]
|
---|
125 |
|
---|
126 |
|
---|
127 | //! [17]
|
---|
128 | int i = 0;
|
---|
129 | while (myNetworkServerNotResponding() && i++ < 50)
|
---|
130 | QTest::qWait(250);
|
---|
131 | //! [17]
|
---|
132 |
|
---|
133 |
|
---|
134 | //! [18]
|
---|
135 | MyFirstTestObject test1;
|
---|
136 | QTest::qExec(&test1);
|
---|
137 |
|
---|
138 | MySecondTestObject test2;
|
---|
139 | QTest::qExec(&test2);
|
---|
140 | //! [18]
|
---|
141 |
|
---|
142 |
|
---|
143 | //! [19]
|
---|
144 | QDir dir;
|
---|
145 |
|
---|
146 | QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
|
---|
147 | dir.mkdir("");
|
---|
148 | //! [19]
|
---|
149 |
|
---|
150 |
|
---|
151 | //! [20]
|
---|
152 | void myTestFunction_data()
|
---|
153 | {
|
---|
154 | QTest::addColumn<QString>("aString");
|
---|
155 | QTest::newRow("just hello") << QString("hello");
|
---|
156 | QTest::newRow("a null string") << QString();
|
---|
157 | }
|
---|
158 | //! [20]
|
---|
159 |
|
---|
160 |
|
---|
161 | //! [21]
|
---|
162 | void myTestFunction_data() {
|
---|
163 | QTest::addColumn<int>("intval");
|
---|
164 | QTest::addColumn<QString>("str");
|
---|
165 | QTest::addColumn<double>("dbl");
|
---|
166 |
|
---|
167 | QTest::newRow("row1") << 1 << "hello" << 1.5;
|
---|
168 | }
|
---|
169 | //! [21]
|
---|
170 |
|
---|
171 |
|
---|
172 | //! [22]
|
---|
173 | void MyTestClass::cleanup()
|
---|
174 | {
|
---|
175 | if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
|
---|
176 | // clean up all database connections
|
---|
177 | closeAllDatabases();
|
---|
178 | }
|
---|
179 | }
|
---|
180 | //! [22]
|
---|
181 |
|
---|
182 |
|
---|
183 | //! [23]
|
---|
184 | QTest::qSleep(250);
|
---|
185 | //! [23]
|
---|
186 |
|
---|
187 | }
|
---|
188 |
|
---|