/
mt_duibutton.cpp
234 lines (191 loc) · 6.79 KB
/
mt_duibutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libdui.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "memorybenchmark.h"
#include "memorybenchmark.inl"
#include "mt_duibutton.h"
#include "duiclassfactory.h"
#include "duiwidgetview.h"
#include <QPainter>
#include <QPixmap>
#include <DuiButton>
#include <DuiApplication>
#include <DuiTheme>
DuiApplication *app;
DuiButton *warmupButton;
const int W = 250;
const int H = 100;
void Mt_DuiButton::initTestCase()
{
int argc = 1;
char *app_name = (char *) "./Mt_DuiButton";
app = new DuiApplication(argc, &app_name);
QPixmap pixmap(W, H);
QPainter painter(&pixmap);
warmupButton = new DuiButton();
warmupButton->setText("text");
warmupButton->setIconID("Icon-home");
warmupButton->setToggledIconID("Icon-close");
warmupButton->setGeometry(QRectF(0, 0, W, H));
while (DuiTheme::hasPendingRequests()) {
usleep(10000);
QCoreApplication::processEvents();
}
warmupButton->paint(&painter, NULL);
delete warmupButton;
warmupButton = NULL;
}
void Mt_DuiButton::cleanupTestCase()
{
delete warmupButton;
delete app;
}
void Mt_DuiButton::initSchema()
{
QTest::addColumn<qint32>("width");
QTest::addColumn<qint32>("height");
QTest::addColumn<QString>("view");
QTest::addColumn<QString>("icon1");
QTest::addColumn<QString>("icon2");
QTest::addColumn<QString>("text");
}
void Mt_DuiButton::memoryDuiButtonView()
{
QFETCH(qint32, width);
QFETCH(qint32, height);
QFETCH(QString, view);
QFETCH(QString, icon1);
QFETCH(QString, icon2);
QFETCH(QString, text);
memoryBenchmark(width, height, view, icon1, icon2, text);
}
void Mt_DuiButton::memoryDuiButtonView_data()
{
initSchema();
QTest::newRow("Empty") << W << H << "DuiButtonView" << "" << "" << "";
QTest::newRow("Text") << W << H << "DuiButtonView" << "" << "" << "ButtonText";
QTest::newRow("Icon") << W << H << "DuiButtonView" << "Icon-home" << "" << "";
QTest::newRow("Text&Icon") << W << H << "DuiButtonView" << "Icon-home" << "" << "ButtonText";
QTest::newRow("Toggle") << W << H << "DuiButtonView" << "Icon-home" << "Icon-close" << "";
QTest::newRow("Toggle&Text") << W << H << "DuiButtonView" << "Icon-home" << "Icon-close" << "ButtonText";
}
void Mt_DuiButton::memoryDuiButtonDefaultView()
{
QFETCH(qint32, width);
QFETCH(qint32, height);
QFETCH(QString, view);
QFETCH(QString, icon1);
QFETCH(QString, icon2);
QFETCH(QString, text);
memoryBenchmark(width, height, view, icon1, icon2, text);
}
void Mt_DuiButton::memoryDuiButtonDefaultView_data()
{
initSchema();
QTest::newRow("Empty") << W << H << "DuiButtonDefaultView" << "" << "" << "";
QTest::newRow("Text") << W << H << "DuiButtonDefaultView" << "" << "" << "ButtonText";
QTest::newRow("Icon") << W << H << "DuiButtonDefaultView" << "Icon-home" << "" << "";
QTest::newRow("Text&Icon") << W << H << "DuiButtonDefaultView" << "Icon-home" << "" << "ButtonText";
QTest::newRow("Toggle") << W << H << "DuiButtonDefaultView" << "Icon-home" << "Icon-close" << "";
QTest::newRow("Toggle&Text") << W << H << "DuiButtonDefaultView" << "Icon-home" << "Icon-close" << "ButtonText";
}
void Mt_DuiButton::memoryDuiButtonIconView()
{
QFETCH(qint32, width);
QFETCH(qint32, height);
QFETCH(QString, view);
QFETCH(QString, icon1);
QFETCH(QString, icon2);
QFETCH(QString, text);
memoryBenchmark(width, height, view, icon1, icon2, text);
}
void Mt_DuiButton::memoryDuiButtonIconView_data()
{
initSchema();
QTest::newRow("Empty") << W << H << "DuiButtonIconView" << "" << "" << "";
QTest::newRow("Text") << W << H << "DuiButtonIconView" << "" << "" << "ButtonText";
QTest::newRow("Icon") << W << H << "DuiButtonIconView" << "Icon-home" << "" << "";
QTest::newRow("Text&Icon") << W << H << "DuiButtonIconView" << "Icon-home" << "" << "ButtonText";
QTest::newRow("Toggle") << W << H << "DuiButtonIconView" << "Icon-home" << "Icon-close" << "";
QTest::newRow("Toggle&Text") << W << H << "DuiButtonIconView" << "Icon-home" << "Icon-close" << "ButtonText";
}
void Mt_DuiButton::memoryDuiButtonViewTimeline()
{
memoryBenchmark(W, H, "DuiButtonView", "Icon-home", "Icon-close", "ButtonText");
}
void Mt_DuiButton::memoryDuiButtonViewDefaultViewTimeline()
{
memoryBenchmark(W, H, "DuiButtonDefaultView", "Icon-home", "Icon-close", "ButtonText");
}
void Mt_DuiButton::memoryDuiButtonViewIconViewTimeline()
{
memoryBenchmark(W, H, "DuiButtonIconView", "Icon-home", "Icon-close", "ButtonText");
}
void Mt_DuiButton::memoryBenchmark(qint32 width, qint32 height, const QString &view, const QString &icon1, const QString &icon2, const QString &text)
{
QPixmap pixmap(width, height);
QPainter painter(&pixmap);
painter.fillRect(QRect(0, 0, width, height), QColor(0, 0, 0));
beginMemoryBenchmark();
DuiButton *button = new DuiButton();
DuiWidgetView *buttonView = DuiClassFactory::instance()->createView(view.toStdString().c_str(), button);
button->setView(buttonView);
button->setGeometry(QRectF(0, 0, width, height));
if (!text.isEmpty()) {
button->setText(text);
button->setTextVisible(true);
} else
button->setTextVisible(false);
if (!icon1.isEmpty()) {
button->setIconID(icon1);
button->setIconVisible(true);
} else
button->setIconVisible(false);
if (!icon2.isEmpty()) {
button->setToggledIconID(icon2);
button->setIconVisible(true);
}
while (DuiTheme::hasPendingRequests()) {
usleep(10000);
QCoreApplication::processEvents();
}
button->paint(&painter, NULL);
outputAllocatedMemorySize();
delete button;
endMemoryBenchmark();
// save a shot (for debugging)
//#define SCREENSHOT
#ifdef SCREENSHOT
QString kuva;
QTextStream(&kuva)
<< view
<< "_"
<< "\"" << icon1 << "\""
<< "_"
<< "\"" << icon2 << "\""
<< "_"
<< "\"" << text << "\""
<< "_"
<< width
<< "x"
<< height
<< ".png";
pixmap.save(kuva, "png", -1);
#endif
}
QTEST_APPLESS_MAIN(Mt_DuiButton)