Test stuff
authorTorste Aikio <zokier@zokier.laptop>
Tue, 29 Jun 2010 08:26:09 +0000 (11:26 +0300)
committerTorste Aikio <zokier@zokier.laptop>
Tue, 29 Jun 2010 08:26:09 +0000 (11:26 +0300)
13 files changed:
ut/stubs/QNetworkAccessManager [new file with mode: 0644]
ut/stubs/QNetworkReply [new file with mode: 0644]
ut/stubs/QSettings [new file with mode: 0644]
ut/stubs/qnetworkaccessmanager.cpp [new file with mode: 0644]
ut/stubs/qnetworkaccessmanager.h [new file with mode: 0644]
ut/stubs/qnetworkreply.cpp [new file with mode: 0644]
ut/stubs/qnetworkreply.h [new file with mode: 0644]
ut/stubs/qsettings.cpp [new file with mode: 0644]
ut/stubs/qsettings.h [new file with mode: 0644]
ut/ut.pri
ut/ut_remote/ut_remote.cpp [new file with mode: 0644]
ut/ut_remote/ut_remote.h [new file with mode: 0644]
ut/ut_remote/ut_remote.pro [new file with mode: 0644]

diff --git a/ut/stubs/QNetworkAccessManager b/ut/stubs/QNetworkAccessManager
new file mode 100644 (file)
index 0000000..b923498
--- /dev/null
@@ -0,0 +1 @@
+#include "qnetworkaccessmanager.h"
diff --git a/ut/stubs/QNetworkReply b/ut/stubs/QNetworkReply
new file mode 100644 (file)
index 0000000..e6ebfbe
--- /dev/null
@@ -0,0 +1 @@
+#include "qnetworkreply.h"
diff --git a/ut/stubs/QSettings b/ut/stubs/QSettings
new file mode 100644 (file)
index 0000000..b9ec26d
--- /dev/null
@@ -0,0 +1 @@
+#include <qsettings.h>
diff --git a/ut/stubs/qnetworkaccessmanager.cpp b/ut/stubs/qnetworkaccessmanager.cpp
new file mode 100644 (file)
index 0000000..e21b209
--- /dev/null
@@ -0,0 +1,21 @@
+#include "qnetworkreply.h"
+#include "qnetworkaccessmanager.h"
+
+#include <QNetworkRequest>
+#include <QStringList>
+
+QStringList QNetworkAccessManager::urls;
+
+QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
+    : QObject(parent)
+{
+}
+
+QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request)
+{
+    urls.append(request.url().toString());
+    QNetworkReply *reply = new QNetworkReply();
+    emit finished(reply);
+    return reply;
+}
+
diff --git a/ut/stubs/qnetworkaccessmanager.h b/ut/stubs/qnetworkaccessmanager.h
new file mode 100644 (file)
index 0000000..d6b1677
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef QNETWORKACCESSMANAGER_H
+#define QNETWORKACCESSMANAGER_H
+
+#include <QObject>
+#include <QNetworkRequest>
+#include <QStringList>
+
+class QNetworkReply;
+
+class QNetworkAccessManager : public QObject
+{
+    Q_OBJECT
+public:
+    QNetworkAccessManager(QObject *parent = 0); 
+    QNetworkReply *get(const QNetworkRequest&);
+    static QStringList urls;
+
+signals:
+    void finished(QNetworkReply*);
+};
+
+#endif //QNETWORKACCESSMANAGER_H
diff --git a/ut/stubs/qnetworkreply.cpp b/ut/stubs/qnetworkreply.cpp
new file mode 100644 (file)
index 0000000..553bf9e
--- /dev/null
@@ -0,0 +1,34 @@
+#include <QDebug>
+#include "qnetworkreply.h"
+
+QNetworkReply::QNetworkReply()
+{
+}
+
+QNetworkReply::~QNetworkReply()
+{
+}
+
+QByteArray QNetworkReply::readAll()
+{
+    return QByteArray();
+}
+
+int QNetworkReply::error() const
+{
+    return 0;
+}
+
+void QNetworkReply::close()
+{
+}
+
+void QNetworkReply::deleteLater()
+{
+}
+
+QByteArray QNetworkReply::readLine(qint64 maxlen)
+{
+    return QByteArray();
+}
+
diff --git a/ut/stubs/qnetworkreply.h b/ut/stubs/qnetworkreply.h
new file mode 100644 (file)
index 0000000..d5b0824
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef QNETWORKREPLY_H
+#define QNETWORKREPLY_H
+
+#include <QByteArray>
+
+class QNetworkReply
+{
+public:
+    enum NetworkError {
+        NoError = 0
+    };
+
+    QNetworkReply();
+    ~QNetworkReply();
+    QByteArray readAll();
+    int error() const;
+    void close();
+    void deleteLater();
+    QByteArray readLine(qint64 maxlen = 0);
+
+};
+
+#endif // QNETWORKREPLY_H
+
diff --git a/ut/stubs/qsettings.cpp b/ut/stubs/qsettings.cpp
new file mode 100644 (file)
index 0000000..0ff38bb
--- /dev/null
@@ -0,0 +1,14 @@
+#include "qsettings.h"
+
+QMap<QString, QVariant> QSettings::values;
+
+void QSettings::setValue(const QString& key, const QVariant& value)
+{
+    values.insert(key, value);
+}
+
+QVariant QSettings::value(const QString &key, const QVariant &defaultValue)
+{
+    return values.value(key, defaultValue);
+}
+
diff --git a/ut/stubs/qsettings.h b/ut/stubs/qsettings.h
new file mode 100644 (file)
index 0000000..77ec894
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef QSETTINGS_H
+#define QSETTINGS_H
+
+#include <QMap>
+#include <QString>
+#include <QVariant>
+
+class QSettings
+{
+public:
+    QSettings(QObject* parent = 0) {}
+    void setValue(const QString& key, const QVariant& value);
+    QVariant value(const QString &key, const QVariant &defaultValue);
+    static QMap<QString, QVariant> values;
+};
+
+#endif
+
index aa8ad01..0a68d03 100644 (file)
--- a/ut/ut.pri
+++ b/ut/ut.pri
@@ -1,26 +1,20 @@
 TEMPLATE        =   app
 TARGET          =   test
 
-WARNINGS        +=  -Wall
-
-# CONFIG          +=  debug
-# QMAKE_CXXFLAGS_DEBUG  +=  -fprofile-arcs
-# QMAKE_CXXFLAGS_DEBUG  +=  -ftest-coverage
-# QMAKE_LFLAGS_DEBUG   +=  -fprofile-arcs
-# QMAKE_LFLAGS_DEBUG   +=  -ftest-coverage
-
-QT              +=  testlib
-
 SRCDIR          =   ../../src
 STUBDIR         =   ../stubs
 
-DEPENDPATH      +=
-
+INCLUDEPATH     +=  $$STUBDIR
 INCLUDEPATH     +=  $$SRCDIR
-INCLUDEPATH     +=  .
 
-VPATH           =   $$SRCDIR
 VPATH           +=  $$STUBDIR
+VPATH           +=  $$SRCDIR
+
+WARNINGS        +=  -Wall
+
+QT              +=  testlib
+
+DEPENDPATH      +=
 
 UI_DIR          =   uics
 MOC_DIR         =   mocs
diff --git a/ut/ut_remote/ut_remote.cpp b/ut/ut_remote/ut_remote.cpp
new file mode 100644 (file)
index 0000000..d221de0
--- /dev/null
@@ -0,0 +1,77 @@
+#include <QSettings>
+#include "ut_remote.h"
+
+#include <fstream>
+
+#include <QtTest>
+#include <QDebug>
+
+#include "qnetworkaccessmanager.h"
+
+#define private public
+#include "remote.h"
+#undef private
+
+void reset()
+{
+    QNetworkAccessManager::urls.clear();
+    QSettings::values.clear();
+}
+
+void Ut_Remote::initTestCase()
+{
+    subject = NULL;
+}
+
+void Ut_Remote::cleanupTestCase()
+{
+}
+
+void Ut_Remote::init()
+{
+    subject = new Remote();
+    reset();
+}
+
+void Ut_Remote::cleanup()
+{
+    if (subject != NULL) {
+        delete subject;
+        subject = NULL;
+    }
+    reset();
+}
+
+void Ut_Remote::testSaveToFile_normal()
+{
+    subject->m_name = "testname";
+    subject->saveToFile();
+    QCOMPARE(QNetworkAccessManager::urls.count(), 1);
+    QCOMPARE(QNetworkAccessManager::urls[0], 
+            QString("http://mercury.wipsl.com/irwi/uploaded/testname"));
+    QSettings settings;
+    QCOMPARE(settings.value("remoteName", "fail").toString(), 
+            QString("testname"));
+}
+
+void Ut_Remote::testSaveToFile_emptyname()
+{
+    subject->m_name = "";
+    subject->saveToFile();
+    QCOMPARE(QNetworkAccessManager::urls.count(), 0);
+    QSettings settings;
+    QCOMPARE(settings.value("remoteName", "testname").toString(), 
+            QString("testname"));
+}
+
+void Ut_Remote::testUpdateInfo()
+{
+}
+
+void Ut_Remote::testSendRating()
+{
+}
+
+QTEST_MAIN(Ut_Remote)
+
+
diff --git a/ut/ut_remote/ut_remote.h b/ut/ut_remote/ut_remote.h
new file mode 100644 (file)
index 0000000..d0373c4
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef UT_REMOTE_H
+#define UT_REMOTE_H
+
+#include <QObject>
+
+class Remote;
+
+class Ut_Remote : public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void initTestCase();
+    void cleanupTestCase();
+    void init();
+    void cleanup();
+
+    void testSaveToFile_normal();
+    void testSaveToFile_emptyname();
+    void testUpdateInfo();
+    void testSendRating();
+
+private:
+    Remote *subject;
+};
+
+#endif // UT_REMOTE_H
+
+
diff --git a/ut/ut_remote/ut_remote.pro b/ut/ut_remote/ut_remote.pro
new file mode 100644 (file)
index 0000000..3295b87
--- /dev/null
@@ -0,0 +1,20 @@
+HEADERS += qnetworkreply.h
+HEADERS += qnetworkaccessmanager.h
+HEADERS += qsettings.h
+HEADERS += remote.h
+HEADERS += rating.h
+HEADERS += ut_remote.h
+
+SOURCES += qnetworkreply.cpp
+SOURCES += qnetworkaccessmanager.cpp
+SOURCES += qsettings.cpp
+SOURCES += ut_remote.cpp
+SOURCES += remote.cpp
+SOURCES += rating.cpp
+
+QT += network
+
+!include( ../ut.pri ) {
+    error( Could not find the ut.pri file )
+}
+