Merge lp:~online-accounts/libaccounts-qt/packaging into lp:libaccounts-qt
- packaging
- Merge into trunk
Proposed by
Alberto Mardegan
Status: | Merged |
---|---|
Approved by: | David Barth |
Approved revision: | no longer in the source branch. |
Merged at revision: | 147 |
Proposed branch: | lp:~online-accounts/libaccounts-qt/packaging |
Merge into: | lp:libaccounts-qt |
Diff against target: |
3617 lines (+1507/-1919) 21 files modified
.qmake.conf (+2/-0) Accounts/Accounts.pro (+4/-7) Accounts/AccountsQt5ConfigVersion.cmake.in (+5/-5) Accounts/AccountsQtConfig.cmake.in (+0/-5) Accounts/AccountsQtConfigVersion.cmake.in (+0/-10) Accounts/account-service.cpp (+0/-4) Accounts/account.cpp (+0/-5) Accounts/accounts-qt.pc.in (+0/-15) Accounts/accountscommon.h (+0/-8) common-project-config.pri (+6/-16) debian/changelog (+8/-0) rpm/libaccounts-qt.changes (+0/-8) rpm/libaccounts-qt.spec (+0/-91) tests/accountstest.cpp (+0/-1476) tests/accountstest.h (+0/-130) tests/accountstest.pro (+0/-56) tests/accountstest.sh (+0/-7) tests/tests.pro (+1/-1) tests/tests.xml (+0/-75) tests/tst_libaccounts.cpp (+1446/-0) tests/tst_libaccounts.pro (+35/-0) |
To merge this branch: | bzr merge lp:~online-accounts/libaccounts-qt/packaging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Online Accounts | Pending | ||
Review via email: mp+276620@code.launchpad.net |
Commit message
Remove debug messages
Since this library is just a thin wrapper around libaccounts-glib, it
makes little sense to have debug messages in here: debugging can be
activated on libaccounts-glib, if needed.
Also, modernize test suite and project structure
Description of the change
Remove debug messages
Since this library is just a thin wrapper around libaccounts-glib, it
makes little sense to have debug messages in here: debugging can be
activated on libaccounts-glib, if needed.
Also, modernize test suite and project structure
To post a comment you must log in.
- 147. By Alberto Mardegan
-
Remove debug messages
Since this library is just a thin wrapper around libaccounts-glib, it
makes little sense to have debug messages in here: debugging can be
activated on libaccounts-glib, if needed.Also, modernize test suite and project structure
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.qmake.conf' |
2 | --- .qmake.conf 1970-01-01 00:00:00 +0000 |
3 | +++ .qmake.conf 2015-11-06 13:54:21 +0000 |
4 | @@ -0,0 +1,2 @@ |
5 | +TOP_SRC_DIR = $$PWD |
6 | +TOP_BUILD_DIR = $$shadowed($$PWD) |
7 | |
8 | === modified file 'Accounts/Accounts.pro' |
9 | --- Accounts/Accounts.pro 2014-03-14 08:21:02 +0000 |
10 | +++ Accounts/Accounts.pro 2015-11-06 13:54:21 +0000 |
11 | @@ -3,6 +3,7 @@ |
12 | include( ../common-vars.pri ) |
13 | |
14 | TEMPLATE = lib |
15 | +TARGET = accounts-qt5 |
16 | |
17 | # Input |
18 | public_headers = \ |
19 | @@ -42,13 +43,9 @@ |
20 | QT += core xml |
21 | QT -= gui |
22 | |
23 | -greaterThan(QT_MAJOR_VERSION, 4) { |
24 | - TARGET = accounts-qt5 |
25 | - CMAKE_BASENAME = AccountsQt5 |
26 | -} else { |
27 | - TARGET = accounts-qt |
28 | - CMAKE_BASENAME = AccountsQt |
29 | -} |
30 | +INCLUDEPATH += $${TOP_SRC_DIR} |
31 | + |
32 | +CMAKE_BASENAME = AccountsQt5 |
33 | |
34 | PKGCONFIG += \ |
35 | glib-2.0 \ |
36 | |
37 | === modified file 'Accounts/AccountsQt5ConfigVersion.cmake.in' |
38 | --- Accounts/AccountsQt5ConfigVersion.cmake.in 2014-03-05 15:49:56 +0000 |
39 | +++ Accounts/AccountsQt5ConfigVersion.cmake.in 2015-11-06 13:54:21 +0000 |
40 | @@ -1,10 +1,10 @@ |
41 | set(PACKAGE_VERSION $${PROJECT_VERSION}) |
42 | |
43 | -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
44 | +if(\"${PACKAGE_VERSION}\" VERSION_LESS \"${PACKAGE_FIND_VERSION}\" ) |
45 | set(PACKAGE_VERSION_COMPATIBLE FALSE) |
46 | -else("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
47 | +else(\"${PACKAGE_VERSION}\" VERSION_LESS \"${PACKAGE_FIND_VERSION}\" ) |
48 | set(PACKAGE_VERSION_COMPATIBLE TRUE) |
49 | - if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") |
50 | + if( \"${PACKAGE_FIND_VERSION}\" STREQUAL \"${PACKAGE_VERSION}\") |
51 | set(PACKAGE_VERSION_EXACT TRUE) |
52 | - endif( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") |
53 | -endif("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
54 | \ No newline at end of file |
55 | + endif( \"${PACKAGE_FIND_VERSION}\" STREQUAL \"${PACKAGE_VERSION}\") |
56 | +endif(\"${PACKAGE_VERSION}\" VERSION_LESS \"${PACKAGE_FIND_VERSION}\" ) |
57 | |
58 | === removed file 'Accounts/AccountsQtConfig.cmake.in' |
59 | --- Accounts/AccountsQtConfig.cmake.in 2014-02-13 14:10:53 +0000 |
60 | +++ Accounts/AccountsQtConfig.cmake.in 1970-01-01 00:00:00 +0000 |
61 | @@ -1,5 +0,0 @@ |
62 | -# ACCOUNTSQT_INCLUDE_DIRS - The libaccounts-qt include directories |
63 | -# ACCOUNTSQT_LIBRARIES - The libraries needed to use libaccounts-qt |
64 | - |
65 | -set(ACCOUNTSQT_LIBRARIES $${INSTALL_LIBDIR}/lib$${TARGET}.so) |
66 | -set(ACCOUNTSQT_INCLUDE_DIRS $${INSTALL_PREFIX}/include/$${TARGET}/) |
67 | \ No newline at end of file |
68 | |
69 | === removed file 'Accounts/AccountsQtConfigVersion.cmake.in' |
70 | --- Accounts/AccountsQtConfigVersion.cmake.in 2014-02-13 14:10:53 +0000 |
71 | +++ Accounts/AccountsQtConfigVersion.cmake.in 1970-01-01 00:00:00 +0000 |
72 | @@ -1,10 +0,0 @@ |
73 | -set(PACKAGE_VERSION $${PROJECT_VERSION}) |
74 | - |
75 | -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
76 | - set(PACKAGE_VERSION_COMPATIBLE FALSE) |
77 | -else("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
78 | - set(PACKAGE_VERSION_COMPATIBLE TRUE) |
79 | - if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") |
80 | - set(PACKAGE_VERSION_EXACT TRUE) |
81 | - endif( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") |
82 | -endif("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) |
83 | \ No newline at end of file |
84 | |
85 | === modified file 'Accounts/account-service.cpp' |
86 | --- Accounts/account-service.cpp 2015-09-30 08:17:50 +0000 |
87 | +++ Accounts/account-service.cpp 2015-11-06 13:54:21 +0000 |
88 | @@ -159,15 +159,11 @@ |
89 | void AccountServicePrivate::onEnabled(AccountService *accountService, |
90 | gboolean isEnabled) |
91 | { |
92 | - TRACE(); |
93 | - |
94 | Q_EMIT accountService->enabled(isEnabled); |
95 | } |
96 | |
97 | void AccountServicePrivate::onChanged(AccountService *accountService) |
98 | { |
99 | - TRACE(); |
100 | - |
101 | Q_EMIT accountService->changed(); |
102 | } |
103 | |
104 | |
105 | === modified file 'Accounts/account.cpp' |
106 | --- Accounts/account.cpp 2015-09-30 08:17:50 +0000 |
107 | +++ Accounts/account.cpp 2015-11-06 13:54:21 +0000 |
108 | @@ -181,8 +181,6 @@ |
109 | |
110 | void Account::Private::on_deleted(Account *self) |
111 | { |
112 | - TRACE(); |
113 | - |
114 | Q_EMIT self->removed(); |
115 | } |
116 | |
117 | @@ -623,14 +621,11 @@ |
118 | GAsyncResult *res, |
119 | Account *self) |
120 | { |
121 | - TRACE() << "Saved accunt ID:" << account->id; |
122 | - |
123 | GError *error = NULL; |
124 | ag_account_store_finish(account, res, &error); |
125 | if (error) { |
126 | if (error->domain == G_IO_ERROR && |
127 | error->code == G_IO_ERROR_CANCELLED) { |
128 | - TRACE() << "Account destroyed, operation cancelled"; |
129 | } else { |
130 | Q_EMIT self->error(Error(error)); |
131 | } |
132 | |
133 | === removed file 'Accounts/accounts-qt.pc.in' |
134 | --- Accounts/accounts-qt.pc.in 2013-01-18 10:49:27 +0000 |
135 | +++ Accounts/accounts-qt.pc.in 1970-01-01 00:00:00 +0000 |
136 | @@ -1,15 +0,0 @@ |
137 | -prefix=$$INSTALL_PREFIX |
138 | -exec_prefix=${prefix} |
139 | -libdir=$$INSTALL_LIBDIR |
140 | -includedir=${prefix}/include/accounts-qt |
141 | -servicefilesdir=${prefix}/share/accounts/services |
142 | -servicetypefilesdir=${prefix}/share/accounts/service-types |
143 | -providerfilesdir=${prefix}/share/accounts/providers |
144 | - |
145 | -Name: libaccounts-qt |
146 | -Description: Accounts Library |
147 | -Version: $$PROJECT_VERSION |
148 | -Libs: -L${libdir} -laccounts-qt |
149 | -Requires: QtCore QtXml |
150 | -Cflags: -I${includedir} |
151 | - |
152 | |
153 | === modified file 'Accounts/accountscommon.h' |
154 | --- Accounts/accountscommon.h 2015-05-22 12:04:52 +0000 |
155 | +++ Accounts/accountscommon.h 2015-11-06 13:54:21 +0000 |
156 | @@ -29,16 +29,8 @@ |
157 | |
158 | #ifdef BUILDING_ACCOUNTS_QT |
159 | |
160 | -// Debug macros |
161 | - |
162 | -#ifdef TRACE |
163 | - #undef TRACE |
164 | -#endif |
165 | - |
166 | #include <QDebug> |
167 | |
168 | -#define TRACE() qDebug() << __FILE__ ":" << __LINE__ << __func__ |
169 | - |
170 | // String conversion |
171 | |
172 | #ifdef ASCII |
173 | |
174 | === modified file 'common-project-config.pri' |
175 | --- common-project-config.pri 2014-03-14 08:21:02 +0000 |
176 | +++ common-project-config.pri 2015-11-06 13:54:21 +0000 |
177 | @@ -11,20 +11,15 @@ |
178 | UI_HEADERS_DIR = ui/include |
179 | UI_SOURCES_DIR = ui/src |
180 | |
181 | -TOP_SRC_DIR = $$PWD |
182 | -TOP_BUILD_DIR = $${TOP_SRC_DIR}/$${BUILD_DIR} |
183 | -QMAKE_LIBDIR += $${TOP_BUILD_DIR}/Accounts |
184 | -INCLUDEPATH += $${TOP_SRC_DIR} |
185 | +!defined(TOP_SRC_DIR, var) { |
186 | + TOP_SRC_DIR = $$PWD |
187 | + TOP_BUILD_DIR = $${TOP_SRC_DIR}/$(BUILD_DIR) |
188 | +} |
189 | |
190 | # we don't like warnings... |
191 | #QMAKE_CXXFLAGS *= -Werror |
192 | |
193 | -greaterThan(QT_MAJOR_VERSION, 4) { |
194 | - # Qt5: use C++11. This is used to avoid the source incompatibility |
195 | - # with the QSKIP macro, as described in: |
196 | - # http://www.kdab.com/porting-from-qt-4-to-qt-5/ |
197 | - QMAKE_CXXFLAGS += -std=c++11 |
198 | -} |
199 | +CONFIG += c++11 |
200 | |
201 | #----------------------------------------------------------------------------- |
202 | # setup the installation prefix |
203 | @@ -42,12 +37,7 @@ |
204 | message("==== install prefix set to `$${INSTALL_PREFIX}'") |
205 | } |
206 | |
207 | -ARCH = $$system(uname -m) |
208 | -contains( ARCH, x86_64 ) { |
209 | - INSTALL_LIBDIR = $${INSTALL_PREFIX}/lib64 |
210 | -} else { |
211 | - INSTALL_LIBDIR = $${INSTALL_PREFIX}/lib |
212 | -} |
213 | +INSTALL_LIBDIR = $${INSTALL_PREFIX}/lib |
214 | |
215 | # default library directory can be overriden by defining LIBDIR when |
216 | # running qmake |
217 | |
218 | === modified file 'debian/changelog' |
219 | --- debian/changelog 2015-11-02 09:12:29 +0000 |
220 | +++ debian/changelog 2015-11-06 13:54:21 +0000 |
221 | @@ -1,3 +1,11 @@ |
222 | +libaccounts-qt (1.14+16.04.20151102-0ubuntu2) UNRELEASED; urgency=medium |
223 | + |
224 | + * Merge from upstream: |
225 | + - Modernize the project structure |
226 | + - Remove debug messages (LP: #1404267) |
227 | + |
228 | + -- Alberto Mardegan <alberto.mardegan@canonical.com> Wed, 04 Nov 2015 10:17:23 +0300 |
229 | + |
230 | libaccounts-qt (1.14+16.04.20151102-0ubuntu1) xenial; urgency=medium |
231 | |
232 | [ Alberto Mardegan ] |
233 | |
234 | === removed directory 'rpm' |
235 | === removed file 'rpm/libaccounts-qt.changes' |
236 | --- rpm/libaccounts-qt.changes 2010-06-28 08:44:55 +0000 |
237 | +++ rpm/libaccounts-qt.changes 1970-01-01 00:00:00 +0000 |
238 | @@ -1,8 +0,0 @@ |
239 | -* Min Jun 28 2010 Alberto Mardegan <alberto.mardegan@nokia.com> - 0.29 |
240 | -- Add ServiceType class |
241 | - |
242 | -* Mon Jun 14 2010 Bernd Wachter <ext-bernd.wachter@nokia.com> - 0.28 |
243 | -- Update to latest version |
244 | - |
245 | -* Wed Apr 21 2010 Bernd Wachter <bwachter@lart.info> - 0.24+0m6-1 |
246 | -- First RPM version |
247 | |
248 | === removed file 'rpm/libaccounts-qt.spec' |
249 | --- rpm/libaccounts-qt.spec 2010-06-28 08:44:55 +0000 |
250 | +++ rpm/libaccounts-qt.spec 1970-01-01 00:00:00 +0000 |
251 | @@ -1,91 +0,0 @@ |
252 | -Name: libaccounts-qt |
253 | -Version: 0.29 |
254 | -Release: 1%{?dist} |
255 | -Summary: Accounts framework |
256 | -Group: System Environment/Libraries |
257 | -License: LGPLv2.1 |
258 | -URL: http://gitorious.org/accounts-sso/accounts-qt |
259 | -Source0: accounts-qt-%{version}.tar.gz |
260 | -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) |
261 | -BuildRequires: qt-devel, doxygen, graphviz |
262 | -BuildRequires: libaccounts-glib-devel >= 0.42 |
263 | -BuildRequires: glib2-devel |
264 | -BuildRequires: fdupes |
265 | - |
266 | -%description |
267 | -Framework to provide accounts |
268 | - |
269 | -%files |
270 | -%defattr(-,root,root,-) |
271 | -%doc README COPYING |
272 | -%{_libdir}/lib*.so.* |
273 | -%{_bindir}/account-tool |
274 | - |
275 | - |
276 | -%package devel |
277 | -Summary: Development files for accounts-qt |
278 | -Group: Development/Libraries |
279 | -Provides: accounts-qt-dev |
280 | -Requires: %{name} = %{version}-%{release} |
281 | - |
282 | -%description devel |
283 | -Headers and static libraries for the accounts. |
284 | - |
285 | -%files devel |
286 | -%defattr(-,root,root,-) |
287 | -%{_libdir}/*.so |
288 | -%{_includedir}/* |
289 | -%{_libdir}/pkgconfig/* |
290 | -%{_libdir}/qt4/* |
291 | - |
292 | - |
293 | -%package tests |
294 | -Summary: Tests for accounts-qt |
295 | -Group: System Environment/Libraries |
296 | -Requires: %{name} = %{version}-%{release} |
297 | - |
298 | -%description tests |
299 | -Tests for accounts-qt. |
300 | - |
301 | -%files tests |
302 | -%defattr(-,root,root,-) |
303 | -%{_datadir}/%{name}-tests/* |
304 | -%{_bindir}/accountstest |
305 | - |
306 | -%package doc |
307 | -Summary: Documentation for accounts-qt |
308 | -Group: Documentation |
309 | - |
310 | -%description doc |
311 | -Doxygen-generated HTML documentation for the accounts. |
312 | - |
313 | -%files doc |
314 | -%defattr(-,root,root,-) |
315 | -%{_datadir}/doc/* |
316 | - |
317 | - |
318 | -%prep |
319 | -%setup -q -n accounts-qt-%{version} |
320 | - |
321 | -%build |
322 | -qmake \ |
323 | - QMF_INSTALL_ROOT=%{_prefix} \ |
324 | - CONFIG+=release \ |
325 | - accounts-qt.pro |
326 | - |
327 | -make %{?_smp_mflags} |
328 | - |
329 | - |
330 | -%install |
331 | -rm -Rf %{buildroot} |
332 | -make INSTALL_ROOT=%{buildroot} install |
333 | -rm %{buildroot}/%{_datadir}/doc/accounts-qt/html/installdox |
334 | -%fdupes %{buildroot}/%{_includedir} |
335 | -%fdupes %{buildroot}/%{_docdir} |
336 | - |
337 | -%post -p /sbin/ldconfig |
338 | - |
339 | -%postun -p /sbin/ldconfig |
340 | - |
341 | -%clean |
342 | -rm -Rf %{buildroot} |
343 | |
344 | === removed file 'tests/accountstest.cpp' |
345 | --- tests/accountstest.cpp 2014-08-14 14:50:11 +0000 |
346 | +++ tests/accountstest.cpp 1970-01-01 00:00:00 +0000 |
347 | @@ -1,1476 +0,0 @@ |
348 | -/* vi: set et sw=4 ts=4 cino=t0,(0: */ |
349 | -/* |
350 | - * This file is part of libaccounts-qt |
351 | - * |
352 | - * Copyright (C) 2009-2011 Nokia Corporation. |
353 | - * |
354 | - * Contact: Alberto Mardegan <alberto.mardegan@nokia.com> |
355 | - * |
356 | - * This library is free software; you can redistribute it and/or |
357 | - * modify it under the terms of the GNU Lesser General Public License |
358 | - * version 2.1 as published by the Free Software Foundation. |
359 | - * |
360 | - * This library is distributed in the hope that it will be useful, but |
361 | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
362 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
363 | - * Lesser General Public License for more details. |
364 | - * |
365 | - * You should have received a copy of the GNU Lesser General Public |
366 | - * License along with this library; if not, write to the Free Software |
367 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
368 | - * 02110-1301 USA |
369 | - */ |
370 | -#include <QtTest/QtTest> |
371 | -#include <QSignalSpy> |
372 | - |
373 | -#include "Accounts/Application" |
374 | -#include "Accounts/Manager" |
375 | -#include "Accounts/AccountService" |
376 | - |
377 | -using namespace Accounts; |
378 | -#include "accountstest.h" |
379 | - |
380 | -#define PROVIDER QString("dummyprovider") |
381 | -#define SERVICE QString("dummyservice") |
382 | -#define MYSERVICE QLatin1String("MyService") |
383 | -#define OTHERSERVICE QLatin1String("OtherService") |
384 | -#define EMAIL_SERVICE_TYPE QLatin1String("e-mail") |
385 | - |
386 | - |
387 | -void clearDb() |
388 | -{ |
389 | - QDir dbroot(QString(getenv("ACCOUNTS"))); |
390 | - dbroot.remove(QString("accounts.db")); |
391 | -} |
392 | - |
393 | -void AccountsTest::initTestCase() |
394 | -{ |
395 | - //init |
396 | - setenv ("ACCOUNTS", "/tmp/", false); |
397 | - setenv ("AG_SERVICES", SERVICES_DIR, false); |
398 | - setenv ("AG_SERVICE_TYPES", SERVICE_TYPES_DIR, false); |
399 | - setenv ("AG_PROVIDERS", PROVIDERS_DIR, false); |
400 | - //clear database |
401 | - clearDb(); |
402 | -} |
403 | - |
404 | -void AccountsTest::cleanupTestCase() |
405 | -{ |
406 | -} |
407 | - |
408 | - |
409 | -/* manager */ |
410 | -void AccountsTest::managerTestCase() |
411 | -{ |
412 | - Manager *mgr = new Manager(); |
413 | - QVERIFY(mgr != NULL); |
414 | - QCOMPARE(mgr->serviceType(), QString()); |
415 | - |
416 | - mgr->setAbortOnTimeout(true); |
417 | - QCOMPARE(mgr->abortOnTimeout(), true); |
418 | - |
419 | - mgr->setTimeout(123); |
420 | - QCOMPARE(mgr->timeout(), quint32(123)); |
421 | - |
422 | - QCOMPARE(mgr->options().testFlag(Manager::DisableNotifications), false); |
423 | - |
424 | - delete mgr; |
425 | - |
426 | - mgr = new Manager(Manager::DisableNotifications); |
427 | - QCOMPARE(mgr->options().testFlag(Manager::DisableNotifications), true); |
428 | - delete mgr; |
429 | -} |
430 | - |
431 | -void AccountsTest::createAccountTestCase() |
432 | -{ |
433 | - clearDb(); |
434 | - |
435 | - Manager * mgr=new Manager(); |
436 | - QVERIFY(mgr!=NULL); |
437 | - |
438 | - Account *account = mgr->createAccount(NULL); |
439 | - QVERIFY(account!=NULL); |
440 | - QVERIFY(account->manager() == mgr); |
441 | - delete account; |
442 | - |
443 | - account = mgr->createAccount(PROVIDER); |
444 | - QVERIFY(account!=NULL); |
445 | - delete account; |
446 | - |
447 | - delete mgr; |
448 | -} |
449 | - |
450 | -void AccountsTest::accountTestCase() |
451 | -{ |
452 | - clearDb(); |
453 | - |
454 | - Manager * mgr=new Manager(); |
455 | - QVERIFY(mgr!=NULL); |
456 | - |
457 | - //this should not exist |
458 | - Account* account2 = mgr->account(1); |
459 | - QVERIFY(account2==NULL); |
460 | - Error error = mgr->lastError(); |
461 | - QCOMPARE(error.type(), Error::AccountNotFound); |
462 | - |
463 | - // make sure there is account |
464 | - Account* account = mgr->createAccount(NULL); |
465 | - account->sync(); |
466 | - |
467 | - //now we get account |
468 | - account2 = mgr->account(1); |
469 | - QVERIFY(account2!=NULL); |
470 | - |
471 | - delete account2; |
472 | - delete account; |
473 | - delete mgr; |
474 | -} |
475 | - |
476 | -void AccountsTest::objectsLifetimeTestCase() |
477 | -{ |
478 | - clearDb(); |
479 | - |
480 | - Manager *manager = new Manager(); |
481 | - |
482 | - // this should not exist |
483 | - Account *account = Account::fromId(manager, 1); |
484 | - QVERIFY(account == 0); |
485 | - Error error = manager->lastError(); |
486 | - QCOMPARE(error.type(), Error::AccountNotFound); |
487 | - |
488 | - // create an account |
489 | - account = new Account(manager, PROVIDER); |
490 | - account->setDisplayName("hi!"); |
491 | - account->syncAndBlock(); |
492 | - AccountId accountId = account->id(); |
493 | - delete account; |
494 | - |
495 | - // Now load it, in two different ways |
496 | - QPointer<Account> sharedAccount = manager->account(accountId); |
497 | - QVERIFY(sharedAccount != 0); |
498 | - QCOMPARE(sharedAccount->displayName(), QString("hi!")); |
499 | - |
500 | - QPointer<Account> ownedAccount = Account::fromId(manager, accountId); |
501 | - QVERIFY(ownedAccount != 0); |
502 | - QCOMPARE(ownedAccount->displayName(), QString("hi!")); |
503 | - |
504 | - /* Load it once more from the shared interface, and see that we get the |
505 | - * same object */ |
506 | - QCOMPARE(manager->account(accountId), sharedAccount.data()); |
507 | - |
508 | - /* Delete the manager; the owned account should survive, the shared |
509 | - * shouldn't */ |
510 | - delete manager; |
511 | - QVERIFY(sharedAccount == 0); |
512 | - QVERIFY(ownedAccount != 0); |
513 | - QVERIFY(ownedAccount->manager() == 0); |
514 | - |
515 | - delete ownedAccount; |
516 | -} |
517 | - |
518 | -void AccountsTest::accountListTestCase() |
519 | -{ |
520 | - clearDb(); |
521 | - |
522 | - Manager *mgr = new Manager(); |
523 | - QVERIFY(mgr != NULL); |
524 | - |
525 | - // make sure there is account |
526 | - Account *account = mgr->createAccount(NULL); |
527 | - account->sync(); |
528 | - |
529 | - AccountIdList list = mgr->accountList(NULL); |
530 | - QVERIFY(!list.isEmpty()); |
531 | - QCOMPARE(list.size(), 1); |
532 | - |
533 | - list = mgr->accountList("e-mail"); |
534 | - QVERIFY(list.isEmpty()); |
535 | - |
536 | - delete account; |
537 | - delete mgr; |
538 | -} |
539 | - |
540 | -void AccountsTest::providerTestCase() |
541 | -{ |
542 | - Manager * mgr=new Manager(); |
543 | - QVERIFY(mgr!=NULL); |
544 | - |
545 | - Account *account = mgr->createAccount(PROVIDER); |
546 | - QVERIFY(account!=NULL); |
547 | - |
548 | - QString provider_name = account->providerName(); |
549 | - QCOMPARE(provider_name, PROVIDER); |
550 | - |
551 | - delete account; |
552 | - |
553 | - /* Test invalid provider */ |
554 | - Provider invalid; |
555 | - QVERIFY(!invalid.isValid()); |
556 | - |
557 | - /* Check listing and loading of XML files */ |
558 | - Provider provider = mgr->provider("MyProvider"); |
559 | - QVERIFY(provider.isValid()); |
560 | - |
561 | - QCOMPARE(provider.displayName(), QString("My Provider")); |
562 | - QCOMPARE(provider.iconName(), QString("general_myprovider")); |
563 | - QCOMPARE(provider.description(), QString("fast & furious")); |
564 | - QCOMPARE(provider.trCatalog(), QString("accounts")); |
565 | - QCOMPARE(provider.pluginName(), QString("generic-oauth")); |
566 | - QCOMPARE(provider.domainsRegExp(), QString(".*example.net")); |
567 | - QCOMPARE(provider.isSingleAccount(), true); |
568 | - |
569 | - QDomDocument dom = provider.domDocument(); |
570 | - QDomElement root = dom.documentElement(); |
571 | - QCOMPARE(root.tagName(), QString("provider")); |
572 | - |
573 | - /* Test copy constructor */ |
574 | - Provider copy(provider); |
575 | - QCOMPARE(copy.displayName(), QString("My Provider")); |
576 | - |
577 | - /* Test assignment */ |
578 | - copy = provider; |
579 | - QCOMPARE(copy.displayName(), QString("My Provider")); |
580 | - copy = invalid; |
581 | - QVERIFY(!copy.isValid()); |
582 | - copy = provider; |
583 | - QCOMPARE(copy.displayName(), QString("My Provider")); |
584 | - |
585 | - ProviderList providers = mgr->providerList(); |
586 | - QVERIFY(!providers.isEmpty()); |
587 | - QVERIFY(providers.size() == 1); |
588 | - QCOMPARE(providers[0].displayName(), QString("My Provider")); |
589 | - |
590 | - delete mgr; |
591 | -} |
592 | - |
593 | -void AccountsTest::serviceTestCase() |
594 | -{ |
595 | - Manager * mgr=new Manager(); |
596 | - QVERIFY(mgr!=NULL); |
597 | - |
598 | - Service service = mgr->service(MYSERVICE); |
599 | - QVERIFY(service.isValid()); |
600 | - QCOMPARE(service.name(), MYSERVICE); |
601 | - QCOMPARE(service.iconName(), QString("general_myservice")); |
602 | - QCOMPARE(service.trCatalog(), QString("accounts")); |
603 | - QStringList tags; |
604 | - tags << "email" << "e-mail"; |
605 | - QCOMPARE(service.tags(), tags.toSet()); |
606 | - // Called twice, because the second time it returns a cached result |
607 | - QCOMPARE(service.tags(), tags.toSet()); |
608 | - QVERIFY(service.hasTag("email")); |
609 | - QVERIFY(!service.hasTag("chat")); |
610 | - |
611 | - service = mgr->service(SERVICE); |
612 | - QVERIFY(!service.isValid()); |
613 | - |
614 | - delete mgr; |
615 | -} |
616 | - |
617 | -void AccountsTest::serviceListTestCase() |
618 | -{ |
619 | - Manager *mgr = new Manager(); |
620 | - QVERIFY(mgr != NULL); |
621 | - |
622 | - ServiceList list = mgr->serviceList(); |
623 | - QVERIFY(!list.isEmpty()); |
624 | - QCOMPARE(list.count(), 2); |
625 | - |
626 | - list = mgr->serviceList("e-mail"); |
627 | - QCOMPARE(list.count(), 1); |
628 | - |
629 | - list = mgr->serviceList("sharing"); |
630 | - QCOMPARE(list.count(), 1); |
631 | - |
632 | - delete mgr; |
633 | -} |
634 | - |
635 | -/* service */ |
636 | - |
637 | -void AccountsTest::serviceConstTestCase() |
638 | -{ |
639 | - Manager * mgr=new Manager(); |
640 | - QVERIFY(mgr!=NULL); |
641 | - |
642 | - Service service = mgr->service(MYSERVICE); |
643 | - QVERIFY(service.isValid()); |
644 | - QCOMPARE(service.name(), MYSERVICE); |
645 | - QCOMPARE(service.displayName(), QString("My Service")); |
646 | - QCOMPARE(service.serviceType(), QString("e-mail")); |
647 | - QCOMPARE(service.provider(), QString("MyProvider")); |
648 | - QVERIFY(service.hasTag(QString("email"))); |
649 | - |
650 | - delete mgr; |
651 | -} |
652 | - |
653 | - |
654 | -/* account */ |
655 | - |
656 | - |
657 | -void AccountsTest::accountConstTestCase() |
658 | -{ |
659 | - Manager * mgr=new Manager(); |
660 | - QVERIFY(mgr!=NULL); |
661 | - |
662 | - Account *account = mgr->createAccount(PROVIDER); |
663 | - QVERIFY(account!=NULL); |
664 | - QVERIFY(account->isWritable()); |
665 | - |
666 | - delete account; |
667 | - delete mgr; |
668 | -} |
669 | - |
670 | -void AccountsTest::accountProviderTestCase() |
671 | -{ |
672 | - Manager *manager = new Manager(); |
673 | - QVERIFY(manager != 0); |
674 | - |
675 | - Account *account = manager->createAccount("MyProvider"); |
676 | - QVERIFY(account != 0); |
677 | - |
678 | - QCOMPARE(account->providerName(), QString("MyProvider")); |
679 | - |
680 | - Provider provider = account->provider(); |
681 | - QCOMPARE(provider.name(), QString("MyProvider")); |
682 | - |
683 | - delete account; |
684 | - delete manager; |
685 | -} |
686 | - |
687 | -void AccountsTest::accountServiceTestCase() |
688 | -{ |
689 | - Manager * mgr=new Manager(); |
690 | - QVERIFY(mgr!=NULL); |
691 | - |
692 | - Account *account = mgr->createAccount("MyProvider"); |
693 | - QVERIFY(account!=NULL); |
694 | - |
695 | - QVERIFY(!account->supportsService(QString("unsupported"))); |
696 | - QVERIFY(account->supportsService(QString("e-mail"))); |
697 | - |
698 | - ServiceList list = account->services(); |
699 | - QVERIFY(!list.isEmpty()); |
700 | - QCOMPARE(list.count(), 1); |
701 | - |
702 | - list = account->services("e-mail"); |
703 | - QCOMPARE(list.count(), 1); |
704 | - |
705 | - list = account->services("unsupported"); |
706 | - QVERIFY(list.isEmpty()); |
707 | - |
708 | - Service service = mgr->service(MYSERVICE); |
709 | - QVERIFY(service.isValid()); |
710 | - |
711 | - /* Test default settings */ |
712 | - account->selectService(service); |
713 | - QCOMPARE(account->value("parameters/server").toString(), |
714 | - QString("talk.google.com")); |
715 | - QCOMPARE(account->valueAsInt("parameters/port"), 5223); |
716 | - SettingSource source; |
717 | - QCOMPARE(account->valueAsInt("parameters/port", 0, &source), 5223); |
718 | - QCOMPARE(source, TEMPLATE); |
719 | - |
720 | - delete account; |
721 | - delete mgr; |
722 | -} |
723 | - |
724 | - |
725 | -void AccountsTest::enabled(const QString & /*serviceName*/, bool enabled) |
726 | -{ |
727 | - m_enabled = enabled; |
728 | -} |
729 | - |
730 | - |
731 | -void AccountsTest::accountEnabledTestCase() |
732 | -{ |
733 | - Manager * mgr=new Manager(); |
734 | - QVERIFY(mgr!=NULL); |
735 | - |
736 | - Account *account = mgr->createAccount(PROVIDER); |
737 | - QVERIFY(account!=NULL); |
738 | - m_enabled=false; |
739 | - QObject::connect(account, SIGNAL(enabledChanged(const QString&,bool)), |
740 | - this, SLOT(enabled(const QString&,bool))); |
741 | - |
742 | - account->setEnabled(true); |
743 | - account->sync(); |
744 | - QVERIFY(account->enabled()); |
745 | - QVERIFY(m_enabled); |
746 | - account->setEnabled(false); |
747 | - account->sync(); |
748 | - QVERIFY(!account->enabled()); |
749 | - QVERIFY(!m_enabled); |
750 | - |
751 | - delete account; |
752 | - delete mgr; |
753 | -} |
754 | - |
755 | -void AccountsTest::display(const QString &displayName) |
756 | -{ |
757 | - m_enabled = !displayName.isNull(); |
758 | -} |
759 | - |
760 | -void AccountsTest::accountDisplayNameTestCase() |
761 | -{ |
762 | - Manager * mgr=new Manager(); |
763 | - QVERIFY(mgr!=NULL); |
764 | - |
765 | - Account *account = mgr->createAccount(PROVIDER); |
766 | - QVERIFY(account!=NULL); |
767 | - m_enabled=false; |
768 | - QObject::connect(account, SIGNAL(displayNameChanged(const QString&)), |
769 | - this, SLOT(display(const QString&))); |
770 | - |
771 | - account->setDisplayName(PROVIDER); |
772 | - account->sync(); |
773 | - QCOMPARE(account->displayName(),PROVIDER); |
774 | - QVERIFY(m_enabled); |
775 | - |
776 | - delete account; |
777 | - delete mgr; |
778 | -} |
779 | - |
780 | - |
781 | - |
782 | -void AccountsTest::accountValueTestCase() |
783 | -{ |
784 | - Manager * mgr=new Manager(); |
785 | - QVERIFY(mgr!=NULL); |
786 | - |
787 | - Account *account = mgr->createAccount(PROVIDER); |
788 | - QVERIFY(account!=NULL); |
789 | - |
790 | - QObject::connect(account, SIGNAL(synced()), |
791 | - this, SLOT(stored())); |
792 | - m_stored = false; |
793 | - account->setValue(QString("test"),QString("value")); |
794 | - int int_value = 666; |
795 | - account->setValue("testint", int_value); |
796 | - QStringList names; |
797 | - names << "Tom" << "Dick" << "Harry"; |
798 | - account->setValue("names", names); |
799 | - account->setValue("big distance", quint64(3)); |
800 | - account->setValue("big difference", qint64(-300)); |
801 | - account->setValue("boolean", false); |
802 | - account->sync(); |
803 | - |
804 | - QTest::qWait(10); |
805 | - QVERIFY(m_stored); |
806 | - |
807 | - /* check that the values we wrote are retrieved successfully */ |
808 | - QVariant val = QVariant::String; |
809 | - account->value(QString("test"), val); |
810 | - QCOMPARE(val.toString(), QString("value")); |
811 | - |
812 | - SettingSource source; |
813 | - source = account->value(QString("test"), val); |
814 | - QCOMPARE(val.toString(), QString("value")); |
815 | - |
816 | - QVariant intval = QVariant::Int; |
817 | - account->value("testint", intval); |
818 | - qDebug("Val: %d", intval.toInt()); |
819 | - QVERIFY(intval.toInt() == int_value); |
820 | - |
821 | - QVERIFY(source == ACCOUNT); |
822 | - |
823 | - QCOMPARE(account->value("names").toStringList(), names); |
824 | - QCOMPARE(account->value("big distance").toULongLong(), quint64(3)); |
825 | - QCOMPARE(account->value("big difference").toLongLong(), qint64(-300)); |
826 | - |
827 | - /* test the convenience methods */ |
828 | - QString strval = account->valueAsString("test"); |
829 | - QCOMPARE (strval, QString("value")); |
830 | - QCOMPARE(account->valueAsString("test", "Hi", &source), QString("value")); |
831 | - QCOMPARE(source, ACCOUNT); |
832 | - |
833 | - QCOMPARE(account->valueAsBool("boolean"), false); |
834 | - QCOMPARE(account->valueAsBool("boolean", true, &source), false); |
835 | - QCOMPARE(source, ACCOUNT); |
836 | - |
837 | - QCOMPARE(account->valueAsUInt64("big distance"), quint64(3)); |
838 | - QCOMPARE(account->valueAsUInt64("big distance", 10, &source), quint64(3)); |
839 | - QCOMPARE(source, ACCOUNT); |
840 | - |
841 | - strval = account->valueAsString("test_unexisting", "hello"); |
842 | - QCOMPARE (strval, QString("hello")); |
843 | - |
844 | - delete account; |
845 | - delete mgr; |
846 | -} |
847 | - |
848 | - |
849 | -void AccountsTest::stored() |
850 | -{ |
851 | - qDebug("%s %d %s:\t", __FILE__, __LINE__, __func__); |
852 | - TRACE(); |
853 | - m_stored = true; |
854 | -} |
855 | - |
856 | -void AccountsTest::error(Accounts::Error error) |
857 | -{ |
858 | - qDebug("%s %d %s:\t", __FILE__, __LINE__, __func__); |
859 | - TRACE() << "error:" << error.type(); |
860 | - m_stored = false; |
861 | -} |
862 | - |
863 | - |
864 | -void AccountsTest::accountSyncTestCase() |
865 | -{ |
866 | - Manager * mgr=new Manager(); |
867 | - QVERIFY(mgr!=NULL); |
868 | - |
869 | - Account *account = mgr->createAccount(PROVIDER); |
870 | - QVERIFY(account!=NULL); |
871 | - |
872 | - QString provider = account->providerName(); |
873 | - QCOMPARE(provider, PROVIDER); |
874 | - |
875 | - m_stored = false; |
876 | - QObject::connect(account, SIGNAL(synced()), |
877 | - this, SLOT(stored())); |
878 | - |
879 | - account->sync(); |
880 | - QTest::qWait(10); |
881 | - QVERIFY(m_stored); |
882 | - |
883 | - delete account; |
884 | - delete mgr; |
885 | -} |
886 | - |
887 | -void AccountsTest::created(Accounts::AccountId id) |
888 | -{ |
889 | - m_created = id; |
890 | -} |
891 | - |
892 | -void AccountsTest::createdTestCase() |
893 | -{ |
894 | - Manager *mgr = new Manager(); |
895 | - QVERIFY(mgr != NULL); |
896 | - |
897 | - m_created = 0; |
898 | - QObject::connect(mgr, SIGNAL(accountCreated(Accounts::AccountId)), |
899 | - this, SLOT(created(Accounts::AccountId))); |
900 | - |
901 | - Account *account = mgr->createAccount(NULL); |
902 | - QVERIFY(account != NULL); |
903 | - |
904 | - /* store the account: this will emit accountCreated */ |
905 | - account->sync(); |
906 | - QVERIFY(m_created != 0); |
907 | - QVERIFY(m_created == account->id()); |
908 | - |
909 | - delete account; |
910 | - delete mgr; |
911 | -} |
912 | - |
913 | -void AccountsTest::removed() |
914 | -{ |
915 | - m_removed = true; |
916 | -} |
917 | - |
918 | -void AccountsTest::removeTestCase() |
919 | -{ |
920 | - Manager *mgr = new Manager(); |
921 | - QVERIFY(mgr != NULL); |
922 | - |
923 | - Account *account = mgr->createAccount(NULL); |
924 | - QVERIFY(account != NULL); |
925 | - |
926 | - /* store the account */ |
927 | - account->sync(); |
928 | - QVERIFY(account->id() != 0); |
929 | - |
930 | - m_removed = false; |
931 | - QObject::connect(account, SIGNAL(removed()), this, SLOT(removed())); |
932 | - |
933 | - /* mark the account for deletion -- and make sure it's not deleted |
934 | - * immediately */ |
935 | - account->remove (); |
936 | - QVERIFY(m_removed == false); |
937 | - |
938 | - /* store the changes */ |
939 | - account->sync(); |
940 | - QVERIFY(m_removed == true); |
941 | - |
942 | - delete account; |
943 | - delete mgr; |
944 | -} |
945 | - |
946 | -void AccountsTest::w_server_notify(const char *key) |
947 | -{ |
948 | - qDebug() << __func__ << ", key = " << key; |
949 | - m_server_notify++; |
950 | -} |
951 | - |
952 | -void AccountsTest::w_port_notify(const char *key) |
953 | -{ |
954 | - qDebug() << __func__ << ", key = " << key; |
955 | - m_port_notify++; |
956 | -} |
957 | - |
958 | -void AccountsTest::w_parameters_notify(const char *key) |
959 | -{ |
960 | - qDebug() << __func__ << ", key = " << key; |
961 | - m_parameters_notify++; |
962 | -} |
963 | - |
964 | -void AccountsTest::onAccountServiceEnabled(bool enabled) |
965 | -{ |
966 | - qDebug() << Q_FUNC_INFO; |
967 | - m_accountServiceEnabledValue = enabled; |
968 | -} |
969 | - |
970 | -void AccountsTest::onAccountServiceChanged() |
971 | -{ |
972 | - qDebug() << Q_FUNC_INFO; |
973 | - AccountService *accountService = qobject_cast<AccountService*>(sender()); |
974 | - m_accountServiceChangedFields = accountService->changedFields(); |
975 | -} |
976 | - |
977 | -void AccountsTest::accountServiceTest() |
978 | -{ |
979 | - Manager *mgr = new Manager(); |
980 | - QVERIFY (mgr != NULL); |
981 | - |
982 | - Service service = mgr->service(MYSERVICE); |
983 | - QVERIFY(service.isValid()); |
984 | - |
985 | - Account *account = mgr->createAccount(NULL); |
986 | - QVERIFY(account != NULL); |
987 | - |
988 | - QObject *parent = new QObject(); |
989 | - QPointer<AccountService> shortLivedAccountService = |
990 | - new AccountService(account, service, parent); |
991 | - QVERIFY(shortLivedAccountService != 0); |
992 | - delete parent; |
993 | - QVERIFY(shortLivedAccountService == 0); |
994 | - |
995 | - AccountService *accountService = new AccountService(account, service); |
996 | - QVERIFY(accountService != NULL); |
997 | - |
998 | - QCOMPARE(accountService->account(), account); |
999 | - QCOMPARE(accountService->account()->providerName(), |
1000 | - account->providerName()); |
1001 | - Service copy = accountService->service(); |
1002 | - QVERIFY(copy.isValid()); |
1003 | - QCOMPARE(copy.name(), service.name()); |
1004 | - |
1005 | - QObject::connect(accountService, SIGNAL(changed()), |
1006 | - this, SLOT(onAccountServiceChanged())); |
1007 | - QObject::connect(accountService, SIGNAL(enabled(bool)), |
1008 | - this, SLOT(onAccountServiceEnabled(bool))); |
1009 | - QSignalSpy spyChanged(accountService, SIGNAL(changed())); |
1010 | - QSignalSpy spyEnabled(accountService, SIGNAL(enabled(bool))); |
1011 | - |
1012 | - accountService->beginGroup("parameters"); |
1013 | - QVERIFY(accountService->group() == "parameters"); |
1014 | - |
1015 | - /* test values from the template */ |
1016 | - QCOMPARE(accountService->value("server").toString(), |
1017 | - UTF8("talk.google.com")); |
1018 | - QCOMPARE(accountService->value("port").toInt(), 5223); |
1019 | - QCOMPARE(accountService->value("old-ssl").toBool(), true); |
1020 | - |
1021 | - /* now, change some values */ |
1022 | - accountService->setValue("server", QString("www.example.com")); |
1023 | - account->selectService(); |
1024 | - account->setEnabled(true); |
1025 | - account->selectService(service); |
1026 | - account->setEnabled(true); |
1027 | - |
1028 | - /* write the data */ |
1029 | - account->sync(); |
1030 | - |
1031 | - /* ensure that the callbacks have been called the correct number of times */ |
1032 | - QCOMPARE(spyChanged.count(), 1); |
1033 | - spyChanged.clear(); |
1034 | - spyEnabled.clear(); |
1035 | - |
1036 | - QStringList expectedChanges; |
1037 | - expectedChanges << "parameters/server"; |
1038 | - expectedChanges << "enabled"; |
1039 | - QCOMPARE(m_accountServiceChangedFields.toSet(), expectedChanges.toSet()); |
1040 | - |
1041 | - QCOMPARE(accountService->value("server").toString(), |
1042 | - UTF8("www.example.com")); |
1043 | - QCOMPARE(accountService->enabled(), true); |
1044 | - |
1045 | - /* check the enabled status */ |
1046 | - account->selectService(); |
1047 | - account->setEnabled(false); |
1048 | - account->sync(); |
1049 | - QCOMPARE(spyChanged.count(), 0); |
1050 | - QCOMPARE(spyEnabled.count(), 1); |
1051 | - QCOMPARE(accountService->enabled(), false); |
1052 | - QCOMPARE(m_accountServiceEnabledValue, accountService->enabled()); |
1053 | - spyEnabled.clear(); |
1054 | - |
1055 | - /* enable the account, but disable the service */ |
1056 | - account->selectService(); |
1057 | - account->setEnabled(true); |
1058 | - account->selectService(service); |
1059 | - account->setEnabled(false); |
1060 | - account->sync(); |
1061 | - QCOMPARE(spyEnabled.count(), 0); |
1062 | - QCOMPARE(accountService->enabled(), false); |
1063 | - |
1064 | - /* re-enable the service */ |
1065 | - account->selectService(service); |
1066 | - account->setEnabled(true); |
1067 | - account->sync(); |
1068 | - QCOMPARE(spyEnabled.count(), 1); |
1069 | - QCOMPARE(accountService->enabled(), true); |
1070 | - QCOMPARE(m_accountServiceEnabledValue, accountService->enabled()); |
1071 | - spyEnabled.clear(); |
1072 | - spyChanged.clear(); |
1073 | - |
1074 | - |
1075 | - /* test some more APIs */ |
1076 | - QStringList expectedList; |
1077 | - expectedList << "server" << "fallback-conference-server" << |
1078 | - "port" << "old-ssl"; |
1079 | - QCOMPARE(accountService->childKeys().toSet(), expectedList.toSet()); |
1080 | - QCOMPARE(accountService->childGroups().toSet(), QSet<QString>()); |
1081 | - QCOMPARE(accountService->contains("port"), true); |
1082 | - accountService->endGroup(); |
1083 | - |
1084 | - expectedList.clear(); |
1085 | - expectedList << "parameters"; |
1086 | - QCOMPARE(accountService->childGroups().toSet(), expectedList.toSet()); |
1087 | - |
1088 | - /* Remove one key */ |
1089 | - accountService->remove("parameters/port"); |
1090 | - account->sync(); |
1091 | - QCOMPARE(spyChanged.count(), 1); |
1092 | - QCOMPARE(m_accountServiceChangedFields, QStringList("parameters/port")); |
1093 | - spyChanged.clear(); |
1094 | - |
1095 | - /* remove all keys */ |
1096 | - accountService->clear(); |
1097 | - account->sync(); |
1098 | - QCOMPARE(spyChanged.count(), 1); |
1099 | - QVERIFY(m_accountServiceChangedFields.contains("parameters/server")); |
1100 | - QVERIFY(m_accountServiceChangedFields.contains("parameters/old-ssl")); |
1101 | - spyChanged.clear(); |
1102 | - |
1103 | - delete accountService; |
1104 | - delete account; |
1105 | - delete mgr; |
1106 | -} |
1107 | - |
1108 | -void AccountsTest::watchesTest() |
1109 | -{ |
1110 | - Manager *mgr = new Manager(); |
1111 | - QVERIFY (mgr != NULL); |
1112 | - |
1113 | - Service service = mgr->service(MYSERVICE); |
1114 | - QVERIFY(service.isValid()); |
1115 | - |
1116 | - /* create an account and some watches */ |
1117 | - Account *account = mgr->createAccount(NULL); |
1118 | - QVERIFY(account != NULL); |
1119 | - |
1120 | - account->selectService(service); |
1121 | - |
1122 | - Watch *w_server = account->watchKey("parameters/server"); |
1123 | - QObject::connect(w_server, SIGNAL(notify(const char *)), |
1124 | - this, SLOT(w_server_notify(const char *))); |
1125 | - |
1126 | - /* test also beginGroup() */ |
1127 | - account->beginGroup("parameters"); |
1128 | - QVERIFY(account->group() == "parameters"); |
1129 | - |
1130 | - Watch *w_parameters = account->watchKey(); /* watch the whole group */ |
1131 | - QObject::connect(w_parameters, SIGNAL(notify(const char *)), |
1132 | - this, SLOT(w_parameters_notify(const char *))); |
1133 | - |
1134 | - Watch *w_port = account->watchKey("port"); |
1135 | - QObject::connect(w_port, SIGNAL(notify(const char *)), |
1136 | - this, SLOT(w_port_notify(const char *))); |
1137 | - |
1138 | - /* now, change some values */ |
1139 | - account->setValue("server", QString("xxx.nokia.com")); |
1140 | - |
1141 | - /* reset the counters */ |
1142 | - m_server_notify = 0; |
1143 | - m_port_notify = 0; |
1144 | - m_parameters_notify = 0; |
1145 | - |
1146 | - /* write the data */ |
1147 | - account->sync(); |
1148 | - |
1149 | - /* ensure that the callbacks have been called the correct number of times */ |
1150 | - QVERIFY(m_server_notify == 1); |
1151 | - QVERIFY(m_parameters_notify == 1); |
1152 | - QVERIFY(m_port_notify == 0); |
1153 | - |
1154 | - /* now change the port and another parameter not being watched */ |
1155 | - account->setValue("port", 45); |
1156 | - account->endGroup(); /* exit from the "parameters/" prefix */ |
1157 | - account->setValue("username", QString("h4ck3r@nokia.com")); |
1158 | - |
1159 | - /* reset the counters */ |
1160 | - m_server_notify = 0; |
1161 | - m_port_notify = 0; |
1162 | - m_parameters_notify = 0; |
1163 | - |
1164 | - /* write the data */ |
1165 | - account->sync(); |
1166 | - |
1167 | - /* ensure that the callbacks have been called the correct number of times */ |
1168 | - QVERIFY(m_server_notify == 0); |
1169 | - QVERIFY(m_parameters_notify == 1); |
1170 | - QVERIFY(m_port_notify == 1); |
1171 | - |
1172 | - /* change port and server, but delete the w_port watch */ |
1173 | - delete w_port; |
1174 | - |
1175 | - account->beginGroup("parameters"); |
1176 | - account->setValue("port", 56); |
1177 | - account->setValue("server", QString("warez.nokia.com")); |
1178 | - |
1179 | - /* reset the counters */ |
1180 | - m_server_notify = 0; |
1181 | - m_port_notify = 0; |
1182 | - m_parameters_notify = 0; |
1183 | - |
1184 | - /* write the data */ |
1185 | - account->sync(); |
1186 | - |
1187 | - /* ensure that the callbacks have been called the correct number of times */ |
1188 | - QVERIFY(m_server_notify == 1); |
1189 | - QVERIFY(m_parameters_notify == 1); |
1190 | - QVERIFY(m_port_notify == 0); |
1191 | - |
1192 | - |
1193 | - delete account; |
1194 | - delete mgr; |
1195 | -} |
1196 | - |
1197 | -void AccountsTest::serviceDataTest() |
1198 | -{ |
1199 | - Manager *mgr = new Manager(); |
1200 | - QVERIFY (mgr != NULL); |
1201 | - |
1202 | - Service service = mgr->service(MYSERVICE); |
1203 | - QVERIFY(service.isValid()); |
1204 | - |
1205 | - QDomDocument doc = service.domDocument(); |
1206 | - QVERIFY(!doc.isNull()); |
1207 | - |
1208 | - delete mgr; |
1209 | -} |
1210 | - |
1211 | -void AccountsTest::settingsTest() |
1212 | -{ |
1213 | - Manager *mgr = new Manager(); |
1214 | - QVERIFY (mgr != NULL); |
1215 | - |
1216 | - /* create an account and some watches */ |
1217 | - Account *account = mgr->createAccount(NULL); |
1218 | - QVERIFY(account != NULL); |
1219 | - |
1220 | - /* create a few keys/groups */ |
1221 | - account->setValue("username", QString("fool")); |
1222 | - account->setValue("email", QString("fool@domain.com")); |
1223 | - |
1224 | - account->beginGroup("parameters"); |
1225 | - account->setValue("server", QString("xxx.nokia.com")); |
1226 | - account->setValue("port", 80); |
1227 | - |
1228 | - account->beginGroup("proxy"); /* this is a subgroup of "parameters" */ |
1229 | - account->setValue("use", true); |
1230 | - account->setValue("address", QString("proxy.nokia.com")); |
1231 | - QCOMPARE(account->group(), QString("parameters/proxy")); |
1232 | - account->endGroup(); |
1233 | - |
1234 | - QCOMPARE(account->group(), QString("parameters")); |
1235 | - account->endGroup(); |
1236 | - |
1237 | - /* write another top-level key */ |
1238 | - account->setValue("verified", false); |
1239 | - |
1240 | - /* re-enter a group */ |
1241 | - account->beginGroup("preferences"); |
1242 | - account->setValue("maximized", true); |
1243 | - account->setValue("initial_directory", QString("xxx")); |
1244 | - QCOMPARE(account->group(), QString("preferences")); |
1245 | - account->endGroup(); |
1246 | - |
1247 | - /* write the data */ |
1248 | - account->sync(); |
1249 | - |
1250 | - /* now check if the groups and keys are layed out as expected */ |
1251 | - QStringList expected; |
1252 | - QStringList result; |
1253 | - |
1254 | - /* check allKeys() */ |
1255 | - expected << "username" << "email" << "verified" << |
1256 | - "parameters/server" << "parameters/port" << |
1257 | - "parameters/proxy/use" << "parameters/proxy/address" << |
1258 | - "preferences/maximized" << "preferences/initial_directory"; |
1259 | - result = account->allKeys(); |
1260 | - |
1261 | - expected.sort(); |
1262 | - result.sort(); |
1263 | - QCOMPARE(result, expected); |
1264 | - |
1265 | - /* check childGroups() */ |
1266 | - expected.clear(); |
1267 | - expected << "parameters" << "preferences"; |
1268 | - result = account->childGroups(); |
1269 | - |
1270 | - expected.sort(); |
1271 | - result.sort(); |
1272 | - QCOMPARE(result, expected); |
1273 | - |
1274 | - /* check childKeys() */ |
1275 | - expected.clear(); |
1276 | - expected << "username" << "email" << "verified"; |
1277 | - result = account->childKeys(); |
1278 | - |
1279 | - expected.sort(); |
1280 | - result.sort(); |
1281 | - QCOMPARE(result, expected); |
1282 | - |
1283 | - |
1284 | - /* now enter a group and test the same methods as above */ |
1285 | - account->beginGroup("parameters"); |
1286 | - |
1287 | - /* allKeys */ |
1288 | - expected.clear(); |
1289 | - expected << "server" << "port" << "proxy/use" << "proxy/address"; |
1290 | - result = account->allKeys(); |
1291 | - |
1292 | - expected.sort(); |
1293 | - result.sort(); |
1294 | - QCOMPARE(result, expected); |
1295 | - |
1296 | - /* childGroups */ |
1297 | - expected.clear(); |
1298 | - expected << "proxy"; |
1299 | - result = account->childGroups(); |
1300 | - |
1301 | - expected.sort(); |
1302 | - result.sort(); |
1303 | - QCOMPARE(result, expected); |
1304 | - |
1305 | - /* childKeys() */ |
1306 | - expected.clear(); |
1307 | - expected << "server" << "port"; |
1308 | - result = account->childKeys(); |
1309 | - |
1310 | - expected.sort(); |
1311 | - result.sort(); |
1312 | - QCOMPARE(result, expected); |
1313 | - |
1314 | - /* contains() */ |
1315 | - QVERIFY(account->contains("server") == true); |
1316 | - QVERIFY(account->contains("unexisting") == false); |
1317 | - |
1318 | - /* test remove() */ |
1319 | - account->remove(""); /* remove all the parameters/ group */ |
1320 | - account->endGroup(); |
1321 | - account->remove("verified"); |
1322 | - |
1323 | - /* we need to sync, for the changes to take effect */ |
1324 | - account->sync(); |
1325 | - |
1326 | - expected.clear(); |
1327 | - expected << "username" << "email" << |
1328 | - "preferences/maximized" << "preferences/initial_directory"; |
1329 | - result = account->allKeys(); |
1330 | - |
1331 | - expected.sort(); |
1332 | - result.sort(); |
1333 | - QCOMPARE(result, expected); |
1334 | - |
1335 | - /* Test clear(): call it from inside the preferences/ group */ |
1336 | - account->beginGroup("preferences"); |
1337 | - account->clear(); |
1338 | - account->sync(); |
1339 | - |
1340 | - expected.clear(); /* all keys should have been deleted */ |
1341 | - result = account->allKeys(); |
1342 | - |
1343 | - expected.sort(); |
1344 | - result.sort(); |
1345 | - QCOMPARE(result, expected); |
1346 | - |
1347 | - delete account; |
1348 | - delete mgr; |
1349 | -} |
1350 | - |
1351 | -void AccountsTest::keySignVerifyTest() |
1352 | -{ |
1353 | -#ifndef HAVE_AEGISCRYPTO |
1354 | - QSKIP("aegis-crypto not detected.", SkipSingle); |
1355 | -#endif |
1356 | - |
1357 | - const QString key = "key"; |
1358 | - const char *token; |
1359 | - QList<const char*> listOfTokens; |
1360 | - listOfTokens << "libaccounts-glib0::accounts-glib-access" |
1361 | - << "libaccounts-glib0::dummy" |
1362 | - << "libaccounts-glib0::idiotic"; |
1363 | - bool ok; |
1364 | - |
1365 | - Manager *mgr = new Manager(); |
1366 | - QVERIFY (mgr != NULL); |
1367 | - |
1368 | - Account *account = mgr->createAccount(NULL); |
1369 | - QVERIFY(account != NULL); |
1370 | - |
1371 | - account->setValue(key, QString("the key value")); |
1372 | - account->syncAndBlock(); |
1373 | - |
1374 | - account->sign(key, listOfTokens.at(0)); |
1375 | - account->syncAndBlock(); |
1376 | - |
1377 | - ok = account->verify(key, &token); |
1378 | - QVERIFY(ok == true); |
1379 | - |
1380 | - ok = account->verifyWithTokens(key, listOfTokens); |
1381 | - QVERIFY(ok == true); |
1382 | - |
1383 | - delete mgr; |
1384 | -} |
1385 | - |
1386 | -void AccountsTest::incrementalAccountIdsTest() |
1387 | -{ |
1388 | - clearDb(); |
1389 | - |
1390 | - Manager * mgr = new Manager; |
1391 | - QVERIFY(mgr != NULL); |
1392 | - |
1393 | - Account *account = mgr->createAccount(NULL); |
1394 | - QVERIFY(account != NULL); |
1395 | - QVERIFY(account->manager() == mgr); |
1396 | - account->syncAndBlock(); |
1397 | - AccountId lastId = account->id(); |
1398 | - |
1399 | - account->remove(); |
1400 | - account->syncAndBlock(); |
1401 | - delete account; |
1402 | - |
1403 | - account = mgr->createAccount(NULL); |
1404 | - QVERIFY(account != NULL); |
1405 | - QVERIFY(account->manager() == mgr); |
1406 | - account->syncAndBlock(); |
1407 | - |
1408 | - QCOMPARE(account->id(), lastId + 1); |
1409 | - |
1410 | - delete account; |
1411 | - delete mgr; |
1412 | -} |
1413 | - |
1414 | -void AccountsTest::selectGlobalAccountSettingsTest() |
1415 | -{ |
1416 | - Manager *mgr = new Manager; |
1417 | - QVERIFY(mgr != NULL); |
1418 | - |
1419 | - Account *account = mgr->createAccount("MyProvider"); |
1420 | - QVERIFY(account != NULL); |
1421 | - QVERIFY(account->manager() == mgr); |
1422 | - |
1423 | - account->syncAndBlock(); |
1424 | - QVERIFY(account->id() > 0); |
1425 | - |
1426 | - account->selectService(); |
1427 | - Service selectedService = account->selectedService(); |
1428 | - QVERIFY(!selectedService.isValid()); |
1429 | - |
1430 | - delete mgr; |
1431 | -} |
1432 | - |
1433 | -void AccountsTest::credentialsIdTest() |
1434 | -{ |
1435 | - Manager *mgr = new Manager; |
1436 | - QVERIFY(mgr != NULL); |
1437 | - |
1438 | - Account *account = mgr->createAccount("MyProvider"); |
1439 | - QVERIFY(account != NULL); |
1440 | - |
1441 | - Service service = mgr->service(MYSERVICE); |
1442 | - QVERIFY(service.isValid()); |
1443 | - |
1444 | - uint globalId = 69, myServiceId = 0xDEAD; |
1445 | - |
1446 | - account->setCredentialsId(globalId); |
1447 | - |
1448 | - account->selectService(service); |
1449 | - account->setCredentialsId(myServiceId); |
1450 | - |
1451 | - account->syncAndBlock(); |
1452 | - QVERIFY(account->id() != 0); |
1453 | - |
1454 | - QCOMPARE(account->credentialsId(), myServiceId); |
1455 | - |
1456 | - /* select a service with no credentials: we should get the global |
1457 | - * credentials ID, but the selected service shouldn't change */ |
1458 | - service = mgr->service(OTHERSERVICE); |
1459 | - QVERIFY(service.isValid()); |
1460 | - |
1461 | - account->selectService(service); |
1462 | - QCOMPARE(account->credentialsId(), globalId); |
1463 | - QCOMPARE(account->selectedService(), service); |
1464 | - |
1465 | - /* now make sure that we can get the ID from the global accounts settings */ |
1466 | - account->selectService(); |
1467 | - QCOMPARE(account->credentialsId(), globalId); |
1468 | - |
1469 | - delete mgr; |
1470 | -} |
1471 | - |
1472 | -void AccountsTest::authDataTest() |
1473 | -{ |
1474 | - Manager *manager = new Manager; |
1475 | - QVERIFY(manager != NULL); |
1476 | - |
1477 | - Account *account = manager->createAccount("MyProvider"); |
1478 | - QVERIFY(account != NULL); |
1479 | - |
1480 | - Service service = manager->service(MYSERVICE); |
1481 | - QVERIFY(service.isValid()); |
1482 | - |
1483 | - const uint credentialsId = 69; |
1484 | - const QString method = "mymethod"; |
1485 | - const QString mechanism = "mymechanism"; |
1486 | - QString prefix = |
1487 | - QString::fromLatin1("auth/%1/%2/").arg(method).arg(mechanism); |
1488 | - |
1489 | - QVariantMap globalParameters; |
1490 | - globalParameters["server"] = UTF8("myserver.com"); |
1491 | - globalParameters["port"] = 8080; |
1492 | - globalParameters["other"] = UTF8("overriden parameter"); |
1493 | - globalParameters["scopes"] = QStringList() << "read" << "write" << "edit"; |
1494 | - |
1495 | - QVariantMap serviceParameters; |
1496 | - serviceParameters["other"] = UTF8("better parameter"); |
1497 | - serviceParameters["boolean"] = true; |
1498 | - |
1499 | - account->setCredentialsId(credentialsId); |
1500 | - account->setValue("auth/method", method); |
1501 | - account->setValue("auth/mechanism", UTF8("overriden mechanism")); |
1502 | - QMapIterator<QString,QVariant> i(globalParameters); |
1503 | - while (i.hasNext()) { |
1504 | - i.next(); |
1505 | - account->setValue(prefix + i.key(), i.value()); |
1506 | - } |
1507 | - |
1508 | - account->selectService(service); |
1509 | - account->setValue("auth/mechanism", mechanism); |
1510 | - i = QMapIterator<QString,QVariant>(serviceParameters); |
1511 | - while (i.hasNext()) { |
1512 | - i.next(); |
1513 | - account->setValue(prefix + i.key(), i.value()); |
1514 | - } |
1515 | - |
1516 | - account->syncAndBlock(); |
1517 | - QVERIFY(account->id() != 0); |
1518 | - |
1519 | - AccountService *accountService = new AccountService(account, service); |
1520 | - QVERIFY(accountService != 0); |
1521 | - |
1522 | - AuthData authData = accountService->authData(); |
1523 | - QCOMPARE(authData.method(), method); |
1524 | - QCOMPARE(authData.mechanism(), mechanism); |
1525 | - QCOMPARE(authData.credentialsId(), credentialsId); |
1526 | - |
1527 | - QVariantMap expectedParameters = globalParameters; |
1528 | - i = QMapIterator<QString,QVariant>(serviceParameters); |
1529 | - while (i.hasNext()) { |
1530 | - i.next(); |
1531 | - expectedParameters.insert(i.key(), i.value()); |
1532 | - } |
1533 | - |
1534 | - QCOMPARE(authData.parameters(), expectedParameters); |
1535 | - |
1536 | - /* Test copy constructor */ |
1537 | - AuthData copy(authData); |
1538 | - QCOMPARE(copy.parameters(), expectedParameters); |
1539 | - |
1540 | - /* And delete destructor */ |
1541 | - AuthData *copy2 = new AuthData(authData); |
1542 | - QCOMPARE(copy2->parameters(), expectedParameters); |
1543 | - delete copy2; |
1544 | - |
1545 | - delete accountService; |
1546 | - delete account; |
1547 | - delete manager; |
1548 | - QVERIFY(service.isValid()); |
1549 | -} |
1550 | - |
1551 | -void AccountsTest::globalAuthDataTest() |
1552 | -{ |
1553 | - Manager *manager = new Manager; |
1554 | - QVERIFY(manager != NULL); |
1555 | - |
1556 | - Account *account = manager->createAccount("MyProvider"); |
1557 | - QVERIFY(account != NULL); |
1558 | - |
1559 | - Service service; // global account |
1560 | - QVERIFY(!service.isValid()); |
1561 | - |
1562 | - AccountService *accountService = new AccountService(account, service); |
1563 | - QVERIFY(accountService != 0); |
1564 | - |
1565 | - AuthData authData = accountService->authData(); |
1566 | - QCOMPARE(authData.method(), QString("oauth2")); |
1567 | - QCOMPARE(authData.mechanism(), QString("user_agent")); |
1568 | - QCOMPARE(authData.credentialsId(), uint(0)); |
1569 | - |
1570 | - QVariantMap expectedParameters; |
1571 | - expectedParameters.insert("Host", QString("myserver.example")); |
1572 | - |
1573 | - QCOMPARE(authData.parameters(), expectedParameters); |
1574 | - |
1575 | - delete accountService; |
1576 | - delete account; |
1577 | - delete manager; |
1578 | -} |
1579 | - |
1580 | -void AccountsTest::listEnabledServices() |
1581 | -{ |
1582 | - clearDb(); |
1583 | - |
1584 | - Manager *mgr = new Manager(); |
1585 | - QVERIFY(mgr != NULL); |
1586 | - |
1587 | - Service service = mgr->service(MYSERVICE); |
1588 | - QVERIFY(service.isValid()); |
1589 | - |
1590 | - Account* account = mgr->createAccount("MyProvider"); |
1591 | - QVERIFY(account != NULL); |
1592 | - account->selectService(service); |
1593 | - account->setEnabled(true); |
1594 | - account->sync(); |
1595 | - |
1596 | - ServiceList list = account->enabledServices(); |
1597 | - QVERIFY(!list.isEmpty()); |
1598 | - QCOMPARE(list.size(), 1); |
1599 | - |
1600 | - account->selectService(service); |
1601 | - account->setEnabled(false); |
1602 | - account->sync(); |
1603 | - |
1604 | - list = account->enabledServices(); |
1605 | - QVERIFY(list.isEmpty()); |
1606 | - |
1607 | - delete account; |
1608 | - delete mgr; |
1609 | -} |
1610 | - |
1611 | - |
1612 | -void AccountsTest::listEnabledByServiceType() |
1613 | -{ |
1614 | - clearDb(); |
1615 | - |
1616 | - Manager *mgr = new Manager("e-mail"); |
1617 | - QVERIFY(mgr != NULL); |
1618 | - QCOMPARE(mgr->serviceType(), QString("e-mail")); |
1619 | - |
1620 | - Account *account = mgr->createAccount("MyProvider"); |
1621 | - QVERIFY(account != NULL); |
1622 | - account->setEnabled(true); |
1623 | - |
1624 | - Service service = mgr->service(MYSERVICE); |
1625 | - QVERIFY(service.isValid()); |
1626 | - account->selectService(service); |
1627 | - account->setEnabled(true); |
1628 | - account->sync(); |
1629 | - |
1630 | - AccountIdList list = mgr->accountListEnabled("e-mail"); |
1631 | - QVERIFY(!list.isEmpty()); |
1632 | - QCOMPARE(list.size(), 1); |
1633 | - |
1634 | - list = mgr->accountListEnabled(); |
1635 | - QCOMPARE(list.count(), 1); |
1636 | - |
1637 | - account->setEnabled(false); |
1638 | - account->sync(); |
1639 | - |
1640 | - list = mgr->accountListEnabled("e-mail"); |
1641 | - QVERIFY(list.isEmpty()); |
1642 | - |
1643 | - delete account; |
1644 | - delete mgr; |
1645 | -} |
1646 | - |
1647 | -void AccountsTest::enabledEvent(Accounts::AccountId id) |
1648 | -{ |
1649 | - m_enabledEvent = id; |
1650 | -} |
1651 | - |
1652 | -void AccountsTest::enabledEvent() |
1653 | -{ |
1654 | - Manager *mgr = new Manager("e-mail"); |
1655 | - QVERIFY(mgr != NULL); |
1656 | - |
1657 | - m_enabledEvent = 0; |
1658 | - QObject::connect(mgr, SIGNAL(enabledEvent(Accounts::AccountId)), |
1659 | - this, SLOT(enabledEvent(Accounts::AccountId))); |
1660 | - |
1661 | - Account *account = mgr->createAccount(NULL); |
1662 | - QVERIFY(account != NULL); |
1663 | - account->setEnabled(true); |
1664 | - account->sync(); |
1665 | - |
1666 | - QVERIFY(m_enabledEvent != 0); |
1667 | - QVERIFY(m_enabledEvent == account->id()); |
1668 | - |
1669 | - //if we create manager without service type the signal shoudl not be emitted |
1670 | - Manager *mgr2 = new Manager(); |
1671 | - QVERIFY(mgr2 != NULL); |
1672 | - |
1673 | - m_enabledEvent = 0; |
1674 | - QObject::connect(mgr2, SIGNAL(enabledEvent(Accounts::AccountId)), |
1675 | - this, SLOT(enabledEvent(Accounts::AccountId))); |
1676 | - |
1677 | - Account *account2 = mgr2->createAccount(NULL); |
1678 | - QVERIFY(account2 != NULL); |
1679 | - account2->setEnabled(true); |
1680 | - account2->sync(); |
1681 | - |
1682 | - QVERIFY(m_enabledEvent == 0); |
1683 | - QVERIFY(m_enabledEvent != account2->id()); |
1684 | - |
1685 | - delete account; |
1686 | - delete account2; |
1687 | - delete mgr; |
1688 | - delete mgr2; |
1689 | -} |
1690 | - |
1691 | -void AccountsTest::serviceTypeTestCase() |
1692 | -{ |
1693 | - Manager *mgr = new Manager(); |
1694 | - QVERIFY(mgr != NULL); |
1695 | - |
1696 | - ServiceType serviceType; |
1697 | - |
1698 | - serviceType = mgr->serviceType("unexisting-type"); |
1699 | - QVERIFY(!serviceType.isValid()); |
1700 | - |
1701 | - serviceType = mgr->serviceType(EMAIL_SERVICE_TYPE); |
1702 | - QVERIFY(serviceType.isValid()); |
1703 | - |
1704 | - QCOMPARE(serviceType.name(), EMAIL_SERVICE_TYPE); |
1705 | - QCOMPARE(serviceType.displayName(), QLatin1String("Electronic mail")); |
1706 | - QCOMPARE(serviceType.trCatalog(), QLatin1String("translation_file")); |
1707 | - QCOMPARE(serviceType.iconName(), QLatin1String("email_icon")); |
1708 | - QVERIFY(serviceType.tags().contains(QString("email"))); |
1709 | - // called twice, because the second time it returns a cached result |
1710 | - QVERIFY(serviceType.tags().contains(QString("email"))); |
1711 | - QVERIFY(serviceType.hasTag(QString("email"))); |
1712 | - QVERIFY(!serviceType.hasTag(QString("fake-email"))); |
1713 | - |
1714 | - QDomDocument dom = serviceType.domDocument(); |
1715 | - QDomElement root = dom.documentElement(); |
1716 | - QCOMPARE(root.tagName(), QString("service-type")); |
1717 | - |
1718 | - ServiceType copy(serviceType); |
1719 | - QCOMPARE(copy.displayName(), QLatin1String("Electronic mail")); |
1720 | - |
1721 | - delete mgr; |
1722 | -} |
1723 | - |
1724 | -void AccountsTest::updateAccountTestCase() |
1725 | -{ |
1726 | - clearDb(); |
1727 | - |
1728 | - Manager *mgr = new Manager("e-mail"); |
1729 | - QVERIFY(mgr != NULL); |
1730 | - |
1731 | - m_updateEvent = 0; |
1732 | - QObject::connect(mgr, SIGNAL(accountUpdated(Accounts::AccountId)), |
1733 | - this, SLOT(updateAccount(Accounts::AccountId))); |
1734 | - |
1735 | - Account *account = mgr->createAccount("MyProvider"); |
1736 | - QVERIFY(account != NULL); |
1737 | - account->syncAndBlock(); |
1738 | - |
1739 | - Service service = mgr->service(MYSERVICE); |
1740 | - QVERIFY(service.isValid()); |
1741 | - account->selectService(service); |
1742 | - |
1743 | - account->setValue("key", QVariant("value")); |
1744 | - account->syncAndBlock(); |
1745 | - |
1746 | - QVERIFY(m_updateEvent != 0); |
1747 | - QVERIFY(m_updateEvent == account->id()); |
1748 | - |
1749 | - //if we create manager without service type the signal shoudl not be emitted |
1750 | - Manager *mgr2 = new Manager(); |
1751 | - QVERIFY(mgr2 != NULL); |
1752 | - |
1753 | - m_updateEvent = 0; |
1754 | - QObject::connect(mgr2, SIGNAL(accountUpdated(Accounts::AccountId)), |
1755 | - this, SLOT(updateAccount(Accounts::AccountId))); |
1756 | - |
1757 | - Account *account2 = mgr2->createAccount(NULL); |
1758 | - QVERIFY(account2 != NULL); |
1759 | - |
1760 | - account2->setValue("key", QVariant("value")); |
1761 | - account2->syncAndBlock(); |
1762 | - |
1763 | - QVERIFY(m_updateEvent == 0); |
1764 | - QVERIFY(m_updateEvent != account2->id()); |
1765 | - |
1766 | - delete account; |
1767 | - delete account2; |
1768 | - delete mgr; |
1769 | - delete mgr2; |
1770 | -} |
1771 | - |
1772 | -void AccountsTest::updateAccount(Accounts::AccountId id) |
1773 | -{ |
1774 | - m_updateEvent = id; |
1775 | -} |
1776 | - |
1777 | -void AccountsTest::applicationTest() |
1778 | -{ |
1779 | - Manager *manager = new Manager(); |
1780 | - QVERIFY(manager != 0); |
1781 | - |
1782 | - Application application = manager->application("Mailer"); |
1783 | - QVERIFY(application.isValid()); |
1784 | - |
1785 | - Service email = manager->service("MyService"); |
1786 | - QVERIFY(email.isValid()); |
1787 | - |
1788 | - Service sharing = manager->service("OtherService"); |
1789 | - QVERIFY(sharing.isValid()); |
1790 | - |
1791 | - QCOMPARE(application.name(), UTF8("Mailer")); |
1792 | - QCOMPARE(application.displayName(), UTF8("Easy Mailer")); |
1793 | - QCOMPARE(application.description(), UTF8("Mailer application")); |
1794 | - QCOMPARE(application.trCatalog(), UTF8("mailer-catalog")); |
1795 | - QCOMPARE(application.iconName(), UTF8("mailer-icon")); |
1796 | - QCOMPARE(application.desktopFilePath(), |
1797 | - UTF8(qgetenv("AG_APPLICATIONS") + "/applications/mailer.desktop")); |
1798 | - QCOMPARE(application.serviceUsage(email), |
1799 | - UTF8("Mailer can retrieve your e-mails")); |
1800 | - |
1801 | - ApplicationList apps = manager->applicationList(email); |
1802 | - QCOMPARE(apps.count(), 1); |
1803 | - QCOMPARE(apps[0].name(), UTF8("Mailer")); |
1804 | - |
1805 | - apps = manager->applicationList(sharing); |
1806 | - QCOMPARE(apps.count(), 1); |
1807 | - application = apps[0]; |
1808 | - QCOMPARE(application.name(), UTF8("Gallery")); |
1809 | - QCOMPARE(application.description(), UTF8("Image gallery")); |
1810 | - QCOMPARE(application.serviceUsage(sharing), |
1811 | - UTF8("Publish images on OtherService")); |
1812 | - |
1813 | - /* Test an invalid application */ |
1814 | - Application app2; |
1815 | - QVERIFY(!app2.isValid()); |
1816 | - Application app3(app2); |
1817 | - QVERIFY(!app3.isValid()); |
1818 | - |
1819 | - delete manager; |
1820 | -} |
1821 | - |
1822 | -QTEST_MAIN(AccountsTest) |
1823 | -// #include "testqstring.moc" |
1824 | |
1825 | === removed file 'tests/accountstest.h' |
1826 | --- tests/accountstest.h 2013-04-26 06:31:51 +0000 |
1827 | +++ tests/accountstest.h 1970-01-01 00:00:00 +0000 |
1828 | @@ -1,130 +0,0 @@ |
1829 | -/* |
1830 | - * This file is part of libaccounts-qt |
1831 | - * |
1832 | - * Copyright (C) 2009-2011 Nokia Corporation. |
1833 | - * |
1834 | - * Contact: Alberto Mardegan <alberto.mardegan@nokia.com> |
1835 | - * |
1836 | - * This library is free software; you can redistribute it and/or |
1837 | - * modify it under the terms of the GNU Lesser General Public License |
1838 | - * version 2.1 as published by the Free Software Foundation. |
1839 | - * |
1840 | - * This library is distributed in the hope that it will be useful, but |
1841 | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
1842 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1843 | - * Lesser General Public License for more details. |
1844 | - * |
1845 | - * You should have received a copy of the GNU Lesser General Public |
1846 | - * License along with this library; if not, write to the Free Software |
1847 | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
1848 | - * 02110-1301 USA |
1849 | - */ |
1850 | -#ifndef ACCOUNTSTEST_H |
1851 | -#define ACCOUNTSTEST_H |
1852 | - |
1853 | -#include <QObject> |
1854 | - |
1855 | -#include "Accounts/Account" |
1856 | - |
1857 | -using namespace Accounts; |
1858 | - |
1859 | -class AccountsTest : public QObject |
1860 | -{ |
1861 | - Q_OBJECT |
1862 | - |
1863 | -public: |
1864 | - |
1865 | -public slots: |
1866 | - void stored(); |
1867 | - void error(Accounts::Error error); |
1868 | - void enabled(const QString &serviceName, bool enabled); |
1869 | - void enabledEvent(Accounts::AccountId id); |
1870 | - void display(const QString &serviceName); |
1871 | - void created(Accounts::AccountId id); |
1872 | - void removed(); |
1873 | - void w_server_notify(const char *); |
1874 | - void w_port_notify(const char *); |
1875 | - void w_parameters_notify(const char *); |
1876 | - void updateAccount(Accounts::AccountId id); |
1877 | - void onAccountServiceEnabled(bool enabled); |
1878 | - void onAccountServiceChanged(); |
1879 | - |
1880 | -private slots: |
1881 | - void initTestCase(); |
1882 | - void cleanupTestCase(); |
1883 | - |
1884 | - void managerTestCase(); |
1885 | - void createAccountTestCase(); |
1886 | - void accountTestCase(); |
1887 | - void objectsLifetimeTestCase(); |
1888 | - void accountListTestCase(); |
1889 | - |
1890 | - void providerTestCase(); |
1891 | - void serviceTestCase(); |
1892 | - void serviceListTestCase(); |
1893 | - |
1894 | - void serviceConstTestCase(); |
1895 | - |
1896 | - void accountConstTestCase(); |
1897 | - |
1898 | - void accountProviderTestCase(); |
1899 | - void accountServiceTestCase(); |
1900 | - void accountEnabledTestCase(); |
1901 | - void accountDisplayNameTestCase(); |
1902 | - |
1903 | - void accountValueTestCase(); |
1904 | - |
1905 | - void accountSyncTestCase(); |
1906 | - |
1907 | - void createdTestCase(); |
1908 | - |
1909 | - void removeTestCase(); |
1910 | - |
1911 | - void accountServiceTest(); |
1912 | - |
1913 | - void watchesTest(); |
1914 | - |
1915 | - void serviceDataTest(); |
1916 | - |
1917 | - void settingsTest(); |
1918 | - |
1919 | - void keySignVerifyTest(); |
1920 | - |
1921 | - void incrementalAccountIdsTest(); |
1922 | - |
1923 | - void selectGlobalAccountSettingsTest(); |
1924 | - |
1925 | - void credentialsIdTest(); |
1926 | - |
1927 | - void authDataTest(); |
1928 | - void globalAuthDataTest(); |
1929 | - |
1930 | - void listEnabledServices(); |
1931 | - |
1932 | - void listEnabledByServiceType(); |
1933 | - |
1934 | - void enabledEvent(); |
1935 | - |
1936 | - void serviceTypeTestCase(); |
1937 | - |
1938 | - void updateAccountTestCase(); |
1939 | - |
1940 | - void applicationTest(); |
1941 | - |
1942 | -private: |
1943 | - bool m_stored; |
1944 | - bool m_enabled; |
1945 | - AccountId m_created; |
1946 | - AccountId m_enabledEvent; |
1947 | - bool m_removed; |
1948 | - int m_rowsInserted; |
1949 | - int m_rowsRemoved; |
1950 | - int m_server_notify; |
1951 | - int m_port_notify; |
1952 | - int m_parameters_notify; |
1953 | - AccountId m_updateEvent; |
1954 | - bool m_accountServiceEnabledValue; |
1955 | - QStringList m_accountServiceChangedFields; |
1956 | -}; |
1957 | - |
1958 | -#endif |
1959 | |
1960 | === removed file 'tests/accountstest.pro' |
1961 | --- tests/accountstest.pro 2013-01-17 17:43:02 +0000 |
1962 | +++ tests/accountstest.pro 1970-01-01 00:00:00 +0000 |
1963 | @@ -1,56 +0,0 @@ |
1964 | -include( ../common-project-config.pri ) |
1965 | -include( ../common-vars.pri ) |
1966 | - |
1967 | -TARGET = accountstest |
1968 | -SOURCES += \ |
1969 | - accountstest.cpp |
1970 | -HEADERS += \ |
1971 | - accountstest.h |
1972 | -QT = \ |
1973 | - core \ |
1974 | - testlib \ |
1975 | - xml |
1976 | - |
1977 | -greaterThan(QT_MAJOR_VERSION, 4) { |
1978 | - LIBS += -laccounts-qt5 |
1979 | -} else { |
1980 | - LIBS += -laccounts-qt |
1981 | -} |
1982 | - |
1983 | -QMAKE_RPATHDIR = $${QMAKE_LIBDIR} |
1984 | - |
1985 | -#Check for the existence of aegis-crypto |
1986 | -system(pkg-config --exists aegis-crypto) :HAVE_AEGISCRYPTO=YES |
1987 | -contains(HAVE_AEGISCRYPTO, YES) { |
1988 | - message("aegis-crypto detected...") |
1989 | - DEFINES += HAVE_AEGISCRYPTO |
1990 | -} |
1991 | - |
1992 | -include( ../common-installs-config.pri ) |
1993 | - |
1994 | -DATA_PATH = $${INSTALL_PREFIX}/share/libaccounts-qt-tests/ |
1995 | - |
1996 | -DEFINES += \ |
1997 | - SERVICES_DIR=\\\"$$DATA_PATH\\\" \ |
1998 | - SERVICE_TYPES_DIR=\\\"$$DATA_PATH\\\" \ |
1999 | - PROVIDERS_DIR=\\\"$$DATA_PATH\\\" |
2000 | - |
2001 | -service.path = $$DATA_PATH |
2002 | -service.files += $${TOP_SRC_DIR}/tests/*.service |
2003 | -INSTALLS += service |
2004 | - |
2005 | -service-type.path = $$DATA_PATH |
2006 | -service-type.files += $${TOP_SRC_DIR}/tests/*.service-type |
2007 | -INSTALLS += service-type |
2008 | - |
2009 | -provider.path = $$DATA_PATH |
2010 | -provider.files += $${TOP_SRC_DIR}/tests/*.provider |
2011 | -INSTALLS += provider |
2012 | - |
2013 | -testsuite.files = $${TOP_SRC_DIR}/tests/tests.xml |
2014 | -testsuite.path = $$DATA_PATH |
2015 | -INSTALLS += testsuite |
2016 | - |
2017 | -QMAKE_EXTRA_TARGETS += check |
2018 | -check.depends = accountstest |
2019 | -check.commands = "TESTDIR=$${TOP_SRC_DIR}/tests $${TOP_SRC_DIR}/tests/accountstest.sh" |
2020 | |
2021 | === modified file 'tests/accountstest.sh' |
2022 | --- tests/accountstest.sh 2015-09-30 08:58:04 +0000 |
2023 | +++ tests/accountstest.sh 2015-11-06 13:54:21 +0000 |
2024 | @@ -1,12 +1,5 @@ |
2025 | #!/bin/sh |
2026 | |
2027 | -export AG_APPLICATIONS=$TESTDIR |
2028 | -export AG_SERVICES=$TESTDIR |
2029 | -export AG_SERVICE_TYPES=$TESTDIR |
2030 | -export AG_PROVIDERS=$TESTDIR |
2031 | -export ACCOUNTS=/tmp/ |
2032 | -export XDG_DATA_HOME=$TESTDIR |
2033 | - |
2034 | # If dbus-test-runner exists, use it to run the tests in a separate D-Bus |
2035 | # session |
2036 | if command -v dbus-test-runner > /dev/null ; then |
2037 | |
2038 | === modified file 'tests/tests.pro' |
2039 | --- tests/tests.pro 2012-03-08 14:05:28 +0000 |
2040 | +++ tests/tests.pro 2015-11-06 13:54:21 +0000 |
2041 | @@ -2,4 +2,4 @@ |
2042 | include( ../common-vars.pri ) |
2043 | |
2044 | TEMPLATE = subdirs |
2045 | -SUBDIRS = accountstest.pro |
2046 | +SUBDIRS = tst_libaccounts.pro |
2047 | |
2048 | === removed file 'tests/tests.xml' |
2049 | --- tests/tests.xml 2010-03-11 10:07:21 +0000 |
2050 | +++ tests/tests.xml 1970-01-01 00:00:00 +0000 |
2051 | @@ -1,75 +0,0 @@ |
2052 | -<testdefinition version="0.1"> |
2053 | - <suite name="libaccounts-qt-tests"> |
2054 | - <set description="libaccounts-qt-tests:accountstest" name="/usr/bin/accountstest"> |
2055 | - <case description="libaccounts-qt-tests:accountstest:managerTestCase" name="accountstest-managerTestCase" level="Feature" type="Functional"> |
2056 | - <step>/usr/bin/accountstest managerTestCase</step> |
2057 | - </case> |
2058 | - <case description="libaccounts-qt-tests:accountstest:createAccountTestCase" name="accountstest-createAccountTestCase" level="Feature" type="Functional"> |
2059 | - <step>/usr/bin/accountstest createAccountTestCase</step></case> |
2060 | - <case description="libaccounts-qt-tests:accountstest:accountTestCase" name="accountstest-accountTestCase" level="Feature" type="Functional"> |
2061 | - <step>/usr/bin/accountstest accountTestCase</step> |
2062 | - </case> |
2063 | - <case description="libaccounts-qt-tests:accountstest:accountListTestCase" name="accountstest-accountListTestCase" level="Feature" type="Functional"> |
2064 | - <step>/usr/bin/accountstest accountListTestCase</step> |
2065 | - </case> |
2066 | - <case description="libaccounts-qt-tests:accountstest:providerTestCase" name="accountstest-providerTestCase" level="Feature" type="Functional"> |
2067 | - <step>/usr/bin/accountstest providerTestCase</step> |
2068 | - </case> |
2069 | - <case description="libaccounts-qt-tests:accountstest:serviceTestCase" name="accountstest-serviceTestCase" level="Feature" type="Functional"> |
2070 | - <step>/usr/bin/accountstest serviceTestCase</step> |
2071 | - </case> |
2072 | - <case description="libaccounts-qt-tests:accountstest:serviceListTestCase" name="accountstest-serviceListTestCase" level="Feature" type="Functional"> |
2073 | - <step>/usr/bin/accountstest serviceListTestCase</step> |
2074 | - </case> |
2075 | - <case description="libaccounts-qt-tests:accountstest:serviceConstTestCase" name="accountstest-serviceConstTestCase" level="Feature" type="Functional"> |
2076 | - <step>/usr/bin/accountstest serviceConstTestCase</step> |
2077 | - </case> |
2078 | - <case description="libaccounts-qt-tests:accountstest:accountConstTestCase" name="accountstest-accountConstTestCase" level="Feature" type="Functional"> |
2079 | - <step>/usr/bin/accountstest accountConstTestCase</step> |
2080 | - </case> |
2081 | - <case description="libaccounts-qt-tests:accountstest:accountServiceTestCase" name="accountstest-accountServiceTestCase" level="Feature" type="Functional"> |
2082 | - <step>/usr/bin/accountstest accountServiceTestCase</step> |
2083 | - </case> |
2084 | - <case description="libaccounts-qt-tests:accountstest:accountEnabledTestCase" name="accountstest-accountEnabledTestCase" level="Feature" type="Functional"> |
2085 | - <step>/usr/bin/accountstest accountEnabledTestCase</step> |
2086 | - </case> |
2087 | - <case description="libaccounts-qt-tests:accountstest:accountDisplayNameTestCase" name="accountstest-accountDisplayNameTestCase" level="Feature" type="Functional"> |
2088 | - <step>/usr/bin/accountstest accountDisplayNameTestCase</step> |
2089 | - </case> |
2090 | - <case description="libaccounts-qt-tests:accountstest:accountValueTestCase" name="accountstest-accountValueTestCase" level="Feature" type="Functional"> |
2091 | - <step>/usr/bin/accountstest accountValueTestCase</step> |
2092 | - </case> |
2093 | - <case description="libaccounts-qt-tests:accountstest:accountSyncTestCase" name="accountstest-accountSyncTestCase" level="Feature" type="Functional"> |
2094 | - <step>/usr/bin/accountstest accountSyncTestCase</step> |
2095 | - </case> |
2096 | - <case description="libaccounts-qt-tests:accountstest:createdTestCase" name="accountstest-createdTestCase" level="Feature" type="Functional"> |
2097 | - <step>/usr/bin/accountstest createdTestCase</step> |
2098 | - </case> |
2099 | - <case description="libaccounts-qt-tests:accountstest:removeTestCase" name="accountstest-removeTestCase" level="Feature" type="Functional"> |
2100 | - <step>/usr/bin/accountstest removeTestCase</step> |
2101 | - </case> |
2102 | - <case description="libaccounts-qt-tests:accountstest:watchesTest" name="accountstest-watchesTest" level="Feature" type="Functional"> |
2103 | - <step>/usr/bin/accountstest watchesTest</step> |
2104 | - </case> |
2105 | - <case description="libaccounts-qt-tests:accountstest:serviceDataTest" name="accountstest-serviceDataTest" level="Feature" type="Functional"> |
2106 | - <step>/usr/bin/accountstest serviceDataTest</step> |
2107 | - </case> |
2108 | - <case description="libaccounts-qt-tests:accountstest:settingsTest" name="accountstest-settingsTest" level="Feature" type="Functional"> |
2109 | - <step>/usr/bin/accountstest settingsTest</step> |
2110 | - </case> |
2111 | - <case description="libaccounts-qt-tests:accountstest:incrementalAccountIdsTest" name="accountstest-incrementalAccountIdsTest" level="Feature" type="Functional"> |
2112 | - <step>/usr/bin/accountstest incrementalAccountIdsTest</step> |
2113 | - </case> |
2114 | - <case description="libaccounts-qt-tests:accountstest:selectGlobalAccountSettingsTest" name="accountstest-selectGlobalAccountSettingsTest" level="Feature" type="Functional"> |
2115 | - <step>/usr/bin/accountstest selectGlobalAccountSettingsTest</step> |
2116 | - </case> |
2117 | - <case description="libaccounts-qt-tests:accountstest:credentialsIdTest" name="accountstest-credentialsIdTest" level="Feature" type="Functional"> |
2118 | - <step>/usr/bin/accountstest credentialsIdTest</step> |
2119 | - </case> |
2120 | - <environments> |
2121 | - <scratchbox>true</scratchbox> |
2122 | - <hardware>true</hardware> |
2123 | - </environments> |
2124 | - </set> |
2125 | - </suite> |
2126 | -</testdefinition> |
2127 | |
2128 | === added file 'tests/tst_libaccounts.cpp' |
2129 | --- tests/tst_libaccounts.cpp 1970-01-01 00:00:00 +0000 |
2130 | +++ tests/tst_libaccounts.cpp 2015-11-06 13:54:21 +0000 |
2131 | @@ -0,0 +1,1446 @@ |
2132 | +/* vi: set et sw=4 ts=4 cino=t0,(0: */ |
2133 | +/* |
2134 | + * This file is part of libaccounts-qt |
2135 | + * |
2136 | + * Copyright (C) 2009-2011 Nokia Corporation. |
2137 | + * Copyright (C) 2015 Canonical Ltd. |
2138 | + * |
2139 | + * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> |
2140 | + * |
2141 | + * This library is free software; you can redistribute it and/or |
2142 | + * modify it under the terms of the GNU Lesser General Public License |
2143 | + * version 2.1 as published by the Free Software Foundation. |
2144 | + * |
2145 | + * This library is distributed in the hope that it will be useful, but |
2146 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
2147 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2148 | + * Lesser General Public License for more details. |
2149 | + * |
2150 | + * You should have received a copy of the GNU Lesser General Public |
2151 | + * License along with this library; if not, write to the Free Software |
2152 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
2153 | + * 02110-1301 USA |
2154 | + */ |
2155 | +#include <QtTest/QtTest> |
2156 | +#include <QSignalSpy> |
2157 | + |
2158 | +#include "Accounts/Account" |
2159 | +#include "Accounts/Application" |
2160 | +#include "Accounts/Manager" |
2161 | +#include "Accounts/AccountService" |
2162 | + |
2163 | +using namespace Accounts; |
2164 | + |
2165 | +#define PROVIDER QStringLiteral("dummyprovider") |
2166 | +#define SERVICE QStringLiteral("dummyservice") |
2167 | +#define MYSERVICE QStringLiteral("MyService") |
2168 | +#define OTHERSERVICE QStringLiteral("OtherService") |
2169 | +#define EMAIL_SERVICE_TYPE QStringLiteral("e-mail") |
2170 | + |
2171 | +Q_DECLARE_METATYPE(Accounts::AccountId) |
2172 | +Q_DECLARE_METATYPE(const char *) |
2173 | + |
2174 | +class AccountsTest: public QObject |
2175 | +{ |
2176 | + Q_OBJECT |
2177 | + |
2178 | +public: |
2179 | + AccountsTest() { |
2180 | + qRegisterMetaType<AccountId>("Accounts::AccountId"); |
2181 | + qRegisterMetaType<const char *>("const char *"); |
2182 | + } |
2183 | + |
2184 | +private Q_SLOTS: |
2185 | + void initTestCase(); |
2186 | + void cleanupTestCase(); |
2187 | + |
2188 | + void testManager(); |
2189 | + void testCreateAccount(); |
2190 | + void testAccount(); |
2191 | + void testObjectsLifetime(); |
2192 | + void testAccountList(); |
2193 | + |
2194 | + void testProvider(); |
2195 | + void testService(); |
2196 | + void testServiceList(); |
2197 | + void testServiceConst(); |
2198 | + void testAccountConst(); |
2199 | + |
2200 | + void testAccountProvider(); |
2201 | + void testAccountServices(); |
2202 | + void testAccountEnabled(); |
2203 | + void testAccountDisplayName(); |
2204 | + void testAccountValue(); |
2205 | + void testAccountSync(); |
2206 | + |
2207 | + void testCreated(); |
2208 | + void testRemove(); |
2209 | + |
2210 | + void testAccountService(); |
2211 | + |
2212 | + void testWatches(); |
2213 | + |
2214 | + void testServiceData(); |
2215 | + void testSettings(); |
2216 | + |
2217 | + void testKeySignVerify(); |
2218 | + |
2219 | + void testIncrementalAccountIds(); |
2220 | + |
2221 | + void testSelectGlobalAccountSettings(); |
2222 | + |
2223 | + void testCredentialsId(); |
2224 | + void testAuthData(); |
2225 | + void testGlobalAuthData(); |
2226 | + |
2227 | + void testListEnabledServices(); |
2228 | + void testListEnabledByServiceType(); |
2229 | + void testEnabledEvent(); |
2230 | + void testServiceType(); |
2231 | + void testUpdateAccount(); |
2232 | + void testApplication(); |
2233 | + |
2234 | +public Q_SLOTS: |
2235 | + void onAccountServiceChanged(); |
2236 | + |
2237 | +private: |
2238 | + QStringList m_accountServiceChangedFields; |
2239 | +}; |
2240 | + |
2241 | +void clearDb() |
2242 | +{ |
2243 | + QDir dbroot(QString(getenv("ACCOUNTS"))); |
2244 | + dbroot.remove(QString("accounts.db")); |
2245 | +} |
2246 | + |
2247 | +void AccountsTest::initTestCase() |
2248 | +{ |
2249 | + //init |
2250 | + setenv("ACCOUNTS", "/tmp/", false); |
2251 | + setenv("AG_APPLICATIONS", DATA_PATH, false); |
2252 | + setenv("AG_SERVICES", DATA_PATH, false); |
2253 | + setenv("AG_SERVICE_TYPES", DATA_PATH, false); |
2254 | + setenv("AG_PROVIDERS", DATA_PATH, false); |
2255 | + setenv("XDG_DATA_HOME", DATA_PATH, false); |
2256 | + //clear database |
2257 | + clearDb(); |
2258 | +} |
2259 | + |
2260 | +void AccountsTest::cleanupTestCase() |
2261 | +{ |
2262 | +} |
2263 | + |
2264 | +void AccountsTest::testManager() |
2265 | +{ |
2266 | + Manager *mgr = new Manager(); |
2267 | + QVERIFY(mgr != 0); |
2268 | + QCOMPARE(mgr->serviceType(), QString()); |
2269 | + |
2270 | + mgr->setAbortOnTimeout(true); |
2271 | + QCOMPARE(mgr->abortOnTimeout(), true); |
2272 | + |
2273 | + mgr->setTimeout(123); |
2274 | + QCOMPARE(mgr->timeout(), quint32(123)); |
2275 | + |
2276 | + QCOMPARE(mgr->options().testFlag(Manager::DisableNotifications), false); |
2277 | + |
2278 | + delete mgr; |
2279 | + |
2280 | + mgr = new Manager(Manager::DisableNotifications); |
2281 | + QCOMPARE(mgr->options().testFlag(Manager::DisableNotifications), true); |
2282 | + delete mgr; |
2283 | +} |
2284 | + |
2285 | +void AccountsTest::testCreateAccount() |
2286 | +{ |
2287 | + clearDb(); |
2288 | + |
2289 | + Manager *mgr = new Manager(); |
2290 | + QVERIFY(mgr != 0); |
2291 | + |
2292 | + Account *account = mgr->createAccount(NULL); |
2293 | + QVERIFY(account != 0); |
2294 | + QVERIFY(account->manager() == mgr); |
2295 | + delete account; |
2296 | + |
2297 | + account = mgr->createAccount(PROVIDER); |
2298 | + QVERIFY(account != 0); |
2299 | + delete account; |
2300 | + |
2301 | + delete mgr; |
2302 | +} |
2303 | + |
2304 | +void AccountsTest::testAccount() |
2305 | +{ |
2306 | + clearDb(); |
2307 | + |
2308 | + Manager *mgr = new Manager(); |
2309 | + QVERIFY(mgr != 0); |
2310 | + |
2311 | + //this should not exist |
2312 | + Account *account2 = mgr->account(1); |
2313 | + QVERIFY(!account2); |
2314 | + Error error = mgr->lastError(); |
2315 | + QCOMPARE(error.type(), Error::AccountNotFound); |
2316 | + |
2317 | + // make sure there is account |
2318 | + Account *account = mgr->createAccount(NULL); |
2319 | + account->sync(); |
2320 | + |
2321 | + //now we get account |
2322 | + account2 = mgr->account(1); |
2323 | + QVERIFY(account2 != 0); |
2324 | + |
2325 | + delete account2; |
2326 | + delete account; |
2327 | + delete mgr; |
2328 | +} |
2329 | + |
2330 | +void AccountsTest::testObjectsLifetime() |
2331 | +{ |
2332 | + clearDb(); |
2333 | + |
2334 | + Manager *manager = new Manager(); |
2335 | + |
2336 | + // this should not exist |
2337 | + Account *account = Account::fromId(manager, 1); |
2338 | + QVERIFY(account == 0); |
2339 | + Error error = manager->lastError(); |
2340 | + QCOMPARE(error.type(), Error::AccountNotFound); |
2341 | + |
2342 | + // create an account |
2343 | + account = new Account(manager, PROVIDER); |
2344 | + account->setDisplayName("hi!"); |
2345 | + account->syncAndBlock(); |
2346 | + AccountId accountId = account->id(); |
2347 | + delete account; |
2348 | + |
2349 | + // Now load it, in two different ways |
2350 | + QPointer<Account> sharedAccount = manager->account(accountId); |
2351 | + QVERIFY(sharedAccount != 0); |
2352 | + QCOMPARE(sharedAccount->displayName(), QString("hi!")); |
2353 | + |
2354 | + QPointer<Account> ownedAccount = Account::fromId(manager, accountId); |
2355 | + QVERIFY(ownedAccount != 0); |
2356 | + QCOMPARE(ownedAccount->displayName(), QString("hi!")); |
2357 | + |
2358 | + /* Load it once more from the shared interface, and see that we get the |
2359 | + * same object */ |
2360 | + QCOMPARE(manager->account(accountId), sharedAccount.data()); |
2361 | + |
2362 | + /* Delete the manager; the owned account should survive, the shared |
2363 | + * shouldn't */ |
2364 | + delete manager; |
2365 | + QVERIFY(sharedAccount == 0); |
2366 | + QVERIFY(ownedAccount != 0); |
2367 | + QVERIFY(ownedAccount->manager() == 0); |
2368 | + |
2369 | + delete ownedAccount; |
2370 | +} |
2371 | + |
2372 | +void AccountsTest::testAccountList() |
2373 | +{ |
2374 | + clearDb(); |
2375 | + |
2376 | + Manager *mgr = new Manager(); |
2377 | + QVERIFY(mgr != 0); |
2378 | + |
2379 | + // make sure there is account |
2380 | + Account *account = mgr->createAccount(NULL); |
2381 | + account->sync(); |
2382 | + |
2383 | + AccountIdList list = mgr->accountList(NULL); |
2384 | + QVERIFY(!list.isEmpty()); |
2385 | + QCOMPARE(list.size(), 1); |
2386 | + |
2387 | + list = mgr->accountList("e-mail"); |
2388 | + QVERIFY(list.isEmpty()); |
2389 | + |
2390 | + delete account; |
2391 | + delete mgr; |
2392 | +} |
2393 | + |
2394 | +void AccountsTest::testProvider() |
2395 | +{ |
2396 | + Manager *mgr = new Manager(); |
2397 | + QVERIFY(mgr != 0); |
2398 | + |
2399 | + Account *account = mgr->createAccount(PROVIDER); |
2400 | + QVERIFY(account != 0); |
2401 | + |
2402 | + QString provider_name = account->providerName(); |
2403 | + QCOMPARE(provider_name, PROVIDER); |
2404 | + |
2405 | + delete account; |
2406 | + |
2407 | + /* Test invalid provider */ |
2408 | + Provider invalid; |
2409 | + QVERIFY(!invalid.isValid()); |
2410 | + |
2411 | + /* Check listing and loading of XML files */ |
2412 | + Provider provider = mgr->provider("MyProvider"); |
2413 | + QVERIFY(provider.isValid()); |
2414 | + |
2415 | + QCOMPARE(provider.displayName(), QString("My Provider")); |
2416 | + QCOMPARE(provider.iconName(), QString("general_myprovider")); |
2417 | + QCOMPARE(provider.description(), QString("fast & furious")); |
2418 | + QCOMPARE(provider.trCatalog(), QString("accounts")); |
2419 | + QCOMPARE(provider.pluginName(), QString("generic-oauth")); |
2420 | + QCOMPARE(provider.domainsRegExp(), QString(".*example.net")); |
2421 | + QCOMPARE(provider.isSingleAccount(), true); |
2422 | + |
2423 | + QDomDocument dom = provider.domDocument(); |
2424 | + QDomElement root = dom.documentElement(); |
2425 | + QCOMPARE(root.tagName(), QString("provider")); |
2426 | + |
2427 | + /* Test copy constructor */ |
2428 | + Provider copy(provider); |
2429 | + QCOMPARE(copy.displayName(), QString("My Provider")); |
2430 | + |
2431 | + /* Test assignment */ |
2432 | + copy = provider; |
2433 | + QCOMPARE(copy.displayName(), QString("My Provider")); |
2434 | + copy = invalid; |
2435 | + QVERIFY(!copy.isValid()); |
2436 | + copy = provider; |
2437 | + QCOMPARE(copy.displayName(), QString("My Provider")); |
2438 | + |
2439 | + ProviderList providers = mgr->providerList(); |
2440 | + QVERIFY(!providers.isEmpty()); |
2441 | + QVERIFY(providers.size() == 1); |
2442 | + QCOMPARE(providers[0].displayName(), QString("My Provider")); |
2443 | + |
2444 | + delete mgr; |
2445 | +} |
2446 | + |
2447 | +void AccountsTest::testService() |
2448 | +{ |
2449 | + Manager *mgr = new Manager(); |
2450 | + QVERIFY(mgr != 0); |
2451 | + |
2452 | + Service service = mgr->service(MYSERVICE); |
2453 | + QVERIFY(service.isValid()); |
2454 | + QCOMPARE(service.name(), MYSERVICE); |
2455 | + QCOMPARE(service.iconName(), QString("general_myservice")); |
2456 | + QCOMPARE(service.trCatalog(), QString("accounts")); |
2457 | + QStringList tags; |
2458 | + tags << "email" << "e-mail"; |
2459 | + QCOMPARE(service.tags(), tags.toSet()); |
2460 | + // Called twice, because the second time it returns a cached result |
2461 | + QCOMPARE(service.tags(), tags.toSet()); |
2462 | + QVERIFY(service.hasTag("email")); |
2463 | + QVERIFY(!service.hasTag("chat")); |
2464 | + |
2465 | + service = mgr->service(SERVICE); |
2466 | + QVERIFY(!service.isValid()); |
2467 | + |
2468 | + delete mgr; |
2469 | +} |
2470 | + |
2471 | +void AccountsTest::testServiceList() |
2472 | +{ |
2473 | + Manager *mgr = new Manager(); |
2474 | + QVERIFY(mgr != 0); |
2475 | + |
2476 | + ServiceList list = mgr->serviceList(); |
2477 | + QVERIFY(!list.isEmpty()); |
2478 | + QCOMPARE(list.count(), 2); |
2479 | + |
2480 | + list = mgr->serviceList("e-mail"); |
2481 | + QCOMPARE(list.count(), 1); |
2482 | + |
2483 | + list = mgr->serviceList("sharing"); |
2484 | + QCOMPARE(list.count(), 1); |
2485 | + |
2486 | + delete mgr; |
2487 | +} |
2488 | + |
2489 | +void AccountsTest::testServiceConst() |
2490 | +{ |
2491 | + Manager *mgr = new Manager(); |
2492 | + QVERIFY(mgr != 0); |
2493 | + |
2494 | + Service service = mgr->service(MYSERVICE); |
2495 | + QVERIFY(service.isValid()); |
2496 | + QCOMPARE(service.name(), MYSERVICE); |
2497 | + QCOMPARE(service.displayName(), QString("My Service")); |
2498 | + QCOMPARE(service.serviceType(), QString("e-mail")); |
2499 | + QCOMPARE(service.provider(), QString("MyProvider")); |
2500 | + QVERIFY(service.hasTag(QString("email"))); |
2501 | + |
2502 | + delete mgr; |
2503 | +} |
2504 | + |
2505 | + |
2506 | +/* account */ |
2507 | + |
2508 | + |
2509 | +void AccountsTest::testAccountConst() |
2510 | +{ |
2511 | + Manager *mgr = new Manager(); |
2512 | + QVERIFY(mgr != 0); |
2513 | + |
2514 | + Account *account = mgr->createAccount(PROVIDER); |
2515 | + QVERIFY(account != 0); |
2516 | + QVERIFY(account->isWritable()); |
2517 | + |
2518 | + delete account; |
2519 | + delete mgr; |
2520 | +} |
2521 | + |
2522 | +void AccountsTest::testAccountProvider() |
2523 | +{ |
2524 | + Manager *manager = new Manager(); |
2525 | + QVERIFY(manager != 0); |
2526 | + |
2527 | + Account *account = manager->createAccount("MyProvider"); |
2528 | + QVERIFY(account != 0); |
2529 | + |
2530 | + QCOMPARE(account->providerName(), QString("MyProvider")); |
2531 | + |
2532 | + Provider provider = account->provider(); |
2533 | + QCOMPARE(provider.name(), QString("MyProvider")); |
2534 | + |
2535 | + delete account; |
2536 | + delete manager; |
2537 | +} |
2538 | + |
2539 | +void AccountsTest::testAccountServices() |
2540 | +{ |
2541 | + Manager *mgr = new Manager(); |
2542 | + QVERIFY(mgr != 0); |
2543 | + |
2544 | + Account *account = mgr->createAccount("MyProvider"); |
2545 | + QVERIFY(account != 0); |
2546 | + |
2547 | + QVERIFY(!account->supportsService(QString("unsupported"))); |
2548 | + QVERIFY(account->supportsService(QString("e-mail"))); |
2549 | + |
2550 | + ServiceList list = account->services(); |
2551 | + QVERIFY(!list.isEmpty()); |
2552 | + QCOMPARE(list.count(), 1); |
2553 | + |
2554 | + list = account->services("e-mail"); |
2555 | + QCOMPARE(list.count(), 1); |
2556 | + |
2557 | + list = account->services("unsupported"); |
2558 | + QVERIFY(list.isEmpty()); |
2559 | + |
2560 | + Service service = mgr->service(MYSERVICE); |
2561 | + QVERIFY(service.isValid()); |
2562 | + |
2563 | + /* Test default settings */ |
2564 | + account->selectService(service); |
2565 | + QCOMPARE(account->value("parameters/server").toString(), |
2566 | + QString("talk.google.com")); |
2567 | + QCOMPARE(account->valueAsInt("parameters/port"), 5223); |
2568 | + SettingSource source; |
2569 | + QCOMPARE(account->valueAsInt("parameters/port", 0, &source), 5223); |
2570 | + QCOMPARE(source, TEMPLATE); |
2571 | + |
2572 | + delete account; |
2573 | + delete mgr; |
2574 | +} |
2575 | + |
2576 | + |
2577 | +void AccountsTest::testAccountEnabled() |
2578 | +{ |
2579 | + Manager *mgr = new Manager(); |
2580 | + QVERIFY(mgr != 0); |
2581 | + |
2582 | + Account *account = mgr->createAccount(PROVIDER); |
2583 | + QVERIFY(account != 0); |
2584 | + QSignalSpy enabled(account, SIGNAL(enabledChanged(const QString&,bool))); |
2585 | + |
2586 | + account->setEnabled(true); |
2587 | + account->sync(); |
2588 | + QVERIFY(account->enabled()); |
2589 | + QTRY_COMPARE(enabled.count(), 1); |
2590 | + QCOMPARE(enabled.at(0).at(1).toBool(), true); |
2591 | + enabled.clear(); |
2592 | + account->setEnabled(false); |
2593 | + account->sync(); |
2594 | + QVERIFY(!account->enabled()); |
2595 | + QTRY_COMPARE(enabled.count(), 1); |
2596 | + QCOMPARE(enabled.at(0).at(1).toBool(), false); |
2597 | + |
2598 | + delete account; |
2599 | + delete mgr; |
2600 | +} |
2601 | + |
2602 | +void AccountsTest::testAccountDisplayName() |
2603 | +{ |
2604 | + Manager *mgr = new Manager(); |
2605 | + QVERIFY(mgr != 0); |
2606 | + |
2607 | + Account *account = mgr->createAccount(PROVIDER); |
2608 | + QVERIFY(account != 0); |
2609 | + QSignalSpy displayNameChanged(account, |
2610 | + SIGNAL(displayNameChanged(const QString&))); |
2611 | + |
2612 | + account->setDisplayName(PROVIDER); |
2613 | + account->sync(); |
2614 | + QCOMPARE(account->displayName(),PROVIDER); |
2615 | + QTRY_COMPARE(displayNameChanged.count(), 1); |
2616 | + QCOMPARE(displayNameChanged.at(0).at(0).toString(), PROVIDER); |
2617 | + |
2618 | + delete account; |
2619 | + delete mgr; |
2620 | +} |
2621 | + |
2622 | + |
2623 | + |
2624 | +void AccountsTest::testAccountValue() |
2625 | +{ |
2626 | + Manager *mgr = new Manager(); |
2627 | + QVERIFY(mgr != 0); |
2628 | + |
2629 | + Account *account = mgr->createAccount(PROVIDER); |
2630 | + QVERIFY(account != 0); |
2631 | + |
2632 | + QSignalSpy synced(account, SIGNAL(synced())); |
2633 | + account->setValue(QString("test"),QString("value")); |
2634 | + int int_value = 666; |
2635 | + account->setValue("testint", int_value); |
2636 | + QStringList names; |
2637 | + names << "Tom" << "Dick" << "Harry"; |
2638 | + account->setValue("names", names); |
2639 | + account->setValue("big distance", quint64(3)); |
2640 | + account->setValue("big difference", qint64(-300)); |
2641 | + account->setValue("boolean", false); |
2642 | + account->sync(); |
2643 | + |
2644 | + QTRY_COMPARE(synced.count(), 1); |
2645 | + |
2646 | + /* check that the values we wrote are retrieved successfully */ |
2647 | + QVariant val = QVariant::String; |
2648 | + account->value(QString("test"), val); |
2649 | + QCOMPARE(val.toString(), QString("value")); |
2650 | + |
2651 | + SettingSource source; |
2652 | + source = account->value(QString("test"), val); |
2653 | + QCOMPARE(val.toString(), QString("value")); |
2654 | + |
2655 | + QVariant intval = QVariant::Int; |
2656 | + account->value("testint", intval); |
2657 | + qDebug("Val: %d", intval.toInt()); |
2658 | + QVERIFY(intval.toInt() == int_value); |
2659 | + |
2660 | + QVERIFY(source == ACCOUNT); |
2661 | + |
2662 | + QCOMPARE(account->value("names").toStringList(), names); |
2663 | + QCOMPARE(account->value("big distance").toULongLong(), quint64(3)); |
2664 | + QCOMPARE(account->value("big difference").toLongLong(), qint64(-300)); |
2665 | + |
2666 | + /* test the convenience methods */ |
2667 | + QString strval = account->valueAsString("test"); |
2668 | + QCOMPARE (strval, QString("value")); |
2669 | + QCOMPARE(account->valueAsString("test", "Hi", &source), QString("value")); |
2670 | + QCOMPARE(source, ACCOUNT); |
2671 | + |
2672 | + QCOMPARE(account->valueAsBool("boolean"), false); |
2673 | + QCOMPARE(account->valueAsBool("boolean", true, &source), false); |
2674 | + QCOMPARE(source, ACCOUNT); |
2675 | + |
2676 | + QCOMPARE(account->valueAsUInt64("big distance"), quint64(3)); |
2677 | + QCOMPARE(account->valueAsUInt64("big distance", 10, &source), quint64(3)); |
2678 | + QCOMPARE(source, ACCOUNT); |
2679 | + |
2680 | + strval = account->valueAsString("test_unexisting", "hello"); |
2681 | + QCOMPARE (strval, QString("hello")); |
2682 | + |
2683 | + delete account; |
2684 | + delete mgr; |
2685 | +} |
2686 | + |
2687 | +void AccountsTest::testAccountSync() |
2688 | +{ |
2689 | + Manager *mgr = new Manager(); |
2690 | + QVERIFY(mgr != 0); |
2691 | + |
2692 | + Account *account = mgr->createAccount(PROVIDER); |
2693 | + QVERIFY(account != 0); |
2694 | + |
2695 | + QString provider = account->providerName(); |
2696 | + QCOMPARE(provider, PROVIDER); |
2697 | + |
2698 | + QSignalSpy synced(account, SIGNAL(synced())); |
2699 | + |
2700 | + account->sync(); |
2701 | + QTRY_COMPARE(synced.count(), 1); |
2702 | + |
2703 | + delete account; |
2704 | + delete mgr; |
2705 | +} |
2706 | + |
2707 | +void AccountsTest::testCreated() |
2708 | +{ |
2709 | + Manager *mgr = new Manager(); |
2710 | + QVERIFY(mgr != 0); |
2711 | + |
2712 | + QSignalSpy created(mgr, SIGNAL(accountCreated(Accounts::AccountId))); |
2713 | + |
2714 | + Account *account = mgr->createAccount(NULL); |
2715 | + QVERIFY(account != 0); |
2716 | + |
2717 | + /* store the account: this will emit accountCreated */ |
2718 | + account->sync(); |
2719 | + QTRY_COMPARE(created.count(), 1); |
2720 | + uint accountId = created.at(0).at(0).toUInt(); |
2721 | + QVERIFY(accountId != 0); |
2722 | + QCOMPARE(accountId, account->id()); |
2723 | + |
2724 | + delete account; |
2725 | + delete mgr; |
2726 | +} |
2727 | + |
2728 | +void AccountsTest::testRemove() |
2729 | +{ |
2730 | + Manager *mgr = new Manager(); |
2731 | + QVERIFY(mgr != 0); |
2732 | + |
2733 | + Account *account = mgr->createAccount(NULL); |
2734 | + QVERIFY(account != 0); |
2735 | + |
2736 | + /* store the account */ |
2737 | + account->sync(); |
2738 | + QVERIFY(account->id() != 0); |
2739 | + |
2740 | + QSignalSpy removed(account, SIGNAL(removed())); |
2741 | + |
2742 | + /* mark the account for deletion -- and make sure it's not deleted |
2743 | + * immediately */ |
2744 | + account->remove (); |
2745 | + QCOMPARE(removed.count(), 0); |
2746 | + |
2747 | + /* store the changes */ |
2748 | + account->sync(); |
2749 | + QCOMPARE(removed.count(), 1); |
2750 | + |
2751 | + delete account; |
2752 | + delete mgr; |
2753 | +} |
2754 | + |
2755 | +void AccountsTest::onAccountServiceChanged() |
2756 | +{ |
2757 | + AccountService *accountService = qobject_cast<AccountService*>(sender()); |
2758 | + m_accountServiceChangedFields = accountService->changedFields(); |
2759 | +} |
2760 | + |
2761 | +void AccountsTest::testAccountService() |
2762 | +{ |
2763 | + Manager *mgr = new Manager(); |
2764 | + QVERIFY(mgr != 0); |
2765 | + |
2766 | + Service service = mgr->service(MYSERVICE); |
2767 | + QVERIFY(service.isValid()); |
2768 | + |
2769 | + Account *account = mgr->createAccount(NULL); |
2770 | + QVERIFY(account != 0); |
2771 | + |
2772 | + QObject *parent = new QObject(); |
2773 | + QPointer<AccountService> shortLivedAccountService = |
2774 | + new AccountService(account, service, parent); |
2775 | + QVERIFY(shortLivedAccountService != 0); |
2776 | + delete parent; |
2777 | + QVERIFY(shortLivedAccountService == 0); |
2778 | + |
2779 | + AccountService *accountService = new AccountService(account, service); |
2780 | + QVERIFY(accountService != 0); |
2781 | + |
2782 | + QCOMPARE(accountService->account(), account); |
2783 | + QCOMPARE(accountService->account()->providerName(), |
2784 | + account->providerName()); |
2785 | + Service copy = accountService->service(); |
2786 | + QVERIFY(copy.isValid()); |
2787 | + QCOMPARE(copy.name(), service.name()); |
2788 | + |
2789 | + QObject::connect(accountService, SIGNAL(changed()), |
2790 | + this, SLOT(onAccountServiceChanged())); |
2791 | + QSignalSpy spyChanged(accountService, SIGNAL(changed())); |
2792 | + QSignalSpy spyEnabled(accountService, SIGNAL(enabled(bool))); |
2793 | + |
2794 | + accountService->beginGroup("parameters"); |
2795 | + QVERIFY(accountService->group() == "parameters"); |
2796 | + |
2797 | + /* test values from the template */ |
2798 | + QCOMPARE(accountService->value("server").toString(), |
2799 | + UTF8("talk.google.com")); |
2800 | + QCOMPARE(accountService->value("port").toInt(), 5223); |
2801 | + QCOMPARE(accountService->value("old-ssl").toBool(), true); |
2802 | + |
2803 | + /* now, change some values */ |
2804 | + accountService->setValue("server", QString("www.example.com")); |
2805 | + account->selectService(); |
2806 | + account->setEnabled(true); |
2807 | + account->selectService(service); |
2808 | + account->setEnabled(true); |
2809 | + |
2810 | + /* write the data */ |
2811 | + account->sync(); |
2812 | + |
2813 | + /* ensure that the callbacks have been called the correct number of times */ |
2814 | + QCOMPARE(spyChanged.count(), 1); |
2815 | + spyChanged.clear(); |
2816 | + spyEnabled.clear(); |
2817 | + |
2818 | + QStringList expectedChanges; |
2819 | + expectedChanges << "parameters/server"; |
2820 | + expectedChanges << "enabled"; |
2821 | + QCOMPARE(m_accountServiceChangedFields.toSet(), expectedChanges.toSet()); |
2822 | + |
2823 | + QCOMPARE(accountService->value("server").toString(), |
2824 | + UTF8("www.example.com")); |
2825 | + QCOMPARE(accountService->enabled(), true); |
2826 | + |
2827 | + /* check the enabled status */ |
2828 | + account->selectService(); |
2829 | + account->setEnabled(false); |
2830 | + account->sync(); |
2831 | + QCOMPARE(spyChanged.count(), 0); |
2832 | + QCOMPARE(spyEnabled.count(), 1); |
2833 | + QCOMPARE(accountService->enabled(), false); |
2834 | + QCOMPARE(spyEnabled.at(0).at(0).toBool(), accountService->enabled()); |
2835 | + spyEnabled.clear(); |
2836 | + |
2837 | + /* enable the account, but disable the service */ |
2838 | + account->selectService(); |
2839 | + account->setEnabled(true); |
2840 | + account->selectService(service); |
2841 | + account->setEnabled(false); |
2842 | + account->sync(); |
2843 | + QCOMPARE(spyEnabled.count(), 0); |
2844 | + QCOMPARE(accountService->enabled(), false); |
2845 | + |
2846 | + /* re-enable the service */ |
2847 | + account->selectService(service); |
2848 | + account->setEnabled(true); |
2849 | + account->sync(); |
2850 | + QCOMPARE(spyEnabled.count(), 1); |
2851 | + QCOMPARE(accountService->enabled(), true); |
2852 | + QCOMPARE(spyEnabled.at(0).at(0).toBool(), accountService->enabled()); |
2853 | + spyEnabled.clear(); |
2854 | + spyChanged.clear(); |
2855 | + |
2856 | + |
2857 | + /* test some more APIs */ |
2858 | + QStringList expectedList; |
2859 | + expectedList << "server" << "fallback-conference-server" << |
2860 | + "port" << "old-ssl"; |
2861 | + QCOMPARE(accountService->childKeys().toSet(), expectedList.toSet()); |
2862 | + QCOMPARE(accountService->childGroups().toSet(), QSet<QString>()); |
2863 | + QCOMPARE(accountService->contains("port"), true); |
2864 | + accountService->endGroup(); |
2865 | + |
2866 | + expectedList.clear(); |
2867 | + expectedList << "parameters"; |
2868 | + QCOMPARE(accountService->childGroups().toSet(), expectedList.toSet()); |
2869 | + |
2870 | + /* Remove one key */ |
2871 | + accountService->remove("parameters/port"); |
2872 | + account->sync(); |
2873 | + QCOMPARE(spyChanged.count(), 1); |
2874 | + QCOMPARE(m_accountServiceChangedFields, QStringList("parameters/port")); |
2875 | + spyChanged.clear(); |
2876 | + |
2877 | + /* remove all keys */ |
2878 | + accountService->clear(); |
2879 | + account->sync(); |
2880 | + QCOMPARE(spyChanged.count(), 1); |
2881 | + QVERIFY(m_accountServiceChangedFields.contains("parameters/server")); |
2882 | + QVERIFY(m_accountServiceChangedFields.contains("parameters/old-ssl")); |
2883 | + spyChanged.clear(); |
2884 | + |
2885 | + delete accountService; |
2886 | + delete account; |
2887 | + delete mgr; |
2888 | +} |
2889 | + |
2890 | +void AccountsTest::testWatches() |
2891 | +{ |
2892 | + Manager *mgr = new Manager(); |
2893 | + QVERIFY(mgr != 0); |
2894 | + |
2895 | + Service service = mgr->service(MYSERVICE); |
2896 | + QVERIFY(service.isValid()); |
2897 | + |
2898 | + /* create an account and some watches */ |
2899 | + Account *account = mgr->createAccount(NULL); |
2900 | + QVERIFY(account != 0); |
2901 | + |
2902 | + account->selectService(service); |
2903 | + |
2904 | + Watch *w_server = account->watchKey("parameters/server"); |
2905 | + QSignalSpy serverNotify(w_server, SIGNAL(notify(const char *))); |
2906 | + |
2907 | + /* test also beginGroup() */ |
2908 | + account->beginGroup("parameters"); |
2909 | + QVERIFY(account->group() == "parameters"); |
2910 | + |
2911 | + Watch *w_parameters = account->watchKey(); /* watch the whole group */ |
2912 | + QSignalSpy parametersNotify(w_parameters, SIGNAL(notify(const char *))); |
2913 | + |
2914 | + Watch *w_port = account->watchKey("port"); |
2915 | + QSignalSpy portNotify(w_port, SIGNAL(notify(const char *))); |
2916 | + |
2917 | + /* now, change some values */ |
2918 | + account->setValue("server", QString("xxx.nokia.com")); |
2919 | + |
2920 | + /* write the data */ |
2921 | + account->sync(); |
2922 | + |
2923 | + /* ensure that the callbacks have been called the correct number of times */ |
2924 | + QCOMPARE(serverNotify.count(), 1); |
2925 | + QCOMPARE(parametersNotify.count(), 1); |
2926 | + QCOMPARE(portNotify.count(), 0); |
2927 | + |
2928 | + /* now change the port and another parameter not being watched */ |
2929 | + account->setValue("port", 45); |
2930 | + account->endGroup(); /* exit from the "parameters/" prefix */ |
2931 | + account->setValue("username", QString("h4ck3r@nokia.com")); |
2932 | + |
2933 | + /* reset the counters */ |
2934 | + serverNotify.clear(); |
2935 | + parametersNotify.clear(); |
2936 | + portNotify.clear(); |
2937 | + |
2938 | + /* write the data */ |
2939 | + account->sync(); |
2940 | + |
2941 | + /* ensure that the callbacks have been called the correct number of times */ |
2942 | + QCOMPARE(serverNotify.count(), 0); |
2943 | + QCOMPARE(parametersNotify.count(), 1); |
2944 | + QCOMPARE(portNotify.count(), 1); |
2945 | + |
2946 | + /* change port and server, but delete the w_port watch */ |
2947 | + delete w_port; |
2948 | + |
2949 | + account->beginGroup("parameters"); |
2950 | + account->setValue("port", 56); |
2951 | + account->setValue("server", QString("warez.nokia.com")); |
2952 | + |
2953 | + /* reset the counters */ |
2954 | + serverNotify.clear(); |
2955 | + parametersNotify.clear(); |
2956 | + portNotify.clear(); |
2957 | + |
2958 | + /* write the data */ |
2959 | + account->sync(); |
2960 | + |
2961 | + /* ensure that the callbacks have been called the correct number of times */ |
2962 | + QCOMPARE(serverNotify.count(), 1); |
2963 | + QCOMPARE(parametersNotify.count(), 1); |
2964 | + QCOMPARE(portNotify.count(), 0); |
2965 | + |
2966 | + delete account; |
2967 | + delete mgr; |
2968 | +} |
2969 | + |
2970 | +void AccountsTest::testServiceData() |
2971 | +{ |
2972 | + Manager *mgr = new Manager(); |
2973 | + QVERIFY(mgr != 0); |
2974 | + |
2975 | + Service service = mgr->service(MYSERVICE); |
2976 | + QVERIFY(service.isValid()); |
2977 | + |
2978 | + QDomDocument doc = service.domDocument(); |
2979 | + QVERIFY(!doc.isNull()); |
2980 | + |
2981 | + delete mgr; |
2982 | +} |
2983 | + |
2984 | +void AccountsTest::testSettings() |
2985 | +{ |
2986 | + Manager *mgr = new Manager(); |
2987 | + QVERIFY(mgr != 0); |
2988 | + |
2989 | + /* create an account and some watches */ |
2990 | + Account *account = mgr->createAccount(NULL); |
2991 | + QVERIFY(account != 0); |
2992 | + |
2993 | + /* create a few keys/groups */ |
2994 | + account->setValue("username", QString("fool")); |
2995 | + account->setValue("email", QString("fool@domain.com")); |
2996 | + |
2997 | + account->beginGroup("parameters"); |
2998 | + account->setValue("server", QString("xxx.nokia.com")); |
2999 | + account->setValue("port", 80); |
3000 | + |
3001 | + account->beginGroup("proxy"); /* this is a subgroup of "parameters" */ |
3002 | + account->setValue("use", true); |
3003 | + account->setValue("address", QString("proxy.nokia.com")); |
3004 | + QCOMPARE(account->group(), QString("parameters/proxy")); |
3005 | + account->endGroup(); |
3006 | + |
3007 | + QCOMPARE(account->group(), QString("parameters")); |
3008 | + account->endGroup(); |
3009 | + |
3010 | + /* write another top-level key */ |
3011 | + account->setValue("verified", false); |
3012 | + |
3013 | + /* re-enter a group */ |
3014 | + account->beginGroup("preferences"); |
3015 | + account->setValue("maximized", true); |
3016 | + account->setValue("initial_directory", QString("xxx")); |
3017 | + QCOMPARE(account->group(), QString("preferences")); |
3018 | + account->endGroup(); |
3019 | + |
3020 | + /* write the data */ |
3021 | + account->sync(); |
3022 | + |
3023 | + /* now check if the groups and keys are layed out as expected */ |
3024 | + QStringList expected; |
3025 | + QStringList result; |
3026 | + |
3027 | + /* check allKeys() */ |
3028 | + expected << "username" << "email" << "verified" << |
3029 | + "parameters/server" << "parameters/port" << |
3030 | + "parameters/proxy/use" << "parameters/proxy/address" << |
3031 | + "preferences/maximized" << "preferences/initial_directory"; |
3032 | + result = account->allKeys(); |
3033 | + |
3034 | + expected.sort(); |
3035 | + result.sort(); |
3036 | + QCOMPARE(result, expected); |
3037 | + |
3038 | + /* check childGroups() */ |
3039 | + expected.clear(); |
3040 | + expected << "parameters" << "preferences"; |
3041 | + result = account->childGroups(); |
3042 | + |
3043 | + expected.sort(); |
3044 | + result.sort(); |
3045 | + QCOMPARE(result, expected); |
3046 | + |
3047 | + /* check childKeys() */ |
3048 | + expected.clear(); |
3049 | + expected << "username" << "email" << "verified"; |
3050 | + result = account->childKeys(); |
3051 | + |
3052 | + expected.sort(); |
3053 | + result.sort(); |
3054 | + QCOMPARE(result, expected); |
3055 | + |
3056 | + /* now enter a group and test the same methods as above */ |
3057 | + account->beginGroup("parameters"); |
3058 | + |
3059 | + /* allKeys */ |
3060 | + expected.clear(); |
3061 | + expected << "server" << "port" << "proxy/use" << "proxy/address"; |
3062 | + result = account->allKeys(); |
3063 | + |
3064 | + expected.sort(); |
3065 | + result.sort(); |
3066 | + QCOMPARE(result, expected); |
3067 | + |
3068 | + /* childGroups */ |
3069 | + expected.clear(); |
3070 | + expected << "proxy"; |
3071 | + result = account->childGroups(); |
3072 | + |
3073 | + expected.sort(); |
3074 | + result.sort(); |
3075 | + QCOMPARE(result, expected); |
3076 | + |
3077 | + /* childKeys() */ |
3078 | + expected.clear(); |
3079 | + expected << "server" << "port"; |
3080 | + result = account->childKeys(); |
3081 | + |
3082 | + expected.sort(); |
3083 | + result.sort(); |
3084 | + QCOMPARE(result, expected); |
3085 | + |
3086 | + /* contains() */ |
3087 | + QVERIFY(account->contains("server") == true); |
3088 | + QVERIFY(account->contains("unexisting") == false); |
3089 | + |
3090 | + /* test remove() */ |
3091 | + account->remove(""); /* remove all the parameters/ group */ |
3092 | + account->endGroup(); |
3093 | + account->remove("verified"); |
3094 | + |
3095 | + /* we need to sync, for the changes to take effect */ |
3096 | + account->sync(); |
3097 | + |
3098 | + expected.clear(); |
3099 | + expected << "username" << "email" << |
3100 | + "preferences/maximized" << "preferences/initial_directory"; |
3101 | + result = account->allKeys(); |
3102 | + |
3103 | + expected.sort(); |
3104 | + result.sort(); |
3105 | + QCOMPARE(result, expected); |
3106 | + |
3107 | + /* Test clear(): call it from inside the preferences/ group */ |
3108 | + account->beginGroup("preferences"); |
3109 | + account->clear(); |
3110 | + account->sync(); |
3111 | + |
3112 | + expected.clear(); /* all keys should have been deleted */ |
3113 | + result = account->allKeys(); |
3114 | + |
3115 | + expected.sort(); |
3116 | + result.sort(); |
3117 | + QCOMPARE(result, expected); |
3118 | + |
3119 | + delete account; |
3120 | + delete mgr; |
3121 | +} |
3122 | + |
3123 | +void AccountsTest::testKeySignVerify() |
3124 | +{ |
3125 | +#ifndef HAVE_AEGISCRYPTO |
3126 | + QSKIP("aegis-crypto not detected."); |
3127 | +#endif |
3128 | + |
3129 | + const QString key = "key"; |
3130 | + const char *token; |
3131 | + QList<const char*> listOfTokens; |
3132 | + listOfTokens << "libaccounts-glib0::accounts-glib-access" |
3133 | + << "libaccounts-glib0::dummy" |
3134 | + << "libaccounts-glib0::idiotic"; |
3135 | + bool ok; |
3136 | + |
3137 | + Manager *mgr = new Manager(); |
3138 | + QVERIFY (mgr != 0); |
3139 | + |
3140 | + Account *account = mgr->createAccount(NULL); |
3141 | + QVERIFY(account != 0); |
3142 | + |
3143 | + account->setValue(key, QString("the key value")); |
3144 | + account->syncAndBlock(); |
3145 | + |
3146 | + account->sign(key, listOfTokens.at(0)); |
3147 | + account->syncAndBlock(); |
3148 | + |
3149 | + ok = account->verify(key, &token); |
3150 | + QVERIFY(ok == true); |
3151 | + |
3152 | + ok = account->verifyWithTokens(key, listOfTokens); |
3153 | + QVERIFY(ok == true); |
3154 | + |
3155 | + delete mgr; |
3156 | +} |
3157 | + |
3158 | +void AccountsTest::testIncrementalAccountIds() |
3159 | +{ |
3160 | + clearDb(); |
3161 | + |
3162 | + Manager *mgr = new Manager; |
3163 | + QVERIFY(mgr != 0); |
3164 | + |
3165 | + Account *account = mgr->createAccount(NULL); |
3166 | + QVERIFY(account != 0); |
3167 | + QVERIFY(account->manager() == mgr); |
3168 | + account->syncAndBlock(); |
3169 | + AccountId lastId = account->id(); |
3170 | + |
3171 | + account->remove(); |
3172 | + account->syncAndBlock(); |
3173 | + delete account; |
3174 | + |
3175 | + account = mgr->createAccount(NULL); |
3176 | + QVERIFY(account != 0); |
3177 | + QVERIFY(account->manager() == mgr); |
3178 | + account->syncAndBlock(); |
3179 | + |
3180 | + QCOMPARE(account->id(), lastId + 1); |
3181 | + |
3182 | + delete account; |
3183 | + delete mgr; |
3184 | +} |
3185 | + |
3186 | +void AccountsTest::testSelectGlobalAccountSettings() |
3187 | +{ |
3188 | + Manager *mgr = new Manager; |
3189 | + QVERIFY(mgr != 0); |
3190 | + |
3191 | + Account *account = mgr->createAccount("MyProvider"); |
3192 | + QVERIFY(account != 0); |
3193 | + QVERIFY(account->manager() == mgr); |
3194 | + |
3195 | + account->syncAndBlock(); |
3196 | + QVERIFY(account->id() > 0); |
3197 | + |
3198 | + account->selectService(); |
3199 | + Service selectedService = account->selectedService(); |
3200 | + QVERIFY(!selectedService.isValid()); |
3201 | + |
3202 | + delete mgr; |
3203 | +} |
3204 | + |
3205 | +void AccountsTest::testCredentialsId() |
3206 | +{ |
3207 | + Manager *mgr = new Manager; |
3208 | + QVERIFY(mgr != 0); |
3209 | + |
3210 | + Account *account = mgr->createAccount("MyProvider"); |
3211 | + QVERIFY(account != 0); |
3212 | + |
3213 | + Service service = mgr->service(MYSERVICE); |
3214 | + QVERIFY(service.isValid()); |
3215 | + |
3216 | + uint globalId = 69, myServiceId = 0xDEAD; |
3217 | + |
3218 | + account->setCredentialsId(globalId); |
3219 | + |
3220 | + account->selectService(service); |
3221 | + account->setCredentialsId(myServiceId); |
3222 | + |
3223 | + account->syncAndBlock(); |
3224 | + QVERIFY(account->id() != 0); |
3225 | + |
3226 | + QCOMPARE(account->credentialsId(), myServiceId); |
3227 | + |
3228 | + /* select a service with no credentials: we should get the global |
3229 | + * credentials ID, but the selected service shouldn't change */ |
3230 | + service = mgr->service(OTHERSERVICE); |
3231 | + QVERIFY(service.isValid()); |
3232 | + |
3233 | + account->selectService(service); |
3234 | + QCOMPARE(account->credentialsId(), globalId); |
3235 | + QCOMPARE(account->selectedService(), service); |
3236 | + |
3237 | + /* now make sure that we can get the ID from the global accounts settings */ |
3238 | + account->selectService(); |
3239 | + QCOMPARE(account->credentialsId(), globalId); |
3240 | + |
3241 | + delete mgr; |
3242 | +} |
3243 | + |
3244 | +void AccountsTest::testAuthData() |
3245 | +{ |
3246 | + Manager *manager = new Manager; |
3247 | + QVERIFY(manager != 0); |
3248 | + |
3249 | + Account *account = manager->createAccount("MyProvider"); |
3250 | + QVERIFY(account != 0); |
3251 | + |
3252 | + Service service = manager->service(MYSERVICE); |
3253 | + QVERIFY(service.isValid()); |
3254 | + |
3255 | + const uint credentialsId = 69; |
3256 | + const QString method = "mymethod"; |
3257 | + const QString mechanism = "mymechanism"; |
3258 | + QString prefix = |
3259 | + QString::fromLatin1("auth/%1/%2/").arg(method).arg(mechanism); |
3260 | + |
3261 | + QVariantMap globalParameters; |
3262 | + globalParameters["server"] = UTF8("myserver.com"); |
3263 | + globalParameters["port"] = 8080; |
3264 | + globalParameters["other"] = UTF8("overriden parameter"); |
3265 | + globalParameters["scopes"] = QStringList() << "read" << "write" << "edit"; |
3266 | + |
3267 | + QVariantMap serviceParameters; |
3268 | + serviceParameters["other"] = UTF8("better parameter"); |
3269 | + serviceParameters["boolean"] = true; |
3270 | + |
3271 | + account->setCredentialsId(credentialsId); |
3272 | + account->setValue("auth/method", method); |
3273 | + account->setValue("auth/mechanism", UTF8("overriden mechanism")); |
3274 | + QMapIterator<QString,QVariant> i(globalParameters); |
3275 | + while (i.hasNext()) { |
3276 | + i.next(); |
3277 | + account->setValue(prefix + i.key(), i.value()); |
3278 | + } |
3279 | + |
3280 | + account->selectService(service); |
3281 | + account->setValue("auth/mechanism", mechanism); |
3282 | + i = QMapIterator<QString,QVariant>(serviceParameters); |
3283 | + while (i.hasNext()) { |
3284 | + i.next(); |
3285 | + account->setValue(prefix + i.key(), i.value()); |
3286 | + } |
3287 | + |
3288 | + account->syncAndBlock(); |
3289 | + QVERIFY(account->id() != 0); |
3290 | + |
3291 | + AccountService *accountService = new AccountService(account, service); |
3292 | + QVERIFY(accountService != 0); |
3293 | + |
3294 | + AuthData authData = accountService->authData(); |
3295 | + QCOMPARE(authData.method(), method); |
3296 | + QCOMPARE(authData.mechanism(), mechanism); |
3297 | + QCOMPARE(authData.credentialsId(), credentialsId); |
3298 | + |
3299 | + QVariantMap expectedParameters = globalParameters; |
3300 | + i = QMapIterator<QString,QVariant>(serviceParameters); |
3301 | + while (i.hasNext()) { |
3302 | + i.next(); |
3303 | + expectedParameters.insert(i.key(), i.value()); |
3304 | + } |
3305 | + |
3306 | + QCOMPARE(authData.parameters(), expectedParameters); |
3307 | + |
3308 | + /* Test copy constructor */ |
3309 | + AuthData copy(authData); |
3310 | + QCOMPARE(copy.parameters(), expectedParameters); |
3311 | + |
3312 | + /* And delete destructor */ |
3313 | + AuthData *copy2 = new AuthData(authData); |
3314 | + QCOMPARE(copy2->parameters(), expectedParameters); |
3315 | + delete copy2; |
3316 | + |
3317 | + delete accountService; |
3318 | + delete account; |
3319 | + delete manager; |
3320 | + QVERIFY(service.isValid()); |
3321 | +} |
3322 | + |
3323 | +void AccountsTest::testGlobalAuthData() |
3324 | +{ |
3325 | + Manager *manager = new Manager; |
3326 | + QVERIFY(manager != 0); |
3327 | + |
3328 | + Account *account = manager->createAccount("MyProvider"); |
3329 | + QVERIFY(account != 0); |
3330 | + |
3331 | + Service service; // global account |
3332 | + QVERIFY(!service.isValid()); |
3333 | + |
3334 | + AccountService *accountService = new AccountService(account, service); |
3335 | + QVERIFY(accountService != 0); |
3336 | + |
3337 | + AuthData authData = accountService->authData(); |
3338 | + QCOMPARE(authData.method(), QString("oauth2")); |
3339 | + QCOMPARE(authData.mechanism(), QString("user_agent")); |
3340 | + QCOMPARE(authData.credentialsId(), uint(0)); |
3341 | + |
3342 | + QVariantMap expectedParameters; |
3343 | + expectedParameters.insert("Host", QString("myserver.example")); |
3344 | + |
3345 | + QCOMPARE(authData.parameters(), expectedParameters); |
3346 | + |
3347 | + delete accountService; |
3348 | + delete account; |
3349 | + delete manager; |
3350 | +} |
3351 | + |
3352 | +void AccountsTest::testListEnabledServices() |
3353 | +{ |
3354 | + clearDb(); |
3355 | + |
3356 | + Manager *mgr = new Manager(); |
3357 | + QVERIFY(mgr != 0); |
3358 | + |
3359 | + Service service = mgr->service(MYSERVICE); |
3360 | + QVERIFY(service.isValid()); |
3361 | + |
3362 | + Account* account = mgr->createAccount("MyProvider"); |
3363 | + QVERIFY(account != 0); |
3364 | + account->selectService(service); |
3365 | + account->setEnabled(true); |
3366 | + account->sync(); |
3367 | + |
3368 | + ServiceList list = account->enabledServices(); |
3369 | + QVERIFY(!list.isEmpty()); |
3370 | + QCOMPARE(list.size(), 1); |
3371 | + |
3372 | + account->selectService(service); |
3373 | + account->setEnabled(false); |
3374 | + account->sync(); |
3375 | + |
3376 | + list = account->enabledServices(); |
3377 | + QVERIFY(list.isEmpty()); |
3378 | + |
3379 | + delete account; |
3380 | + delete mgr; |
3381 | +} |
3382 | + |
3383 | + |
3384 | +void AccountsTest::testListEnabledByServiceType() |
3385 | +{ |
3386 | + clearDb(); |
3387 | + |
3388 | + Manager *mgr = new Manager("e-mail"); |
3389 | + QVERIFY(mgr != 0); |
3390 | + QCOMPARE(mgr->serviceType(), QString("e-mail")); |
3391 | + |
3392 | + Account *account = mgr->createAccount("MyProvider"); |
3393 | + QVERIFY(account != 0); |
3394 | + account->setEnabled(true); |
3395 | + |
3396 | + Service service = mgr->service(MYSERVICE); |
3397 | + QVERIFY(service.isValid()); |
3398 | + account->selectService(service); |
3399 | + account->setEnabled(true); |
3400 | + account->sync(); |
3401 | + |
3402 | + AccountIdList list = mgr->accountListEnabled("e-mail"); |
3403 | + QVERIFY(!list.isEmpty()); |
3404 | + QCOMPARE(list.size(), 1); |
3405 | + |
3406 | + list = mgr->accountListEnabled(); |
3407 | + QCOMPARE(list.count(), 1); |
3408 | + |
3409 | + account->setEnabled(false); |
3410 | + account->sync(); |
3411 | + |
3412 | + list = mgr->accountListEnabled("e-mail"); |
3413 | + QVERIFY(list.isEmpty()); |
3414 | + |
3415 | + delete account; |
3416 | + delete mgr; |
3417 | +} |
3418 | + |
3419 | +void AccountsTest::testEnabledEvent() |
3420 | +{ |
3421 | + Manager *mgr = new Manager("e-mail"); |
3422 | + QVERIFY(mgr != 0); |
3423 | + |
3424 | + QSignalSpy enabledEvent1(mgr, SIGNAL(enabledEvent(Accounts::AccountId))); |
3425 | + |
3426 | + Account *account = mgr->createAccount(NULL); |
3427 | + QVERIFY(account != 0); |
3428 | + account->setEnabled(true); |
3429 | + account->sync(); |
3430 | + |
3431 | + QTRY_COMPARE(enabledEvent1.count(), 1); |
3432 | + QCOMPARE(enabledEvent1.at(0).at(0).toUInt(), account->id()); |
3433 | + |
3434 | + //if we create manager without service type the signal should not be emitted |
3435 | + Manager *mgr2 = new Manager(); |
3436 | + QVERIFY(mgr2 != 0); |
3437 | + |
3438 | + QSignalSpy enabledEvent2(mgr2, SIGNAL(enabledEvent(Accounts::AccountId))); |
3439 | + |
3440 | + Account *account2 = mgr2->createAccount(NULL); |
3441 | + QVERIFY(account2 != 0); |
3442 | + account2->setEnabled(true); |
3443 | + account2->sync(); |
3444 | + |
3445 | + QCOMPARE(enabledEvent2.count(), 0); |
3446 | + |
3447 | + delete account; |
3448 | + delete account2; |
3449 | + delete mgr; |
3450 | + delete mgr2; |
3451 | +} |
3452 | + |
3453 | +void AccountsTest::testServiceType() |
3454 | +{ |
3455 | + Manager *mgr = new Manager(); |
3456 | + QVERIFY(mgr != 0); |
3457 | + |
3458 | + ServiceType serviceType; |
3459 | + |
3460 | + serviceType = mgr->serviceType("unexisting-type"); |
3461 | + QVERIFY(!serviceType.isValid()); |
3462 | + |
3463 | + serviceType = mgr->serviceType(EMAIL_SERVICE_TYPE); |
3464 | + QVERIFY(serviceType.isValid()); |
3465 | + |
3466 | + QCOMPARE(serviceType.name(), EMAIL_SERVICE_TYPE); |
3467 | + QCOMPARE(serviceType.displayName(), QStringLiteral("Electronic mail")); |
3468 | + QCOMPARE(serviceType.trCatalog(), QStringLiteral("translation_file")); |
3469 | + QCOMPARE(serviceType.iconName(), QStringLiteral("email_icon")); |
3470 | + QVERIFY(serviceType.tags().contains(QString("email"))); |
3471 | + // called twice, because the second time it returns a cached result |
3472 | + QVERIFY(serviceType.tags().contains(QString("email"))); |
3473 | + QVERIFY(serviceType.hasTag(QString("email"))); |
3474 | + QVERIFY(!serviceType.hasTag(QString("fake-email"))); |
3475 | + |
3476 | + QDomDocument dom = serviceType.domDocument(); |
3477 | + QDomElement root = dom.documentElement(); |
3478 | + QCOMPARE(root.tagName(), QString("service-type")); |
3479 | + |
3480 | + ServiceType copy(serviceType); |
3481 | + QCOMPARE(copy.displayName(), QStringLiteral("Electronic mail")); |
3482 | + |
3483 | + delete mgr; |
3484 | +} |
3485 | + |
3486 | +void AccountsTest::testUpdateAccount() |
3487 | +{ |
3488 | + clearDb(); |
3489 | + |
3490 | + Manager *mgr = new Manager("e-mail"); |
3491 | + QVERIFY(mgr != 0); |
3492 | + |
3493 | + QSignalSpy accountUpdated(mgr, |
3494 | + SIGNAL(accountUpdated(Accounts::AccountId))); |
3495 | + |
3496 | + Account *account = mgr->createAccount("MyProvider"); |
3497 | + QVERIFY(account != 0); |
3498 | + account->syncAndBlock(); |
3499 | + |
3500 | + Service service = mgr->service(MYSERVICE); |
3501 | + QVERIFY(service.isValid()); |
3502 | + account->selectService(service); |
3503 | + |
3504 | + account->setValue("key", QVariant("value")); |
3505 | + account->syncAndBlock(); |
3506 | + |
3507 | + QTRY_COMPARE(accountUpdated.count(), 1); |
3508 | + QCOMPARE(accountUpdated.at(0).at(0).toUInt(), account->id()); |
3509 | + |
3510 | + //if we create manager without service type the signal shoudl not be emitted |
3511 | + Manager *mgr2 = new Manager(); |
3512 | + QVERIFY(mgr2 != 0); |
3513 | + |
3514 | + QSignalSpy accountUpdated2(mgr2, |
3515 | + SIGNAL(accountUpdated(Accounts::AccountId))); |
3516 | + |
3517 | + Account *account2 = mgr2->createAccount(NULL); |
3518 | + QVERIFY(account2 != 0); |
3519 | + |
3520 | + account2->setValue("key", QVariant("value")); |
3521 | + account2->syncAndBlock(); |
3522 | + |
3523 | + QCOMPARE(accountUpdated2.count(), 0); |
3524 | + |
3525 | + delete account; |
3526 | + delete account2; |
3527 | + delete mgr; |
3528 | + delete mgr2; |
3529 | +} |
3530 | + |
3531 | +void AccountsTest::testApplication() |
3532 | +{ |
3533 | + Manager *manager = new Manager(); |
3534 | + QVERIFY(manager != 0); |
3535 | + |
3536 | + Application application = manager->application("Mailer"); |
3537 | + QVERIFY(application.isValid()); |
3538 | + |
3539 | + Service email = manager->service("MyService"); |
3540 | + QVERIFY(email.isValid()); |
3541 | + |
3542 | + Service sharing = manager->service("OtherService"); |
3543 | + QVERIFY(sharing.isValid()); |
3544 | + |
3545 | + QCOMPARE(application.name(), UTF8("Mailer")); |
3546 | + QCOMPARE(application.displayName(), UTF8("Easy Mailer")); |
3547 | + QCOMPARE(application.description(), UTF8("Mailer application")); |
3548 | + QCOMPARE(application.trCatalog(), UTF8("mailer-catalog")); |
3549 | + QCOMPARE(application.iconName(), UTF8("mailer-icon")); |
3550 | + QCOMPARE(application.desktopFilePath(), |
3551 | + UTF8(qgetenv("AG_APPLICATIONS") + "/applications/mailer.desktop")); |
3552 | + QCOMPARE(application.serviceUsage(email), |
3553 | + UTF8("Mailer can retrieve your e-mails")); |
3554 | + |
3555 | + ApplicationList apps = manager->applicationList(email); |
3556 | + QCOMPARE(apps.count(), 1); |
3557 | + QCOMPARE(apps[0].name(), UTF8("Mailer")); |
3558 | + |
3559 | + apps = manager->applicationList(sharing); |
3560 | + QCOMPARE(apps.count(), 1); |
3561 | + application = apps[0]; |
3562 | + QCOMPARE(application.name(), UTF8("Gallery")); |
3563 | + QCOMPARE(application.description(), UTF8("Image gallery")); |
3564 | + QCOMPARE(application.serviceUsage(sharing), |
3565 | + UTF8("Publish images on OtherService")); |
3566 | + |
3567 | + /* Test an invalid application */ |
3568 | + Application app2; |
3569 | + QVERIFY(!app2.isValid()); |
3570 | + Application app3(app2); |
3571 | + QVERIFY(!app3.isValid()); |
3572 | + |
3573 | + delete manager; |
3574 | +} |
3575 | + |
3576 | +QTEST_GUILESS_MAIN(AccountsTest) |
3577 | +#include "tst_libaccounts.moc" |
3578 | |
3579 | === added file 'tests/tst_libaccounts.pro' |
3580 | --- tests/tst_libaccounts.pro 1970-01-01 00:00:00 +0000 |
3581 | +++ tests/tst_libaccounts.pro 2015-11-06 13:54:21 +0000 |
3582 | @@ -0,0 +1,35 @@ |
3583 | +include( ../common-project-config.pri ) |
3584 | +include( ../common-vars.pri ) |
3585 | + |
3586 | +TARGET = accountstest |
3587 | +SOURCES += \ |
3588 | + tst_libaccounts.cpp |
3589 | +QT = \ |
3590 | + core \ |
3591 | + testlib \ |
3592 | + xml |
3593 | + |
3594 | +LIBS += -laccounts-qt5 |
3595 | + |
3596 | +INCLUDEPATH += $${TOP_SRC_DIR} |
3597 | +QMAKE_LIBDIR += \ |
3598 | + $${TOP_BUILD_DIR}/Accounts |
3599 | +QMAKE_RPATHDIR = $${QMAKE_LIBDIR} |
3600 | + |
3601 | +#Check for the existence of aegis-crypto |
3602 | +system(pkg-config --exists aegis-crypto) :HAVE_AEGISCRYPTO=YES |
3603 | +contains(HAVE_AEGISCRYPTO, YES) { |
3604 | + message("aegis-crypto detected...") |
3605 | + DEFINES += HAVE_AEGISCRYPTO |
3606 | +} |
3607 | + |
3608 | +include( ../common-installs-config.pri ) |
3609 | + |
3610 | +DATA_PATH = $${TOP_SRC_DIR}/tests |
3611 | + |
3612 | +DEFINES += \ |
3613 | + DATA_PATH=\\\"$$DATA_PATH\\\" |
3614 | + |
3615 | +QMAKE_EXTRA_TARGETS += check |
3616 | +check.depends = $${TARGET} |
3617 | +check.commands = "TESTDIR=$${TOP_SRC_DIR}/tests $${TOP_SRC_DIR}/tests/accountstest.sh" |