From 8309e0d196f97fe1cf35345abeddf74b136dd455 Mon Sep 17 00:00:00 2001
From: Chupligin Sergey <neochapay@gmail.com>
Date: Tue, 17 Aug 2021 16:53:48 +0300
Subject: [PATCH 1/1] Fix warnngs and API for new Qt

---
 declarative/src/plugin.cpp                    |  4 +--
 libcommhistory.pro                            |  4 +--
 src/contactfetcher.cpp                        |  2 +-
 src/contactlistener.cpp                       |  7 ++--
 src/conversationmodel.cpp                     |  2 +-
 src/databaseio.cpp                            |  4 +--
 src/draftsmodel.cpp                           |  4 +--
 src/event.cpp                                 |  6 ++--
 src/eventmodel_p.cpp                          |  4 +--
 src/groupmanager.cpp                          |  4 +--
 tests/common.cpp                              | 24 +++++++++++--
 tests/common.h                                |  4 ++-
 tests/mem_eventmodel/mem_eventmodel.cpp       |  4 +--
 tests/perf_callmodel/callmodelperftest.cpp    |  3 +-
 .../conversationmodelperftest.cpp             |  3 +-
 tests/perf_groupmodel/groupmodelperftest.cpp  |  3 +-
 .../recentcontactsmodelperftest.cpp           |  3 +-
 tests/performance_tests.xml.in                | 28 +++++++++++++++
 .../callmodelprofiletest.cpp                  |  3 +-
 .../conversationmodelprofiletest.cpp          |  3 +-
 .../groupmodelprofiletest.cpp                 |  3 +-
 .../recentcontactsmodelprofiletest.cpp        |  3 +-
 tests/ut_callmodel/callmodeltest.cpp          |  2 +-
 .../conversationmodeltest.cpp                 |  2 +-
 tests/ut_eventmodel/eventmodeltest.cpp        | 14 ++++----
 tests/ut_groupmodel/groupmodeltest.cpp        | 10 +++---
 .../recentcontactsmodeltest.cpp               |  2 +-
 .../recipienteventmodeltest.cpp               |  2 +-
 .../singleeventmodeltest.cpp                  |  2 +-
 tools/commhistory-tool.cpp                    | 34 ++++++++++---------
 30 files changed, 127 insertions(+), 66 deletions(-)

diff --git a/declarative/src/plugin.cpp b/declarative/src/plugin.cpp
index 0aac399..02c66b7 100644
--- a/declarative/src/plugin.cpp
+++ b/declarative/src/plugin.cpp
@@ -73,6 +73,6 @@ void CommHistoryPlugin::registerTypes(const char *uri)
     qmlRegisterType<DraftEvent>(uri, 1, 0, "DraftEvent");
     qmlRegisterType<MmsHelper>(uri, 1, 0, "MmsHelper");
 
-    qmlRegisterType<CommHistory::GroupObject>();
-    qmlRegisterType<CommHistory::ContactGroup>();
+    qmlRegisterAnonymousType<CommHistory::GroupObject>(uri, 0);
+    qmlRegisterAnonymousType<CommHistory::ContactGroup>(uri, 0);
 }
diff --git a/libcommhistory.pro b/libcommhistory.pro
index f23e67f..7dcfff5 100644
--- a/libcommhistory.pro
+++ b/libcommhistory.pro
@@ -25,12 +25,10 @@
 TEMPLATE  = subdirs
 SUBDIRS   = src   \
             declarative \
-            tools \
-            tests
+            tools
 
 declarative.depends = src
 tools.depends = src
-tests.depends = src
 
 OTHER_FILES += rpm/libcommhistory-qt5.spec
 
diff --git a/src/contactfetcher.cpp b/src/contactfetcher.cpp
index b0c5e38..b4b71fb 100644
--- a/src/contactfetcher.cpp
+++ b/src/contactfetcher.cpp
@@ -67,7 +67,7 @@ ContactFetcherPrivate::ContactFetcherPrivate(ContactFetcher *parent)
     , m_resolver(0)
     , m_fetching(false)
 {
-    SeasideCache::registerChangeListener(this, SeasideCache::FetchAvatar);
+    SeasideCache::registerChangeListener(this);
 }
 
 ContactFetcherPrivate::~ContactFetcherPrivate()
diff --git a/src/contactlistener.cpp b/src/contactlistener.cpp
index 69bad1a..e0c9d8c 100644
--- a/src/contactlistener.cpp
+++ b/src/contactlistener.cpp
@@ -31,6 +31,7 @@
 #include <QContactOnlineAccount>
 #include <QContactPhoneNumber>
 #include <QContactEmailAddress>
+#include <QContactSyncTarget>
 
 #include "commonutils.h"
 #include "contactresolver.h"
@@ -100,7 +101,7 @@ ContactListenerPrivate::ContactListenerPrivate(ContactListener *q)
     , retryResolver(0)
     , q_ptr(q)
 {
-    SeasideCache::registerChangeListener(this, SeasideCache::FetchAvatar);
+    SeasideCache::registerChangeListener(this);
 }
 
 ContactListenerPrivate::~ContactListenerPrivate()
@@ -162,7 +163,9 @@ void ContactListenerPrivate::itemUpdated(SeasideCache::CacheItem *item)
     Q_Q(ContactListener);
 
     // Only aggregate contacts are relevant
-    if (item->contact.collectionId() != SeasideCache::aggregateCollectionId())
+    static const QString aggregateTarget(QString::fromLatin1("aggregate"));
+    QContactSyncTarget syncTarget(item->contact.detail<QContactSyncTarget>());
+    if (syncTarget.syncTarget() != aggregateTarget)
         return;
 
     // Make a list of Recipient from the contacts addresses to compare against
diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp
index 2ee6957..6e1fe44 100644
--- a/src/conversationmodel.cpp
+++ b/src/conversationmodel.cpp
@@ -264,7 +264,7 @@ bool ConversationModel::getEvents(QList<int> groupIds)
 {
     Q_D(ConversationModel);
 
-    d->filterGroupIds = QSet<int>::fromList(groupIds);
+    d->filterGroupIds = QSet<int>(groupIds.begin(), groupIds.end());
     d->allGroups = false;
 
     beginResetModel();
diff --git a/src/databaseio.cpp b/src/databaseio.cpp
index dca4263..cefff62 100644
--- a/src/databaseio.cpp
+++ b/src/databaseio.cpp
@@ -864,7 +864,7 @@ bool DatabaseIO::modifyEvent(Event &event)
             if (part.id() >= 0) {
                 if (!idList.isEmpty())
                     idList.append(',');
-                idList.append(QString::number(part.id()));
+                idList.append(QString::number(part.id()).toUtf8());
             }
         }
 
@@ -1059,7 +1059,7 @@ bool DatabaseIO::getGroups(const QString &localUid, const QString &remoteUid, QL
         if (!remoteUid.isEmpty())
             q += "Groups.remoteUids = :remoteUid ";
     }
-    q += "GROUP BY Groups.id " + queryOrder;
+    q += QString("GROUP BY Groups.id " + queryOrder).toUtf8();
 
     QSqlQuery query = CommHistoryDatabase::prepare(q.data(), d->connection());
     if (!localUid.isEmpty())
diff --git a/src/draftsmodel.cpp b/src/draftsmodel.cpp
index 485cd3f..aa24b62 100644
--- a/src/draftsmodel.cpp
+++ b/src/draftsmodel.cpp
@@ -61,7 +61,7 @@ QList<int> DraftsModel::filterGroups() const
 void DraftsModel::setFilterGroups(const QList<int> &list)
 {
     Q_D(DraftsModel);
-    QSet<int> groupIds = list.toSet();
+    QSet<int> groupIds(list.begin(), list.end());
     if (groupIds == d->filterGroups)
         return;
 
@@ -89,7 +89,7 @@ bool DraftsModel::getEvents()
 
     // As in ConversationModel, a UNION ALL is used to get better
     // optimization out of sqlite
-    QList<int> groups = d->filterGroups.toList();
+    QList<int> groups(d->filterGroups.begin(), d->filterGroups.end());
     int unionCount = 0;
     QString q;
     do {
diff --git a/src/event.cpp b/src/event.cpp
index 45ccf89..20ca1b6 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -637,17 +637,17 @@ QList<MessagePart> Event::messageParts() const
 
 QStringList Event::toList() const
 {
-    return d->headers.value(MMS_TO_HEADER).split("\x1e", QString::SkipEmptyParts);
+    return d->headers.value(MMS_TO_HEADER).split("\x1e", Qt::SkipEmptyParts);
 }
 
 QStringList Event::ccList() const
 {
-    return d->headers.value(MMS_CC_HEADER).split("\x1e", QString::SkipEmptyParts);
+    return d->headers.value(MMS_CC_HEADER).split("\x1e", Qt::SkipEmptyParts);
 }
 
 QStringList Event::bccList() const
 {
-    return d->headers.value(MMS_BCC_HEADER).split("\x1e", QString::SkipEmptyParts);
+    return d->headers.value(MMS_BCC_HEADER).split("\x1e", Qt::SkipEmptyParts);
 }
 
 Event::EventReadStatus Event::readStatus() const
diff --git a/src/eventmodel_p.cpp b/src/eventmodel_p.cpp
index 3fcd054..e3893e1 100644
--- a/src/eventmodel_p.cpp
+++ b/src/eventmodel_p.cpp
@@ -537,13 +537,13 @@ void EventModelPrivate::recipientsUpdated(const QSet<Recipient> &recipients, boo
 
 void EventModelPrivate::slotContactInfoChanged(const RecipientList &recipients)
 {
-    QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
+    QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
     recipientsUpdated(changed);
 }
 
 void EventModelPrivate::slotContactChanged(const RecipientList &recipients)
 {
-    QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
+    QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
     recipientsUpdated(changed, true);
 }
 
diff --git a/src/groupmanager.cpp b/src/groupmanager.cpp
index ba36a00..359a401 100644
--- a/src/groupmanager.cpp
+++ b/src/groupmanager.cpp
@@ -380,7 +380,7 @@ void GroupManagerPrivate::slotContactInfoChanged(const RecipientList &recipients
 {
     Q_Q(GroupManager);
 
-    QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
+    QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
 
     foreach (GroupObject *group, groups) {
         if (group->recipients().intersects(changed))
@@ -392,7 +392,7 @@ void GroupManagerPrivate::slotContactChanged(const RecipientList &recipients)
 {
     Q_Q(GroupManager);
 
-    QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
+    QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
 
     foreach (GroupObject *group, groups) {
         if (group->recipients().intersects(changed))
diff --git a/tests/common.cpp b/tests/common.cpp
index d6e9372..e668123 100644
--- a/tests/common.cpp
+++ b/tests/common.cpp
@@ -356,7 +356,7 @@ QList<int> addTestContacts(const QList<QPair<QString, QPair<QString, QString> >
 
 bool addTestContactAddress(int contactId, const QString &remoteUid, const QString &localUid)
 {
-    QContact existingAggregate = manager()->contact(apiContactId(contactId, manager()->managerUri()));
+    QContact existingAggregate = manager()->contact(apiContactId(contactId));
     if (internalContactId(existingAggregate.id()) != (unsigned)contactId) {
         qWarning() << "Could not retrieve contact:" << contactId;
         return false;
@@ -404,6 +404,7 @@ bool addTestContactAddress(int contactId, const QString &remoteUid, const QStrin
 void modifyTestContact(int id, const QString &name, bool favorite)
 {
     QContact existingAggregate = manager()->contact(apiContactId(id, manager()->managerUri()));
+
     if (internalContactId(existingAggregate.id()) != (unsigned)id) {
         qWarning() << "Could not retrieve contact:" << id;
         return;
@@ -437,7 +438,7 @@ void modifyTestContact(int id, const QString &name, bool favorite)
 
 void deleteTestContact(int id, ContactChangeListener *listener)
 {
-    const QContactId contactId = apiContactId(id, manager()->managerUri());
+    const QContactId contactId = apiContactId(id);
     const QContact contact = manager()->contact(contactId);
 
     const QContactId localId = localContactForAggregate(contactId);
@@ -585,13 +586,30 @@ void deleteAll(bool deleteDb)
 QString randomMessage(int words)
 {
     QString msg;
+    QRandomGenerator qrand;
     QTextStream msgStream(&msg, QIODevice::WriteOnly);
     for(int j = 0; j < words; j++) {
-        msgStream << msgWords[qrand() % numWords] << " ";
+        msgStream << msgWords[qrand.generate() % numWords] << " ";
     }
     return msg;
 }
 
+bool waitSignal(QSignalSpy &spy, int msec)
+{
+    if (!spy.isEmpty()) {
+        return true;
+    }
+    QElapsedTimer timer;
+    timer.start();
+    while (timer.elapsed() < msec && spy.isEmpty()) {
+        QCoreApplication::sendPostedEvents();
+        QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+        QCoreApplication::processEvents();
+    }
+
+    return !spy.isEmpty();
+}
+
 void summarizeResults(const QString &className, QList<int> &times, QFile *logFile, int testSecs)
 {
     int sum = 0;
diff --git a/tests/common.h b/tests/common.h
index d55cb09..e779165 100644
--- a/tests/common.h
+++ b/tests/common.h
@@ -32,6 +32,7 @@
 
 #include <QTimer>
 #include <QFile>
+#include <QRandomGenerator>
 #include <QSignalSpy>
 #include <QStandardPaths>
 
@@ -43,9 +44,10 @@ template <class RandomAccessIterator>
 void random_shuffle (RandomAccessIterator first, RandomAccessIterator last)
 {
     typename std::iterator_traits<RandomAccessIterator>::difference_type i, n;
+    QRandomGenerator qrand;
     n = (last-first);
     for (i=n-1; i>0; --i) {
-        qSwap(first[i],first[qrand() % (i+1)]);
+        qSwap(first[i],first[qrand.generate() % (i+1)]);
     }
 }
 
diff --git a/tests/mem_eventmodel/mem_eventmodel.cpp b/tests/mem_eventmodel/mem_eventmodel.cpp
index 499145d..1b50fa2 100644
--- a/tests/mem_eventmodel/mem_eventmodel.cpp
+++ b/tests/mem_eventmodel/mem_eventmodel.cpp
@@ -37,7 +37,7 @@ Group group;
 #define WAIT_TIMEOUT 30000
 #define CALM_TIMEOUT 500
 
-#define MALLINFO_DUMP(s) {struct mallinfo m = mallinfo();qDebug() << "MALLINFO" << (s) << m.arena << m.uordblks << m.fordblks;}
+#define MALLINFO_DUMP(s) {struct mallinfo2 m = mallinfo2();qDebug() << "MALLINFO" << (s) << m.arena << m.uordblks << m.fordblks;}
 
 static void waitWithDeletes(int msec)
 {
@@ -125,7 +125,7 @@ void MemEventModelTest::addEvents()
 
         waitWithDeletes(100);
         MALLINFO_DUMP("query done");
-        struct mallinfo m = mallinfo();
+        struct mallinfo2 m = mallinfo2();
 
         if (i >= 50)
             mem += m.uordblks - lastMem;
diff --git a/tests/perf_callmodel/callmodelperftest.cpp b/tests/perf_callmodel/callmodelperftest.cpp
index 2f6328b..c838a3c 100644
--- a/tests/perf_callmodel/callmodelperftest.cpp
+++ b/tests/perf_callmodel/callmodelperftest.cpp
@@ -40,7 +40,7 @@ void CallModelPerfTest::initTestCase()
         logFile = 0;
     }
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void CallModelPerfTest::init()
@@ -103,6 +103,7 @@ void CallModelPerfTest::getEvents()
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
     QList<QPair<QString, QPair<QString, QString> > > contactDetails;
+    QRandomGenerator qrand;
 
     int ci = remoteUids.count();
     while(ci < contacts) {
diff --git a/tests/perf_conversationmodel/conversationmodelperftest.cpp b/tests/perf_conversationmodel/conversationmodelperftest.cpp
index 31b6d06..2650938 100644
--- a/tests/perf_conversationmodel/conversationmodelperftest.cpp
+++ b/tests/perf_conversationmodel/conversationmodelperftest.cpp
@@ -41,7 +41,7 @@ void ConversationModelPerfTest::initTestCase()
         logFile = 0;
     }
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void ConversationModelPerfTest::init()
@@ -90,6 +90,7 @@ void ConversationModelPerfTest::getEvents()
     qRegisterMetaType<QModelIndex>("QModelIndex");
 
     QDateTime startTime = QDateTime::currentDateTime();
+    QRandomGenerator qrand;
 
     cleanupTestGroups();
     cleanupTestEvents();
diff --git a/tests/perf_groupmodel/groupmodelperftest.cpp b/tests/perf_groupmodel/groupmodelperftest.cpp
index a4e6c58..f9f64c8 100644
--- a/tests/perf_groupmodel/groupmodelperftest.cpp
+++ b/tests/perf_groupmodel/groupmodelperftest.cpp
@@ -41,7 +41,7 @@ void GroupModelPerfTest::initTestCase()
         logFile = 0;
     }
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void GroupModelPerfTest::init()
@@ -102,6 +102,7 @@ void GroupModelPerfTest::getGroups()
 
     GroupModel addModel;
     QDateTime when = QDateTime::currentDateTime();
+    QRandomGenerator qrand;
 
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
diff --git a/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp b/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp
index acde7cd..097b19e 100644
--- a/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp
+++ b/tests/perf_recentcontactsmodel/recentcontactsmodelperftest.cpp
@@ -41,7 +41,7 @@ void RecentContactsModelPerfTest::initTestCase()
         logFile = 0;
     }
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void RecentContactsModelPerfTest::init()
@@ -87,6 +87,7 @@ void RecentContactsModelPerfTest::getEvents()
 
     EventModel addModel;
     QDateTime when = QDateTime::currentDateTime();
+    QRandomGenerator qrand;
 
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
diff --git a/tests/performance_tests.xml.in b/tests/performance_tests.xml.in
index 01e0f25..8820b78 100644
--- a/tests/performance_tests.xml.in
+++ b/tests/performance_tests.xml.in
@@ -3,6 +3,34 @@
    <suite name="libcommhistory-qt5-tests-performance" domain="mw">
        <description>libcommhistory tests</description>
 
+<<<<<<< HEAD:tests/performance_tests.xml.in
+=======
+       <set name="libcommhistory-qt5-tests-auto" feature="libcommhistory-qt5">
+           <description>libcommhistory-qt5 auto tests</description>
+           <case name="ut_callmodel" level="Component" type="Functional">
+               <step>@RUN_TEST@ auto ut_callmodel</step>
+           </case>
+           <case name="ut_conversationmodel" level="Component" type="Functional">
+               <step>@RUN_TEST@ auto ut_conversationmodel</step>
+           </case>
+           <case name="ut_eventmodel" level="Component" type="Functional" insignificant="true">
+               <step>@RUN_TEST@ auto ut_eventmodel</step>
+           </case>
+           <case name="ut_groupmodel" level="Component" type="Functional" timeout="180">
+               <step>@RUN_TEST@ auto ut_groupmodel</step>
+           </case>
+           <case name="ut_recentcontactsmodel" level="Component" type="Functional" timeout="180">
+               <step>@RUN_TEST@ auto ut_recentcontactsmodel</step>
+           </case>
+           <case name="ut_recipienteventmodel" level="Component" type="Functional">
+               <step>@RUN_TEST@ auto ut_recipienteventmodel</step>
+           </case>
+           <case name="ut_singleeventmodel" level="Component" type="Functional">
+               <step>@RUN_TEST@ auto ut_singleeventmodel</step>
+           </case>
+       </set>
+
+>>>>>>> 51bb0bc (Fix warnngs and API for new Qt):tests/tests.xml.in
        <set name="libcommhistory-qt5-tests-performance" feature="libcommhistory-qt5">
            <description>libcommhistory-qt5 performance tests</description>
            <case name="perf_callmodel" level="Component" type="Performance" timeout="2500">
diff --git a/tests/profile_callmodel/callmodelprofiletest.cpp b/tests/profile_callmodel/callmodelprofiletest.cpp
index d6be571..aa00609 100644
--- a/tests/profile_callmodel/callmodelprofiletest.cpp
+++ b/tests/profile_callmodel/callmodelprofiletest.cpp
@@ -38,7 +38,7 @@ void CallModelProfileTest::initTestCase()
 
     logFile = 0;
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void CallModelProfileTest::init()
@@ -61,6 +61,7 @@ void CallModelProfileTest::prepare()
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "new contacts";
 
     QList<QPair<QString, QPair<QString, QString> > > contactDetails;
+    QRandomGenerator qrand;
 
     int ci = remoteUids.count();
     while(ci < contacts) {
diff --git a/tests/profile_conversationmodel/conversationmodelprofiletest.cpp b/tests/profile_conversationmodel/conversationmodelprofiletest.cpp
index 72818b2..00ec5b6 100644
--- a/tests/profile_conversationmodel/conversationmodelprofiletest.cpp
+++ b/tests/profile_conversationmodel/conversationmodelprofiletest.cpp
@@ -39,7 +39,7 @@ void ConversationModelProfileTest::initTestCase()
 
     logFile = 0;
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void ConversationModelProfileTest::init()
@@ -58,6 +58,7 @@ void ConversationModelProfileTest::prepare()
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
     QList<QPair<QString, QPair<QString, QString> > > contactDetails;
+    QRandomGenerator qrand;
 
     int ci = remoteUids.count();
     while(ci < contacts) {
diff --git a/tests/profile_groupmodel/groupmodelprofiletest.cpp b/tests/profile_groupmodel/groupmodelprofiletest.cpp
index 19745a1..3e2b1d7 100644
--- a/tests/profile_groupmodel/groupmodelprofiletest.cpp
+++ b/tests/profile_groupmodel/groupmodelprofiletest.cpp
@@ -37,7 +37,7 @@ void GroupModelProfileTest::initTestCase()
 
     logFile = 0;
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void GroupModelProfileTest::init()
@@ -57,6 +57,7 @@ void GroupModelProfileTest::prepare()
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
     QList<QPair<QString, QPair<QString, QString> > > contactDetails;
+    QRandomGenerator qrand;
 
     int ci = remoteUids.count();
     while(ci < contacts) {
diff --git a/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp b/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp
index 84f3b92..1f44ce8 100644
--- a/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp
+++ b/tests/profile_recentcontactsmodel/recentcontactsmodelprofiletest.cpp
@@ -37,7 +37,7 @@ void RecentContactsModelProfileTest::initTestCase()
 
     logFile = 0;
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator( QDateTime::currentDateTime().toTime_t() );
 }
 
 void RecentContactsModelProfileTest::init()
@@ -60,6 +60,7 @@ void RecentContactsModelProfileTest::prepare()
     qDebug() << Q_FUNC_INFO << "- Creating" << contacts << "contacts";
 
     QList<QPair<QString, QPair<QString, QString> > > contactDetails;
+    QRandomGenerator qrand;
 
     int ci = remoteUids.count();
     while(ci < contacts) {
diff --git a/tests/ut_callmodel/callmodeltest.cpp b/tests/ut_callmodel/callmodeltest.cpp
index 6163e15..f6e4db4 100644
--- a/tests/ut_callmodel/callmodeltest.cpp
+++ b/tests/ut_callmodel/callmodeltest.cpp
@@ -59,7 +59,7 @@ void CallModelTest::initTestCase()
     initTestDatabase();
     QVERIFY( QDBusConnection::sessionBus().isConnected() );
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator qrand( QDateTime::currentDateTime().toTime_t() );
 
     Group group1, group2;
     addTestGroups( group1, group2 );
diff --git a/tests/ut_conversationmodel/conversationmodeltest.cpp b/tests/ut_conversationmodel/conversationmodeltest.cpp
index 137d97d..9d512c8 100644
--- a/tests/ut_conversationmodel/conversationmodeltest.cpp
+++ b/tests/ut_conversationmodel/conversationmodeltest.cpp
@@ -45,7 +45,7 @@ void ConversationModelTest::initTestCase()
 
     loop = new QEventLoop(this);
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
 
     addTestGroups(group1, group2);
 
diff --git a/tests/ut_eventmodel/eventmodeltest.cpp b/tests/ut_eventmodel/eventmodeltest.cpp
index 3ae9e8a..0388010 100644
--- a/tests/ut_eventmodel/eventmodeltest.cpp
+++ b/tests/ut_eventmodel/eventmodeltest.cpp
@@ -60,7 +60,7 @@ void EventModelTest::initTestCase()
 {
     initTestDatabase();
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
 
     new Adaptor(this);
     QVERIFY(QDBusConnection::sessionBus().registerObject(
@@ -997,9 +997,9 @@ void EventModelTest::testCcBcc()
     Event e;
     QVERIFY(model.databaseIO().getEvent(event.id(), e));
     QVERIFY(compareEvents(event, e));
-    QCOMPARE(e.ccList().toSet(), ccList.toSet());
-    QCOMPARE(e.bccList().toSet(), bccList.toSet());
-    QCOMPARE(e.toList().toSet(), toList.toSet());
+    QCOMPARE(QSet<QString>(e.ccList().begin(), e.ccList().end()), QSet<QString>(ccList.begin(), ccList.end()));
+    QCOMPARE(QSet<QString>(e.bccList().begin(),e.bccList().end()), QSet<QString>(bccList.begin(), bccList.end()));
+    QCOMPARE(QSet<QString>(e.toList().begin(),e.toList().end()), QSet<QString>(toList.begin(), toList.end()));
 
     event.resetModifiedProperties();
     ccList.clear();
@@ -1020,9 +1020,9 @@ void EventModelTest::testCcBcc()
 
     QVERIFY(model.databaseIO().getEvent(event.id(), e));
     QVERIFY(compareEvents(event, e));
-    QCOMPARE(e.ccList().toSet(), ccList.toSet());
-    QCOMPARE(e.bccList().toSet(), bccList.toSet());
-    QCOMPARE(e.toList().toSet(), toList.toSet());
+    QCOMPARE(QSet<QString>(e.ccList().begin(), e.ccList().end()), QSet<QString>(ccList.begin(), ccList.end()));
+    QCOMPARE(QSet<QString>(e.bccList().begin(),e.bccList().end()), QSet<QString>(bccList.begin(), bccList.end()));
+    QCOMPARE(QSet<QString>(e.toList().begin(),e.toList().end()), QSet<QString>(toList.begin(), toList.end()));
 
     event.resetModifiedProperties();
     ccList.clear();
diff --git a/tests/ut_groupmodel/groupmodeltest.cpp b/tests/ut_groupmodel/groupmodeltest.cpp
index 48b8f71..64f91d3 100644
--- a/tests/ut_groupmodel/groupmodeltest.cpp
+++ b/tests/ut_groupmodel/groupmodeltest.cpp
@@ -108,7 +108,7 @@ void GroupModelTest::initTestCase()
 
     loop = new QEventLoop(this);
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
 }
 
 void GroupModelTest::addInitialTestGroups()
@@ -706,9 +706,9 @@ void GroupModelTest::streamingQuery()
 
     QTRY_COMPARE(modelReady.count(), 1);
     QVERIFY(!streamModel.canFetchMore(QModelIndex()));
-    QCOMPARE(idsOrig.toSet().size(), idsOrig.size());
-    QCOMPARE(idsStream.toSet().size(), idsStream.size());
-    QVERIFY(idsOrig.toSet() == idsStream.toSet());
+    QCOMPARE(QSet<int>(idsOrig.begin(), idsOrig.end()).size(), idsOrig.size());
+    QCOMPARE(QSet<int>(idsStream.begin(), idsStream.end()).size(), idsStream.size());
+    QVERIFY(QSet<int>(idsOrig.begin(), idsOrig.end()) == QSet<int>(idsStream.begin(), idsStream.end()));
 
     modelThread.quit();
     modelThread.wait(5000);
@@ -969,6 +969,8 @@ void GroupModelTest::resolveContact()
     QSignalSpy groupDataChanged(&groupModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)));
     QSignalSpy groupsCommitted(&groupModel, SIGNAL(groupsCommitted(QList<int>,bool)));
 
+    QRandomGenerator qrand;
+
     QString phoneNumber = QString().setNum(qrand() % 10000000);
     QString contactName = QString("Test Contact 123");
     int contactId = addTestContact(contactName, phoneNumber, RING_ACCOUNT, &contactChangeListener);
diff --git a/tests/ut_recentcontactsmodel/recentcontactsmodeltest.cpp b/tests/ut_recentcontactsmodel/recentcontactsmodeltest.cpp
index a0d2286..85cea78 100644
--- a/tests/ut_recentcontactsmodel/recentcontactsmodeltest.cpp
+++ b/tests/ut_recentcontactsmodel/recentcontactsmodeltest.cpp
@@ -136,7 +136,7 @@ void RecentContactsModelTest::initTestCase()
     QVERIFY(QDBusConnection::sessionBus().isConnected());
     ContactChangeListener contactChangeListener;
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator qsrand(QDateTime::currentDateTime().toTime_t());
 
     addTestGroups( group1, group2 );
 
diff --git a/tests/ut_recipienteventmodel/recipienteventmodeltest.cpp b/tests/ut_recipienteventmodel/recipienteventmodeltest.cpp
index 208ca03..83a59dc 100644
--- a/tests/ut_recipienteventmodel/recipienteventmodeltest.cpp
+++ b/tests/ut_recipienteventmodel/recipienteventmodeltest.cpp
@@ -36,7 +36,7 @@ void RecipientEventModelTest::initTestCase()
 {
     initTestDatabase();
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator(QDateTime::currentDateTime().toTime_t());
 }
 
 void RecipientEventModelTest::cleanupTestCase()
diff --git a/tests/ut_singleeventmodel/singleeventmodeltest.cpp b/tests/ut_singleeventmodel/singleeventmodeltest.cpp
index 7383c16..1eaf028 100644
--- a/tests/ut_singleeventmodel/singleeventmodeltest.cpp
+++ b/tests/ut_singleeventmodel/singleeventmodeltest.cpp
@@ -20,7 +20,7 @@ void SingleEventModelTest::initTestCase()
 {
     initTestDatabase();
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator(QDateTime::currentDateTime().toTime_t());
 
     addTestGroups(group1, group2);
 }
diff --git a/tools/commhistory-tool.cpp b/tools/commhistory-tool.cpp
index cd65376..fb78e11 100644
--- a/tools/commhistory-tool.cpp
+++ b/tools/commhistory-tool.cpp
@@ -268,7 +268,7 @@ int doAdd(const QStringList &arguments, const QVariantMap &options)
     if (options.contains("-out"))
         direction = Event::Outbound;
 
-    qsrand(QDateTime::currentDateTime().toTime_t());
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
     bool randomRemote = true;
     if (arguments.count() > 3) {
         remoteUid = arguments.at(3);
@@ -281,7 +281,7 @@ int doAdd(const QStringList &arguments, const QVariantMap &options)
         Event e;
 
         if (direction == Event::UnknownDirection)
-            e.setDirection((Event::EventDirection)((qrand() & 1) + 1));
+            e.setDirection((Event::EventDirection)((qrand.generate() & 1) + 1));
         else
             e.setDirection(direction);
 
@@ -289,20 +289,20 @@ int doAdd(const QStringList &arguments, const QVariantMap &options)
         {
             e.setType(Event::MMSEvent);
             e.setLocalUid(localUid);
-            e.setSubject(mmsSubject[qrand() % numMmsSubjects]);
+            e.setSubject(mmsSubject[qrand.generate() % numMmsSubjects]);
             e.setMessageToken(QUuid::createUuid().toString());
 
-            if(e.direction() == Event::Outbound || qrand() % 2 == 0)
+            if(e.direction() == Event::Outbound || qrand.generate() % 2 == 0)
             {
-                if(qrand() % 2 == 0)
+                if(qrand.generate() % 2 == 0)
                     e.setCcList(QStringList() << "111111" << "222222" << "iam@cc.list.com");
-                if(qrand() % 2 == 0)
+                if(qrand.generate() % 2 == 0)
                     e.setBccList(QStringList() << "33333" << "44444" << "iam@bcc.list.com");
 
                 QList<MessagePart> parts;
 
                 bool smilAdded = false;
-                if (qrand() % 2 == 0)
+                if (qrand.generate() % 2 == 0)
                 {
                     MessagePart part1;
                     part1.setContentType("application/smil");
@@ -313,7 +313,7 @@ int doAdd(const QStringList &arguments, const QVariantMap &options)
                 part2.setContentId("text_slide1");
                 part2.setContentType("text/plain");
                 parts << part2;
-                if (smilAdded || qrand() % 3 == 0)
+                if (smilAdded || qrand.generate() % 3 == 0)
                 {
                     MessagePart part3;
                     part3.setContentId("catphoto");
@@ -343,15 +343,15 @@ int doAdd(const QStringList &arguments, const QVariantMap &options)
         } else {
             e.setIsRead(false);
         }
-        e.setBytesReceived(qrand() % 1024);
+        e.setBytesReceived(qrand.generate() % 1024);
         e.setGroupId(groupId);
         if (randomRemote) {
-            e.setRecipients(Recipient(e.localUid(), remoteUids[qrand() % numRemoteUids]));
+            e.setRecipients(Recipient(e.localUid(), remoteUids[qrand.generate() % numRemoteUids]));
         } else {
             e.setRecipients(Recipient(e.localUid(), remoteUid));
         }
 
-        e.setFreeText(messageText.isNull() ? textContent[qrand() % numTextContents] : messageText);
+        e.setFreeText(messageText.isNull() ? textContent[qrand.generate() % numTextContents] : messageText);
 
         events.append(e);
     }
@@ -372,7 +372,7 @@ int doAddCall( const QStringList &arguments, const QVariantMap &options )
 {
     Q_UNUSED( options )
 
-    qsrand( QDateTime::currentDateTime().toTime_t() );
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
 
     int count = 1;
     if (options.contains("-n")) {
@@ -407,7 +407,7 @@ int doAddCall( const QStringList &arguments, const QVariantMap &options )
         }
 
         if (callType == -1)
-            callType = qrand() % 3;
+            callType = qrand.generate() % 3;
 
         Event::EventDirection direction = Event::Inbound;
         bool isMissed = false;
@@ -476,6 +476,8 @@ int doAddClass0(const QStringList &arguments, const QVariantMap &options)
     Q_UNUSED(arguments)
     Q_UNUSED(options)
 
+    QRandomGenerator qrand(QDateTime::currentDateTime().toTime_t());
+
     QStringList sosRemoteUids;
     sosRemoteUids << "112"
                   << "911"
@@ -491,10 +493,10 @@ int doAddClass0(const QStringList &arguments, const QVariantMap &options)
     Event e;
 
     e.setLocalUid(RING_ACCOUNT);
-    e.setRecipients(Recipient(e.localUid(), sosRemoteUids.at(qrand() % sosRemoteUids.count())));
+    e.setRecipients(Recipient(e.localUid(), sosRemoteUids.at(qrand.generate() % sosRemoteUids.count())));
     e.setDirection(Event::Inbound);
     e.setType(Event::ClassZeroSMSEvent);
-    e.setFreeText(sosMessages.at(qrand() % sosMessages.count()));
+    e.setFreeText(sosMessages.at(qrand.generate() % sosMessages.count()));
     QDateTime now = QDateTime::currentDateTime();
     e.setStartTime(now);
     e.setEndTime(now);
@@ -1177,7 +1179,7 @@ int doJsonImport(const QStringList &arguments, const QVariantMap &options)
             return -1;
         }
 
-        dateOffset = endTime.secsTo(QDateTime(QDate::currentDate()));
+        dateOffset = endTime.secsTo(QDate::currentDate().startOfDay());
     }
 
     bool ok = true;
-- 
2.32.0

