Merge lp:~unity-api-team/libusermetrics/gettext-on-bg-thread into lp:libusermetrics
- gettext-on-bg-thread
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Pete Woods | ||||
Approved revision: | 182 | ||||
Merged at revision: | 180 | ||||
Proposed branch: | lp:~unity-api-team/libusermetrics/gettext-on-bg-thread | ||||
Merge into: | lp:libusermetrics | ||||
Diff against target: |
758 lines (+270/-52) 11 files modified
debian/libusermetricsinput1.symbols (+2/-0) debian/libusermetricsoutput1.symbols (+2/-0) src/libusermetricscommon/Localisation.cpp (+81/-18) src/libusermetricscommon/Localisation.h (+46/-2) src/libusermetricsoutput/DataSource.cpp (+20/-15) src/libusermetricsoutput/DataSource.h (+7/-0) src/libusermetricsoutput/UserMetricsImpl.cpp (+20/-3) src/libusermetricsoutput/UserMetricsImpl.h (+6/-0) tests/unit/libusermetricsoutput/TestSyncedUserMetricsStore.cpp (+17/-0) tests/unit/libusermetricsoutput/TestUserMetricsImpl.cpp (+56/-1) tests/unit/qml/tst_Metrics.qml (+13/-13) |
||||
To merge this branch: | bzr merge lp:~unity-api-team/libusermetrics/gettext-on-bg-thread | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Florian Boucault (community) | code | Approve | |
Review via email: mp+238480@code.launchpad.net |
Commit message
Run gettext on a background thread, communicating asynchronously
Description of the change
Run gettext on a background thread, communicating asynchronously
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:179
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Pete Woods (pete-woods) wrote : | # |
Bah, gcov symbols. The build works except for gcov exporting some random symbols. It will build under launchpad.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:180
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:181
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'debian/libusermetricsinput1.symbols' |
2 | --- debian/libusermetricsinput1.symbols 2013-09-04 13:44:30 +0000 |
3 | +++ debian/libusermetricsinput1.symbols 2014-10-20 13:30:00 +0000 |
4 | @@ -55,3 +55,5 @@ |
5 | usermetricsinput_metricupdate_add_data@Base 1.0.1 |
6 | usermetricsinput_metricupdate_add_null@Base 1.0.1 |
7 | usermetricsinput_metricupdate_delete@Base 1.0.1 |
8 | + (optional=gcov)"__gcov_rewrite@Base" 0replaceme |
9 | + (optional=gcov)"__gcov_var@Base" 0replaceme |
10 | |
11 | === modified file 'debian/libusermetricsoutput1.symbols' |
12 | --- debian/libusermetricsoutput1.symbols 2013-06-20 15:59:31 +0000 |
13 | +++ debian/libusermetricsoutput1.symbols 2014-10-20 13:30:00 +0000 |
14 | @@ -42,3 +42,5 @@ |
15 | (c++)"typeinfo name for UserMetricsOutput::UserMetrics@Base" 1.0.1 |
16 | (c++)"vtable for UserMetricsOutput::ColorTheme@Base" 1.0.1 |
17 | (c++)"vtable for UserMetricsOutput::UserMetrics@Base" 1.0.1 |
18 | + (optional=gcov)"__gcov_rewrite@Base" 0replaceme |
19 | + (optional=gcov)"__gcov_var@Base" 0replaceme |
20 | |
21 | === modified file 'src/libusermetricscommon/Localisation.cpp' |
22 | --- src/libusermetricscommon/Localisation.cpp 2014-09-16 16:11:00 +0000 |
23 | +++ src/libusermetricscommon/Localisation.cpp 2014-10-20 13:30:00 +0000 |
24 | @@ -17,23 +17,86 @@ |
25 | */ |
26 | |
27 | #include <libusermetricscommon/Localisation.h> |
28 | +#include <QtCore/QDebug> |
29 | #include <QtCore/QProcess> |
30 | |
31 | -QString gettextExternal(const QString &textDomain, const QString &messageId, |
32 | - const QString &localeDir) { |
33 | - QProcess gettext; |
34 | - |
35 | - if (!localeDir.isEmpty()) { |
36 | - QProcessEnvironment env(QProcessEnvironment::systemEnvironment()); |
37 | - env.insert("TEXTDOMAINDIR", localeDir); |
38 | - gettext.setProcessEnvironment(env); |
39 | - } |
40 | - |
41 | - gettext.setProcessChannelMode(QProcess::ForwardedErrorChannel); |
42 | - gettext.start("gettext", QStringList() << textDomain << messageId); |
43 | - gettext.waitForReadyRead(200); |
44 | - QByteArray ba(gettext.readAllStandardOutput()); |
45 | - gettext.kill(); |
46 | - |
47 | - return QString::fromUtf8(ba); |
48 | -} |
49 | +namespace { |
50 | +static QWeakPointer<ExternalGettext> instance; |
51 | +} |
52 | + |
53 | +class ExternalGettext::Priv: public QObject { |
54 | +Q_OBJECT |
55 | + |
56 | +public Q_SLOTS: |
57 | + void tr(GettextRequest::Ptr request) { |
58 | + QProcess gettext; |
59 | + |
60 | + if (!request->m_localeDir.isEmpty()) { |
61 | + QProcessEnvironment env(QProcessEnvironment::systemEnvironment()); |
62 | + env.insert("TEXTDOMAINDIR", request->m_localeDir); |
63 | + gettext.setProcessEnvironment(env); |
64 | + } |
65 | + |
66 | + gettext.setProcessChannelMode(QProcess::ForwardedErrorChannel); |
67 | + gettext.start("gettext", |
68 | + QStringList() << request->m_textDomain << request->m_messageId); |
69 | + gettext.waitForReadyRead(200); |
70 | + QByteArray ba(gettext.readAllStandardOutput()); |
71 | + gettext.waitForFinished(200); |
72 | + |
73 | + Q_EMIT request->result(QString::fromUtf8(ba), request->m_requestId); |
74 | + } |
75 | +}; |
76 | + |
77 | +ExternalGettext::Ptr ExternalGettext::singletonInstance() { |
78 | + ExternalGettext::Ptr result(instance); |
79 | + |
80 | + if (!result) { |
81 | + qRegisterMetaType<GettextRequest::Ptr>("GettextRequest::Ptr"); |
82 | + result.reset(new ExternalGettext); |
83 | + instance = result; |
84 | + } |
85 | + return result; |
86 | +} |
87 | + |
88 | +ExternalGettext::ExternalGettext() { |
89 | + m_thread.start(); |
90 | + |
91 | + p.reset(new Priv); |
92 | + p->moveToThread(&m_thread); |
93 | + |
94 | + connect(this, SIGNAL(newRequest(GettextRequest::Ptr)), |
95 | + p.data(), SLOT(tr(GettextRequest::Ptr)), |
96 | + Qt::QueuedConnection); |
97 | +} |
98 | + |
99 | +ExternalGettext::~ExternalGettext() { |
100 | + if (m_thread.isRunning()) { |
101 | + m_thread.quit(); |
102 | + m_thread.wait(); |
103 | + } |
104 | +} |
105 | + |
106 | +void ExternalGettext::tr(const QString &textDomain, const QString &messageId, |
107 | + const QString &localeDir, const QObject *who, |
108 | + const QString &requestId) { |
109 | + |
110 | + GettextRequest::Ptr r(new GettextRequest); |
111 | + |
112 | + r->m_textDomain = textDomain; |
113 | + r->m_messageId = messageId; |
114 | + r->m_localeDir = localeDir; |
115 | + r->m_requestId = requestId; |
116 | + |
117 | + r->moveToThread(&m_thread); |
118 | + |
119 | + connect(r.data(), |
120 | + SIGNAL(result(const QString &, const QString &)), |
121 | + who, |
122 | + SLOT(translationResult(const QString &, const QString &)), |
123 | + Qt::QueuedConnection); |
124 | + |
125 | + Q_EMIT newRequest(r); |
126 | +} |
127 | + |
128 | +#include "Localisation.moc" |
129 | |
130 | === modified file 'src/libusermetricscommon/Localisation.h' |
131 | --- src/libusermetricscommon/Localisation.h 2014-09-16 08:14:45 +0000 |
132 | +++ src/libusermetricscommon/Localisation.h 2014-10-20 13:30:00 +0000 |
133 | @@ -20,7 +20,9 @@ |
134 | #define USERMETRICSCOMMON_LOCALISATION_H_ |
135 | |
136 | #include <libintl.h> |
137 | +#include <QtCore/QSharedPointer> |
138 | #include <QtCore/QString> |
139 | +#include <QtCore/QThread> |
140 | |
141 | inline char * _(const char *__msgid) { |
142 | return dgettext(GETTEXT_PACKAGE, __msgid); |
143 | @@ -40,7 +42,49 @@ |
144 | return dcngettext(GETTEXT_PACKAGE, __msgid1, __msgid2, __n, __category); |
145 | } |
146 | |
147 | -QString gettextExternal(const QString &textDomain, const QString &messageId, |
148 | - const QString &localeDir = ""); |
149 | +class GettextRequest: public QObject { |
150 | +Q_OBJECT |
151 | + |
152 | +public: |
153 | + typedef QSharedPointer<GettextRequest> Ptr; |
154 | + |
155 | + QString m_textDomain; |
156 | + QString m_messageId; |
157 | + QString m_localeDir; |
158 | + QString m_requestId; |
159 | + |
160 | +Q_SIGNALS: |
161 | + void result(const QString &result, const QString &requestId); |
162 | +}; |
163 | + |
164 | + |
165 | +class ExternalGettext: public QObject { |
166 | +Q_OBJECT |
167 | + |
168 | +public: |
169 | + typedef QSharedPointer<ExternalGettext> Ptr; |
170 | + |
171 | + static Ptr singletonInstance(); |
172 | + |
173 | + ExternalGettext(); |
174 | + |
175 | + ~ExternalGettext(); |
176 | + |
177 | +public Q_SLOTS: |
178 | + void tr(const QString &textDomain, const QString &messageId, |
179 | + const QString &localeDir, const QObject *who, |
180 | + const QString &requestId); |
181 | + |
182 | +Q_SIGNALS: |
183 | + void newRequest(GettextRequest::Ptr request); |
184 | + |
185 | +protected: |
186 | + class Priv; |
187 | + |
188 | + QThread m_thread; |
189 | + QSharedPointer<Priv> p; |
190 | +}; |
191 | + |
192 | +Q_DECLARE_METATYPE(GettextRequest::Ptr) |
193 | |
194 | #endif // USERMETRICSCOMMON_LOCALISATION_H_ |
195 | |
196 | === modified file 'src/libusermetricsoutput/DataSource.cpp' |
197 | --- src/libusermetricsoutput/DataSource.cpp 2013-09-04 09:09:23 +0000 |
198 | +++ src/libusermetricsoutput/DataSource.cpp 2014-10-20 13:30:00 +0000 |
199 | @@ -17,15 +17,13 @@ |
200 | */ |
201 | |
202 | #include <libusermetricsoutput/DataSource.h> |
203 | -#include <libusermetricscommon/Localisation.h> |
204 | |
205 | using namespace UserMetricsOutput; |
206 | |
207 | DataSource::DataSource(const QString &localeDir, QObject *parent) : |
208 | QObject(parent), m_formatString(""), m_formatStringTr(""), m_emptyDataString( |
209 | ""), m_emptyDataStringTr(""), m_textDomain(""), m_localeDir( |
210 | - localeDir), m_type(USER) { |
211 | - |
212 | + localeDir), m_type(USER), m_externalGettext(ExternalGettext::singletonInstance()) { |
213 | } |
214 | |
215 | DataSource::~DataSource() { |
216 | @@ -35,13 +33,24 @@ |
217 | return m_formatStringTr; |
218 | } |
219 | |
220 | +void DataSource::translationResult(const QString &result, const QString &requestId) |
221 | +{ |
222 | + if (requestId == "format-string") { |
223 | + if (result != m_formatStringTr) { |
224 | + m_formatStringTr = result; |
225 | + formatStringChanged (m_formatStringTr); |
226 | + } |
227 | + } else if (requestId == "empty-data-string") { |
228 | + if (result != m_emptyDataStringTr) { |
229 | + m_emptyDataStringTr = result; |
230 | + emptyDataStringChanged(m_emptyDataStringTr); |
231 | + } |
232 | + } |
233 | +} |
234 | + |
235 | void DataSource::updateFormatStringTranslation() { |
236 | - QString newFormatStringTr( |
237 | - gettextExternal(m_textDomain, m_formatString, m_localeDir)); |
238 | - if (newFormatStringTr != m_formatStringTr) { |
239 | - m_formatStringTr = newFormatStringTr; |
240 | - formatStringChanged(m_formatStringTr); |
241 | - } |
242 | + m_externalGettext->tr(m_textDomain, m_formatString, |
243 | + m_localeDir, this, "format-string"); |
244 | } |
245 | |
246 | void DataSource::setFormatString(const QString &formatString) { |
247 | @@ -52,12 +61,8 @@ |
248 | } |
249 | |
250 | void DataSource::updateEmptyDataStringTranslation() { |
251 | - QString newEmptyDataStringTr( |
252 | - gettextExternal(m_textDomain, m_emptyDataString, m_localeDir)); |
253 | - if (newEmptyDataStringTr != m_emptyDataStringTr) { |
254 | - m_emptyDataStringTr = newEmptyDataStringTr; |
255 | - emptyDataStringChanged(m_emptyDataStringTr); |
256 | - } |
257 | + m_externalGettext->tr(m_textDomain, m_emptyDataString, |
258 | + m_localeDir, this, "empty-data-string"); |
259 | } |
260 | |
261 | const QString & DataSource::emptyDataString() const { |
262 | |
263 | === modified file 'src/libusermetricsoutput/DataSource.h' |
264 | --- src/libusermetricsoutput/DataSource.h 2013-09-04 09:09:23 +0000 |
265 | +++ src/libusermetricsoutput/DataSource.h 2014-10-20 13:30:00 +0000 |
266 | @@ -24,6 +24,8 @@ |
267 | #include <QtCore/QSharedPointer> |
268 | #include <QtCore/QVariantMap> |
269 | |
270 | +#include <libusermetricscommon/Localisation.h> |
271 | + |
272 | namespace UserMetricsOutput { |
273 | |
274 | class DataSource; |
275 | @@ -85,6 +87,9 @@ |
276 | |
277 | void optionsChanged(const QVariantMap &options); |
278 | |
279 | +protected Q_SLOTS: |
280 | + void translationResult(const QString &result, const QString &requestId); |
281 | + |
282 | protected: |
283 | void updateFormatStringTranslation(); |
284 | |
285 | @@ -105,6 +110,8 @@ |
286 | MetricType m_type; |
287 | |
288 | QVariantMap m_options; |
289 | + |
290 | + ExternalGettext::Ptr m_externalGettext; |
291 | }; |
292 | |
293 | } |
294 | |
295 | === modified file 'src/libusermetricsoutput/UserMetricsImpl.cpp' |
296 | --- src/libusermetricsoutput/UserMetricsImpl.cpp 2014-09-16 08:14:45 +0000 |
297 | +++ src/libusermetricsoutput/UserMetricsImpl.cpp 2014-10-20 13:30:00 +0000 |
298 | @@ -214,6 +214,10 @@ |
299 | // we emit no signal if the data has stayed empty |
300 | } |
301 | |
302 | +void UserMetricsImpl::dataSourceStringsChanged() { |
303 | + updateCurrentDataSet(0); |
304 | +} |
305 | + |
306 | void UserMetricsImpl::updateCurrentDataSet(const QVariantList *newData) { |
307 | Q_UNUSED(newData); |
308 | |
309 | @@ -251,6 +255,16 @@ |
310 | secondMonthDate.daysInMonth(), dataIndex, end); |
311 | |
312 | DataSourcePtr dataSource(m_userMetricsStore->dataSource(dataSourcePath)); |
313 | + if (m_dataSourceFormatStringConnection) { |
314 | + disconnect(m_dataSourceFormatStringConnection); |
315 | + } |
316 | + if (m_dataSourceEmptyDataStringConnection) { |
317 | + disconnect(m_dataSourceEmptyDataStringConnection); |
318 | + } |
319 | + m_dataSourceFormatStringConnection = connect(dataSource.data(), SIGNAL(formatStringChanged(const QString &)), |
320 | + this, SLOT(dataSourceStringsChanged())); |
321 | + m_dataSourceEmptyDataStringConnection = connect(dataSource.data(), SIGNAL(emptyDataStringChanged(const QString &)), |
322 | + this, SLOT(dataSourceStringsChanged())); |
323 | if (dataSource.isNull()) { |
324 | qWarning() << _("Data source not found") << " [" << dataSourcePath << "]"; |
325 | } else { |
326 | @@ -272,9 +286,12 @@ |
327 | setLabel(emptyDataString); |
328 | } |
329 | } else { |
330 | - setLabel( |
331 | - dataSource->formatString().arg( |
332 | - m_dataSet->head().toString())); |
333 | + QString label; |
334 | + if (!dataSource->formatString().isEmpty()) { |
335 | + label = dataSource->formatString().arg( |
336 | + m_dataSet->head().toString()); |
337 | + } |
338 | + setLabel(label); |
339 | } |
340 | } |
341 | } |
342 | |
343 | === modified file 'src/libusermetricsoutput/UserMetricsImpl.h' |
344 | --- src/libusermetricsoutput/UserMetricsImpl.h 2013-07-17 11:40:21 +0000 |
345 | +++ src/libusermetricsoutput/UserMetricsImpl.h 2014-10-20 13:30:00 +0000 |
346 | @@ -74,6 +74,8 @@ |
347 | |
348 | virtual void dataSetAdded(const QString &dataSourceName); |
349 | |
350 | + virtual void dataSourceStringsChanged(); |
351 | + |
352 | protected: |
353 | virtual void prepareToLoadDataSource(); |
354 | |
355 | @@ -120,6 +122,10 @@ |
356 | UserData::const_iterator m_dataSetIterator; |
357 | |
358 | DataSetPtr m_dataSet; |
359 | + |
360 | + QMetaObject::Connection m_dataSourceFormatStringConnection; |
361 | + |
362 | + QMetaObject::Connection m_dataSourceEmptyDataStringConnection; |
363 | }; |
364 | |
365 | } |
366 | |
367 | === modified file 'tests/unit/libusermetricsoutput/TestSyncedUserMetricsStore.cpp' |
368 | --- tests/unit/libusermetricsoutput/TestSyncedUserMetricsStore.cpp 2013-10-22 08:53:23 +0000 |
369 | +++ tests/unit/libusermetricsoutput/TestSyncedUserMetricsStore.cpp 2014-10-20 13:30:00 +0000 |
370 | @@ -73,6 +73,9 @@ |
371 | { |
372 | DataSourcePtr dataSource(store.dataSource(DBusPaths::dataSource(1))); |
373 | ASSERT_FALSE(dataSource.isNull()); |
374 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
375 | + SIGNAL(emptyDataStringChanged(const QString &))); |
376 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
377 | EXPECT_EQ(QString("format string one %1"), dataSource->formatString()); |
378 | EXPECT_EQ(QString("empty data string one"), |
379 | dataSource->emptyDataString()); |
380 | @@ -82,6 +85,9 @@ |
381 | { |
382 | DataSourcePtr dataSource(store.dataSource(DBusPaths::dataSource(2))); |
383 | ASSERT_FALSE(dataSource.isNull()); |
384 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
385 | + SIGNAL(emptyDataStringChanged(const QString &))); |
386 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
387 | EXPECT_EQ(QString("format string two %1"), dataSource->formatString()); |
388 | EXPECT_EQ(QString("empty data string two"), |
389 | dataSource->emptyDataString()); |
390 | @@ -107,6 +113,9 @@ |
391 | { |
392 | DataSourcePtr dataSource(store.dataSource(DBusPaths::dataSource(1))); |
393 | ASSERT_FALSE(dataSource.isNull()); |
394 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
395 | + SIGNAL(formatStringChanged(const QString &))); |
396 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
397 | EXPECT_EQ(QString("format string one %1"), dataSource->formatString()); |
398 | EXPECT_EQ(QString("text-domain-one"), dataSource->textDomain()); |
399 | } |
400 | @@ -130,6 +139,11 @@ |
401 | { |
402 | DataSourcePtr dataSource(store.dataSource(DBusPaths::dataSource(1))); |
403 | ASSERT_FALSE(dataSource.isNull()); |
404 | + if (dataSource->emptyDataString().isEmpty()) { |
405 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
406 | + SIGNAL(emptyDataStringChanged(const QString &))); |
407 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
408 | + } |
409 | EXPECT_EQ(QString("format string one %1"), dataSource->formatString()); |
410 | EXPECT_EQ(QString("no data source ones"), |
411 | dataSource->emptyDataString()); |
412 | @@ -139,6 +153,9 @@ |
413 | { |
414 | DataSourcePtr dataSource(store.dataSource(DBusPaths::dataSource(2))); |
415 | ASSERT_FALSE(dataSource.isNull()); |
416 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
417 | + SIGNAL(emptyDataStringChanged(const QString &))); |
418 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
419 | EXPECT_EQ(QString("format string two %1"), dataSource->formatString()); |
420 | EXPECT_EQ(QString("no data source twos"), |
421 | dataSource->emptyDataString()); |
422 | |
423 | === modified file 'tests/unit/libusermetricsoutput/TestUserMetricsImpl.cpp' |
424 | --- tests/unit/libusermetricsoutput/TestUserMetricsImpl.cpp 2013-09-04 09:09:23 +0000 |
425 | +++ tests/unit/libusermetricsoutput/TestUserMetricsImpl.cpp 2014-10-20 13:30:00 +0000 |
426 | @@ -190,6 +190,8 @@ |
427 | } |
428 | |
429 | DataSourcePtr dataSource(new DataSource()); |
430 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
431 | + SIGNAL(formatStringChanged(const QString &))); |
432 | dataSource->setFormatString("test format string %1"); |
433 | userDataStore->insert("data-source-id", dataSource); |
434 | |
435 | @@ -215,6 +217,7 @@ |
436 | dataSet->setLastUpdated(QDate(2001, 01, 07)); |
437 | dataSet->setData(data); |
438 | |
439 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
440 | EXPECT_EQ(QString("test format string 1").toStdString(), |
441 | model->label().toStdString()); |
442 | |
443 | @@ -282,6 +285,8 @@ |
444 | data << 70.0 << 65.0; |
445 | |
446 | DataSourcePtr dataSource(new DataSource()); |
447 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
448 | + SIGNAL(formatStringChanged(const QString &))); |
449 | dataSource->setFormatString("test format string %1"); |
450 | userDataStore->insert("data-source-id", dataSource); |
451 | |
452 | @@ -307,6 +312,7 @@ |
453 | model->setUsername("username"); |
454 | model->readyForDataChangeSlot(); |
455 | |
456 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
457 | EXPECT_EQ(QString("test format string 100"), model->label()); |
458 | |
459 | // assertions about first month's data |
460 | @@ -342,6 +348,8 @@ |
461 | |
462 | TEST_F(UserMetricsImplTest, FollowsCurrentDataSource) { |
463 | DataSourcePtr dataSource(new DataSource()); |
464 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
465 | + SIGNAL(formatStringChanged(const QString &))); |
466 | dataSource->setFormatString("test format string %1"); |
467 | userDataStore->insert("data-source-id", dataSource); |
468 | |
469 | @@ -367,6 +375,7 @@ |
470 | model->setUsername("username"); |
471 | model->readyForDataChangeSlot(); |
472 | |
473 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
474 | EXPECT_EQ(QString("test format string 100"), model->label()); |
475 | |
476 | // assertions about first month's data |
477 | @@ -414,6 +423,8 @@ |
478 | setLanguage("en_FAKELANG"); |
479 | |
480 | DataSourcePtr dataSource(new DataSource(TEST_LOCALEDIR)); |
481 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
482 | + SIGNAL(formatStringChanged(const QString &))); |
483 | dataSource->setFormatString("%1 untranslated messages received"); |
484 | dataSource->setTextDomain("foo"); |
485 | userDataStore->insert("data-source-id", dataSource); |
486 | @@ -440,6 +451,8 @@ |
487 | model->setUsername("username"); |
488 | model->readyForDataChangeSlot(); |
489 | |
490 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
491 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
492 | EXPECT_EQ(QString("100 translated messages received").toStdString(), |
493 | model->label().toStdString()); |
494 | |
495 | @@ -454,6 +467,8 @@ |
496 | setLanguage("en_FAKELANG"); |
497 | |
498 | DataSourcePtr dataSource(new DataSource(TEST_LOCALEDIR)); |
499 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
500 | + SIGNAL(emptyDataStringChanged(const QString &))); |
501 | dataSource->setFormatString("%1 untranslated messages received"); |
502 | dataSource->setEmptyDataString("no untranslated messages today"); |
503 | dataSource->setTextDomain("foo"); |
504 | @@ -481,6 +496,8 @@ |
505 | model->setUsername("username"); |
506 | model->readyForDataChangeSlot(); |
507 | |
508 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
509 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
510 | EXPECT_EQ(QString("no translated messages today").toStdString(), |
511 | model->label().toStdString()); |
512 | |
513 | @@ -504,6 +521,8 @@ |
514 | data << 70.0 << 65.0; |
515 | |
516 | DataSourcePtr dataSource(new DataSource()); |
517 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
518 | + SIGNAL(emptyDataStringChanged(const QString &))); |
519 | dataSource->setFormatString("test other format string %1"); |
520 | dataSource->setEmptyDataString("no data source two"); |
521 | userDataStore->insert("data-source-id2", dataSource); |
522 | @@ -530,7 +549,8 @@ |
523 | model->setUsername("username"); |
524 | model->readyForDataChangeSlot(); |
525 | |
526 | - EXPECT_EQ(QString("no data source two"), model->label()); |
527 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
528 | + EXPECT_EQ(QString("no data source two").toStdString(), model->label().toStdString()); |
529 | |
530 | // assertions about first month's data |
531 | { |
532 | @@ -573,6 +593,8 @@ |
533 | data << 95.0 << 100.0 << 90.0 << 0.0; |
534 | |
535 | DataSourcePtr dataSource(new DataSource()); |
536 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
537 | + SIGNAL(emptyDataStringChanged(const QString &))); |
538 | dataSource->setFormatString("this format string won't be used %1"); |
539 | dataSource->setEmptyDataString("there's no data"); |
540 | userDataStore->insert("data-source-id", dataSource); |
541 | @@ -599,6 +621,7 @@ |
542 | model->setUsername("username"); |
543 | model->readyForDataChangeSlot(); |
544 | |
545 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
546 | EXPECT_EQ(QString("there's no data"), model->label()); |
547 | |
548 | // assertions about first month's data |
549 | @@ -638,6 +661,8 @@ |
550 | data << 100.0 << 0.0; |
551 | |
552 | DataSourcePtr dataSource(new DataSource()); |
553 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
554 | + SIGNAL(formatStringChanged(const QString &))); |
555 | dataSource->setFormatString("a format string with %1 in it"); |
556 | userDataStore->insert("data-source-id", dataSource); |
557 | |
558 | @@ -663,6 +688,7 @@ |
559 | model->setUsername("username"); |
560 | model->readyForDataChangeSlot(); |
561 | |
562 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
563 | EXPECT_EQ(QString("No data for today (data-source-id)"), model->label()); |
564 | |
565 | // assertions about first month's data |
566 | @@ -702,6 +728,8 @@ |
567 | // first data set |
568 | { |
569 | DataSourcePtr dataSource(new DataSource()); |
570 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
571 | + SIGNAL(emptyDataStringChanged(const QString &))); |
572 | dataSource->setFormatString("data source one %1 value"); |
573 | dataSource->setEmptyDataString("no data source one"); |
574 | userDataStore->insert("data-source-one", dataSource); |
575 | @@ -713,11 +741,15 @@ |
576 | DataSetPtr dataSet(*dataSetIterator); |
577 | dataSet->setLastUpdated(QDate(2001, 1, 4)); |
578 | dataSet->setData(data); |
579 | + |
580 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
581 | } |
582 | |
583 | // second data set |
584 | { |
585 | DataSourcePtr dataSource(new DataSource()); |
586 | + QSignalSpy emptyDataStringChangedSpy(dataSource.data(), |
587 | + SIGNAL(emptyDataStringChanged(const QString &))); |
588 | dataSource->setFormatString("data source 2 %1 value"); |
589 | dataSource->setEmptyDataString("no data source two"); |
590 | userDataStore->insert("data-source-two", dataSource); |
591 | @@ -730,6 +762,8 @@ |
592 | DataSetPtr dataSet(*dataSetIterator); |
593 | dataSet->setLastUpdated(QDate(2001, 1, 7)); |
594 | dataSet->setData(data); |
595 | + |
596 | + ASSERT_TRUE(emptyDataStringChangedSpy.wait()); |
597 | } |
598 | |
599 | QSharedPointer<ColorTheme> blankColorTheme( |
600 | @@ -820,6 +854,8 @@ |
601 | // first data set |
602 | { |
603 | DataSourcePtr dataSource(new DataSource()); |
604 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
605 | + SIGNAL(formatStringChanged(const QString &))); |
606 | dataSource->setFormatString("data source one %1 value"); |
607 | userDataStore->insert("data-source-one", dataSource); |
608 | |
609 | @@ -831,11 +867,14 @@ |
610 | dataSet->setLastUpdated(QDate(2001, 1, 7)); |
611 | dataSet->setData(data); |
612 | |
613 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
614 | } |
615 | |
616 | // second data set |
617 | { |
618 | DataSourcePtr dataSource(new DataSource()); |
619 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
620 | + SIGNAL(formatStringChanged(const QString &))); |
621 | dataSource->setFormatString("data source two %1 value"); |
622 | userDataStore->insert("data-source-two", dataSource); |
623 | |
624 | @@ -847,6 +886,8 @@ |
625 | DataSetPtr dataSet(*dataSetIterator); |
626 | dataSet->setLastUpdated(QDate(2001, 1, 7)); |
627 | dataSet->setData(data); |
628 | + |
629 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
630 | } |
631 | } |
632 | |
633 | @@ -861,6 +902,8 @@ |
634 | // fourth data set |
635 | { |
636 | DataSourcePtr dataSource(new DataSource()); |
637 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
638 | + SIGNAL(formatStringChanged(const QString &))); |
639 | dataSource->setFormatString("data source three %1 value"); |
640 | userDataStore->insert("data-source-three", dataSource); |
641 | |
642 | @@ -872,12 +915,16 @@ |
643 | DataSetPtr dataSet(*dataSetIterator); |
644 | dataSet->setLastUpdated(QDate(2001, 1, 7)); |
645 | dataSet->setData(data); |
646 | + |
647 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
648 | } |
649 | |
650 | // fifth data set |
651 | { |
652 | |
653 | DataSourcePtr dataSource(new DataSource()); |
654 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
655 | + SIGNAL(formatStringChanged(const QString &))); |
656 | dataSource->setFormatString("data source four %1 value"); |
657 | userDataStore->insert("data-source-xfour", dataSource); |
658 | |
659 | @@ -889,6 +936,8 @@ |
660 | DataSetPtr dataSet(*dataSetIterator); |
661 | dataSet->setLastUpdated(QDate(2001, 1, 7)); |
662 | dataSet->setData(data); |
663 | + |
664 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
665 | } |
666 | } |
667 | |
668 | @@ -1148,6 +1197,8 @@ |
669 | data << 100.0 << 95.0 << -100.0; |
670 | |
671 | DataSourcePtr dataSource(new DataSource()); |
672 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
673 | + SIGNAL(formatStringChanged(const QString &))); |
674 | dataSource->setFormatString("test format string %1"); |
675 | QVariantMap options; |
676 | options["minimum"] = 0.0; |
677 | @@ -1176,6 +1227,7 @@ |
678 | model->setUsername("username"); |
679 | model->readyForDataChangeSlot(); |
680 | |
681 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
682 | EXPECT_EQ(QString("test format string 100"), model->label()); |
683 | |
684 | // assertions about first month's data |
685 | @@ -1199,6 +1251,8 @@ |
686 | data << 0.0 << 5.0 << 200.0; |
687 | |
688 | DataSourcePtr dataSource(new DataSource()); |
689 | + QSignalSpy formatStringChangedSpy(dataSource.data(), |
690 | + SIGNAL(formatStringChanged(const QString &))); |
691 | dataSource->setFormatString("test format string %1"); |
692 | QVariantMap options; |
693 | options["maximum"] = 100.0; |
694 | @@ -1227,6 +1281,7 @@ |
695 | model->setUsername("username"); |
696 | model->readyForDataChangeSlot(); |
697 | |
698 | + ASSERT_TRUE(formatStringChangedSpy.wait()); |
699 | EXPECT_EQ(QString("test format string 0"), model->label()); |
700 | |
701 | // assertions about first month's data |
702 | |
703 | === modified file 'tests/unit/qml/tst_Metrics.qml' |
704 | --- tests/unit/qml/tst_Metrics.qml 2013-10-02 09:34:27 +0000 |
705 | +++ tests/unit/qml/tst_Metrics.qml 2014-10-20 13:30:00 +0000 |
706 | @@ -50,20 +50,20 @@ |
707 | metric.minimum = 0.0 |
708 | metric.maximum = 10.0 |
709 | info = dbusQuery.queryMetricInfo(1); |
710 | - compare(info.minimum, 0.0, "Metric minimum was not set properly"); |
711 | - compare(info.maximum, 10.0, "Metric maximum was not set properly"); |
712 | + fuzzyCompare(info.minimum, 0.0, 0.01, "Metric minimum was not set properly"); |
713 | + fuzzyCompare(info.maximum, 10.0, 0.01, "Metric maximum was not set properly"); |
714 | |
715 | // Test update and increment with integers and floating point data |
716 | metric.update(0); |
717 | - compare(dbusQuery.queryCurrentValue(1), 0, "Data not updated successfully") |
718 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 0, 0.01, "Data not updated successfully") |
719 | metric.increment(); |
720 | - compare(dbusQuery.queryCurrentValue(1), 1, "Data not incremented successfully") |
721 | + compare(dbusQuery.queryCurrentValue(1), 1, 0.01, "Data not incremented successfully") |
722 | metric.increment(7776); |
723 | - compare(dbusQuery.queryCurrentValue(1), 7777, "Data not incremented successfully") |
724 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 7777, 0.01, "Data not incremented successfully") |
725 | metric.increment(0.999); |
726 | - compare(dbusQuery.queryCurrentValue(1), 7777.999, "Data not incremented successfully") |
727 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 7777.999, 0.01, "Data not incremented successfully") |
728 | metric.update(5.5); |
729 | - compare(dbusQuery.queryCurrentValue(1), 5.5, "Data not updated successfully") |
730 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 5.5, 0.01, "Data not updated successfully") |
731 | |
732 | // Check that when changing the metric format or emptyFormat nothing else changes and |
733 | // no new metrics are created |
734 | @@ -93,18 +93,18 @@ |
735 | // Check that now the "metric" object points to the newly created metric and changes to it don't |
736 | // affect the old metric |
737 | metric.update(0); |
738 | - compare(dbusQuery.queryCurrentValue(1), 5.5, "Metric 1 data was changed while metric 2 was in use"); |
739 | - compare(dbusQuery.queryCurrentValue(2), 0, "Metric 2 data was not updated correctly"); |
740 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 5.5, 0.01, "Metric 1 data was changed while metric 2 was in use"); |
741 | + fuzzyCompare(dbusQuery.queryCurrentValue(2), 0, 0.01, "Metric 2 data was not updated correctly"); |
742 | metric.increment(1.5); |
743 | - compare(dbusQuery.queryCurrentValue(1), 5.5, "Metric 1 data was changed while metric 2 was in use"); |
744 | - compare(dbusQuery.queryCurrentValue(2), 1.5, "Metric 2 data was not incremented correctly"); |
745 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 5.5, 0.01, "Metric 1 data was changed while metric 2 was in use"); |
746 | + fuzzyCompare(dbusQuery.queryCurrentValue(2), 1.5, 0.01, "Metric 2 data was not incremented correctly"); |
747 | |
748 | // Make sure that making the "metric" object point back to the original metric by restoring the |
749 | // original name works fine and has no side effects. |
750 | metric.name = originalName; |
751 | metric.update(0); |
752 | - compare(dbusQuery.queryCurrentValue(1), 0, "Metric 1 data was not changed when pointing to it"); |
753 | - compare(dbusQuery.queryCurrentValue(2), 1.5, "Metric 2 data was changed when pointing to metric 1"); |
754 | + fuzzyCompare(dbusQuery.queryCurrentValue(1), 0, 0.01, "Metric 1 data was not changed when pointing to it"); |
755 | + fuzzyCompare(dbusQuery.queryCurrentValue(2), 1.5, 0.01, "Metric 2 data was changed when pointing to metric 1"); |
756 | info = dbusQuery.queryMetricInfo(3); |
757 | compare(info, null, "A new metric shouldn't have been created when pointing back to metric 1"); |
758 | } |
Code looks good to me.