1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QTest>
5#include "src_qtestlib_qtestcase.cpp"
6//! [0]
7class MyFirstTest: public QObject
8{
9 Q_OBJECT
10
11private:
12 bool myCondition()
13 {
14 return true;
15 }
16
17private slots:
18 void initTestCase()
19 {
20 qDebug(msg: "Called before everything else.");
21 }
22
23 void myFirstTest()
24 {
25 QVERIFY(true); // check that a condition is satisfied
26 QCOMPARE(1, 1); // compare two values
27 }
28
29 void mySecondTest()
30 {
31 QVERIFY(myCondition());
32 QVERIFY(1 != 2);
33 }
34
35 void cleanupTestCase()
36 {
37 qDebug(msg: "Called after myFirstTest and mySecondTest.");
38 }
39};
40//! [0]
41
42
43//! [8]
44void TestQString::toUpper()
45{
46 QString str = "Hello";
47 QVERIFY(str.toUpper() == "HELLO");
48}
49//! [8]
50
51void TestQString::Compare()
52{
53//! [11]
54QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
55QCOMPARE(QString("Hello").toUpper(), QString("HELLO"));
56QCOMPARE(QString("HellO").toUpper(), QString("HELLO"));
57QCOMPARE(QString("HELLO").toUpper(), QString("HELLO"));
58//! [11]
59}
60
61//! [12]
62class MyFirstBenchmark: public QObject
63{
64 Q_OBJECT
65private slots:
66 void myFirstBenchmark()
67 {
68 QString string1;
69 QString string2;
70 QBENCHMARK {
71 string1.localeAwareCompare(s: string2);
72 }
73 }
74};
75//! [12]
76

source code of qtbase/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp