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>
5
#include "
src_qtestlib_qtestcase.cpp
"
7
class
MyFirstTest
:
public
QObject
8
{
9
Q_OBJECT
10
11
private
:
12
bool
myCondition()
13
{
14
return
true
;
15
}
16
17
private
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
44
void
TestQString::toUpper
()
45
{
46
QString
str
=
"Hello"
;
47
QVERIFY
(
str
.
toUpper
() ==
"HELLO"
);
48
}
50
51
void
TestQString::Compare
()
52
{
54
QCOMPARE
(
QString
(
"hello"
).
toUpper
(),
QString
(
"HELLO"
));
55
QCOMPARE
(
QString
(
"Hello"
).
toUpper
(),
QString
(
"HELLO"
));
56
QCOMPARE
(
QString
(
"HellO"
).
toUpper
(),
QString
(
"HELLO"
));
57
QCOMPARE
(
QString
(
"HELLO"
).
toUpper
(),
QString
(
"HELLO"
));
59
}
60
62
class
MyFirstBenchmark
:
public
QObject
63
{
64
Q_OBJECT
65
private
slots
:
66
void
myFirstBenchmark()
67
{
68
QString
string1;
69
QString
string2;
70
QBENCHMARK
{
71
string1.localeAwareCompare(string2);
72
}
73
}
74
};
MyFirstBenchmark
[12]
Definition
doc_src_qtestlib.cpp:63
MyFirstTest
[0]
Definition
doc_src_qtestlib.cpp:8
QObject
\inmodule QtCore
Definition
qobject.h:103
QString
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition
qstring.h:129
QString::toUpper
QString toUpper() const &
Definition
qstring.h:439
TestQString::toUpper
void toUpper()
[0]
Definition
doc_src_qtestlib.cpp:44
TestQString::Compare
void Compare()
[8]
Definition
doc_src_qtestlib.cpp:51
str
QString str
[2]
Definition
doc_src_containers.cpp:177
QBENCHMARK
#define QBENCHMARK
Definition
qbenchmark.h:40
qDebug
#define qDebug
[1]
Definition
qlogging.h:164
QCOMPARE
#define QCOMPARE(actual, expected)
Definition
qtestcase.h:81
QVERIFY
#define QVERIFY(statement)
Definition
qtestcase.h:58
Q_OBJECT
#define Q_OBJECT
Definition
qtmetamacros.h:119
slots
#define slots
Definition
qtmetamacros.h:40
src_qtestlib_qtestcase.cpp
qtbase
src
testlib
doc
snippets
code
doc_src_qtestlib.cpp
Generated by
1.10.0