Code reviewed by Ville Tiensuu, findings fixed. Removed teststringformations unit...
authorlampehe-local <henri.lampela@ixonos.com>
Mon, 19 Apr 2010 11:32:06 +0000 (14:32 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Mon, 19 Apr 2010 11:32:06 +0000 (14:32 +0300)
src/cookiehandler/cookiehandler.cpp
src/cookiehandler/cookiehandler.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
tests/situareservice/teststringformations/teststringformations.cpp [deleted file]
tests/situareservice/teststringformations/teststringformations.pro [deleted file]

index 01145d2..df6df19 100644 (file)
@@ -33,11 +33,21 @@ CookieHandler::~CookieHandler()
     qDebug() << __PRETTY_FUNCTION__;
 }
 
-QString CookieHandler::formCookie(QString apiKeyValue, QString expiresValue, QString userValue, QString sessionKeyValue, QString sessionSecretValue, QString signatureValue, QString localeValue)
+QString CookieHandler::formCookie(const QString &apiKeyValue, QString expiresValue,
+                                  QString userValue, QString sessionKeyValue,
+                                  QString sessionSecretValue, const QString &signatureValue,
+                                  const QString &localeValue)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QString cookie, apiKey, user, expires, sessionKey, sessionSecret, locale, variable;
+    QString cookie;
+    QString apiKey;
+    QString user;
+    QString expires;
+    QString sessionKey;
+    QString sessionSecret;
+    QString locale;
+    QString variable;
     QString signature = EQUAL_MARK;
     QStringList variableList;
 
index 9c6af32..afc72c1 100644 (file)
@@ -26,7 +26,7 @@
 #include "../situareservice/situarecommon.h"
 
 /**
-* @brief
+* @brief Class for cookie cretion.
 *
 * @author Henri Lampela
 * @class CookieHandler cookiehandler.h "cookiehandler/cookiehandler.h"
@@ -59,7 +59,9 @@ public:
     * @param localeValue used locale
     * @return QString formed cookie
     */
-    QString formCookie(QString apiKeyValue, QString expiresValue, QString userValue, QString sessionKeyValue, QString sessionSecretValue, QString signatureValue, QString localeValue);
+    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+                       QString sessionKeyValue, QString sessionSecretValue,
+                       const QString &signatureValue, const QString &localeValue);
 
 };
 
index 56936c5..8cebae4 100644 (file)
 #include "../cookiehandler/cookiehandler.h"
 
 SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
-        : QObject(parent), networkManager(manager)
+        : QObject(parent), m_networkManager(manager)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(&facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
+    connect(&m_facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
 
-    connect(networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
+    connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
 
-    credentials = facebookAuthentication.loginCredentials();
+    m_credentials = m_facebookAuthentication.loginCredentials();
 }
 
 SituareService::~SituareService()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    delete networkManager;
+    delete m_networkManager;
 }
 
-void SituareService::updateLocation(QPointF coordinates, QString status, bool publish)
+void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
+                                    const bool &publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     CookieHandler cookieHandler;
 
-    QString cookie = cookieHandler.formCookie(API_KEY, credentials.expires(), credentials.userID(), credentials.sessionKey(),
-                                              credentials.sessionSecret(), credentials.sig(), EN_LOCALE);
+    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;
@@ -68,14 +70,15 @@ void SituareService::updateLocation(QPointF coordinates, QString status, bool pu
     sendRequest(url, COOKIE, cookie);
 }
 
-void SituareService::reverseGeo(QPointF coordinates)
+void SituareService::reverseGeo(const QPointF &coordinates)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     CookieHandler cookieHandler;
 
-    QString cookie = cookieHandler.formCookie(API_KEY, credentials.expires(), credentials.userID(), credentials.sessionKey(),
-                                              credentials.sessionSecret(), credentials.sig(), EN_LOCALE);
+    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                              m_credentials.sig(), EN_LOCALE);
 
     QString urlParameters = formUrlParameters(coordinates);
     QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
@@ -83,15 +86,14 @@ void SituareService::reverseGeo(QPointF coordinates)
     sendRequest(url, COOKIE, cookie);
 }
 
-QUrl SituareService::formUrl(const QString baseUrl, const QString phpScript, QString urlParameters)
+QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters)
 {
     qDebug() << __PRETTY_FUNCTION__;
     QString urlString;
 
-
     urlString.append(baseUrl);
     urlString.append(phpScript);
-    if(urlParameters != NULL)  // ToDo: check this better
+    if(urlParameters != NULL)
         urlString.append(urlParameters);
 
     QUrl url = QUrl(urlString);
@@ -101,7 +103,7 @@ QUrl SituareService::formUrl(const QString baseUrl, const QString phpScript, QSt
     return url;
 }
 
-QString SituareService::formUrlParameters(QPointF coordinates, QString status, QString publish)
+QString SituareService::formUrlParameters(const QPointF &coordinates, QString status, QString publish)
 {
     QString parameters;
 
@@ -137,7 +139,7 @@ QString SituareService::formUrlParameters(QPointF coordinates, QString status, Q
     return parameters;
 }
 
-void SituareService::sendRequest(QUrl url, const QString cookieType, QString cookie)
+void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
 {
     qDebug() << __PRETTY_FUNCTION__ << "url: " << url;
 
@@ -146,9 +148,9 @@ void SituareService::sendRequest(QUrl url, const QString cookieType, QString coo
     request.setUrl(url);
     request.setRawHeader(cookieType.toAscii(), cookie.toUtf8());
 
-    QNetworkReply *reply = networkManager->get(request);
+    QNetworkReply *reply = m_networkManager->get(request);
 
-    currentRequests.append(reply);
+    m_currentRequests.append(reply);
 }
 
 void SituareService::requestFinished(QNetworkReply *reply)
@@ -167,7 +169,8 @@ void SituareService::requestFinished(QNetworkReply *reply)
         QByteArray replyArray = reply->read(max);
         qDebug() << "Reply from: " << url << "reply " << replyArray;
         // ToDo: results handling includes Situare's errors
-        // works like situare's error handling i.e. both lat & lon are missing/wrong -> we get only error for wrong lon
+        // works like situare's error handling i.e. both lat & lon are missing/wrong
+        // -> we get only error for wrong lon
         if(replyArray == ERROR_LAT.toAscii()) {
             qDebug() << "Error: " << ERROR_LAT;
             // ToDo: signal UI?
@@ -190,12 +193,12 @@ void SituareService::requestFinished(QNetworkReply *reply)
         }
     }
 
-    currentRequests.removeAll(reply);
+    m_currentRequests.removeAll(reply);
     reply->deleteLater();
 }
 
 void SituareService::credentialsReady()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    credentials = facebookAuthentication.loginCredentials();
+    m_credentials = m_facebookAuthentication.loginCredentials();
 }
index 0a50eaa..d87f444 100644 (file)
@@ -29,9 +29,8 @@
 #include <QNetworkRequest>
 #include <QNetworkReply>
 #include <QUrl>
-
-#include "../facebookservice/facebookauthentication.h"  // not final
-#include "../facebookservice/facebookcredentials.h"  // not final
+#include "../facebookservice/facebookauthentication.h"
+#include "../facebookservice/facebookcredentials.h"
 
 /**
 * @brief SituareService class for communicating with Situare server
@@ -66,14 +65,30 @@ public:
     * @param status message
     * @param publish publish location on Facebook wall (true/false)
     */
-    void updateLocation(QPointF coordinates, QString status, bool publish);
+    void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
 
     /**
     * @brief Translates coordinates to street address via Situare server
     *
     * @param coordinates coordinates to be translated
     */
-    void reverseGeo(QPointF coordinates);
+    void reverseGeo(const QPointF &coordinates);
+
+public slots:
+
+    /**
+    * @brief Public slot, which indicates when http request has been completed
+    *
+    * @param reply storage for http reply
+    */
+    void requestFinished(QNetworkReply *reply);
+
+
+    /**
+    * @brief Public slot, which indicates when facebook credentials are ready
+    *
+    */
+    void credentialsReady();
 
 private:
 
@@ -85,7 +100,7 @@ private:
     * @param urlParameters optional parameters for url
     * @return QUrl formed url
     */
-    QUrl formUrl(const QString baseUrl, const QString phpScript, QString urlParameters = 0);
+    QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
 
     /**
     * @brief Forms url parameters
@@ -95,7 +110,7 @@ private:
     * @param publish optional publish location on Facebook wall (true/false)
     * @return QString
     */
-    QString formUrlParameters(QPointF coordinates, QString status = 0, QString publish = 0);
+    QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
 
     /**
     * @brief Sends http request
@@ -104,7 +119,7 @@ private:
     * @param cookieType type of the cookie
     * @param cookie http cookie
     */
-    void sendRequest(QUrl url, const QString cookieType, QString cookie);
+    void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
 
 signals:
 
@@ -115,28 +130,12 @@ signals:
     */
     void error(const QString &error);
 
-public slots:
-
-    /**
-    * @brief Public slot, which indicates when http request has been completed
-    *
-    * @param reply storage for http reply
-    */
-    void requestFinished(QNetworkReply *reply);
-
-
-    /**
-    * @brief Public slot, which indicates when facebook credentials are ready
-    *
-    */
-    void credentialsReady();
-
 private:
 
-    FacebookCredentials credentials; ///< FacebookCredentials
-    QList<QNetworkReply *> currentRequests; ///< List of current http requests
-    FacebookAuthentication facebookAuthentication; ///< Pointer to FacebookAuthentication
-    QNetworkAccessManager *networkManager; ///< Pointer to QNetworkAccessManager
+    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
 };
 
 #endif // SITUARESERVICE_H
diff --git a/tests/situareservice/teststringformations/teststringformations.cpp b/tests/situareservice/teststringformations/teststringformations.cpp
deleted file mode 100644 (file)
index 314990b..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
- /*
-    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 <QPointF>
-
-
-#include "../../../src/situareservice/situareservice.h"
-#include "../../../src/situareservice/situarecommon.h"
-
-
-class testStringFormations : public QObject
-{
-    Q_OBJECT
-private:
-    SituareService *situare;
-
-private slots:
-
-    void testWithNoPublishNoStatus();       // part 1 of testFormUrlParameters
-    void testWithStatusNoPublish();         // part 2 of testFormUrlParameters
-    void testWithPublishTrueNoStatus();     // part 3 of testFormUrlParameters
-    void testWithStatusPublishTrue();       // part 4 of testFormUrlParameters
-    void testWithStatusPublishFalse();      // part 5 of testFormUrlParameters
-    void testWithPublishFalseNoStatus();    // part 6 of testFormUrlParameters
-
-    void testFormUpdateLocationUrl();       // updateLocation url test
-    void testFormReverseGeoUrl();           // reverseGeo url test
-
-};
-
-void testStringFormations::testWithNoPublishNoStatus()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "";
-    QString status = "";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5"), params);
-}
-
-void testStringFormations::testWithStatusNoPublish()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "";
-    QString status = "testing";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5&data=testing"), params);
-}
-
-void testStringFormations::testWithPublishTrueNoStatus()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "true";
-    QString status = "";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true"), params);
-}
-
-void testStringFormations::testWithStatusPublishTrue()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "true";
-    QString status = "testing";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true&data=testing"), params);
-}
-
-void testStringFormations::testWithStatusPublishFalse()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "false";
-    QString status = "testing";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false&data=testing"), params);
-}
-
-void testStringFormations::testWithPublishFalseNoStatus()
-{
-    QPointF coordinates(65.3, 25.5);
-    QString publish = "false";
-    QString status = "";
-    QString params = situare->formUrlParameters(coordinates, status, publish);
-
-    QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false"), params);
-}
-
-void testStringFormations::testFormUpdateLocationUrl()
-{
-    QString urlParameters = "?lat=65.3&lon=25.5&publish=false";
-    QUrl url = situare->formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
-
-    QCOMPARE(QString("http://client.situare.net/updateLocation.php?lat=65.3&lon=25.5&publish=false"), url.toString());
-}
-
-void testStringFormations::testFormReverseGeoUrl()
-{
-    QPointF coordinates(65.3, 25.5);
-
-    QString params = situare->formUrlParameters(coordinates);
-
-    QUrl url = situare->formUrl(SITUARE_URL, REVERSE_GEO, params);
-
-    QCOMPARE(QString("http://client.situare.net/reversegeo.php?lat=65.3&lon=25.5"), url.toString());
-}
-
-
-QTEST_MAIN(testStringFormations)
-#include "teststringformations.moc"
diff --git a/tests/situareservice/teststringformations/teststringformations.pro b/tests/situareservice/teststringformations/teststringformations.pro
deleted file mode 100644 (file)
index 054fa88..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-# #####################################################################
-# Automatically generated by qmake (2.01a) Thu Apr 8 14:56:57 2010
-# #####################################################################
-CONFIG += qtestlib
-TEMPLATE = app
-TARGET = 
-DEPENDPATH += .
-INCLUDEPATH += .
-
-# Input
-HEADERS += ../../../src/situareservice/situareservice.h \
-           ../../../src/cookiehandler/cookiehandler.h \
-           ../../../src/facebookservice/facebookauthentication.h \
-           ../../../src/facebookservice/facebookcredentials.h
-
-SOURCES += teststringformations.cpp \
-    ../../../src/situareservice/situareservice.cpp \
-    ../../../src/cookiehandler/cookiehandler.cpp \
-    ../../../src/facebookservice/facebookauthentication.cpp \
-    ../../../src/facebookservice/facebookcredentials.cpp
-QT = core \
-    gui \
-    network \
-    webkit