source: trunk/doc/src/snippets/code/doc_src_qtestlib.qdoc@ 244

Last change on this file since 244 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 1.9 KB
Line 
1//! [0]
2class MyFirstTest: public QObject
3{
4 Q_OBJECT
5private slots:
6 void initTestCase()
7 { qDebug("called before everything else"); }
8 void myFirstTest()
9 { QVERIFY(1 == 1); }
10 void mySecondTest()
11 { QVERIFY(1 != 2); }
12 void cleanupTestCase()
13 { qDebug("called after myFirstTest and mySecondTest"); }
14};
15//! [0]
16
17
18//! [1]
19QT += testlib
20//! [1]
21
22
23//! [2]
24testname [options] [testfunctions[:testdata]]...
25//! [2]
26
27
28//! [3]
29/myTestDirectory$ testQString toUpper
30//! [3]
31
32
33//! [4]
34/myTestDirectory$ testQString toUpper toInt:zero
35//! [4]
36
37
38//! [5]
39/myTestDirectory$ testMyWidget -vs -eventdelay 500
40//! [5]
41
42
43//! [6]
44cetest [options] ...
45//! [6]
46
47
48//! [7]
49set INCLUDE=C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Activesync\Inc;%INCLUDE%
50set LIB=C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Activesync\Lib;%LIB%
51//! [7]
52
53
54//! [8]
55void TestQString::toUpper()
56{
57 QString str = "Hello";
58 QVERIFY(str.toUpper() == "HELLO");
59}
60//! [8]
61
62
63//! [9]
64/myTestDirectory$ qmake -project "QT += testlib"
65/myTestDirectory$ qmake
66/myTestDirectory$ make
67//! [9]
68
69
70//! [10]
71********* Start testing of TestQString *********
72Config: Using QTest library 4.5.1, Qt 4.5.1
73PASS : TestQString::initTestCase()
74PASS : TestQString::toUpper()
75PASS : TestQString::cleanupTestCase()
76Totals: 3 passed, 0 failed, 0 skipped
77********* Finished testing of TestQString *********
78//! [10]
79
80
81//! [11]
82QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
83QCOMPARE(QString("Hello").toUpper(), QString("HELLO"));
84QCOMPARE(QString("HellO").toUpper(), QString("HELLO"));
85QCOMPARE(QString("HELLO").toUpper(), QString("HELLO"));
86//! [11]
87
88//! [12]
89class MyFirstBenchmark: public QObject
90{
91 Q_OBJECT
92private slots:
93 void myFirstBenchmark()
94 {
95 QString string1;
96 QString string2;
97 QBENCHMARK {
98 string1.localeAwareCompare(string2);
99 }
100 }
101};
102//! [12]
Note: See TracBrowser for help on using the repository browser.