~ubuntuone-hackers/ubuntu-download-manager/saucy

« back to all changes in this revision

Viewing changes to ubuntu-download-manager-tests/test_download_factory.cpp

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2013-09-26 14:06:33 UTC
  • mfrom: (105.5.6 valid-hash-method)
  • Revision ID: tarmac-20130926140633-p9pj4rm3wjmi0q5s
Return DBus error when the hash method is not known. Fixes: https://bugs.launchpad.net/bugs/1228246.

Approved by Roberto Alsina, PS Jenkins bot, Diego Sarmentero.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <single_download.h>
 
20
#include <hash_algorithm.h>
20
21
#include "./test_download_factory.h"
21
22
 
22
23
TestDownloadFactory::TestDownloadFactory(QObject *parent)
66
67
    _apparmor->record();
67
68
 
68
69
    QString hash = "my-hash";
69
 
    QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
 
70
    QString algo = "Md5";
70
71
 
71
72
    // same as above but assert hash and hash algo
72
73
    Download* download = _downFactory->createDownload("", QUrl(),
83
84
 
84
85
    SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
85
86
    QCOMPARE(hash, single->hash());
86
 
    QCOMPARE(algo, single->hashAlgorithm());
 
87
    QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
87
88
}
88
89
 
89
90
void
93
94
    // create a download, assert that it was
94
95
    // created and that the id and the path are correctly set
95
96
    Download* download = _downFactory->createDownload("",
96
 
        QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
 
97
        QList<GroupDownloadStruct>(), "Md5",
97
98
        true, QVariantMap(), QMap<QString, QString>());
98
99
 
99
100
    QList<MethodData> calledMethods = _apparmor->calledMethods();
160
161
    metadata["objectpath"] = id.toString();
161
162
 
162
163
    QString hash = "my-hash";
163
 
    QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
 
164
    QString algo = "Md5";
164
165
 
165
166
    // same as above but assert hash and hash algo
166
167
    Download* download = _downFactory->createDownload("", QUrl(),
175
176
 
176
177
    SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
177
178
    QCOMPARE(hash, single->hash());
178
 
    QCOMPARE(algo, single->hashAlgorithm());
 
179
    QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
179
180
}
180
181
 
181
182
void
186
187
    metadata["objectpath"] = "bad-id";
187
188
 
188
189
    QString hash = "my-hash";
189
 
    QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
 
190
    QString algo = "Md5";
190
191
 
191
192
    // same as above but assert hash and hash algo
192
193
    Download* download = _downFactory->createDownload("", QUrl(),
203
204
 
204
205
    SingleDownload* single = reinterpret_cast<SingleDownload*>(download);
205
206
    QCOMPARE(hash, single->hash());
206
 
    QCOMPARE(algo, single->hashAlgorithm());
 
207
    QCOMPARE(HashAlgorithm::getHashAlgo(algo), single->hashAlgorithm());
207
208
}
208
209
 
209
210
void
218
219
    metadata["objectpath"] = id.toString();
219
220
 
220
221
    Download* download = _downFactory->createDownload("",
221
 
        QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
 
222
        QList<GroupDownloadStruct>(), "Md5",
222
223
        true, metadata, QMap<QString, QString>());
223
224
 
224
225
    QList<MethodData> calledMethods = _apparmor->calledMethods();
239
240
    metadata["objectpath"] = "bad-id";
240
241
 
241
242
    Download* download = _downFactory->createDownload("",
242
 
        QList<GroupDownloadStruct>(), QCryptographicHash::Md5,
 
243
        QList<GroupDownloadStruct>(), "Md5",
243
244
        true, metadata, QMap<QString, QString>());
244
245
 
245
246
    QList<MethodData> calledMethods = _apparmor->calledMethods();
273
274
TestDownloadFactory::testCreateDownloadForGroupWithHash() {
274
275
    _apparmor->record();
275
276
    Download* download = _downFactory->createDownloadForGroup(true, "", QUrl(),
276
 
        "", QCryptographicHash::Md5, QVariantMap(), QMap<QString, QString>());
 
277
        "", "Md5", QVariantMap(), QMap<QString, QString>());
277
278
 
278
279
    QList<MethodData> calledMethods = _apparmor->calledMethods();
279
280
    QCOMPARE(1, calledMethods.count());