2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Jussi Laitinen - jussi.laitinen@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include "networkaccessmanagermock.h"
27 NetworkAccessManagerMock::NetworkAccessManagerMock(QNetworkAccessManager *manager, QObject *parent)
28 : QNetworkAccessManager(parent)
31 qDebug() << __PRETTY_FUNCTION__;
34 NetworkReplyMock *NetworkAccessManagerMock::createRequest(Operation op, const QNetworkRequest &request,
35 QIODevice *outgoingData)
37 qDebug() << __PRETTY_FUNCTION__;
39 reply = new NetworkReplyMock(this);
40 this->request = request;
44 case NetworkAccessManagerMock::CORRECT:
45 QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
47 case NetworkAccessManagerMock::INCORRECT:
48 QTimer::singleShot(0, this, SLOT(generateError()));
50 case NetworkAccessManagerMock::DELAYED_CORRECT:
51 QTimer::singleShot(0, this, SLOT(generateDelayedCorrectReply()));
54 QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
60 NetworkAccessManagerMock::~NetworkAccessManagerMock()
65 NetworkReplyMock *NetworkAccessManagerMock::get(const QNetworkRequest &request)
67 qDebug() << __PRETTY_FUNCTION__;
68 this->request = request;
73 void NetworkAccessManagerMock::setMode(int mode)
78 void NetworkAccessManagerMock::generateError()
80 qDebug() << __PRETTY_FUNCTION__;
81 reply->setUrl(request.url());
82 reply->setError(QNetworkReply::HostNotFoundError, "Host not found");
83 emit QNetworkAccessManager::finished(reply);
86 void NetworkAccessManagerMock::generateCorrectReply()
88 qDebug() << __PRETTY_FUNCTION__;
89 reply->setUrl(request.url());
90 reply->setError(QNetworkReply::NoError, "No error");
92 // if (!image.load(":testTile.png", 0)) {
93 // qDebug() << "could not load image";
97 // qDebug() << "image loaded";
100 // QBuffer buffer(&array);
101 // buffer.open(QBuffer::WriteOnly);
102 // if (image.save(&buffer, "PNG"))
103 // qDebug() << "image saved";
105 // reply->setData(array);
106 emit QNetworkAccessManager::finished(reply);
109 void NetworkAccessManagerMock::generateDelayedCorrectReply()
111 qDebug() << __PRETTY_FUNCTION__;
112 QTimer::singleShot(4000, this, SLOT(generateCorrectReply()));