Skip to content

Commit

Permalink
Merge branch 'jb52802-tests' into 'master'
Browse files Browse the repository at this point in the history
Jb52802 tests

See merge request mer-core/libcommhistory!52
  • Loading branch information
blam committed Mar 19, 2021
2 parents 26b4280 + c526296 commit 91a353c
Show file tree
Hide file tree
Showing 57 changed files with 217 additions and 344 deletions.
28 changes: 6 additions & 22 deletions rpm/libcommhistory-qt5.spec
Expand Up @@ -21,18 +21,12 @@ BuildRequires: libphonenumber-devel
%description
Library for accessing the communications (IM, SMS and call) history database.

%package unit-tests
Summary: Unit Test files for libcommhistory
%package tests
Summary: Test files for libcommhistory
Requires: blts-tools

%description unit-tests
Unit Test files for libcommhistory

%package performance-tests
Summary: Performance Test files for libcommhistory

%description performance-tests
Performance Test files for libcommhistory
%description tests
Test files for libcommhistory

%package tools
Summary: Command line tools for libcommhistory
Expand Down Expand Up @@ -84,12 +78,6 @@ install -m 644 -p %{SOURCE1} %{buildroot}%{_datadir}/mapplauncherd/privileges.d
%postun
/sbin/ldconfig

%post unit-tests
for n in ut_recentcontactsmodel ut_callmodel; do
pathname=/opt/tests/libcommhistory-qt5-unit-tests/$n
chgrp privileged $pathname && chmod g+s $pathname
done

%files
%defattr(-,root,root,-)
%{_libdir}/libcommhistory-qt5.so*
Expand All @@ -104,13 +92,9 @@ done
%defattr(-,root,root,-)
%{_libdir}/qt5/qml/org/nemomobile/commhistory

%files unit-tests
%defattr(-,root,root,-)
/opt/tests/libcommhistory-qt5-unit-tests

%files performance-tests
%files tests
%defattr(-,root,root,-)
/opt/tests/libcommhistory-qt5-performance-tests
/opt/tests/libcommhistory-qt5

%files devel
%defattr(-,root,root,-)
Expand Down
12 changes: 10 additions & 2 deletions src/commhistorydatabase.cpp
Expand Up @@ -28,12 +28,15 @@
#include <QSqlQuery>
#include <QDebug>
#include <QStandardPaths>
#include <QCoreApplication>

// Appended to GenericDataLocation (or a hardcoded equivalent on Qt4)
#define COMMHISTORY_DATABASE_DIR "/commhistory/"
#define COMMHISTORY_DATABASE_NAME "commhistory.db"
#define COMMHISTORY_DATA_DIR COMMHISTORY_DATABASE_DIR "data/"

static QString db_root_dir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);

static const char *db_setup[] = {
"PRAGMA temp_store = MEMORY",
"PRAGMA journal_mode = WAL",
Expand Down Expand Up @@ -345,9 +348,14 @@ QSqlQuery CommHistoryDatabase::prepare(const char *statement, const QSqlDatabase
return query;
}

void CommHistoryDatabasePath::setRootDir(const QString &rootDir)
{
db_root_dir = rootDir;
}

QString CommHistoryDatabasePath::databaseDir()
{
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String(COMMHISTORY_DATABASE_DIR);
return db_root_dir + QLatin1String(COMMHISTORY_DATABASE_DIR);
}

QString CommHistoryDatabasePath::databaseFile()
Expand All @@ -357,7 +365,7 @@ QString CommHistoryDatabasePath::databaseFile()

QString CommHistoryDatabasePath::dataDir()
{
return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral(COMMHISTORY_DATA_DIR);
return db_root_dir + QStringLiteral(COMMHISTORY_DATA_DIR);
}

QString CommHistoryDatabasePath::dataDir(int id)
Expand Down
2 changes: 2 additions & 0 deletions src/commhistorydatabasepath.h
Expand Up @@ -32,6 +32,8 @@ class LIBCOMMHISTORY_EXPORT CommHistoryDatabasePath
static QString databaseFile();
static QString dataDir();
static QString dataDir(int id);

static void setRootDir(const QString &rootDir);
};

#endif
49 changes: 23 additions & 26 deletions tests/common.cpp
Expand Up @@ -56,6 +56,7 @@
#include "common.h"
#include "commonutils.h"
#include "contactlistener.h"
#include "commhistorydatabasepath.h"

QTCONTACTS_USE_NAMESPACE

Expand Down Expand Up @@ -142,6 +143,13 @@ quint64 idleTicks = 0;
QSet<QContactId> addedContactIds;
QSet<int> addedEventIds;

void initTestDatabase()
{
deleteAll();

CommHistoryDatabasePath::setRootDir(TEST_DATABASE_DIR);
}

int addTestEvent(EventModel &model,
Event::EventType type,
Event::EventDirection direction,
Expand Down Expand Up @@ -230,7 +238,6 @@ int addTestContact(const QString &name, const QString &remoteUid, const QString

foreach (const QContactRelationship &relationship, manager()->relationships(QContactRelationship::Aggregates(), contact.id(), QContactRelationship::Second)) {
const QContactId &aggId = relationship.first();
qDebug() << "********** contact id" << aggId;
addedContactIds.insert(aggId);
return internalContactId(aggId);
}
Expand Down Expand Up @@ -265,7 +272,6 @@ QList<int> addTestContacts(const QList<QPair<QString, QPair<QString, QString> >
foreach (const QContactRelationship &relationship, manager()->relationships(QContactRelationship::Aggregates())) {
if (constituentIds.contains(relationship.second())) {
const QContactId &aggId = relationship.first();
qDebug() << "********** contact id" << aggId;
addedContactIds.insert(aggId);
ids.append(internalContactId(aggId));
}
Expand Down Expand Up @@ -371,29 +377,6 @@ void deleteTestContact(int id)
addedContactIds.remove(contactId);
}

void cleanUpTestContacts()
{
if (!addedContactIds.isEmpty()) {
QString aggregatesType = QContactRelationship::Aggregates();

const QList<QContactId> contactIdsToRemove = addedContactIds.toList();
QList<QContact> contactsToRemove;
for (const QContactId &contactId : addedContactIds) {
const QContactId localId = localContactForAggregate(contactId);
QContact localContact = manager()->contact(localId);
if (!localContact.isEmpty()) {
contactsToRemove.append(localContact);
}
}

if (!SeasideCache::removeContacts(contactsToRemove)) {
qWarning() << "Unable to remove test contacts:" << addedContactIds;
}

addedContactIds.clear();
}
}

void cleanupTestGroups()
{
GroupModel groupModel;
Expand Down Expand Up @@ -505,9 +488,20 @@ void deleteAll()
{
qDebug() << Q_FUNC_INFO << "- Deleting all";

cleanUpTestContacts();
cleanupTestGroups();
cleanupTestEvents();

if (!QDir(TEST_DATABASE_DIR).removeRecursively()) {
qWarning() << "Unable to remove test database directory:" << TEST_DATABASE_DIR;
}

if (!qgetenv("LIBCONTACTS_TEST_MODE").isEmpty()) {
QString contactsDbDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/system/privileged/Contacts/qtcontacts-sqlite-test");
if (!QDir(contactsDbDir).removeRecursively()) {
qWarning() << "Unable to remove test contacts database directory:" << contactsDbDir;
}
}
}

QString randomMessage(int words)
Expand Down Expand Up @@ -585,6 +579,9 @@ void waitForIdle(int pollInterval) {

bool waitSignal(QSignalSpy &spy, int msec)
{
if (!spy.isEmpty()) {
return true;
}
QTime timer;
timer.start();
while (timer.elapsed() < msec && spy.isEmpty()) {
Expand Down
7 changes: 6 additions & 1 deletion tests/common.h
Expand Up @@ -30,6 +30,7 @@

#include <QFile>
#include <QSignalSpy>
#include <QStandardPaths>

#include <iterator>

Expand All @@ -51,6 +52,9 @@ void waitForSignal(QObject *object, const char *signal);

using namespace CommHistory;

const QString TEST_DATABASE_DIR = QStandardPaths::writableLocation(QStandardPaths::TempLocation)
+ "/tests";

const QString ACCOUNT1 = "/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0";
const QString ACCOUNT2 = "/org/freedesktop/Telepathy/Account/gabble/jabber/dut2_40localhost0";

Expand All @@ -65,6 +69,8 @@ const int WAIT_SIGNAL_TIMEOUT = 5000;
/* Duration of phone calls added with addTestEvent */
const int TESTCALL_SECS = 100;

void initTestDatabase();

int addTestEvent(EventModel &model,
Event::EventType type,
Event::EventDirection direction,
Expand All @@ -87,7 +93,6 @@ bool addTestContactAddress(int contactId, const QString &remoteUid, const QStrin
void modifyTestContact(int id, const QString &name, bool favorite = false);
void deleteTestContact(int id);
QContactId localContactForAggregate(const QContactId &contactId);
void cleanUpTestContacts();
void cleanupTestGroups();
void cleanupTestEvents();
bool compareEvents(Event &e1, Event &e2);
Expand Down
66 changes: 0 additions & 66 deletions tests/do_tests_xml.sh

This file was deleted.

17 changes: 10 additions & 7 deletions tests/mem_eventmodel/mem_eventmodel.cpp
Expand Up @@ -40,6 +40,8 @@ Group group;

void MemEventModelTest::initTestCase()
{
initTestDatabase();

MALLINFO_DUMP("INIT");

addTestGroup(group, "/org/freedesktop/Telepathy/Account/gabble/jabber/dut_40localhost0", "td@localhost");
Expand All @@ -66,9 +68,9 @@ void MemEventModelTest::addEvent()
e1.setRecipients(Recipient(e1.localUid(), "td@localhost"));
e1.setFreeText("addEvents 1");

QVERIFY(model->addEvent(e1));
QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool)));

QVERIFY(model->addEvent(e1));
QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT));

QTest::qWait(CALM_TIMEOUT);
Expand Down Expand Up @@ -101,8 +103,8 @@ void MemEventModelTest::addEvents()
e1.setRecipients(Recipient(e1.localUid(), "td@localhost"));
e1.setFreeText(QString("addEvents %1").arg(i));

QVERIFY(model->addEvent(e1));
QSignalSpy eventsCommitted(model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool)));
QVERIFY(model->addEvent(e1));

QVERIFY(waitSignal(eventsCommitted, WAIT_TIMEOUT));
waitWithDeletes(100);
Expand Down Expand Up @@ -197,19 +199,20 @@ void MemEventModelTest::callSetFilter()
QSignalSpy ready(model, SIGNAL(modelReady(bool)));

model->getEvents();
ready.clear();
QVERIFY(waitSignal(ready, WAIT_TIMEOUT));

int expectedReadyCount = 1;
QTRY_COMPARE(ready.count(), expectedReadyCount);
expectedReadyCount++;

for(int i = 0; i < 5; i++) {

if (i&1)
model->setFilter(CallModel::SortByTime, CommHistory::CallEvent::MissedCallType);
else
model->setFilter(CallModel::SortByContact, CommHistory::CallEvent::UnknownCallType);
ready.clear();
QVERIFY(waitSignal(ready, WAIT_TIMEOUT));
QTest::qWait(100);

QTRY_COMPARE(ready.count(), expectedReadyCount);
expectedReadyCount++;
MALLINFO_DUMP("get");
}
delete model;
Expand Down
1 change: 0 additions & 1 deletion tests/mem_eventmodel/mem_eventmodel.pro
Expand Up @@ -25,7 +25,6 @@ include( ../../common-vars.pri )
include( ../tests.pri )

TARGET = mem_eventmodel
DESTDIR = ../bin
QT -= gui

SOURCES += mem_eventmodel.cpp
Expand Down
4 changes: 2 additions & 2 deletions tests/perf_callmodel/callmodelperftest.cpp
Expand Up @@ -32,15 +32,15 @@ using namespace CommHistory;

void CallModelPerfTest::initTestCase()
{
initTestDatabase();

logFile = new QFile("libcommhistory-performance-test.log");
if(!logFile->open(QIODevice::Append)) {
qDebug() << "!!!! Failed to open log file !!!!";
logFile = 0;
}

qsrand( QDateTime::currentDateTime().toTime_t() );

deleteAll();
}

void CallModelPerfTest::init()
Expand Down
1 change: 0 additions & 1 deletion tests/perf_callmodel/perf_callmodel.pro
Expand Up @@ -25,7 +25,6 @@ include( ../../common-vars.pri )
include( ../performance_tests.pri )

TARGET = perf_callmodel
DESTDIR = ../perf_bin
QT -= gui
SOURCES += callmodelperftest.cpp
HEADERS += callmodelperftest.h
Expand Down
5 changes: 0 additions & 5 deletions tests/perf_callmodel/test_set.xml

This file was deleted.

0 comments on commit 91a353c

Please sign in to comment.