Skip to content

Commit

Permalink
[sociald] Add unit test framework. Contributes to JB#6804
Browse files Browse the repository at this point in the history
This commit adds a unit test framework for sociald, and adds a unit
test for Facebook friend synchronisation.

Contributes to JB#6804
  • Loading branch information
Chris Adams authored and Antti Seppälä committed Jan 2, 2014
1 parent ba372fc commit cedfa92
Show file tree
Hide file tree
Showing 20 changed files with 1,299 additions and 104 deletions.
12 changes: 12 additions & 0 deletions rpm/sociald.spec
Expand Up @@ -84,6 +84,18 @@ Translation source for sociald
%{_datadir}/translations/source/lipstick-jolla-home-facebook.ts
%{_datadir}/translations/source/lipstick-jolla-home-twitter.ts

%package tests
Summary: Automatable tests for sociald
License: TBD
Group: System/Applications

%description tests
Automatable tests for sociald

%files tests
%defattr(-,root,root,-)
/opt/tests/sociald/*

%prep
%setup -q -n %{name}-%{version}

Expand Down
3 changes: 2 additions & 1 deletion sociald.pro
@@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS = src
SUBDIRS = src tests
tests.depends = src

OTHER_FILES += rpm/sociald.spec
108 changes: 108 additions & 0 deletions src/common.pri
@@ -0,0 +1,108 @@
CONFIG += link_pkgconfig
CONFIG += meegotouchevents-qt5
PKGCONFIG += Qt5Contacts \
libsailfishkeyprovider \
sailfishaccounts \
libsignon-qt5 \
nemonotifications-qt5 \
buteosyncfw5 \
libmkcal-qt5 \
libkcalcoren-qt5 \
socialcache

DEFINES *= USING_QTPIM
DEFINES *= BEGIN_CONTACTS_NAMESPACE=QT_BEGIN_NAMESPACE_CONTACTS
DEFINES *= END_CONTACTS_NAMESPACE=QT_END_NAMESPACE_CONTACTS
DEFINES *= USE_CONTACTS_NAMESPACE=QTCONTACTS_USE_NAMESPACE

QT += \
network \
dbus \
sql

include($$PWD/facebook/facebook.pri)
include($$PWD/twitter/twitter.pri)
include($$PWD/google/google.pri)

# the unit tests need to provide a custom QNAM and uses a different database directory
HEADERS += $$PWD/socialdnetworkaccessmanager_p.h
!contains(DEFINES, 'SOCIALD_TEST_DEFINE') {
SOURCES += $$PWD/socialdnetworkaccessmanager_p.cpp
DEFINES += 'PRIVILEGED_DATA_DIR=\'\"/home/nemo/.local/share/system/privileged/\"\''
}

DEFINES += 'SYNC_DATABASE_DIR=\'\"Sync\"\''
DEFINES += 'SOCIALD_SYNC_DATABASE_NAME=\'\"sociald.db\"\''

HEADERS += \
$$PWD/constants_p.h \
$$PWD/buteosocialsync.h \
$$PWD/socialnetworksyncadaptor.h \
$$PWD/syncservice.h \
$$PWD/syncservice_p.h \
$$PWD/trace.h \
$$PWD/internaldatabasemanipulationinterface.h

SOURCES += \
$$PWD/buteosocialsync.cpp \
$$PWD/socialnetworksyncadaptor.cpp \
$$PWD/syncservice.cpp \
$$PWD/internaldatabasemanipulationinterface.cpp

#This causes issues with the unit tests
#MOC_DIR = $$PWD/../.moc
#OBJECTS_DIR = $$PWD/../.obj

target.path += /usr/lib/buteo-plugins-qt5
client.path = /etc/buteo/profiles/client
client.files = xml/sociald.xml

OTHER_FILES += shared_eventfeed.files

# lipstick event feed subview shared components
shared_eventfeed.files = \
$$PWD/eventfeed/SocialAvatar.qml \
$$PWD/eventfeed/SocialBody.qml \
$$PWD/eventfeed/SocialButton.qml \
$$PWD/eventfeed/SocialContent.qml \
$$PWD/eventfeed/SocialMediaRow.qml \
$$PWD/eventfeed/SocialImage.qml \
$$PWD/eventfeed/SocialInfoLabel.qml \
$$PWD/eventfeed/SocialComment.qml \
$$PWD/eventfeed/SocialReplyField.qml \
$$PWD/eventfeed/SocialAccountPullDownMenu.qml \
$$PWD/eventfeed/SocialAccountPage.qml \
$$PWD/eventfeed/SocialStatusUpdater.qml \
$$PWD/eventfeed/SocialMediaFeedPage.qml \
$$PWD/eventfeed/SocialMediaFeedItem.qml \
$$PWD/eventfeed/SocialMediaAccountDelegate.qml \
$$PWD/eventfeed/SocialMediaIndicator.qml \
$$PWD/eventfeed/SocialMediaPreviewRow.qml
shared_eventfeed.path = /usr/share/lipstick/eventfeed/shared/

# translations
TS_FILE = $$OUT_PWD/sociald.ts
EE_QM = $$OUT_PWD/sociald_eng_en.qm
ts.commands += lupdate -no-recursive $$PWD/facebook $$PWD/twitter -ts $$TS_FILE
ts.CONFIG += no_check_exist
ts.output = $$TS_FILE
ts.input = .
ts_install.files = $$TS_FILE
ts_install.path = /usr/share/translations/source
ts_install.CONFIG += no_check_exist

# should add -markuntranslated "-" when proper translations are in place (or for testing)
engineering_english.commands += lrelease -idbased $$TS_FILE -qm $$EE_QM
engineering_english.CONFIG += no_check_exist
engineering_english.depends = ts
engineering_english.input = $$TS_FILE
engineering_english.output = $$EE_QM
engineering_english_install.path = /usr/share/translations
engineering_english_install.files = $$EE_QM
engineering_english_install.CONFIG += no_check_exist

QMAKE_EXTRA_TARGETS += ts engineering_english
PRE_TARGETDEPS += ts engineering_english

INSTALLS += target client shared_eventfeed ts_install engineering_english_install

23 changes: 23 additions & 0 deletions src/socialdnetworkaccessmanager_p.cpp
@@ -0,0 +1,23 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
****************************************************************************/

#include "socialdnetworkaccessmanager_p.h"

/* The default implementation is just a normal QNetworkAccessManager */

SocialdNetworkAccessManager::SocialdNetworkAccessManager(QObject *parent)
: QNetworkAccessManager(parent)
{
}

QNetworkReply *SocialdNetworkAccessManager::createRequest(
QNetworkAccessManager::Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData)
{
return QNetworkAccessManager::createRequest(op, req, outgoingData);
}
26 changes: 26 additions & 0 deletions src/socialdnetworkaccessmanager_p.h
@@ -0,0 +1,26 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
****************************************************************************/

#ifndef SOCIALD_QNAMFACTORY_P_H
#define SOCIALD_QNAMFACTORY_P_H

#include <QNetworkAccessManager>

class SocialdNetworkAccessManager : public QNetworkAccessManager
{
Q_OBJECT

public:
SocialdNetworkAccessManager(QObject *parent = 0);

protected:
QNetworkReply *createRequest(QNetworkAccessManager::Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData = 0);
};

#endif
3 changes: 2 additions & 1 deletion src/socialnetworksyncadaptor.cpp
Expand Up @@ -7,6 +7,7 @@

#include "socialnetworksyncadaptor.h"
#include "syncservice.h"
#include "socialdnetworkaccessmanager_p.h"
#include "constants_p.h"
#include "trace.h"

Expand Down Expand Up @@ -55,7 +56,7 @@ SocialNetworkSyncAdaptor::SocialNetworkSyncAdaptor(QString serviceName,
: QObject(parent)
, dataType(dataType)
, accountManager(new AccountManager(this))
, networkAccessManager(new QNetworkAccessManager(this))
, networkAccessManager(new SocialdNetworkAccessManager(this))
, m_syncDb(new SocialNetworkSyncDatabase())
, m_status(SocialNetworkSyncAdaptor::Invalid)
, m_serviceName(serviceName)
Expand Down
104 changes: 2 additions & 102 deletions src/src.pro
Expand Up @@ -2,106 +2,6 @@ TEMPLATE = lib

TARGET = sociald-client
VERSION = 0.0.58
CONFIG += link_pkgconfig plugin

CONFIG += meegotouchevents-qt5
PKGCONFIG += Qt5Contacts \
libsailfishkeyprovider \
sailfishaccounts \
libsignon-qt5 \
nemonotifications-qt5 \
buteosyncfw5 \
libmkcal-qt5 \
libkcalcoren-qt5 \
socialcache

DEFINES *= USING_QTPIM
DEFINES *= BEGIN_CONTACTS_NAMESPACE=QT_BEGIN_NAMESPACE_CONTACTS
DEFINES *= END_CONTACTS_NAMESPACE=QT_END_NAMESPACE_CONTACTS
DEFINES *= USE_CONTACTS_NAMESPACE=QTCONTACTS_USE_NAMESPACE

target.path += /usr/lib/buteo-plugins-qt5

client.path = /etc/buteo/profiles/client
client.files = xml/sociald.xml

QT += \
network \
dbus \
sql

include(facebook/facebook.pri)
include(twitter/twitter.pri)
include(google/google.pri)

DEFINES += 'PRIVILEGED_DATA_DIR=\'\"/home/nemo/.local/share/system/privileged/\"\''
DEFINES += 'SYNC_DATABASE_DIR=\'\"Sync\"\''
DEFINES += 'SOCIALD_SYNC_DATABASE_NAME=\'\"sociald.db\"\''

HEADERS += \
$$PWD/constants_p.h \
$$PWD/buteosocialsync.h \
$$PWD/socialnetworksyncadaptor.h \
$$PWD/syncservice.h \
$$PWD/syncservice_p.h \
$$PWD/trace.h \
$$PWD/internaldatabasemanipulationinterface.h

SOURCES += \
$$PWD/buteosocialsync.cpp \
$$PWD/socialnetworksyncadaptor.cpp \
$$PWD/syncservice.cpp \
$$PWD/internaldatabasemanipulationinterface.cpp

OTHER_FILES += shared_eventfeed.files

MOC_DIR = $$PWD/../.moc
OBJECTS_DIR = $$PWD/../.obj

# lipstick event feed subview shared components
shared_eventfeed.files = \
$$PWD/eventfeed/SocialAvatar.qml \
$$PWD/eventfeed/SocialBody.qml \
$$PWD/eventfeed/SocialButton.qml \
$$PWD/eventfeed/SocialContent.qml \
$$PWD/eventfeed/SocialMediaRow.qml \
$$PWD/eventfeed/SocialImage.qml \
$$PWD/eventfeed/SocialInfoLabel.qml \
$$PWD/eventfeed/SocialComment.qml \
$$PWD/eventfeed/SocialReplyField.qml \
$$PWD/eventfeed/SocialAccountPullDownMenu.qml \
$$PWD/eventfeed/SocialAccountPage.qml \
$$PWD/eventfeed/SocialStatusUpdater.qml \
$$PWD/eventfeed/SocialMediaFeedPage.qml \
$$PWD/eventfeed/SocialMediaFeedItem.qml \
$$PWD/eventfeed/SocialMediaAccountDelegate.qml \
$$PWD/eventfeed/SocialMediaIndicator.qml \
$$PWD/eventfeed/SocialMediaPreviewRow.qml
shared_eventfeed.path = /usr/share/lipstick/eventfeed/shared/

# translations
TS_FILE = $$OUT_PWD/sociald.ts
EE_QM = $$OUT_PWD/sociald_eng_en.qm
ts.commands += lupdate -no-recursive $$PWD/facebook $$PWD/twitter -ts $$TS_FILE
ts.CONFIG += no_check_exist
ts.output = $$TS_FILE
ts.input = .
ts_install.files = $$TS_FILE
ts_install.path = /usr/share/translations/source
ts_install.CONFIG += no_check_exist

# should add -markuntranslated "-" when proper translations are in place (or for testing)
engineering_english.commands += lrelease -idbased $$TS_FILE -qm $$EE_QM
engineering_english.CONFIG += no_check_exist
engineering_english.depends = ts
engineering_english.input = $$TS_FILE
engineering_english.output = $$EE_QM
engineering_english_install.path = /usr/share/translations
engineering_english_install.files = $$EE_QM
engineering_english_install.CONFIG += no_check_exist

QMAKE_EXTRA_TARGETS += ts engineering_english
PRE_TARGETDEPS += ts engineering_english

INSTALLS += target client shared_eventfeed ts_install engineering_english_install
CONFIG += plugin

include(common.pri)
44 changes: 44 additions & 0 deletions tests/networkstubs_p.cpp
@@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Chris Adams <chris.adams@jollamobile.com>
**
****************************************************************************/

#include "networkstubs_p.h"
#include "socialdnetworkaccessmanager_p.h"

#include <QDateTime>
#include <QTimer>

/*
* This implementation overrides the networking classes for testing purposes.
* The unit test for each social network should provide an implementation of
* TestNetworkReply::generateData() in order to return the required data.
*/

SocialdNetworkAccessManager::SocialdNetworkAccessManager(QObject *parent)
: QNetworkAccessManager(parent)
{
}

QNetworkReply *SocialdNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op,
const QNetworkRequest &req,
QIODevice *outgoingData)
{
Q_UNUSED(op)
Q_UNUSED(outgoingData)

QString generator; // TODO: create generator from request, if we want to test different branches.

// construct a test reply, which will contain the expected data and trigger finished()
TestNetworkReply *retn = new TestNetworkReply(this);
retn->setOperation(op);
retn->setRequest(req);
retn->setUrl(req.url());
retn->m_readAllData = TestNetworkReply::generateData(req.url(), generator);
retn->open(QIODevice::ReadOnly);
retn->setFinished(true);
QTimer::singleShot(100, retn, SIGNAL(finished()));
return retn;
}

0 comments on commit cedfa92

Please sign in to comment.