~system-image-client-team/system-image-client/trunk

« back to all changes in this revision

Viewing changes to tests/systemimageclient/downloadmanagermock.cpp

  • Committer: Tarmac
  • Author(s): Albert Astals
  • Date: 2012-07-23 15:08:47 UTC
  • mfrom: (60.5.18 pipe_everything)
  • Revision ID: tarmac-20120723150847-wrjlrzrx95wo65rj
Do not use any temporary file at all. Approved by jenkins, Ted Gould.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "downloadmanager.h"
19
19
 
20
20
// Qt includes
21
 
#include <QTemporaryFile>
22
 
#include <QTextStream>
 
21
#include <QFile>
 
22
#include <QProcess>
23
23
 
24
24
DownloadManager::DownloadManager()
25
25
{
26
26
}
27
27
 
28
 
bool DownloadManager::downloadToFile(const QUrl &url)
 
28
void DownloadManager::setHashCalculation(HashUtils::HashType /*type*/)
 
29
{
 
30
}
 
31
 
 
32
bool DownloadManager::downloadToProcess(const QUrl &url, QProcess *process)
29
33
{
30
34
    m_lastDownloadedUrl = url;
31
 
    QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(bool, true));
32
 
    return true;
33
 
}
34
 
 
35
 
QTemporaryFile *DownloadManager::file()
36
 
{
37
 
    QTemporaryFile *f = new QTemporaryFile();
38
 
    f->open();
39
35
 
40
36
    const QString fileContentToReturn = m_filesContentToReturn.front();
41
37
    if (m_filesContentToReturn.count() > 1) {
42
38
        m_filesContentToReturn.pop_front();
43
39
    }
44
40
 
45
 
    QFile f2(fileContentToReturn);
46
 
    f2.open(QIODevice::ReadOnly);
47
 
    f->write(f2.readAll());
48
 
    f2.close();
49
 
    f->close();
50
 
    return f;
 
41
    QFile f(fileContentToReturn);
 
42
    f.open(QIODevice::ReadOnly);
 
43
    process->write(f.readAll());
 
44
    process->closeWriteChannel();
 
45
    f.close();
 
46
 
 
47
    QMetaObject::invokeMethod(this, "downloadFinished", Qt::QueuedConnection, Q_ARG(bool, true), Q_ARG(quint64, 1234));
 
48
    return true;
 
49
}
 
50
 
 
51
QByteArray DownloadManager::hash() const
 
52
{
 
53
    return QByteArray();
51
54
}
52
55
 
53
56
#include "downloadmanager.moc"