Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
doc_src_qtestlib.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QTest>
6//! [0]
7class MyFirstTest: public QObject
8{
10
11private:
12 bool myCondition()
13 {
14 return true;
15 }
16
17private slots:
18 void initTestCase()
19 {
20 qDebug("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 {
32 QVERIFY(1 != 2);
33 }
34
35 void cleanupTestCase()
36 {
37 qDebug("Called after myFirstTest and mySecondTest.");
38 }
39};
40//! [0]
41
42
43//! [8]
45{
46 QString str = "Hello";
47 QVERIFY(str.toUpper() == "HELLO");
48}
49//! [8]
50
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]
63{
65private slots:
66 void myFirstBenchmark()
67 {
72 }
73 }
74};
75//! [12]