1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 18:58:55 +01:00
Clementine-audio-player-Mac.../tests/mock_networkaccessmanager.h

71 lines
2.2 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MOCK_NETWORKACCESSAMANGER_H
#define MOCK_NETWORKACCESSMANAGER_H
2010-03-03 21:35:19 +01:00
#include <QByteArray>
#include <QMap>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QUrl>
#include "test_utils.h"
#include "gmock/gmock.h"
2010-03-03 21:35:19 +01:00
// Usage:
// Create a MockNetworkAccessManager.
// Call ExpectGet() with appropriate expectations and the data you want back.
// This will return a MockNetworkReply*. When you are ready for the reply to
// arrive, call MockNetworkReply::Done().
class MockNetworkReply : public QNetworkReply {
Q_OBJECT
public:
MockNetworkReply();
2010-03-03 21:35:19 +01:00
MockNetworkReply(const QByteArray& data);
2010-03-03 21:35:19 +01:00
// Use these to set expectations.
void SetData(const QByteArray& data);
virtual void setAttribute(QNetworkRequest::Attribute code, const QVariant& value);
2010-03-03 21:35:19 +01:00
// Call this when you are ready for the finished() signal.
void Done();
protected:
MOCK_METHOD0(abort, void());
virtual qint64 readData(char* data, qint64);
virtual qint64 writeData(const char* data, qint64);
2010-03-03 21:35:19 +01:00
QByteArray data_;
qint64 pos_;
};
class MockNetworkAccessManager : public QNetworkAccessManager {
Q_OBJECT
public:
MockNetworkReply* ExpectGet(
2010-03-03 21:35:19 +01:00
const QString& contains, // A string that should be present in the URL.
const QMap<QString, QString>& params, // Required URL parameters.
int status, // Returned HTTP status code.
const QByteArray& ret_data); // Returned data.
protected:
MOCK_METHOD3(createRequest, QNetworkReply*(Operation, const QNetworkRequest&, QIODevice*));
};
#endif