Debian Codegraph @

tests/benchmarks/gui/text/qfontmetrics/main.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QObject>
5 #include <QFont>
6 #include <QFontMetrics>
7
8 #include <qtest.h>
9
10 //this test benchmarks the once-off (per font configuration) cost
11 //associated with using QFontMetrics
12 class tst_QFontMetrics : public QObject
13 {
14 Q_OBJECT
15 public:
16 tst_QFontMetrics() {}
17 private slots:
18 void fontmetrics_create();
19 void fontmetrics_create_once_loaded();
20
21 void fontmetrics_height();
22 void fontmetrics_height_once_loaded();
23
24 private:
25 void testQFontMetrics(const QFontMetrics &fm);
26 };
27
28 void tst_QFontMetrics::testQFontMetrics( const QFontMetrics &fm )
29 {
30 int fontHeight = fm.height();
31 Q_UNUSED(fontHeight);
32 }
33
34 void tst_QFontMetrics::fontmetrics_create()
35 {
36 QBENCHMARK {
37 QFont boldfont = QGuiApplication::font();
38 boldfont.setBold( true );
39 boldfont.setPointSize(boldfont.pointSize() * 1.5 );
40 QFontMetrics bfm( boldfont );
41 }
42 }
43
44 void tst_QFontMetrics::fontmetrics_create_once_loaded()
45 {
46 QBENCHMARK {
47 QFont boldfont = QGuiApplication::font();
48 boldfont.setBold( true );
49 boldfont.setPointSize(boldfont.pointSize() * 1.5 );
50 QFontMetrics bfm( boldfont );
51 }
52 }
53
54 void tst_QFontMetrics::fontmetrics_height()
55 {
56 QFont boldfont = QGuiApplication::font();
57 boldfont.setBold( true );
58 boldfont.setPointSize(boldfont.pointSize() * 1.5 );
59 QFontMetrics bfm( boldfont );
60
61 QBENCHMARK { testQFontMetrics(bfm); }
62 }
63
64 void tst_QFontMetrics::fontmetrics_height_once_loaded()
65 {
66 QFont boldfont = QGuiApplication::font();
67 boldfont.setBold( true );
68 boldfont.setPointSize(boldfont.pointSize() * 1.5 );
69 QFontMetrics bfm( boldfont );
70 QBENCHMARK { testQFontMetrics(bfm); }
71 }
72
73 QTEST_MAIN(tst_QFontMetrics)
74
75 #include "main.moc"