Added user class and related unit-tests, implemented user data fetching, re-factored...
authorlampehe-local <henri.lampela@ixonos.com>
Fri, 23 Apr 2010 05:29:31 +0000 (08:29 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Fri, 23 Apr 2010 05:29:31 +0000 (08:29 +0300)
19 files changed:
src/situareservice/situarecommon.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro
src/user/user.cpp [new file with mode: 0644]
src/user/user.h [new file with mode: 0644]
tests/situareservice/networkaccessmanagermock.cpp [new file with mode: 0644]
tests/situareservice/networkaccessmanagermock.h [new file with mode: 0644]
tests/situareservice/networkreplymock.cpp [new file with mode: 0644]
tests/situareservice/networkreplymock.h [new file with mode: 0644]
tests/situareservice/testfetchlocations/testfetchlocations.cpp [new file with mode: 0644]
tests/situareservice/testfetchlocations/testfetchlocations.pro [new file with mode: 0644]
tests/situareservice/testlocationupdate/networkaccessmanagermock.cpp [deleted file]
tests/situareservice/testlocationupdate/networkaccessmanagermock.h [deleted file]
tests/situareservice/testlocationupdate/networkreplymock.cpp [deleted file]
tests/situareservice/testlocationupdate/networkreplymock.h [deleted file]
tests/situareservice/testlocationupdate/testlocationupdate.cpp
tests/user/testuser.cpp [new file with mode: 0644]
tests/user/user.pro [new file with mode: 0644]

index 8440c5f..19824ec 100644 (file)
@@ -35,6 +35,7 @@ const QString TEST_API_KEY = "cf77865a5070f2c2ba3b52cbf3371579";
 // 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";
@@ -56,6 +57,7 @@ const QString AMBERSAND_MARK = "&";
 const QString EQUAL_MARK = "=";
 const QString UNDERLINE_MARK = "_";
 const QString BREAK_MARK = ";";
+const QString OPENING_BRACE_MARK = "{";
 
 // Coordinates
 const QString LATITUDE = "lat";
index 8cebae4..1f98fc3 100644 (file)
@@ -25,6 +25,7 @@
 #include "situareservice.h"
 #include "situarecommon.h"
 #include "../cookiehandler/cookiehandler.h"
+#include "parser.h"
 
 SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
         : QObject(parent), m_networkManager(manager)
@@ -45,8 +46,7 @@ SituareService::~SituareService()
     delete m_networkManager;
 }
 
-void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
-                                    const bool &publish)
+void SituareService::fetchLocations()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -56,16 +56,7 @@ void SituareService::updateLocation(const QPointF &coordinates, const QString &s
                                               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);
 }
@@ -86,6 +77,31 @@ void SituareService::reverseGeo(const QPointF &coordinates)
     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__;
@@ -186,6 +202,10 @@ void SituareService::requestFinished(QNetworkReply *reply)
             // 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?
@@ -202,3 +222,49 @@ void SituareService::credentialsReady()
     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);
+}
index d87f444..cc703ee 100644 (file)
 #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
@@ -59,13 +61,10 @@ public:
     ~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
@@ -74,6 +73,15 @@ public:
     */
     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:
 
     /**
@@ -121,6 +129,13 @@ private:
     */
     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:
 
     /**
@@ -130,12 +145,23 @@ 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
index 692831f..b6bf66f 100644 (file)
@@ -3,6 +3,8 @@
 # -------------------------------------------------
 TARGET = ../situare
 TEMPLATE = app
+INCLUDEPATH += "/home/lampehe-local/Downloads/qjson/src"
+LIBS += "-lqjson"
 RESOURCES += images.qrc
 SOURCES += main.cpp \
     ui/mainwindow.cpp \
@@ -20,7 +22,8 @@ SOURCES += main.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 \
@@ -39,7 +42,8 @@ HEADERS += ui/mainwindow.h \
     cookiehandler/cookiehandler.h \
     facebookservice/facebookcredentials.h \
     facebookservice/facebookauthentication.h \
-    facebookservice/facebookcommon.h
+    facebookservice/facebookcommon.h \
+    user/user.h
 QT += network \
     webkit
 
diff --git a/src/user/user.cpp b/src/user/user.cpp
new file mode 100644 (file)
index 0000000..6bb83f8
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+   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 &note)
+{
+    m_note = note;
+}
+
+void User::setProfileImageUrl(const QUrl &imageUrl)
+{
+    m_profileImageUrl = imageUrl;
+}
+
+void User::setTimestamp(const QString &timestamp)
+{
+    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;
+}
diff --git a/src/user/user.h b/src/user/user.h
new file mode 100644 (file)
index 0000000..a281a43
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+   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 &note);
+
+    /**
+    * @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 &timestamp);
+
+    /**
+    * @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
diff --git a/tests/situareservice/networkaccessmanagermock.cpp b/tests/situareservice/networkaccessmanagermock.cpp
new file mode 100644 (file)
index 0000000..d18a5b5
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+   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()));
+}
diff --git a/tests/situareservice/networkaccessmanagermock.h b/tests/situareservice/networkaccessmanagermock.h
new file mode 100644 (file)
index 0000000..6147408
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+   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
diff --git a/tests/situareservice/networkreplymock.cpp b/tests/situareservice/networkreplymock.cpp
new file mode 100644 (file)
index 0000000..911e896
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+   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();
+}
diff --git a/tests/situareservice/networkreplymock.h b/tests/situareservice/networkreplymock.h
new file mode 100644 (file)
index 0000000..d125aed
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+   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
diff --git a/tests/situareservice/testfetchlocations/testfetchlocations.cpp b/tests/situareservice/testfetchlocations/testfetchlocations.cpp
new file mode 100644 (file)
index 0000000..99fc584
--- /dev/null
@@ -0,0 +1,122 @@
+ /*
+    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"
diff --git a/tests/situareservice/testfetchlocations/testfetchlocations.pro b/tests/situareservice/testfetchlocations/testfetchlocations.pro
new file mode 100644 (file)
index 0000000..57be8f9
--- /dev/null
@@ -0,0 +1,28 @@
+######################################################################
+# 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
diff --git a/tests/situareservice/testlocationupdate/networkaccessmanagermock.cpp b/tests/situareservice/testlocationupdate/networkaccessmanagermock.cpp
deleted file mode 100644 (file)
index d18a5b5..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-   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()));
-}
diff --git a/tests/situareservice/testlocationupdate/networkaccessmanagermock.h b/tests/situareservice/testlocationupdate/networkaccessmanagermock.h
deleted file mode 100644 (file)
index 6147408..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-   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
diff --git a/tests/situareservice/testlocationupdate/networkreplymock.cpp b/tests/situareservice/testlocationupdate/networkreplymock.cpp
deleted file mode 100644 (file)
index 911e896..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-   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();
-}
diff --git a/tests/situareservice/testlocationupdate/networkreplymock.h b/tests/situareservice/testlocationupdate/networkreplymock.h
deleted file mode 100644 (file)
index d125aed..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-   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
index 5db71d5..0047653 100644 (file)
@@ -27,8 +27,8 @@
 
 #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
diff --git a/tests/user/testuser.cpp b/tests/user/testuser.cpp
new file mode 100644 (file)
index 0000000..3b19369
--- /dev/null
@@ -0,0 +1,212 @@
+ /*
+    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"
diff --git a/tests/user/user.pro b/tests/user/user.pro
new file mode 100644 (file)
index 0000000..0644b33
--- /dev/null
@@ -0,0 +1,13 @@
+######################################################################
+# 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