Merge lp:~mardy/ubuntu-system-settings-online-accounts/lp1373279 into lp:~online-accounts/ubuntu-system-settings-online-accounts/master
- lp1373279
- Merge into master
Proposed by
Alberto Mardegan
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 227 | ||||
Proposed branch: | lp:~mardy/ubuntu-system-settings-online-accounts/lp1373279 | ||||
Merge into: | lp:~online-accounts/ubuntu-system-settings-online-accounts/master | ||||
Diff against target: |
580 lines (+505/-8) 8 files modified
.bzrignore (+1/-0) system-settings-plugin/online-accounts.settings (+2/-6) system-settings-plugin/plugin.cpp (+116/-0) system-settings-plugin/plugin.h (+36/-0) system-settings-plugin/system-settings-plugin.pro (+24/-1) tests/system-settings-plugin/system-settings-plugin.pro (+32/-0) tests/system-settings-plugin/tst_plugin.cpp (+292/-0) tests/tests.pro (+2/-1) |
||||
To merge this branch: | bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/lp1373279 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandre Abreu (community) | Approve | ||
Review via email: mp+247453@code.launchpad.net |
Commit message
Add account data as search keywords
Description of the change
Add account data as search keywords
To post a comment you must log in.
- 226. By Alberto Mardegan
-
Avoid inserting duplicate keywords
- 227. By Alberto Mardegan
-
Added tests
- 228. By Alberto Mardegan
-
Remove unnecessary friend
Revision history for this message
Alberto Mardegan (mardy) wrote : | # |
I fixed the code as suggested by Alex, and added some unit tests.
Revision history for this message
Alexandre Abreu (abreu-alexandre) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2014-12-11 12:51:46 +0000 | |||
3 | +++ .bzrignore 2015-02-02 15:22:49 +0000 | |||
4 | @@ -57,3 +57,4 @@ | |||
5 | 57 | /tests/online-accounts-ui/tst_notification | 57 | /tests/online-accounts-ui/tst_notification |
6 | 58 | /tests/online-accounts-ui/tst_signonui_request | 58 | /tests/online-accounts-ui/tst_signonui_request |
7 | 59 | /tests/plugin/tst_application_manager | 59 | /tests/plugin/tst_application_manager |
8 | 60 | /tests/system-settings-plugin/tst_plugin | ||
9 | 60 | 61 | ||
10 | === modified file 'system-settings-plugin/online-accounts.settings' | |||
11 | --- system-settings-plugin/online-accounts.settings 2014-09-24 19:05:32 +0000 | |||
12 | +++ system-settings-plugin/online-accounts.settings 2015-02-02 15:22:49 +0000 | |||
13 | @@ -14,14 +14,10 @@ | |||
14 | 14 | "access", | 14 | "access", |
15 | 15 | "authorize", | 15 | "authorize", |
16 | 16 | "revoke", | 16 | "revoke", |
23 | 17 | "web", | 17 | "web" |
18 | 18 | "facebook", | ||
19 | 19 | "twitter", | ||
20 | 20 | "flickr", | ||
21 | 21 | "google", | ||
22 | 22 | "gmail" | ||
24 | 23 | ], | 18 | ], |
25 | 24 | "has-dynamic-keywords": true, | 19 | "has-dynamic-keywords": true, |
26 | 25 | "has-dynamic-visibility": false, | 20 | "has-dynamic-visibility": false, |
27 | 21 | "plugin": "online-accounts", | ||
28 | 26 | "page-component": "MainPage.qml" | 22 | "page-component": "MainPage.qml" |
29 | 27 | } | 23 | } |
30 | 28 | 24 | ||
31 | === added file 'system-settings-plugin/plugin.cpp' | |||
32 | --- system-settings-plugin/plugin.cpp 1970-01-01 00:00:00 +0000 | |||
33 | +++ system-settings-plugin/plugin.cpp 2015-02-02 15:22:49 +0000 | |||
34 | @@ -0,0 +1,116 @@ | |||
35 | 1 | /* | ||
36 | 2 | * Copyright (C) 2015 Canonical Ltd. | ||
37 | 3 | * | ||
38 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
39 | 5 | * | ||
40 | 6 | * This program is free software: you can redistribute it and/or modify it | ||
41 | 7 | * under the terms of the GNU General Public License version 3, as published | ||
42 | 8 | * by the Free Software Foundation. | ||
43 | 9 | * | ||
44 | 10 | * This program is distributed in the hope that it will be useful, but | ||
45 | 11 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
46 | 12 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
47 | 13 | * PURPOSE. See the GNU General Public License for more details. | ||
48 | 14 | * | ||
49 | 15 | * You should have received a copy of the GNU General Public License along | ||
50 | 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
51 | 17 | */ | ||
52 | 18 | |||
53 | 19 | #include "plugin.h" | ||
54 | 20 | |||
55 | 21 | #include <Accounts/Account> | ||
56 | 22 | #include <Accounts/Manager> | ||
57 | 23 | #include <Accounts/Provider> | ||
58 | 24 | #include <Accounts/Service> | ||
59 | 25 | #include <QDebug> | ||
60 | 26 | #include <QStringList> | ||
61 | 27 | #include <SystemSettings/ItemBase> | ||
62 | 28 | #include <libintl.h> | ||
63 | 29 | |||
64 | 30 | using namespace SystemSettings; | ||
65 | 31 | |||
66 | 32 | class Item: public ItemBase | ||
67 | 33 | { | ||
68 | 34 | Q_OBJECT | ||
69 | 35 | |||
70 | 36 | public: | ||
71 | 37 | Item(const QVariantMap &staticData, QObject *parent = 0); | ||
72 | 38 | ~Item(); | ||
73 | 39 | |||
74 | 40 | private: | ||
75 | 41 | void computeKeywords(); | ||
76 | 42 | }; | ||
77 | 43 | |||
78 | 44 | Item::Item(const QVariantMap &staticData, QObject *parent): | ||
79 | 45 | ItemBase(staticData, parent) | ||
80 | 46 | { | ||
81 | 47 | computeKeywords(); | ||
82 | 48 | } | ||
83 | 49 | |||
84 | 50 | Item::~Item() | ||
85 | 51 | { | ||
86 | 52 | } | ||
87 | 53 | |||
88 | 54 | static QStringList translations(const QString &text, const QString &domain) | ||
89 | 55 | { | ||
90 | 56 | /* Return a list of keywords based on a translatable name: | ||
91 | 57 | * - the untranslated text (lowercase, split into words) | ||
92 | 58 | * - the translated text (lowercase, split into words) | ||
93 | 59 | */ | ||
94 | 60 | QStringList keys; | ||
95 | 61 | keys = text.toLower().split(" ", QString::SkipEmptyParts); | ||
96 | 62 | if (!domain.isEmpty()) { | ||
97 | 63 | QByteArray baText = text.toUtf8(); | ||
98 | 64 | QByteArray baDomain = domain.toUtf8(); | ||
99 | 65 | QString translated = QString::fromUtf8(dgettext(baDomain.constData(), | ||
100 | 66 | baText.constData())); | ||
101 | 67 | if (translated != text) { | ||
102 | 68 | keys.append(translated.toLower().split(" ", | ||
103 | 69 | QString::SkipEmptyParts)); | ||
104 | 70 | } | ||
105 | 71 | } | ||
106 | 72 | return keys; | ||
107 | 73 | } | ||
108 | 74 | |||
109 | 75 | void Item::computeKeywords() | ||
110 | 76 | { | ||
111 | 77 | Accounts::Manager *manager = new Accounts::Manager; | ||
112 | 78 | |||
113 | 79 | QStringList keywords; | ||
114 | 80 | |||
115 | 81 | /* List available providers, and add their names to the search keywords */ | ||
116 | 82 | Q_FOREACH(const Accounts::Provider &provider, manager->providerList()) { | ||
117 | 83 | keywords.append(provider.name().toLower()); | ||
118 | 84 | keywords.append(translations(provider.displayName(), | ||
119 | 85 | provider.trCatalog())); | ||
120 | 86 | } | ||
121 | 87 | |||
122 | 88 | /* Same for services */ | ||
123 | 89 | Q_FOREACH(const Accounts::Service &service, manager->serviceList()) { | ||
124 | 90 | keywords.append(service.name().toLower()); | ||
125 | 91 | keywords.append(translations(service.displayName(), | ||
126 | 92 | service.trCatalog())); | ||
127 | 93 | } | ||
128 | 94 | |||
129 | 95 | /* Also add the account display names */ | ||
130 | 96 | Q_FOREACH(Accounts::AccountId id, manager->accountList()) { | ||
131 | 97 | Accounts::Account *account = manager->account(id); | ||
132 | 98 | if (Q_UNLIKELY(!account)) continue; | ||
133 | 99 | QString name = account->displayName().toLower(); | ||
134 | 100 | if (!name.isEmpty()) { | ||
135 | 101 | keywords.append(name); | ||
136 | 102 | } | ||
137 | 103 | } | ||
138 | 104 | |||
139 | 105 | delete manager; | ||
140 | 106 | |||
141 | 107 | setKeywords(keywords); | ||
142 | 108 | } | ||
143 | 109 | |||
144 | 110 | ItemBase *Plugin::createItem(const QVariantMap &staticData, | ||
145 | 111 | QObject *parent) | ||
146 | 112 | { | ||
147 | 113 | return new Item(staticData, parent); | ||
148 | 114 | } | ||
149 | 115 | |||
150 | 116 | #include "plugin.moc" | ||
151 | 0 | 117 | ||
152 | === added file 'system-settings-plugin/plugin.h' | |||
153 | --- system-settings-plugin/plugin.h 1970-01-01 00:00:00 +0000 | |||
154 | +++ system-settings-plugin/plugin.h 2015-02-02 15:22:49 +0000 | |||
155 | @@ -0,0 +1,36 @@ | |||
156 | 1 | /* | ||
157 | 2 | * Copyright (C) 2015 Canonical Ltd. | ||
158 | 3 | * | ||
159 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
160 | 5 | * | ||
161 | 6 | * This program is free software: you can redistribute it and/or modify it | ||
162 | 7 | * under the terms of the GNU General Public License version 3, as published | ||
163 | 8 | * by the Free Software Foundation. | ||
164 | 9 | * | ||
165 | 10 | * This program is distributed in the hope that it will be useful, but | ||
166 | 11 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
167 | 12 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
168 | 13 | * PURPOSE. See the GNU General Public License for more details. | ||
169 | 14 | * | ||
170 | 15 | * You should have received a copy of the GNU General Public License along | ||
171 | 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
172 | 17 | */ | ||
173 | 18 | |||
174 | 19 | #ifndef ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H | ||
175 | 20 | #define ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H | ||
176 | 21 | |||
177 | 22 | #include <QObject> | ||
178 | 23 | #include <SystemSettings/PluginInterface> | ||
179 | 24 | |||
180 | 25 | class Plugin: public QObject, public SystemSettings::PluginInterface2 | ||
181 | 26 | { | ||
182 | 27 | Q_OBJECT | ||
183 | 28 | Q_PLUGIN_METADATA(IID "com.ubuntu.SystemSettings.PluginInterface/2.0") | ||
184 | 29 | Q_INTERFACES(SystemSettings::PluginInterface2) | ||
185 | 30 | |||
186 | 31 | public: | ||
187 | 32 | SystemSettings::ItemBase *createItem(const QVariantMap &staticData, | ||
188 | 33 | QObject *parent = 0); | ||
189 | 34 | }; | ||
190 | 35 | |||
191 | 36 | #endif // ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H | ||
192 | 0 | 37 | ||
193 | === modified file 'system-settings-plugin/system-settings-plugin.pro' | |||
194 | --- system-settings-plugin/system-settings-plugin.pro 2014-08-13 13:11:06 +0000 | |||
195 | +++ system-settings-plugin/system-settings-plugin.pro 2015-02-02 15:22:49 +0000 | |||
196 | @@ -1,7 +1,27 @@ | |||
197 | 1 | include(../common-project-config.pri) | 1 | include(../common-project-config.pri) |
198 | 2 | include($${TOP_SRC_DIR}/common-vars.pri) | 2 | include($${TOP_SRC_DIR}/common-vars.pri) |
199 | 3 | 3 | ||
201 | 4 | TEMPLATE=aux | 4 | TEMPLATE=lib |
202 | 5 | TARGET = online-accounts | ||
203 | 6 | |||
204 | 7 | CONFIG += \ | ||
205 | 8 | link_pkgconfig \ | ||
206 | 9 | plugin \ | ||
207 | 10 | qt | ||
208 | 11 | |||
209 | 12 | QT += \ | ||
210 | 13 | core \ | ||
211 | 14 | qml | ||
212 | 15 | |||
213 | 16 | PKGCONFIG += \ | ||
214 | 17 | SystemSettings \ | ||
215 | 18 | accounts-qt5 | ||
216 | 19 | |||
217 | 20 | SOURCES += \ | ||
218 | 21 | plugin.cpp | ||
219 | 22 | |||
220 | 23 | HEADERS += \ | ||
221 | 24 | plugin.h | ||
222 | 5 | 25 | ||
223 | 6 | QML_SOURCES = \ | 26 | QML_SOURCES = \ |
224 | 7 | AccountEditPage.qml \ | 27 | AccountEditPage.qml \ |
225 | @@ -19,6 +39,9 @@ | |||
226 | 19 | settings.path = $${PLUGIN_MANIFEST_DIR} | 39 | settings.path = $${PLUGIN_MANIFEST_DIR} |
227 | 20 | INSTALLS += settings | 40 | INSTALLS += settings |
228 | 21 | 41 | ||
229 | 42 | target.path = $${PLUGIN_MODULE_DIR} | ||
230 | 43 | INSTALLS += target | ||
231 | 44 | |||
232 | 22 | image.files = settings-accounts.svg | 45 | image.files = settings-accounts.svg |
233 | 23 | image.path = $${PLUGIN_MANIFEST_DIR}/icons | 46 | image.path = $${PLUGIN_MANIFEST_DIR}/icons |
234 | 24 | INSTALLS += image | 47 | INSTALLS += image |
235 | 25 | 48 | ||
236 | === added directory 'tests/system-settings-plugin' | |||
237 | === added file 'tests/system-settings-plugin/system-settings-plugin.pro' | |||
238 | --- tests/system-settings-plugin/system-settings-plugin.pro 1970-01-01 00:00:00 +0000 | |||
239 | +++ tests/system-settings-plugin/system-settings-plugin.pro 2015-02-02 15:22:49 +0000 | |||
240 | @@ -0,0 +1,32 @@ | |||
241 | 1 | include(../../common-project-config.pri) | ||
242 | 2 | |||
243 | 3 | TARGET = tst_plugin | ||
244 | 4 | |||
245 | 5 | CONFIG += \ | ||
246 | 6 | debug \ | ||
247 | 7 | link_pkgconfig | ||
248 | 8 | |||
249 | 9 | QT += \ | ||
250 | 10 | core \ | ||
251 | 11 | qml \ | ||
252 | 12 | testlib | ||
253 | 13 | |||
254 | 14 | PKGCONFIG += \ | ||
255 | 15 | SystemSettings \ | ||
256 | 16 | accounts-qt5 | ||
257 | 17 | |||
258 | 18 | SYSTEM_SETTINGS_PLUGIN_DIR = $${TOP_SRC_DIR}/system-settings-plugin | ||
259 | 19 | |||
260 | 20 | INCLUDEPATH += \ | ||
261 | 21 | $${SYSTEM_SETTINGS_PLUGIN_DIR} | ||
262 | 22 | |||
263 | 23 | SOURCES += \ | ||
264 | 24 | $${SYSTEM_SETTINGS_PLUGIN_DIR}/plugin.cpp \ | ||
265 | 25 | tst_plugin.cpp | ||
266 | 26 | |||
267 | 27 | HEADERS += \ | ||
268 | 28 | $${SYSTEM_SETTINGS_PLUGIN_DIR}/plugin.h | ||
269 | 29 | |||
270 | 30 | check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}" | ||
271 | 31 | check.depends = $${TARGET} | ||
272 | 32 | QMAKE_EXTRA_TARGETS += check | ||
273 | 0 | 33 | ||
274 | === added file 'tests/system-settings-plugin/tst_plugin.cpp' | |||
275 | --- tests/system-settings-plugin/tst_plugin.cpp 1970-01-01 00:00:00 +0000 | |||
276 | +++ tests/system-settings-plugin/tst_plugin.cpp 2015-02-02 15:22:49 +0000 | |||
277 | @@ -0,0 +1,292 @@ | |||
278 | 1 | /* | ||
279 | 2 | * Copyright (C) 2014 Canonical Ltd. | ||
280 | 3 | * | ||
281 | 4 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
282 | 5 | * | ||
283 | 6 | * This file is part of online-accounts-ui | ||
284 | 7 | * | ||
285 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
286 | 9 | * under the terms of the GNU General Public License version 3, as published | ||
287 | 10 | * by the Free Software Foundation. | ||
288 | 11 | * | ||
289 | 12 | * This program is distributed in the hope that it will be useful, but | ||
290 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
291 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
292 | 15 | * PURPOSE. See the GNU General Public License for more details. | ||
293 | 16 | * | ||
294 | 17 | * You should have received a copy of the GNU General Public License along | ||
295 | 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
296 | 19 | */ | ||
297 | 20 | |||
298 | 21 | #include <Accounts/Account> | ||
299 | 22 | #include <Accounts/Manager> | ||
300 | 23 | |||
301 | 24 | #include <QDebug> | ||
302 | 25 | #include <QDir> | ||
303 | 26 | #include <QDomDocument> | ||
304 | 27 | #include <QDomElement> | ||
305 | 28 | #include <QFile> | ||
306 | 29 | #include <QSignalSpy> | ||
307 | 30 | #include <QTemporaryDir> | ||
308 | 31 | #include <QTest> | ||
309 | 32 | |||
310 | 33 | #include <SystemSettings/ItemBase> | ||
311 | 34 | |||
312 | 35 | #include "plugin.h" | ||
313 | 36 | |||
314 | 37 | namespace QTest { | ||
315 | 38 | template<> | ||
316 | 39 | char *toString(const QSet<QString> &set) | ||
317 | 40 | { | ||
318 | 41 | QByteArray ba = "QSet<QString>("; | ||
319 | 42 | QStringList list = set.toList(); | ||
320 | 43 | ba += list.join(", "); | ||
321 | 44 | ba += ")"; | ||
322 | 45 | return qstrdup(ba.data()); | ||
323 | 46 | } | ||
324 | 47 | } // QTest namespace | ||
325 | 48 | |||
326 | 49 | /* mocking libintl { */ | ||
327 | 50 | static QHash<QString,QHash<QByteArray,QByteArray> > m_translations; | ||
328 | 51 | extern "C" { | ||
329 | 52 | char *dgettext(const char *domainname, const char *msgid) | ||
330 | 53 | { | ||
331 | 54 | return (char *)m_translations[domainname].value(msgid).data(); | ||
332 | 55 | } | ||
333 | 56 | char *dcgettext(const char *__domainname, const char *__msgid, int __category) | ||
334 | 57 | { | ||
335 | 58 | Q_UNUSED(__category); | ||
336 | 59 | return dgettext(__domainname, __msgid); | ||
337 | 60 | } | ||
338 | 61 | } // extern C | ||
339 | 62 | /* } mocking libintl */ | ||
340 | 63 | |||
341 | 64 | class PluginTest: public QObject | ||
342 | 65 | { | ||
343 | 66 | Q_OBJECT | ||
344 | 67 | |||
345 | 68 | struct FileData { | ||
346 | 69 | FileData() {} | ||
347 | 70 | FileData(const QString &name, const QString &domain): | ||
348 | 71 | name(name), domain(domain) {} | ||
349 | 72 | QString name; | ||
350 | 73 | QString domain; | ||
351 | 74 | }; | ||
352 | 75 | |||
353 | 76 | public: | ||
354 | 77 | PluginTest(); | ||
355 | 78 | |||
356 | 79 | private Q_SLOTS: | ||
357 | 80 | void testKeywords_data(); | ||
358 | 81 | void testKeywords(); | ||
359 | 82 | |||
360 | 83 | private: | ||
361 | 84 | void setDataDir(const QTemporaryDir &dir); | ||
362 | 85 | void writeProvider(const QString &id, const QString &name, | ||
363 | 86 | const QString &domain); | ||
364 | 87 | void writeService(const QString &id, const QString &name, | ||
365 | 88 | const QString &domain); | ||
366 | 89 | void writeLibaccountsFile(const QString &type, const QString &id, | ||
367 | 90 | const QString &name, const QString &domain); | ||
368 | 91 | void createAccount(const QString &name); | ||
369 | 92 | |||
370 | 93 | private: | ||
371 | 94 | QHash<QString,FileData> m_providersData; | ||
372 | 95 | QHash<QString,FileData> m_servicesData; | ||
373 | 96 | QDir m_dataDir; | ||
374 | 97 | }; | ||
375 | 98 | |||
376 | 99 | PluginTest::PluginTest(): | ||
377 | 100 | QObject(0) | ||
378 | 101 | { | ||
379 | 102 | m_providersData["provider_noname"] = FileData("", ""); | ||
380 | 103 | m_providersData["provider_nodomain"] = FileData("Happy", ""); | ||
381 | 104 | m_providersData["provider_translated"] = FileData("Joyful", "translations1"); | ||
382 | 105 | |||
383 | 106 | m_servicesData["service_nodomain"] = FileData("Sad", ""); | ||
384 | 107 | m_servicesData["service_translated"] = FileData("Depressed", "translations1"); | ||
385 | 108 | m_servicesData["service_translated2"] = FileData("Depressed", "translations2"); | ||
386 | 109 | |||
387 | 110 | m_translations["translations1"]["Happy"] = "Contento"; | ||
388 | 111 | m_translations["translations1"]["Joyful"] = "Gioioso"; | ||
389 | 112 | m_translations["translations1"]["Sad"] = "Triste"; | ||
390 | 113 | m_translations["translations1"]["Depressed"] = "Depresso1"; | ||
391 | 114 | m_translations["translations1"]["Black"] = "Nero"; | ||
392 | 115 | m_translations["translations1"]["White"] = "Bianco"; | ||
393 | 116 | |||
394 | 117 | m_translations["translations2"]["Depressed"] = "Depresso2"; | ||
395 | 118 | } | ||
396 | 119 | |||
397 | 120 | void PluginTest::setDataDir(const QTemporaryDir &dir) | ||
398 | 121 | { | ||
399 | 122 | QVERIFY(dir.isValid()); | ||
400 | 123 | |||
401 | 124 | m_dataDir = QDir(dir.path()); | ||
402 | 125 | |||
403 | 126 | QByteArray dataPath = dir.path().toUtf8(); | ||
404 | 127 | qputenv("ACCOUNTS", dataPath); | ||
405 | 128 | qputenv("AG_PROVIDERS", dataPath); | ||
406 | 129 | qputenv("AG_SERVICES", dataPath); | ||
407 | 130 | } | ||
408 | 131 | |||
409 | 132 | void PluginTest::writeProvider(const QString &id, const QString &name, | ||
410 | 133 | const QString &domain) | ||
411 | 134 | { | ||
412 | 135 | writeLibaccountsFile("provider", id, name, domain); | ||
413 | 136 | } | ||
414 | 137 | |||
415 | 138 | void PluginTest::writeService(const QString &id, const QString &name, | ||
416 | 139 | const QString &domain) | ||
417 | 140 | { | ||
418 | 141 | writeLibaccountsFile("service", id, name, domain); | ||
419 | 142 | } | ||
420 | 143 | |||
421 | 144 | void PluginTest::writeLibaccountsFile(const QString &type, const QString &id, | ||
422 | 145 | const QString &name, const QString &domain) | ||
423 | 146 | { | ||
424 | 147 | QDomDocument doc; | ||
425 | 148 | QDomElement root = doc.createElement(type); | ||
426 | 149 | root.setAttribute("id", id); | ||
427 | 150 | doc.appendChild(root); | ||
428 | 151 | |||
429 | 152 | QDomElement nameTag = doc.createElement("name"); | ||
430 | 153 | nameTag.appendChild(doc.createTextNode(name)); | ||
431 | 154 | root.appendChild(nameTag); | ||
432 | 155 | |||
433 | 156 | QDomElement domainTag = doc.createElement("translations"); | ||
434 | 157 | domainTag.appendChild(doc.createTextNode(domain)); | ||
435 | 158 | root.appendChild(domainTag); | ||
436 | 159 | |||
437 | 160 | if (type == "service") { | ||
438 | 161 | QDomElement typeTag = doc.createElement("type"); | ||
439 | 162 | typeTag.appendChild(doc.createTextNode("something")); | ||
440 | 163 | root.appendChild(typeTag); | ||
441 | 164 | } | ||
442 | 165 | |||
443 | 166 | QFile file(m_dataDir.filePath(id + "." + type)); | ||
444 | 167 | if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { | ||
445 | 168 | qWarning() << "Could not write file" << file.fileName(); | ||
446 | 169 | return; | ||
447 | 170 | } | ||
448 | 171 | |||
449 | 172 | file.write(doc.toString().toUtf8()); | ||
450 | 173 | } | ||
451 | 174 | |||
452 | 175 | void PluginTest::createAccount(const QString &name) | ||
453 | 176 | { | ||
454 | 177 | Accounts::Manager *manager = new Accounts::Manager; | ||
455 | 178 | |||
456 | 179 | Accounts::Account *account = manager->createAccount("any"); | ||
457 | 180 | account->setDisplayName(name); | ||
458 | 181 | account->syncAndBlock(); | ||
459 | 182 | |||
460 | 183 | delete manager; | ||
461 | 184 | } | ||
462 | 185 | |||
463 | 186 | void PluginTest::testKeywords_data() | ||
464 | 187 | { | ||
465 | 188 | QTest::addColumn<QStringList>("providers"); | ||
466 | 189 | QTest::addColumn<QStringList>("services"); | ||
467 | 190 | QTest::addColumn<QStringList>("accountNames"); | ||
468 | 191 | QTest::addColumn<QStringList>("keywords"); | ||
469 | 192 | |||
470 | 193 | QTest::newRow("provider, no name") << | ||
471 | 194 | (QStringList() << "provider_noname") << | ||
472 | 195 | QStringList() << | ||
473 | 196 | QStringList() << | ||
474 | 197 | (QStringList() << "provider_noname"); | ||
475 | 198 | |||
476 | 199 | QTest::newRow("provider, untranslated") << | ||
477 | 200 | (QStringList() << "provider_nodomain") << | ||
478 | 201 | QStringList() << | ||
479 | 202 | QStringList() << | ||
480 | 203 | (QStringList() << "provider_nodomain" << "happy"); | ||
481 | 204 | |||
482 | 205 | QTest::newRow("provider, translated") << | ||
483 | 206 | (QStringList() << "provider_translated") << | ||
484 | 207 | QStringList() << | ||
485 | 208 | QStringList() << | ||
486 | 209 | (QStringList() << "provider_translated" << "joyful" << "gioioso"); | ||
487 | 210 | |||
488 | 211 | QTest::newRow("service, untranslated") << | ||
489 | 212 | QStringList() << | ||
490 | 213 | (QStringList() << "service_nodomain") << | ||
491 | 214 | QStringList() << | ||
492 | 215 | (QStringList() << "service_nodomain" << "sad"); | ||
493 | 216 | |||
494 | 217 | QTest::newRow("service, translated 1") << | ||
495 | 218 | QStringList() << | ||
496 | 219 | (QStringList() << "service_translated") << | ||
497 | 220 | QStringList() << | ||
498 | 221 | (QStringList() << "service_translated" << "depressed" << "depresso1"); | ||
499 | 222 | |||
500 | 223 | QTest::newRow("service, translated 2") << | ||
501 | 224 | QStringList() << | ||
502 | 225 | (QStringList() << "service_translated2") << | ||
503 | 226 | QStringList() << | ||
504 | 227 | (QStringList() << "service_translated2" << "depressed" << "depresso2"); | ||
505 | 228 | |||
506 | 229 | QTest::newRow("one account, one word") << | ||
507 | 230 | QStringList() << | ||
508 | 231 | QStringList() << | ||
509 | 232 | (QStringList() << "tom@example.com") << | ||
510 | 233 | (QStringList() << "tom@example.com"); | ||
511 | 234 | |||
512 | 235 | QTest::newRow("one account, many words") << | ||
513 | 236 | QStringList() << | ||
514 | 237 | QStringList() << | ||
515 | 238 | (QStringList() << "My little sweet account") << | ||
516 | 239 | (QStringList() << "my little sweet account"); | ||
517 | 240 | |||
518 | 241 | QTest::newRow("combined") << | ||
519 | 242 | (QStringList() << "provider_translated" << "provider_nodomain") << | ||
520 | 243 | (QStringList() << "service_translated" << "service_translated2") << | ||
521 | 244 | (QStringList() << "john@invalid" << "harry@mysite.com") << | ||
522 | 245 | (QStringList() << "provider_translated" << "joyful" << "gioioso" << | ||
523 | 246 | "provider_nodomain" << "happy" << | ||
524 | 247 | "service_translated" << "depressed" << "depresso1" << | ||
525 | 248 | "service_translated2" << "depressed" << "depresso2" << | ||
526 | 249 | "john@invalid" << "harry@mysite.com"); | ||
527 | 250 | } | ||
528 | 251 | |||
529 | 252 | void PluginTest::testKeywords() | ||
530 | 253 | { | ||
531 | 254 | QFETCH(QStringList, providers); | ||
532 | 255 | QFETCH(QStringList, services); | ||
533 | 256 | QFETCH(QStringList, accountNames); | ||
534 | 257 | QFETCH(QStringList, keywords); | ||
535 | 258 | |||
536 | 259 | QTemporaryDir dataDir; | ||
537 | 260 | |||
538 | 261 | setDataDir(dataDir); | ||
539 | 262 | |||
540 | 263 | /* Create the needed files */ | ||
541 | 264 | Q_FOREACH(const QString &providerId, providers) { | ||
542 | 265 | writeProvider(providerId, | ||
543 | 266 | m_providersData[providerId].name, | ||
544 | 267 | m_providersData[providerId].domain); | ||
545 | 268 | } | ||
546 | 269 | |||
547 | 270 | Q_FOREACH(const QString &serviceId, services) { | ||
548 | 271 | writeService(serviceId, | ||
549 | 272 | m_servicesData[serviceId].name, | ||
550 | 273 | m_servicesData[serviceId].domain); | ||
551 | 274 | } | ||
552 | 275 | |||
553 | 276 | /* create the accounts */ | ||
554 | 277 | Q_FOREACH(const QString &displayName, accountNames) { | ||
555 | 278 | createAccount(displayName); | ||
556 | 279 | } | ||
557 | 280 | |||
558 | 281 | /* Now do the actual test */ | ||
559 | 282 | Plugin plugin; | ||
560 | 283 | |||
561 | 284 | SystemSettings::ItemBase *item = plugin.createItem(QVariantMap()); | ||
562 | 285 | QStringList pluginKeywords = item->keywords(); | ||
563 | 286 | |||
564 | 287 | QCOMPARE(pluginKeywords.toSet(), keywords.toSet()); | ||
565 | 288 | } | ||
566 | 289 | |||
567 | 290 | QTEST_MAIN(PluginTest); | ||
568 | 291 | |||
569 | 292 | #include "tst_plugin.moc" | ||
570 | 0 | 293 | ||
571 | === modified file 'tests/tests.pro' | |||
572 | --- tests/tests.pro 2014-10-03 14:56:11 +0000 | |||
573 | +++ tests/tests.pro 2015-02-02 15:22:49 +0000 | |||
574 | @@ -5,4 +5,5 @@ | |||
575 | 5 | client \ | 5 | client \ |
576 | 6 | online-accounts-service \ | 6 | online-accounts-service \ |
577 | 7 | online-accounts-ui \ | 7 | online-accounts-ui \ |
579 | 8 | plugin | 8 | plugin \ |
580 | 9 | system-settings-plugin |
small comment inline