// Situare PHP scripts
const QString UPDATE_LOCATION = "updateLocation.php";
const QString REVERSE_GEO = "reversegeo.php";
+const QString GET_LOCATIONS = "getLocations.php";
// Cookies
const QString COOKIE = "Cookie";
const QString EQUAL_MARK = "=";
const QString UNDERLINE_MARK = "_";
const QString BREAK_MARK = ";";
+const QString OPENING_BRACE_MARK = "{";
// Coordinates
const QString LATITUDE = "lat";
#include "situareservice.h"
#include "situarecommon.h"
#include "../cookiehandler/cookiehandler.h"
+#include "parser.h"
SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
: QObject(parent), m_networkManager(manager)
delete m_networkManager;
}
-void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
- const bool &publish)
+void SituareService::fetchLocations()
{
qDebug() << __PRETTY_FUNCTION__;
m_credentials.sessionKey(), m_credentials.sessionSecret(),
m_credentials.sig(), EN_LOCALE);
-
- QString publishValue;
- if(publish) {
- publishValue = PUBLISH_TRUE;
- }
- else {
- publishValue = PUBLISH_FALSE;
- }
- QString urlParameters = formUrlParameters(coordinates, status, publishValue);
- QUrl url = formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
+ QUrl url = formUrl(SITUARE_URL, GET_LOCATIONS);
sendRequest(url, COOKIE, cookie);
}
sendRequest(url, COOKIE, cookie);
}
+void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
+ const bool &publish)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ CookieHandler cookieHandler;
+
+ QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+ m_credentials.sessionKey(), m_credentials.sessionSecret(),
+ m_credentials.sig(), EN_LOCALE);
+
+
+ QString publishValue;
+ if(publish) {
+ publishValue = PUBLISH_TRUE;
+ }
+ else {
+ publishValue = PUBLISH_FALSE;
+ }
+ QString urlParameters = formUrlParameters(coordinates, status, publishValue);
+ QUrl url = formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
+
+ sendRequest(url, COOKIE, cookie);
+}
+
QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters)
{
qDebug() << __PRETTY_FUNCTION__;
// ToDo: signal UI?
emit error(replyArray);
}
+ else if(replyArray.startsWith(OPENING_BRACE_MARK.toAscii())) {
+ qDebug() << "JSON string";
+ parseUserData(replyArray);
+ }
else {
// no error -> update was successful
// ToDo: signal UI?
qDebug() << __PRETTY_FUNCTION__;
m_credentials = m_facebookAuthentication.loginCredentials();
}
+
+void SituareService::parseUserData(const QByteArray &jsonReply)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QJson::Parser parser;
+ bool ok;
+
+ QVariantMap result = parser.parse (jsonReply, &ok).toMap();
+ if (!ok) {
+
+ qFatal("An error occurred during parsing");
+ exit (1);
+ }
+
+ QList<User *> friendsList;
+
+ QVariant userVariant = result.value("user");
+ QMap<QString, QVariant> userMap = userVariant.toMap();
+
+ QPointF coordinates(userMap["longitude"].toReal(), userMap["latitude"].toReal());
+
+ QUrl imageUrl = userMap["profile_pic"].toUrl();
+
+ User user = User(userMap["address"].toString(), coordinates, userMap["name"].toString(),
+ userMap["note"].toString(), imageUrl, userMap["timestamp"].toString(),
+ true, userMap["uid"].toString());
+
+ foreach (QVariant friendsVariant, result["friends"].toList()) {
+ QMap<QString, QVariant> friendMap = friendsVariant.toMap();
+ QVariant distance = friendMap["distance"];
+ QMap<QString, QVariant> distanceMap = distance.toMap();
+
+ QPointF coordinates(friendMap["longitude"].toReal(), friendMap["latitude"].toReal());
+
+ QUrl imageUrl = friendMap["profile_pic"].toUrl();
+
+ User *user = new User(friendMap["address"].toString(), coordinates, friendMap["name"].toString(),
+ friendMap["note"].toString(), imageUrl, friendMap["timestamp"].toString(),
+ false, friendMap["uid"].toString(), distanceMap["units"].toString(),
+ distanceMap["value"].toDouble());
+
+ friendsList.append(user);
+ }
+ emit userDataChanged(user, friendsList);
+}
#define SITUARESERVICE_H
#include <QObject>
-#include <QPointF>
-#include <QNetworkAccessManager>
-#include <QNetworkRequest>
-#include <QNetworkReply>
-#include <QUrl>
#include "../facebookservice/facebookauthentication.h"
#include "../facebookservice/facebookcredentials.h"
+#include "../user/user.h"
+
+class QNetworkAccessManager;
+class QNetworkReply;
+class QNetworkRequest;
+class QPointF;
+class QUrl;
/**
* @brief SituareService class for communicating with Situare server
~SituareService();
/**
- * @brief Updates location to the Situare server
+ * @brief Retrieves location user and friends information from Situare server
*
- * @param coordinates current cordinates
- * @param status message
- * @param publish publish location on Facebook wall (true/false)
*/
- void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
+ void fetchLocations();
/**
* @brief Translates coordinates to street address via Situare server
*/
void reverseGeo(const QPointF &coordinates);
+ /**
+ * @brief Updates location to the Situare server
+ *
+ * @param coordinates current cordinates
+ * @param status message
+ * @param publish publish location on Facebook wall (true/false)
+ */
+ void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
+
public slots:
/**
*/
void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
+ /**
+ * @brief Parses user and friend data from JSON string
+ *
+ * @param jsonReply JSON string
+ */
+ void parseUserData(const QByteArray &jsonReply);
+
signals:
/**
*/
void error(const QString &error);
+
+ /**
+ * @brief Signals when user data is retrieved
+ *
+ * @param user instance of user
+ * @param friendList list of friends
+ */
+ void userDataChanged(User &user, QList<User *> &friendList); // not final
+
private:
FacebookCredentials m_credentials; ///< handle for FacebookCredentials
QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
+ //QList<User *> m_friendList;
+ //User m_user;
};
#endif // SITUARESERVICE_H
# -------------------------------------------------
TARGET = ../situare
TEMPLATE = app
+INCLUDEPATH += "/home/lampehe-local/Downloads/qjson/src"
+LIBS += "-lqjson"
RESOURCES += images.qrc
SOURCES += main.cpp \
ui/mainwindow.cpp \
ui/pixmap.cpp \
ui/infotab.cpp \
ui/updatelocation/updatelocationdialog.cpp \
- ui/updatelocation/texteditautoresizer.cpp
+ ui/updatelocation/texteditautoresizer.cpp \
+ user/user.cpp
HEADERS += ui/mainwindow.h \
ui/mapviewscreen.h \
ui/listviewscreen.h \
cookiehandler/cookiehandler.h \
facebookservice/facebookcredentials.h \
facebookservice/facebookauthentication.h \
- facebookservice/facebookcommon.h
+ facebookservice/facebookcommon.h \
+ user/user.h
QT += network \
webkit
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include "user.h"
+
+User::User(QString address, QPointF coordinates, QString name, QString note, QUrl imageUrl,
+ QString timestamp, bool type, QString userId, QString units, double value)
+ : m_address(address)
+ , m_coordinates(coordinates)
+ , m_name(name)
+ , m_note(note)
+ , m_profileImageUrl(imageUrl)
+ , m_timestamp(timestamp)
+ , m_type(type)
+ , m_units(units)
+ , m_userId(userId)
+ , m_value(value)
+{
+
+}
+
+void User::setAddress(const QString &address)
+{
+ m_address = address;
+}
+
+void User::setCoordinates(const QPointF &coordinates)
+{
+ m_coordinates = coordinates;
+}
+
+void User::setDistance(const double &value, const QString &units)
+{
+ m_value = value;
+ m_units = units;
+}
+
+void User::setNote(const QString ¬e)
+{
+ m_note = note;
+}
+
+void User::setProfileImageUrl(const QUrl &imageUrl)
+{
+ m_profileImageUrl = imageUrl;
+}
+
+void User::setTimestamp(const QString ×tamp)
+{
+ m_timestamp = timestamp;
+}
+
+QString User::address() const
+{
+ return m_address;
+}
+
+QPointF User::coordinates() const
+{
+ return m_coordinates;
+}
+
+void User::distance(double &value, QString &units) const
+{
+ value = m_value;
+ units = m_units;
+}
+
+QString User::name() const
+{
+ return m_name;
+}
+
+QString User::note() const
+{
+ return m_note;
+}
+
+QUrl User::profileImageUrl() const
+{
+ return m_profileImageUrl;
+}
+
+QString User::timestamp() const
+{
+ return m_timestamp;
+}
+
+bool User::type() const
+{
+ return m_type;
+}
+
+QString User::userId() const
+{
+ return m_userId;
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef USER_H
+#define USER_H
+
+#include <QPointF>
+#include <QString>
+#include <QUrl>
+
+/**
+* @brief Class to store user information (applies to friends also)
+*
+* @author Henri Lampela
+* @class User user.h "user/user.h"
+*/
+class User
+{
+public:
+
+ /**
+ * @brief Default constructor, initializes member data
+ *
+ */
+ User(const QString address, const QPointF coordinates, const QString name, const QString note,
+ const QUrl imageUrl, const QString timestamp, const bool type, const QString userId,
+ const QString units = 0, const double value = 0);
+
+ /**
+ * @brief Set address
+ *
+ * @param address street address
+ */
+ void setAddress(const QString &address);
+
+ /**
+ * @brief Set coordinates ( x = lon, y = lat )
+ *
+ * @param coordinates coordinates
+ */
+ void setCoordinates(const QPointF &coordinates);
+
+ /**
+ * @brief Set distance
+ *
+ * @param value distance
+ * @param units unit type
+ */
+ void setDistance(const double &value, const QString &units);
+
+ /**
+ * @brief Set note
+ *
+ * @param note note/status message
+ */
+ void setNote(const QString ¬e);
+
+ /**
+ * @brief Set download address for profile image
+ *
+ * @param imageUrl image url
+ */
+ void setProfileImageUrl(const QUrl &imageUrl);
+
+ /**
+ * @brief Set timestamp for last status update, timestamp is in literal mode
+ *
+ * @param timestamp timestamp
+ */
+ void setTimestamp(const QString ×tamp);
+
+ /**
+ * @brief Get address
+ *
+ * @return QString address
+ */
+ QString address() const;
+
+ /**
+ * @brief Get coordinates
+ *
+ * @return QPointF coordinates
+ */
+ QPointF coordinates() const;
+
+ /**
+ * @brief Get distance and units
+ *
+ * @param value distance
+ * @param units unit type
+ */
+ void distance(double &value, QString &units) const;
+
+ /**
+ * @brief Get name
+ *
+ * @return QString profile name
+ */
+ QString name() const;
+
+ /**
+ * @brief Get note/status message
+ *
+ * @return QString note
+ */
+ QString note() const;
+
+ /**
+ * @brief Get download address for profile image
+ *
+ * @return QString url
+ */
+ QUrl profileImageUrl() const;
+
+ /**
+ * @brief Get timestamp of last status update
+ *
+ * @return QString timestamp
+ */
+ QString timestamp() const;
+
+ /**
+ * @brief Get user type
+ *
+ * @return bool user type (true = user, false = friend)
+ */
+ bool type() const;
+
+ /**
+ * @brief Get userId
+ *
+ * @return QString userId
+ */
+ QString userId() const;
+
+private:
+ QString m_address; ///< placeholder for address information
+ QPointF m_coordinates; ///< placeholder for coordinates
+ QString m_name; ///< placeholder for name
+ QString m_note; ///< placeholder for note
+ QUrl m_profileImageUrl; ///< placeholder for image url
+ QString m_timestamp; ///< placeholer for timestamp
+ bool m_type; ///< placeholder for user type
+ QString m_units; ///< placeholder for distance unit type
+ QString m_userId; ///< placeholder for userId
+ double m_value; ///< placeholder for distance value
+};
+
+
+#endif // USER_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QDebug>
+#include <QBuffer>
+#include "networkaccessmanagermock.h"
+
+NetworkAccessManagerMock::NetworkAccessManagerMock(QNetworkAccessManager *manager, QObject *parent)
+ : QNetworkAccessManager(parent)
+ , mode(0)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+NetworkReplyMock *NetworkAccessManagerMock::createRequest(Operation op, const QNetworkRequest &request,
+ QIODevice *outgoingData)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ reply = new NetworkReplyMock(this);
+ this->request = request;
+
+ switch (this->mode) {
+
+ case NetworkAccessManagerMock::CORRECT:
+ QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
+ break;
+ case NetworkAccessManagerMock::INCORRECT:
+ QTimer::singleShot(0, this, SLOT(generateError()));
+ break;
+ case NetworkAccessManagerMock::DELAYED_CORRECT:
+ QTimer::singleShot(0, this, SLOT(generateDelayedCorrectReply()));
+ break;
+ default:
+ QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
+ break;
+ }
+ return reply;
+}
+
+NetworkAccessManagerMock::~NetworkAccessManagerMock()
+{
+ delete reply;
+}
+
+NetworkReplyMock *NetworkAccessManagerMock::get(const QNetworkRequest &request)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ this->request = request;
+
+ return reply;
+}
+
+void NetworkAccessManagerMock::setMode(int mode)
+{
+ this->mode = mode;
+}
+
+void NetworkAccessManagerMock::generateError()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ reply->setUrl(request.url());
+ reply->setError(QNetworkReply::HostNotFoundError, "Host not found");
+ emit QNetworkAccessManager::finished(reply);
+}
+
+void NetworkAccessManagerMock::generateCorrectReply()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ reply->setUrl(request.url());
+ reply->setError(QNetworkReply::NoError, "No error");
+// QImage image;
+// if (!image.load(":testTile.png", 0)) {
+// qDebug() << "could not load image";
+// image = QImage();
+// }
+// else
+// qDebug() << "image loaded";
+//
+// QByteArray array;
+// QBuffer buffer(&array);
+// buffer.open(QBuffer::WriteOnly);
+// if (image.save(&buffer, "PNG"))
+// qDebug() << "image saved";
+// buffer.close();
+// reply->setData(array);
+ emit QNetworkAccessManager::finished(reply);
+}
+
+void NetworkAccessManagerMock::generateDelayedCorrectReply()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QTimer::singleShot(4000, this, SLOT(generateCorrectReply()));
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef NETWORKACCESSMANAGERMOCK_H
+#define NETWORKACCESSMANAGERMOCK_H
+
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QTimer>
+#include "networkreplymock.h"
+
+
+class NetworkAccessManagerMock : public QNetworkAccessManager
+{
+ Q_OBJECT
+public:
+ NetworkAccessManagerMock(QNetworkAccessManager *manager = 0, QObject *parent = 0);
+
+ ~NetworkAccessManagerMock();
+
+ NetworkReplyMock *get(const QNetworkRequest &request);
+
+ void setMode(int mode);
+
+
+ enum {CORRECT, INCORRECT, DELAYED_CORRECT};
+
+protected:
+ NetworkReplyMock *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData);
+
+signals:
+ void finished(NetworkReplyMock *reply);
+
+ private slots:
+ void generateError();
+ void generateCorrectReply();
+ void generateDelayedCorrectReply();
+
+private:
+ NetworkReplyMock *reply;
+ QNetworkRequest request;
+ int mode;
+};
+
+#endif // NETWORKACCESSMANAGERMOCK_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QNetworkRequest>
+#include <QDebug>
+#include "networkreplymock.h"
+
+NetworkReplyMock::NetworkReplyMock(QObject *parent)
+ : QNetworkReply(parent)
+ , m_offset(0)
+{
+}
+
+void NetworkReplyMock::setError(NetworkError errorCode, const QString &errorString)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QNetworkReply::setError(errorCode, errorString);
+}
+
+
+qint64 NetworkReplyMock::readData(char *data, qint64 maxLen)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ if (m_offset < m_content.size()) {
+ qint64 number = qMin(maxLen, m_content.size() - m_offset);
+ memcpy(data, m_content.constData() + m_offset, number);
+ m_offset += number;
+ return number;
+ }
+ else {
+ return -1;
+ }
+}
+
+QByteArray NetworkReplyMock::readAll()
+{
+ return m_content;
+}
+
+qint64 NetworkReplyMock::bytesAvailable() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ return m_content.size() - m_offset;
+}
+
+void NetworkReplyMock::setUrl(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QNetworkReply::setUrl(url);
+}
+
+void NetworkReplyMock::abort()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void NetworkReplyMock::test()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void NetworkReplyMock::setData(const QByteArray &content)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+// setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
+// setHeader(QNetworkRequest::ContentLengthHeader, QVariant(this->m_content.size()));
+ m_content.append(content);
+ qDebug() << "Content size: " << m_content.size();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#ifndef NETWORKREPLYMOCK_H
+#define NETWORKREPLYMOCK_H
+
+#include <QNetworkReply>
+#include <QUrl>
+
+
+class NetworkReplyMock : public QNetworkReply
+{
+ Q_OBJECT
+public:
+ NetworkReplyMock(QObject *parent = 0);
+ void abort();
+ qint64 bytesAvailable() const;
+
+ bool isSequential() const
+ {
+ return true;
+ }
+ void setError(NetworkError errorCode, const QString &errorString);
+ void setData(const QByteArray &content);
+ void setUrl(const QUrl &url);
+ void test();
+ QByteArray readAll();
+
+protected:
+ qint64 readData(char *data, qint64 maxlen);
+
+private:
+ QByteArray m_content;
+ qint64 m_offset;
+};
+
+#endif // NETWORKREPLYMOCK_H
--- /dev/null
+ /*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+ */
+
+#include <QtTest/QtTest>
+#include <QtCore>
+//#include <QNetworkAccessManager>
+
+
+#include "../../../src/situareservice/situareservice.h"
+#include "../../../src/situareservice/situarecommon.h"
+#include "../networkaccessmanagermock.h"
+#include "../networkreplymock.h"
+
+class QNetworkAccessManager;
+
+
+class testFetchLocations : public QObject
+{
+ Q_OBJECT
+public:
+ ~testFetchLocations();
+private:
+ SituareService *situare;
+ NetworkAccessManagerMock *managerMock;
+ QList<QNetworkReply *> currentRequests;
+
+private slots:
+
+ //void testIncorrectUrl();
+ //void testCorrectUrl();
+ void testFetchLocationsCase();
+};
+
+testFetchLocations::~testFetchLocations()
+{
+ delete situare;
+ delete managerMock;
+}
+
+
+//void testFetchLocations::testIncorrectUrl()
+//{
+// QNetworkAccessManager *manager = new QNetworkAccessManager();
+// managerMock = new NetworkAccessManagerMock(manager, this);
+// situare = new SituareService(this, manager);
+//
+// managerMock->setMode(NetworkAccessManagerMock::INCORRECT);
+//
+// QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+//
+// QVERIFY(receivedErrorSpy.isValid());
+//
+// // incorrect url
+//
+// situare->sendRequest(QUrl("http://client.situare.nett"), COOKIE, QString(""));
+// QTest::qWait(1000);
+// QCOMPARE(receivedErrorSpy.count(), 1);
+//
+// delete manager;
+//}
+
+//void testFetchLocations::testCorrectUrl()
+//{
+// QNetworkAccessManager *manager = new QNetworkAccessManager();
+// managerMock = new NetworkAccessManagerMock(manager, this);
+// situare = new SituareService(this, manager);
+//
+// managerMock->setMode(NetworkAccessManagerMock::CORRECT);
+//
+// QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+//
+// QVERIFY(receivedErrorSpy.isValid());
+//
+// QUrl url = QUrl("http://client.situare.net");
+//
+// situare->sendRequest(url, COOKIE, QString(""));
+// QTest::qWait(1000);
+//
+// QCOMPARE(receivedErrorSpy.count(), 0);
+//
+// delete manager;
+//}
+
+void testFetchLocations::testFetchLocationsCase()
+{
+ QNetworkAccessManager *manager = new QNetworkAccessManager();
+ managerMock = new NetworkAccessManagerMock(manager, this);
+ situare = new SituareService(this, manager);
+
+ managerMock->setMode(NetworkAccessManagerMock::CORRECT);
+
+ QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+
+ situare->fetchLocations();
+ QTest::qWait(1000);
+
+ QCOMPARE(receivedErrorSpy.count(), 0);
+
+ delete manager;
+}
+
+
+QTEST_MAIN(testFetchLocations)
+#include "testfetchlocations.moc"
--- /dev/null
+######################################################################
+# Automatically generated by qmake (2.01a) Wed Apr 21 10:16:04 2010
+######################################################################
+
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += ../../../src/situareservice/situareservice.h \
+ ../../../src/facebookservice/facebookauthentication.h \
+ ../../../src/facebookservice/facebookcredentials.h \
+ ../../../src/situareservice/situarecommon.h \
+ ../../../src/cookiehandler/cookiehandler.h \
+ ../networkaccessmanagermock.h \
+ ../networkreplymock.h
+SOURCES += testfetchlocations.cpp \
+ ../../../src/situareservice/situareservice.cpp \
+ ../../../src/facebookservice/facebookauthentication.cpp \
+ ../../../src/facebookservice/facebookcredentials.cpp \
+ ../../../src/cookiehandler/cookiehandler.cpp \
+ ../networkaccessmanagermock.cpp \
+ ../networkreplymock.cpp
+QT += core \
+ network \
+ webkit
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Henri Lampela - henri.lampela@ixonos.com
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#include <QDebug>
-#include <QBuffer>
-#include "networkaccessmanagermock.h"
-
-NetworkAccessManagerMock::NetworkAccessManagerMock(QNetworkAccessManager *manager, QObject *parent)
- : QNetworkAccessManager(parent)
- , mode(0)
-{
- qDebug() << __PRETTY_FUNCTION__;
-}
-
-NetworkReplyMock *NetworkAccessManagerMock::createRequest(Operation op, const QNetworkRequest &request,
- QIODevice *outgoingData)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- reply = new NetworkReplyMock(this);
- this->request = request;
-
- switch (this->mode) {
-
- case NetworkAccessManagerMock::CORRECT:
- QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
- break;
- case NetworkAccessManagerMock::INCORRECT:
- QTimer::singleShot(0, this, SLOT(generateError()));
- break;
- case NetworkAccessManagerMock::DELAYED_CORRECT:
- QTimer::singleShot(0, this, SLOT(generateDelayedCorrectReply()));
- break;
- default:
- QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
- break;
- }
- return reply;
-}
-
-NetworkAccessManagerMock::~NetworkAccessManagerMock()
-{
- delete reply;
-}
-
-NetworkReplyMock *NetworkAccessManagerMock::get(const QNetworkRequest &request)
-{
- qDebug() << __PRETTY_FUNCTION__;
- this->request = request;
-
- return reply;
-}
-
-void NetworkAccessManagerMock::setMode(int mode)
-{
- this->mode = mode;
-}
-
-void NetworkAccessManagerMock::generateError()
-{
- qDebug() << __PRETTY_FUNCTION__;
- reply->setUrl(request.url());
- reply->setError(QNetworkReply::HostNotFoundError, "Host not found");
- emit QNetworkAccessManager::finished(reply);
-}
-
-void NetworkAccessManagerMock::generateCorrectReply()
-{
- qDebug() << __PRETTY_FUNCTION__;
- reply->setUrl(request.url());
- reply->setError(QNetworkReply::NoError, "No error");
-// QImage image;
-// if (!image.load(":testTile.png", 0)) {
-// qDebug() << "could not load image";
-// image = QImage();
-// }
-// else
-// qDebug() << "image loaded";
-//
-// QByteArray array;
-// QBuffer buffer(&array);
-// buffer.open(QBuffer::WriteOnly);
-// if (image.save(&buffer, "PNG"))
-// qDebug() << "image saved";
-// buffer.close();
-// reply->setData(array);
- emit QNetworkAccessManager::finished(reply);
-}
-
-void NetworkAccessManagerMock::generateDelayedCorrectReply()
-{
- qDebug() << __PRETTY_FUNCTION__;
- QTimer::singleShot(4000, this, SLOT(generateCorrectReply()));
-}
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Henri Lampela - henri.lampela@ixonos.com
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#ifndef NETWORKACCESSMANAGERMOCK_H
-#define NETWORKACCESSMANAGERMOCK_H
-
-#include <QNetworkAccessManager>
-#include <QNetworkRequest>
-#include <QTimer>
-#include "networkreplymock.h"
-
-
-class NetworkAccessManagerMock : public QNetworkAccessManager
-{
- Q_OBJECT
-public:
- NetworkAccessManagerMock(QNetworkAccessManager *manager = 0, QObject *parent = 0);
-
- ~NetworkAccessManagerMock();
-
- NetworkReplyMock *get(const QNetworkRequest &request);
-
- void setMode(int mode);
-
-
- enum {CORRECT, INCORRECT, DELAYED_CORRECT};
-
-protected:
- NetworkReplyMock *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData);
-
-signals:
- void finished(NetworkReplyMock *reply);
-
- private slots:
- void generateError();
- void generateCorrectReply();
- void generateDelayedCorrectReply();
-
-private:
- NetworkReplyMock *reply;
- QNetworkRequest request;
- int mode;
-};
-
-#endif // NETWORKACCESSMANAGERMOCK_H
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Henri Lampela - henri.lampela@ixonos.com
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#include <QNetworkRequest>
-#include <QDebug>
-#include "networkreplymock.h"
-
-NetworkReplyMock::NetworkReplyMock(QObject *parent)
- : QNetworkReply(parent)
- , m_offset(0)
-{
-}
-
-void NetworkReplyMock::setError(NetworkError errorCode, const QString &errorString)
-{
- qDebug() << __PRETTY_FUNCTION__;
- QNetworkReply::setError(errorCode, errorString);
-}
-
-
-qint64 NetworkReplyMock::readData(char *data, qint64 maxLen)
-{
- qDebug() << __PRETTY_FUNCTION__;
- if (m_offset < m_content.size()) {
- qint64 number = qMin(maxLen, m_content.size() - m_offset);
- memcpy(data, m_content.constData() + m_offset, number);
- m_offset += number;
- return number;
- }
- else {
- return -1;
- }
-}
-
-QByteArray NetworkReplyMock::readAll()
-{
- return m_content;
-}
-
-qint64 NetworkReplyMock::bytesAvailable() const
-{
- qDebug() << __PRETTY_FUNCTION__;
- return m_content.size() - m_offset;
-}
-
-void NetworkReplyMock::setUrl(const QUrl &url)
-{
- qDebug() << __PRETTY_FUNCTION__;
- QNetworkReply::setUrl(url);
-}
-
-void NetworkReplyMock::abort()
-{
- qDebug() << __PRETTY_FUNCTION__;
-}
-
-void NetworkReplyMock::test()
-{
- qDebug() << __PRETTY_FUNCTION__;
-}
-
-void NetworkReplyMock::setData(const QByteArray &content)
-{
- qDebug() << __PRETTY_FUNCTION__;
-// setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
-// setHeader(QNetworkRequest::ContentLengthHeader, QVariant(this->m_content.size()));
- m_content.append(content);
- qDebug() << "Content size: " << m_content.size();
-}
+++ /dev/null
-/*
- Situare - A location system for Facebook
- Copyright (C) 2010 Ixonos Plc. Authors:
-
- Henri Lampela - henri.lampela@ixonos.com
- Jussi Laitinen - jussi.laitinen@ixonos.com
-
- Situare is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
-
- Situare is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Situare; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA.
-*/
-
-#ifndef NETWORKREPLYMOCK_H
-#define NETWORKREPLYMOCK_H
-
-#include <QNetworkReply>
-#include <QUrl>
-
-
-class NetworkReplyMock : public QNetworkReply
-{
- Q_OBJECT
-public:
- NetworkReplyMock(QObject *parent = 0);
- void abort();
- qint64 bytesAvailable() const;
-
- bool isSequential() const
- {
- return true;
- }
- void setError(NetworkError errorCode, const QString &errorString);
- void setData(const QByteArray &content);
- void setUrl(const QUrl &url);
- void test();
- QByteArray readAll();
-
-protected:
- qint64 readData(char *data, qint64 maxlen);
-
-private:
- QByteArray m_content;
- qint64 m_offset;
-};
-
-#endif // NETWORKREPLYMOCK_H
#include "../../../src/situareservice/situareservice.h"
#include "../../../src/situareservice/situarecommon.h"
-#include "networkaccessmanagermock.h"
-#include "networkreplymock.h"
+#include "../networkaccessmanagermock.h"
+#include "../networkreplymock.h"
class testLocationUpdate : public QObject
--- /dev/null
+ /*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+ */
+
+#include <QtTest/QtTest>
+#include <QtCore>
+#include <QPointer>
+#include <QUrl>
+#include <QDebug>
+
+
+#include "../../src/user/user.h"
+
+
+class TestUser : public QObject
+{
+ Q_OBJECT
+public:
+ TestUser();
+ ~TestUser();
+private:
+ User *user;
+
+private slots:
+
+ void testAddress();
+ void testCoordinates();
+ void testName();
+ void testNote();
+ void testImageUrl();
+ void testTimestamp();
+ void testUserType();
+ void testDistance();
+ void testUserId();
+};
+
+TestUser::TestUser()
+{
+ const QString address = "Kuja 3 A, 90560 Oulu, Finland";
+ const QPointF coordinates(65.3, 25.5);
+ const QString name = "Jukka Kukka";
+ const QString note = "Testing";
+ const QUrl imageUrl = QUrl("http://profile.ak.fbcdn.net/v225/874/99/q100000139211584_3252.jpg");
+ const QString timestamp = "1 minute ago";
+ const bool userType = false;
+ const QString units = "km";
+ const QString userId = "111000222";
+ const double value = 12.1;
+
+ user = new User(address, coordinates, name, note, imageUrl, timestamp, userType, userId, units, value);
+}
+
+TestUser::~TestUser()
+{
+ delete user;
+}
+
+void TestUser::testAddress()
+{
+ QString newValue = "Kalmakuja 6 B, 90650 Oulu, Finland";
+ QString oldValue = user->address();
+
+ qDebug() << oldValue;
+
+ user->setAddress(newValue);
+
+ QString currentValue = user->address();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, newValue);
+}
+
+void TestUser::testCoordinates()
+{
+ QPointF oldValue = user->coordinates();
+
+ qDebug() << oldValue;
+
+ QPointF newValue(64.3, 25.8);
+
+ user->setCoordinates(newValue);
+
+ QPointF currentValue = user->coordinates();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, newValue);
+}
+
+void TestUser::testName()
+{
+ QString currentValue = user->name();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, QString("Jukka Kukka"));
+}
+
+void TestUser::testNote()
+{
+ QString oldValue = user->note();
+
+ qDebug() << oldValue;
+
+ QString newValue = "Still testing";
+
+ user->setNote(newValue);
+
+ QString currentValue = user->note();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, newValue);
+}
+
+void TestUser::testImageUrl()
+{
+ QUrl oldValue = user->profileImageUrl();
+
+ qDebug() << oldValue;
+
+ QUrl newValue = QUrl("http://profile.ak.fbcdn.net/v225/874/99/xxxxxxx.jpg");
+
+ user->setProfileImageUrl(newValue);
+
+ QUrl currentValue = user->profileImageUrl();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, newValue);
+}
+
+void TestUser::testTimestamp()
+{
+ QString oldValue = user->timestamp();
+
+ qDebug() << oldValue;
+
+ QString newValue = "2 minutes ago";
+
+ user->setTimestamp(newValue);
+
+ QString currentValue = user->timestamp();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, newValue);
+}
+
+void TestUser::testUserType()
+{
+ bool currentValue = user->type();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, false);
+}
+
+void TestUser::testDistance()
+{
+ QString oldUnitValue;
+ double oldDistanceValue;
+
+ user->distance(oldDistanceValue, oldUnitValue);
+
+ qDebug() << oldDistanceValue << oldUnitValue;
+
+ QString newUnitValue = "miles";
+ double newDistanceValue = 2.13;
+
+ user->setDistance(newDistanceValue, newUnitValue);
+
+ QString currentUnitValue;
+ double currentDistanceValue;
+
+ user->distance(currentDistanceValue, currentUnitValue);
+
+ qDebug() << currentDistanceValue << currentUnitValue;
+
+ QCOMPARE(currentDistanceValue, newDistanceValue);
+ QCOMPARE(currentUnitValue, newUnitValue);
+}
+
+void TestUser::testUserId()
+{
+ QString currentValue = user->userId();
+
+ qDebug() << currentValue;
+
+ QCOMPARE(currentValue, QString("111000222"));
+}
+
+QTEST_MAIN(TestUser)
+#include "testuser.moc"
--- /dev/null
+######################################################################
+# Automatically generated by qmake (2.01a) Thu Apr 22 12:14:27 2010
+######################################################################
+
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += ../../src/user/user.h
+SOURCES += testuser.cpp ../../src/user/user.cpp