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

55 lines
1.5 KiB
C
Raw Normal View History

#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