Added project for building all unit tests
[situare] / tests / situareservice / networkreplymock.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Jussi Laitinen - jussi.laitinen@ixonos.com
7
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.
11
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.
16
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,
20    USA.
21 */
22
23 #include <QNetworkRequest>
24 #include <QDebug>
25 #include "networkreplymock.h"
26
27 NetworkReplyMock::NetworkReplyMock(QObject *parent)
28     : QNetworkReply(parent)
29     , m_offset(0)
30 {
31 }
32
33 void NetworkReplyMock::setError(NetworkError errorCode, const QString &errorString)
34 {
35      qDebug() << __PRETTY_FUNCTION__;
36      QNetworkReply::setError(errorCode, errorString);
37 }
38
39
40 qint64 NetworkReplyMock::readData(char *data, qint64 maxLen)
41 {
42     qDebug() << __PRETTY_FUNCTION__;
43     if (m_offset < m_content.size()) {
44         qint64 number = qMin(maxLen, m_content.size() - m_offset);
45         memcpy(data, m_content.constData() + m_offset, number);
46         m_offset += number;
47         return number;
48    }
49    else {
50         return -1;
51    }
52 }
53
54 QByteArray NetworkReplyMock::readAll()
55 {
56     return m_content;
57 }
58
59 qint64 NetworkReplyMock::bytesAvailable() const
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62     return m_content.size() - m_offset;
63 }
64
65 void NetworkReplyMock::setUrl(const QUrl &url)
66 {
67     qDebug() << __PRETTY_FUNCTION__;
68     QNetworkReply::setUrl(url);
69 }
70
71 void NetworkReplyMock::abort()
72 {
73     qDebug() << __PRETTY_FUNCTION__;
74 }
75
76 void NetworkReplyMock::test()
77 {
78      qDebug() << __PRETTY_FUNCTION__;
79 }
80
81 void NetworkReplyMock::setData(const QByteArray &content)
82 {
83      qDebug() << __PRETTY_FUNCTION__;
84 //     setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
85 //     setHeader(QNetworkRequest::ContentLengthHeader, QVariant(this->m_content.size()));
86      m_content.append(content);
87      qDebug() << "Content size: " << m_content.size();
88 }