Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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>
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 {
31 QVERIFY(myCondition());
32 QVERIFY(1 != 2);
33 }
34
35 void cleanupTestCase()
36 {
37 qDebug("Called after myFirstTest and mySecondTest.");
38 }
39};
41
42
45{
46 QString str = "Hello";
47 QVERIFY(str.toUpper() == "HELLO");
48}
50
52{
54QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
55QCOMPARE(QString("Hello").toUpper(), QString("HELLO"));
56QCOMPARE(QString("HellO").toUpper(), QString("HELLO"));
57QCOMPARE(QString("HELLO").toUpper(), QString("HELLO"));
59}
60
63{
65private slots:
66 void myFirstBenchmark()
67 {
68 QString string1;
69 QString string2;
71 string1.localeAwareCompare(string2);
72 }
73 }
74};
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString toUpper() const &
Definition qstring.h:439
QString str
[2]
#define QBENCHMARK
Definition qbenchmark.h:40
#define qDebug
[1]
Definition qlogging.h:164
#define QCOMPARE(actual, expected)
Definition qtestcase.h:81
#define QVERIFY(statement)
Definition qtestcase.h:58
#define Q_OBJECT
#define slots