~ubuntu-branches/ubuntu/vivid/sflphone/vivid

« back to all changes in this revision

Viewing changes to kde/src/test/account_test.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2013-06-30 11:40:56 UTC
  • mfrom: (4.1.18 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130630114056-0np50jkyqo6vnmii
Tags: 1.2.3-2
* changeset_r92d62cfc54732bbbcfff2b1d36c096b120b981a5.diff 
  - fixes automatic endian detection 
* Update Vcs: fixes vcs-field-not-canonical

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *   Copyright (C) 2012-2013 by Savoir-Faire Linux                            *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>   *
 
4
 *                                                                            *
 
5
 *   This library is free software; you can redistribute it and/or            *
 
6
 *   modify it under the terms of the GNU Lesser General Public               *
 
7
 *   License as published by the Free Software Foundation; either             *
 
8
 *   version 2.1 of the License, or (at your option) any later version.       *
 
9
 *                                                                            *
 
10
 *   This library is distributed in the hope that it will be useful,          *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
 
13
 *   Lesser General Public License for more details.                          *
 
14
 *                                                                            *
 
15
 *   You should have received a copy of the Lesser GNU General Public License *
 
16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
 
17
 *****************************************************************************/
 
18
#include <QtCore/QString>
 
19
#include <QtTest/QtTest>
 
20
//#include <QtCore>
 
21
 
 
22
#include "../src/lib/configurationmanager_interface_singleton.h"
 
23
#include "../src/lib/callmanager_interface_singleton.h"
 
24
#include "../src/lib/instance_interface_singleton.h"
 
25
#include "../src/lib/typedefs.h"
 
26
#include "../src/lib/account.h"
 
27
#include "../src/lib/accountlist.h"
 
28
#include "../src/lib/dbus/metatypes.h"
 
29
 
 
30
class AccountTests: public QObject
 
31
{
 
32
   Q_OBJECT
 
33
private slots:
 
34
   /*void testValidity();
 
35
   void testMonth_data();
 
36
   void testMonth();*/
 
37
 
 
38
   //Testing accountlist
 
39
   void testAccountList();
 
40
   void testIP2IP();
 
41
   void testIP2IPAlias();
 
42
 
 
43
   //Building account
 
44
   void testCreateAccount();
 
45
   void testGetNewAccount();
 
46
   void cleanupTestCase();
 
47
 
 
48
   //Attributes test
 
49
   void testAccountAlias_data();
 
50
   void testAccountAlias                  ();
 
51
   
 
52
   void testAccountType                   ();
 
53
   void testAccountHostname_data();
 
54
   void testAccountHostname               ();
 
55
   void testAccountHostnameInvalid_data   ();
 
56
   void testAccountHostnameInvalid        ();
 
57
   void testAccountUsername               ();
 
58
   void testAccountPassword_data          ();
 
59
   void testAccountPassword               ();
 
60
   void testAccountMailbox                ();
 
61
   void testTlsPassword                   ();
 
62
   void testTlsCaListFile                 ();
 
63
   void testTlsCertificateFile            ();
 
64
   void testTlsPrivateKeyFile             ();
 
65
   void testTlsCiphers                    ();
 
66
   void testTlsServerName                 ();
 
67
   void testAccountSipStunServer          ();
 
68
   void testPublishedAddress              ();
 
69
   void testLocalInterface                ();
 
70
   void testRingtonePath_data();
 
71
   void testRingtonePath                  ();
 
72
   void testTlsMethod                     ();
 
73
   void testAccountRegistrationExpire     ();
 
74
   void testTlsNegotiationTimeoutSec      ();
 
75
   void testTlsNegotiationTimeoutMsec     ();
 
76
   void testLocalPort_data();
 
77
   void testLocalPort                     ();
 
78
   void testTlsListenerPort_data();
 
79
   void testTlsListenerPort               ();
 
80
   void testPublishedPort_data();
 
81
   void testPublishedPort                 ();
 
82
   void testAccountEnabled                ();
 
83
   void testTlsVerifyServer               ();
 
84
   void testTlsVerifyClient               ();
 
85
   void testTlsRequireClientCertificate   ();
 
86
   void testTlsEnable                     ();
 
87
   void testAccountDisplaySasOnce         ();
 
88
   void testAccountSrtpRtpFallback        ();
 
89
   void testAccountZrtpDisplaySas         ();
 
90
   void testAccountZrtpNotSuppWarning     ();
 
91
   void testAccountZrtpHelloHash          ();
 
92
   void testAccountSipStunEnabled         ();
 
93
   void testPublishedSameAsLocal          ();
 
94
   void testConfigRingtoneEnabled         ();
 
95
   void testDisableAllAccounts            ();
 
96
 
 
97
private:
 
98
   QString id;
 
99
   
 
100
};
 
101
 
 
102
 
 
103
//BEGIN Getting a valid account
 
104
void AccountTests::testAccountList()
 
105
{
 
106
   AccountList* list = AccountList::getInstance();
 
107
   QCOMPARE( list != nullptr , true);
 
108
   QCOMPARE( list->size() >= 1, true);
 
109
}
 
110
 
 
111
void AccountTests::testIP2IP() {
 
112
   Account* acc = AccountList::getInstance()->getAccountById("IP2IP");
 
113
   QCOMPARE( acc != nullptr, true);
 
114
   if (acc) {
 
115
      QCOMPARE( acc->getAlias(), QString("IP2IP"));
 
116
   }
 
117
}
 
118
 
 
119
void AccountTests::testIP2IPAlias() {
 
120
   Account* acc = AccountList::getInstance()->getAccountById("IP2IP");
 
121
   if (acc) {
 
122
      QCOMPARE( acc->getAlias(), QString("IP2IP"));
 
123
      QCOMPARE( acc->getAlias() != QString("qwerty"), true);
 
124
   }
 
125
}
 
126
//END Getting a valid account
 
127
 
 
128
 
 
129
//BEGIN Creating a new account
 
130
void AccountTests::testCreateAccount()
 
131
{
 
132
   Account* acc = Account::buildNewAccountFromAlias("unit_test_account");
 
133
   acc->save();
 
134
   id = acc->getAccountId();
 
135
   QCOMPARE( acc != nullptr, true);
 
136
}
 
137
 
 
138
void AccountTests::testGetNewAccount()
 
139
{
 
140
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
141
   QCOMPARE( acc != nullptr, true);
 
142
}
 
143
//END creating a new account
 
144
 
 
145
//BEGIN Testing every account attributes
 
146
 
 
147
void AccountTests::testAccountAlias_data()
 
148
{
 
149
   QTest::addColumn<QString>("alias");
 
150
 
 
151
   QTest::newRow("valid"      ) << QString( "unit_alias" );
 
152
   QTest::newRow("valid_reset") << QString( "unit_alias1");
 
153
   QTest::newRow("numeric"    ) << QString( "2314234"    );
 
154
   QTest::newRow("non-ascii"  ) << QString( "ééèè>>||``" );
 
155
}
 
156
 
 
157
void AccountTests::testAccountAlias                  ()/*QString detail*/
 
158
{
 
159
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
160
   //acc->setAccountAlias("unit_alias");
 
161
   //QCOMPARE( acc->getAccountAlias(), QString("unit_alias"));
 
162
 
 
163
   QFETCH(QString, alias);
 
164
   acc->setAccountAlias(alias);
 
165
   acc->save();
 
166
   QCOMPARE( acc->getAccountAlias(), alias );
 
167
   
 
168
}
 
169
 
 
170
void AccountTests::testAccountType                   ()/*QString detail*/
 
171
{
 
172
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
173
   acc->setAccountType("IAX");
 
174
   acc->save();
 
175
   QCOMPARE( acc->getAccountType(), QString("IAX") );
 
176
   acc->setAccountType("SIP");
 
177
   acc->save();
 
178
   QCOMPARE( acc->getAccountType(), QString("SIP") );
 
179
 
 
180
   //Test invalid
 
181
   acc->setAccountType("OTH");
 
182
   QCOMPARE( acc->getAccountType() == "OTH", false );
 
183
}
 
184
 
 
185
void AccountTests::testAccountHostname_data()
 
186
{
 
187
   QTest::addColumn<QString>("hostname");
 
188
   QTest::newRow("valid"          ) << QString( "validHostname"  );
 
189
   QTest::newRow("validPlusDigit" ) << QString( "validHostname2" );
 
190
   QTest::newRow("ipv4"           ) << QString( "192.168.77.12"  );
 
191
   QTest::newRow("ipv42"          ) << QString( "10.0.250.1"     );
 
192
}
 
193
 
 
194
//This test the various hostnames that should be allowed by the daemon
 
195
void AccountTests::testAccountHostname               ()
 
196
{
 
197
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
198
   QFETCH(QString, hostname);
 
199
   acc->setAccountHostname(hostname);
 
200
   acc->save();
 
201
   QCOMPARE( acc->getAccountHostname(), hostname );
 
202
}
 
203
 
 
204
void AccountTests::testAccountHostnameInvalid_data()
 
205
{
 
206
   QTest::addColumn<QString>("hostname");
 
207
   QTest::newRow("invalid_ipv4"       ) << QString( "192.256.12.0"    );
 
208
   QTest::newRow("invalid_ipv42"      ) << QString( "192.168.12.0000" );
 
209
   QTest::newRow("invalid_ipv43"      ) << QString( "192.168.12."     );
 
210
   QTest::newRow("invalid_ipv44"      ) << QString( "192.168.1"       );
 
211
   QTest::newRow("invalid_ipv45"      ) << QString( ".192.168.1.1"    );
 
212
   QTest::newRow("invalid_ipv46"      ) << QString( ".192.1E8.1.1"    );
 
213
   QTest::newRow("invalid_hostname"   ) << QString( ".23423"          );
 
214
}
 
215
 
 
216
//This test hostname that should be rejected by the daemon
 
217
void AccountTests::testAccountHostnameInvalid        ()
 
218
{
 
219
   QFETCH(QString, hostname);
 
220
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
221
   acc->setAccountHostname(hostname);
 
222
   acc->save();
 
223
   QVERIFY(acc->getAccountHostname() != hostname);
 
224
}
 
225
 
 
226
void AccountTests::testAccountUsername               ()/*QString detail*/
 
227
{
 
228
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
229
   acc->setAccountHostname("1234567879");
 
230
   acc->save();
 
231
   QString username = acc->getAccountHostname();
 
232
   QCOMPARE(username,QString("1234567879"));
 
233
   
 
234
}
 
235
 
 
236
void AccountTests::testAccountPassword_data()
 
237
{
 
238
   QTest::addColumn<QString>("password");
 
239
   QTest::newRow( "numeric"      ) << QString( "1234567879"   );
 
240
   QTest::newRow( "alphanumeric" ) << QString( "asdf1234"     );
 
241
   QTest::newRow( "strong"       ) << QString( "!\"'''4)(--@" );
 
242
}
 
243
 
 
244
void AccountTests::testAccountPassword               ()/*QString detail*/
 
245
{
 
246
   /*QFETCH(QString, password);
 
247
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
248
   acc->setAccountPassword(password);
 
249
   QString pwd = acc->getAccountPassword();
 
250
   QCOMPARE(pwd,password);*/
 
251
}
 
252
 
 
253
void AccountTests::testAccountMailbox                ()/*QString detail*/
 
254
{
 
255
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
256
   acc->setAccountMailbox("1234567879");
 
257
   acc->save();
 
258
   QString mailbox = acc->getAccountMailbox();
 
259
   QCOMPARE(mailbox,QString("1234567879"));
 
260
   
 
261
}
 
262
 
 
263
void AccountTests::testTlsPassword                   ()/*QString detail*/
 
264
{
 
265
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
266
   acc->setTlsPassword("1234567879");
 
267
   acc->save();
 
268
   QString tlspass = acc->getTlsPassword();
 
269
   QCOMPARE(tlspass,QString("1234567879"));
 
270
}
 
271
 
 
272
void AccountTests::testTlsCaListFile                 ()/*QString detail*/
 
273
{
 
274
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
275
   QSKIP("TODO",SkipAll);
 
276
}
 
277
 
 
278
void AccountTests::testTlsCertificateFile            ()/*QString detail*/
 
279
{
 
280
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
281
   QSKIP("TODO",SkipAll);
 
282
}
 
283
 
 
284
void AccountTests::testTlsPrivateKeyFile             ()/*QString detail*/
 
285
{
 
286
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
287
   QSKIP("TODO",SkipAll);
 
288
}
 
289
 
 
290
void AccountTests::testTlsCiphers                    ()/*QString detail*/
 
291
{
 
292
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
293
   QSKIP("TODO",SkipAll);
 
294
}
 
295
 
 
296
void AccountTests::testTlsServerName                 ()/*QString detail*/
 
297
{
 
298
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
299
   acc->setTlsServerName("qwerty");
 
300
   acc->save();
 
301
   QString tlsserver = acc->getTlsServerName();
 
302
   QCOMPARE(tlsserver,QString("qwerty"));
 
303
}
 
304
 
 
305
void AccountTests::testAccountSipStunServer          ()/*QString detail*/
 
306
{
 
307
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
308
   acc->setAccountSipStunServer("qwerty");
 
309
   acc->save();
 
310
   QString tlsserver = acc->getAccountSipStunServer();
 
311
   QCOMPARE(tlsserver,QString("qwerty"));
 
312
}
 
313
 
 
314
void AccountTests::testPublishedAddress              ()/*QString detail*/
 
315
{
 
316
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
317
   QSKIP("TODO",SkipAll);
 
318
}
 
319
 
 
320
void AccountTests::testLocalInterface                ()/*QString detail*/
 
321
{
 
322
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
323
   QSKIP("TODO",SkipAll);
 
324
}
 
325
 
 
326
void AccountTests::testRingtonePath_data()
 
327
{
 
328
   QTest::addColumn<QString>("path");
 
329
   QMap<QString,QString> ringtonePaths = ConfigurationManagerInterfaceSingleton::getInstance().getRingtoneList();
 
330
   QMutableMapIterator<QString, QString> iter(ringtonePaths);
 
331
   while (iter.hasNext()) {
 
332
      iter.next();
 
333
      QTest::newRow( iter.value().toAscii() ) << iter.key();
 
334
   }
 
335
   QTest::newRow( "invalidWav" ) << QString("invalid/tmp2/fake_file.wav");
 
336
   QTest::newRow( "invalidAu"  ) << QString("invalid/tmp2/fake_file.au");
 
337
   QTest::newRow( "invalidUl"  ) << QString("invalid/tmp2/fake_file.ul");
 
338
   
 
339
   QString tmpPath = QDir::tempPath();
 
340
   QFile file (tmpPath+"/testWav.wav");
 
341
   file.open(QIODevice::WriteOnly);
 
342
   file.close();
 
343
   QTest::newRow( "wav_file"      ) << tmpPath+"/testWav.wav";
 
344
   
 
345
   QFile file2 (tmpPath+"/testAu.au");
 
346
   file2.open(QIODevice::WriteOnly);
 
347
   file2.close();
 
348
   QTest::newRow( "au_file"      ) << tmpPath+"/testAu.au";
 
349
 
 
350
   QFile file3 (tmpPath+"/testUl.ul");
 
351
   file3.open(QIODevice::WriteOnly);
 
352
   file3.close();
 
353
   QTest::newRow( "ul_file"      ) << tmpPath+"/testUl.ul";
 
354
   
 
355
}
 
356
 
 
357
void AccountTests::testRingtonePath                  ()/*QString detail*/
 
358
{
 
359
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
360
   QFETCH(QString, path);
 
361
   acc->setRingtonePath(path);
 
362
   acc->save();
 
363
   if (path.indexOf("invalid") != -1)
 
364
      QCOMPARE(acc->getRingtonePath() == path ,false);
 
365
   else
 
366
      QCOMPARE(acc->getRingtonePath(),path);
 
367
}
 
368
 
 
369
void AccountTests::testTlsMethod                     ()/*int     detail*/
 
370
{
 
371
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
372
   QSKIP("TODO",SkipAll);
 
373
}
 
374
 
 
375
void AccountTests::testAccountRegistrationExpire     ()/*int     detail*/
 
376
{
 
377
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
378
   acc->setAccountRegistrationExpire(10000);
 
379
   acc->save();
 
380
   QCOMPARE(acc->getAccountRegistrationExpire(),10000);
 
381
 
 
382
   //Time machines are not on the market yet
 
383
   acc->setAccountRegistrationExpire(-10000);
 
384
   acc->save();
 
385
   QCOMPARE(acc->getAccountRegistrationExpire() == -10000,false);
 
386
}
 
387
 
 
388
void AccountTests::testTlsNegotiationTimeoutSec      ()/*int     detail*/
 
389
{
 
390
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
391
   acc->setTlsNegotiationTimeoutSec(10000);
 
392
   acc->save();
 
393
 
 
394
   QCOMPARE(acc->getTlsNegotiationTimeoutSec(),10000);
 
395
 
 
396
   //Time machines are not on the market yet
 
397
   acc->setTlsNegotiationTimeoutSec(-10000);
 
398
   acc->save();
 
399
   QCOMPARE(acc->getTlsNegotiationTimeoutSec() == -10000,false);
 
400
}
 
401
 
 
402
void AccountTests::testTlsNegotiationTimeoutMsec     ()/*int     detail*/
 
403
{
 
404
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
405
 
 
406
   acc->setTlsNegotiationTimeoutMsec(10000);
 
407
   acc->save();
 
408
   QCOMPARE(acc->getTlsNegotiationTimeoutMsec(),10000);
 
409
 
 
410
   //Time machines are not on the market yet
 
411
   acc->setTlsNegotiationTimeoutMsec(-10000);
 
412
   acc->save();
 
413
   QCOMPARE(acc->getTlsNegotiationTimeoutMsec() == -10000,false);
 
414
}
 
415
 
 
416
void AccountTests::testLocalPort_data()
 
417
{
 
418
   //It is really an unsigned short, but lets do real tests instead
 
419
   QTest::addColumn<int>("port");
 
420
   QTest::newRow( "null"     ) << 0      ;
 
421
   QTest::newRow( "2000"     ) << 2000   ;
 
422
   QTest::newRow( "high"     ) << 65533  ;
 
423
   QTest::newRow( "over"     ) << 1000000;
 
424
   QTest::newRow( "negative" ) << -1000  ;
 
425
 
 
426
}
 
427
 
 
428
void AccountTests::testLocalPort                     ()/*short   detail*/
 
429
{
 
430
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
431
   QFETCH(int, port);
 
432
   acc->setLocalPort(port);
 
433
   acc->save();
 
434
   if (port < 0 || port > 65533)
 
435
      QCOMPARE(acc->getLocalPort() == port,false);
 
436
   else
 
437
      QCOMPARE(acc->getLocalPort(),port);
 
438
}
 
439
 
 
440
void AccountTests::testTlsListenerPort_data()
 
441
{
 
442
   //It is really an unsigned short, but lets do real tests instead
 
443
   QTest::addColumn<int>("port");
 
444
   QTest::newRow( "null"     ) << 0      ;
 
445
   QTest::newRow( "2000"     ) << 2000   ;
 
446
   QTest::newRow( "high"     ) << 65533  ;
 
447
   QTest::newRow( "over"     ) << 1000000;
 
448
   QTest::newRow( "negative" ) << -1000  ;
 
449
 
 
450
}
 
451
 
 
452
void AccountTests::testTlsListenerPort               ()/*short   detail*/
 
453
{
 
454
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
455
   QFETCH(int, port);
 
456
   acc->setTlsListenerPort(port);
 
457
   acc->save();
 
458
   if (port < 0 || port > 65533)
 
459
      QCOMPARE(acc->getTlsListenerPort() == port,false);
 
460
   else
 
461
      QCOMPARE(acc->getTlsListenerPort(),port);
 
462
}
 
463
 
 
464
void AccountTests::testPublishedPort_data()
 
465
{
 
466
   //It is really an unsigned short, but lets do real tests instead
 
467
   QTest::addColumn<int>("port");
 
468
   QTest::newRow( "null"     ) << 0      ;
 
469
   QTest::newRow( "2000"     ) << 2000   ;
 
470
   QTest::newRow( "high"     ) << 65533  ;
 
471
   QTest::newRow( "over"     ) << 1000000;
 
472
   QTest::newRow( "negative" ) << -1000  ;
 
473
 
 
474
}
 
475
 
 
476
void AccountTests::testPublishedPort                 ()/*short   detail*/
 
477
{
 
478
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
479
   QFETCH(int, port);
 
480
   acc->setPublishedPort(port);
 
481
   acc->save();
 
482
   if (port < 0 || port > 65533)
 
483
      QCOMPARE(acc->getPublishedPort() == port,false);
 
484
   else
 
485
      QCOMPARE(acc->getPublishedPort(),port);
 
486
}
 
487
 
 
488
void AccountTests::testAccountEnabled                ()/*bool    detail*/
 
489
{
 
490
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
491
   acc->setAccountEnabled(false);
 
492
   QCOMPARE(acc->isAccountEnabled(),false);
 
493
   acc->setAccountEnabled(true);
 
494
   QCOMPARE(acc->isAccountEnabled(),true);
 
495
}
 
496
 
 
497
void AccountTests::testTlsVerifyServer               ()/*bool    detail*/
 
498
{
 
499
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
500
   QSKIP("TODO",SkipAll);
 
501
}
 
502
 
 
503
void AccountTests::testTlsVerifyClient               ()/*bool    detail*/
 
504
{
 
505
   //Account* acc = AccountList::getInstance()->getAccountById(id);
 
506
   QSKIP("TODO",SkipAll);
 
507
}
 
508
 
 
509
void AccountTests::testTlsRequireClientCertificate   ()/*bool    detail*/
 
510
{
 
511
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
512
   acc->setTlsRequireClientCertificate(true);
 
513
   acc->save();
 
514
   QCOMPARE(acc->isTlsRequireClientCertificate(),true);
 
515
   acc->setTlsRequireClientCertificate(false);
 
516
   acc->save();
 
517
   QCOMPARE(acc->isTlsRequireClientCertificate(),false);
 
518
}
 
519
 
 
520
void AccountTests::testTlsEnable                     ()/*bool    detail*/
 
521
{
 
522
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
523
   acc->setTlsEnable(true);
 
524
   acc->save();
 
525
   QCOMPARE(acc->isTlsEnable(),true);
 
526
   acc->setTlsEnable(false);
 
527
   acc->save();
 
528
   QCOMPARE(acc->isTlsEnable(),false);
 
529
}
 
530
 
 
531
void AccountTests::testAccountDisplaySasOnce         ()/*bool    detail*/
 
532
{
 
533
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
534
   acc->setAccountDisplaySasOnce(true);
 
535
   acc->save();
 
536
   QCOMPARE(acc->isAccountDisplaySasOnce(),true);
 
537
   acc->setAccountDisplaySasOnce(false);
 
538
   acc->save();
 
539
   QCOMPARE(acc->isAccountDisplaySasOnce(),false);
 
540
}
 
541
 
 
542
void AccountTests::testAccountSrtpRtpFallback        ()/*bool    detail*/
 
543
{
 
544
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
545
   acc->setAccountSrtpRtpFallback(true);
 
546
   acc->save();
 
547
   QCOMPARE(acc->isAccountSrtpRtpFallback(),true);
 
548
   acc->setAccountSrtpRtpFallback(false);
 
549
   acc->save();
 
550
   QCOMPARE(acc->isAccountSrtpRtpFallback(),false);
 
551
}
 
552
 
 
553
void AccountTests::testAccountZrtpDisplaySas         ()/*bool    detail*/
 
554
{
 
555
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
556
   acc->setAccountSrtpRtpFallback(true);
 
557
   acc->save();
 
558
   QCOMPARE(acc->isAccountSrtpRtpFallback(),true);
 
559
   acc->setAccountSrtpRtpFallback(false);
 
560
   acc->save();
 
561
   QCOMPARE(acc->isAccountSrtpRtpFallback(),false);
 
562
}
 
563
 
 
564
void AccountTests::testAccountZrtpNotSuppWarning     ()/*bool    detail*/
 
565
{
 
566
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
567
   acc->setAccountZrtpNotSuppWarning(true);
 
568
   acc->save();
 
569
   QCOMPARE(acc->isAccountZrtpNotSuppWarning(),true);
 
570
   acc->setAccountZrtpNotSuppWarning(false);
 
571
   acc->save();
 
572
   QCOMPARE(acc->isAccountZrtpNotSuppWarning(),false);
 
573
}
 
574
 
 
575
void AccountTests::testAccountZrtpHelloHash          ()/*bool    detail*/
 
576
{
 
577
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
578
   acc->setAccountZrtpHelloHash(true);
 
579
   acc->save();
 
580
   QCOMPARE(acc->isAccountZrtpHelloHash(),true);
 
581
   acc->setAccountZrtpHelloHash(false);
 
582
   acc->save();
 
583
   QCOMPARE(acc->isAccountZrtpHelloHash(),false);
 
584
}
 
585
 
 
586
void AccountTests::testAccountSipStunEnabled         ()/*bool    detail*/
 
587
{
 
588
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
589
   acc->setAccountSipStunEnabled(true);
 
590
   acc->save();
 
591
   QCOMPARE(acc->isAccountSipStunEnabled(),true);
 
592
   acc->setAccountSipStunEnabled(false);
 
593
   acc->save();
 
594
   QCOMPARE(acc->isAccountSipStunEnabled(),false);
 
595
}
 
596
 
 
597
void AccountTests::testPublishedSameAsLocal          ()/*bool    detail*/
 
598
{
 
599
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
600
   acc->setPublishedSameAsLocal(true);
 
601
   acc->save();
 
602
   QCOMPARE(acc->isPublishedSameAsLocal(),true);
 
603
   acc->setPublishedSameAsLocal(false);
 
604
   acc->save();
 
605
   QCOMPARE(acc->isPublishedSameAsLocal(),false);
 
606
}
 
607
 
 
608
void AccountTests::testConfigRingtoneEnabled         ()/*bool    detail*/
 
609
{
 
610
   Account* acc = AccountList::getInstance()->getAccountById(id);
 
611
   acc->setRingtoneEnabled(true);
 
612
   acc->save();
 
613
   QCOMPARE(acc->isRingtoneEnabled(),true);
 
614
   acc->setRingtoneEnabled(false);
 
615
   acc->save();
 
616
   QCOMPARE(acc->isRingtoneEnabled(),false);
 
617
}
 
618
 
 
619
//END Testing every account attributes
 
620
 
 
621
//BEGIN testing account list
 
622
 
 
623
void AccountTests::testDisableAllAccounts()
 
624
{
 
625
   QList<bool> saveState;
 
626
   //Disable all accounts
 
627
   for (int i=0;i<AccountList::getInstance()->size();i++) {
 
628
      saveState << (*AccountList::getInstance())[i]->isAccountEnabled();
 
629
      (*AccountList::getInstance())[i]->setAccountEnabled(false);
 
630
      (*AccountList::getInstance())[i]->save();
 
631
   }
 
632
 
 
633
   QCOMPARE(AccountList::getCurrentAccount(),(Account*)nullptr);
 
634
 
 
635
   //Restore state
 
636
   for (int i=0;i<AccountList::getInstance()->size();i++) {
 
637
      (*AccountList::getInstance())[i]->setAccountEnabled(saveState[i]);
 
638
      (*AccountList::getInstance())[i]->save();
 
639
   }
 
640
}
 
641
 
 
642
//END testing account list
 
643
 
 
644
//BEGIN cleanup
 
645
void AccountTests::cleanupTestCase() {
 
646
   AccountList::getInstance()->removeAccount(AccountList::getInstance()->getAccountById(id));
 
647
   QCOMPARE( AccountList::getInstance()->getAccountById(id) == nullptr, true);
 
648
}
 
649
//END cleanup
 
650
 
 
651
QTEST_MAIN(AccountTests)
 
652
#include "account_test.moc"